def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge())

    S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(),
                              gp_Vec(gp_Pnt(0., 0., 0.),
                                     gp_Pnt(0., 100., 0.)))
    display.EraseAll()
    #    display.DisplayShape(S.Shape())

    W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.),
                                                        gp_Pnt(100., 45., 50.)).Edge())

    aplane = Geom_Plane(0., 1., 0., -45.)

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(),
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
예제 #2
0
def project_point_on_plane(plane: Geom_Plane, point: gp_Pnt) -> gp_Pnt:
    """
    project point on plane
    @param plane: Geom_Plane
    @param point: gp_Pnt
    """
    pl = plane.Pln()
    aa, bb = projlib_Project(pl, point).Coord()
    point = plane.Value(aa, bb)
    return point
예제 #3
0
def reflect(p0, v0, ax):
    ray = gp_Lin(p0, vec_to_dir(v0))
    intersection = IntAna_IntConicQuad(ray, gp_Pln(ax), precision_Angular(),
                                       precision_Confusion())
    p1 = intersection.Point(1)
    vx, vy = gp_Vec(1, 0, 0), gp_Vec(0, 1, 0)
    handle = Geom_Plane(ax)
    handle.D1(0.5, 0.5, gp_Pnt(), vx, vy)
    vz = vx.Crossed(vy)
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz)))
    return p1, v1
예제 #4
0
def get_angle(ax, v0, v1):
    p0 = ax.Location()
    dx = ax.XDirection()
    dy = ax.YDirection()
    dz = ax.Direction()
    pl_x = Geom_Plane(p0, dy)
    pl_y = Geom_Plane(p0, dx)
    v0_x = proj_vec(pl_x, p0, v0)
    v1_x = proj_vec(pl_x, p0, v1)
    v0_y = proj_vec(pl_y, p0, v0)
    v1_y = proj_vec(pl_y, p0, v1)
    return v1_x.Angle(v0_x), v1_y.Angle(v0_y)
예제 #5
0
def faircurve(event=None):
    pt1 = gp_Pnt2d(0., 0.)
    pt2 = gp_Pnt2d(0., 120.)
    height = 100.
    pl = Geom_Plane(gp_Pln())
    for i in range(0, 40):
        # TODO: the parameter slope needs to be visualized
        slope = i / 100.
        bc = batten_curve(pt1, pt2, height, slope, math.radians(i),
                          math.radians(-i))
        display.EraseAll()
        edge = BRepBuilderAPI_MakeEdge(bc, pl.GetHandle()).Edge()
        display.DisplayShape(edge, update=True)
        time.sleep(0.21)
