示例#1
0
文件: Program.py 项目: danheeks/PyCAM
    def ApplySurfaceToText(self, surface, surfaces_written):
        if not surface in surfaces_written:
            surfaces_written[surface] = True

            tris = geom.Stl()

            for solid in surface.solids:
                o = cad.GetObjectFromId(cad.OBJECT_TYPE_STL_SOLID, solid)
                tris += o.GetTris(surface.tolerance)

            # name the stl file
            import tempfile
            temp_filename = tempfile.gettempdir(
            ) + '/surface%d.stl' % self.number_for_stl_file
            self.number_for_stl_file += 1

            # write stl file
            tris.WriteStl(temp_filename)

            import attach
            import ocl_funcs

            attach.units = self.units
            attach.attach_begin()
            import nc.nc
            nc.nc.creator.stl = ocl_funcs.STLSurfFromFile(temp_filename)
            nc.nc.creator.minz = -10000.0
            nc.nc.creator.material_allowance = surface.material_allowance

        wx.GetApp().attached_to_surface = surface
示例#2
0
文件: Program.py 项目: danheeks/PyCAM
    def MakeGCode(self):
        wx.GetApp().attached_to_surface = None
        self.number_for_stl_file = 1
        wx.GetApp().tool_number = 0

        # import the relevant machine
        machine_module = __import__('nc.' + self.machine.post,
                                    fromlist=['dummy'])
        import importlib
        importlib.reload(machine_module)
        output(self.GetOutputFileName())
        program_begin(self.GetID(), self.GetTitle())

        absolute()

        if self.units > 25.0:
            imperial()
        else:
            metric()

        set_plane(0)

        if self.path_control_mode != PATH_CONTROL_UNDEFINED:
            set_path_control_mode(self.path_control_mode,
                                  self.motion_blending_tolerance,
                                  self.naive_cam_tolerance)

        for tool in self.tools.GetChildren():
            tool.DoGCodeCalls()

        surfaces_written = {}
        patterns_written = {}

        for op in self.operations.GetChildren():
            if op.active:
                surface = cad.GetObjectFromId(Surface.type, op.surface)
                if surface != None: import attach
                surface_apply_before_pattern = (
                    surface !=
                    None) and not surface.same_for_each_pattern_position
                surface_apply_after_pattern = (
                    surface != None) and surface.same_for_each_pattern_position
                if surface_apply_before_pattern:
                    self.ApplySurfaceToText(surface, surfaces_written)
                tranform_begun = self.ApplyPatternToText(
                    op.pattern, patterns_written)
                if surface_apply_after_pattern:
                    self.ApplySurfaceToText(surface, surfaces_written)
                failure = op.DoGCodeCalls()
                if surface_apply_after_pattern: attach.attach_end()
                if tranform_begun: transform.transform_end()
                if surface_apply_before_pattern: attach.attach_end()
                wx.GetApp().attached_to_surface = None
                if failure:
                    wx.MessageBox(failure)
                    cad.Select(op)
                    return

        program_end()
示例#3
0
 def GetBoxWithInvisibles(self):
     self.box = geom.Box3D()
     # return the box around all the solids
     for solid in self.solids:
         object = cad.GetObjectFromId(cad.OBJECT_TYPE_STL_SOLID, solid)
         if object:
             self.box.InsertBox(object.GetBox())
     return self.box
示例#4
0
文件: Program.py 项目: danheeks/PyCAM
 def ApplyPatternToText(self, p, patterns_written):
     pattern = cad.GetObjectFromId(Pattern.type, p)
     if pattern != None:
         # write a transform redirector
         import transform
         transform.transform_begin(pattern.GetMatrices())
         return True
     return False
