示例#1
0
def wire_triangle2():
    '''
        isosceles triangle
    output
        w:  TopoDS_Wire
    '''
    ang = random.gauss(2 * pi / 3, pi / 6)
    amin = pi / 3
    amax = 5 * pi / 6
    if ang > amax:
        ang = amax
    if ang < amin:
        ang = amin
    pt1 = gp_Pnt(-1, 0, 0)
    pt2 = gp_Pnt(-1, 0, 0)
    pt2.Rotate(gp_OZ(), ang)
    pt3 = gp_Pnt(-1, 0, 0)
    pt3.Rotate(gp_OZ(), -ang)

    ed1 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt1, pt2).Value()).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt2, pt3).Value()).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt3, pt1).Value()).Edge()

    wire = BRepBuilderAPI_MakeWire(ed1, ed2, ed3).Wire()

    return wire
 def test_memory_handle_getobject(self):
     """
     See https://github.com/tpaviot/pythonocc-generator/pull/24
     This commit tries to fix the issue tpaviot/pythonocc-core#292.
     When we got a handle from ann API function and called GetObject()
     the lifetime of the object was determined only by the handle.
     This lead to crashes, when only a reference to the object was stored.
     The commit registers the handle with its object to prevent premature
     destruction.
     This test case ensures everything is ok. Following lines used to crash
     on pythonocc-0.16.5
     """
     a = gp_Pnt(0., 0., 0.)
     b = gp_Pnt(100., 100., 100.)
     line3 = GC_MakeSegment(a, b).Value().GetObject()
     assert line3.FirstParameter() == 0.
     assert GC_MakeSegment(a, b).Value().GetObject().FirstParameter() == 0.
     assert GC_MakeSegment(a, b).Value().GetObject().GetHandle().GetObject(
     ).GetHandle().GetObject().FirstParameter() == 0.
     assert b.IsEqual(line3.EndPoint(), 0.01)
     assert b.IsEqual(
         GC_MakeSegment(a, b).Value().GetObject().EndPoint(), 0.01)
     assert b.IsEqual(
         GC_MakeSegment(a, b).Value().GetObject().GetHandle().GetObject().
         GetHandle().GetObject().EndPoint(), 0.01)
示例#3
0
    def __init__(
        self,
        HChord=0,
        CentreLocation=[0, 0, 0],
        ScarfAngle=3,
        HighlightRadius=1.45,
        MeanNacelleLength=5.67,
        construct_geometry=True,
    ):

        if HChord == 0:
            print("No HChord specified to fit engine to: creating default")
            SP = gp_Pnt(MeanNacelleLength * 2.2, 0, HighlightRadius * 1.75)
            EP = gp_Pnt(MeanNacelleLength * 0.5, 0, HighlightRadius * 1.75)
            HChord = GC_MakeSegment(SP, EP).Value()

        # Add all kwargs as attributes
        super(Engine, self).__init__(
            components={},
            construct_geometry=construct_geometry,
            HChord=HChord,
            CentreLocation=CentreLocation,
            ScarfAngle=ScarfAngle,
            HighlightRadius=HighlightRadius,
            MeanNacelleLength=MeanNacelleLength,
        )
