コード例 #1
0
 def makeSqProfile(self, size):
     # points and segments need to be in CW sequence to get W pointing along Z
     p1 = gp_Pnt2d(-size, size)
     p2 = gp_Pnt2d(size, size)
     p3 = gp_Pnt2d(size, -size)
     p4 = gp_Pnt2d(-size, -size)
     seg1 = GCE2d_MakeSegment(p1, p2)
     seg2 = GCE2d_MakeSegment(p2, p3)
     seg3 = GCE2d_MakeSegment(p3, p4)
     seg4 = GCE2d_MakeSegment(p4, p1)
     e1 = BRepBuilderAPI_MakeEdge(seg1.Value(), self.plane)
     e2 = BRepBuilderAPI_MakeEdge(seg2.Value(), self.plane)
     e3 = BRepBuilderAPI_MakeEdge(seg3.Value(), self.plane)
     e4 = BRepBuilderAPI_MakeEdge(seg4.Value(), self.plane)
     aWire = BRepBuilderAPI_MakeWire(e1.Edge(), e2.Edge(), e3.Edge(),
                                     e4.Edge())
     myWireProfile = aWire.Wire()
     return myWireProfile  # TopoDS_Wire
コード例 #2
0
 def test_auto_import_of_dependent_modules(self) -> None:
     """ Test: automatic import of dependent modules """
     returned_object = GCE2d_MakeSegment(gp_Pnt2d(1, 1),
                                         gp_Pnt2d(3, 4)).Value()
     # for this unittest, don't use the issinstance() function,
     # since the OCC.Geom2d module
     # is *not* manually imported
     returned_object_type = '%s' % type(returned_object)
     self.assertEqual(returned_object_type, "<class 'OCC.Core.Geom2d.Geom2d_TrimmedCurve'>")
コード例 #3
0
  def makeHelixOnCyl(self):
    bas = BRepAdaptor_Surface(self.face)
    cyl = bas.Cylinder()

    delta_v = bas.LastVParameter() - bas.FirstVParameter()
    v_final = bas.LastVParameter()

    dv_du = self.pitch / (2*pi)
    l = delta_v / sin(atan(dv_du))

    aLine2d = gp_Lin2d(gp_Pnt2d(bas.FirstUParameter(),bas.FirstVParameter()), gp_Dir2d(1,dv_du))
    if not self.reverse_helix:
      aSegment = GCE2d_MakeSegment(aLine2d, 0.0, l)
    else:
      aSegment = GCE2d_MakeSegment(aLine2d, l, 0.0)

    helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), Geom_CylindricalSurface(cyl)).Edge()

    #self.aLine2d = aLine2d
    #self.aSegment = aSegment
    self.helix_edge = helix_edge
    return helix_edge
コード例 #4
0
    def test_circles2d_from_curves(self):
        '''Test: circles2d from curves'''
        P1 = gp_Pnt2d(9, 6)
        P2 = gp_Pnt2d(10, 4)
        P3 = gp_Pnt2d(6, 7)
        C = gce_MakeCirc2d(P1, P2, P3).Value()

        QC = gccent_Outside(C)
        P4 = gp_Pnt2d(-2, 7)
        P5 = gp_Pnt2d(12, -3)
        L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1)

        QL = gccent_Unqualified(L)
        radius = 2.
        TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion())

        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol + 1):
                circ = TR.ThisSolution(k)
                # find the solution circle
                pnt1 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt1)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt2 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt2)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the second tangent point

        aLine = GCE2d_MakeSegment(L, -2, 20).Value()
        self.assertIsInstance(aLine, Geom2d_TrimmedCurve)
        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol + 1):
                circ = TR.ThisSolution(k)
                aCircle = Geom2d_Circle(circ)
                self.assertIsInstance(aCircle, Geom2d_Circle)
                # find the solution circle (index, outvalue, outvalue, gp_Pnt2d)
                pnt3 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt3)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt4 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt4)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