示例#5
0
    def OnGlCommands(self, select, marked, no_color):
        if marked and not select:
            tool = Tool.FindTool(self.tool_number)
            if tool == None:
                return
            radius = tool.CuttingRadius(True)
            global circle_sketch
            global arc1
            global arc2

            # get 3d position from the point objects, sorted by distance from camera
            forwards = wx.GetApp(
            ).frame.graphics_canvas.viewport.view_point.Forwards()
            lens_point = wx.GetApp(
            ).frame.graphics_canvas.viewport.view_point.lens_point
            posns = []
            for point in self.points:
                object = cad.GetObjectFromId(cad.OBJECT_TYPE_POINT, point)
                if object == None:
                    continue
                pos = object.GetStartPoint()
                dotp = (lens_point - pos) * forwards
                posns.append(DotpAndPos(dotp, pos))

            posns = sorted(posns)

            for dotp_and_pos in posns:
                pos = dotp_and_pos.pos
                p0 = pos + geom.Point3D(-radius, 0, 0)
                p1 = pos + geom.Point3D(radius, 0, 0)

                if circle_sketch == None:
                    circle_sketch = cad.NewSketch()
                    arc1 = cad.NewArc(p0, p1, geom.Point3D(0, 0, 1), pos)
                    arc2 = cad.NewArc(p1, p0, geom.Point3D(0, 0, 1), pos)
                    circle_sketch.Add(arc1)
                    circle_sketch.Add(arc2)
                else:
                    arc1.SetStartPoint(p0)
                    arc1.SetEndPoint(p1)
                    arc1.SetCentrePoint(pos)
                    arc2.SetStartPoint(p1)
                    arc2.SetEndPoint(p0)
                    arc2.SetCentrePoint(pos)

                cad.Material(cad.Color(255, 255, 0)).glMaterial(1.0)
                cad.DrawEnableLighting()
                cad.DrawDisableDepthTesting()
                cad.DrawEnableCullFace()
                cad.Sketch.RenderAsExtrusion(circle_sketch, self.start_depth,
                                             self.final_depth)
                cad.DrawDisableCullFace()
                cad.DrawEnableDepthTesting()
                cad.DrawDisableLighting()
示例#6
0
 def OnGlCommands(self, select, marked, no_color):
     if marked and not select:
         object = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH, self.sketch)
         if object != None:
             cad.Material(cad.Color(255, 255, 0)).glMaterial(1.0)
             cad.DrawEnableLighting()
             #cad.DrawDisableDepthTesting()
             cad.DrawEnableCullFace()
             cad.Sketch.RenderAsExtrusion(object, self.start_depth, self.final_depth)
             cad.DrawDisableCullFace()
             #cad.DrawEnableDepthTesting()
             cad.DrawDisableLighting()
示例#7
0
 def SetSketchOrderAndCombo(self, s):
     self.order = cad.SketchOrderType.SketchOrderTypeUnknown
     
     sketch = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH, s)
     if sketch and sketch.GetType() == cad.OBJECT_TYPE_SKETCH:
         self.order = sketch.GetSketchOrder()
         
     if self.order == cad.SketchOrderType.SketchOrderTypeOpen:
         self.cmbToolOnSide.SetString(0, 'Left')
         self.cmbToolOnSide.SetString(1, 'Right')
     elif self.order == cad.SketchOrderType.SketchOrderTypeCloseCW or self.order == cad.SketchOrderType.SketchOrderTypeCloseCCW:
         self.cmbToolOnSide.SetString(0, 'Outside')
         self.cmbToolOnSide.SetString(1, 'Inside')
     else:
         self.cmbToolOnSide.SetString(0, 'Outside or Left')
         self.cmbToolOnSide.SetString(1, 'Inside or Right')
示例#8
0
文件: wing.py 项目: danheeks/IbusOrni
def GetCurveFromSketch(sketch_id):
    sketch_file_path = tempfile.gettempdir() + '/sketch.dxf'
    sketch = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH, sketch_id)
    if sketch == None:
        return
    else:
        sketch.WriteDxf(sketch_file_path)
        area = geom.AreaFromDxf(sketch_file_path)
        curves = area.GetCurves()
        if len(curves) > 0:
            curve = curves[0]
            if curve.NumVertices() > 1:
                if curve.FirstVertex().p.x > curve.LastVertex().p.x:
                    curve.Reverse()
                return curve
    return None
示例#9
0
 def DoEachSketch(self, callback, data):
     # data is a tuple, whatever you want to pass on
     # callback gets called for each separate sketch
           
     object = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH, self.sketch)
     
     if object != None:
         if object.GetType() == cad.OBJECT_TYPE_SKETCH:
             re_ordered_sketch = None
             sketch_order = object.GetSketchOrder()
             if sketch_order == cad.SketchOrderType.SketchOrderTypeBad:
                 re_ordered_sketch = object.MakeACopy()
                 re_ordered_sketch.ReOrderSketch(cad.SketchOrderType.SketchOrderTypeReOrder)
                 object = re_ordered_sketch
                 sketch_order = object.GetSketchOrder()
             if (sketch_order == cad.SketchOrderType.SketchOrderTypeMultipleCurves) or (sketch_order == cad.SketchOrderType.SketchOrderHasCircles):
                 new_separate_sketches = object.Split()
                 for one_curve_sketch in new_separate_sketches:
                     callback(one_curve_sketch, data)
             else:
                 callback(object, data)
