Exemplo n.º 1
0
 def GetOwnerForDrawingObjects(self):
     if self.add_to_sketch:
         if self.container == None:
             self.container = cad.NewSketch()
             cad.AddUndoably(self.container)
         return self.container
     return cad.GetApp()
Exemplo n.º 2
0
def Export(path):
    # make model xml structure
    root = ET.Element('model')
    root.set('unit', 'millimeter')

    resources = ET.SubElement(root, 'resources')

    next_object_id = 1

    doc = cad.GetApp()
    object = doc.GetFirstChild()

    while object:
        tris = object.GetTris(0.01)
        if tris != None:
            xmlobject = ET.SubElement(resources, 'object')
            xmlobject.set('id', str(next_object_id))
            next_object_id += 1
            xmlobject.set('type', 'model')
            mesh = tris.GetMesh()
            xmlmesh = ET.SubElement(xmlobject, 'mesh')
            xmlvertices = ET.SubElement(xmlmesh, 'vertices')
            vertices, faces = mesh.GetFaces()
            for vertex in vertices:
                xmlvertex = ET.SubElement(xmlvertices, 'vertex')
                xmlvertex.set('x', str(vertex[0]))
                xmlvertex.set('y', str(vertex[1]))
                xmlvertex.set('z', str(vertex[2]))
            xmltriangles = ET.SubElement(xmlmesh, 'triangles')
            for face in faces:
                if len(face) == 3:
                    xmltriangle = ET.SubElement(xmltriangles, 'triangle')
                    xmltriangle.set('v1', str(face[0]))
                    xmltriangle.set('v2', str(face[1]))
                    xmltriangle.set('v3', str(face[2]))

        object = doc.GetNextChild()

    # add a build section
    build = ET.SubElement(root, 'build')
    for i in range(0, next_object_id):
        item = ET.SubElement(build, 'item')
        item.set('objectid', str(i + 1))

    if os.path.exists(path):
        os.remove(path)

    import zipfile
    import zlib
    zf = zipfile.ZipFile(path, mode='w', compression=zipfile.ZIP_DEFLATED)
    zf.writestr(
        '[Content_Types].xml', '''<?xml version="1.0" encoding="UTF-8"?> 
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default ContentType="application/vnd.openxmlformats-package.relationships+xml" Extension="rels" /><Default ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" Extension="model" /></Types>'''
        .encode('utf-8'))
    zf.writestr('3D/3dmodel.model', ET.tostring(root, encoding='utf8'))
    zf.writestr(
        '_rels/.rels', '''<?xml version="1.0" encoding="UTF-8"?> 
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rel0" Target="/3D/3dmodel.model" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" /></Relationships>'''
        .encode('utf-8'))
Exemplo n.º 3
0
    def AddLeftControls(self):
        self.cmbSketch = HTypeObjectDropDown(self, cad.OBJECT_TYPE_SKETCH,
                                             cad.GetApp(), self.OnSketchCombo)
        self.btnSketchPick = wx.Button(self, wx.ID_ANY, 'Pick')
        self.MakeLabelAndControl('Sketches', self.cmbSketch,
                                 self.btnSketchPick).AddToSizer(self.sizerLeft)
        self.btnSketchPick.Bind(wx.EVT_BUTTON, self.OnSketchPick)

        DepthOpDlg.AddLeftControls(self)
Exemplo n.º 4
0
    def Render(self, just_for_calculation=False):
        self.render_just_for_calculation = just_for_calculation
        if not just_for_calculation:
            if os.name == 'nt':
                font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
                self.dc.SetFont(font)

                # draw a white background rectangle
                size = self.GetClientSize()
                pTopLeft = self.CalcUnscrolledPosition(0, 0)
                pBottomRight = self.CalcUnscrolledPosition(size.x, size.y)
                self.dc.SetBrush(wx.Brush("white"))
                self.dc.SetPen(wx.Pen("white"))
                self.dc.DrawRectangle(wx.Rect(pTopLeft, pBottomRight))

            # set background
            self.dc.SetBackgroundMode(wx.SOLID)
            self.dc.SetBackground(wx.Brush("white", wx.SOLID))
            self.dc.Clear()

            self.tree_buttons = []
            self.rendered_objects = []

        self.xpos = 0  # start at the left
        self.ypos = 0  # -scroll_y_pos; // start at the top
        self.max_xpos = 0

        prev_object = None
        prev_object_expanded = None
        doc = cad.GetApp()
        object = doc.GetFirstChild()

        while object != None:
            next_object = doc.GetNextChild()
            expanded = self.IsExpanded(object)
            self.RenderObject(expanded, prev_object, prev_object_expanded,
                              object, next_object, 0)
            prev_object = object
            prev_object_expanded = expanded
            object = next_object

        # draw the dragged objects
        if self.dragging:
            drag_size = self.GetDraggedListSize()
            self.dc.SetBrush(wx.Brush("orange"))
            self.dc.SetPen(wx.Pen("blue"))
            self.dc.DrawRectangle(self.drag_position, drag_size)
            self.RenderDraggedList()
            if self.drag_paste_rect.width > 0:
                self.dc.SetPen(wx.Pen("black"))
                self.dc.SetBrush(wx.Brush("black"))
                self.dc.DrawRectangle(self.drag_paste_rect)
