Пример #1
0
def make_sewed(*faces) -> TopoDS_Shell:
    bld = BRepBuilderAPI_Sewing()
    for f in faces:
        bld.Add(f)
    bld.Perform()
    result = bld.SewedShape()
    return ShapeToTopology()(result)
Пример #2
0
    def UpdateZone(self, Surfaces, display):
        print(self.Surfaces)

        sewing = BRepBuilderAPI_Sewing()
        for i in self.Surfaces:
            sewing.Add(Surfaces[i].GHShape)
        sewing.Perform()
        sewed_shape = sewing.SewedShape()

        tds = topods()

        #        FixedShape = ShapeFix_Shell(tds.Shell(sewed_shape))
        #        FixedShape.Perform()

        solid = BRepBuilderAPI_MakeSolid(tds.Shell(sewed_shape))

        #        Test = BRepClass3d_SolidClassifier()
        #        Test.Perform()

        display.DisplayShape(solid.Shape())

        #print('done')

        Props = GProp_GProps()
        brepgprop.VolumeProperties(solid.Shape(), Props)
        self.Vol = Props.Mass()

        print(self.Vol)

        return display
Пример #3
0
def make_shell_frm_faces(occ_face_list, tolerance=1e-06):
    #make shell
    sewing = BRepBuilderAPI_Sewing()
    sewing.SetTolerance(tolerance)
    for f in occ_face_list:
        sewing.Add(f)

    sewing.Perform()
    sewing_shape = fetch.shape2shapetype(sewing.SewedShape())
    #topo_dict = fetch.topos_frm_compound(sewing_shape)
    #shell_list = topo_dict["shell"]
    shell_list = fetch.geom_explorer(sewing_shape, "shell")
    return shell_list
Пример #4
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
Пример #5
0
    def combine_faces(compshape, sew_tolerance):
        """
        Method to combine faces in a shell by adding connectivity and continuity
        :param compshape: TopoDS_Shape
        :param sew_tolerance: tolerance for sewing
        :return: Topo_Shell
        """

        offsew = BRepOffsetAPI_FindContigousEdges(sew_tolerance)
        sew = BRepBuilderAPI_Sewing(sew_tolerance)

        face_explorers = TopExp_Explorer(compshape, TopAbs_FACE)
        n_faces = 0
        # cycle on Faces
        while face_explorers.More():
            tface = topods.Face(face_explorers.Current())
            sew.Add(tface)
            offsew.Add(tface)
            n_faces += 1
            face_explorers.Next()

        offsew.Perform()
        offsew.Dump()
        sew.Perform()
        shell = sew.SewedShape()
        sew.Dump()

        shell = topods.Shell(shell)
        shell_fixer = ShapeFix_Shell()
        shell_fixer.FixFaceOrientation(shell)

        if shell_fixer.Perform():
            print("{} shells fixed! ".format(shell_fixer.NbShells()))
        else:
            print "Shells not fixed! "

        new_shell = shell_fixer.Shell()

        if brepalgo_IsValid(new_shell):
            print "Shell valid! "
        else:
            print "Shell failed! "

        return new_shell
Пример #6
0
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
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