예제 #6
0
    def _BuildSpars(self, ChordFactor, ScaleFactor):

        LE = self._GenerateLeadingEdge()

        self.NoStiffners = self.NoStiffnersLE + self.NoStiffnersTE

        SectionsProfiles = []
        SparLEFullWing = []
        SparTEFullWing = []
        SparMIDFullWing = []

        SparLEup = []
        SparLEdown = []
        SparMIDup = []
        SparMIDdown = []
        SparTEup = []
        SparTEdown = []

        planeStiffEps = []

        PStiffUpFullWing = []
        PStiffDownFullWing = []
        StringerUpFullWing = []
        StringerDownFullWing = []

        EpsS = np.linspace(0, 1, self.SegmentNoLoft + 1)
        SectionsProfiles = [
            self.AirfoilFunct(EpsS[d], LE[d], self.ChordFunct, ChordFactor,
                              self.DihedralFunct, self.TwistFunct).Curve
            for d in xrange(self.SegmentNoLoft + 1)
        ]

        # Stringers generation
        h = 0
        cont3 = 0
        PointsUp = []
        PointsDown = []
        PointsMIDup = []
        PointsMIDdown = []

        for SecR in SectionsProfiles:
            ChordLenght = ((ChordFactor * self.ChordFunct(EpsS[h])) /
                           np.cos(np.radians(self.TwistFunct(EpsS[h]))))
            LELengthX = LE[h, 0]
            LEplanePositionX = (self.PositionLESpar * ChordLenght) * np.cos(
                self.TwistFunct(EpsS[h])) + LELengthX
            TEplanePositionX = (self.PositionTESpar * ChordLenght) * np.cos(
                self.TwistFunct(EpsS[h])) + LELengthX
            MIDplanePositionX = (self.PositionMIDSpar * ChordLenght) * np.cos(
                self.TwistFunct(EpsS[h])) + LELengthX

            planeLEi = Geom_Plane(
                gp_Pln(gp_Pnt(LEplanePositionX, 0., 0.),
                       gp_Dir(gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(1., 0., 0.)))))
            planeMIDi = Geom_Plane(
                gp_Pln(gp_Pnt(MIDplanePositionX, 0., 0.),
                       gp_Dir(gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(1., 0., 0.)))))
            planeTEi = Geom_Plane(
                gp_Pln(gp_Pnt(TEplanePositionX, 0., 0.),
                       gp_Dir(gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(1., 0., 0.)))))

            #            planeLEi.Rotate(gp_OY(), -np.radians(self.TwistFunct(EpsS[h])))
            #            planeMIDi.Rotate(gp_OY(), -np.radians(self.TwistFunct(EpsS[h])))
            #            planeTEi.Rotate(gp_OY(), -np.radians(self.TwistFunct(EpsS[h])))

            SegmentStiffLE = (MIDplanePositionX -
                              LEplanePositionX) / (self.NoStiffnersLE - 1)
            SegmentStiffTE = (TEplanePositionX -
                              MIDplanePositionX) / (self.NoStiffnersTE)
            NoStiffners = self.NoStiffnersLE + self.NoStiffnersTE

            PStiffUpi = []
            PStiffDowni = []
            PosStiffiEps = LEplanePositionX

            for g in xrange(NoStiffners):

                planeStiffEps = Geom_Plane(
                    gp_Pln(
                        gp_Pnt(PosStiffiEps, 0., 0.),
                        gp_Dir(gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(1., 0.,
                                                                 0.)))))

                StiffiEps = GeomAPI_IntCS(SecR, planeStiffEps.GetHandle())
                with act.assert_isdone(StiffiEps,
                                       'failed to calculate intersection'):
                    nb_results = StiffiEps.NbPoints()
                    if nb_results == 1:
                        return StiffiEps.Point(1)
                    #print("One point intersection")
                    elif nb_results >= 1:
                        #print("More than one intersection point")
                        PStiff = []
                        for i in range(1, nb_results + 1):
                            PStiff.append(StiffiEps.Point(i))

                    else:
                        return None
                PStiffUpi.append(PStiff[0])
                PStiffDowni.append(PStiff[nb_results - 1])
                if g <= self.NoStiffnersLE - 2:
                    PosStiffiEps = PosStiffiEps + SegmentStiffLE
                else:
                    PosStiffiEps = PosStiffiEps + SegmentStiffTE

                PointsUp.append(PStiff[0])
                PointsDown.append(PStiff[nb_results - 1])

            SparLEi = GeomAPI_IntCS(SecR, planeLEi.GetHandle())
            with act.assert_isdone(SparLEi,
                                   'failed to calculate intersection'):
                nb_results = SparLEi.NbPoints()
                #print(nb_results)
                if nb_results == 1:
                    return SparLEi.Point(1)
                #print("One point intersection")
                elif nb_results >= 1:
                    #print("More than one intersection point")
                    PLE = []
                    for i in range(1, nb_results + 1):
                        PLE.append(SparLEi.Point(i))

                else:
                    return None

            SegLE = GC_MakeSegment(PLE[0], PLE[nb_results - 1]).Value()

            SparMIDi = GeomAPI_IntCS(SecR, planeMIDi.GetHandle())
            with act.assert_isdone(SparMIDi,
                                   'failed to calculate intersection'):
                nb_results = SparMIDi.NbPoints()
                #print(nb_results)
                if nb_results == 1:
                    return SparMIDi.Point(1)
                #print("One point intersection")
                elif nb_results >= 1:
                    #print("More than one intersection point")
                    PMID = []
                    for i in range(1, nb_results + 1):
                        PMID.append(SparMIDi.Point(i))

                else:
                    return None

            SegMID = GC_MakeSegment(PMID[0], PMID[nb_results - 1]).Value()
            PointsMIDup.append(PMID[0])
            PointsMIDdown.append(PMID[nb_results - 1])

            SparTEi = GeomAPI_IntCS(SecR, planeTEi.GetHandle())
            with act.assert_isdone(SparTEi,
                                   'failed to calculate intersection'):
                nb_results = SparTEi.NbPoints()
                #print(nb_results)
                if nb_results == 1:
                    return SparTEi.Point(1)
                #print("One point intersection")
                elif nb_results >= 1:
                    #print("More than one intersection point")
                    PTE = []
                    for i in range(1, nb_results + 1):
                        PTE.append(SparTEi.Point(i))

                else:
                    return None

            SegTE = GC_MakeSegment(PTE[0], PTE[nb_results - 1]).Value()

            #print(len(SparMIDdown))
            #print(len(SparMIDup))
            #print(len(SparLEup))
            #print(len(SparLEdown))
            SparLEFullWing.append(SegLE)
            SparMIDFullWing.append(SegMID)
            SparTEFullWing.append(SegTE)
            SparLEup.append(PLE[0])
            SparLEdown.append(PLE[nb_results - 1])
            SparMIDup.append(PMID[0])
            #print(PMID[nb_results-1])
            SparMIDdown.append(PMID[nb_results - 1])
            SparTEup.append(PTE[0])
            SparTEdown.append(PTE[nb_results - 1])
            PStiffUpFullWing.append(PStiffUpi)
            PStiffDownFullWing.append(PStiffDowni)
            cont3 = cont3 + 1

            h = h + 1