Exemplo n.º 5
0
 def AddProgramIfThereIsntOne(self):
     # check if there is already a program in the document
     doc = cad.GetApp()
     object = doc.GetFirstChild()
     while object != None:
         if object.GetType() == Program.type:
             self.program = object
             return
         object = doc.GetNextChild()
     
     # add a program
     self.program = Program.Program()
     programs.append(self.program)
     self.program.add_initial_children()        
     cad.AddUndoably(self.program)
Exemplo n.º 6
0
    def OnPrintPage(self, page):
        wx.GetApp().frame.printout = self
        dc = self.GetDC()
        if dc:
            self.SetUnitsFactor()
            cad.SetGetLinesPixelsPerMm(1.0 / self.scale)

            for start, x, y, z in cad.GetApp().GetLines():
                if not start:
                    self.GetDC().DrawLine(
                        self.xoff + (px * self.logUnitsFactorx + 0.5),
                        self.yoff - (py * self.logUnitsFactory + 0.5),
                        self.xoff + (x * self.logUnitsFactorx + 0.5),
                        self.yoff - (y * self.logUnitsFactory + 0.5))
                px = x
                py = y

            return True
        else:
            return False
Exemplo n.º 7
0
 def RegisterObjectTypes(self):
     step.SetResPath(self.cad_dir)
     step.SetApp(cad.GetApp())
     App.RegisterObjectTypes(self)
     cad.RegisterOnEndXmlWrite(step.WriteSolids)
     step.SetStepFileObjectType(
         cad.RegisterObjectType("STEP_file",
                                step.CreateStepFileObject,
                                add_to_filter=False))
     step.SetSolidType(cad.RegisterObjectType("Solid", None))
     step.SetFaceType(cad.RegisterObjectType("Face", None))
     step.SetEdgeType(cad.RegisterObjectType("Edge", None))
     step.SetEllipseType(
         cad.RegisterObjectType("Ellipse", step.CreateEllipse))
     step.SetSplineType(cad.RegisterObjectType("Spline", step.CreateSpline))
     self.RegisterImportFileTypes(['step', 'stp'], 'STEP Files',
                                  ImportSolidsFile)
     self.RegisterImportFileTypes(['iges', 'igs'], 'IGES Files',
                                  ImportSolidsFile)
     self.RegisterExportFileTypes(['step', 'stp'], 'STEP Files',
                                  ExportSolidsFile)
     self.RegisterExportFileTypes(['iges', 'igs'], 'IGES Files',
                                  ExportSolidsFile)
Exemplo n.º 8
0
import os
import sys
cam_dir = os.path.dirname(os.path.realpath(__file__))
pycad_dir = os.path.realpath(cam_dir + '/../PyCAD')
sys.path.append(pycad_dir)
import wx
from nc.nc import *
import cad
import cam

cam.SetResPath(cam_dir)
cam.SetApp(cad.GetApp())

from SolidApp import SolidApp # from CAD
import Program
import Tool
import Tools
import Operations
import Patterns
import Surface
import Surfaces
import Stock
import Stocks
import NcCode
import Profile
import Pocket
import Drilling
import ScriptOp
import Tags
import Tag
import Pattern
Exemplo n.º 9
0
def Export(path):
    f = open(path, 'w')

    f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg1348"
   inkscape:version="0.92.1 r15371"
   sodipodi:docname""")
    f.write('="' + GetFileName(path) + '">\n')
    f.write("""  <defs
     id="defs1342" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="3.959798"
     inkscape:cx="203.20224"
     inkscape:cy="997.78291"
     inkscape:document-units="mm"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1920"
     inkscape:window-height="1017"
     inkscape:window-x="-8"
     inkscape:window-y="-8"
     inkscape:window-maximized="1" />
  <metadata
     id="metadata1345">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title />
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1">\n""")
    doc = cad.GetApp()
    object = doc.GetFirstChild()
    path_id = 1350

    cols = ['ff0000', '00ff00', '0000ff', 'ffff00', '00ffff', 'ff00ff']
    col_index = 0

    while object:
        if object.GetType() == cad.OBJECT_TYPE_SKETCH:
            f.write(
                '    <path\n       style="fill:none;stroke:#' +
                cols[col_index] +
                ';stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"\n'
            )
            col_index += 1
            if col_index == len(cols):
                col_index = 0
            f.write('       d="m')
            first = True
            line = object.GetFirstChild()
            while line:
                if first:
                    s = line.GetStartPoint()
                    f.write(' ' + str(s.x) + ',' + str(-s.y))
                e = line.GetEndPoint()
                f.write(' ' + str(e.x - s.x) + ',' + str(-(e.y - s.y)))
                line = object.GetNextChild()
                s = e
                first = False
            f.write('"\n       id="path' + str(path_id) + '"\n')
            f.write('       inkscape:connector-curvature="0" />\n')
            path_id += 1
        object = doc.GetNextChild()
    f.write('  </g>\n</svg>\n')

    f.close()
