Ejemplo n.º 1
0
 def update_shape(self, change=None):
     d = self.declaration
     builder = BRepBuilderAPI_Sewing()
     for s in self.child_shapes():
         builder.Add(Topology.cast_shape(s))
     builder.Perform()
     self.shape = Topology.cast_shape(builder.SewedShape())
Ejemplo n.º 2
0
    def __init__(self,
                 faces,
                 tol=None,
                 cut_free_edges=False,
                 non_manifold=False):
        if tol is None:
            tol = max([f.tol_max for f in faces])

        builder = BRepBuilderAPI_Sewing(tol, True, True, cut_free_edges,
                                        non_manifold)
        for f in faces:
            builder.Add(f.object)
        builder.Perform()

        shape = Shape.wrap(builder.SewedShape())
        self._shells = []
        self._shell = None
        self._nshells = 0
        if shape.is_compound:
            self._shells = shape.shells
            self._nshells = len(self._shells)
        elif shape.is_face:
            self._shell = shape.to_shell()
            self._nshells = 1
        elif shape.is_shell:
            self._shell = shape
            self._nshells = 1
        else:
            raise RuntimeError('Invalid shape type in ShellBySewing.')
Ejemplo n.º 3
0
def sew_shapes(shapes, tolerance=0.001):
    sew = BRepBuilderAPI_Sewing(tolerance)
    for shp in shapes:
        if isinstance(shp, list):
            for i in shp:
                sew.Add(i)
        else:
            sew.Add(shp)
    sew.Perform()
    print("n degenerated shapes", sew.NbDegeneratedShapes())
    print("n deleted faces:", sew.NbDeletedFaces())
    print("n free edges", sew.NbFreeEdges())
    print("n multiple edges:", sew.NbMultipleEdges())
    result = ShapeToTopology()(sew.SewedShape())
    return result
def get_faceted_L_shape(x, y, z):
    pnt_A = gp_Pnt(x + 0, y + 0, z + 0)
    pnt_B = gp_Pnt(x +20, y + 0, z + 0)
    pnt_C = gp_Pnt(x +20, y +10, z + 0)
    pnt_D = gp_Pnt(x + 0, y +10, z + 0)
    pnt_E = gp_Pnt(x + 0, y + 0, z +20)
    pnt_F = gp_Pnt(x +10, y + 0, z +20)
    pnt_G = gp_Pnt(x +10, y +10, z +20)
    pnt_H = gp_Pnt(x +0, y +10, z +20)
    pnt_I = gp_Pnt(x +10, y + 0, z +10)
    pnt_J = gp_Pnt(x +10, y +10, z +10)
    pnt_K = gp_Pnt(x +20, y + 0, z +10)
    pnt_L = gp_Pnt(x +20, y +10, z +10)

    face_1 = make_face_from_4_points(pnt_A, pnt_B, pnt_C, pnt_D)
    face_2 = make_face_from_4_points(pnt_B, pnt_C, pnt_L, pnt_K)
    face_3 = make_face_from_4_points(pnt_E, pnt_F, pnt_G, pnt_H)
    face_4 = make_face_from_4_points(pnt_A, pnt_E, pnt_H, pnt_D)
    face_5 = make_face_from_4_points(pnt_G, pnt_F, pnt_I, pnt_J)
    face_6 = make_face_from_4_points(pnt_I, pnt_K, pnt_L, pnt_J)

    polygon_1 = BRepBuilderAPI_MakePolygon()
    polygon_1.Add(pnt_A)
    polygon_1.Add(pnt_B)
    polygon_1.Add(pnt_K)
    polygon_1.Add(pnt_I)
    polygon_1.Add(pnt_F)
    polygon_1.Add(pnt_E)
    polygon_1.Close()

    face_7 = BRepBuilderAPI_MakeFace(polygon_1.Wire()).Face()
    polygon_2 = BRepBuilderAPI_MakePolygon()
    polygon_2.Add(pnt_D)
    polygon_2.Add(pnt_H)
    polygon_2.Add(pnt_G)
    polygon_2.Add(pnt_J)
    polygon_2.Add(pnt_L)
    polygon_2.Add(pnt_C)
    polygon_2.Close()
    face_8 = BRepBuilderAPI_MakeFace(polygon_2.Wire()).Face()

    sew = BRepBuilderAPI_Sewing()
    for face in [face_1, face_2, face_3, face_4, face_5, face_6, face_7, face_8]:
        sew.Add(face)
    sew.Perform()

    return sew.SewedShape()