# Method to create spars - VIA SEGMENTS
#LE
        LoftLESparFullWing = []
        for iii in xrange(0,
                          len(PointsUp) - 2 * (self.NoStiffners - 1),
                          self.NoStiffners):
            SegUp = GC_MakeSegment(PointsUp[iii],
                                   PointsUp[iii + self.NoStiffners]).Value()
            SegDown = GC_MakeSegment(PointsDown[iii + self.NoStiffners],
                                     PointsDown[iii]).Value()
            SegSide1 = GC_MakeSegment(PointsDown[iii], PointsUp[iii]).Value()
            SegSide2 = GC_MakeSegment(PointsUp[iii + self.NoStiffners],
                                      PointsDown[iii +
                                                 self.NoStiffners]).Value()
            EdgeSegUp = act.make_edge(SegUp)
            EdgeSegDown = act.make_edge(SegDown)
            EdgeSide1 = act.make_edge(SegSide1)
            EdgeSide2 = act.make_edge(SegSide2)
            WireSparLE = act.make_wire(
                [EdgeSide1, EdgeSegUp, EdgeSide2, EdgeSegDown])
            FaceSparLEi = act.make_face(WireSparLE)

            if self.ScaleFactor != 1:
                Origin = gp_Pnt(0., 0., 0.)
                FaceSparLE = act.scale_uniformal(FaceSparLEi, Origin,
                                                 self.ScaleFactor)
                LoftLESparFullWing.append(FaceSparLE)
#MID
        LoftMIDSparFullWing = []
        for iii in xrange(0, self.SegmentNoLoft):
            SegUp = GC_MakeSegment(PointsMIDup[iii],
                                   PointsMIDup[iii + 1]).Value()
            SegDown = GC_MakeSegment(PointsMIDdown[iii + 1],
                                     PointsMIDdown[iii]).Value()
            SegSide1 = GC_MakeSegment(PointsMIDdown[iii],
                                      PointsMIDup[iii]).Value()
            SegSide2 = GC_MakeSegment(PointsMIDup[iii + 1],
                                      PointsMIDdown[iii + 1]).Value()
            EdgeSegUp = act.make_edge(SegUp)
            EdgeSegDown = act.make_edge(SegDown)
            EdgeSide1 = act.make_edge(SegSide1)
            EdgeSide2 = act.make_edge(SegSide2)
            WireSparMID = act.make_wire(
                [EdgeSide1, EdgeSegUp, EdgeSide2, EdgeSegDown])
            FaceSparMIDi = act.make_face(WireSparMID)

            if self.ScaleFactor != 1:
                Origin = gp_Pnt(0., 0., 0.)
                FaceSparMID = act.scale_uniformal(FaceSparMIDi, Origin,
                                                  self.ScaleFactor)
                LoftMIDSparFullWing.append(FaceSparMID)