コード例 #5
0
 def cline_gen(self, cline):
     '''Generate a cline extending to the edge of the border.
     cline coords (a,b,c) are in (mm) values.'''
     self.clList.append(cline)
     # TopLft & BotRgt corners of the border
     trimbox = (-self.size, self.size, self.size, -self.size)
     endpts = cline_box_intrsctn(cline, trimbox)
     if len(endpts) == 2:
         ep1, ep2 = endpts
         aPnt1 = gp_Pnt2d(ep1[0], ep1[1])
         aPnt2 = gp_Pnt2d(ep2[0], ep2[1])
         aSegment = GCE2d_MakeSegment(
             aPnt1, aPnt2).Value()  #type: Handle_Geom2d_TrimmedCurve
         # convert 2d line segment to 3d line
         aLine = geomapi_To3d(aSegment,
                              self.gpPlane)  # type: Handle_Geom_Curve
         self.clineList.append(aLine)
コード例 #6
0
def startBottle(startOnly=True):  # minus the neck fillet, shelling & threads
    partName = "Bottle-start"
    # 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
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)

    # Apply the mirror transformation
    aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)

    # Get the mirrored shape back out of the transformation
    # and convert back to a wire
    aMirroredShape = aBRespTrsf.Shape()

    # A wire instead of a generic shape now
    aMirroredWire = topods.Wire(aMirroredShape)

    # Combine the two constituent wires
    mkWire = BRepBuilderAPI_MakeWire()
    mkWire.Add(aWire.Wire())
    mkWire.Add(aMirroredWire)
    myWireProfile = mkWire.Wire()

    # The face that we'll sweep to make the prism
    myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)

    # We want to sweep the face along the Z axis to the height
    aPrismVec = gp_Vec(0, 0, height)
    myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)

    # Add fillets to all edges through the explorer
    mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
    anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE)

    while anEdgeExplorer.More():
        anEdge = topods.Edge(anEdgeExplorer.Current())
        mkFillet.Add(thickness / 12.0, anEdge)

        anEdgeExplorer.Next()

    myBody = mkFillet.Shape()

    # Create the neck of the bottle
    neckLocation = gp_Pnt(0, 0, height)
    neckAxis = gp_DZ()
    neckAx2 = gp_Ax2(neckLocation, neckAxis)

    myNeckRadius = thickness / 4.0
    myNeckHeight = height / 10.0

    mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
    myBody = BRepAlgoAPI_Fuse(myBody, mkCylinder.Shape())
    if startOnly:  # quit here
        uid = win.getNewPartUID(myBody.Shape(), name=partName)
        win.redraw()
        return

    partName = "Bottle-complete"
    # Our goal is to find the highest Z face and remove it
    faceToRemove = None
    zMax = -1

    # We have to work our way through all the faces to find the highest Z face
    aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE)
    while aFaceExplorer.More():
        aFace = topods.Face(aFaceExplorer.Current())

        if face_is_plane(aFace):
            aPlane = geom_plane_from_face(aFace)

            # We want the highest Z face, so compare this to the previous faces
            aPnt = aPlane.Location()
            aZ = aPnt.Z()
            if aZ > zMax:
                zMax = aZ
                faceToRemove = aFace

        aFaceExplorer.Next()

    facesToRemove = TopTools_ListOfShape()
    facesToRemove.Append(faceToRemove)

    myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove,
                                          -thickness / 50.0, 0.001)

    # Set up our surfaces for the threading on the neck
    neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
    aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
    aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

    # Set up the curves for the threads on the bottle's neck
    aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
    aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
    anAx2d = gp_Ax2d(aPnt, aDir)

    aMajor = 2.0 * math.pi
    aMinor = myNeckHeight / 10.0

    anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
    anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

    anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
    anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

    anEllipsePnt1 = anEllipse1.Value(0)
    anEllipsePnt2 = anEllipse1.Value(math.pi)

    aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)

    # Build edges and wires for threading
    anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
    anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
    anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
    anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)

    threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                             anEdge2OnSurf1.Edge())
    threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                             anEdge2OnSurf2.Edge())

    # Compute the 3D representations of the edges/wires
    breplib.BuildCurves3d(threadingWire1.Shape())
    breplib.BuildCurves3d(threadingWire2.Shape())

    # Create the surfaces of the threading
    aTool = BRepOffsetAPI_ThruSections(True)
    aTool.AddWire(threadingWire1.Wire())
    aTool.AddWire(threadingWire2.Wire())
    aTool.CheckCompatibility(False)
    myThreading = aTool.Shape()

    # Build the resulting compound
    aRes = TopoDS_Compound()
    aBuilder = BRep_Builder()
    aBuilder.MakeCompound(aRes)
    aBuilder.Add(aRes, myBody.Shape())
    aBuilder.Add(aRes, myThreading)
    uid = win.getNewPartUID(aRes, name=partName)
    win.redraw()