Ejemplo n.º 5
0
    def __init__(self, shape=None, tol=None, min_tol=None, max_tol=None,
                 cut_free_edges=False, non_manifold=False):
        if tol is None:
            if shape is None:
                tol = 1.0e-7
            else:
                tol = shape.tol_max

        self._tool = BRepBuilderAPI_Sewing(tol, True, True, cut_free_edges,
                                           non_manifold)

        if min_tol is not None:
            self._tool.SetMinTolerance(min_tol)
        if max_tol is not None:
            self._tool.SetMaxTolerance(max_tol)

        if shape is not None:
            self._tool.Load(shape.object)
            self._tool.Perform()
Ejemplo n.º 6
0
class SewShape(object):
    """
    Sew the shape.

    :param afem.topology.entities.Shape shape: The context shape to sew.
    :param float tol: Sewing tolerance. If *None* is provided then the
        average tolerance of the shape will be used. If no shape is
        provided, then a default value of 1.0e-7 is used.
    :param float min_tol: Minimum tolerance.
    :param float max_tol: Maximum tolerance.
    :param bool cut_free_edges: Option for cutting of free edges.
    :param bool non_manifold: Option for non-manifold processing.

    .. note::

        If *shape* is *None* then the user is expected to manually load the
        shape and perform the operation.
    """

    def __init__(self, shape=None, tol=None, min_tol=None, max_tol=None,
                 cut_free_edges=False, non_manifold=False):
        if tol is None:
            if shape is None:
                tol = 1.0e-7
            else:
                tol = shape.tol_max

        self._tool = BRepBuilderAPI_Sewing(tol, True, True, cut_free_edges,
                                           non_manifold)

        if min_tol is not None:
            self._tool.SetMinTolerance(min_tol)
        if max_tol is not None:
            self._tool.SetMaxTolerance(max_tol)

        if shape is not None:
            self._tool.Load(shape.object)
            self._tool.Perform()

    def load(self, shape):
        """
        Load the context shape to sew.

        :param afem.topology.entities.Shape shape: The shape.

        :return: None.
        """
        self._tool.Load(shape.object)

    def add(self, shape):
        """
        Add a shape to be sewed or controlled.

        :param afem.topology.entities.Shape shape: The shape.

        :return: None.
        """
        self._tool.Add(shape.object)

    def perform(self):
        """
        Perform the sewing operation.

        :return: None.
        """
        self._tool.Perform()

    @property
    def sewed_shape(self):
        """
        :return: The sewed shape. May be a null shape if nothing is
            constructed.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.SewedShape())

    @property
    def n_free_edges(self):
        """
        :return: Number of free edges.
        :rtype: int
        """
        return self._tool.NbFreeEdges()

    @property
    def free_edges(self):
        """
        :return: Free edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.FreeEdge(i))
            edges.append(e)
        return edges

    @property
    def n_multiple_edges(self):
        """
        :return: Number of edges connected to more than two faces.
        :rtype: int
        """
        return self._tool.NbMultipleEdges()

    @property
    def multiple_edges(self):
        """
        :return: Multiple edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.MultipleEdge(i))
            edges.append(e)
        return edges

    @property
    def n_manifold_edges(self):
        """
        :return: Number of manifold edges.
        :rtype: int
        """
        return self._tool.NbContigousEdges()

    @property
    def manifold_edges(self):
        """
        :return: Manifold edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.ContigousEdge(i))
            edges.append(e)
        return edges

    def is_modified(self, shape):
        """
        Check to see if input shape has been modified.

        :param afem.topology.entities.Shape shape: The shape.

        :return: *True* if modified, *False* if not.
        :rtype: bool
        """
        self._tool.IsModified(shape.object)

    def modified(self, shape):
        """
        Get a modified shape.

        :param afem.topology.entities.Shape shape: The shape.

        :return: The modified shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.Modified(shape.object))

    def is_modified_subshape(self, subshape):
        """
        Check to see if input sub-shape has been modified.

        :param afem.topology.entities.Shape subshape: The sub-shape.

        :return: *True* if modified, *False* if not.
        :rtype: bool
        """
        self._tool.IsModifiedSubShape(subshape.object)

    def modified_subshape(self, subshape):
        """
        Get a modified sub-shape.

        :param afem.topology.entities.Shape subshape: The sub-shape.

        :return: The modified sub-shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.ModifiedSubShape(subshape.object))
