예제 #1
0
    def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()):
        plan = self.pln_on_face(face)
        plan_axs = plan.Position()

        pln_angle = self.tmp_axis.Angle(plan_axs)
        ref_angle = self.tmp_axis.Direction().AngleWithRef(
            plan_axs.Direction(), axs.Direction())
        print(np.rad2deg(pln_angle), np.rad2deg(ref_angle))

        trf = gp_Trsf()
        if np.abs(ref_angle) >= np.pi / 2:
            trf.SetRotation(axs, -ref_angle)
        elif 0 < ref_angle < np.pi / 2:
            trf.SetRotation(axs, np.pi - ref_angle)
        elif -np.pi / 2 < ref_angle < 0:
            trf.SetRotation(axs, -ref_angle - np.pi)
        else:
            trf.SetRotation(axs, -ref_angle)
        #trf.SetTransformation(axs3.Rotated(axs, angle), axs3)
        loc_face = TopLoc_Location(trf)
        new_face = face.Located(loc_face)
        # self.sol_builder.Add(new_face)
        self.face_lst.Append(new_face)
        # face.Location(loc_face)
        if self.show == True:
            self.display.DisplayShape(new_face)
        return new_face
예제 #2
0
    def face_expand(self, face=TopoDS_Face()):
        print(face)

        find_edge = LocOpe_FindEdges(self.tmp_face, face)
        find_edge.InitIterator()

        while find_edge.More():
            if face not in self.face_cnt:
                edge = find_edge.EdgeTo()
                line = self.prop_edge(edge)
                plan = self.pln_on_face(face)

                plan_axs = plan.Position()
                line_axs = line.Position()

                print(self.tmp_axis.Axis())
                print(plan.Position().Axis())
                #print(self.cal_len(edge), self.cal_are(face))

                new_face = self.face_rotate(face, line_axs)
                #self.face_tranfer(face, plan.Axis())

                plan = self.pln_on_face(face)
                print(face, self.cal_are(face), plan)
                print(plan, plan.Axis())
                self.face_cnt.append(face)
            find_edge.Next()
예제 #3
0
 def face_tranfer(self, face=TopoDS_Face(), axs=gp_Ax1()):
     axs_3 = gp_Ax3(axs.Location(), axs.Direction())
     trf = gp_Trsf()
     trf.SetTransformation(axs_3, self.tmp_axs3)
     loc_face = TopLoc_Location(trf)
     face.Location(loc_face)
     return face
예제 #4
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()
예제 #5
0
 def face_init(self, face=TopoDS_Face()):
     self.tmp_face = face
     self.tmp_plan = self.pln_on_face(self.tmp_face)
     self.tmp_axis = self.tmp_plan.Position()
     self.tmp_face_n = 0
     self.show_axs_pln(self.tmp_axis, scale=20, name="Fix-Face")
     self.display.DisplayShape(self.tmp_face, color="RED")
예제 #6
0
    def face_expand(self, face=TopoDS_Face()):
        plan = self.pln_on_face(face)
        find_edge = LocOpe_FindEdges(self.tmp_face, face)
        find_edge.InitIterator()
        edge_n = 0
        while find_edge.More():
            edge = find_edge.EdgeTo()
            line = self.prop_edge(edge)

            e_curve, u0, u1 = BRep_Tool.Curve(edge)
            p = e_curve.Value((u0 + u1) / 2)
            i = (edge_n + self.tmp_face_n) % len(self.colors)
            self.display.DisplayShape(edge, color=self.colors[i])
            self.display.DisplayMessage(
                p, "Face{:d}-Edge{:d}".format(self.tmp_face_n, edge_n))

            plan_axs = plan.Position()
            line_axs = line.Position()
            line_axs.SetLocation(p)

            print()
            print("Face: {:d}, Edge: {:d}".format(self.tmp_face_n, edge_n))
            print(self.tmp_axis.Axis())
            print(plan.Position().Axis())
            #print(self.cal_len(edge), self.cal_are(face))

            self.face_rotate(face, line_axs)
            #self.face_tranfer(face, plan.Axis())

            plan = self.pln_on_face(face)
            print(face, self.cal_are(face), plan)
            print(plan, plan.Axis())
            find_edge.Next()

            edge_n += 1
