def through_sections(): #ruled circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire() circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire() circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire() circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire() generatorA = BRepOffsetAPI_ThruSections(False, True) # the use of the map function fails at producing the ThruSection # on py3k. Why ? # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4]) # we have to use a loop for wir in [wire_1, wire_2, wire_3, wire_4]: generatorA.AddWire(wir) generatorA.Build() display.DisplayShape(generatorA.Shape()) #smooth circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire() circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire() circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire() circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire() generatorB = BRepOffsetAPI_ThruSections(True, False) # same here, the following line fails # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b]) for wir in [wire_1b, wire_2b, wire_3b, wire_4b]: generatorB.AddWire(wir) generatorB.Build() display.DisplayShape(generatorB.Shape(), update=True)
def through_sections(): #ruled circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire() circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire() circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire() circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire() generatorA = BRepOffsetAPI_ThruSections(False, True) [generatorA.AddWire(w) for w in [wire_1, wire_2, wire_3, wire_4]] generatorA.Build() display.DisplayShape(generatorA.Shape()) # smooth circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire() circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire() circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire() circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire() generatorB = BRepOffsetAPI_ThruSections(True, False) [generatorB.AddWire(w) for w in [wire_1b, wire_2b, wire_3b, wire_4b]] generatorB.Build() display.DisplayShape(generatorB.Shape(), update=True)
def makeLoft(cls, listOfWire, ruled=False): """ makes a loft from a list of wires The wires will be converted into faces when possible-- it is presumed that nobody ever actually wants to make an infinitely thin shell for a real FreeCADPart. """ # the True flag requests building a solid instead of a shell. loft_builder = BRepOffsetAPI_ThruSections(True, ruled) for w in listOfWire: loft_builder.AddWire(w.wrapped) loft_builder.Build() return cls(loft_builder.Shape())
def _generate_tip(self, maxDeg): """ Private method to generate the surface that closing the blade tip. :param int maxDeg: Define the maximal U degree of generated surface """ self._import_occ_libs() generator = BRepOffsetAPI_ThruSections(False, False, 1e-10) generator.SetMaxDegree(maxDeg) # npoints_up == npoints_down npoints = len(self.blade_coordinates_down[-1][0]) vertices_1 = TColgp_HArray1OfPnt(1, npoints) vertices_2 = TColgp_HArray1OfPnt(1, npoints) for j in range(npoints): vertices_1.SetValue( j + 1, gp_Pnt(1000 * self.blade_coordinates_down[-1][0][j], 1000 * self.blade_coordinates_down[-1][1][j], 1000 * self.blade_coordinates_down[-1][2][j])) vertices_2.SetValue( j + 1, gp_Pnt(1000 * self.blade_coordinates_up[-1][0][j], 1000 * self.blade_coordinates_up[-1][1][j], 1000 * self.blade_coordinates_up[-1][2][j])) # Initializes an algorithm for constructing a constrained # BSpline curve passing through the points of the blade last # section, with tolerance = 1e-9 bspline_1 = GeomAPI_Interpolate(vertices_1.GetHandle(), False, 1e-9) bspline_1.Perform() bspline_2 = GeomAPI_Interpolate(vertices_2.GetHandle(), False, 1e-9) bspline_2.Perform() edge_1 = BRepBuilderAPI_MakeEdge(bspline_1.Curve()).Edge() edge_2 = BRepBuilderAPI_MakeEdge(bspline_2.Curve()).Edge() # Add BSpline wire to the generator constructor generator.AddWire(BRepBuilderAPI_MakeWire(edge_1).Wire()) generator.AddWire(BRepBuilderAPI_MakeWire(edge_2).Wire()) # Returns the shape built by the shape construction algorithm generator.Build() # Returns the Face generated by each edge of the first section self.generated_tip = generator.GeneratedFace(edge_1)
def update_shape(self, change): from .occ_draw import OccVertex, OccWire d = self.declaration shape = BRepOffsetAPI_ThruSections(d.solid, d.ruled, d.precision) #: TODO: Support Smoothing, Max degree, par type, etc... for child in self.children(): if isinstance(child, OccVertex): shape.AddVertex(child.shape.Vertex()) elif isinstance(child, OccWire): shape.AddWire(child.shape.Wire()) #: TODO: Handle transform??? #: Set the shape self.shape = shape
def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2, check_compatibility=True): 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 _generate_lower_face(self, maxDeg): """ Private method to generate the blade lower face. :param int maxDeg: Define the maximal U degree of generated surface """ self._import_occ_libs() # Initializes ThruSections algorithm for building a shell passing # through a set of sections (wires). The generated faces between # the edges of every two consecutive wires are smoothed out with # a precision criterion = 1e-10 generator = BRepOffsetAPI_ThruSections(False, False, 1e-10) generator.SetMaxDegree(maxDeg) # Define upper edges (wires) for the face generation for i in range(self.n_sections): npoints = len(self.blade_coordinates_down[i][0]) vertices = TColgp_HArray1OfPnt(1, npoints) for j in range(npoints): vertices.SetValue( j + 1, gp_Pnt(1000 * self.blade_coordinates_down[i][0][j], 1000 * self.blade_coordinates_down[i][1][j], 1000 * self.blade_coordinates_down[i][2][j])) # Initializes an algorithm for constructing a constrained # BSpline curve passing through the points of the blade i-th # section, with tolerance = 1e-9 bspline = GeomAPI_Interpolate(vertices.GetHandle(), False, 1e-9) bspline.Perform() edge = BRepBuilderAPI_MakeEdge(bspline.Curve()).Edge() if i == 0: bound_root_edge = edge # Add BSpline wire to the generator constructor generator.AddWire(BRepBuilderAPI_MakeWire(edge).Wire()) # Returns the shape built by the shape construction algorithm generator.Build() # Returns the Face generated by each edge of the first section self.generated_lower_face = generator.GeneratedFace(bound_root_edge)
anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(Handle_Geom2d_Curve(anArc2), Handle_Geom_Surface(aCyl2)) anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), Handle_Geom_Surface(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) display, start_display, add_menu, add_function_to_menu = init_display('wx') display.DisplayColoredShape(aRes)
def AddSurfaceLoft(objs, continuity=GeomAbs_C2, check_compatibility=True, solid=True, first_vertex=None, last_vertex=None, max_degree=8, close_sections=True): """Create a lift surface through curve objects Parameters ---------- objs : list of python classes Each obj is expected to have an obj.Curve attribute : see airconics.primitives.airfoil class continuity : OCC.GeomAbs.GeomAbs_XX type (default C2) The order of continuity (C^0, C^1, C^2, G^0, ....) check_compatibility : bool (default=True) Adds a surface compatibility check to the builder solid : bool (default=True) Creates a solid object from the loft if True first_vertex : TopoDS_Vertex (optional, default=None) The starting vertex of the surface to add to the 'ThruSections' algorithm last_vertex : TopoDS_Vertex (optional, default=None) The end vertex of the surface to add to the 'ThruSections' algorithm max_degree : int (default=8) The order of the fitted NURBS surface close_sections : bool (default=True): Connects the start and end point of the loft rib curves if true. This has the same effect as adding an airfoil trailing edge. Returns ------- shape : TopoDS_Shape The generated loft surface Notes ----- Uses OCC.BRepOffsetAPI.BRepOffsetAPI_ThruSections. This function is ORDER DEPENDANT, i.e. add elements in the order through which they should be lofted """ assert (len(objs) >= 2), 'Loft Failed: Less than two input curves' # Note: This is to give a smooth loft. ruled = False pres3d = 1e-6 args = [solid, ruled, pres3d] # args (in order) for ThruSections generator = BRepOffsetAPI_ThruSections(*args) generator.SetMaxDegree(max_degree) # from OCC.GeomAbs import GeomAbs_G1 generator.SetParType(Approx_ChordLength) if first_vertex: generator.AddVertex(first_vertex) for obj in objs: try: # Check if this is an airconics object with a GeomBspline handle # as its 'Curve' attribute obj = obj.Curve # edge = [make_edge(obj)] except: # Assume the object is already a geombspline handle pass # try: # # If working with an airconics object, the OCC curve is stored # # in obj.Curve: edges = [make_edge(obj)] if close_sections: crv = obj.GetObject() if crv.IsClosed() is False: # Add Finite TE edge TE = make_edge(crv.Value(1), crv.Value(0)) edges.append(TE) generator.AddWire(BRepBuilderAPI_MakeWire(*edges).Wire()) # else: # generator if last_vertex: generator.AddVertex(last_vertex) generator.CheckCompatibility(check_compatibility) generator.SetContinuity(continuity) generator.Build() with assert_isdone(generator, 'failed lofting'): return generator.Shape()
w0 = 10.0 rz = pz + 1/pz*(np.pi*w0/wave)**2 wz = w0 * np.sqrt (1 + (wave*pz/(np.pi*w0**2))**2) t0 = wave / (np.pi * w0) plt.figure() plt.plot (pz, rz) plt.figure() plt.plot (pz, wz) plt.plot (pz, np.tan(t0)*pz) plt.show () display, start_display, add_menu, add_function_to_menu = init_display() api = BRepOffsetAPI_ThruSections() for z in np.linspace(0, 1000, 10): r_z = z + 1/z*(np.pi*w0/wave)**2 w_z = w0 * np.sqrt (1 + (wave*z/(np.pi*w0**2))**2) print (z, r_z, w_z) pnt = gp_Pnt (0, 0, z) axs = gp_Ax3 (pnt, gp_Dir(0, 0, 1)) ax2 = axs.Ax2() px = np.linspace(-1, 1, 100) * 100 py = np.linspace(-1, 1, 100) * 100 pxy = np.meshgrid (px, py) pz = -1*(pxy[0]**2/(2*r_z) + pxy[1]**2/(2*r_z)) pln = surf_spl(*pxy, pz, axs) wxy = Geom_Ellipse (ax2, w_z, w_z).Elips() wxy = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge (wxy).Edge()).Wire() print (wxy, pln)