#TE
        LoftTESparFullWing = []
        for iii in xrange(self.NoStiffners - 1,
                          len(PointsUp) - (self.NoStiffners),
                          self.NoStiffners):
            SegUp = GC_MakeSegment(PointsUp[iii],
                                   PointsUp[iii + self.NoStiffners]).Value()
            SegDown = GC_MakeSegment(PointsDown[iii + self.NoStiffners],
                                     PointsDown[iii]).Value()
            SegSide1 = GC_MakeSegment(PointsDown[iii], PointsUp[iii]).Value()
            SegSide2 = GC_MakeSegment(PointsUp[iii + self.NoStiffners],
                                      PointsDown[iii +
                                                 self.NoStiffners]).Value()
            EdgeSegUp = act.make_edge(SegUp)
            EdgeSegDown = act.make_edge(SegDown)
            EdgeSide1 = act.make_edge(SegSide1)
            EdgeSide2 = act.make_edge(SegSide2)
            WireSparTE = act.make_wire(
                [EdgeSide1, EdgeSegUp, EdgeSide2, EdgeSegDown])
            FaceSparTEi = act.make_face(WireSparTE)

            if self.ScaleFactor != 1:
                Origin = gp_Pnt(0., 0., 0.)
                FaceSparTE = act.scale_uniformal(FaceSparTEi, Origin,
                                                 self.ScaleFactor)
                LoftTESparFullWing.append(FaceSparTE)

        for g in range(self.NoStiffners):
            for gg in range(self.SegmentNoLoft):
                SegStringerUp = GC_MakeSegment(
                    PointsUp[gg * self.NoStiffners + g],
                    PointsUp[gg * self.NoStiffners + g +
                             self.NoStiffners]).Value()
                SegStringerDown = GC_MakeSegment(
                    PointsDown[gg * self.NoStiffners + g],
                    PointsDown[gg * self.NoStiffners + g +
                               self.NoStiffners]).Value()
                EdgeUp = act.make_edge(SegStringerUp)
                EdgeDown = act.make_edge(SegStringerDown)
                WireStringUp = act.make_wire(EdgeUp)
                WireStringDown = act.make_wire(EdgeDown)
                if self.ScaleFactor != 1:
                    Origin = gp_Pnt(0., 0., 0.)
                    StrUpFullWingi = act.scale_uniformal(
                        WireStringUp, Origin, self.ScaleFactor)
                    StrDownFullWingi = act.scale_uniformal(
                        WireStringDown, Origin, self.ScaleFactor)
                #print('hello')
            #print(self.ScaleFactor)
                StringerUpFullWing.append(StrUpFullWingi)
                StringerDownFullWing.append(StrDownFullWingi)

        return LoftLESparFullWing, LoftTESparFullWing, LoftMIDSparFullWing, StringerUpFullWing, StringerDownFullWing, PointsUp, PointsDown
n_edges = 0

# Explore the faces of the shape (these are known to be named)
exp = TopExp_Explorer(shape, TopAbs_FACE)
while exp.More():
    s = exp.Current()

    tp = Topo(s)
    for face in tp.faces():
        ifcopenshell.geom.utils.display_shape(face)
        for edge in list(Topo(face).edges()):

            curve_handle, first, last = BRep_Tool.CurveOnSurface(
                edge, section_face)

            plane = Geom_Plane(section_plane)
            e = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first,
                                        last).Edge()
            #            handle_adaptor = Geom2dAdaptor_Curve(curve_handle)
            curve_adapt = BRepAdaptor_Curve(e)

            if curve_adapt.GetType() == GeomAbs_Line:
                v = list(Topo(e).vertices())
                y1, z1 = BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(v[0]).Z()
                y2, z2 = BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(v[-1]).Z()

                plt.plot([y1, y2], [z1, z2], color="red", alpha=0.2)
                ifcopenshell.geom.utils.display_shape(e, clr=RED)

