def scale(occtopology, scale_factor, ref_pypt): """ This function uniformly scales an OCCtopology based on the reference point and the scale factor. Parameters ---------- occtopology : OCCtopology The OCCtopology to be scaled. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex scale_factor : float The scale factor. ref_pypt : tuple of floats The OCCtopology will scale in reference to this point. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) Returns ------- scaled topology : OCCtopology (OCCshape) The scaled OCCtopology. """ xform = gp_Trsf() gp_pnt = construct.make_gppnt(ref_pypt) xform.SetScale(gp_pnt, scale_factor) brep = BRepBuilderAPI_Transform(xform) brep.Perform(occtopology, True) trsfshape = brep.Shape() return trsfshape
def move(orig_pypt, location_pypt, occtopology): """ This function moves an OCCtopology from the orig_pypt to the location_pypt. Parameters ---------- orig_pypt : tuple of floats The OCCtopology will move in reference to this point. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) location_pypt : tuple of floats The destination of where the OCCtopology will be moved in relation to the orig_pypt. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) occtopology : OCCtopology The OCCtopology to be moved. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex Returns ------- moved topology : OCCtopology (OCCshape) The moved OCCtopology. """ gp_ax31 = gp_Ax3(gp_Pnt(orig_pypt[0], orig_pypt[1], orig_pypt[2]), gp_DZ()) gp_ax32 = gp_Ax3( gp_Pnt(location_pypt[0], location_pypt[1], location_pypt[2]), gp_DZ()) aTrsf = gp_Trsf() aTrsf.SetTransformation(gp_ax32, gp_ax31) trsf_brep = BRepBuilderAPI_Transform(aTrsf) trsf_brep.Perform(occtopology, True) trsf_shp = trsf_brep.Shape() return trsf_shp
def TransformShape(self, X: float, Y: float, Z: float, RX: float, RY: float, RZ: float, Shape: TopoDS_Compound) -> TopoDS_Compound: trsf = self.__GetTransform(X, Y, Z, RX, RY, RZ) transform = BRepBuilderAPI_Transform(Shape, trsf, False) transform.Build() return transform.Shape()
def mirror_pnt_dir(brep, pnt, direction, copy=False): ''' @param brep: @param line: ''' trns = gp_Trsf() trns.SetMirror(gp_Ax1(pnt, direction)) brep_trns = BRepBuilderAPI_Transform(brep, trns, copy) with assert_isdone(brep_trns, 'could not produce mirror'): brep_trns.Build() return brep_trns.Shape()
def mirror_axe2(brep, axe2, copy=False): ''' @param brep: @param line: ''' trns = gp_Trsf() trns.SetMirror(axe2) brep_trns = BRepBuilderAPI_Transform(brep, trns, copy) with assert_isdone(brep_trns, 'could not produce mirror'): brep_trns.Build() return brep_trns.Shape()
def translate_topods_from_vector(brep_or_iterable, vec, copy=False): ''' translate a brep over a vector @param brep: the Topo_DS to translate @param vec: the vector defining the translation @param copy: copies to brep if True ''' trns = gp_Trsf() trns.SetTranslation(vec) brep_trns = BRepBuilderAPI_Transform(brep_or_iterable, trns, copy) brep_trns.Build() return brep_trns.Shape()
def scale_uniformal(brep, pnt, factor, copy=False): ''' translate a brep over a vector @param brep: the Topo_DS to translate @param pnt: a gp_Pnt @param triple: scaling factor @param copy: copies to brep if True ''' trns = gp_Trsf() trns.SetScale(pnt, factor) brep_trns = BRepBuilderAPI_Transform(brep, trns, copy) brep_trns.Build() return brep_trns.Shape()
def rotate(brep, axe, degree, copy=False): ''' @param brep: @param axe: @param degree: ''' from math import radians trns = gp_Trsf() trns.SetRotation(axe, radians(degree)) brep_trns = BRepBuilderAPI_Transform(brep, trns, copy) with assert_isdone(brep_trns, 'could not produce rotation'): brep_trns.Build() return ST(brep_trns.Shape())
def translate_topods_from_vector(brep, vec, copy=False): """Translate a brep over a vector. Args: brep (BRep): the Topo_DS to translate vec (gp_Vec): the vector defining the translation copy (bool): copies to brep if True """ trns = gp_Trsf() trns.SetTranslation(vec) brep_trns = BRepBuilderAPI_Transform(brep, trns, copy) brep_trns.Build() return brep_trns.Shape()
def transformed_shape(self): r"""The shape of the part, placed in its final location Returns ------- an OCC shape, in its final location """ trsf = gp_Trsf() m = self.combined_matrix trsf.SetValues(m[0, 0], m[0, 1], m[0, 2], m[0, 3], m[1, 0], m[1, 1], m[1, 2], m[1, 3], m[2, 0], m[2, 1], m[2, 2], m[2, 3]) transformed = BRepBuilderAPI_Transform(self.shape, trsf) return transformed.Shape()
def rotate_shp_3_axis(shape, revolve_axis, rotation): """ Rotate a shape around a pre-defined rotation axis gp_Ax1. @param rotation : rotation in degrees around (gp_Ax1) @param shape : shape in question @param revolve_axis : rotation axis gp_Ax1 @return : the rotated shape. """ alpha = gp_Trsf() alpha.SetRotation(revolve_axis, np.deg2rad(rotation)) brep_trns = BRepBuilderAPI_Transform(shape, alpha, False) shp = brep_trns.Shape() return shp
def translate_topods_from_vector(brep_or_iterable, vec, copy=False): ''' translate a brep over a vector @param brep: the Topo_DS to translate @param vec: the vector defining the translation @param copy: copies to brep if True ''' st = ShapeToTopology() trns = gp_Trsf() trns.SetTranslation(vec) if issubclass(brep_or_iterable.__class__, TopoDS_Shape): brep_trns = BRepBuilderAPI_Transform(brep_or_iterable, trns, copy) brep_trns.Build() return st(brep_trns.Shape()) else: return [translate_topods_from_vector(brep_or_iterable, vec, copy) for i in brep_or_iterable]
def makeWholeWire(): global myWireProfile xAxis = gp_OX() # Set up the mirror aTrsf = gp_Trsf() aTrsf.SetMirror(xAxis) # Apply the mirror transform aBRepTrsf = BRepBuilderAPI_Transform(aWire, aTrsf) # Convert mirrored shape to a wire aMirroredShape = aBRepTrsf.Shape() aMirroredWire = topods_Wire(aMirroredShape) # Combine the two wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() return myWireProfile
def mirror_shape(shape, pln): """ Mirror a shape about a plane. :param afem.topology.entities.Shape shape: The shape. :param afem.geometry.entities.Plane pln: The plane. :return: The mirrored shape. :rtype: afem.topology.entities.Shape :raise RuntimeError: If the transformation fails or is not done. """ trsf = gce_MakeMirror(pln.gp_pln).Value() builder = BRepBuilderAPI_Transform(shape.object, trsf, True) if not builder.IsDone(): raise RuntimeError('Failed to mirror the shape.') return Shape.wrap(builder.Shape())
def create_model(self, rotate_angle=None): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array if rotate_angle == None: prism1 = makePrismFromFace(aFace, extrudeDir) else: prism = makePrismFromFace(aFace, extrudeDir) trns = gp_Trsf() # axis = numpy.array([1.0, 0.0, 0.0]) angle = radians(rotate_angle) trns.SetRotation(gp_OX(), angle) brep_trns = BRepBuilderAPI_Transform(prism, trns, False) brep_trns.Build() prism1 = brep_trns.Shape() return prism1
def rotate_shape(shape, axis, angle, unite="deg"): """Rotate a shape around an axis, with a given angle. @param shape : the shape to rotate @point : the origin of the axis @vector : the axis direction @angle : the value of the rotation @return: the rotated shape. """ assert_shape_not_null(shape) if unite == "deg": # convert angle to radians angle = radians(angle) trns = gp_Trsf() trns.SetRotation(axis, angle) brep_trns = BRepBuilderAPI_Transform(shape, trns, False) brep_trns.Build() shp = brep_trns.Shape() return shp
def makeWholeWire(event=None): global myWireProfile xAxis = gp_OX() # Set up the mirror aTrsf = gp_Trsf() aTrsf.SetMirror(xAxis) # Apply the mirror transform aBRepTrsf = BRepBuilderAPI_Transform(aWire, aTrsf) # Convert mirrored shape to a wire aMirroredShape = aBRepTrsf.Shape() aMirroredWire = topods_Wire(aMirroredShape) # Combine the two wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() display.DisplayColoredShape(myWireProfile, 'BLUE') display.Repaint() win.statusBar().showMessage('Make whole wire complete')
def rotate_shp_3_axis(shape, rx, ry, rz, unity="deg"): """ Rotate a shape around (O,x), (O,y) and (O,z). @param rx_degree : rotation around (O,x) @param ry_degree : rotation around (O,y) @param rz_degree : rotation around (O,z) @return : the rotated shape. """ if unity == "deg": # convert angle to radians rx = radians(rx) ry = radians(ry) rz = radians(rz) alpha = gp_Trsf() alpha.SetRotation(gp_OX(), rx) beta = gp_Trsf() beta.SetRotation(gp_OY(), ry) gamma = gp_Trsf() gamma.SetRotation(gp_OZ(), rz) brep_trns = BRepBuilderAPI_Transform(shape, alpha * beta * gamma, False) shp = brep_trns.Shape() return shp
def _place(self): """ put the part where it belongs. This should be called after the shape has been initialized, so that the shape can be transformed """ assert (self._shape is not None) if self._parent is not None: trans = self._parent.shape.Location().Transformation() else: trans = gp_Trsf() translation = gp_Trsf() translation.SetTranslation(gp_Vec(*self._position)) trans = trans * translation rot = euler_to_gp_trsf(self._orientation) trans = trans * rot brep_trns = BRepBuilderAPI_Transform(self._shape, trans, False) brep_trns.Build() self._shape = brep_trns.Shape()
def rotate(occtopology, rot_pypt, pyaxis, degree): """ This function rotates an OCCtopology based on the rotation point, an axis and the rotation degree. Parameters ---------- occtopology : OCCtopology The OCCtopology to be rotated. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex rot_pypt : tuple of floats The OCCtopology will rotate in reference to this point. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) pyaxis : tuple of floats The OCCtopology will rotate along this axis. A pyaxis is a tuple that documents the xyz of a direction e.g. (x,y,z) degree : float The degree of rotation. Returns ------- rotated topology : OCCtopology (OCCshape) The rotated OCCtopology. """ from math import radians gp_ax3 = gp_Ax1(gp_Pnt(rot_pypt[0], rot_pypt[1], rot_pypt[2]), gp_Dir(pyaxis[0], pyaxis[1], pyaxis[2])) aTrsf = gp_Trsf() aTrsf.SetRotation(gp_ax3, radians(degree)) rot_brep = BRepBuilderAPI_Transform(aTrsf) rot_brep.Perform(occtopology, True) rot_shape = rot_brep.Shape() return rot_shape
def get_wire(self): if (self.wire == None): occ_edges = [] for i, e in enumerate(self.edges): o = "Element %i/%i: " % (i, len(self.edges)) if (isinstance(e, Line3)): occ_edges.append(e.to_edge()) elif (isinstance(e, Fillet2)): if ((len(self.edges)) <= (i + 1)): error("Not enough elements for fillet") exit(0) else: occ_edges.append( e.to_edge(self.edges[i - 1], self.edges[i + 1])) o += repr(e) debug(o) if occ_edges == []: return None self.wire = make_wire(occ_edges) trsf_wire = BRepBuilderAPI_Transform(self.wire, self.trsf) trsf_shape = trsf_wire.Shape() self.wire = topods.Wire(trsf_shape) self.face = None return self.wire
def translate_shp(shp, vec, copy=False): trns = gp_Trsf() trns.SetTranslation(vec) brep_trns = BRepBuilderAPI_Transform(shp, trns, copy) brep_trns.Build() return brep_trns.Shape()
from cadracks_core.model import AnchorablePart, Assembly from cadracks_core.anchors import Anchor ap1 = AnchorablePart( shape=BRepPrimAPI_MakeBox(10, 10, 10).Shape(), anchors=[Anchor(p=(5, 5, 10), u=(0, 0, 1), v=(0, 1, 0), name='t1')], name='ap1') m = gp_Trsf() m.SetTranslation(gp_Vec(100, 0, 0)) trf = BRepBuilderAPI_Transform(m) s2 = BRepPrimAPI_MakeBox(20, 20, 20).Shape() trf.Perform(s2, False) ap2 = AnchorablePart( shape=trf.Shape(), anchors=[Anchor(p=(110, 10, 20), u=(0, 0, 1), v=(0, 1, 0), name='t2')], name='ap2') a = Assembly(root_part=ap1, name='simple assembly') a.add_part(part_to_add=ap2, part_to_add_anchors=['t2'], receiving_parts=[ap1], receiving_parts_anchors=['t1'], links=[Joint(anchor=ap1.transformed_anchors['t1'], rx=1)]) __assembly__ = a if __name__ == "__main__": from OCC.Display.SimpleGui import init_display
# 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)
cubes = list() new_cubes = list() for i in range(nb_cubes): randx = randint(-random_range, random_range) randy = randint(-random_range, random_range) randz = randint(-random_range, random_range) m = gp_Trsf() m.SetTranslation(gp_Vec(randx, randy, randz)) trf = BRepBuilderAPI_Transform(m) s2 = BRepPrimAPI_MakeBox(10, 10, 10).Shape() trf.Perform(s2, False) cubes.append( AnchorablePart(shape=trf.Shape(), anchors=[ Anchor(p=(5 + randx, 5 + randy, 10 + randz), u=(0, 0, 1), v=(0, 1, 0), name='top'), Anchor(p=(5 + randx, 5 + randy, 0 + randz), u=(0, 0, -1), v=(0, 1, 0), name='bottom') ], name='ap')) new_cubes = deepcopy(cubes) a = Assembly(root_part=new_cubes[0], name='cubes pile')
def get_boundingbox_shape(bb): """ Given the dict returned by `get_boundingbox`, this function creates a TopoDS_Compound to visualize the bounding box, including annotations :param bb: dict returned by `get_boundingbox` :return: a TopoDS_Compound to visualize the bounding box """ compound = TopoDS_Compound() builder = BRep_Builder() builder.MakeCompound(compound) bb_box = BRepPrimAPI_MakeBox(bb['dx'], bb['dy'], bb['dz']).Shape() translation = gp_Trsf() translation.SetTranslation(gp_Vec(bb['xmin'], bb['ymin'], bb['zmin'])) brep_trns = BRepBuilderAPI_Transform(bb_box, translation, False) brep_trns.Build() bb_box = brep_trns.Shape() anEdgeExplorer = TopExp_Explorer(bb_box, TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) builder.Add(compound, anEdge) anEdgeExplorer.Next() dx_string = text_to_brep(str(round(bb['dx'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True) transformation = gp_Trsf() transformation.SetTranslation(gp_Vec(bb['xmin'] + 120, bb['ymin'] - 120, 0)) brep_trns = BRepBuilderAPI_Transform(dx_string, transformation, False) brep_trns.Build() dx_string = brep_trns.Shape() builder.Add(compound, dx_string) dy_string = text_to_brep(str(round(bb['dy'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True) t1 = gp_Trsf() z = gp_Ax1(gp_Pnt(), gp_Dir(0, 0, 1)) t1.SetRotation(z, radians(90)) t2 = gp_Trsf() t2.SetTranslation(gp_Vec(bb['xmin'] - 25, bb['ymin'] + 120, 0)) brep_trns = BRepBuilderAPI_Transform(dy_string, t2 * t1, False) brep_trns.Build() dy_string = brep_trns.Shape() builder.Add(compound, dy_string) dz_string = text_to_brep(str(round(bb['dz'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True) x = gp_Ax1(gp_Pnt(), gp_Dir(1, 0, 0)) y = gp_Ax1(gp_Pnt(), gp_Dir(0, 1, 0)) z = gp_Ax1(gp_Pnt(), gp_Dir(0, 0, 1)) t1 = gp_Trsf() t1.SetRotation(z, radians(90)) t2 = gp_Trsf() t2.SetRotation(y, radians(90)) t3 = gp_Trsf() t3.SetRotation(x, radians(90)) t4 = gp_Trsf() t4.SetTranslation(gp_Vec(bb['xmin'], bb['ymin'] - 25, 120)) brep_trns = BRepBuilderAPI_Transform(dz_string, t4 * t3 * t2 * t1, False) brep_trns.Build() dz_string = brep_trns.Shape() builder.Add(compound, dz_string) return compound
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()
def cut_out(base): outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter) inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter) geom_outer = GCE2d_MakeCircle(outer).Value() geom_inner = GCE2d_MakeCircle(inner).Value() geom_inner.Reverse() base_angle = (2. * M_PI) / mounting_hole_count hole_angle = atan(hole_radius / mounting_radius) correction_angle = 3 * hole_angle left = gp_Lin2d(gp_Origin2d(), gp_DX2d()) right = gp_Lin2d(gp_Origin2d(), gp_DX2d()) left.Rotate(gp_Origin2d(), correction_angle) right.Rotate(gp_Origin2d(), base_angle - correction_angle) geom_left = GCE2d_MakeLine(left).Value() geom_right = GCE2d_MakeLine(right).Value() inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left) inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right) inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right) inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left) if inter_1.Point(1).X() > 0: p1 = inter_1.Point(1) else: p1 = inter_1.Point(2) if inter_2.Point(1).X() > 0: p2 = inter_2.Point(1) else: p2 = inter_2.Point(2) if inter_3.Point(1).X() > 0: p3 = inter_3.Point(1) else: p3 = inter_3.Point(2) if inter_4.Point(1).X() > 0: p4 = inter_4.Point(1) else: p4 = inter_4.Point(2) trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value() trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value() plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0), gp_Pnt(p3.X(), p3.Y(), 0)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p1.X(), p1.Y(), 0)).Edge() cutout_wire = BRepBuilderAPI_MakeWire(arc1) cutout_wire.Add(lin1) cutout_wire.Add(arc2) cutout_wire.Add(lin2) # Turn the wire into a face cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire()) filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face()) explorer = BRepTools_WireExplorer(cutout_wire.Wire()) while explorer.More(): vertex = explorer.CurrentVertex() filleted_face.AddFillet(vertex, roller_radius) explorer.Next() cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(), gp_Vec(0.0, 0.0, thickness)).Shape() result = base rotate = gp_Trsf() for i in range(0, mounting_hole_count): rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count) rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True) result = BRepAlgoAPI_Cut(result, rotated_cutout.Shape()).Shape() return result