Beispiel #1
0
    def curve_of_wire(wire):
        """
        Get the curve of the wire. The edges are concatenated so the
        resulting curve may be C0 continuous.

        :param OCCT.TopoDS.TopoDS_Wire wire: The wire.

        :return: Concatenated curve of wire.
        :rtype: OCCT.Geom.Geom_BSplineCurve

        :raise RuntimeError: If an unsupported curve type is found.
        """
        geom_convert = GeomConvert_CompCurveToBSplineCurve()
        exp = BRepTools_WireExplorer(wire)
        tol = ExploreShape.global_tolerance(wire, 1)
        while exp.More():
            e = TopoDS.Edge_(exp.Current())
            exp.Next()
            adp_crv = BRepAdaptor_Curve(e)
            geom_convert.Add(adp_crv.BSpline(), tol)
        crv = geom_convert.BSplineCurve()
        if not isinstance(crv, Geom_BSplineCurve):
            msg = 'Unsupported curve type.'
            raise RuntimeError(msg)
        return crv
Beispiel #2
0
    def __init__(self, wire, face=None):
        if face is None:
            explorer = BRepTools_WireExplorer(wire)
        else:
            explorer = BRepTools_WireExplorer(wire, face)

        edges = []
        current_verts = []
        while explorer.More():
            ei = TopoDS.Edge_(explorer.Current())
            vi = TopoDS.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:
            data = ShapeExtend_WireData(wire)
            fix = ShapeFix_WireSegment(data)
            v1 = fix.LastVertex()
            ordered_verts.append(v1)

        self._edges = edges
        self._current_verts = current_verts
        self._ordered_verts = ordered_verts
Beispiel #3
0
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)
Beispiel #4
0
 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)
Beispiel #5
0
    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
Beispiel #6
0
    def _loop_topo(self, edges=True):
        wexp = self.wire_explorer = BRepTools_WireExplorer(self.wire)

        items = set()  # list that stores hashes to avoid redundancy
        occ_seq = TopTools_ListOfShape()

        get_current = wexp.Current if edges else wexp.CurrentVertex

        while wexp.More():
            current_item = get_current()
            if current_item not in items:
                items.add(current_item)
                occ_seq.Append(current_item)
            wexp.Next()

        # Convert occ_seq to python list
        seq = []
        topology_type = TopoDS.Edge_ if edges else TopoDS.Vertex_
        occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq)
        while occ_iterator.More():
            topo_to_add = topology_type(occ_iterator.Value())
            seq.append(topo_to_add)
            occ_iterator.Next()
        return seq
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
Beispiel #8
0
 def _reinitialize(self):
     self.wire_explorer = BRepTools_WireExplorer(self.wire)
     self.done = False
Beispiel #9
0
 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