Ejemplo n.º 1
0
 def __init__(self, shape):
     tool = ShapeAnalysis_FreeBounds(shape.object)
     closed_wires = Compound(tool.GetClosedWires())
     open_wires = Compound(tool.GetOpenWires())
     self._closed_wires = closed_wires.wires
     self._open_wires = open_wires.wires
     self._edges = closed_wires.edges + open_wires.edges
Ejemplo n.º 2
0
 def __init__(self, shape):
     tool = ShapeAnalysis_FreeBounds(shape)
     cmp_closed_wires = tool.GetClosedWires()
     cmp_open_wires = tool.GetOpenWires()
     self._closed_wires = ExploreShape.get_wires(cmp_closed_wires)
     self._open_wires = ExploreShape.get_wires(cmp_open_wires)
     self._edges = (ExploreShape.get_edges(cmp_closed_wires) +
                    ExploreShape.get_edges(cmp_open_wires))
Ejemplo n.º 3
0
def load_dxf(filename):
    doc = ezdxf.readfile(filename)
    edges = TopTools_HSequenceOfShape()

    for element in doc.modelspace():
        dxf_type = element.dxftype()
        d = element.dxf
        if dxf_type == 'LINE':
            node = Segment(points=[d.start, d.end]).render()
        elif dxf_type == 'ARC':
            node = Arc(position=d.center,
                       radius=d.radius,
                       alpha1=radians(d.start_angle),
                       alpha2=radians(d.end_angle)).render()
        elif dxf_type == 'CIRCLE':
            node = Circle(radius=d.radius, position=d.center).render()
        else:
            log.warning(f"Unhandled element: {element}")
            continue
        edges.Append(node)

    wires = ShapeAnalysis_FreeBounds.ConnectEdgesToWires_(edges, 1e-6, False)

    builder = BRep_Builder()
    shape = TopoDS_Compound()
    builder.MakeCompound(shape)

    for i in range(1, wires.Size() + 1):
        builder.Add(shape, wires.Value(i))

    return [TopoShape(shape=shape)]
Ejemplo n.º 4
0
    def __init__(self, edges, tol=None, shared=False):
        # Build
        hedges = TopTools_HSequenceOfShape()
        for e in edges:
            hedges.Append(e.object)

        if tol is None:
            tol = max([e.tol_max for e in edges])

        hwires = ShapeAnalysis_FreeBounds.ConnectEdgesToWires_(
            hedges, tol, shared)

        wires = []
        for i in range(1, hwires.Length() + 1):
            w = Wire(hwires.Value(i))
            wires.append(w)

        self._wires = wires
Ejemplo n.º 5
0
    def test_ConnectEdgesToWires(self):
        """
        Test ShapeAnalysis_FreeBounds::ConnectEdgesToWires
        """
        p1 = gp_Pnt()
        p2 = gp_Pnt(1, 0, 0)
        e1 = BRepBuilderAPI_MakeEdge(p1, p2).Edge()

        p3 = gp_Pnt(1, 1, 0)
        e2 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()

        seq = TopTools_HSequenceOfShape()
        seq.Append(e1)
        seq.Append(e2)

        wires = ShapeAnalysis_FreeBounds.ConnectEdgesToWires_(
            seq, 1.0e-7, False)
        self.assertFalse(wires.IsEmpty())
        self.assertEqual(wires.Length(), 1)