示例#10
0
    def DoGCodeCalls(self):
        failure = self.CheckToolExists()
        if failure: return failure
        tool = Tool.FindTool(self.tool_number)

        depth_params = self.GetDepthParams()
        tool_diameter = tool.CuttingRadius(True) * 2.0
        SpeedOp.DoGCodeCalls(self)

        for point in self.points:
            object = cad.GetObjectFromId(cad.OBJECT_TYPE_POINT, point)
            pos = object.GetEndPoint()
            drill(x=pos.x / wx.GetApp().program.units,
                  y=pos.y / wx.GetApp().program.units,
                  dwell=self.dwell,
                  depthparams=depth_params,
                  retract_mode=self.retract_mode,
                  spindle_mode=self.spindle_mode,
                  internal_coolant_on=self.internal_coolant_on,
                  rapid_to_clearance=self.rapid_to_clearance)

        end_canned_cycle()
示例#11
0
    def GetProperties(self):
        properties = []

        sketch_order = cad.SketchOrderType.SketchOrderTypeUnknown
        sketch_object = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH,
                                            self.sketch)
        if sketch_object != None:
            sketch_order = sketch_object.GetSketchOrder()
        choices = []
        if sketch_order == cad.SketchOrderType.SketchOrderTypeOpen:
            choices.append('Left')
            choices.append('Right')
        elif sketch_order == cad.SketchOrderType.SketchOrderTypeCloseCW or sketch_order == cad.SketchOrderType.SketchOrderTypeCloseCCW:
            choices.append('Outside')
            choices.append('Inside')
        else:
            choices.append('Outside or Left')
            choices.append('Inside or Right')
        choices.append('On')
        choice = 0
        if self.tool_on_side == PROFILE_RIGHT_OR_INSIDE:
            choice = 1
        elif self.tool_on_side == PROFILE_LEFT_OR_OUTSIDE:
            choice = 2
        properties.append(
            PyChoiceProperty("Tool On Side",
                             'tool_on_side',
                             choices,
                             self,
                             alternative_values=[
                                 PROFILE_LEFT_OR_OUTSIDE,
                                 PROFILE_RIGHT_OR_INSIDE, PROFILE_ON
                             ]))

        properties.append(
            PyChoiceProperty("Cut Mode", 'cut_mode', ['Conventional', 'Climb'],
                             self))
        properties.append(PyProperty("Auto Roll On", 'auto_roll_on', self))
        properties.append(PyProperty("Roll On Point", 'roll_on_point', self))
        properties.append(PyProperty("Auto Roll Off", 'auto_roll_off', self))
        properties.append(PyProperty("Roll Off Point", 'roll_off_point', self))
        properties.append(
            PyPropertyLength("Roll Radius", 'auto_roll_radius', self))
        properties.append(PyProperty("Use Start Point", 'start_given', self))
        properties.append(PyProperty("Start Point", 'start', self))
        properties.append(PyProperty("Use End Point", 'end_given', self))
        properties.append(PyProperty("End Point", 'end', self))
        properties.append(
            PyProperty("End Beyond Full Profile", 'end_beyond_full_profile',
                       self))
        properties.append(
            PyPropertyLength("Extend Before Start", 'extend_at_start', self))
        properties.append(
            PyPropertyLength("Extend Past End", 'extend_at_end', self))
        properties.append(
            PyPropertyLength("Lead In Line Length", 'lead_in_line_len', self))
        properties.append(
            PyPropertyLength("Lead Out Line Length", 'lead_out_line_len',
                             self))
        properties.append(
            PyPropertyLength("Offset Extra", 'offset_extra', self))
        properties.append(
            PyProperty("Do Finishing Pass", 'do_finishing_pass', self))
        properties.append(
            PyProperty("Only Finishing Pass", 'only_finishing_pass', self))
        properties.append(
            PyProperty("Finishing Feed Rate", 'finishing_h_feed_rate', self))
        properties.append(
            PyChoiceProperty("Finish Cut Mode", 'finishing_cut_mode',
                             ['Conventional', 'Climb'], self))
        properties.append(
            PyPropertyLength("Finishing Step Down", 'finishing_step_down',
                             self))

        properties += SketchOp.GetProperties(self)

        return properties