Exemple #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_MakeCylinder
          from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut

          print("Get Shape gTube")
          x = pos[0]
          y = pos[1]
          z = pos[2]
          tube1 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(x,y,z), \
                  gp_Dir(0, 0, 1)),\
                  self.Radius[1], self.Z).Shape()
          if self.Radius[0] != 0 :
             tube2 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(x,y,z), \
                     gp_Dir(0, 0, 1)),\
                     self.Radius[0], self.Z).Shape()
             tube1 = BRepAlgoAPI_Cut(tube1, tube2).Shape()
          if self.Sector.completeRev() == False :
             print("Need to section")
             if self.Sector.less90() == True :
                print("Common")
                shape = self.Sector.makeCommon(self.Radius[1], self.Z, tube1) 
             else :
                print("Cut") 
                shape = self.Sector.makeCut(self.Radius[1], self.Z, tube1)
             if self.Sector.getStart() == 0 :
                return shape
             else :
                return self.Sector.rotate(shape)
          else : 
             return tube1 
Exemple #2
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
Exemple #3
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)
 def create_model(self):
     cylinder1 = BRepPrimAPI_MakeCylinder(
         gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r,
         self.H).Shape()
     cylinder2 = BRepPrimAPI_MakeCylinder(
         gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r - self.T,
         self.H).Shape()
     prism = BRepAlgoAPI_Cut(cylinder1, cylinder2).Shape()
     return prism
Exemple #5
0
    def gen_through(self):
        obj = BRepOffsetAPI_ThruSections()

        ax2_1 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
        crl_1 = gp_Circ(ax2_1, 100)
        obj.AddWire(crl_1)

        ax2_2 = gp_Ax2(gp_Pnt(0, 0, 100), gp_Dir(0, 0, 1))
        crl_2 = gp_Circ(ax2_2, 200)
        obj.AddWire(crl_2)

        obj.Build()
        self.display.DisplayShape(obj.Shape())
Exemple #6
0
def pnt_eclips(pnt, wxy=[10, 20]):
    if wxy[0] >= wxy[1]:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        w_x = wxy[0]
        w_y = wxy[1]
    elif wxy[1] >= wxy[0]:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(0, 1, 0))
        w_x = wxy[1]
        w_y = wxy[0]
    else:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        w_x = wxy[0]
        w_y = wxy[1]
    return Geom_Ellipse(ax2, w_x, w_y)
Exemple #7
0
def _box(x, y=None, z=None, center=False, size=None):
    if size is None:
        size = x

    if isinstance(size, (float, int)):
        x = size
        if y is None and z is None:
            size = (x, x, x)
        else:
            if z is None:
                size = (x, y, 0)
            else:
                size = (x, y, z)

    x, y, z = size[0], size[1], size[2]

    if center:
        pnt = point3()

        if center is True:
            pnt = point3(-x / 2, -y / 2, -z / 2)

        if isinstance(center, str):
            if ("x" in center):
                pnt += point3(-x/2, 0, 0)
            if ("y" in center):
                pnt += point3(0, -y/2, 0)
            if ("z" in center):
                pnt += point3(0, 0, -z/2)

        ax2 = gp_Ax2(pnt.Pnt(), gp_Dir(0, 0, 1))
        return Shape(OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeBox(ax2, *size).Shape())
    else:
        return Shape(OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeBox(*size).Shape())
    def create_section_box(self):
        top_left_corner = gp.gp_Pnt(self.section_box['top_left_corner'][0],
                                    self.section_box['top_left_corner'][1],
                                    self.section_box['top_left_corner'][2])
        axis = gp.gp_Ax2(
            top_left_corner,
            gp.gp_Dir(self.section_box['projection'][0],
                      self.section_box['projection'][1],
                      self.section_box['projection'][2]),
            gp.gp_Dir(self.section_box['x_axis'][0],
                      self.section_box['x_axis'][1],
                      self.section_box['x_axis'][2]))
        section_box = BRepPrimAPI.BRepPrimAPI_MakeBox(axis,
                                                      self.section_box['x'],
                                                      self.section_box['y'],
                                                      self.section_box['z'])
        self.section_box['shape'] = section_box.Shape()
        self.section_box['face'] = section_box.BottomFace()

        source = gp.gp_Ax3(axis)
        self.transformation_data = {
            'top_left_corner': self.section_box['top_left_corner'],
            'projection': self.section_box['projection'],
            'x_axis': self.section_box['x_axis']
        }
        destination = gp.gp_Ax3(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 0, -1),
                                gp.gp_Dir(1, 0, 0))
        self.transformation_dest = destination
        self.transformation = gp.gp_Trsf()
        self.transformation.SetDisplacement(source, destination)
Exemple #9
0
    def createEdges(self):

        edges = []
        # Join points a,b
        edge = make_edge(getGpPt(self.a), getGpPt(self.b))
        edges.append(edge)
        # # Join points b1 and b2
        # cirl = gp_Circ(gp_Ax2(getGpPt(self.o1), getGpDir(self.wDir)), self.R1)
        # edge = make_edge(cirl,getGpPt(self.b2), getGpPt(self.b1))
        # edges.append(edge)
        # Join points b and c2
        edge = make_edge(getGpPt(self.b), getGpPt(self.c2))
        edges.append(edge)
        # join points c2 and c1
        cirl2 = gp_Circ(gp_Ax2(getGpPt(self.o2), getGpDir(self.wDir)), self.R1)
        edge = make_edge(cirl2, getGpPt(self.c1), getGpPt(self.c2))
        edges.append(edge)
        # Join points c1 and d
        edge = make_edge(getGpPt(self.c1), getGpPt(self.d))
        edges.append(edge)
        # Join points d and a
        edge = make_edge(getGpPt(self.d), getGpPt(self.a))
        edges.append(edge)

        return edges