コード例 #7
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 math import pi

from OCC.Core.gp import gp_Pnt2d, gp_XOY, gp_Lin2d, gp_Ax3, gp_Dir2d
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Core.Geom import Geom_CylindricalSurface
from OCC.Core.GCE2d import GCE2d_MakeSegment

from OCC.Display.WebGl import threejs_renderer

# First build a helix
aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0)
aLine2d = gp_Lin2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0))
aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0)

helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0,
                                     6.0 * pi).Edge()

display = threejs_renderer.ThreejsRenderer()
display.DisplayShape(helix_edge, color=(1, 0, 0), line_width=1.)
display.render()
コード例 #8
0
aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
anAx2d = gp_Ax2d(aPnt, aDir)

aMajor = 2.0 * math.pi
aMinor = myNeckHeight / 10.0

anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

anEllipsePnt1 = anEllipse1.Value(0)
anEllipsePnt2 = anEllipse1.Value(math.pi)

aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)

# Build edges and wires for threading
anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)

threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                         anEdge2OnSurf1.Edge())
threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                         anEdge2OnSurf2.Edge())

# Compute the 3D representations of the edges/wires
breplib.BuildCurves3d(threadingWire1.Shape())
breplib.BuildCurves3d(threadingWire2.Shape())
コード例 #9
0
def _helix(r, h, step=None, pitch=None, angle=0, left=False):
    radius = r
    height = h

    if pitch:
        pitch = math.sin(pitch) * 2 * math.pi * r
    else:
        pitch = step

    if pitch < precision_Confusion():
        raise Exception("Pitch of helix too small")

    if height < precision_Confusion():
        raise Exception("Height of helix too small")

    cylAx2 = gp_Ax2(gp_Pnt(0.0, 0.0, 0.0), gp_DZ())

    if abs(angle) < precision_Confusion():
        # Cylindrical helix
        if radius < precision_Confusion():
            raise Exception("Radius of helix too small")

        surf = Geom_CylindricalSurface(gp_Ax3(cylAx2), radius)
        isCylinder = True
    else:
        # Conical helix
        if abs(angle) < precision_Confusion():
            raise Exception("Angle of helix too small")

        surf = Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius)
        isCylinder = False

    turns = height / pitch
    wholeTurns = math.floor(turns)
    partTurn = turns - wholeTurns

    aPnt = gp_Pnt2d(0, 0)
    aDir = gp_Dir2d(2. * math.pi, pitch)
    coneDir = 1.0

    if left:
        aDir.SetCoord(-2. * math.pi, pitch)
        coneDir = -1.0

    aAx2d = gp_Ax2d(aPnt, aDir)
    line = Geom2d_Line(aAx2d)
    beg = line.Value(0)

    mkWire = BRepBuilderAPI_MakeWire()

    for i in range(wholeTurns):
        if isCylinder:
            end = line.Value(
                math.sqrt(4.0 * math.pi * math.pi + pitch * pitch) * (i + 1))
        else:
            u = coneDir * (i + 1) * 2.0 * math.pi
            v = ((i + 1) * pitch) / math.cos(angle)
            end = gp_Pnt2d(u, v)

        segm = GCE2d_MakeSegment(beg, end).Value()
        edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf).Edge()
        mkWire.Add(edgeOnSurf)
        beg = end

    if partTurn > precision_Confusion():
        if (isCylinder):
            end = line.Value(
                math.sqrt(4.0 * math.pi * math.pi + pitch * pitch) * turns)
        else:
            u = coneDir * turns * 2.0 * math.pi
            v = height / math.cos(angle)
            end = gp_Pnt2d(u, v)

        segm = GCE2d_MakeSegment(beg, end).Value()
        edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf).Edge()
        mkWire.Add(edgeOnSurf)

    shape = mkWire.Wire()
    breplib.BuildCurves3d(shape)
    return Shape(shape)
コード例 #10
0
ファイル: curve2.py プロジェクト: mirmik/zencad
def _segment(a, b):
    return Curve2(GCE2d_MakeSegment(a, b).Value())