예제 #1
0
def cut_solid_parts(array):
    from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
    from OCC.Core.BRepFeat import BRepFeat_SplitShape
    from OCC.TopTools import TopTools_ListIteratorOfListOfShape
    from OCC.Extend.TopologyUtils import TopologyExplorer
    from OCC.Core.TopoDS import TopoDS_Face
    #array contains several parts
    for i, si in enumerate(array):
        #for ki in si.dico:
        shpi = si.solid
        split = BRepFeat_SplitShape(shpi)
        for j, sj in enumerate(array):
            if i != j:
                shpj = sj.solid
                sect = BRepAlgoAPI_Section(shpi, shpj, False)
                sect.ComputePCurveOn1(True)
                sect.Approximation(True)
                sect.SetFuzzyValue(1.e-12)
                sect.Build()
                shpsect = sect.Shape()
                for edg in TopologyExplorer(shpsect).edges():
                    face = TopoDS_Face()
                    if sect.HasAncestorFaceOn1(edg, face):
                        split.Add(edg, face)
        split.Build()
        lst = TopTools_ListIteratorOfListOfShape(split.Modified(shpi))
        while lst.More():
            for face in TopologyExplorer(lst.Value()).faces():
                array[i].splitsolid.append(face)
            lst.Next()
예제 #2
0
파일: bop.py 프로젝트: tnakaicode/AFEM-OCC
    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()
예제 #3
0
파일: bop.py 프로젝트: tnakaicode/AFEM-OCC
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()
예제 #4
0
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
파일: bop.py 프로젝트: tnakaicode/AFEM-OCC
    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
def split_shells_by_solid(array, solid, display):
    from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
    from OCC.Core.BRepFeat import BRepFeat_SplitShape
    from OCC.TopTools import TopTools_ListIteratorOfListOfShape
    from OCC.Extend.TopologyUtils import TopologyExplorer
    from OCC.Core.TopoDS import TopoDS_Face
    for i, si in enumerate(array):
        for ki in si.dico:
            print ki
            sfi = si.dico[ki]
            split = BRepFeat_SplitShape(sfi.Shape())
            sect = BRepAlgoAPI_Section(solid, sfi.Shape(), False)
            sect.ComputePCurveOn1(True)
            sect.Approximation(True)
            sect.SetFuzzyValue(1.e-12)
            sect.Build()
            shpsect = sect.Shape()
            for edg in TopologyExplorer(shpsect).edges():
                face = TopoDS_Face()
                if sect.HasAncestorFaceOn1(edg, face):
                    split.Add(edg, face)
            split.Build()
            ais_shape = display.DisplayColoredShape(split.Shape(), color='RED')
            display.Context.SetTransparency(ais_shape, 0.5)
예제 #7
0
파일: bop.py 프로젝트: tnakaicode/AFEM-OCC
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)
예제 #8
0
        all_points.append(edge_points)
    if len(all_points) != 0:
        pol = segments_to_polyline(all_points)
        all_edges = polyline3d_to_edges(pol)
    for edg in all_edges:
        face_explorer = TopExp_Explorer(faces1[f].Shape(), TopAbs_FACE)
        while False:  #face_explorer.More():
            try:
                TopOpeBRepTool_CurveTool_MakePCurveOnFace(
                    edg, topods_Face(face_explorer.Current()))
                print 'done'
            except:
                print 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr'
            face_explorer.Next()
    print 'out'
    ss = BRepFeat_SplitShape(faces1[f].Shape())
    ss.SetCheckInterior(True)
    for edg in all_edges:
        face = TopoDS_Face()
        if section.HasAncestorFaceOn1(edg, face):
            ss.Add(edg, face)
            display.DisplayColoredShape(face, 'RED')
    ss.Build()
    dl = ss.DirectLeft()
    test = TopTools_ListIteratorOfListOfShape(dl)
    #display.DisplayColoredShape(ss.Shape(),'GREEN')
    display.DisplayColoredShape(faces1[f].Shape(), 'RED')
#surfaces = [med_ax]
#for k in fore_cad:
#    surfaces.append(fore_cad[k])
#    display.DisplayShape(fore_cad[k])