示例#4
0
def CutSect(Shape, SpanStation):
    """
    Parameters
    ----------
    Shape : TopoDS_Shape
        The Shape to find planar cut section (parallel to xz plane)

    SpanStation : scalar in range (0, 1)
        y-direction location at which to cut Shape

    Returns
    -------
    Section : result of OCC.BRepAlgoAPI.BRepAlgoAPI_Section (TopoDS_Shape)
        The cut section of shape given a cut plane parallel to xz at input
        Spanstation.

    Chord : result of OCC.GC.GC_MakeSegment.Value (Geom_TrimmedCurve)
        The Chord line between x direction extremeties
    """
    (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents([Shape])

    YStation = Ymin + (Ymax - Ymin) * SpanStation
    OriginX = Xmin - 1
    OriginZ = Zmin - 1

    P = gp_Pln(gp_Pnt(OriginX, YStation, OriginZ), gp_Dir(gp_Vec(0, 1, 0)))
    # Note: using 2*extents here as previous +1 trimmed plane too short
    CutPlaneSrf = make_face(P, 0, Zmax + 2, 0, Xmax + 2)

    I = BRepAlgoAPI_Section(Shape, CutPlaneSrf)
    I.ComputePCurveOn1(True)
    I.Approximation(True)
    I.Build()
    Section = I.Shape()

    (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents([Section])

    #     Currently assume only one edge exists in the intersection:
    exp = TopExp_Explorer(Section, TopAbs_EDGE)
    edge = topods_Edge(exp.Current())

    #    Find the apparent chord of the section (that is, the line connecting the
    #    fore most and aftmost points on the curve
    DivPoints = Uniform_Points_on_Curve(edge, 200)

    Xs = np.array([pt.X() for pt in DivPoints])

    min_idx = np.argmin(Xs)
    LeadingPoint = gp_Pnt(Xs[min_idx], DivPoints[min_idx].Y(),
                          DivPoints[min_idx].Z())

    max_idx = np.argmax(Xs)
    TrailingPoint = gp_Pnt(Xs[max_idx], DivPoints[max_idx].Y(),
                           DivPoints[max_idx].Z())

    HChord = GC_MakeSegment(TrailingPoint, LeadingPoint).Value()
    #    Chord = HChord.GetObject()
    return Section, HChord
示例#5
0
 def update_shape(self, change):
     d = self.declaration
     points = self.get_points()
     if len(points) > 1:
         edges = []
         for i in range(1, len(points)):
             segment = GC_MakeSegment(points[i - 1], points[i]).Value()
             edges.append(BRepBuilderAPI_MakeEdge(segment))
         self.shape = edges
示例#6
0
def wire_rectangle():
    '''
    output
        w:  TopoDS_Wire
    '''
    pt1 = gp_Pnt(0, 1, 0)
    pt2 = gp_Pnt(-1, 0, 0)
    pt3 = gp_Pnt(0, -1, 0)
    pt4 = gp_Pnt(1, 0, 0)

    ed1 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt1, pt2).Value()).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt2, pt3).Value()).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt3, pt4).Value()).Edge()
    ed4 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt4, pt1).Value()).Edge()

    wire = BRepBuilderAPI_MakeWire(ed1, ed2, ed3, ed4).Wire()

    return wire
示例#7
0
 def create_shape(self):
     d = self.declaration
     points = [gp_Pnt(*p) for p in d.points]
     if len(points) < 2:
         raise ValueError("A segment requires at least two points")
     edges = []
     for i in range(1, len(points)):
         segment = GC_MakeSegment(points[i - 1], points[i]).Value()
         edges.append(BRepBuilderAPI_MakeEdge(segment))
     self.shape = edges
示例#8
0
def wire_triangle3():
    '''
    equal sided triangle, centered at origin
    output
        w:  TopoDS_Wire
    '''
    pt1 = gp_Pnt(-1, 0, 0)
    pt2 = gp_Pnt(-1, 0, 0)
    pt2.Rotate(gp_OZ(), 2 * pi / 3)
    pt3 = gp_Pnt(-1, 0, 0)
    pt3.Rotate(gp_OZ(), 4 * pi / 3)

    ed1 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt1, pt2).Value()).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt2, pt3).Value()).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt3, pt1).Value()).Edge()

    wire = BRepBuilderAPI_MakeWire(ed1, ed2, ed3).Wire()

    return wire
