예제 #1
0
    def __init__(self, shape, edges=None, check_interior=True):
        super(SplitShapeByEdges, self).__init__()

        self._bop = BRepFeat_SplitShape(shape.object)

        if not check_interior:
            self._bop.SetCheckInterior(False)

        if edges is not None:
            edge_seq = TopTools_SequenceOfShape()
            for e in edges:
                edge_seq.Append(e.object)
            self._bop.Add(edge_seq)
            self.build()
예제 #2
0
class LocalSplit(BopCore):
    """
    Perform a local split of a shape in the context of a basis shape. This tool
    only splits faces.

    :param afem.topology.entities.Shape shape: The local shape.
    :param tool: The tool to split with.
    :type tool: afem.topology.entities.Shape or afem.geometry.entities.Surface
    :param afem.topology.entities.Shape basis_shape: The basis shape that the
        local shape is part of.
    :param bool approximate: Option to approximate intersection curves.
    :param float fuzzy_val: Fuzzy tolerance value.
    :param bool nondestructive: Option to not modify the input shapes.
    """
    def __init__(self,
                 shape,
                 tool,
                 basis_shape,
                 approximate=False,
                 fuzzy_val=None,
                 nondestructive=False):
        super(LocalSplit, self).__init__()

        # Intersect
        section = IntersectShapes(shape, tool, True, False, approximate,
                                  fuzzy_val, nondestructive)
        sec_edges = section.edges

        # Split
        self._bop = BRepFeat_SplitShape(basis_shape.object)
        for e in sec_edges:
            status, f = section.has_ancestor_face1(e)
            if status:
                self._bop.Add(e.object, f.object)
        self.build()
예제 #3
0
파일: bop.py 프로젝트: sanderboer/AFEM
    def __init__(self, shape, tool, basis_shape, approximate=False,
                 fuzzy_val=None, nondestructive=False):
        super(LocalSplit, self).__init__()

        # Intersect
        section = IntersectShapes(shape, tool, True, False, approximate,
                                  fuzzy_val, nondestructive)
        sec_edges = section.edges

        # Split
        self._bop = BRepFeat_SplitShape(basis_shape.object)
        for e in sec_edges:
            status, f = section.has_ancestor_face1(e)
            if status:
                self._bop.Add(e.object, f.object)
        self.build()
def split_shape(event=None):
    S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape()
    asect = BRepAlgoAPI_Section(S, gp_Pln(1, 2, 1, -15), False)
    asect.ComputePCurveOn1(True)
    asect.Approximation(True)
    asect.Build()
    R = asect.Shape()

    asplit = BRepFeat_SplitShape(S)

    for edg in TopologyExplorer(R).edges():
        face = TopoDS_Face()
        if asect.HasAncestorFaceOn1(edg, face):
            asplit.Add(edg, face)

    asplit.Build()
    display.EraseAll()
    display.DisplayShape(asplit.Shape())
    display.FitAll()
예제 #5
0
class LocalSplit(BopCore):
    """
    Perform a local split of a shape in the context of a basis shape. This tool
    only splits faces.

    :param afem.topology.entities.Shape shape: The local shape.
    :param tool: The tool to split with.
    :type tool: afem.topology.entities.Shape or afem.geometry.entities.Surface
    :param afem.topology.entities.Shape basis_shape: The basis shape that the
        local shape is part of.
    :param bool approximate: Option to approximate intersection curves.
    :param float fuzzy_val: Fuzzy tolerance value.
    :param bool nondestructive: Option to not modify the input shapes.

    Usage:

    >>> from afem.geometry import *
    >>> from afem.topology import *
    >>> pln = PlaneByAxes().plane
    >>> builder = SolidByPlane(pln, 5., 5., 5.)
    >>> box = builder.solid
    >>> tool = PlaneByAxes(axes='xy').plane
    >>> face = box.faces[0]
    >>> split = LocalSplit(face, tool, box)
    >>> assert split.is_done
    """
    def __init__(self,
                 shape,
                 tool,
                 basis_shape,
                 approximate=False,
                 fuzzy_val=None,
                 nondestructive=False):
        super(LocalSplit, self).__init__()

        # Intersect
        section = IntersectShapes(shape, tool, True, False, approximate,
                                  fuzzy_val, nondestructive)
        sec_edges = section.edges

        # Split
        self._bop = BRepFeat_SplitShape(basis_shape.object)
        for e in sec_edges:
            status, f = section.has_ancestor_face1(e)
            if status:
                self._bop.Add(e.object, f.object)
        self.build()
예제 #6
0
class SplitShapeByEdges(BopCore):
    """
    Split a shape using edges.

    :param afem.topology.entities.Shape shape: The basis shape.
    :param edges: The edges to split the shape with. If provided, then the
        results will be built during initialization. If none are provided then
        the user is expected to add edges and build manually.
    :type edges: collections.Sequence(afem.topology.entities.Edge) or None
    :param bool check_interior: Option to check internal intersections.
    """
    def __init__(self, shape, edges=None, check_interior=True):
        super(SplitShapeByEdges, self).__init__()

        self._bop = BRepFeat_SplitShape(shape.object)

        if not check_interior:
            self._bop.SetCheckInterior(False)

        if edges is not None:
            edge_seq = TopTools_SequenceOfShape()
            for e in edges:
                edge_seq.Append(e.object)
            self._bop.Add(edge_seq)
            self.build()

    def add_edges(self, shapes):
        """
        Add splittings edges or wires for the initial shape.

        :param collections.Sequence(afem.topology.entities.Shape) shapes: The
            splitting edges or wires.

        :return: *True* if added, *False* if not.
        :rtype: bool
        """
        seq = TopTools_SequenceOfShape()
        for s in shapes:
            seq.Append(s.object)
        return self._bop.Add(seq)

    def add_wire_on_face(self, w, f):
        """
        Add the wire on the face.

        :param afem.topology.entities.Wire w: The wire.
        :param afem.topology.entities.Face f: The face.

        :return: None.
        """
        self._bop.Add(w.object, f.object)

    def add_edge_on_face(self, e, f):
        """
        Add the edge on the face.

        :param afem.topology.entities.Edge e: The edge.
        :param afem.topology.entities.Face f: The face.

        :return: None
        """
        self._bop.Add(e.object, f.object)

    def add_edges_on_face(self, e, f):
        """

        :param collections.Sequence(afem.topology.entities.Edge) e: The edges.
        :param afem.topology.entities.Face f: The face.

        :return: None
        """
        # Avoid circular imports
        from afem.topology.create import CompoundByShapes

        cmp = CompoundByShapes(e).compound
        self._bop.Add(cmp.object, f.object)

    def add_edge_on_edge(self, e1, e2):
        """
        Add the edge on an existing edge.

        :param afem.topology.entities.Edge e1: The edge.
        :param afem.topology.entities.Edge e2: The existing edge.

        :return: None.
        """
        self._bop.Add(e1.object, e2.object)