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 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 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 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 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 translate_shape(shape, vec): """ Translate a shape along a vector. :param afem.topology.entities.Shape shape: The shape. :param Union[afem.geometry.entitites.Vector, Sequence] vec: The vector. :return: The translated shape. :rtype: afem.topology.entities.Shape :raise RuntimeError: If the translation fails or is not done. """ trsf = gce_MakeTranslation(vec.gp_vec).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 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 update_shape(self, change=None): d = self.declaration #: Get the shape to apply the tranform to if d.shape: make_copy = True original = coerce_shape(d.shape) else: # Use the first child make_copy = False child = self.get_first_child() original = child.shape t = self.get_transform() transform = BRepBuilderAPI_Transform(original, t, make_copy) shape = transform.Shape() # Convert it back to the original type self.shape = Topology.cast_shape(shape)
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
# 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)
def create_shape(self): """ Create the shape by loading it from the given path. """ shape = self.load_shape() t = self.get_transform() loaded_shape = BRepBuilderAPI_Transform(shape, t, False) self.shape = loaded_shape.Shape()