예제 #1
0
      def getShape(self, pos, rotation) :
          import cadquery as cq
          from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir
          from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone
          from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut

          print("Get Shape gCone")
          x = pos[0]
          y = pos[1]
          z = pos[2]
          cone1 = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(x,y,z), \
                  gp_Dir(0, 0, 1)),\
                  self.R1[1], self.R2[1], self.Z).Shape()
          if (self.R1[0] != 0 or self.R2[0] != 0 ) :
             cone2 = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(x,y,z), \
                  gp_Dir(0, 0, 1)),\
                  self.R1[0], self.R2[0], self.Z).Shape()
             cone1 = BRepAlgoAPI_Cut(cone1, cone2).Shape()
          if self.Sector != None :
             if self.Sector.completeRev() == False :
                print("Need to section")
                if self.Sector.less90() == True :
                   print("Common")
                   shape = self.Sector.makeCommon(self.R1[1], self.Z, cone1) 
                else :
                   print("Cut") 
                   shape = self.Sector.makeCut(self.R1[1], self.Z, cone1)
                if self.Sector.getStart() == 0 :
                   return shape
                else :
                   return self.Sector.rotate(shape)
          print("Cone Shape")
          print(cone1)
          return(cone1)
예제 #2
0
 def do_cone():
     axe = gp_Ax2()
     axe.SetLocation(gp_Pnt((random_vec()*scope).XYZ()))
     axe.SetDirection(gp_Dir(random_vec()))
     cone = BRepPrimAPI_MakeCone(axe,
                                 0, #random.uniform(0,), # r1
                                 random.uniform(10, 30), # r2
                                 random.uniform(30, 1500), # h
                                )
     return cone.Shape()
예제 #3
0
def New_shp(Xmax, Xmin, Ymax, Ymin, Zmax, Zmin, X, Y, Z):
    Index = random.randint(1, 4)
    position = cal_position(Xmax, Xmin, Ymax, Ymin, Zmax, Zmin)
    A = (X + Y + Z) / 5
    if Index == 1:
        X1 = random.uniform(0.5 * A, A)
        Y1 = random.uniform(0.5 * A, A)
        Z1 = random.uniform(0.5 * A, A)
        nshp = BRepPrimAPI_MakeBox(
            gp_Pnt(-0.5 * X1 + position[0], -0.5 * Y1 + position[1],
                   -0.5 * Z1 + position[2]), X1, Y1, Z1).Shape()
    if Index == 2:

        R = random.uniform(0.25 * A, 0.5 * A)
        nshp = BRepPrimAPI_MakeSphere(
            gp_Pnt(position[0], position[1], position[2]), R).Shape()
    if Index == 3:
        R2 = random.uniform(0.25 * A, 0.5 * A)
        H = random.uniform(0.5 * A, A)
        origin = gp_Ax2(
            gp_Pnt(position[0], position[1], -0.5 * H + position[2]),
            gp_Dir(0.0, 0.0, 1.0))
        nshp = BRepPrimAPI_MakeCone(origin, R2, 0, H).Shape()
    if Index == 4:

        R = random.uniform(0.25 * A, 0.5 * A)
        H = random.uniform(0.5 * A, A)
        cylinder_origin = gp_Ax2(
            gp_Pnt(position[0], position[1], -0.5 * H + position[2]),
            gp_Dir(0.0, 0.0, 1.0))
        nshp = BRepPrimAPI_MakeCylinder(cylinder_origin, R, H).Shape()
    return nshp
예제 #4
0
def mounting_holes(base):
    result = base
    for i in range(0, mounting_hole_count):
        center = gp_Pnt(cos(i * M_PI / 3) * mounting_radius,
                        sin(i * M_PI / 3) * mounting_radius, 0.0)
        center_axis = gp_Ax2(center, gp_DZ())

        cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius,
                                            thickness).Shape()
        result = BRepAlgoAPI_Cut(result, cylinder).Shape()

        cone = BRepPrimAPI_MakeCone(center_axis,
                                    hole_radius + thickness / 2.,
                                    hole_radius, thickness / 2.)
        result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape()

    return result
예제 #5
0
    def cylinder(self, r, r1, r2, d, d1, d2, h, center=False):
        nr1 = None
        nr2 = None
        nh = None
        if (not is_var_set(d)) and is_var_set(r):
            nr1 = r
            nr2 = r
        elif is_var_set(d) and (not is_var_set(r)):
            nr1 = d / 2.0
            nr2 = d / 2.0
        elif is_var_set(d) and is_var_set(r):
            nr1 = d / 2.0
            nr2 = d / 2.0
        elif (not is_var_set(d)) and (not is_var_set(r)) and (
                is_var_set(r1) and is_var_set(r2)):
            nr1 = r1
            nr2 = r2
        elif (not is_var_set(d)) and (not is_var_set(r)) and (
                is_var_set(d1) and is_var_set(d2)):
            nr1 = d1 / 2.0
            nr2 = d2 / 2.0
        else:
            nr1 = 0.5
            nr2 = 0.5

        nh = 1.0
        if is_var_set(h):
            nh = h

        ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
        s = None
        if nr1 == nr2:
            s = BRepPrimAPI_MakeCylinder(ax, nr1, nh).Shape()
        else:
            s = BRepPrimAPI_MakeCone(ax, nr1, nr2, nh).Shape()
        scls = SCLShape(s)
        if (center):
            debug("center cylinder")
            trsf = gp_Trsf()
            trsf.SetTranslation(gp_Vec(0, 0, -h / 2.0))
            scls.transform(trsf)
        sclp = SCLPart3(self)
        sclp.set_shape(scls)
        name = get_inc_name("cylinder")
        sclp.set_name(name)
        debug("Creating cylinder %s" % (name, ))
        self.add_child_context(sclp)
