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 offsetWireList(wireList, offsetAmount): if len(wireList) == 0: print "Warning: zero wires in the shape-- skipping" return [] bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() for w in wireList: bo.AddWire(w) bo.Perform(offsetAmount, 0.0) #if this crashes, try using a small non zero number for the last argument if not bo.IsDone(): print "Warning: offset not computed!" return None else: #make sure to return a list of wires also, since we got one in returnWires = [] shape = bo.Shape() if shape.ShapeType() == TopAbs.TopAbs_WIRE: returnWires.append(cast(shape)) elif shape.ShapeType() == TopAbs.TopAbs_COMPOUND: bb = TopExp.TopExp_Explorer() bb.Init(shape, TopAbs.TopAbs_WIRE) while bb.More(): w = topoDS.wire(bb.Current()) returnWires.append(cast(w)) bb.Next() bb.ReInit() return returnWires
def offset2dWire(wire, distance): bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(wire) bo.Perform(distance, 0.0) #this line crashes hard, but only sometimes. #print "done offsetting.."; if not bo.IsDone(): raise Exception, "Offset Was Not Successful." else: return bo.Shape()
def offsetWire(wire, offsetAmount): TOLERANCE = 0.0005 #print wire; bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset(wire, GeomAbs.GeomAbs_Line) #bo.AddWire(wire); #print "about to offset by %0.2f" % offset; bo.Perform(offsetAmount, TOLERANCE) #this line crashes hard, but only sometimes. #print "done offsetting.."; if not bo.IsDone(): raise Exception, "Offset Was Not Successful." else: return bo.Shape()
def offsetFace(face, offset): ow = brt.OuterWire(face) bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(ow) for w in Topo(face).wires(): if not w.IsSame(ow): #TestDisplay.display.showShape(w); bo.AddWire(w) #print "about to offset by %0.2f" % offset; bo.Perform(offset, 0.0) #this line crashes hard, but only sometimes. #print "done offsetting.."; bo.Check() return bo.Shape()
def _offsetFace(self, face, offset): ow = brt.OuterWire(face) bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(ow) for w in Topo(face).wires(): if not w.IsSame(ow): #TestDisplay.display.showShape(w); bo.AddWire(w) #print "about to offset by %0.2f" % offset; bo.Perform(offset, TOLERANCE) #this line crashes hard, but only sometimes. #print "done offsetting.."; if not bo.IsDone(): raise Exception, "Offset Was Not Successful." else: return bo.Shape()
def offsetFace(face, offsetAmount): ow = brt.OuterWire(face) bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(ow) for w in Topo(face).wires(): if not w.IsSame(ow): bo.AddWire(w) print "about to offset by %0.2f" % offsetAmount bo.Perform(offsetAmount, TOLERANCE) #this line crashes hard, but only sometimes. #print "done offsetting.."; if not bo.IsDone(): print "Warning: offset not computed!" return None else: return bo.Shape()
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 testOffsetReferences(): ow = makeHeartWire() bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset() bo.AddWire(ow) TestDisplay.display.showShape(ow) bo.Perform(-0.01, 0.0) newWire = bo.Shape() TestDisplay.display.showShape(newWire) #now see if we can figure out which edge in the new wire goes with which for oldEdge in Topo(ow).edges(): listOfShape = bo.Generated(oldEdge) #listOfShape is TopTools.TopTools_ListOfShape newEdge = listOfShape.First() print "Old EdgeID is %d, New EdgeId is %d" % (oldEdge.__hash__(), newEdge.__hash__())
verts1 = [MakeVertex(pt) for pt in points1] edges1 = [MakeEdge(v1, v2) for v1, v2 in pairs(verts1)] edges1.append(MakeEdge(verts1[-1], verts1[0])) wire1 = MakeWire(edges1) points2 = [ (-1, -1, 4), (1, -1, 4), #(1.3,0,4), (1, 1, 4), (-1, 1, 4) ] verts2 = [MakeVertex(pt) for pt in points2] edges2 = [MakeEdge(v1, v2) for v1, v2 in pairs(verts2)] edges2.append(MakeEdge(verts2[-1], verts2[0])) wire2 = MakeWire(edges2) section = BRepOffsetAPI.BRepOffsetAPI_ThruSections(True) section.AddVertex(MakeVertex((0, 0, -1)).Vertex()) section.AddWire(wire1.Wire()) section.AddWire(wire2.Wire()) section.AddVertex(MakeVertex((0, 0, 5)).Vertex()) view(section.Shape())
spine = MakeWire(edges) s = 0.2 pts = [(-s, s, 0), (s, s, 0), (s, -s, 0), (-s, -s, 0)] vs = [MakeVertex(p) for p in pts] vs.append(vs[0]) es = [MakeEdge(v1, v2) for v1, v2 in pairs(vs)] ws = MakeWire(es) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(ws.Wire()) #pipe = BRepOffsetAPI.BRepOffsetAPI_MakeEvolved(face.Face(), spine.Wire(), # 3) #pipe.SetMode(gp.gp_Dir(0,0,1)) #pipe.Add(ws.Shape(), False, True) pipe = BRepOffsetAPI.BRepOffsetAPI_MakePipe(spine.Wire(), face.Shape()) display.DisplayShape(pipe.Shape()) display.FitAll() start_display() print "end" #step_export = STEPControl.STEPControl_Writer() #step_export.Transfer(pipe.Shape(), STEPControl.STEPControl_AsIs) #step_export.Write("/home/bryan/test_pipe.stp")