示例#9
0
    def _TransformAirfoil(self):
        """Given a normal airfoil, nose in origin, chord along
        x axis, applies rotations, translation and (soon) smoothing
        """
        # TODO: Smoothing
        #        for i in range(self.SmoothingIterations):
        #            rs.FairCurve(self.Curve)

        # Can assume that the chord is from 0,0,0 to 1,0,0 before translation
        h_ChordLine = GC_MakeSegment(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Value()
        ChordLine = h_ChordLine.GetObject()

        Curve = self.Curve.GetObject()

        #        Scaling:
        Curve.Scale(gp_Pnt(0, 0, 0), self.ChordLength)
        ChordLine.Scale(gp_Pnt(0, 0, 0), self.ChordLength)

        #        Rotations - Note that direction is opposite to Rhino
        #        Dihedral:
        if self.Rotation:
            Curve.Rotate(gp_OX(), np.radians(self.Rotation))
            ChordLine.Rotate(gp_OX(), np.radians(self.Rotation))

#        Twist:
        if self.Twist:
            Curve.Rotate(gp_OY(), -np.radians(self.Twist))
            ChordLine.Rotate(gp_OY(), -np.radians(self.Twist))

#        Translation:
#        self.Curve = Handle_Geom_BSplineCurve_DownCast(Curve.Translated(
#                                                        gp_Vec(*self.LE))
#                                                       )
        Curve.Translate(gp_Vec(*self.LE))
        ChordLine.Translate(gp_Vec(*self.LE))

        self.ChordLine = ChordLine.GetHandle()

        return None
示例#10
0
    def _BuildPanels(self, ChordFactor, ScaleFactor):

        LESpar, TESpar, MIDSpar, StringerUp, StringerDown, PointsUp, PointsDown = self._BuildSpars(
            self.ChordFactor, self.ScaleFactor)
        PanelUp = []
        PanelDown = []

        cont = 1
        for ii in range(0, len(PointsUp) - self.NoStiffners - 1):
            if cont == self.NoStiffners:
                cont = 0
            else:
                cont = cont

                # Panel from segments
                SegH1 = GC_MakeSegment(
                    PointsUp[ii], PointsUp[ii + self.NoStiffners]).Value()
                SegH2 = GC_MakeSegment(PointsUp[ii + 1],
                                       PointsUp[ii + self.NoStiffners +
                                                1]).Value()
                SegV1 = GC_MakeSegment(PointsUp[ii], PointsUp[ii + 1]).Value()
                SegV2 = GC_MakeSegment(PointsUp[ii + self.NoStiffners],
                                       PointsUp[ii + self.NoStiffners +
                                                1]).Value()
                EdgeHUp1 = act.make_edge(SegH1)
                EdgeHUp2 = act.make_edge(SegH2)
                EdgeVUp1 = act.make_edge(SegV1)
                EdgeVUp2 = act.make_edge(SegV2)
                WirePanelUp = act.make_wire(
                    [EdgeHUp1, EdgeVUp1, EdgeHUp2, EdgeVUp2])
                PanelUpi = act.make_face(WirePanelUp)
                # In this way the pannel will be ordered in alternance between upper and lower surface
                SegH1 = GC_MakeSegment(
                    PointsDown[ii], PointsDown[ii + self.NoStiffners]).Value()
                SegH2 = GC_MakeSegment(PointsDown[ii + 1],
                                       PointsDown[ii + self.NoStiffners +
                                                  1]).Value()
                SegV1 = GC_MakeSegment(PointsDown[ii],
                                       PointsDown[ii + 1]).Value()
                SegV2 = GC_MakeSegment(PointsDown[ii + self.NoStiffners],
                                       PointsDown[ii + self.NoStiffners +
                                                  1]).Value()
                EdgeHUp1 = act.make_edge(SegH1)
                EdgeHUp2 = act.make_edge(SegH2)
                EdgeVUp1 = act.make_edge(SegV1)
                EdgeVUp2 = act.make_edge(SegV2)
                WirePanelDown = act.make_wire(
                    [EdgeHUp1, EdgeVUp1, EdgeHUp2, EdgeVUp2])
                PanelDowni = act.make_face(WirePanelDown)

                if self.ScaleFactor != 1:
                    Origin = gp_Pnt(0., 0., 0.)
                    PanelUpi = act.scale_uniformal(PanelUpi, Origin,
                                                   self.ScaleFactor)
                    PanelDowni = act.scale_uniformal(PanelDowni, Origin,
                                                     self.ScaleFactor)

                PanelUp.append(PanelUpi)
                PanelDown.append(PanelDowni)
            cont = cont + 1

        return PanelUp, PanelDown
示例#11
0
    def _BuildRibs(self, ChordFactor, ScaleFactor):
        """Generates Ribs surface along the wingspan, given the general,
        nondimensional parameters of the object (variations of chord length,
        dihedral, etc.) and the two scaling factors.

        Parameters
        ----------
        ChordFactor - float
            Factor againt which the standard shape is scaled in the chordwise
            direction
        ScaleFactor - float
            Factor againt which the standard shape is scaled in the world
            coordinates

        Returns
        -------
        Ribs : TopoDS_Shape
            The generated Ribs surface
        """
        SectionsRibs = []
        RibsFace = []

        Step = (self.SegmentNoLoft) / (self.NoRibs - 1)
        LEPointsR = self._GenerateLeadingEdge()
        Eps = np.linspace(0, 1, self.SegmentNoLoft + 1)
        SectionsRibs = [
            self.AirfoilFunct(Eps[i], LEPointsR[i], self.ChordFunct,
                              ChordFactor, self.DihedralFunct,
                              self.TwistFunct).Curve
            for i in xrange(0, self.SegmentNoLoft + 1, Step)
        ]

        LESpar, TESpar, MIDSpar, StringerUp, StringerDown, PointsUp, PointsDown = self._BuildSpars(
            self.ChordFactor, self.ScaleFactor)

        # RIBS generated from segments
        for i in range(0, self.NoRibs):
            for ii in range(0, self.NoStiffners - 1):
                SegUp = GC_MakeSegment(
                    PointsUp[ii + i * self.NoStiffners * (Step)],
                    PointsUp[ii + i * self.NoStiffners * (Step) + 1]).Value()
                SegDown = GC_MakeSegment(
                    PointsDown[ii + i * self.NoStiffners * (Step) + 1],
                    PointsDown[ii + i * self.NoStiffners * (Step)]).Value()
                SegSide1 = GC_MakeSegment(
                    PointsDown[ii + i * self.NoStiffners * (Step)],
                    PointsUp[ii + i * self.NoStiffners * (Step)]).Value()
                SegSide2 = GC_MakeSegment(
                    PointsUp[ii + i * self.NoStiffners * (Step) + 1],
                    PointsDown[ii + i * self.NoStiffners * (Step) +
                               1]).Value()
                EdgeSegUp = act.make_edge(SegUp)
                EdgeSegDown = act.make_edge(SegDown)
                EdgeSide1 = act.make_edge(SegSide1)
                EdgeSide2 = act.make_edge(SegSide2)
                WireRib = act.make_wire(
                    [EdgeSide1, EdgeSegUp, EdgeSide2, EdgeSegDown])
                FaceRibi = act.make_face(WireRib)
                if self.ScaleFactor != 1:
                    Origin = gp_Pnt(0., 0., 0.)
                    FaceRib = act.scale_uniformal(FaceRibi, Origin,
                                                  self.ScaleFactor)
                    RibsFace.append(FaceRib)

        return SectionsRibs, RibsFace
示例#12
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
    return Handle_Geom_Plane.DownCast(BRep_Tool_Surface(aFace)).GetObject()


height = 70
width = 50
thickness = 30

# The points we'll use to create the profile of the bottle's body
aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
aPnt5 = gp_Pnt(width / 2.0, 0, 0)

aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

# Could also construct the line edges directly using the points
# instead of the resulting line
aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())