Exemple #10
0
def wxy_wire(pnt, wxy=[10, 20]):
    if wxy[0] >= wxy[1]:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        w_x = wxy[0]
        w_y = wxy[1]
    elif wxy[1] >= wxy[0]:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(0, 1, 0))
        w_x = wxy[1]
        w_y = wxy[0]
    else:
        ax2 = gp_Ax2(pnt, gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        w_x = wxy[0]
        w_y = wxy[1]
    obj = Geom_Ellipse(ax2, w_x, w_y).Elips()
    obj = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(obj).Edge()).Wire()
    return obj
Exemple #11
0
    def create_model(self):
        boltCylinderex = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r,
            self.cylex_length).Shape()
        boltCylinder1 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(-self.shaftDir)), self.r,
            self.cyl1_length).Shape()
        bolt_endplate = BRepPrimAPI_MakeBox(getGpPt(self.p3),
                                            self.endplate_width,
                                            self.endplate_width,
                                            self.endplate_thickness).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder1, bolt_endplate).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinderex, Anchor_BOlt).Shape()

        return Anchor_BOlt
Exemple #12
0
 def _to_occ(self) -> BRepPrimAPI_MakeBox:
     xaxis = self.frame.xaxis.scaled(-0.5 * self.xsize)
     yaxis = self.frame.yaxis.scaled(-0.5 * self.ysize)
     zaxis = self.frame.zaxis.scaled(-0.5 * self.zsize)
     frame = self.frame.transformed(
         Translation.from_vector(xaxis + yaxis + zaxis))
     ax2 = gp_Ax2(gp_Pnt(*frame.point), gp_Dir(*frame.zaxis),
                  gp_Dir(*frame.xaxis))
     return BRepPrimAPI_MakeBox(ax2, self.xsize, self.ysize, self.zsize)
Exemple #13
0
def addNeck():
    neckLocation = gp_Pnt(0, 0, height)
    neckNormal = gp_DZ()
    neckAx2 = gp_Ax2(neckLocation, neckNormal)
    myNeckRadius = thickness / 4.
    myNeckHeight = height / 10.
    MKCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
    myNeck = MKCylinder.Shape()
    return myNeck
Exemple #14
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()
Exemple #15
0
def _cylinder(r, h, yaw=None, center=False):
    if yaw:
        if center:
            ax2 = gp_Ax2(gp_Pnt(0, 0, -h/2), gp_Dir(0, 0, 1))
            raw = OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeCylinder(
                ax2, r, h, yaw).Shape()
            return Shape(raw)
        else:
            raw = OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeCylinder(
                r, h, yaw).Shape()
            return Shape(raw)
    else:
        if center:
            ax2 = gp_Ax2(gp_Pnt(0, 0, -h/2), gp_Dir(0, 0, 1))
            raw = OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeCylinder(
                ax2, r, h).Shape()
            return Shape(raw)
        else:
            raw = OCC.Core.BRepPrimAPI.BRepPrimAPI_MakeCylinder(r, h).Shape()
            return Shape(raw)
Exemple #16
0
    def create_model(self):
        boltCylinderex = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r,
            self.cylex_length).Shape()
        boltCylinder1 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(-self.shaftDir)), self.r,
            self.cyl1_length).Shape()
        boltCylinder2 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p2), getGpDir(self.angle1)), self.r,
            self.hightcyl2).Shape()
        sphere1 = BRepPrimAPI_MakeSphere(getGpPt(self.p2), self.r).Shape()
        sphere2 = BRepPrimAPI_MakeSphere(getGpPt(self.p3), self.r).Shape()
        sphere3 = BRepPrimAPI_MakeSphere(getGpPt(self.p5), self.r).Shape()

        edg_points = gp_Circ(gp_Ax2(getGpPt(self.p3), getGpDir(self.shaftDir)),
                             self.r)
        hexwire = BRepBuilderAPI_MakeWire()
        hexedge = BRepBuilderAPI_MakeEdge(edg_points).Edge()
        hexwire.Add(hexedge)
        hexwire_wire = hexwire.Wire()
        hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
        revolve_axis = gp_Ax1(getGpPt(self.p4), gp_Dir(0, -1, 0))
        boltCylinder3 = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                              math.radians(180.)).Shape()

        boltCylinder4 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p5), getGpDir(self.angle2)), self.r,
            self.cyl4_length).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder1, boltCylinder2).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(sphere1, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(sphere2, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder3, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(sphere3, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder4, Anchor_BOlt).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinderex, Anchor_BOlt).Shape()

        return Anchor_BOlt
Exemple #17
0
def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)),
                       40.)
    wire_1 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    # the use of the map function fails at producing the ThruSection
    # on py3k. Why ?
    # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4])
    # we have to use a loop
    for wir in [wire_1, wire_2, wire_3, wire_4]:
        generatorA.AddWire(wir)
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    #smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_1b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_3b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_4b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    # same here, the following line fails
    # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b])
    for wir in [wire_1b, wire_2b, wire_3b, wire_4b]:
        generatorB.AddWire(wir)
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
 def test_shape_conversion_as_py_none(self):
     # see issue #600 and PR #614
     # a null topods_shape should be returned as Py_None by the TopoDS transformer
     # the following test case returns a null topods_shape
     box = BRepPrimAPI_MakeBox(1., 1., 1.).Shape()
     hlr = HLRBRep_Algo()
     hlr.Add(box)
     projector = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(-1.75, 1.1, 5)))
     hlr.Projector(projector)
     hlr.Update()
     hlr.Hide()
     hlr_shapes = HLRBRep_HLRToShape(hlr)
     visible_smooth_edges = hlr_shapes.Rg1LineVCompound()
     self.assertTrue(visible_smooth_edges is None)