display.DisplayShape(tetrahedron_shell, update=True)
start_display()
    def get_current_loft(self):
        wires = []
        curves = []
        propeller_number_, xz_mirror_, xy_mirror_, yz_mirror_ \
            , rot_x_, hub_length, pitch_angle, root_le_pos_x_, \
        root_le_pos_y_, root_le_pos_z_, section_1_length_, section_2_length_, \
        section_3_length_, section_4_length_, section_5_length_, section_1_profile_, \
        section_2_profile_, section_3_profile_, section_4_profile_, section_5_profile_, \
        section_1_z_, section_2_z_, section_3_z_, section_4_z_, section_5_z_ \
            , section_1_chord_, section_2_chord_, section_3_chord_, section_4_chord_, \
        section_5_chord_, section_1_pitch_angle_, section_2_pitch_angle_, \
        section_3_pitch_angle_, section_4_pitch_angle_, section_5_pitch_angle_ = read_propeller_parameters(
            name=self.name)
        interval = 5

        chords = [
            section_1_chord_, section_1_chord_, section_2_chord_,
            section_3_chord_, section_4_chord_, section_5_chord_, 0.001
        ]
        profile = [
            section_1_profile_, section_1_profile_, section_2_profile_,
            section_3_profile_, section_4_profile_, section_5_profile_,
            section_5_profile_
        ]
        length = [
            0, section_1_length_, section_2_length_, section_3_length_,
            section_4_length_, section_5_length_ / 2, section_5_length_ / 2
        ]
        z = [
            section_1_z_, section_1_z_, section_2_z_, section_3_z_,
            section_4_z_, section_5_z_, section_5_z_
        ]
        pitch = [
            0, section_1_pitch_angle_, section_2_pitch_angle_,
            section_3_pitch_angle_, section_4_pitch_angle_,
            section_5_pitch_angle_, section_5_pitch_angle_
        ]

        n = random.random()
        lifting_surface = self.config.get_wings().create_wing(
            f"{n}", len(chords), f"naca4412")

        sections = [-hub_length / 2, 0.1 * hub_length, hub_length / 2]

        radius = [
            0.00,
            rot_x_ / 2,
            rot_x_ / 2,
        ]

        x_ = []
        x_.extend(np.linspace(sections[0], sections[1], num=interval))
        x_.append(0.9 * hub_length)

        radii = []
        radii.extend(np.linspace(radius[0], radius[1], num=interval))
        radii.append((rot_x_ / 2))

        print(x_, radii)

        n = random.random()
        hub = self.config.get_fuselages().create_fuselage(
            f"hub{n}", len(x_), "circularProfile")
        for (x, rad, index) in zip(x_, radii, range(1, len(x_) + 1)):
            section = hub.get_section(index)
            sectionElement = section.get_section_element(1)
            sectionElementCenter = sectionElement.get_ctigl_section_element()
            sectionElementCenter.set_center(tigl3.geometry.CTiglPoint(x, 0, 0))
            sectionElementCenter.set_area(getArea(rad))

        n_sections = lifting_surface.get_section_count()
        lifting_surface.set_root_leposition(
            tigl3.geometry.CTiglPoint(-chords[0] / 2, 0, 0))
        print(n_sections)
        y = 0.0
        x = hub_length / 2
        for (z_, chord, length_, pitch_, profile_,
             idx) in zip(z, chords, length, pitch, profile,
                         range(1, n_sections + 1)):
            profile__ = "naca" + profile_
            constant = 0.0
            nacanumber = profile__.split("naca")[1]
            if nacanumber.isdigit():
                if len(nacanumber) == 4:
                    constant = int(nacanumber[2:]) * 0.01
            s = lifting_surface.get_section(idx)
            e = s.get_section_element(1)
            ce = e.get_ctigl_section_element()
            ce.set_width(chord)
            ce.set_height(chord * constant)
            center = ce.get_center()
            y += length_
            center.x = x
            center.y = y
            center.z = 0.0
            ce.set_center(center)
            ce.set_profile_uid(f"{profile_}")
            e.set_rotation(tigl3.geometry.CTiglPoint(0, pitch_, 0))
        lifting_surface.set_rotation(
            tigl3.geometry.CTiglPoint(0, pitch_angle, 0))
        for idx in range(1, n_sections + 1):
            s = lifting_surface.get_section(idx)
            e = s.get_section_element(1)
            ce = e.get_ctigl_section_element()
            wires.append(ce.get_wire())
        for l in wires:
            adapt = BRepAdaptor_CompCurve(l)
            curve = Handle_BRepAdaptor_HCompCurve(
                BRepAdaptor_HCompCurve(adapt))
            approx = Approx_Curve3d(curve, 0.001, GeomAbs_C2, 200, 12)
            if (approx.IsDone() and approx.HasResult()):
                curves.append(approx.Curve())

        surface1 = tigl3.surface_factories.interpolate_curves(curves)
        face1 = BRepBuilderAPI_MakeFace(surface1, 1e-6).Face()
        face2 = BRepBuilderAPI_MakeFace(surface1, 1e-6).Face()

        sew = BRepBuilderAPI_Sewing()
        sew.Add(face1)
        sew.Add(face2)
        sew.Perform()
        shape = sew.SewedShape()
        print(shape)

        tds = topods()
        model = BRepBuilderAPI_MakeSolid()
        model.Add(tds.Shell(shape))
        solid = model.Solid()
        print(solid)

        rot_trafo = tigl3.geometry.CTiglTransformation()
        rot_trafo.add_rotation_x(90)

        loft = []
        loft.append(hub.get_loft().shape())
        loft.append(
            tigl3.geometry.CNamedShape(rot_trafo.transform(solid),
                                       "cut").shape())

        if propeller_number_ == 2:
            trafo = tigl3.geometry.CTiglTransformation()
            trafo.add_mirroring_at_xzplane()
            loft.append(
                tigl3.geometry.CNamedShape(trafo.transform(loft[1]),
                                           "cut").shape())
        elif propeller_number_ >= 3:
            delta = 360 / propeller_number_
            for i in range(1, propeller_number_ + 1):
                loft_copy = deepcopy(loft[1])
                trafo = tigl3.geometry.CTiglTransformation()
                trafo.add_rotation_x(delta * i)
                print(delta * i)
                loft.append(
                    tigl3.geometry.CNamedShape(trafo.transform(loft_copy),
                                               "cut").shape())
        builder = BRep_Builder()
        assembly = TopoDS_Compound()
        builder.MakeCompound(assembly)
        for l in loft:
            builder.Add(assembly, l)
        trafo = tigl3.geometry.CTiglTransformation()
        trafo.add_translation(root_le_pos_x_, root_le_pos_y_, root_le_pos_z_)
        assembly = trafo.transform(assembly)

        return [assembly]
