def make_shell(*args): shell = BRepBuilderAPI_MakeShell(*args) st = ShapeToTopology() with assert_isdone(shell, 'failed to produce shell'): result = shell.Shell() shell.Delete() return st(result)
def make_prism(profile, vec): ''' makes a finite prism ''' pri = BRepPrimAPI_MakePrism(profile, vec, True) with assert_isdone(pri, 'failed building prism'): pri.Build() return pri.Shape()
def distance_on_curve(self, distance, close_parameter, estimate_parameter): '''returns the parameter if there is a parameter on the curve with a distance length from u raises OutOfBoundary if no such parameter exists ''' gcpa = GCPnts_AbscissaPoint(self.adaptor, distance, close_parameter, estimate_parameter, 1e-5) with assert_isdone(gcpa, 'couldnt compute distance on curve'): return gcpa.Parameter()
def curve_to_bspline(crv_handle, tolerance=TOLERANCE, continuity=GeomAbs_C1, sections=300, degree=12): approx_curve = GeomConvert_ApproxCurve(crv_handle, tolerance, continuity, sections, degree) with assert_isdone(approx_curve, 'could not compute bspline from curve'): return approx_curve.Curve()
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 rotate(brep, axe, degree, copy=True): ''' @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 make_closed_polygon(*args): poly = BRepBuilderAPI_MakePolygon() for pt in args: if isinstance(pt, list) or isinstance(pt, tuple): for i in pt: poly.Add(i) else: poly.Add(pt) poly.Build() poly.Close() with assert_isdone(poly, 'failed to produce wire'): result = poly.Wire() return result
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) wire.Build() with assert_isdone(wire, 'failed to produce wire'): result = wire.Wire() return result
def make_polygon(args, closed=False): poly = BRepBuilderAPI_MakePolygon() for pt in args: # support nested lists if isinstance(pt, list) or isinstance(pt, tuple): for i in pt: poly.Add(i) else: poly.Add(pt) if closed: poly.Close() poly.Build() with assert_isdone(poly, 'failed to produce wire'): result = poly.Wire() return result
def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2, check_compatibility=True): from OCC.BRepOffsetAPI import BRepOffsetAPI_ThruSections sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance) for i in elements: if isinstance(i, TopoDS_Wire): sections.AddWire(i) elif isinstance(i, TopoDS_Vertex): sections.AddVertex(i) else: raise TypeError('elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool' % i.__class__) sections.CheckCompatibility(check_compatibility) sections.SetContinuity(continuity) sections.Build() with assert_isdone(sections, 'failed lofting'): te = ShapeToTopology() loft = te(sections.Shape()) return loft
def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2, check_compatibility=True): from OCC.BRepOffsetAPI import BRepOffsetAPI_ThruSections sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance) for i in elements: if isinstance(i, TopoDS_Wire): sections.AddWire(i) elif isinstance(i, TopoDS_Vertex): sections.AddVertex(i) else: raise TypeError( 'elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool' % i.__class__) sections.CheckCompatibility(check_compatibility) sections.SetContinuity(continuity) sections.Build() with assert_isdone(sections, 'failed lofting'): te = ShapeToTopology() loft = te(sections.Shape()) return loft
def make_pipe(spine, profile): from OCC.BRepOffsetAPI import BRepOffsetAPI_MakePipe pipe = BRepOffsetAPI_MakePipe(spine, profile) with assert_isdone(pipe, 'failed building pipe'): pipe.Build() return pipe.Shape()
def make_vertex(*args): vert = BRepBuilderAPI_MakeVertex(*args) with assert_isdone(vert, 'failed to produce vertex'): result = vert.Vertex() vert.Delete() return result
def make_box(*args): box = BRepPrimAPI_MakeBox(*args) box.Build() with assert_isdone(box, 'failed to built a cube...'): return box.Shape()
def make_face(*args): face = BRepBuilderAPI_MakeFace(*args) with assert_isdone(face, 'failed to produce face'): result = face.Face() face.Delete() return result
def make_evolved(spine, profile): evol = BRepOffsetAPI_MakeEvolved(spine, profile) with assert_isdone(evol, 'failed buillding evolved'): evol.Build() return evol.Evolved()
def make_solid(*args): sld = BRepBuilderAPI_MakeSolid(*args) with assert_isdone(sld, 'failed to produce solid'): result = sld.Solid() sld.Delete() return result
def make_edge(*args): edge = BRepBuilderAPI_MakeEdge(*args) with assert_isdone(edge, 'failed to produce edge'): result = edge.Edge() edge.Delete() return result