def edges(self) -> List[BRepEdge]: edges = [] explorer = BRepTools_WireExplorer(self.loop) while explorer.More(): edge = explorer.Current() edges.append(BRepEdge(edge)) explorer.Next() return edges
def vertices(self) -> List[BRepVertex]: vertices = [] explorer = BRepTools_WireExplorer(self.loop) while explorer.More(): vertex = explorer.CurrentVertex() vertices.append(BRepVertex(vertex)) explorer.Next() return vertices
class WireExplorer(object): ''' Wire traversal ''' def __init__(self, wire): assert isinstance(wire, TopoDS_Wire), 'not a TopoDS_Wire' self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self): self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _loop_topo(self, edges=True): if self.done: self._reinitialize() topologyType = topods_Edge if edges else topods_Vertex seq = [] hashes = [] # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() current_item_hash = current_item.__hash__() if not current_item_hash in hashes: hashes.append(current_item_hash) occ_seq.Append(current_item) self.wire_explorer.Next() # Convert occ_seq to python list occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = topologyType(occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() self.done = True return iter(seq) def ordered_edges(self): return self._loop_topo(edges=True) def ordered_vertices(self): return self._loop_topo(edges=False)
def curve(self): """ :return: The curve formed by concatenating all the underlying curves of the edges. :rtype: afem.geometry.entities.NurbsCurve """ geom_convert = GeomConvert_CompCurveToBSplineCurve() exp = BRepTools_WireExplorer(self.object) tol = self.tol_max while exp.More(): e = TopoDS.Edge_(exp.Current()) exp.Next() adp_crv = BRepAdaptor_Curve(e) geom_convert.Add(adp_crv.BSpline(), tol) geom_curve = geom_convert.BSplineCurve() return Curve.wrap(geom_curve)
class WireExplorer: ''' Wire traversal ''' def __init__(self, wire): if not isinstance(wire, TopoDS_Wire): raise AsssertionError('not a TopoDS_Wire') self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self): self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _loop_topo(self, edges=True): if self.done: self._reinitialize() topologyType = topods_Edge if edges else topods_Vertex seq = [] occ_seq = [] while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() occ_seq.append(current_item) self.wire_explorer.Next() # Convert occ_seq to python list for elem in occ_seq: topo_to_add = topologyType(elem) seq.append(topo_to_add) self.done = True return iter(seq) def ordered_edges(self): return self._loop_topo(edges=True) def ordered_vertices(self): return self._loop_topo(edges=False)
def getTestFace(): P1 = gp_Pnt(0., 0., 0.) P12 = gp_Pnt(0., 2., 2.) P2 = gp_Pnt(0., 10., 0.) P3 = gp_Pnt(0., 10., 10.) P4 = gp_Pnt(0., 0., 10.) P5 = gp_Pnt(5., 5., 5.) SceneDrawPoint('p1', P1) SceneDrawPoint('p12', P12) SceneDrawPoint('p2', P2) SceneDrawPoint('p3', P3) SceneDrawPoint('p4', P4) SceneDrawPoint('p5', P5) W = BRepBuilderAPI_MakePolygon() W.Add(P1) W.Add(P12) W.Add(P2) W.Add(P3) W.Add(P4) W.Add(P1) SceneDrawShape('w', W.Shape()) # Initialize a BuildPlateSurface BPSurf = GeomPlate_BuildPlateSurface(3, 15, 2) # Create the curve constraints anExp = BRepTools_WireExplorer() anExp.Init(W.Wire()) while anExp.More(): E = anExp.Current() C = BRepAdaptor_HCurve() C.ChangeCurve().Initialize(E) Cont = BRepFill_CurveConstraint(C, 0) BPSurf.Add(Cont) anExp.Next() # Point constraint PCont = GeomPlate_PointConstraint(P5, 0) BPSurf.Add(PCont) # Compute the Plate surface BPSurf.Perform() # Approximation of the Plate surface MaxSeg = 9 MaxDegree = 8 CritOrder = 0 PSurf = BPSurf.Surface() dmax = max(0.0001, 10 * BPSurf.G0Error()) Tol = 0.0001 Mapp = GeomPlate_MakeApprox(PSurf, Tol, MaxSeg, MaxDegree, dmax, CritOrder) Surf = Mapp.Surface() # create a face corresponding to the approximated Plate Surface Umin, Umax, Vmin, Vmax = PSurf.Bounds() #MF = BRepBuilderAPI_MakeFace (Surf, Umin, Umax, Vmin, Vmax, Tol) MF = BRepBuilderAPI_MakeFace(Surf, Tol) return MF
class WireExplorer: """ Wire traversal """ def __init__(self, wire: TopoDS_Wire) -> None: if not isinstance(wire, TopoDS_Wire): raise AssertionError("not a TopoDS_Wire") self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self) -> None: self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _loop_topo(self, edges: Optional[bool] = True) -> Iterator[Any]: if self.done: self._reinitialize() topology_type = topods_Edge if edges else topods_Vertex seq = [] while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() seq.append(topology_type(current_item)) self.wire_explorer.Next() self.done = True return iter(seq) def ordered_edges(self) -> Iterator[TopoDS_Edge]: return self._loop_topo(edges=True) def ordered_vertices(self) -> Iterator[TopoDS_Vertex]: return self._loop_topo(edges=False)
def __init__(self, wire, face=None): if face is None: explorer = BRepTools_WireExplorer(wire.object) else: explorer = BRepTools_WireExplorer(wire.object, face.object) edges = [] current_verts = [] while explorer.More(): ei = Edge(explorer.Current()) vi = Vertex(explorer.CurrentVertex()) edges.append(ei) current_verts.append(vi) explorer.Next() # CurrentVertex doesn't get the last vertex. Try to get it. ordered_verts = list(current_verts) if edges: vi = Vertex(explorer.CurrentVertex()) ordered_verts.append(vi) self._edges = edges self._current_verts = current_verts self._ordered_verts = ordered_verts
def _reinitialize(self): self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False
def __init__(self, wire): assert isinstance(wire, TopoDS_Wire), 'not a TopoDS_Wire' self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False
def __init__(self, wire): if not isinstance(wire, TopoDS_Wire): raise AsssertionError('not a TopoDS_Wire') self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False
def getWireStartPointAndTangentDir(aWire): ex = BRepTools_WireExplorer(aWire) edge = ex.Current() vertex = ex.CurrentVertex() v = getVectorTangentToCurveAtPoint(edge, 0) return BRep_Tool.Pnt(vertex), gp_Dir(v)
def cut_out(base): outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter) inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter) geom_outer = GCE2d_MakeCircle(outer).Value() geom_inner = GCE2d_MakeCircle(inner).Value() geom_inner.Reverse() base_angle = (2. * M_PI) / mounting_hole_count hole_angle = atan(hole_radius / mounting_radius) correction_angle = 3 * hole_angle left = gp_Lin2d(gp_Origin2d(), gp_DX2d()) right = gp_Lin2d(gp_Origin2d(), gp_DX2d()) left.Rotate(gp_Origin2d(), correction_angle) right.Rotate(gp_Origin2d(), base_angle - correction_angle) geom_left = GCE2d_MakeLine(left).Value() geom_right = GCE2d_MakeLine(right).Value() inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left) inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right) inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right) inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left) if inter_1.Point(1).X() > 0: p1 = inter_1.Point(1) else: p1 = inter_1.Point(2) if inter_2.Point(1).X() > 0: p2 = inter_2.Point(1) else: p2 = inter_2.Point(2) if inter_3.Point(1).X() > 0: p3 = inter_3.Point(1) else: p3 = inter_3.Point(2) if inter_4.Point(1).X() > 0: p4 = inter_4.Point(1) else: p4 = inter_4.Point(2) trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value() trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value() plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0), gp_Pnt(p3.X(), p3.Y(), 0)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p1.X(), p1.Y(), 0)).Edge() cutout_wire = BRepBuilderAPI_MakeWire(arc1) cutout_wire.Add(lin1) cutout_wire.Add(arc2) cutout_wire.Add(lin2) # Turn the wire into a face cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire()) filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face()) explorer = BRepTools_WireExplorer(cutout_wire.Wire()) while explorer.More(): vertex = explorer.CurrentVertex() filleted_face.AddFillet(vertex, roller_radius) explorer.Next() cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(), gp_Vec(0.0, 0.0, thickness)).Shape() result = base rotate = gp_Trsf() for i in range(0, mounting_hole_count): rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count) rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True) result = BRepAlgoAPI_Cut(result, rotated_cutout.Shape()).Shape() return result