Exemplo n.º 10
0
    def OnMouse(self, event):
        # to do? if(wxGetApp().m_property_grid_validation)return;
        if event.Entering():
            self.SetFocus()  # so middle wheel works

        if event.LeftDown():
            button = self.HitTest(event.GetPosition())

            if button:
                if button.type == ButtonTypePlus or button.type == ButtonTypeMinus:
                    self.SetExpanded(button.obj, button.type == ButtonTypePlus)
                    self.SetVirtualSize(self.GetRenderSize())
                    self.Refresh()
                else:
                    self.OnLabelLeftDown(button.obj, event)
                    self.clicked_object = button.obj
            else:
                cad.ClearSelection(True)

            self.button_down_point = event.GetPosition()

        if event.LeftUp():
            if self.dragging:
                self.dragging = False

                # find the object to drop on to
                button = self.HitTest(event.GetPosition())

                if (button == None) or not cad.ObjectMarked(
                        button.obj
                ):  # can only drop on to an item other than one of the items being dragged
                    # test drop possible
                    drag_possible = True

                    add_to = cad.GetApp()
                    if button and button.paste_into: add_to = button.paste_into
                    for object in self.dragged_list:
                        if not add_to.CanAdd(object) or not object.CanAddTo(
                                add_to):
                            drag_possible = False
                            break

                    if drag_possible:
                        cad.StartHistory()

                        # cut the objects
                        cad.DeleteObjectsUndoably(self.dragged_list)

                        # paste the objects
                        for object in self.dragged_list:
                            if object.OneOfAKind():
                                one_found = False
                                child = add_to.GetFirstChild()
                                while child:
                                    if child.GetType() == object.GetType():
                                        child.CopyFrom(object)
                                        one_found = True
                                        break

                                    child = add_to.GetNextChild()

                                if not one_found:
                                    cad.AddUndoably(
                                        object, add_to, button.paste_before if
                                        (button != None) else None)
                            else:
                                cad.AddUndoably(
                                    object, add_to, button.paste_before if
                                    (button != None) else None)

                        cad.EndHistory()
                    else:
                        self.Refresh()
                else:
                    self.Refresh()
            else:
                if self.waiting_until_left_up:
                    cad.ClearSelection(False)
                    cad.Select(self.clicked_object, True)
            self.waiting_until_left_up = False

        if event.RightDown():
            button = self.HitTest(event.GetPosition())
            self.clicked_object = None
            if (button != None) and (button.type == ButtonTypeLabelBefore
                                     or button.type == ButtonTypeLabel):
                self.clicked_object = button.obj
                self.OnLabelRightDown(button.obj, event)

        if event.RightUp():
            if self.dragging:
                self.dragging = False
            else:
                tools = self.GetDropDownTools(event.ControlDown())
                menu = wx.Menu()
                for tool in tools:
                    wx.GetApp().AddToolToListAndMenu(tool, menu)
                self.PopupMenu(menu, event.GetPosition())

        if event.Dragging():
            if event.LeftIsDown() or event.RightIsDown():
                if (not self.dragging) and (
                        math.fabs(self.button_down_point.x - event.GetX()) > 2
                        or math.fabs(self.button_down_point.y - event.GetY()) >
                        2):
                    self.dragging = True
                    self.dragged_list = cad.GetSelectedObjects()

            if self.dragging:
                self.drag_position = self.CalcUnscrolledPosition(
                    event.GetPosition())
                button = self.HitTest(event.GetPosition())
                self.drag_paste_rect = wx.Rect(0, 0, 0, 0)
                if (button != None) and (button.type == ButtonTypeLabelBefore):
                    self.drag_paste_rect = button.rect
                self.Refresh()

        if event.LeftDClick():
            if self.clicked_object:
                wx.GetApp().EditUndoably(self.clicked_object)

        event.Skip()
Exemplo n.º 11
0
 def OnRedraw(self, e):
     cad.GetApp().KillGLLists()
     self.frame.graphics_canvas.Refresh()