# Create a wire out of the edges
aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())

# Quick way to specify the X axis
xAxis = gp_OX()

# Set up the mirror
示例#14
0
display, start_display = init_display()[:2]

myWidth = 50
myHeight = 70
myThickness = 30

# Profile : Define Support Points
aPnt1 = gp_Pnt(-myWidth / 2, 0, 0)
aPnt2 = gp_Pnt(-myWidth / 2, -myThickness / 4, 0)
aPnt3 = gp_Pnt(0, -myThickness / 2, 0)
aPnt4 = gp_Pnt(myWidth / 2, -myThickness / 4, 0)
aPnt5 = gp_Pnt(myWidth / 2, 0, 0)

# Profile : Define the Geometry
aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

# Profile : Define the Topology
aEdge1 = MakeEdge(aSegment1.Value())
aEdge2 = MakeEdge(aArcOfCircle.Value())
aEdge3 = MakeEdge(aSegment2.Value())
aWire = MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())

# Complete Profile
xAxis = OCC.gp.gp_OX()
aTrsf = OCC.gp.gp_Trsf()
aTrsf.SetMirror(xAxis)
aBRepTrsf = Transform(aWire.Wire(), aTrsf)
aMirroredShape = aBRepTrsf.Shape()
aMirroredWire = OCC.TopoDS.TopoDS_Shape(aMirroredShape)
示例#15
0
from OCC.GC import GC_MakeLine

display, start_display, add_menu, add_function_to_menu = init_display(
    'qt-pyqt5', (1024, 768))
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
pnt1 = gp_Pnt(-1, -1, 40)
pnt2 = gp_Pnt(-1, -10, 40)

origin = gp_Pnt(0, 0, 0)
xdirection = gp_Dir(1, 0, 0)
xaxis = gp.OX()
t = gp_Trsf()
t.SetMirror(xaxis)
xline = GC_MakeLine(gp.OX()).Value()

