def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.vDir prism1 = makePrismFromFace(aFace, extrudeDir) edges = makeEdgesFromPoints(self.points2) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.H * self.wDir prism2 = makePrismFromFace(aFace, extrudeDir) edges = makeEdgesFromPoints(self.points3) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.H * self.wDir prism3 = makePrismFromFace(aFace, extrudeDir) if self.to_left: prism = BRepAlgoAPI_Cut(prism1, prism2).Shape() else: prism = BRepAlgoAPI_Cut(prism1, prism3).Shape() return prism
def getDaoCaseSurface(self): r = self.aBaseRadius r2 = r * 2 h = self.aCaseHeight h2 = h / 2 offset = self.aOffset gap = self.aCaseGap rTop = r + offset + gap rSphere = gp_Vec(0, rTop, h2).Magnitude() sphere = BRepPrimAPI_MakeSphere(rSphere).Shape() limit = BRepPrimAPI_MakeBox(gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2, h2)).Shape() step01Surface = BRepAlgoAPI_Common(sphere, limit).Shape() step02Surface = getShapeTranslate(step01Surface, 0, 0, -h2) cutIngSurface = self.getCached('getDaoIngSurface', offset - gap) cutYangSurface = self.getCached('getDaoYangSurface', offset - gap) step03Surface = BRepAlgoAPI_Cut(step02Surface, cutIngSurface).Shape() step04Surface = BRepAlgoAPI_Cut(step03Surface, cutYangSurface).Shape() step05Surface = getShapeTranslate(step04Surface, 0, 0, -h2) return step05Surface
def create_part(data): outer_cyl = BRepPrimAPI_MakeCylinder(data["d_out"], data["l"]).Shape() inner_cyl = BRepPrimAPI_MakeCylinder(data["d_in"], data["l"]).Shape() cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(outer_cyl) L2 = TopTools_ListOfShape() L2.Append(inner_cyl) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(5e-5) cut.SetRunParallel(False) cut.Build() shape = cut.Shape() anchors = {"bottom": {"p": [0.0, 0.0, 0.0], "u": [0.0, 0.0, -1.0], "v": [1.0, 0.0, 0.0]}, "top": {"p": [0.0, 0.0, data["l"]], "u": [0.0, 0.0, 1.0], "v": [1.0, 0.0, 0.0]}} properties = None return shape, anchors, properties
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
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 get_only_column_models(self): columns = self.get_column_models() nutbolt = self.get_nut_bolt_models() onlycolumn = BRepAlgoAPI_Cut(columns, nutbolt).Shape() return onlycolumn
def get_welded_modules(self): """ :return: CAD model for all the welds """ if self.C.preference != 'Outside': welded_sec = [self.flangePlateWeldL11Model, self.flangePlateWeldL12Model, self.flangePlateWeldL21Model, self.flangePlateWeldL22Model, self.flangePlateWeldW11Model, self.flangePlateWeldW12Model, self.flangePlateWeldW21Model, self.flangePlateWeldW22Model, \ self.webPlateWeldL11Model, self.webPlateWeldL12Model, self.webPlateWeldL21Model, self.webPlateWeldL22Model, self.webPlateWeldW11Model, self.webPlateWeldW12Model, self.webPlateWeldW21Model, self.webPlateWeldW22Model, \ self.innerflangePlateWeldL11Model, self.innerflangePlateWeldL12Model, self.innerflangePlateWeldL21Model, self.innerflangePlateWeldL22Model, self.innerflangePlateWeldL31Model, self.innerflangePlateWeldL32Model, self.innerflangePlateWeldL41Model, self.innerflangePlateWeldL42Model, \ self.innerflangePlateWeldW11Model, self.innerflangePlateWeldW12Model, self.innerflangePlateWeldW21Model, self.innerflangePlateWeldW22Model, self.innerflangePlateWeldW31Model, self.innerflangePlateWeldW32Model, self.innerflangePlateWeldW41Model, self.innerflangePlateWeldW42Model] else: welded_sec = [self.flangePlateWeldL11Model, self.flangePlateWeldL12Model, self.flangePlateWeldL21Model, self.flangePlateWeldL22Model, self.flangePlateWeldW11Model, self.flangePlateWeldW12Model, self.flangePlateWeldW21Model, self.flangePlateWeldW22Model, \ self.webPlateWeldL11Model, self.webPlateWeldL12Model, self.webPlateWeldL21Model, self.webPlateWeldL22Model, self.webPlateWeldW11Model, self.webPlateWeldW12Model, self.webPlateWeldW21Model, self.webPlateWeldW22Model] welds = welded_sec[0] for comp in welded_sec[1:]: welds = BRepAlgoAPI_Fuse(comp, welds).Shape() welds = BRepAlgoAPI_Cut(welds, self.weldCutPlateModel).Shape() return welds
def mill(): """Mill profile on active WP into active part.""" wp = win.activeWp if win.lineEditStack: depth = float(win.lineEditStack.pop()) * win.unitscale wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return wire = wp.wire workPart = win.activePart uid = win.activePartUID punchProfile = BRepBuilderAPI_MakeFace(wire) aPrismVec = wp.wVec * -depth tool = BRepPrimAPI_MakePrism(punchProfile.Shape(), aPrismVec).Shape() newPart = BRepAlgoAPI_Cut(workPart, tool).Shape() win.erase_shape(uid) doc.replaceShape(uid, newPart) win.draw_shape(uid) win.setActivePart(uid) win.statusBar().showMessage("Mill operation complete") win.clearCallback() else: win.registerCallback(millC) win.lineEdit.setFocus() statusText = "Enter milling depth (pos in -w direction)" win.statusBar().showMessage(statusText)
def get_only_members_models(self): mem = self.get_members_models() nut_bolts = self.get_nut_bolt_array_models() array = BRepAlgoAPI_Cut(mem, nut_bolts).Shape() return array
def create_model(self): box1 = BRepPrimAPI_MakeBox(getGpPt(self.a1), self.L, self.L, self.H).Shape() box2 = BRepPrimAPI_MakeBox(getGpPt(self.a2), self.L - self.T, self.L - self.T, self.H).Shape() prism = BRepAlgoAPI_Cut(box1, box2).Shape() return prism
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
def get_columnModel(self): final_col = self.columnModel nut_bolt_list = self.nut_bolt_array.get_colbolts() for bolt in nut_bolt_list[:]: final_col = BRepAlgoAPI_Cut(final_col, bolt).Shape() return final_col
def get_beamModel(self): final_beam = self.beamModel nut_bolt_list = self.nut_bolt_array.get_beambolts() for bolt in nut_bolt_list[:]: final_beam = BRepAlgoAPI_Cut(final_beam, bolt).Shape() return final_beam
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
def get_only_beams_Models(self): ''' Returns: All the beams and bolts array or group in the connection ''' beams = self.get_beamsModel() nutbolt = self.get_nut_bolt_arrayModels() onlybeams = BRepAlgoAPI_Cut(beams, nutbolt).Shape() return onlybeams
def from_boolean_difference(cls, A: 'BRep', B: 'BRep') -> 'BRep': """Construct a BRep from the boolean difference of two other BReps. Parameters ---------- A : :class:`~compas_occ.brep.BRep` B : :class:`~compas_occ.brep.BRep` Returns ------- :class:`~compas_occ.brep.BRep` """ cut = BRepAlgoAPI_Cut(A.shape, B.shape) if not cut.IsDone(): raise Exception( "Boolean difference operation could not be completed.") brep = BRep() brep.shape = cut.Shape() return brep
def cut(event=None): # Create Box Box = BRepPrimAPI_MakeBox(200, 60, 60).Shape() # Create Sphere Sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape() # Cut: the shere is cut 'by' the box Cut = BRepAlgoAPI_Cut(Sphere, Box).Shape() display.EraseAll() ais_box = display.DisplayShape(Box) display.Context.SetTransparency(ais_box, 0.8, True) display.DisplayShape(Cut) display.FitAll()
def cut(event=None): # Create Box Box = BRepPrimAPI_MakeBox(200, 60, 60).Shape() # Create Sphere Sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape() # Cut: the shere is cut 'by' the box Cut = BRepAlgoAPI_Cut(Sphere, Box).Shape() rnd = JupyterRenderer() rnd.DisplayShape(Box, transparency = True, opacity =0.2) rnd.DisplayShape(Cut, render_edges=True) rnd.Display()
def fuzzy_cut(shape_A, shape_B, tol=5e-5, parallel=False): """ returns shape_A - shape_B """ cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(shape_A) L2 = TopTools_ListOfShape() L2.Append(shape_B) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(tol) cut.SetRunParallel(parallel) cut.Build() return cut.Shape()
def _set_shape(self): self._shape = BRepPrimAPI_MakeBox(self._length, self._section[0], self._section[1]).Shape() if self._saw_start is not None: if -90+1e-6 < self._saw_start < 90-1e-6: ra = radians(self._saw_start) sina = sin(ra) cosa = cos(ra) if ra > 0: pnt = gp_Pnt(0, 0, 0) pln = gp_Pln(pnt, gp_Dir(-sina, 0, cosa)) pnt_out = gp_Pnt(0, 0, self._section[1]) else: pnt = gp_Pnt(0, 0, self._section[1]) pln = gp_Pln(pnt, gp_Dir(sina, 0, -cosa)) pnt_out = gp_Pnt(0, 0, 0) face = BRepBuilderAPI_MakeFace(pln).Shape() tool = BRepPrimAPI_MakeHalfSpace(face, pnt_out).Solid() self._shape = BRepAlgoAPI_Cut(self._shape, tool).Shape() if self._saw_end is not None: if -90 + 1e-6 < self._saw_end < 90-1e-6: ra = radians(self._saw_end) sina = sin(ra) cosa = cos(ra) if ra > 0: pnt = gp_Pnt(self._length, 0, 0) pln = gp_Pln(pnt, gp_Dir(sina, 0, cosa)) pnt_out = gp_Pnt(self._length, 0, self._section[1]) else: pnt = gp_Pnt(self._length, 0, self._section[1]) pln = gp_Pln(pnt, gp_Dir(-sina, 0, -cosa)) pnt_out = gp_Pnt(self._length, 0, 0) face = BRepBuilderAPI_MakeFace(pln).Shape() tool = BRepPrimAPI_MakeHalfSpace(face, pnt_out).Solid() self._shape = BRepAlgoAPI_Cut(self._shape, tool).Shape()
def __init__(self): plotocc.__init__(self) self.b1 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[100, 100, 105]) self.b2 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[210, 210, 210]) self.base = BRepAlgoAPI_Cut(self.b2, self.b1).Shape() self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0)) print(self.b1) top = Topo(self.base) print(top.number_of_faces())
def move_to_box(iname, cname, wname, visualize=False): """Move foam to periodic box. Works on BREP files. Information about physical volumes is lost. Args: iname (str): input filename cname (str): output filename with cells wname (str): output filename with walls visualize (bool): show picture of foam morphology in box if True """ cells = TopoDS_Shape() builder = BRep_Builder() breptools_Read(cells, iname, builder) texp = TopologyExplorer(cells) solids = list(texp.solids()) cells = TopoDS_Compound() builder.MakeCompound(cells) box = BRepPrimAPI_MakeBox(gp_Pnt(1, -1, -1), 3, 3, 3).Shape() vec = gp_Vec(-1, 0, 0) solids = slice_and_move(solids, box, vec) box = BRepPrimAPI_MakeBox(gp_Pnt(-3, -1, -1), 3, 3, 3).Shape() vec = gp_Vec(1, 0, 0) solids = slice_and_move(solids, box, vec) box = BRepPrimAPI_MakeBox(gp_Pnt(-1, 1, -1), 3, 3, 3).Shape() vec = gp_Vec(0, -1, 0) solids = slice_and_move(solids, box, vec) box = BRepPrimAPI_MakeBox(gp_Pnt(-1, -3, -1), 3, 3, 3).Shape() vec = gp_Vec(0, 1, 0) solids = slice_and_move(solids, box, vec) box = BRepPrimAPI_MakeBox(gp_Pnt(-1, -1, 1), 3, 3, 3).Shape() vec = gp_Vec(0, 0, -1) solids = slice_and_move(solids, box, vec) box = BRepPrimAPI_MakeBox(gp_Pnt(-1, -1, -3), 3, 3, 3).Shape() vec = gp_Vec(0, 0, 1) solids = slice_and_move(solids, box, vec) create_compound(solids, cells, builder) breptools_Write(cells, cname) if visualize: display, start_display, _, _ = init_display() display.DisplayShape(cells, update=True) start_display() box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 1, 1, 1).Shape() walls = BRepAlgoAPI_Cut(box, cells).Shape() breptools_Write(walls, wname) if visualize: display, start_display, _, _ = init_display() display.DisplayShape(walls, update=True) start_display()
def general_split_algorithm(array, tool): from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut from OCC.Core.TopTools import TopTools_ListOfShape cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() for s in array: L1.Append(s) L2 = TopTools_ListOfShape() for t in tool: L2.Append(t) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(1.e-18) cut.SetRunParallel(False) cut.Build() return cut.Shape()
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * -self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) cylOrigin = self.sec_origin innerCyl = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(cylOrigin), getGpDir(-self.wDir)), self.d / 2, self.T + 1).Shape() prism = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return prism
def sweep_pipe(edge, xvec, r, wt, geom_repr=ElemType.SOLID): if geom_repr not in [ElemType.SOLID, ElemType.SHELL]: raise ValueError("Sweeping pipe must be either 'solid' or 'shell'") t = TopologyExplorer(edge) points = [v for v in t.vertices()] point = BRep_Tool_Pnt(points[0]) # x, y, z = point.X(), point.Y(), point.Z() direction = gp_Dir(*unit_vector(xvec).astype(float).tolist()) # pipe makeWire = BRepBuilderAPI_MakeWire() makeWire.Add(edge) makeWire.Build() wire = makeWire.Wire() try: if geom_repr == ElemType.SOLID: i = make_circular_sec_face(point, direction, r - wt) elbow_i = BRepOffsetAPI_MakePipe(wire, i).Shape() o = make_circular_sec_face(point, direction, r) elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape() else: elbow_i = None o = make_circular_sec_wire(point, direction, r) elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape() except RuntimeError as e: logging.error(f'Pipe sweep failed: "{e}"') return wire if geom_repr == ElemType.SOLID: boolean_result = BRepAlgoAPI_Cut(elbow_o, elbow_i).Shape() if boolean_result.IsNull(): logging.debug("Boolean returns None") else: boolean_result = elbow_o return boolean_result
def difference(self): children = self.get_children() shapes = [] debug("children: %s" % (children, )) for c in children: if c.shape != None: shapes.append(c.shape) u = None f = None if len(shapes) > 1: f = shapes[0].get_shape() for s in shapes[1:]: f = BRepAlgoAPI_Cut(f, s.get_shape()).Shape() self.shape = SCLShape(f) self.shape.set_shape_color(shapes[0].get_shape_color()) self.children = []
def make_cylinder(p, vec, h, r, t=None): """ :param p: :param vec: :param h: :param r: :param t: Wall thickness (if applicable). Will make a :return: """ cylinder_origin = gp_Ax2(gp_Pnt(p[0], p[1], p[2]), gp_Dir(vec[0], vec[1], vec[2])) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, r, h).Shape() if t is not None: cutout = BRepPrimAPI_MakeCylinder(cylinder_origin, r - t, h).Shape() return BRepAlgoAPI_Cut(cylinder, cutout).Shape() else: return cylinder
def getDaoCase(r, bevel, decor, h): r2 = r * 2 h2 = h / 2 rTop = r + 2 * bevel + decor rSphere = gp_Vec(0, rTop, h2).Magnitude() sphere = BRepPrimAPI_MakeSphere(rSphere).Shape() limit = BRepPrimAPI_MakeBox(gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2, h2)).Shape() case = BRepAlgoAPI_Common(sphere, limit).Shape() case = getShapeTranslate(case, 0, 0, -h2) cylOut = BRepPrimAPI_MakeCylinder(r + bevel + decor, decor * 2).Shape() #SceneDrawShape('out',cylOut) cylIn = BRepPrimAPI_MakeCylinder(r + bevel, decor * 3).Shape() #SceneDrawShape('in',cylIn) bevelTool = BRepAlgoAPI_Cut(cylOut, cylIn).Shape() bevelTool = getShapeTranslate(bevelTool, 0, 0, -bevel / 2) #SceneDrawShape('tool',bevelTool) case = BRepAlgoAPI_Cut(case, bevelTool).Shape() return case
def boolean_cut(base): # Create a cylinder cylinder_radius = 0.25 cylinder_height = 2.0 cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, - cylinder_height / 2.0), gp_Dir(0.0, 0.0, 1.0)) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius, cylinder_height) # Repeatedly move and subtract it from the input shape move = gp_Trsf() boolean_result = base clone_radius = 1.0 for clone in range(8): angle = clone * pi / 4.0 # Move the cylinder move.SetTranslation(gp_Vec(cos(angle) * clone_radius, sin(angle) * clone_radius, 0.0)) moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move, True).Shape() # Subtract the moved cylinder from the drilled sphere boolean_result = BRepAlgoAPI_Cut(boolean_result, moved_cylinder).Shape() return boolean_result
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.length * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) if self.notchObj is not None: uDir = numpy.array([-1.0, 0.0, 0]) wDir = numpy.array([0.0, 1.0, 0.0]) shiftOri = self.D / 2.0 * self.vDir + self.notchObj.width / 2.0 * self.wDir + self.B / 2.0 * -self.uDir # + self.notchObj.width* self.wDir + self.T/2.0 * -self.uDir origin2 = self.sec_origin + shiftOri self.notchObj.place(origin2, uDir, wDir) notchModel = self.notchObj.create_model() prism = BRepAlgoAPI_Cut(prism, notchModel).Shape() return prism