def testAutoImportOfDependentModules(self):
     """ 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.Geom2d.Handle_Geom2d_TrimmedCurve'>")
Ejemplo n.º 2
0
 def testAutoImportOfDependentModules(self):
     ''' when a module returns an object defined in another module,
     this module should be automatically imported in scope
     '''
     print 'Test: automatic import of dependent modules'
     from OCC.GCE2d import GCE2d_MakeSegment
     from OCC.gp import gp_Pnt2d
     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.Geom2d.Handle_Geom2d_TrimmedCurve'>")
Ejemplo n.º 3
0
    def makeHelix(cls,
                  pitch,
                  height,
                  radius,
                  center=Vector(0, 0, 0),
                  dir=Vector(0, 0, 1),
                  angle=360.0,
                  lefthand=False):
        """
        Make a helix with a given pitch, height and radius
        By default a cylindrical surface is used to create the helix. If
        the fourth parameter is set (the apex given in degree) a conical surface is used instead'
        """

        # 1. build underlying cylindrical/conical surface
        if angle == 360.:
            geom_surf = Geom_CylindricalSurface(
                gp_Ax3(center.toPnt(), dir.toDir()), radius)
        else:
            geom_surf = Geom_ConicalSurface(
                gp_Ax3(center.toPnt(), dir.toDir()),
                angle * DEG2RAD,  # TODO why no orientation?
                radius)

        # 2. construct an semgent in the u,v domain
        if lefthand:
            geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0),
                                    gp_Dir2d(-2 * pi, pitch))
        else:
            geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0),
                                    gp_Dir2d(2 * pi, pitch))

        # 3. put it together into a wire
        n_turns = height / pitch
        u_start = geom_line.Value(0.)
        u_stop = geom_line.Value(sqrt(n_turns * ((2 * pi)**2 + pitch**2)))
        geom_seg = GCE2d_MakeSegment(u_start, u_stop).Value()

        e = BRepBuilderAPI_MakeEdge(geom_seg, geom_surf.GetHandle()).Edge()

        # 4. Convert to wire and fix building 3d geom from 2d geom
        w = BRepBuilderAPI_MakeWire(e).Wire()
        breplib_BuildCurves3d(w)

        return cls(w)
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(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi)
anArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(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(Handle_Geom2d_Curve(anArc1),
                                         Handle_Geom_Surface(aCyl1))
anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(),
                                         Handle_Geom_Surface(aCyl1))
anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(Handle_Geom2d_Curve(anArc2),
                                         Handle_Geom_Surface(aCyl2))
anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(),
                                         Handle_Geom_Surface(aCyl2))

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