def copyToZ(self, z, layerNo): "makes a copy of this slice, transformed to the specified z height" theCopy = Slice() theCopy.zLevel = z theCopy.fillAngle = self.fillAngle theCopy.layerNo = layerNo theCopy.thickness = self.thickness # make transformation p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(0, 0, z) xform = gp.gp_Trsf() xform.SetTranslation(p1, p2) bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform) # copy all of the faces for f in self.faces: bt.Perform(f.face, True) newFace = Face(OCCUtil.cast(bt.Shape())) # copy shells for shell in f.shellWires: # print shell bt.Perform(shell, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) # copy fillWires for fill in f.fillWires: bt.Perform(fill, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) theCopy.addFace(newFace) return theCopy
def testOffsetReferences(): #f = TestObjects.makeHeartFace(); #f must be a face with one outer and one inner wire f = TestObjects.makeSquareWithRoundHole() wires = OCCUtil.wireListFromFace(f) outer = wires[0] inner = wires[1] display.DisplayColoredShape(outer, 'GREEN') display.DisplayColoredShape(inner, 'WHITE') #add wires to offset. bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(outer) bo.AddWire(inner) bo.Perform(-0.2, 0.0) #do an offset shape = bo.Shape() for w in Topo(shape).wires(): display.DisplayColoredShape(OCCUtil.cast(shape), 'YELLOW') for e in Topo(outer).edges(): print "Outer Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e)))) for e in Topo(inner).edges(): print "Inner Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e)))) display.FitAll()
def offsetOnce(self,distance): bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset(); map(bo.AddWire, self.lastWires); print "%d wires to offset at step 1, distance = %0.3f" % ( len(self.lastWires),distance); bo.Perform(distance,0.0); result1 = Topo(bo.Shape()); #now offset back outwards bo2 = BRepOffsetAPI.BRepOffsetAPI_MakeOffset(); for w in result1.wires(): bo2.AddWire(w); print "Offsetting %0.3f" % ( (-0.5)*distance); bo2.Perform((-0.5)*distance, 0.0); result2 = Topo(bo2.Shape()); returnList= []; #compound result can be a compound of edges and/or wires. weird weird for c in OCCUtil.childShapes(bo2.Shape() ): #display.DisplayColoredShape(c,'BLUE') if c.ShapeType() == TopAbs.TopAbs_WIRE: returnList.append(c); #these are actually the wires we want to keep self.otherWires.append(c); elif c.ShapeType() == TopAbs.TopAbs_EDGE: w = OCCUtil.wireFromEdges([c]) returnList.append(w); self.otherWires.append(w); else: print "Warning: compound resulting from offset i am confused about-- not an edge or a wire." if len(returnList) == 0: return returnList; #do nothing further if the offset computed no curves else: print "2nd step yielded %d wires" % len(returnList) #for each original edge, compute its descendant edges #self.edgeMap will contain entries with the original edges, pointing to the generated #edges and the corresponding wire: # e1 --> [ (e2, w2 ), (e3 , w3 ) ]; for w in self.lastWires: originalWire = Topo(w); for oe in originalWire.edges(): self.edgeMap[oe.__hash__()] = []; #find generated values from first transformation generatedStep1 = OCCUtil.listFromTopToolsListOfShape(bo.Generated(oe)); for ne in generatedStep1: #find edges generated from that original edge generatedStep2 = OCCUtil.listFromTopToolsListOfShape(bo2.Generated(ne)); for ge in generatedStep2: #get wire this belongs to this returns a list but how could there ever be more than one? gwires = [] for g in result2.wires_from_edge(ge): gwires.append(g); self.edgeMap[oe.__hash__()].append ( (ge,gwires[0] )); self.lastWires = returnList; return returnList;
def makeOffsets(wire, d=True): numOffsets = 0 if d: display.DisplayColoredShape(startWire, 'YELLOW') STEP = 0.5 for offset in Util.frange6(0.5, 4.0, STEP): #print "offsetting by %0.3f" % offset o = OCCUtil.offsetWire(startWire, offset * (-1.0)) numOffsets += 1 if d: display.DisplayColoredShape(o, 'RED') o2 = OCCUtil.offsetWire(startWire, offset * (-1.0) + (STEP / 2.0)) numOffsets += 1 #create a naive centerline by setting in( which could conflict with others ) #if d: display.DisplayColoredShape(o2,'GREEN'); #now offset back out to create centerline. if the result is a compound, then we must offset each member wire if o.ShapeType() == TopAbs.TopAbs_COMPOUND: t = Topo(o) for w in t.wires(): w2 = OCCUtil.offsetWire(w, STEP * (0.5)) numOffsets += 1 if d: display.DisplayColoredShape(w2, 'BLUE') else: #wire o2 = OCCUtil.offsetWire(OCCUtil.cast(o), STEP * (0.5)) numOffsets += 1 if d: display.DisplayColoredShape(o2, 'WHITE') return numOffsets
def testSplitWire2(): "intersections on different edges. one edge completely inside" e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0)); e2 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(2,0,0),gp.gp_Pnt(5,0,0)); e3 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(5,0,0),gp.gp_Pnt(6,0,0)); #trick here. after building a wire, the edges change identity. #evidently, BRepBuilder_MakeWire makes copies of the underliying edges. w = OCCUtil.wireFromEdges([e1,e2,e3]); ee = Wrappers.Wire(w).edgesAsList(); #print "Original Edges: %d %d %d " % ( ee[0].__hash__(),ee[1].__hash__(),ee[2].__hash__()); p1 = PointOnAnEdge(ee[0],1.0,gp.gp_Pnt(1.0,0,0)); p2 = PointOnAnEdge(ee[2],0.5,gp.gp_Pnt(5.0,0,0)); ee = splitWire(w,[p2,p1]); assert len(ee) == 1; length = 0; for e in ee[0]: ew = Wrappers.Edge(e); length += ew.distanceBetweenEnds(); #print "length=%0.3f" % length; assert length == 4.5;
def copyToZ(self, z, layerNo): "makes a copy of this slice, transformed to the specified z height" theCopy = Slice() theCopy.zLevel = z theCopy.fillAngle = self.fillAngle theCopy.layerNo = layerNo theCopy.thickness = self.thickness #make transformation p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(0, 0, z) xform = gp.gp_Trsf() xform.SetTranslation(p1, p2) bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform) #copy all of the faces for f in self.faces: bt.Perform(f.face, True) newFace = Face(OCCUtil.cast(bt.Shape())) #copy shells for shell in f.shellWires: #print shell bt.Perform(shell, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) #copy fillWires for fill in f.fillWires: bt.Perform(fill, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) theCopy.addFace(newFace) return theCopy
def trimmedEdgeFromPoints(self,point1, point2,tolerance): print "I am %s" % self print "Creating new edge from points: ",Point(point1),Point(point2) #(param1,newPoint1) = OCCUtil.findPointOnCurve(point1,self.handleCurve,tolerance); #(param2,newPoint2) = OCCUtil.findPointOnCurve(point2,self.handleCurve,tolerance); #well this is annoying-- the parameter range appears to be preventing projection, so we need to pad them fp = self.firstParameter; fpnt = self.firstPoint; lp = self.lastParameter; lpnt = self.lastPoint; if fp > lp: (lp,fp)=(fp,lp); (fpnt,lpnt)=(lpnt,fpnt); print "Params: fp=%0.3f, lp=%0.3f,tolerance=%0.3f" % ( fp, lp,tolerance); (param1,newPoint1) = OCCUtil.findPointOnCurve(point1,self.handleCurve,tolerance); #check bounds by hand if param1 < fp: param1 = fp; newPoint1 = fpnt; if param1 > lp: parm1 = fp; newPoint1 = lpnt; print "point 1!" (param2,newPoint2) = OCCUtil.findPointOnCurve(point2,self.handleCurve,tolerance); if param2 < fp: param2 = fp; newPoint2 = fpnt; if param2 > lp: parm2 = fp; newPoint2 = lpnt; return self.trimmedEdge(param1,param2);
def testSplitWire1(): """ Test split wire function. there are two main cases: wires with intersection on different edges, and a wire with a single edge split in many places """ #case 1: a single edge with lots of intersections along its length e = OCCUtil.edgeFromTwoPoints( gp.gp_Pnt(0,0,0),gp.gp_Pnt(5,0,0)); w = OCCUtil.wireFromEdges([e]); #out of order on purpose p1 = PointOnAnEdge(e,1.0,gp.gp_Pnt(1.0,0,0)); p3 = PointOnAnEdge(e,3.0,gp.gp_Pnt(3.0,0,0)); p2 = PointOnAnEdge(e,2.0,gp.gp_Pnt(2.0,0,0)); p4 = PointOnAnEdge(e,4.0,gp.gp_Pnt(4.0,0,0)); ee = splitWire(w,[p1,p3,p2,p4] ); assert len(ee) == 2; length = 0; for e in ee: ew = Wrappers.Edge(e[0]); length += ew.distanceBetweenEnds(); assert length == 2.0;
def makeOffsets(wire,d=True): numOffsets = 0; if d: display.DisplayColoredShape(startWire,'YELLOW'); STEP = 0.5; for offset in Util.frange6(0.5,4.0,STEP): #print "offsetting by %0.3f" % offset o = OCCUtil.offsetWire(startWire,offset*(-1.0)); numOffsets+=1; if d: display.DisplayColoredShape(o, 'RED'); o2 = OCCUtil.offsetWire(startWire,offset*(-1.0) + (STEP/2.0) ); numOffsets+=1; #create a naive centerline by setting in( which could conflict with others ) #if d: display.DisplayColoredShape(o2,'GREEN'); #now offset back out to create centerline. if the result is a compound, then we must offset each member wire if o.ShapeType() == TopAbs.TopAbs_COMPOUND: t = Topo(o); for w in t.wires(): w2 = OCCUtil.offsetWire(w,STEP*(0.5)); numOffsets+=1; if d: display.DisplayColoredShape(w2, 'BLUE'); else: #wire o2 = OCCUtil.offsetWire(OCCUtil.cast(o),STEP*(0.5)); numOffsets+=1; if d: display.DisplayColoredShape(o2, 'WHITE'); return numOffsets;
def testOffsetReferences(): #f = TestObjects.makeHeartFace(); #f must be a face with one outer and one inner wire f = TestObjects.makeSquareWithRoundHole(); wires = OCCUtil.wireListFromFace(f); outer = wires[0]; inner = wires[1]; display.DisplayColoredShape(outer,'GREEN'); display.DisplayColoredShape(inner,'WHITE'); #add wires to offset. bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset(); bo.AddWire(outer); bo.AddWire(inner); bo.Perform(-0.2,0.0); #do an offset shape = bo.Shape(); for w in Topo(shape).wires(): display.DisplayColoredShape(OCCUtil.cast(shape),'YELLOW'); for e in Topo(outer).edges(): print "Outer Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e) )) ); for e in Topo(inner).edges(): print "Inner Edge %d has %d generated shapes" % ( e.__hash__(), len(OCCUtil.listFromTopToolsListOfShape(bo.Generated(e) )) ); display.FitAll();
def makeWireFromPointList(points): edges = []; for (p,q) in Util.ntuples(points,2,True): print p,q edges.append(OCCUtil.edgeFromTwoPoints(OCCUtil.pnt(p[0],p[1]),OCCUtil.pnt(q[0],q[1]))); return OCCUtil.wireFromEdges(edges);
def makeFaceWithHold(): "creates a face with a thin feature due to a hole" ow = makeSquareWire(); #box 0,0 --> 5,5 p1 = OCCUtil.pnt(0.4,0.4); p2 = OCCUtil.pnt(2.0,0.4); p3 = OCCUtil.pnt(2.0,2.0); p4 = OCCUtil.pnt(2.0,0.4);
def makeFaceWithHold(): "creates a face with a thin feature due to a hole" ow = makeSquareWire() #box 0,0 --> 5,5 p1 = OCCUtil.pnt(0.4, 0.4) p2 = OCCUtil.pnt(2.0, 0.4) p3 = OCCUtil.pnt(2.0, 2.0) p4 = OCCUtil.pnt(2.0, 0.4)
def testBasicFaceOffset(): f = TestObjects.makeHeartFaceNoHole(); startWires = OCCUtil.wireListFromFace(f); display.DisplayColoredShape(startWires,'GREEN'); cw = startWires; for i in range(3): w = OCCUtil.offsetWireList(cw,-0.2); display.DisplayColoredShape(w,'RED'); cw = w;
def makeHeartWire(): "make a heart wire" e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0,0,0), gp.gp_Pnt(4.0,4.0,0)); circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2,4,0),gp.gp().DZ()),2); e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4,4,0),gp.gp_Pnt(0,4,0)).Edge(); circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2,4,0),gp.gp().DZ()),2); e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0,4,0),gp.gp_Pnt(-4,4,0)).Edge(); e4 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(-4,4,0), gp.gp_Pnt(0,0,0)); return OCCUtil.wireFromEdges([e1,e2,e3,e4]);
def testBasicFaceOffset(): f = TestObjects.makeHeartFaceNoHole() startWires = OCCUtil.wireListFromFace(f) display.DisplayColoredShape(startWires, 'GREEN') cw = startWires for i in range(3): w = OCCUtil.offsetWireList(cw, -0.2) display.DisplayColoredShape(w, 'RED') cw = w
def makeWireFromPointList(points): edges = [] for (p, q) in Util.ntuples(points, 2, True): print p, q edges.append( OCCUtil.edgeFromTwoPoints(OCCUtil.pnt(p[0], p[1]), OCCUtil.pnt(q[0], q[1]))) return OCCUtil.wireFromEdges(edges)
def makeHeartWire(): "make a heart wire" e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 4.0, 0)) circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 4, 0), gp.gp().DZ()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4, 4, 0), gp.gp_Pnt(0, 4, 0)).Edge() circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2, 4, 0), gp.gp().DZ()), 2) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 4, 0), gp.gp_Pnt(-4, 4, 0)).Edge() e4 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(-4, 4, 0), gp.gp_Pnt(0, 0, 0)) return OCCUtil.wireFromEdges([e1, e2, e3, e4])
def makeHexArray(self, bottomLeftCenter, countX, countY): """ makes an array of hexagons bottomLeftCenter is the center of the top left hex, as a three-element tuple countX is the number of hexes in the x direction countY is the number of hexes in the y direction returns a list of wires representing a hexagon fill pattern """ pattern = self.makePeriodic(bottomLeftCenter) wireBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeWire(pattern) #make horizontal array tsf = gp.gp_Trsf() pDist = 2.0 * self.cartesianSpacing()[0] tsf.SetTranslation(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(pDist, 0, 0)) tx = BRepBuilderAPI.BRepBuilderAPI_Transform(tsf) currentShape = pattern for i in range(1, int((countX / 2) + 1)): tx.Perform(currentShape, False) currentShape = tx.Shape() #display.DisplayShape(currentShape); wireBuilder.Add(OCCUtil.cast(currentShape)) #create an array by alternately offsetting one cell right and #moving down topHalf = wireBuilder.Wire() #topHalf= approximatedWire(topHalf); wires = [] wires.append(topHalf) dY = self.cartesianSpacing()[1] / 2.0 dX = self.cartesianSpacing()[0] ####TODO// performance note. This method takes about 31ms to compute 1000x1000 hex. # pretty good, except that nearly 50% of the time is spent in makeTransform!!! # a much better method would be to use the same transform object somehow for i in range(1, int(countY * 2)): if i % 2 == 0: t = makeTransform(0, dY * i, 0) else: t = makeTransform(dX, dY * i, 0) t.Perform(topHalf, False) w = OCCUtil.cast(t.Shape()) #approximate the wire #wires.append ( approximatedWire(w)); wires.append(w) #display.DisplayShape(wires); return wires
def _makeHatchLines(self): """ make straight hatch lines. TODO: need to use fillAngle to rotate the lines as well. Trsf object """ xMin = self.bounds[0] - ( self.HATCH_PADDING); yMin = self.bounds[1] - ( self.HATCH_PADDING); xMax = self.bounds[2] + (self.HATCH_PADDING); yMax = self.bounds[3] + (self.HATCH_PADDING) ; wires = []; for y in Util.frange6(yMin,yMax,self.spacing): e = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(xMin,y,self.zLevel),gp.gp_Pnt(xMax,y,self.zLevel)); wires.append(OCCUtil.wireFromEdges([e])); return wires;
def getWires(self): q = time.clock() en = self.graphBuilder.walkEdges() #print "Walked Edges-- %d total paths, %0.3f sec" % (len(en), ( time.clock() - q ) ); wires = [] for path in en: wb = OCCUtil.WireBuilder() for edge in Util.pairwise(path): #each pair is a set of nodes that form an edge in the graph. We need to ge the OCC edges from each for occEdge in self.graphBuilder.getEdges(edge[0], edge[1]): wb.add(OCCUtil.cast(occEdge)) wires.append(wb.wire()) return wires
def _makeHatchLines(self): """ make straight hatch lines. TODO: need to use fillAngle to rotate the lines as well. Trsf object """ xMin = self.bounds[0] - (self.HATCH_PADDING) yMin = self.bounds[1] - (self.HATCH_PADDING) xMax = self.bounds[2] + (self.HATCH_PADDING) yMax = self.bounds[3] + (self.HATCH_PADDING) wires = [] for y in Util.frange6(yMin, yMax, self.spacing): e = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(xMin, y, self.zLevel), gp.gp_Pnt(xMax, y, self.zLevel)) wires.append(OCCUtil.wireFromEdges([e])) return wires
def build(self): wire = self.request.wire topoWire = Topo(wire) #get all the vertices for the wire #these are sorted by ascending distance choices = OCCUtil.nearestVertices([wire], self.request.startPoint, MAX_DISTANCE) #print "There are %d choices" % len(choices); bestSolution = None for (wire, vertex, point, distance) in choices: #print "vertex: distance %0.3f" % distance; sol = JoinAtVertex(self.request, vertex).compute() if distance < self.tolerance: #compute a joint solution based on this vertex if bestSolution is None: bestSolution = sol elif sol.isBetterThan(bestSolution): #print "switching solution to another vertex!" bestSolution = sol else: #all of the points below this one will be even less attractive, and #entry angle doesnt matter because we'll probably rapid there. Thus, #simply choose the next one if bestSolution: break else: sol.isJoint = False bestSolution = sol #at this point we have the best solution, which is either a joint to a vertex #with the best combination of angles, or we have a move to then nearest vertex bestSolution.buildWire() return bestSolution
def build(self): wire = self.request.wire topoWire = Topo(wire) # get all the vertices for the wire # these are sorted by ascending distance choices = OCCUtil.nearestVertices([wire], self.request.startPoint, MAX_DISTANCE) # print "There are %d choices" % len(choices); bestSolution = None for (wire, vertex, point, distance) in choices: # print "vertex: distance %0.3f" % distance; sol = JoinAtVertex(self.request, vertex).compute() if distance < self.tolerance: # compute a joint solution based on this vertex if bestSolution is None: bestSolution = sol elif sol.isBetterThan(bestSolution): # print "switching solution to another vertex!" bestSolution = sol else: # all of the points below this one will be even less attractive, and # entry angle doesnt matter because we'll probably rapid there. Thus, # simply choose the next one if bestSolution: break else: sol.isJoint = False bestSolution = sol # at this point we have the best solution, which is either a joint to a vertex # with the best combination of angles, or we have a move to then nearest vertex bestSolution.buildWire() return bestSolution
def makeSection2(self, cuttingPlane, shapeToSection, zLevel): """ Uses BrepSection Algo. this generally returns a list of wires, not a face """ #section is certainly faster, but produces only edges. #those have to be re-organized into wires, probably #using ShapeAnalysis_WireOrder face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI.BRepAlgoAPI_Section(self.solid.shape, face) #section = BRepAlgo.BRepAlgo_Section(self.solid.shape,face); section.Build() if section.IsDone(): #Topology.dumpTopology(section.Shape()); #what we got back was a compound of edges t = Topo(section.Shape()) wb = OCCUtil.MultiWireBuilder() for e in t.edges(): wb.addEdge(e) wires = wb.getWires() print wires for w in wires: Topology.dumpTopology(w) return wires else: raise Exception("Could not compute Section!")
def __init__(self, face): self.face = face self.originalWires = OCCUtil.wireListFromFace(face) self.edgeMap = {} self.otherWires = [] self.lastWires = self.originalWires self.display = None self.outputWires = []
def addBoundaryWire(self,wire): #for finding an edge node wr = Wrappers.Wire(wire); eS = wr.edgesAsSequence(); for i in range(1,eS.Length()+1): e = OCCUtil.cast(eS.Value(i)); self.addSingleBoundaryEdge(e);
def __init__(self,face): self.face= face; self.originalWires = OCCUtil.wireListFromFace(face); self.edgeMap = {}; self.otherWires = []; self.lastWires = self.originalWires; self.display = None; self.outputWires = [];
def _fillSlice(self, slice): #how many shells do we need? #attempt to create the number of shells requested by the user, plus one additional for infill for f in slice.faces: numShells = (int)(self.options.fillingWallThickness / self.extruder.trackWidth()) + 1 numShells = max(2, numShells) faceWires = OCCUtil.wireListFromFace(f.face) #regardless, the last successfully created offset is used for hatch infill shells = [] for i in range(1, numShells): #compute offset inwards by one track width offset = (-1) * i * self.extruder.trackWidth() innerEdge = OCCUtil.offsetWireList(faceWires, offset) if len(innerEdge) == 0: #performance: dont offset if there were already no wires continue pathCenter = OCCUtil.offsetWireList( innerEdge, self.extruder.trackWidth() / 2) if len(pathCenter) > 0: shells.append(pathCenter) if len(shells) > 1: #use last one for filling. print "%d shells were available for Hatching" % len(shells) lastShell = shells.pop() s = self.solid h = hatchlib.Hatcher(lastShell, zLevel, (s.xMin, s.yMin, s.xMax, s.yMax), self.extruder.trackWidth(), cSlice.fillAngle) h.hatch() ww = h.getWires() print "Hatching complete: %d fillWires created" % len(ww) f.fillWires = ww else: print "WARNING: not filling this layer, too few shells were computable" #add shells for s in shells: for ss in s: f.shellWires.append(ss)
def trimmedEdge(self,parameter1, parameter2): "make a trimmed edge based on a start and end parameter on the same curve" "p1 and p2 are either points or parameters" print "Computing new edge: p1=%0.3f, p2=%0.3f, fp=%0.3f, lp=%0.3f" % (parameter1,parameter2,self.firstParameter,self.lastParameter); if abs(parameter1 - parameter2) < 0.0001: print "WARNING: removing degenerate edge"; return None; e = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve, parameter1, parameter2 ); return e;
def offsetOnceSimple(self, distance): bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() map(bo.AddWire, self.lastWires) print "%d wires to offset at step 1, distance = %0.3f" % (len( self.lastWires), distance) bo.Perform(distance * (0.5), 0.0) result1 = Topo(bo.Shape()) returnList = [] #compound result can be a compound of edges and/or wires. weird weird for c in OCCUtil.childShapes(bo.Shape()): display.DisplayColoredShape(c, 'BLUE') if c.ShapeType() == TopAbs.TopAbs_WIRE: returnList.append(c) #these are actually the wires we want to keep elif c.ShapeType() == TopAbs.TopAbs_EDGE: w = OCCUtil.wireFromEdges([c]) returnList.append(w) else: print "Warning: compound resulting from offset i am confused about-- not an edge or a wire." #for each original edge, compute its descendant edges #self.edgeMap will contain entries with the original edges, pointing to the generated #edges and the corresponding wire: # e1 --> [ (e2, w2 ), (e3 , w3 ) ]; for w in self.lastWires: originalWire = Topo(w) for oe in originalWire.edges(): self.edgeMap[oe.__hash__()] = [] #find generated values from first transformation generatedStep1 = OCCUtil.listFromTopToolsListOfShape( bo.Generated(oe)) for ne in generatedStep1: #get wire this belongs to this returns a list but how could there ever be more than one? gwires = [] for g in result1.wires_from_edge(ne): gwires.append(g) self.edgeMap[oe.__hash__()].append((ne, gwires[0])) self.lastWires = returnList self.otherWires.extend(returnList) return returnList
def _compute(self): (p1,p,p2) = (self.p1,self.closestParam, self.p2); #p1 < p < p2 #i think this works well for small distance. not as well if d is large. if (p - p1) < (2.0)*self.distanceFromStartPoint: #TODO: this code is nearly same as the branch below but with p1 and p2 swapped, #connect to start vertex self.connectingPoint = self.edgeStart; self.connectingParm = p1; #compute shortened edge e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1+self.trackWidth,p2); self.otherEdges = [e1]; #enter the wire by connecting start to vertex directly self.connectingEdges = [ OCCUtil.edgeFromTwoPoints(self.startPoint,self.connectingPoint) ]; elif (p2 - p )< (2.0)*self.distanceFromStartPoint: #connect to end vertex self.connectingPoint = self.edgeEnd; self.connectingParm = p2; #compute shortened edge e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,p2-self.trackWidth); self.otherEdges = [e1]; #enter the wire by connecting start to vertex directly self.connectingEdges = [ OCCUtil.edgeFromTwoPoints(self.startPoint,self.connectingPoint) ]; else: #connect to middle of the edge self.connectingEdges = []; firstEdge = None; #which end is closer? if (p - p1) > (p2 - p ): #p2 is closer pTarget = p + (2.0)*self.distanceFromStartPoint; pEnd = pTarget - self.trackWidth; secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,pTarget,p2); self.otherEdges = [OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,pEnd) ]; else: #p1 is closer pTarget = p - (2.0)*self.distanceFromStartPoint; pEnd = pTarget + self.trackWidth; secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,pTarget); self.otherEdges = [OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,pEnd,p2) ]; self.connectingParam = pTarget; self.connectingPoint = self.curve.Value(pTarget); self.connectingEdges.append( OCCUtil.edgeFromTwoPoints(self.startPoint, self.connectingPoint)); self.connectingEdges.append(secondEdge);
def build(self): topoWire = Topo(self.wire) #compute closest point on the wire brp = BRepExtrema.BRepExtrema_DistShapeShape() brp.LoadS1(OCCUtil.make_vertex(self.startPoint)) brp.LoadS2(self.wire) result = brp.Perform() p1 = brp.PointOnShape2(1) wb = OCCUtil.WireBuilder() closestParam = None if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge interSectingEdge = OCCUtil.cast(brp.SupportOnShape2(1)) closestParam = brp.ParOnEdgeS2(1) else: #closest point is a point on a vertex, here we'll shorten one edge #in this case closest point is a vertex, so we dont have a param on an edge vertex = OCCUtil.cast(brp.SupportOnShape2(1)) edges = [] for e in topoWire.edges_from_vertex(vertex): edges.append(e) interSectingEdge = edges[0] #compute parameter along one curve #break the edge into two new edges. account for a split distance between them. ej = EdgeJoin(interSectingEdge, self.startPoint, self.trackWidth, closestParam) #add lead-in edges for e in ej.connectingEdges: wb.add(e) #now add all of the other edges in the wire except the original one that we split for e in topoWire.edges(): if not e.IsSame(interSectingEdge): wb.add(e) for e in ej.otherEdges: wb.add(e) return wb.wire()
def build(self): topoWire = Topo(self.wire); #compute closest point on the wire brp = BRepExtrema.BRepExtrema_DistShapeShape(); brp.LoadS1(OCCUtil.make_vertex(self.startPoint)); brp.LoadS2(self.wire); result = brp.Perform(); p1 = brp.PointOnShape2(1); wb = OCCUtil.WireBuilder(); closestParam = None; if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge interSectingEdge = OCCUtil.cast(brp.SupportOnShape2(1)); closestParam = brp.ParOnEdgeS2(1); else: #closest point is a point on a vertex, here we'll shorten one edge #in this case closest point is a vertex, so we dont have a param on an edge vertex = OCCUtil.cast(brp.SupportOnShape2(1)); edges = []; for e in topoWire.edges_from_vertex(vertex): edges.append(e); interSectingEdge = edges[0]; #compute parameter along one curve #break the edge into two new edges. account for a split distance between them. ej = EdgeJoin(interSectingEdge,self.startPoint,self.trackWidth ,closestParam); #add lead-in edges for e in ej.connectingEdges: wb.add(e); #now add all of the other edges in the wire except the original one that we split for e in topoWire.edges(): if not e.IsSame(interSectingEdge): wb.add(e); for e in ej.otherEdges: wb.add(e); return wb.wire();
def trimmedEdge(self, parameter1, parameter2): "make a trimmed edge based on a start and end parameter on the same curve" "p1 and p2 are either points or parameters" print "Computing new edge: p1=%0.3f, p2=%0.3f, fp=%0.3f, lp=%0.3f" % ( parameter1, parameter2, self.firstParameter, self.lastParameter) if abs(parameter1 - parameter2) < 0.0001: print "WARNING: removing degenerate edge" return None e = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve, parameter1, parameter2) return e
def _fillSlice(self, slice): # how many shells do we need? # attempt to create the number of shells requested by the user, plus one additional for infill for f in slice.faces: numShells = (int)(self.options.fillingWallThickness / self.extruder.trackWidth()) + 1 numShells = max(2, numShells) faceWires = OCCUtil.wireListFromFace(f.face) # regardless, the last successfully created offset is used for hatch infill shells = [] for i in range(1, numShells): # compute offset inwards by one track width offset = (-1) * i * self.extruder.trackWidth() innerEdge = OCCUtil.offsetWireList(faceWires, offset) if len(innerEdge) == 0: # performance: dont offset if there were already no wires continue pathCenter = OCCUtil.offsetWireList(innerEdge, self.extruder.trackWidth() / 2) if len(pathCenter) > 0: shells.append(pathCenter) if len(shells) > 1: # use last one for filling. print "%d shells were available for Hatching" % len(shells) lastShell = shells.pop() s = self.solid h = hatchlib.Hatcher( lastShell, zLevel, (s.xMin, s.yMin, s.xMax, s.yMax), self.extruder.trackWidth(), cSlice.fillAngle ) h.hatch() ww = h.getWires() print "Hatching complete: %d fillWires created" % len(ww) f.fillWires = ww else: print "WARNING: not filling this layer, too few shells were computable" # add shells for s in shells: for ss in s: f.shellWires.append(ss)
def displayAllEdgesAndVertices(g): i = 0 for en in g.edges_iter(data=True): i += 1 displayEdgeFromGraph(en[2]) print "%d edges total" % i i = 0 for n in g.nodes_iter(): i += 1 p = gp.gp_Pnt(n[0], n[1], 0) display.DisplayShape(OCCUtil.make_vertex(p), update=False) print "%d nodes total" % i
def makeEdgeIndicator(edge): "makes an indicator showing which way the edge goes" ew = Wrappers.Edge(edge); fp = ew.firstParameter; lp = ew.lastParameter; if ew.reversed: p = fp + (( lp - fp ) * 1 / 5 ); else: p = fp + ((lp - fp) * 4 /5 ); midPnt = ew.curve.Value(p); return OCCUtil.make_vertex(midPnt);
def makeEdgeIndicator(edge): "makes an indicator showing which way the edge goes" ew = Wrappers.Edge(edge) fp = ew.firstParameter lp = ew.lastParameter if ew.reversed: p = fp + ((lp - fp) * 1 / 5) else: p = fp + ((lp - fp) * 4 / 5) midPnt = ew.curve.Value(p) return OCCUtil.make_vertex(midPnt)
def buildWire(self): #simply do the work of the trimming and construction. wB = OCCUtil.WireBuilder() wire = self.jointRequest.wire tw = Topo(wire) edgeToTrim = self.pointOnEdge.edge #shorten the selected edge #TODO: maybe simplify this to return pointOnEdge? (self.trimmedEdge, self.trimmedPoint, self.trimmedVec) = OCCUtil.shortenEdge(edgeToTrim, self.pointOnEdge.point, self.trimDistance) wB.add(self.trimmedEdge) #add the edges we didnt touch for e in tw.edges(): if not e.IsSame(edgeToTrim): wB.add(e) self.wire = wB.wire()
def displayAllEdgesAndVertices(g): i=0; for en in g.edges_iter(data=True): i+=1; displayEdgeFromGraph(en[2]) print "%d edges total" % i i=0 for n in g.nodes_iter(): i+=1; p = gp.gp_Pnt(n[0],n[1],0); display.DisplayShape(OCCUtil.make_vertex(p),update=False); print "%d nodes total" % i
def trimmedEdgeFromPoints(self, point1, point2, tolerance): print "I am %s" % self print "Creating new edge from points: ", Point(point1), Point(point2) #(param1,newPoint1) = OCCUtil.findPointOnCurve(point1,self.handleCurve,tolerance); #(param2,newPoint2) = OCCUtil.findPointOnCurve(point2,self.handleCurve,tolerance); #well this is annoying-- the parameter range appears to be preventing projection, so we need to pad them fp = self.firstParameter fpnt = self.firstPoint lp = self.lastParameter lpnt = self.lastPoint if fp > lp: (lp, fp) = (fp, lp) (fpnt, lpnt) = (lpnt, fpnt) print "Params: fp=%0.3f, lp=%0.3f,tolerance=%0.3f" % (fp, lp, tolerance) (param1, newPoint1) = OCCUtil.findPointOnCurve(point1, self.handleCurve, tolerance) #check bounds by hand if param1 < fp: param1 = fp newPoint1 = fpnt if param1 > lp: parm1 = fp newPoint1 = lpnt print "point 1!" (param2, newPoint2) = OCCUtil.findPointOnCurve(point2, self.handleCurve, tolerance) if param2 < fp: param2 = fp newPoint2 = fpnt if param2 > lp: parm2 = fp newPoint2 = lpnt return self.trimmedEdge(param1, param2)
def TestWireJoiner(): wire = TestObjects.makeOffsetTestWire() conditions = [] #each test condition is two points, representing an edge #that was drawn last. #in these tests, the red curve is the trimmed one, and the green is the original. #the yellow markers on the leadin edges and the joining segment is closer to the end #in each case, the solution found should minimize overlap and trim the other edge #as necessary. conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0))) conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) for (startPoint, endPoint) in conditions: display.EraseAll() display.DisplayColoredShape(wire, 'GREEN') initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint) display.DisplayColoredShape( OCCUtil.edgeFromTwoPoints(startPoint, endPoint), 'BLUE') display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector)) vec = gp.gp_Vec(startPoint, endPoint) jrequest = JointRequest(endPoint, vec, 0.8, wire) wj = WireJoiner(jrequest, 4.0) #this is a huge tolerance, but helps for testing solution = wj.build() display.DisplayColoredShape(solution.wire, 'RED') entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint) display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge)) if solution.isJoint: display.DisplayColoredShape(entryEdge, 'WHITE') else: display.DisplayColoredShape(entryEdge, 'YELLOW') time.sleep(5)
def TestWireJoiner(): wire = TestObjects.makeOffsetTestWire() conditions = [] # each test condition is two points, representing an edge # that was drawn last. # in these tests, the red curve is the trimmed one, and the green is the original. # the yellow markers on the leadin edges and the joining segment is closer to the end # in each case, the solution found should minimize overlap and trim the other edge # as necessary. conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0))) conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0))) conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0))) for (startPoint, endPoint) in conditions: display.EraseAll() display.DisplayColoredShape(wire, "GREEN") initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint) display.DisplayColoredShape(OCCUtil.edgeFromTwoPoints(startPoint, endPoint), "BLUE") display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector)) vec = gp.gp_Vec(startPoint, endPoint) jrequest = JointRequest(endPoint, vec, 0.8, wire) wj = WireJoiner(jrequest, 4.0) # this is a huge tolerance, but helps for testing solution = wj.build() display.DisplayColoredShape(solution.wire, "RED") entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint) display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge)) if solution.isJoint: display.DisplayColoredShape(entryEdge, "WHITE") else: display.DisplayColoredShape(entryEdge, "YELLOW") time.sleep(5)
def distToPoint( wire, vertex): brp = BRepExtrema.BRepExtrema_DistShapeShape(); brp.LoadS1(vertex); brp.LoadS2(wire); result = brp.Perform(); if result: if brp.NbSolution() > 1: print "weird, more than one solution" point = brp.PointOnShape2(1); #otherwise, figure out what kind of location we have. if brp.SupportTypeShape2(1) == BRepExtrema.BRepExtrema_IsOnEdge: #closest point is a point along an edge edge = OCCUtil.cast(brp.SupportOnShape2(1)); parameter = brp.ParOnEdgeS2(1); #print "Closest point is on an edge" else: #closest point is a point on a vertex vertex = OCCUtil.cast(brp.SupportOnShape2(1)); #print "closest point is on vertex" return point;
def getWires(self): q = time.clock(); en = self.graphBuilder.walkEdges(); #print "Walked Edges-- %d total paths, %0.3f sec" % (len(en), ( time.clock() - q ) ); wires = []; for path in en: wb = OCCUtil.WireBuilder(); for edge in Util.pairwise(path): #each pair is a set of nodes that form an edge in the graph. We need to ge the OCC edges from each for occEdge in self.graphBuilder.getEdges(edge[0],edge[1]): wb.add( OCCUtil.cast(occEdge) ); wires.append(wb.wire() ); return wires;
def getPointAtVertex(self, vertex): p = brepTool.Parameter(vertex, self.edge) r = PointOnEdge() r.param = p r.vertex = vertex r.edge = self.edge (r.point, r.vector) = OCCUtil.D1AtPointOnCurve(self.curve, p) #tricky-- reverse the vector if the edge is reversed if self.reversed: r.vector = r.vector.Reversed() r.niceVec = Vec(r.vector) r.nicePoint = Pnt(r.point) return r
def testLineDirection(): p1 = gp.gp_Pnt(0,0,0); p2 = gp.gp_Pnt(1,0,0); p3 = gp.gp_Pnt(-1,0,0); e1 = OCCUtil.edgeFromTwoPoints(p1,p2); e2 = OCCUtil.edgeFromTwoPoints(p1,p3); (hCurve1, startp1, endp1) = brepTool.Curve(e1); (hCurve2, startp2, endp2) = brepTool.Curve(e2); curve1 = hCurve1.GetObject(); q1 = gp.gp_Pnt(); v1 = gp.gp_Vec(); q2 = gp.gp_Pnt(); v2 = gp.gp_Vec(); curve1 = GeomAdaptor.GeomAdaptor_Curve(hCurve1); curve2 = GeomAdaptor.GeomAdaptor_Curve(hCurve2); curve1.D1(endp1,q1,v1); curve2.D1(endp2,q2,v2); print v2.Angle(v1); print v1.Magnitude(),v1.X(), v1.Y(), v1.Z(); print v2.Magnitude(),v2.X(), v2.Y(), v2.Z();
def testLineDirection(): p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(1, 0, 0) p3 = gp.gp_Pnt(-1, 0, 0) e1 = OCCUtil.edgeFromTwoPoints(p1, p2) e2 = OCCUtil.edgeFromTwoPoints(p1, p3) (hCurve1, startp1, endp1) = brepTool.Curve(e1) (hCurve2, startp2, endp2) = brepTool.Curve(e2) curve1 = hCurve1.GetObject() q1 = gp.gp_Pnt() v1 = gp.gp_Vec() q2 = gp.gp_Pnt() v2 = gp.gp_Vec() curve1 = GeomAdaptor.GeomAdaptor_Curve(hCurve1) curve2 = GeomAdaptor.GeomAdaptor_Curve(hCurve2) curve1.D1(endp1, q1, v1) curve2.D1(endp2, q2, v2) print v2.Angle(v1) print v1.Magnitude(), v1.X(), v1.Y(), v1.Z() print v2.Magnitude(), v2.X(), v2.Y(), v2.Z()
def buildGraph(self): g = self.graph; #add fill edge nodes first for e in self.fillEdges: g.add_edge(e[0], e[1], {"type":'FILL', "edgeList":e[2]}); #add boundary nodes. for (edge, pointList ) in self.boundaryEdges.iteritems(): #sort the points by parameter sortedPoints = sorted(pointList,key = lambda p: p.param ); for (poe1,poe2) in Util.pairwise(sortedPoints): #dont add if there is already an edge if not g.has_edge(poe1.node,poe2.node): #here we need to trim each edge to limit it to the desired parameters g.add_edge(poe1.node,poe2.node,{"type":"BOUND", "edge": OCCUtil.trimmedEdge(edge,poe1.param,poe2.param)});
def approximatedWire(wire): "returns a bezier approximation of the specified wire as an edge" #make a parameterized approximation of the wire adaptor = BRepAdaptor.BRepAdaptor_CompCurve(wire) curve = BRepAdaptor.BRepAdaptor_HCompCurve(adaptor) curveHandle = curve.GetHandle() #approximate the curve using a tolerance approx = Approx.Approx_Curve3d(curveHandle, 0.01, GeomAbs.GeomAbs_C2, 1000, 8) if approx.IsDone() and approx.HasResult(): # have the result anApproximatedCurve = approx.Curve() builder = BRepLib.BRepLib_MakeEdge(anApproximatedCurve) e = builder.Edge() return OCCUtil.wireFromEdges([e])
def computeBounds(self): "Get the bounds of all the faces" if self.bounds == None: box = Bnd.Bnd_Box() b = BRepBndLib.BRepBndLib() for f in OCCUtil.hSeqIterator(s.faces): b.Add(f, box) bounds = box.Get() xMin = bounds[0] xMax = bounds[3] yMin = bounds[1] yMax = bounds[4] zMin = bounds[2] zMax = bounds[5] self.bounds = [xMin, xMax, yMin, yMax, zMin, zMax] return self.bounds
def buildWire(self): # simply do the work of the trimming and construction. wB = OCCUtil.WireBuilder() wire = self.jointRequest.wire tw = Topo(wire) edgeToTrim = self.pointOnEdge.edge # shorten the selected edge # TODO: maybe simplify this to return pointOnEdge? (self.trimmedEdge, self.trimmedPoint, self.trimmedVec) = OCCUtil.shortenEdge( edgeToTrim, self.pointOnEdge.point, self.trimDistance ) wB.add(self.trimmedEdge) # add the edges we didnt touch for e in tw.edges(): if not e.IsSame(edgeToTrim): wB.add(e) self.wire = wB.wire()
def makeSection(self, cuttingPlane, shapeToSection, zLevel): """ Uses halfspaces to make a cut. """ bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane) face = bff.Face() origin = gp.gp_Pnt(0, 0, zLevel - 1) # odd, a halfspace is faster than a box? hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin) hs.Build() halfspace = hs.Solid() # make the cut bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape, halfspace) cutShape = bc.Shape() ff = [] for face in Topo(cutShape).faces(): if OCCUtil.isFaceAtZLevel(zLevel, face): ff.append(face) return ff
def addFillEdges(self,edgeList): if len(edgeList) == 1: (f,l) = brepTool.Range(edgeList[0]); p1 = tP( OCCUtil.pointAtParameter( edgeList[0],f)); p2 = tP( OCCUtil.pointAtParameter( edgeList[0],l)); else: firstEdge = edgeList[0]; lastEdge = edgeList[-1]; (f,l) = brepTool.Range(firstEdge); (n,m) = brepTool.Range(lastEdge); if firstEdge.Orientation() == TopAbs.TopAbs_FORWARD: p1 = tP( OCCUtil.pointAtParameter( firstEdge,f)); else: p1 = tP( OCCUtil.pointAtParameter ( firstEdge,l)); if lastEdge.Orientation() == TopAbs.TopAbs_FORWARD: p2 = tP(OCCUtil.pointAtParameter(lastEdge,m )); else: p2 = tP(OCCUtil.pointAtParameter(lastEdge,n )); self.fillEdges.append( (p1,p2,edgeList )); #would be nice if edge lists and edges looked the same
def makeOffsetTestWire(): "creates difficult test cases for offsetting" p1 = OCCUtil.pnt(11.0,0); p2 = OCCUtil.pnt(7.0,8.0); p3 = OCCUtil.pnt(7.0,12.0); p4 = OCCUtil.pnt(17.0,22.0); p5 = OCCUtil.pnt(0.0,22.0); p6 = OCCUtil.pnt(3.0,17.0); p7 = OCCUtil.pnt(4.0,8.0 ); c1 = OCCUtil.pnt(10.0,18.5); c2 = OCCUtil.pnt(6.0,3.0); edges = []; edges.append( OCCUtil.edgeFromTwoPoints( p1, p2 )); edges.append( OCCUtil.edgeFromTwoPoints( p2, p3 )); circle = GC.GC_MakeArcOfCircle(p3, c1, p4); #circle through 3 points e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge(); edges.append(e2); edges.append( OCCUtil.edgeFromTwoPoints( p4, p5 )); edges.append( OCCUtil.edgeFromTwoPoints( p5, p6 )); edges.append( OCCUtil.edgeFromTwoPoints( p6, p7 )); circle = GC.GC_MakeArcOfCircle(p1, c2, p7 ); #circle through 3 points e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value() ).Edge(); edges.append(e3); return OCCUtil.wireFromEdges(edges);