예제 #6
0
    def __init__(self):
        plotocc.__init__(self)
        self.compound = TopoDS_Compound()
        self.builder = BRep_Builder()
        self.builder.MakeCompound(self.compound)

        box = BRepPrimAPI_MakeBox(100, 200, 300).Shape()
        self.display.DisplayShape(box)

        con = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(500, 0, 0), gp_Dir(0, 0, 1)),
                                   100, 200, 300).Shape()
        self.display.DisplayShape(con)

        # https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_graphic3d___camera.html
        self.camera = self.display.View.Camera()
        print(self.camera.Scale(), dir_to_vec(self.camera.OrthogonalizedUp()))
        print(self.camera.ViewDimensions())
예제 #7
0
 def renderCone(self, geometry, transforms, styleName, layerName):
     r1, r2, h = geometry
     shape = BRepPrimAPI_MakeCone (r1, r2, h).Shape()
     self.renderShapeObj(shape, transforms,styleName)
예제 #8
0
import sys

from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCone
from OCC.Core.Graphic3d import Graphic3d_NOM_PLASTIC, Graphic3d_NOM_ALUMINIUM
from OCC.Core.V3d import V3d_SpotLight, V3d_COMPLETE, V3d_XnegYnegZpos
from OCC.Core.Quantity import Quantity_NOC_WHITE, Quantity_NOC_CORAL2, Quantity_NOC_BROWN
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.Core.gp import gp_Vec

from OCC.Extend.ShapeFactory import translate_shp

# first create geometry
from core_classic_occ_bottle import bottle
table = translate_shp(BRepPrimAPI_MakeBox(100, 100, 10).Shape(), gp_Vec(-50, -50, -10))
glass_out = BRepPrimAPI_MakeCone(7, 9, 25).Shape()
glass_in = translate_shp(BRepPrimAPI_MakeCone(7, 9, 25).Shape(), gp_Vec(0., 0., 0.2))
glass = BRepAlgoAPI_Cut(glass_out, glass_in).Shape()
translated_glass = translate_shp(glass, gp_Vec(-30, -30, 0))

# then inits display
display, start_display, add_menu, add_function_to_menu = init_display()

# create one spotlight
spot_light = V3d_SpotLight(display.Viewer, -100, -100, 100,
                           V3d_XnegYnegZpos, Quantity_NOC_WHITE)
## display the spotlight in rasterized mode
spot_light.Display(display.View, V3d_COMPLETE)
display.View.SetLightOn()

display.DisplayShape(bottle, material=Graphic3d_NOM_ALUMINIUM)
from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCone
from OCC.Core.Graphic3d import Graphic3d_NOM_PLASTIC, Graphic3d_NOM_ALUMINIUM
from OCC.Core.V3d import V3d_SpotLight, V3d_COMPLETE, V3d_XnegYnegZpos
from OCC.Core.Quantity import Quantity_NOC_WHITE, Quantity_NOC_CORAL2, Quantity_NOC_BROWN
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.Core.gp import gp_Vec

from OCC.Extend.ShapeFactory import translate_shp

# first create geometry
from core_classic_occ_bottle import bottle
table = translate_shp(
    BRepPrimAPI_MakeBox(100, 100, 10).Shape(), gp_Vec(-50, -50, -10))
glass_out = BRepPrimAPI_MakeCone(7, 9, 25).Shape()
glass_in = translate_shp(
    BRepPrimAPI_MakeCone(7, 9, 25).Shape(), gp_Vec(0., 0., 0.2))
glass = BRepAlgoAPI_Cut(glass_out, glass_in).Shape()
translated_glass = translate_shp(glass, gp_Vec(-30, -30, 0))

# then inits display
display, start_display, add_menu, add_function_to_menu = init_display()

# create one spotlight
spot_light = V3d_SpotLight(display.Viewer_handle, -100, -100, 100,
                           V3d_XnegYnegZpos, Quantity_NOC_WHITE)
## display the spotlight in rasterized mode
spot_light.Display(display.View_handle, V3d_COMPLETE)
display.View.SetLightOn()
예제 #10
0
 def renderCone(self, aRadius1, aRadius2, aHeight):
     shape = BRepPrimAPI_MakeCone(aRadius1, aRadius2, aHeight).Shape()
     self._renderShapeObj(shape)
if __name__ == '__main__':
    display, start_display, add_menu, add_function_to_menu = init_display(
        "qt-pyqt5")
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox

    def sphere(event=None):
        display.DisplayShape(BRepPrimAPI_MakeSphere(100).Shape(), update=True)

    def cube(event=None):
        display.DisplayShape(BRepPrimAPI_MakeBox(1, 1, 1).Shape(), update=True)

    def quit(event=None):
        sys.exit()

    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeCone
    from OCC.Core.gp import gp_Pnt, gp_Ax2, gp_Dir
    from OCC.Display.OCCViewer import rgb_color

    my_cone = BRepPrimAPI_MakeCone(1, 0, 4).Shape()
    my_cone = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, -1)),
                                   0, 2, 4).Shape()

    display.DisplayShape(my_cone)

    add_menu('primitives')
    add_function_to_menu('primitives', sphere)
    add_function_to_menu('primitives', cube)
    add_function_to_menu('primitives', quit)
    start_display()  #
예제 #12
0
from cadquery import Shape
from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone

ret = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(.0, .0, .0), gp_Dir(0, 0, 1)), 6, 4,
                           20).Shape()

# show_object needs a CadQuery object
result = Shape.cast(ret)

show_object(result)