Ejemplo n.º 7
0
def _build_solid(compound, divide_closed):
    """
    Method to try and build a valid solid from an OpenVSP component.
    """
    # Get all the faces in the compound. The surfaces must be split. Discard
    # any with zero area.
    top_exp = TopExp_Explorer(compound, TopAbs_FACE)
    faces = []
    while top_exp.More():
        shape = top_exp.Current()
        face = CheckShape.to_face(shape)
        fprop = GProp_GProps()
        BRepGProp.SurfaceProperties_(face, fprop, 1.0e-7)
        a = fprop.Mass()
        if a <= 1.0e-7:
            top_exp.Next()
            continue
        faces.append(face)
        top_exp.Next()

    # Replace any planar B-Spline surfaces with planes
    non_planar_faces = []
    planar_faces = []
    for f in faces:
        hsrf = BRep_Tool.Surface_(f)
        try:
            is_pln = GeomLib_IsPlanarSurface(hsrf, 1.0e-7)
            if is_pln.IsPlanar():
                w = ShapeAnalysis.OuterWire_(f)
                # Fix the wire because they are usually degenerate edges in
                # the planar end caps.
                builder = BRepBuilderAPI_MakeWire()
                for e in ExploreShape.get_edges(w):
                    if LinearProps(e).length > 1.0e-7:
                        builder.Add(e)
                w = builder.Wire()
                fix = ShapeFix_Wire()
                fix.Load(w)
                geom_pln = Geom_Plane(is_pln.Plan())
                fix.SetSurface(geom_pln)
                fix.FixReorder()
                fix.FixConnected()
                fix.FixEdgeCurves()
                fix.FixDegenerated()
                w = fix.WireAPIMake()
                # Build the planar face
                fnew = BRepBuilderAPI_MakeFace(w, True).Face()
                planar_faces.append(fnew)
            else:
                non_planar_faces.append(f)
        except RuntimeError:
            non_planar_faces.append(f)

    # Make a compound of the faces
    shape = CreateShape.compound(non_planar_faces + planar_faces)

    # Split closed faces
    if divide_closed:
        divide = ShapeUpgrade_ShapeDivideClosed(shape)
        divide.Perform()
        shape = divide.Result()

    # Sew shape
    sew = BRepBuilderAPI_Sewing(1.0e-7)
    sew.Load(shape)
    sew.Perform()
    sewn_shape = sew.SewedShape()

    if sewn_shape.ShapeType() == TopAbs_FACE:
        face = sewn_shape
        sewn_shape = TopoDS_Shell()
        builder = BRep_Builder()
        builder.MakeShell(sewn_shape)
        builder.Add(sewn_shape, face)

    # Attempt to unify planar domains
    unify_shp = ShapeUpgrade_UnifySameDomain(sewn_shape, False, True, False)
    unify_shp.Build()
    shape = unify_shp.Shape()

    # Make solid
    shell = ExploreShape.get_shells(shape)[0]
    solid = ShapeFix_Solid().SolidFromShell(shell)

    # Limit tolerance
    FixShape.limit_tolerance(solid)

    # Check shape validity
    check_shp = BRepCheck_Analyzer(solid, True)
    if check_shp.IsValid():
        return solid, True, []
    else:
        invalid_shapes = _topods_iterator_check(solid, check_shp)
        return solid, False, invalid_shapes
e3 = BRepBuilderAPI_MakeEdge(v2, v1).Edge()
e4 = BRepBuilderAPI_MakeEdge(v3, v2).Edge()
e5 = BRepBuilderAPI_MakeEdge(v3, v1).Edge()

# create wires
w0 = BRepBuilderAPI_MakeWire(e5, e3, e4).Wire()
w1 = BRepBuilderAPI_MakeWire(e1, e3, e0).Wire()
w2 = BRepBuilderAPI_MakeWire(e0, e5, e2).Wire()
w3 = BRepBuilderAPI_MakeWire(e2, e4, e1).Wire()

# then create faces
f0 = BRepBuilderAPI_MakeFace(w0).Face()
f1 = BRepBuilderAPI_MakeFace(w1).Face()
f2 = BRepBuilderAPI_MakeFace(w2).Face()
f3 = BRepBuilderAPI_MakeFace(w3).Face()

# sew the faces together to create a shell
sew = BRepBuilderAPI_Sewing()
sew.Add(f0)
sew.Add(f1)
sew.Add(f2)
sew.Add(f3)
sew.Perform()
tetrahedron_shell = sew.SewedShape()

# display the result
display, start_display, add_menu, add_function_to_menu = init_display()

display.DisplayShape(tetrahedron_shell, update=True)
start_display()