Пример #8
0
    def curved_surface(self):
        self.read_parameters()
        n = random.random()
        self.lifting_surface = self.wings.create_wing(f"{n}", 5,
                                                      self.airfoil_type)

        chords = [
            self.section_1_chord_, self.section_2_chord_,
            self.section_3_chord_, self.section_4_chord_, self.section_5_chord_
        ]
        y = [
            self.section_1_y_, self.section_2_y_, self.section_3_y_,
            self.section_4_y_, self.section_5_y_
        ]
        x = [
            self.section_1_x_, self.section_2_x_, self.section_3_x_,
            self.section_4_x_, self.section_5_x_
        ]
        z = [
            self.section_1_z_, self.section_2_z_, self.section_3_z_,
            self.section_4_z_, self.section_5_z_
        ]
        twist = [
            self.section_1_twist_angle_, self.section_2_twist_angle_,
            self.section_3_twist_angle_, self.section_4_twist_angle_,
            self.section_5_twist_angle_
        ]

        profile = self.airfoil_type
        constant = 0.5
        nacanumber = profile.split("naca")[1]
        if nacanumber.isdigit():
            if len(nacanumber) == 4:
                constant = int(nacanumber[2:]) * 0.01
        # decrease section size towards wing tips

        wires = []
        curves = []

        n_sections = self.lifting_surface.get_section_count()

        for idx in range(1, n_sections + 1):
            s = self.lifting_surface.get_section(idx)
            e = s.get_section_element(1)
            ce = e.get_ctigl_section_element()
            ce.set_width(chords[idx - 1])
            ce.set_height(chords[idx - 1] * constant)
            center = ce.get_center()
            center.x = x[idx - 1]
            center.y = y[idx - 1]
            center.z = z[idx - 1]
            ce.set_center(center)

        self.lifting_surface.set_rotation(
            tigl3.geometry.CTiglPoint(self.rot_x_, self.rot_y_, self.rot_z_))
        self.lifting_surface.set_root_leposition(
            tigl3.geometry.CTiglPoint(self.root_le_pos_x_, self.root_le_pos_y_,
                                      self.root_le_pos_z_))
        for idx in range(1, n_sections + 1):
            s = self.lifting_surface.get_section(idx)
            e = s.get_section_element(1)
            ce = e.get_ctigl_section_element()
            wires.append(ce.get_wire())

        for l in wires:
            adapt = BRepAdaptor_CompCurve(l)
            curve = Handle_BRepAdaptor_HCompCurve(
                BRepAdaptor_HCompCurve(adapt))
            approx = Approx_Curve3d(curve, 0.001, GeomAbs_C2, 200, 12)
            if (approx.IsDone() and approx.HasResult()):
                curves.append(approx.Curve())

        surface = tigl3.surface_factories.interpolate_curves(curves)
        sew = BRepBuilderAPI_Sewing()
        face1 = BRepBuilderAPI_MakeFace(surface, 1e-6).Face()
        face2 = BRepBuilderAPI_MakeFace(surface, 1e-6).Face()
        sew.Add(face1)
        sew.Add(face2)
        sew.Perform()
        shape = sew.SewedShape()

        tds = topods()
        model = BRepBuilderAPI_MakeSolid()
        model.Add(tds.Shell(shape))
        solid = model.Solid()
        loft = []
        loft.append(solid)
        if self.xy_mirror_:
            trafo = tigl3.geometry.CTiglTransformation()
            trafo.add_mirroring_at_xyplane()
            loft.append(
                tigl3.geometry.CNamedShape(trafo.transform(loft[0]),
                                           "cut").shape())
        elif self.xz_mirror_:
            trafo = tigl3.geometry.CTiglTransformation()
            trafo.add_mirroring_at_xzplane()
            loft.append(
                tigl3.geometry.CNamedShape(trafo.transform(loft[0]),
                                           "cut").shape())
        elif self.yz_mirror_:
            trafo = tigl3.geometry.CTiglTransformation()
            trafo.add_mirroring_at_yzplane()
            loft.append(
                tigl3.geometry.CNamedShape(trafo.transform(loft[0]),
                                           "cut").shape())
        self.old_profile = self.airfoil_type
        return loft