geom_curve = GC_MakeSegment(pnt1, pnt2).Value()
bt = BRepBuilderAPI_Transform(my_box, t)
# what about a geom line!?
# ok what about something rotated?
#edge = BRepBuilderAPI_MakeEdge(10)
#my_box2 = BRepPrimAPI_MakeBox(5., 5., 5.).Shape()
#wire = BRepBuilderAPI_MakeWire(10, 10).Shape()


def f():
    display.DisplayShape(geom_curve, update=True)
    display.DisplayShape(bt.Shape(), update=True)


QTimer().singleShot(300, f)
display.DisplayShape(GC_MakeLine(gp.OX()).Value())
示例#16
0
    def BuildTurbofanNacelle(self):
        """
        The defaults yield a nacelle similar to that of an RR Trent 1000 / GEnx

        #TODO: break this down into modular function calls
        """
        CentreLocation = self.CentreLocation

        MeanNacelleLength = self.MeanNacelleLength
        HighlightRadius = self.HighlightRadius
        HighlightDepth = 0.12 * self.MeanNacelleLength
        SectionNo = 100

        #         Draw the nacelle with centre of the intake highlight circle in 0,0,0
        HHighlight = act.make_circle3pt([0, 0, HighlightRadius],
                                        [0, -HighlightRadius, 0],
                                        [0, 0, -HighlightRadius])
        Highlight = HHighlight.GetObject()
        HHighlightCutterCircle = \
            act.make_circle3pt([0, 0, HighlightRadius * 1.5],
                               [0, -HighlightRadius * 1.5, 0],
                               [0, 0, -HighlightRadius * 1.5])
        HighlightCutterCircle = HHighlightCutterCircle.GetObject()
        #         Fan disk for CFD boundary conditions
        FanCircle = Handle_Geom_Circle.DownCast(
            Highlight.Translated(gp_Vec(MeanNacelleLength * 0.25, 0, 0)))
        wire = act.make_wire(act.make_edge(FanCircle))
        FanDisk = act.make_face(wire)
        self.AddComponent(FanDisk, 'FanDisk')

        #         Aft outflow for CFD boundary conditions
        BypassCircle = Handle_Geom_Circle.DownCast(
            Highlight.Translated(gp_Vec(MeanNacelleLength * 0.85, 0, 0)))
        wire = act.make_wire(act.make_edge(BypassCircle))
        BypassDisk = act.make_face(wire)
        self.AddComponent(BypassDisk, 'BypassDisk')

        #         Outflow cone
        TailConeBasePoint = np.array([MeanNacelleLength * 0.84, 0, 0])
        TailConeHeight = MeanNacelleLength * (1.35 - 0.84)
        TailConeRadius = HighlightRadius * 0.782
        TailCone = act.AddCone(TailConeBasePoint, TailConeRadius,
                               TailConeHeight)
        self.AddComponent(TailCone, 'TailCone')

        #         Spinner cone
        SpinnerConeBasePoint = np.array([MeanNacelleLength * 0.26, 0, 0])
        SpinnerConeHeight = MeanNacelleLength * (0.26 - 0.08)
        SpinnerConeRadius = MeanNacelleLength * 0.09
        Spinner = act.AddCone(SpinnerConeBasePoint,
                              SpinnerConeRadius,
                              SpinnerConeHeight,
                              direction=gp_Dir(-1, 0, 0))
        self.AddComponent(Spinner, 'Spinner')
        #
        # Tilt the intake
        RotAx = gp_OY()
        Highlight.Rotate(RotAx, np.radians(self.ScarfAngle))
        #        # Set up the disk for separating the intake lip later
        HighlightCutterCircle.Rotate(RotAx, np.radians(self.ScarfAngle))
        HighlightCutterDisk = act.PlanarSurf(HighlightCutterCircle)

        HighlightCutterDisk =\
            act.translate_topods_from_vector(HighlightCutterDisk,
                                             gp_Vec(HighlightDepth, 0, 0))

        #         Build the actual airfoil sections to define the nacelle
        HighlightPointVector = act.Uniform_Points_on_Curve(
            Highlight.GetHandle(), SectionNo)

        Sections = []
        TailPoints = []
        Twist = 0
        AirfoilSeligName = 'goe613'

        Rotations = np.linspace(0, 360, SectionNo)

        for i, pt in enumerate(HighlightPointVector):
            AfChord = MeanNacelleLength - pt.X()
            Af = primitives.Airfoil([pt.X(), pt.Y(), pt.Z()],
                                    AfChord,
                                    Rotations[i],
                                    Twist,
                                    SeligProfile=AirfoilSeligName).Curve
            Sections.append(Af)
            TailPoints.append(Af.GetObject().EndPoint())

        self._sections = Sections

        #        # Build the actual nacelle OML surface
        #        EndCircle = act.points_to_bspline(TailPoints)    #Dont need this?
        #        self._EndCircle = EndCircle
        Nacelle = act.AddSurfaceLoft(Sections)
        self.AddComponent(Nacelle, 'Nacelle')
        #        TODO: Separate the lip
        #        Cowling, HighlightSection = act.TrimShapebyPlane(Nacelle,
        #                                                          HighlightCutterDisk,
        #                                                          True)

        #        Move the engine into its actual place on the wing
        self.TranslateComponents(gp_Vec(*CentreLocation))

        # Now build the pylon between the engine and the chord on the wing
        CP1 = gp_Pnt(MeanNacelleLength * 0.26 + CentreLocation[0],
                     CentreLocation[1],
                     CentreLocation[2] + HighlightRadius * 0.1)
        CP2 = gp_Pnt(MeanNacelleLength * 0.4 + CentreLocation[0],
                     CentreLocation[1],
                     HighlightRadius * 1.45 + CentreLocation[2])

        # Get the chord from its handle
        Chord = self.HChord.GetObject()
        CP3 = Chord.EndPoint()
        CP4 = Chord.StartPoint()
        self._pylonPts = [CP1, CP2, CP3, CP4]

        #        Pylon wireframe
        tangents = np.array([[0, 0, 1], [1, 0, 0]])
        PylonTop = act.points_to_bspline([CP1, CP2, CP3, CP4],
                                         tangents=tangents)
        self._PylonTop = PylonTop
        PylonBase_LE = [CP1.X(), CP1.Y(), CP1.Z()]
        PylonAf = primitives.Airfoil(PylonBase_LE,
                                     MeanNacelleLength * 1.35,
                                     90,
                                     0,
                                     Naca4Profile='0012',
                                     EnforceSharpTE=False)
        self._PylonAf = PylonAf
        LowerTE = PylonAf.ChordLine.GetObject().EndPoint()
        #        LowerTE = rs.CurveEndPoint(PylonChord)
        PylonTE = GC_MakeSegment(LowerTE, CP4).Value()
        self._PylonTE = PylonTE

        edges = [
            act.make_edge(PylonAf.ChordLine),
            act.make_edge(PylonTop),
            act.make_edge(PylonTE)
        ]

        Pylon_symplane = act.make_face(act.make_wire(*edges))
        self.AddComponent(Pylon_symplane, 'Pylon_symplane')

        #         TODO: Pylon surface. Currently a flat plate at symmetry plane.
        #        This should be done with a plate surface (similar to NetworkSrf in
        #        Rhino), but I haven't got this to work yet
        #         Method 1: Sweep - gives the wrong shape
        #        Pylon_tip = GC_MakeCircle(gp_Ax1(CP4, gp_Dir(0, 1, 0)),
        #                                  PylonAf.ChordLength*0.001
        #                                  ).Value()
        #
        #        Pylon_curve = PylonAf.Curve.GetObject()
        #        PylonAf_TE = act.make_edge(Pylon_curve.StartPoint(),
        #                                   Pylon_curve.EndPoint())
        #        PylonAf_Face = act.PlanarSurf(PylonAf.Curve)
        #        PylonAf_closedwire = act.make_wire(act.make_edge(PylonAf.Curve),
        #                                           PylonAf_TE)
        #        sections = [PylonAf.Curve, PylonTE]
        #        spine = act.make_wire(act.make_edge(PylonTop))
        #        self.PylonLeft = act.make_pipe_shell(spine, sections)
        #
        #         Move into place under the wing
        #        self._Translate(gp_Vec(0,-CentreLocation[1],0))
        #
        # TODO: Mirror the pylon half surface
        #        PylonRight = act.mirror(PylonLeft, plane='xz')
        #        PylonAfCurve = act.AddTEtoOpenAirfoil(PylonAfCurve)
        #        PylonAfSrf = rs.AddPlanarSrf(PylonAfCurve)

        return None