예제 #7
0
파일: occ_utils.py 프로젝트: hducg/CADGen
def face_adjacent(shape, face, edge):
    efmap = TopTools_IndexedDataMapOfShapeListOfShape()
    topexp_MapShapesAndAncestors(shape, TopAbs_EDGE, TopAbs_FACE, efmap)
    adjface = TopoDS_Face()
    if TopOpeBRepBuild_Tools.GetAdjacentFace(face, edge, efmap, adjface):
        return adjface
    else:
        return None
예제 #8
0
    def face_init(self, face=TopoDS_Face()):
        self.face_num += 1
        self.tmp_face = face
        self.tmp_plan = self.pln_on_face(self.tmp_face)
        self.tmp_axis = self.tmp_plan.Position()
        print(self.tmp_axis)

        if self.show == True:
            self.display.DisplayMessage(self.tmp_axis.Location(),
                                        "{:04d}".format(self.face_num))
            pass
예제 #9
0
파일: bop.py 프로젝트: tnakaicode/AFEM-OCC
    def has_ancestor_face2(self, edge):
        """
        Get the ancestor face on the intersection edge on the second shape
        if available.

        :param afem.topology.entities.Edge edge: The edge.

        :return: *True* and the face if available, *False* and *None* if not.
        :rtype: tuple(bool, afem.topology.entities.Face or None)
        """
        f = TopoDS_Face()
        if self._bop.HasAncestorFaceOn2(edge.object, f):
            return True, Face(f)
        return False, None
예제 #10
0
    def pln_on_face(self, face=TopoDS_Face()):
        face_adaptor = BRepAdaptor_Surface(face)
        face_trf = face_adaptor.Trsf()
        face_pln = face_adaptor.Plane()
        #face_dir = face_adaptor.Direction()

        face_umin = face_adaptor.FirstUParameter()
        face_vmin = face_adaptor.FirstVParameter()
        face_umax = face_adaptor.LastUParameter()
        face_vmax = face_adaptor.LastVParameter()
        face_u = (face_umax + face_umin) / 2
        face_v = (face_vmax + face_vmin) / 2
        face_pnt = face_adaptor.Value(face_u, face_v)

        return face_pln
예제 #11
0
    def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()):
        plan = self.pln_on_face(face)
        plan_axs = plan.Position()
        self.display.DisplayShape(plan_axs.Location())

        v0 = dir_to_vec(self.tmp_axis.Direction())
        v1 = dir_to_vec(plan_axs.Direction())
        print(v0.Dot(v1))

        lin_vec = gp_Vec(axs.Location(), plan_axs.Location())
        edg_circl = Geom_Circle(
            gp_Circ(
                gp_Ax2(axs.Location(), axs.Direction(), vec_to_dir(lin_vec)),
                5))
        rim_u0, rim_u1 = edg_circl.FirstParameter(), edg_circl.LastParameter()
        rim_p0 = edg_circl.Value(rim_u0)

        pln_angle = self.tmp_axis.Angle(plan_axs)
        ref_angle = self.tmp_axis.Direction().AngleWithRef(
            plan_axs.Direction(), axs.Direction())
        print(np.rad2deg(pln_angle), np.rad2deg(ref_angle))

        rim_u2 = -ref_angle
        rim_p2 = edg_circl.Value(rim_u2)
        rim_angle = Geom_TrimmedCurve(edg_circl, rim_u0, rim_u2)

        trf = gp_Trsf()
        #trf.SetRotation(axs, 2*np.pi - ref_angle)
        if np.abs(ref_angle) >= np.pi / 2:
            trf.SetRotation(axs, -ref_angle)
        elif 0 < ref_angle < np.pi / 2:
            trf.SetRotation(axs, np.pi - ref_angle)
        elif -np.pi / 2 < ref_angle < 0:
            trf.SetRotation(axs, -ref_angle - np.pi)
        else:
            trf.SetRotation(axs, -ref_angle)
        #trf.SetTransformation(axs3.Rotated(axs, angle), axs3)
        loc_face = TopLoc_Location(trf)
        new_face = face.Moved(loc_face)
        self.display.DisplayShape(new_face, transparency=0.5)
        self.display.DisplayShape(rim_angle)
        self.display.DisplayShape(rim_p0)
        self.display.DisplayShape(rim_p2)
        return new_face
예제 #12
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()
예제 #13
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)
예제 #14
0
        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])
#for k in aft_cad:
#    surfaces.append(fore_cad[k])
#    display.DisplayShape(aft_cad[k])