def split_edge_with_face(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Builder()
    # Add the edge as an argument and the face as a tool. This will split
    # the edge with the face.
    splitter.AddArgument(edge)
    splitter.AddArgument(face)
    splitter.Perform()

    edges = []
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
    while exp.More():
        edges.append(exp.Current())
        exp.Next()
    print('Number of edges in split shape: ', len(edges))
    display.DisplayShape(edges[0], color='red')
    display.DisplayShape(edges[1], color='green')
    display.DisplayShape(edges[2], color='yellow')
    display.FitAll()
Exemple #2
0
def general_fuse_algorithm(array):
    from OCC.Core.BOPAlgo import BOPAlgo_Builder
    builder = BOPAlgo_Builder()
    for s in array:
        builder.AddArgument(s)
    builder.Perform()
    result = builder.Shape()
    return result
def split_face_with_edge(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Builder()
    # Add the face as an argument and the edge as a tool. This will split
    # the face with the edge.
    splitter.AddArgument(face)
    splitter.AddArgument(edge)
    splitter.Perform()
    display.DisplayShape(splitter.Shape())
    display.FitAll()
def split_compound(compound):
    all_faces = get_faces(compound)
    planar_faces = list(filter(lambda x: Face(x).is_planar(), all_faces))

    p1, v1 = gp_Pnt(50, 50, 25), gp_Vec(0, 0, -1)
    fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    bo = BOPAlgo_Builder()
    bo.AddArgument(copy.deepcopy(compound))
    # bo.AddArgument(fc1)

    # display.DisplayShape(fc1, transparency=0.7)
    for f in planar_faces:
        gprop = BRepGProp_Face(f)
        normal_point = gp_Pnt(0, 0, 0)
        normal_vec = gp_Vec(0, 0, 0)
        gprop.Normal(0, 0, normal_point, normal_vec)
        big_face = make_face(gp_Pln(normal_point,
                                    vec_to_dir(normal_vec)), -1000, 1000,
                             -1000, 1000)  # limited, not infinite plane
        bo.AddArgument(big_face)
        # display.DisplayShape(big_face, transparency=0.7)

    bo.Perform()
    # print("error status: {}".format(bo.ErrorStatus()))

    top = Topo(bo.Shape())
    result = [s for s in top.solids()]
    return result
Exemple #5
0
    def save_all_assamle(self):
        from OCC.Core.BOPAlgo import BOPAlgo_Builder
        print(self.modules.keys())
        builder = BOPAlgo_Builder()

        for name in self.modules:
            builder.AddArgument(self.modules[name])

        builder.SetRunParallel(True)
        builder.Perform()
        shape = builder.Shape()
        self.save_assembly(shape)
Exemple #6
0
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.BOPAlgo import BOPAlgo_Builder

display, start_display, add_menu, add_function_to_menu = init_display()
my_box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
my_box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape()

# use the GFA
builder = BOPAlgo_Builder()
builder.AddArgument(my_box1)
builder.AddArgument(my_box2)
builder.SetRunParallel(True)
builder.Perform()  # or .PerformWithFiller(aPF);
error_code = builder.ErrorStatus()
if error_code != 0:
    raise AssertionError("Failed with error code %i" % error_code)
result = builder.Shape()
display.DisplayShape(result, update=True)
start_display()
Exemple #7
0
    def inter_with_frame(self):
        # print('Start_inter_analyse')
        #print(self.names_models)
        all_result = 0
        props = GProp_GProps()
        # self.display.DisplayShape(body_inter, color='YELLOW')
        brepgprop_VolumeProperties(self.frame, props)
        mass_frame = props.Mass()

        cp = BRepBuilderAPI_Copy(self.frame)
        cp.Perform(self.frame)
        shape = cp.Shape()

        builder = BOPAlgo_Builder()

        for name in self.modules:
            builder.AddArgument(self.modules[name])

        builder.SetRunParallel(True)
        builder.Perform()
        models = builder.Shape()

        props = GProp_GProps()
        # self.display.DisplayShape(body_inter, color='YELLOW')

        brepgprop_VolumeProperties(models, props)
        mass_models = props.Mass()

        mass_1 = mass_frame + mass_models
        '''builder = BOPAlgo_Builder()

        builder.AddArgument(shape)
        builder.AddArgument(models)

        builder.SetRunParallel(True)
        builder.Perform()
        m_w_frame = builder.Shape()'''

        self.m_w_frame = BRepAlgoAPI_Fuse(shape, models).Shape()
        # self.display.DisplayShape(m_w_frame, color='YELLOW', transparency=0.9)

        props = GProp_GProps()

        brepgprop_VolumeProperties(self.m_w_frame, props)
        mass_2 = props.Mass()

        mass = mass_1 - mass_2

        # print(self.modules)
        '''for model in self.modules:
            # print('#')
            props = GProp_GProps()
            new_shape = BRepAlgoAPI_Cut(shape, self.modules[model]).Shape()
            # self.display.DisplayShape(body_inter, color='YELLOW')
            brepgprop_VolumeProperties(new_shape, props)
            mass_frame_2 = props.Mass()
            self.display.DisplayShape(new_shape, color='YELLOW', transparency=0.9)

            mass = mass_frame - mass_frame_2

            props = GProp_GProps()
            inter = TopOpeBRep_ShapeIntersector()
            inter.InitIntersection(self.modules[model], self.frame)
            flag = inter.MoreIntersection()
            body_inter = inter.CurrentGeomShape(1)
            brepgprop_VolumeProperties(body_inter, props)
            mass = props.Mass()

            props = GProp_GProps()
            body_inter = inter.CurrentGeomShape(2)
            brepgprop_VolumeProperties(body_inter, props)
            mass = abs(mass) + abs(props.Mass())

            dss = BRepExtrema_DistShapeShape()
            dss.LoadS1(self.modules[model])
            dss.LoadS2(self.frame)
            dss.Perform()

            flag = dss.IsDone()
            mass = dss.Value()
            print(mass)
            print(flag)'''
        print(mass)

        if mass > 1e-6:
            # print(mass)
            all_result += 1

        return all_result
Exemple #8
0
    box = make_box(200, 200, 200)

    p1, v1 = gp_Pnt(50, 50, 50), gp_Vec(0, 0, -1)
    fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    p2, v2 = gp_Pnt(50, 50, 50), gp_Vec(0, 1, -1)
    fc2 = make_face(gp_Pln(p2, vec_to_dir(v2)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    p3, v3 = gp_Pnt(50, 50, 25), gp_Vec(1, 1, -1)
    fc3 = make_face(gp_Pln(p3, vec_to_dir(v3)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    bo = BOPAlgo_Builder()
    bo.AddArgument(box)
    bo.AddArgument(fc1)
    bo.AddArgument(fc2)
    bo.AddArgument(fc3)

    bo.Perform()
    #print("error status: {}".format(bo.ErrorStatus()))

    colos = ["BLUE", "RED", "GREEN", "YELLOW", "BLACK", "WHITE", "BLUE", "RED"]

    top = Topo(bo.Shape())
    for i, sol in enumerate(top.solids()):
        display.DisplayShape(sol, color=colos[i], transparency=0.5)

    display.FitAll()
Exemple #9
0
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.BOPAlgo import BOPAlgo_Builder

display, start_display, add_menu, add_function_to_menu = init_display()
my_box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
my_box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape()

# use the GFA
builder = BOPAlgo_Builder()
builder.AddArgument(my_box1)
builder.AddArgument(my_box2)
builder.SetRunParallel(True)
builder.Perform()  # or .PerformWithFiller(aPF);
if builder.HasErrors():
    raise AssertionError("Failed with error: ", builder.DumpErrorsToString())
result = builder.Shape()
display.DisplayShape(result, update=True)
start_display()