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 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 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