#                line = curve_adapt.Line()
##                r = GCPnts_AbscissaPoint(handle_adaptor)
예제 #8
0
    def BuildFuselageOML(self, Max_attempt=5):
        """Builds the Fuselage outer mould line
        Notes
        -----
        It is not expected that users will interact with this directly. Use
        the Fuslage class initialisation fuction instead
        """
        NetworkSrfSettings = np.array([[35, 20, 15, 15,
                                        20], [35, 30, 15, 5, 20],
                                       [35, 20, 15, 2,
                                        20], [30, 30, 15, 2, 20],
                                       [30, 20, 15, 2,
                                        20], [25, 20, 15, 2, 20],
                                       [20, 20, 15, 2, 20],
                                       [15, 20, 15, 2, 20]])
        HStarboardCurve, HPortCurve, FSVUCurve, FSVLCurve, FSVMeanCurve, \
            NoseEndX, TailStartX, EndX =                               \
            self.FuselageLongitudinalGuideCurves(self.NoseLengthRatio,
                                                  self.TailLengthRatio)

        # Returning the PortCurve and StarboardCurve as Geom_BSplineCurve
        # makes kernel freeze in pythonocc 0.16.5, so needed to carry around a
        # handle instead - very strange bug!
        PortCurve = HPortCurve.GetObject()
        StarboardCurve = HStarboardCurve.GetObject()

        # Compute the stern point coordinates of the fuselage
        Pu = FSVUCurve.EndPoint()
        Pl = FSVLCurve.EndPoint()
        self.SternPoint = gp_Pnt(Pu.X(), Pu.Y(), 0.5 * (Pu.Z() + Pl.Z()))
        Pu = FSVUCurve.StartPoint()
        Pl = FSVLCurve.StartPoint()
        self.BowPoint = gp_Pnt(Pu.X(), Pu.Y(), 0.5 * (Pu.Z() + Pl.Z()))

        i_attempt = 0
        while i_attempt < Max_attempt:
            i_attempt = i_attempt + 1
            print("Surface fit attempt {}".format(i_attempt))

            # Construct array of cross section definition frames
            SX0 = 0
            SX1 = 0.04 * NoseEndX
            SX2 = SX1 + 0.25 * NoseEndX
            SX3 = NoseEndX
            SX4 = TailStartX
            SX5 = EndX

            Step01, Step12, Step23, Step34, Step45 = \
                NetworkSrfSettings[i_attempt - 1]

            print("""Attempting loft surface fit with network density
                setup {}""".format(NetworkSrfSettings[i_attempt][:]))
            Stations01 = np.linspace(SX0, SX1, max([Step01, 2]))
            Stations12 = np.linspace(SX1, SX2, max([Step12, 2]))
            Stations23 = np.linspace(SX2, SX3, max([Step23, 2]))
            Stations34 = np.linspace(SX3, SX4, max([Step34, 2]))
            Stations45 = np.linspace(SX4, SX5, max([Step45, 2]))

            StationRange = np.hstack([
                Stations01[:-1], Stations12[:-1], Stations23[:-1],
                Stations34[:-1], Stations45
            ])
            C = []
            FirstTime = True

            for i, XStation in enumerate(StationRange[1:]):
                # Create plane normal to x direction
                P = Geom_Plane(
                    gp_Pln(gp_Pnt(XStation, 0, 0), gp_Dir(gp_Vec(1, 0, 0))))
                # Make into a face for visualisation/debugging
                try:
                    IPoint2 = act.points_from_intersection(P, FSVUCurve)
                    IPoint3 = act.points_from_intersection(P, PortCurve)
                    IPoint4 = act.points_from_intersection(P, FSVLCurve)
                    IPoint1 = act.points_from_intersection(P, StarboardCurve)
                    #
                    IPointCentre = act.points_from_intersection(
                        P, FSVMeanCurve)
                except RuntimeError:
                    print(
                        "Intersection Points at Section X={} Not Found".format(
                            XStation))
                    print("Skipping this plane location")
                    continue

                PseudoDiameter = abs(IPoint4.Z() - IPoint2.Z())
                if self.CylindricalMidSection and\
                        NoseEndX < XStation < TailStartX:
                    print("Enforcing circularity in the central section...")
                    if FirstTime:
                        PseudoRadius = PseudoDiameter / 2.
                        FirstTime = False
                    PseudoRadius = PseudoDiameter / 2.
                    # Note: Add Circle with radius PseudoRadius at Pc
                    from OCC.GC import GC_MakeCircle
                    c = GC_MakeCircle(gp_Ax2(IPointCentre, gp_Dir(1, 0, 0)),
                                      PseudoRadius).Value()

                else:
                    # Set the tangents at each point for interpolation:
                    # assume that these are solely in 1 axis as points lie
                    # extremities of an elliptical shape
                    tangents = np.array([[0, -1, 0], [0, 0, -1], [0, 1, 0],
                                         [0, 0, 1]])
                    c = act.points_to_bspline(
                        [IPoint2, IPoint3, IPoint4, IPoint1],
                        periodic=True,
                        scale=False,
                        tangents=tangents)

                C.append(c)

#             Fit fuselage external surface
            sections = [act.make_wire(act.make_edge(curve)) for curve in C]
            guides = ([
                FSVUCurve.GetHandle(),
                PortCurve.GetHandle(),
                FSVLCurve.GetHandle(),
                StarboardCurve.GetHandle()
            ])
            guides = [act.make_wire(act.make_edge(guide)) for guide in guides]
            self._Lguides = guides
            self._Csections = sections
            self._NoseVertex = act.make_vertex(self.BowPoint)
            try:
                OMLSurf = \
                    act.AddSurfaceLoft(C, first_vertex=self._NoseVertex,
                                       continuity=GeomAbs_C2, solid=False)
            except:
                OMLSurf = None

            if OMLSurf is not None:
                print("Network surface fit succesful on attempt {}\n".format(
                    i_attempt))
                self.AddComponent(OMLSurf, 'OML')
                return None

