def superWireReverse(debuglist,closed=False): '''superWireReverse(debuglist,[closed]): forces a wire between edges that don't necessarily have coincident endpoints. If closed=True, wire will always be closed. debuglist has a tuple for every edge.The first entry is the edge, the second is the flag 'does not nedd to be inverted' ''' #taken from draftlibs def median(v1,v2): vd = v2.sub(v1) vd.scale(.5,.5,.5) return v1.add(vd) try: from DraftGeomUtils import findMidpoint except ImportError: #workaround for Version 0.12 from draftlibs.fcgeo import findMidpoint #workaround for Version 0.12 import Part #edges = sortEdges(edgeslist) print debuglist newedges = [] for i in range(len(debuglist)): curr = debuglist[i] if i == 0: if closed: prev = debuglist[-1] else: prev = None else: prev = debuglist[i-1] if i == (len(debuglist)-1): if closed: nexte = debuglist[0] else: nexte = None else: nexte = debuglist[i+1] print i,prev,curr,nexte if prev: if curr[0].Vertexes[-1*(not curr[1])].Point == \ prev[0].Vertexes[-1*prev[1]].Point: p1 = curr[0].Vertexes[-1*(not curr[1])].Point else: p1 = median(curr[0].Vertexes[-1*(not curr[1])].Point,\ prev[0].Vertexes[-1*prev[1]].Point) else: p1 = curr[0].Vertexes[-1*(not curr[1])].Point if nexte: if curr[0].Vertexes[-1*curr[1]].Point == \ nexte[0].Vertexes[-1*(not nexte[1])].Point: p2 = nexte[0].Vertexes[-1*(not nexte[1])].Point else: p2 = median(curr[0].Vertexes[-1*(curr[1])].Point,\ nexte[0].Vertexes[-1*(not nexte[1])].Point) else: p2 = curr[0].Vertexes[-1*(curr[1])].Point if isinstance(curr[0].Curve,Part.Line): print "line",p1,p2 newedges.append(Part.Line(p1,p2).toShape()) elif isinstance(curr[0].Curve,Part.Circle): p3 = findMidpoint(curr[0]) print "arc",p1,p3,p2 newedges.append(Part.Arc(p1,p3,p2).toShape()) else: print "Cannot superWire edges that are not lines or arcs" return None print newedges return Part.Wire(newedges)
def make_curves(self): item = "" edges=[] s=Gui.Selection.getSelectionEx() for i in s: for e in i.SubElementNames: edges.append(getattr(i.Object.Shape,e)) sorted_edges = [] sorted_edges = sortEdges(edges) #item += '#another test after sorted_edges \n' def isSameVertex(V1, V2):#borrowed from yorik's fcgeo.py- thanks yorik! ''' Test if vertexes have same coordinates with precision 10E(-precision)''' if round(V1.X-V2.X,1)==0 and round(V1.Y-V2.Y,1)==0 and round(V1.Z-V2.Z,1)==0 : return True else : return False 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 += "curve = area.Curve()\n" 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 += "curve.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])) if cross1[2] > 0: direct = '1 ' #we seem to be working in a rh system in FreeCAD else: direct = '-1 ' item += "curve.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 += "curve.append(area.Point( "+str(s.Vertexes[-1].Point[0])+", " +str(s.Vertexes[-1].Point[1])+ "))\n" else: pass #export curve elements to heekscnc #to reverse the curve: #item += "curve.append(area.Point(" + str(end.Vertexes[0].X) + "," + str(end.Vertexes[0].Y) + "))" if path == 'closedpath': item += "curve.append(area.Point(" + str(start.Vertexes[1].X) + "," + str(start.Vertexes[1].Y)+ "))\n" item += "curve.Reverse()\n" self.form.textEditCurve.append(item)
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 make_curves(self): item = "" edges = [] s = Gui.Selection.getSelectionEx() for i in s: for e in i.SubElementNames: edges.append(getattr(i.Object.Shape, e)) sorted_edges = [] sorted_edges = sortEdges(edges) #item += '#another test after sorted_edges \n' def isSameVertex(V1, V2): #borrowed from yorik's fcgeo.py- thanks yorik! ''' Test if vertexes have same coordinates with precision 10E(-precision)''' if round(V1.X - V2.X, 1) == 0 and round( V1.Y - V2.Y, 1) == 0 and round(V1.Z - V2.Z, 1) == 0: return True else: return False 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 += "curve = area.Curve()\n" 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 += "curve.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])) if cross1[2] > 0: direct = '1 ' #we seem to be working in a rh system in FreeCAD else: direct = '-1 ' item += "curve.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 += "curve.append(area.Point( " + str( s.Vertexes[-1].Point[0]) + ", " + str( s.Vertexes[-1].Point[1]) + "))\n" else: pass #export curve elements to heekscnc #to reverse the curve: #item += "curve.append(area.Point(" + str(end.Vertexes[0].X) + "," + str(end.Vertexes[0].Y) + "))" if path == 'closedpath': item += "curve.append(area.Point(" + str( start.Vertexes[1].X) + "," + str(start.Vertexes[1].Y) + "))\n" item += "curve.Reverse()\n" self.form.textEditCurve.append(item)