def areaOpShapes(self, obj): '''areaOpShapes(obj) ... returns envelope for all wires formed by the base edges.''' PathLog.track() if obj.UseComp: self.commandlist.append(Path.Command("(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")")) else: self.commandlist.append(Path.Command("(Uncompensated Tool Path)")) shapes = [] if obj.Base: basewires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) basewires.append((b[0], findWires(edgelist))) for base,wires in basewires: for wire in wires: f = Part.makeFace(wire, 'Part::FaceMakerSimple') # shift the compound to the bottom of the base object for # proper sectioning zShift = b[0].Shape.BoundBox.ZMin - f.BoundBox.ZMin newPlace = FreeCAD.Placement(FreeCAD.Vector(0, 0, zShift), f.Placement.Rotation) f.Placement = newPlace env = PathUtils.getEnvelope(base.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, False)) return shapes
def areaOpShapes(self, obj): '''areaOpShapes(obj) ... returns envelope for all wires formed by the base edges.''' PathLog.track() if obj.UseComp: self.commandlist.append( Path.Command("(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")")) else: self.commandlist.append(Path.Command("(Uncompensated Tool Path)")) shapes = [] if obj.Base: wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: f = Part.makeFace(wire, 'Part::FaceMakerSimple') # shift the compound to the bottom of the base object for # proper sectioning zShift = b[0].Shape.BoundBox.ZMin - f.BoundBox.ZMin newPlace = FreeCAD.Placement(FreeCAD.Vector(0, 0, zShift), f.Placement.Rotation) f.Placement = newPlace env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, False)) return shapes
def execute(self, obj): import Part # math #DraftGeomUtils output = "" toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError( "No Tool Controller is selected. We need a tool to build a Path." ) else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = toolLoad.Proxy.getTool(toolLoad) if not tool or tool.Diameter == 0: FreeCAD.Console.PrintError( "No Tool found or diameter is zero. We need a tool to build a Path." ) return else: self.radius = tool.Diameter / 2 output += "(" + obj.Label + ")" if obj.UseComp: output += "(Compensated Tool Path. Diameter: " + str( self.radius * 2) + ")" else: output += "(Uncompensated Tool Path)" if obj.Base: wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: edgelist = wire.Edges edgelist = Part.__sortEdges__(edgelist) output += self._buildPathLibarea(obj, edgelist) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def execute(self, obj): import Part # math #DraftGeomUtils output = "" toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError("No Tool Controller is selected. We need a tool to build a Path.") else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = toolLoad.Proxy.getTool(toolLoad) if not tool or tool.Diameter == 0: FreeCAD.Console.PrintError("No Tool found or diameter is zero. We need a tool to build a Path.") return else: self.radius = tool.Diameter/2 output += "(" + obj.Label + ")" if obj.UseComp: output += "(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")" else: output += "(Uncompensated Tool Path)" if obj.Base: wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: edgelist = wire.Edges edgelist = Part.__sortEdges__(edgelist) output += self._buildPathLibarea(obj, edgelist) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def execute(self, obj): import Part # math #DraftGeomUtils output = "" toolLoad = PathUtils.getLastToolLoad(obj) # obj.ToolController = PathUtils.getToolControllers(obj) # toolLoad = PathUtils.getToolLoad(obj, obj.ToolController) if toolLoad is None or toolLoad.ToolNumber == 0: self.vertFeed = 100 self.horizFeed = 100 self.vertRapid = 100 self.horizRapid = 100 self.radius = 0.25 obj.ToolNumber = 0 obj.ToolDescription = "UNDEFINED" else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = PathUtils.getTool(obj, toolLoad.ToolNumber) if tool.Diameter == 0: self.radius = 0.25 else: self.radius = tool.Diameter/2 obj.ToolNumber = toolLoad.ToolNumber obj.ToolDescription = toolLoad.Name if obj.UserLabel == "": obj.Label = obj.Name + " :" + obj.ToolDescription else: obj.Label = obj.UserLabel + " :" + obj.ToolDescription output += "(" + obj.Label + ")" if obj.Side != "On": output += "(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")" else: output += "(Uncompensated Tool Path)" if obj.Base: # hfaces = [] # vfaces = [] wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: edgelist = wire.Edges edgelist = Part.__sortEdges__(edgelist) output += self._buildPathLibarea(obj, edgelist) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def getGeom(g): geom = g.Group name = g.Label objs = [] item = "# ***** "+name+" *****\n" edges=[] points = [] for s in geom: if s.Shape.ShapeType =='Vertex': points.append(s) elif s.Shape.ShapeType =='Wire': edges.extend(s.Shape.Edges) elif s.Shape.ShapeType =='Face': edges.extend(s.Shape.OuterWire.Edges) else: #objs.append(s.Object) edges.append(s.Shape) sorted_edges = [] sorted_edges = sortEdges(edges) wire1 = findWires(sorted_edges) start=sorted_edges[0] end=sorted_edges[-1] startingZ = start.Vertexes[0].Z #set starting depth to same Z as starting curve element #self.form.lineEditStartDepth.setText(str(start.Vertexes[0].Z)) item += name+" = area.Curve()\n" if isReallyClosed(wire1[0]): item += '#closed path\n' path = 'closedpath' else: item += '#open path\n' path = 'openpath' # if isSameVertex(start.Vertexes[0],end.Vertexes[1]) : # item += '#closed path\n' # path = 'closedpath' # else: # item += '#open path\n' # path = 'openpath' #if path == 'openpath' : item += name+".append(area.Point(" + str(start.Vertexes[0].X) + "," + str(start.Vertexes[0].Y)+ "))\n" for s in sorted_edges: #edges.append(s) if (isinstance(s.Curve,Part.Circle)): mp = findMidpoint(s) ce = s.Curve.Center # tang1 = s.Curve.tangent(s.ParameterRange[0]) ; tang2 = s.Curve.tangent(s.ParameterRange[1]) # cross1 = Vector.cross(Base.Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Base.Vector(tang2[0][0],tang2[0][1],tang2[0][2])) #look at isClockwise in DraftGeomUtils.py # if cross1[2] > 0: if isClockwise(s): direct = '1 ' #we seem to be working in a rh system in FreeCAD else: direct = '-1 ' item += name+".append(area.Vertex("+str(direct)+ ", area.Point( "+ str(s.Vertexes[-1].Point[0])+", "+str(s.Vertexes[-1].Point[1])+ "), area.Point("+str(s.Curve.Center [0])+ ", " + str(s.Curve.Center[1])+ ")))\n" elif (isinstance(s.Curve,Part.Line)): item += name+".append(area.Point( "+str(s.Vertexes[-1].Point[0])+", " +str(s.Vertexes[-1].Point[1])+ "))\n" else: pass # if path == 'closedpath': # item += name+".append(area.Point(" + str(start.Vertexes[1].X) + "," + str(start.Vertexes[1].Y)+ "))\n" #item+= name+".Reverse()\n" #return item if points: item+= name+"_startparams = {'key':'value'}\n" item+= name+"_startparams['startpt'] = True\n" item+= name+"_startparams['startptX'] = "+str(points[0].X)+"\n" item+= name+"_startparams['startptY'] = "+str(points[0].Y)+"\n" #item+= "kurve_funcs.make_smaller( "+ name+ ", start = area.Point(" + str(points[0].X)+","+str(points[0].Y)+"))\n" else: item+= name+"_startparams = {'key':'value'}\n" item+= name+"_startparams['startpt'] = False\n" # item+="profileparams['side'] = 'left'\n" # item+="profile("+name+", profileparams,"+ name+"_startparams)\n" return item
def SortPath(wire, Side, radius, clockwise, firstedge=None, SegLen=0.5): '''SortPath(wire,Side,radius,clockwise,firstedge=None,SegLen =0.5) Sorts the wire and reverses it, if needed. Splits arcs over 180 degrees in two. Returns the reordered offset of the wire. ''' if firstedge: edgelist = wire.Edges[:] if wire.isClosed(): elindex = None n = 0 for e in edgelist: if isSameEdge(e, firstedge): # FreeCAD.Console.PrintMessage('found first edge\n') elindex = n n = n + 1 l1 = edgelist[:elindex] l2 = edgelist[elindex:] newedgelist = l2 + l1 if clockwise: newedgelist.reverse() last = newedgelist.pop(-1) newedgelist.insert(0, last) preoffset = [] for e in newedgelist: if clockwise: r = reverseEdge(e) preoffset.append(r) else: preoffset.append(e) sortedpreoff = Part.__sortEdges__(preoffset) wire = Part.Wire(sortedpreoff) #wire = findWires(sortedpreoff)[0] else: sortedpreoff = Part.__sortEdges__(edgelist) wire = Part.Wire(sortedpreoff) #wire = findWires(sortedpreoff)[0] edgelist = [] for e in wire.Edges: if geomType(e) == "Circle": arclist = filterArcs(e) for a in arclist: edgelist.append(a) elif geomType(e) == "Line": edgelist.append(e) elif geomType(e) == "BSplineCurve" or \ geomType(e) == "BezierCurve" or \ geomType(e) == "Ellipse": edgelist.append(Part.Wire(curvetowire(e, (SegLen)))) #newwire = Part.Wire(edgelist) sortededges = Part.__sortEdges__(edgelist) newwire = findWires(sortededges)[0] if Side == 'Left': # we use the OCC offset feature offset = newwire.makeOffset(radius) # tool is outside line elif Side == 'Right': offset = newwire.makeOffset(-radius) # tool is inside line else: if wire.isClosed(): offset = newwire.makeOffset(0.0) else: offset = newwire return offset
def execute(self, obj): import Part # math #DraftGeomUtils output = "" toolLoad = PathUtils.getLastToolLoad(obj) # obj.ToolController = PathUtils.getToolControllers(obj) # toolLoad = PathUtils.getToolLoad(obj, obj.ToolController) if toolLoad is None or toolLoad.ToolNumber == 0: self.vertFeed = 100 self.horizFeed = 100 self.vertRapid = 100 self.horizRapid = 100 self.radius = 0.25 obj.ToolNumber = 0 obj.ToolDescription = "UNDEFINED" else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = PathUtils.getTool(obj, toolLoad.ToolNumber) if tool.Diameter == 0: self.radius = 0.25 else: self.radius = tool.Diameter / 2 obj.ToolNumber = toolLoad.ToolNumber obj.ToolDescription = toolLoad.Name if obj.UserLabel == "": obj.Label = obj.Name + " :" + obj.ToolDescription else: obj.Label = obj.UserLabel + " :" + obj.ToolDescription output += "(" + obj.Label + ")" if obj.Side != "On": output += "(Compensated Tool Path. Diameter: " + str( self.radius * 2) + ")" else: output += "(Uncompensated Tool Path)" if obj.Base: # hfaces = [] # vfaces = [] wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: edgelist = wire.Edges edgelist = Part.__sortEdges__(edgelist) output += self._buildPathLibarea(obj, edgelist) if obj.Active: path = Path.Path(output) obj.Path = path obj.ViewObject.Visibility = True else: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False
def SortPath(wire, Side, radius, clockwise, firstedge=None, SegLen=0.5): '''SortPath(wire,Side,radius,clockwise,firstedge=None,SegLen =0.5) Sorts the wire and reverses it, if needed. Splits arcs over 180 degrees in two. Returns the reordered offset of the wire. ''' if firstedge: edgelist = wire.Edges[:] if wire.isClosed(): elindex = None n = 0 for e in edgelist: if isSameEdge(e, firstedge): # FreeCAD.Console.PrintMessage('found first edge\n') elindex = n n = n + 1 l1 = edgelist[:elindex] l2 = edgelist[elindex:] newedgelist = l2 + l1 if clockwise: newedgelist.reverse() last = newedgelist.pop(-1) newedgelist.insert(0, last) preoffset = [] for e in newedgelist: if clockwise: r = reverseEdge(e) preoffset.append(r) else: preoffset.append(e) sortedpreoff = Part.__sortEdges__(preoffset) wire = Part.Wire(sortedpreoff) #wire = findWires(sortedpreoff)[0] else: sortedpreoff = Part.__sortEdges__(edgelist) wire = Part.Wire(sortedpreoff) #wire = findWires(sortedpreoff)[0] edgelist = [] for e in wire.Edges: if geomType(e) == "Circle": arclist = filterArcs(e) for a in arclist: edgelist.append(a) elif geomType(e) == "Line": edgelist.append(e) elif geomType(e) == "BSplineCurve" or \ geomType(e) == "BezierCurve" or \ geomType(e) == "Ellipse": edgelist.append(Part.Wire(curvetowire(e, (SegLen)))) #newwire = Part.Wire(edgelist) sortededges = Part.__sortEdges__(edgelist) newwire = findWires(sortededges)[0] print "newwire is clockwise: " + str(is_clockwise(newwire)) if is_clockwise(newwire) is not clockwise: newwire.reverse() print "newwire is clockwise: " + str(is_clockwise(newwire)) if Side == 'Left': # we use the OCC offset feature offset = newwire.makeOffset(radius) # tool is outside line elif Side == 'Right': offset = newwire.makeOffset(-radius) # tool is inside line else: if wire.isClosed(): offset = newwire.makeOffset(0.0) else: offset = newwire print "offset wire is clockwise: " + str(is_clockwise(offset)) offset.reverse() print "offset wire is clockwise: " + str(is_clockwise(offset)) return offset
def execute(self, obj, getsim=False): commandlist = [] sim = None if not obj.Active: path = Path.Path("(inactive operation)") obj.Path = path obj.ViewObject.Visibility = False return parentJob = PathUtils.findParentJob(obj) if parentJob is None: return baseobject = parentJob.Base if baseobject is None: return self.depthparams = depth_params( clearance_height=obj.ClearanceHeight.Value, safe_height=obj.SafeHeight.Value, start_depth=obj.StartDepth.Value, step_down=obj.StepDown.Value, z_finish_step=0.0, final_depth=obj.FinalDepth.Value, user_depths=None) toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError( "No Tool Controller is selected. We need a tool to build a Path." ) else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value self.vertRapid = toolLoad.VertRapid.Value self.horizRapid = toolLoad.HorizRapid.Value tool = toolLoad.Proxy.getTool(toolLoad) if not tool or tool.Diameter == 0: FreeCAD.Console.PrintError( "No Tool found or diameter is zero. We need a tool to build a Path." ) return else: self.radius = tool.Diameter / 2 commandlist.append(Path.Command("(" + obj.Label + ")")) if obj.UseComp: commandlist.append( Path.Command("(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")")) else: commandlist.append(Path.Command("(Uncompensated Tool Path)")) if obj.Base: wires = [] for b in obj.Base: edgelist = [] for sub in b[1]: edgelist.append(getattr(b[0].Shape, sub)) wires.extend(findWires(edgelist)) for wire in wires: f = Part.makeFace(wire, 'Part::FaceMakerSimple') # shift the compound to the bottom of the base object for # proper sectioning zShift = b[0].Shape.BoundBox.ZMin - f.BoundBox.ZMin newPlace = FreeCAD.Placement(FreeCAD.Vector(0, 0, zShift), f.Placement.Rotation) f.Placement = newPlace env = PathUtils.getEnvelope(baseobject.Shape, subshape=f, depthparams=self.depthparams) try: (pp, sim) = self._buildPathArea(obj, baseobject=env, start=obj.StartPoint, getsim=getsim) commandlist.extend(pp.Commands) except Exception as e: FreeCAD.Console.PrintError(e) FreeCAD.Console.PrintError( "Something unexpected happened. Unable to generate a contour path. Check project and tool config." ) # Let's finish by rapid to clearance...just for safety commandlist.append(Path.Command("G0", {"Z": obj.ClearanceHeight.Value})) path = Path.Path(commandlist) obj.Path = path obj.ViewObject.Visibility = True return sim