#         If all attempts at fitting a network surface failed, we attempt a
#            Pipe Shell:
        if OMLSurf is None:
            print("""Failed to fit network surface to the external shape of the
                fuselage""")
            print("""Attempting alternative fitting method, quality likely to
                be low...""")

            try:
                OMLSurf = act.make_pipe_shell(C)
                self.AddComponent(OMLSurf, 'OML')
            except:
                raise (RuntimeError, "Could not produce a valid OML surface")

#    Note: The following is the last resort surface fit from Rhino Airconics
#                And currently is not available in OCC Airconics:

#            SimplificationReqd = True # Enforce simplification
#            if not(FuselageOMLSurf):
#                print "Alternative fitting method failed too. Out of ideas."
#
#        if FuselageOMLSurf and SimplificationReqd:
#            rs.UnselectAllObjects()
#            rs.SelectObject(FuselageOMLSurf)
#            ToleranceStr = str(0.0005*EndX)
#            print "Smoothing..."
#            rs.Command("FitSrf " + ToleranceStr)
#            rs.UnselectAllObjects()
#

# Shouldnt get here
        return None
예제 #9
0
def EdgeOnSurface(edge, section_plane, lim_coord1, lim_coord2, XYZ):

    section_face = BRepBuilderAPI_MakeFace(section_plane, lim_coord1[0],
                                           lim_coord1[1], lim_coord2[0],
                                           lim_coord2[1]).Face()
    curve_handle, first, last = BRep_Tool.CurveOnSurface(edge, section_face)

    plane = Geom_Plane(section_plane)
    edge_on_surface = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(),
                                              first, last).Edge()
    curve_adaptor = BRepAdaptor_Curve(edge_on_surface)

    if curve_adaptor.GetType() == GeomAbs_Line:

        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        obj = Line3D(v1, v2)

    elif curve_adaptor.GetType() == GeomAbs_Circle:
        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        start = [v1[i] for i in range(len(XYZ)) if XYZ[i]]
        end = [v2[i] for i in range(len(XYZ)) if XYZ[i]]

        circle = curve_adaptor.Circle()
        center = []
        for i in range(len(XYZ)):
            if XYZ[i] and i == 0:
                center.append(circle.Location().X())
            elif XYZ[i] and i == 1:
                center.append(circle.Location().Y())
            elif XYZ[i] and i == 2:
                center.append(circle.Location().Z())
            else:
                center.append(0.5 * (v1[i] + v2[i]))
        radius = circle.Radius()

        vec_start = (start[0] - center[0], start[1] - center[1])
        vec_end = (end[0] - center[0], end[1] - center[1])

        t1 = angle360(vec_start)
        t2 = angle360(vec_end)

        if not XYZ[0]:
            axis = circle.Axis().Direction().X()
        elif not XYZ[1]:
            axis = circle.Axis().Direction().Y()
        elif not XYZ[2]:
            axis = circle.Axis().Direction().Z()

        if axis < 0:
            t1, t2 = t2, t1

        obj = Arc3D(v1, v2, t1, t2, center, radius)

    elif curve_adaptor.GetType() == GeomAbs_BSplineCurve:

        bspline = curve_adaptor.BSpline().GetObject()
        degree = bspline.Degree()
        knots = [
            bspline.Knot(index) for index in range(1,
                                                   bspline.NbKnots() + 1)
        ]
        mults = [
            bspline.Multiplicity(index)
            for index in range(1,
                               bspline.NbKnots() + 1)
        ]
        poles = [(bspline.Pole(index).X(), bspline.Pole(index).Y(),
                  bspline.Pole(index).Z())
                 for index in range(1,
                                    bspline.NbPoles() + 1)]
        periodic = bspline.IsPeriodic()
        obj = BSpline3D(poles, mults, knots, degree, periodic)

    else:

        print(curve_adaptor.GetType())
        warnings.warn("Not recognized curve!")

    return obj
예제 #10
0
 def CreateConstructionGeometry(self):
     """
     Creates the plane and vector used for projecting wetted area
     """
     self.XoY_Plane = Geom_Plane(gp_Ax3(gp_XOY()))
     self.ProjVectorZ = gp_Dir(0, 0, 1)