def Compute(self): self.myGeometry = Geom_SurfaceOfRevolution(self.myCurve, self.myRevolveAxis) face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry, True, 1.0e-6) face.Build() self.myAIS_InteractiveObject = AIS_Shape(face.Shape()) self.myContext.Display(self.myAIS_InteractiveObject, True)
def main(): vertices = [gp_Pnt(p[0], p[1], p[2]) for p in mesh['vertices']] oFaces = [] builder = BRep_Builder() shell = TopoDS_Shell() builder.MakeShell(shell) for face in mesh['faces']: edges = [] face.reverse() for i in range(len(face)): cur = face[i] nxt = face[(i + 1) % len(face)] segment = GC_MakeSegment(vertices[cur], vertices[nxt]) edges.append(BRepBuilderAPI_MakeEdge(segment.Value())) wire = BRepBuilderAPI_MakeWire() for edge in edges: wire.Add(edge.Edge()) oFace = BRepBuilderAPI_MakeFace(wire.Wire()) builder.Add(shell, oFace.Shape()) write_stl_file(shell, "./cube_binding.stl")
def extrude_polyline2d(polyline, frame, height): pol3d = polyline.to_frame(frame) lines = [] yb_point = Point([frame[0][i] for i in range(3)]) yb_vec = Vector([frame[1][0][i] for i in range(3)]).unit() print '*************' print yb_vec orig = gp_Pnt(frame[0][0], frame[0][1], frame[0][2]) vec = gp_Dir(yb_vec[0], yb_vec[1], yb_vec[2]) plane = gp_Pln(orig, vec) for i, p in enumerate(pol3d[:-1]): print p print 'zob' gp0 = gp_Pnt(p[0], p[1], p[2]) gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2]) lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge()) wire = BRepBuilderAPI_MakeWire(lines[0]) for l in lines[1:]: wire.Add(l) face = BRepBuilderAPI_MakeFace(wire.Wire()) print 'normal' print[vec.X(), vec.Y(), vec.Z()] extrude = BRepPrimAPI_MakePrism( face.Shape(), gp_Vec(height * vec.X(), height * vec.Y(), height * vec.Z())).Shape() return extrude
def extrude(): """Extrude profile on active WP to create a new part.""" wp = win.activeWp if len(win.lineEditStack) == 2: name = win.lineEditStack.pop() length = float(win.lineEditStack.pop()) * win.unitscale wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return myFaceProfile = BRepBuilderAPI_MakeFace(wp.wire) aPrismVec = wp.wVec * length myBody = BRepPrimAPI_MakePrism(myFaceProfile.Shape(), aPrismVec).Shape() uid = doc.addComponent(myBody, name, DEFAULT_COLOR) win.build_tree() win.setActivePart(uid) win.draw_shape(uid) win.syncUncheckedToHideList() win.statusBar().showMessage("New part created.") win.clearCallback() else: win.registerCallback(extrudeC) win.lineEdit.setFocus() statusText = "Enter extrusion length, then enter part name." win.statusBar().showMessage(statusText)
def _make_face(surf, u1=None, u2=None, v1=None, v2=None): if u1 is None: u1, u2, v1, v2 = surf.Surface().Bounds() algo = BRepBuilderAPI_MakeFace(surf.Surface(), u1, u2, v1, v2, 1e-6) algo.Build() return Shape(algo.Face())
def Compute(self): if len(self.myCurves) == 2: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myStyle) elif len(self.myCurves) == 3: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myCurves[2], self.myStyle) elif len(self.myCurves) == 4: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myCurves[2], self.myCurves[3], self.myStyle) self.myGeometry = self.myGeometry.Surface() face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry, True, 1.0e-6) face.Build() face = face.Shape() self.myAIS_InteractiveObject = AIS_Shape(face) self.myContext.Display(self.myAIS_InteractiveObject, True) self.SetCenter(face) self.InitClippingPlane()
def brep_feat_local_revolution(event=None): S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = list(TopologyExplorer(S).faces()) F1 = faces[2] surf = BRep_Tool_Surface(F1) D = gp_OX() MW1 = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(100., 100.) p2 = gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(200., 100.) p2 = gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(150., 200.) p2 = gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) MKF1 = BRepBuilderAPI_MakeFace() MKF1.Init(surf, False, 1e-6) MKF1.Add(MW1.Wire()) FP = MKF1.Face() breplib_BuildCurves3d(FP) MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True) F2 = faces[4] MKrev.Perform(F2) display.EraseAll() display.DisplayShape(MKrev.Shape()) display.FitAll()
def pull(): """Pull profile on active WP onto active part.""" wp = win.activeWp if win.lineEditStack: length = 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 pullProfile = BRepBuilderAPI_MakeFace(wire) aPrismVec = wp.wVec * length tool = BRepPrimAPI_MakePrism(pullProfile.Shape(), aPrismVec).Shape() newPart = BRepAlgoAPI_Fuse(workPart, tool).Shape() win.erase_shape(uid) doc.replaceShape(uid, newPart) win.draw_shape(uid) win.setActivePart(uid) win.statusBar().showMessage("Pull operation complete") win.clearCallback() else: win.registerCallback(pullC) win.lineEdit.setFocus() statusText = "Enter pull distance (pos in +w direction)" win.statusBar().showMessage(statusText)
def makeFace(event=None): global myFaceProfile myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) if myFaceProfile.IsDone(): bottomFace = myFaceProfile.Face() display.DisplayShape(bottomFace, color='YELLOW', transparency=0.6) display.Repaint() win.statusBar().showMessage('Make face complete')
def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(TopologyExplorer(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.FitAll()
def Compute(self): self.myGeometry = GeomFill_Pipe(self.myPath, self.myProfile, self.myProfile) self.myGeometry.Perform() face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry.Surface(), True, 1.0e-6) face.Build() self.myAIS_InteractiveObject = AIS_Shape(face.Shape()) self.myContext.Display(self.myAIS_InteractiveObject, True)
def __init__(self, wire: TopoDS_Wire): super().__init__() mkface = BRepBuilderAPI_MakeFace(wire) if not mkface.IsDone(): OCCWrapper.OccError('OccFaceFromWire', mkface) else: self.done = True self.face = mkface.Face() return
def _create_from_svg(cls, filepath, height_mm): assert isinstance(filepath, pathlib.Path) if not filepath.is_file(): raise IOError( "Unable to create Face from image file: {}. File does not exist" .format(filepath)) # Load as a document rather than as paths directly (using svg2paths) because # the document respects any transforms doc = Document(str(filepath)) paths = doc.paths() continuous_paths = cls._get_continuous_subpaths(paths) continuous_paths = cls._remove_zero_length_lines(continuous_paths) ymin = min([path.bbox()[2] for path in continuous_paths]) ymax = max([path.bbox()[3] for path in continuous_paths]) current_height = ymax - ymin assert current_height >= 0 scaling_factor = height_mm / current_height scaled_paths = [ path.scaled(scaling_factor, -scaling_factor) for path in continuous_paths ] # Line up to the x and y axes xmin = min([path.bbox()[0] for path in scaled_paths]) ymin = min([path.bbox()[2] for path in scaled_paths]) translated_paths = [ path.translated(complex(-xmin, -ymin)) for path in scaled_paths ] normalized_paths = cls._normalize_paths_clockwise(translated_paths) path_hierarchies = cls._create_path_hierarchy(normalized_paths) # Currently only really support a single main contiguous shape with holes. # Although multiple disconnected shapes can be generated, they won't be # perfectly represented by the final geometry because some material has to # connect them assert len(path_hierarchies) == 1 faceMaker = BRepBuilderAPI_MakeFace(PL_XZ) for path_hierarchy in path_hierarchies: root_edges = cls._create_edges_from_path( path_hierarchy.root_path()) root_wire = cls._create_wire_from_edges(root_edges) faceMaker.Add(root_wire) for sub_path in path_hierarchy.child_paths(): sub_path_edges = cls._create_edges_from_path(sub_path) sub_path_wire = cls._create_wire_from_edges(sub_path_edges) # reverse the wire so it creates a hole sub_path_wire.Reverse() faceMaker.Add(sub_path_wire) return faceMaker.Shape()
def heightmap_from_image(event=None): """ takes the heightmap from a jpeg file and apply a texture this example requires numpy/matplotlib """ print("opening image") heightmap = Image.open('../assets/images/mountain_heightmap.jpg') heightmap.show() width = heightmap.size[0] height = heightmap.size[1] # create the gp_Pnt array print("image size: ", width, height) print("parse image and fill in point array") for i in range(1, width): for j in range(1, height): # all 3 RGB values are equal, just take the first one # vertex 1 height_value = heightmap.getpixel((i - 1, j - 1))[0] v1 = gp_Pnt(i, j, float(height_value) / 10) # vertex 2 height_value = heightmap.getpixel((i, j - 1))[0] v2 = gp_Pnt(i + 1, j, float(height_value) / 10) # vertex 3 height_value = heightmap.getpixel((i, j))[0] v3 = gp_Pnt(i + 1, j + 1, float(height_value) / 10) # vertex 4 height_value = heightmap.getpixel((i - 1, j))[0] v4 = gp_Pnt(i, j + 1, float(height_value) / 10) # boundaries b1 = boundary_curve_from_2_points(v1, v2) b2 = boundary_curve_from_2_points(v2, v3) b3 = boundary_curve_from_2_points(v3, v4) b4 = boundary_curve_from_2_points(v4, v1) # bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2) bConstrainedFilling.Init(b1, b2, b3, b4, False) srf1 = bConstrainedFilling.Surface() # make a face from this srf patch = BRepBuilderAPI_MakeFace() bounds = True toldegen = 1e-6 patch.Init(srf1, bounds, toldegen) patch.Build() display.DisplayShape(patch.Face()) # then create faces print("%s%%" % int(float(i) / width * 100)) #display.process_events() display.FitAll() # finally display image heightmap.show()
def get_faceted_L_shape(x, y, z): pnt_A = gp_Pnt(x + 0, y + 0, z + 0) pnt_B = gp_Pnt(x + 20, y + 0, z + 0) pnt_C = gp_Pnt(x + 20, y + 10, z + 0) pnt_D = gp_Pnt(x + 0, y + 10, z + 0) pnt_E = gp_Pnt(x + 0, y + 0, z + 20) pnt_F = gp_Pnt(x + 10, y + 0, z + 20) pnt_G = gp_Pnt(x + 10, y + 10, z + 20) pnt_H = gp_Pnt(x + 0, y + 10, z + 20) pnt_I = gp_Pnt(x + 10, y + 0, z + 10) pnt_J = gp_Pnt(x + 10, y + 10, z + 10) pnt_K = gp_Pnt(x + 20, y + 0, z + 10) pnt_L = gp_Pnt(x + 20, y + 10, z + 10) face_1 = make_face_from_4_points(pnt_A, pnt_B, pnt_C, pnt_D) face_2 = make_face_from_4_points(pnt_B, pnt_C, pnt_L, pnt_K) face_3 = make_face_from_4_points(pnt_E, pnt_F, pnt_G, pnt_H) face_4 = make_face_from_4_points(pnt_A, pnt_E, pnt_H, pnt_D) face_5 = make_face_from_4_points(pnt_G, pnt_F, pnt_I, pnt_J) face_6 = make_face_from_4_points(pnt_I, pnt_K, pnt_L, pnt_J) polygon_1 = BRepBuilderAPI_MakePolygon() polygon_1.Add(pnt_A) polygon_1.Add(pnt_B) polygon_1.Add(pnt_K) polygon_1.Add(pnt_I) polygon_1.Add(pnt_F) polygon_1.Add(pnt_E) polygon_1.Close() face_7 = BRepBuilderAPI_MakeFace(polygon_1.Wire()).Face() polygon_2 = BRepBuilderAPI_MakePolygon() polygon_2.Add(pnt_D) polygon_2.Add(pnt_H) polygon_2.Add(pnt_G) polygon_2.Add(pnt_J) polygon_2.Add(pnt_L) polygon_2.Add(pnt_C) polygon_2.Close() face_8 = BRepBuilderAPI_MakeFace(polygon_2.Wire()).Face() sew = BRepBuilderAPI_Sewing() for face in [ face_1, face_2, face_3, face_4, face_5, face_6, face_7, face_8 ]: sew.Add(face) sew.Perform() return sew.SewedShape()
def add_wire_to_face(face, wire, reverse=False): ''' apply a wire to a face use reverse to set the orientation of the wire to opposite @param face: @param wire: @param reverse: ''' face = BRepBuilderAPI_MakeFace(face) if reverse: wire.Reverse() face.Add(wire) result = face.Face() face.Delete() return result
def make_PolyPlane(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()): lxy = radi - 0.1 pnts = [] angl = 360 / num for i in range(num): thet = np.deg2rad(i * angl) + np.deg2rad(shft) x, y = radi * np.sin(thet), radi * np.cos(thet) pnts.append(gp_Pnt(x, y, 0)) pnts.append(pnts[0]) poly = make_polygon(pnts) brep = BRepBuilderAPI_MakeFace(gp_Pln(), poly) brep.Add(poly) face = brep.Face() face.Location(set_loc(gp_Ax3(), axs)) return face
def constrained_filling(event=None): # left pts1 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0), gp_Pnt(0, 1, 0.3), gp_Pnt(0, 2, -0.3), gp_Pnt(0, 3, 0.15), gp_Pnt(0, 4, 0))) # front pts2 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0), gp_Pnt(1, 0, -0.3), gp_Pnt(2, 0, 0.15), gp_Pnt(3, 0, 0), gp_Pnt(4, 0, 0))) # back pts3 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 4, 0), gp_Pnt(1, 4, 0.3), gp_Pnt(2, 4, -0.15), gp_Pnt(3, 4, 0), gp_Pnt(4, 4, 1))) # rechts pts4 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(4, 0, 0), gp_Pnt(4, 1, 0), gp_Pnt(4, 2, 2), gp_Pnt(4, 3, -0.15), gp_Pnt(4, 4, 1))) spl1, b1 = get_simple_bound(pts1) spl2, b2 = get_simple_bound(pts2) spl3, b3 = get_simple_bound(pts3) spl4, b4 = get_simple_bound(pts4) # build the constrained surface bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2) bConstrainedFilling.Init(b1, b2, b3, b4, False) srf1 = bConstrainedFilling.Surface() display.EraseAll() for i in [spl1, spl2, spl3, spl4]: edg = BRepBuilderAPI_MakeEdge(i) edg.Build() _edg = edg.Shape() display.DisplayShape(_edg) f = BRepBuilderAPI_MakeFace(srf1, 1e-6) f.Build() shp = f.Shape() return shp
def make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile # explicitly tell to not use ssl verification ssl._create_default_https_context = ssl._create_unverified_context print("Connecting to m-selig, retrieving foil data") f = urllib2.urlopen(foil_dat_url) print("Building foil geometry") plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., 1.)) # Z=0 plan / XY plan section_pts_2d = [] for line in f.readlines()[1:]: # The first line contains info only # 2 - do some cleanup on the data (mostly dealing with spaces) data = line.split() # 3 - create an array of points if len(data) == 2: # two coordinates for each point section_pts_2d.append( gp_Pnt2d( float(data[0]) * self.chord, float(data[1]) * self.chord)) # 4 - use the array to create a spline describing the airfoil section spline_2d = Geom2dAPI_PointsToBSpline( point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d), len(section_pts_2d) - 1, # order min len(section_pts_2d)) # order max spline = geomapi.To3d(spline_2d.Curve(), plan) # 5 - figure out if the trailing edge has a thickness or not, # and create a Face try: #first and last point of spline -> trailing edge trailing_edge = make_edge( gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0), gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0)) face = BRepBuilderAPI_MakeFace( make_wire([make_edge(spline), trailing_edge])) except AssertionError: # the trailing edge segment could not be created, probably because # the points are too close # No need to build a trailing edge face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline))) # 6 - extrude the Face to create a Solid return BRepPrimAPI_MakePrism( face.Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 0., self.span))).Shape()
def quad_to_face(points: Quad) -> TopoDS_Face: """Convert a quad to a BRep face with an underlying ruled surface. Parameters ---------- points : [point, point, point, point] Four points defining a quad. Returns ------- TopoDS_Face Raises ------ AssertionError If the number of points is not 4. """ assert len(points) == 4, "The number of input points should be four." points = [Point(*point) for point in points] curve1 = GeomAPI_PointsToBSpline( array1_from_points1([points[0], points[1]])).Curve() curve2 = GeomAPI_PointsToBSpline( array1_from_points1([points[3], points[2]])).Curve() srf = geomfill_Surface(curve1, curve2) return BRepBuilderAPI_MakeFace(srf, 1e-6).Face()
def triangle_to_face(points: Triangle) -> TopoDS_Face: """Convert a triangle to a BRep face. Parameters ---------- points : [point, point, point] Three points defining a triangle. Returns ------- TopoDS_Face Raises ------ AssertionError If the number of points is not 3. """ assert len(points) == 3, "The number of input points should be three." polygon = BRepBuilderAPI_MakePolygon() for point in points: polygon.Add(gp_Pnt(*point)) polygon.Close() wire = polygon.Wire() return BRepBuilderAPI_MakeFace(wire).Face()
def slice_selected_surfaces(nozz_dia, direc): slices = [] counter1 = 0 edge_clearance = nozz_dia / 2 xmin, ymin, zzz, xmax, ymax, zzz =\ Slicing.get_surfaces_boundingbox(surfaces) new_surfaces = Slicing.sort_surfaces(surfaces, direc) if direc == 'X': imin = xmin imax = xmax elif direc == 'Y': imin = ymin imax = ymax for i in numpy.arange(imin+edge_clearance, imax-edge_clearance+nozz_dia/2, \ nozz_dia): if direc == 'X': plane = gp_Pln(gp_Pnt(i, 0., 0), gp_Dir(1., 0., 0.)) elif direc == 'Y': plane = gp_Pln(gp_Pnt(0., i, 0), gp_Dir(0., 1., 0.)) face = BRepBuilderAPI_MakeFace(plane).Face() slices.append([]) for surface in new_surfaces: slices[counter1].extend(Slicing.plane_shape_intersection(face,\ surface)) counter1 = counter1 + 1 return slices
def slicer(event=None): # Param Zmin, Zmax, deltaZ = -100, 100, 5 # Note: the shape can also come from a shape selected from InteractiveViewer if 'display' in dir(): shape = display.GetSelectedShape() else: # Create the shape to slice shape = BRepPrimAPI_MakeSphere(60.).Shape() # Define the direction D = gp_Dir(0., 0., 1.) # the z direction # Perform slice sections = [] init_time = time.time() # for total time computation for z in range(Zmin, Zmax, deltaZ): # Create Plane defined by a point and the perpendicular direction P = gp_Pnt(0, 0, z) Pln = gp_Pln(P, D) face = BRepBuilderAPI_MakeFace(Pln).Shape() # Computes Shape/Plane intersection section_shp = BRepAlgoAPI_Section(shape, face) if section_shp.IsDone(): sections.append(section_shp) total_time = time.time() - init_time print("%.3fs necessary to perform slice." % total_time) display.EraseAll() display.DisplayShape(shape) for section_ in sections: display.DisplayShape(section_.Shape()) display.FitAll()
def getTestFace(): P1 = gp_Pnt(0., 0., 0.) P12 = gp_Pnt(0., 2., 2.) P2 = gp_Pnt(0., 10., 0.) P3 = gp_Pnt(0., 10., 10.) P4 = gp_Pnt(0., 0., 10.) P5 = gp_Pnt(5., 5., 5.) SceneDrawPoint('p1', P1) SceneDrawPoint('p12', P12) SceneDrawPoint('p2', P2) SceneDrawPoint('p3', P3) SceneDrawPoint('p4', P4) SceneDrawPoint('p5', P5) W = BRepBuilderAPI_MakePolygon() W.Add(P1) W.Add(P12) W.Add(P2) W.Add(P3) W.Add(P4) W.Add(P1) SceneDrawShape('w', W.Shape()) # Initialize a BuildPlateSurface BPSurf = GeomPlate_BuildPlateSurface(3, 15, 2) # Create the curve constraints anExp = BRepTools_WireExplorer() anExp.Init(W.Wire()) while anExp.More(): E = anExp.Current() C = BRepAdaptor_HCurve() C.ChangeCurve().Initialize(E) Cont = BRepFill_CurveConstraint(C, 0) BPSurf.Add(Cont) anExp.Next() # Point constraint PCont = GeomPlate_PointConstraint(P5, 0) BPSurf.Add(PCont) # Compute the Plate surface BPSurf.Perform() # Approximation of the Plate surface MaxSeg = 9 MaxDegree = 8 CritOrder = 0 PSurf = BPSurf.Surface() dmax = max(0.0001, 10 * BPSurf.G0Error()) Tol = 0.0001 Mapp = GeomPlate_MakeApprox(PSurf, Tol, MaxSeg, MaxDegree, dmax, CritOrder) Surf = Mapp.Surface() # create a face corresponding to the approximated Plate Surface Umin, Umax, Vmin, Vmax = PSurf.Bounds() #MF = BRepBuilderAPI_MakeFace (Surf, Umin, Umax, Vmin, Vmax, Tol) MF = BRepBuilderAPI_MakeFace(Surf, Tol) return MF
def split_edge_with_face(event=None): display.EraseAll() p0 = gp_Pnt() vnorm = gp_Dir(1, 0, 0) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face() p1 = gp_Pnt(0, 0, 15) p2 = gp_Pnt(0, 0, -15) edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() # Initialize splitter splitter = BOPAlgo_Splitter() # Add the edge as an argument and the face as a tool. This will split # the edge with the face. splitter.AddArgument(edge) splitter.AddTool(face) splitter.Perform() edges = [] exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE) while exp.More(): edges.append(exp.Current()) exp.Next() print('Number of edges in split shape: ', len(edges)) display.DisplayShape(edges[0], color='red') display.DisplayShape(edges[1], color='green') display.DisplayShape(edges[2], color='yellow') display.FitAll()
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick): """ This method demonstrates how to create a revolved shape from a drawn closed edge. It currently creates a hollow cylinder adapted from algotopia.com's opencascade_basic tutorial: http://www.algotopia.com/contents/opencascade/opencascade_basic :param pnt: :param height: :param revolve_angle: :param rotation: :param wall_thick: :type pnt: dict :type height: float :type revolve_angle: float :type rotation: float :type wall_thick: float """ from OCC.Core.BRepBuilderAPI import ( BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, ) from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000 face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000 # point to create an edge from edg_points = [ gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), ] # aggregate edges in wire hexwire = BRepBuilderAPI_MakeWire() for i in range(len(edg_points) - 1): hexedge = BRepBuilderAPI_MakeEdge(edg_points[i], edg_points[i + 1]).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() # face from wire hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(gp_Pnt(pnt["X"], pnt["Y"], pnt["Z"]), gp_Dir(0, 0, 1)) # create revolved shape revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis, np.radians( float(revolve_angle))).Shape() revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis, rotation) return revolved_shape_
def brep_feat_rib(event=None): mkw = BRepBuilderAPI_MakeWire() mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge()) S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 100., 0.))) display.EraseAll() # display.DisplayShape(S.Shape()) W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.), gp_Pnt(100., 45., 50.)).Edge()) aplane = Geom_Plane(0., 1., 0., -45.) aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane, gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.), 1, True) aform.Perform() display.DisplayShape(aform.Shape()) display.FitAll()
def revolve(): """Revolve profile on active WP to create a new part.""" wp = win.activeWp if win.lineEditStack and len(win.ptStack) == 2: p2 = win.ptStack.pop() p1 = win.ptStack.pop() name = win.lineEditStack.pop() win.clearAllStacks() wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return face = BRepBuilderAPI_MakeFace(wp.wire).Shape() revolve_axis = gp_Ax1(p1, gp_Dir(gp_Vec(p1, p2))) myBody = BRepPrimAPI_MakeRevol(face, revolve_axis).Shape() uid = doc.addComponent(myBody, name, DEFAULT_COLOR) win.build_tree() win.setActivePart(uid) win.draw_shape(uid) win.syncUncheckedToHideList() win.statusBar().showMessage("New part created.") win.clearCallback() else: win.registerCallback(revolveC) display.SetSelectionModeVertex() win.lineEdit.setFocus() statusText = "Pick two points on revolve axis." win.statusBar().showMessage(statusText)
def bez_face(px, py, pz, axs=gp_Ax3()): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) #print (i, j, px[i, j], py[i, j], pz[i, j]) surf = Geom_BezierSurface(pnt_2d) # api.Interpolate(pnt_2d) #surface = BRepBuilderAPI_MakeFace(curve, 1e-6) # return surface.Face() face = BRepBuilderAPI_MakeFace(surf, 1e-6).Face() face.Location(set_loc(gp_Ax3(), axs)) return face
def spl_face(px, py, pz, axs=gp_Ax3()): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) #print (i, j, px[i, j], py[i, j], pz[i, j]) api = GeomAPI_PointsToBSplineSurface(pnt_2d, 3, 8, GeomAbs_G2, 0.001) api.Interpolate(pnt_2d) #surface = BRepBuilderAPI_MakeFace(curve, 1e-6) # return surface.Face() face = BRepBuilderAPI_MakeFace(api.Surface(), 1e-6).Face() face.Location(set_loc(gp_Ax3(), axs)) return face