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 split_compound(compound): all_faces = get_faces(compound) planar_faces = list(filter(lambda x: Face(x).is_planar(), all_faces)) p1, v1 = gp_Pnt(50, 50, 25), gp_Vec(0, 0, -1) fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000, 1000) # limited, not infinite plane bo = BOPAlgo_Builder() bo.AddArgument(copy.deepcopy(compound)) # bo.AddArgument(fc1) # display.DisplayShape(fc1, transparency=0.7) for f in planar_faces: gprop = BRepGProp_Face(f) normal_point = gp_Pnt(0, 0, 0) normal_vec = gp_Vec(0, 0, 0) gprop.Normal(0, 0, normal_point, normal_vec) big_face = make_face(gp_Pln(normal_point, vec_to_dir(normal_vec)), -1000, 1000, -1000, 1000) # limited, not infinite plane bo.AddArgument(big_face) # display.DisplayShape(big_face, transparency=0.7) bo.Perform() # print("error status: {}".format(bo.ErrorStatus())) top = Topo(bo.Shape()) result = [s for s in top.solids()] return result
def __init__(self, size, face=None, faceU=None, ax3=None): # gp_Ax3 of XYZ coord system origin = gp_Pnt(0, 0, 0) wDir = gp_Dir(0, 0, 1) uDir = gp_Dir(1, 0, 0) vDir = gp_Dir(0, 1, 0) xyzAx3 = gp_Ax3(origin, wDir, uDir) if (not face and not ax3): # create default wp (in XY plane at 0,0,0) axis3 = xyzAx3 gpPlane = gp_Pln(xyzAx3) self.gpPlane = gpPlane # type: gp_Pln self.plane = Geom_Plane(gpPlane) # type: Geom_Plane elif face: # create workplane on face, uDir defined by faceU wDir = face_normal(face) # from OCCUtils.Construct module props = GProp_GProps() brepgprop_SurfaceProperties(face, props) origin = props.CentreOfMass() ''' surface = BRep_Tool_Surface(face) # type: Handle_Geom_Surface plane = Handle_Geom_Plane.DownCast(surface).GetObject() # type: Geom_Plane gpPlane = plane.Pln() # type: gp_Pln origin = gpPlane.Location() # type: gp_Pnt ''' uDir = face_normal(faceU) # from OCCUtils.Construct module axis3 = gp_Ax3(origin, wDir, uDir) vDir = axis3.YDirection() self.gpPlane = gp_Pln(axis3) self.plane = Geom_Plane(self.gpPlane) # type: Geom_Plane elif ax3: axis3 = ax3 uDir = axis3.XDirection() vDir = axis3.YDirection() wDir = axis3.Axis().Direction() origin = axis3.Location() self.gpPlane = gp_Pln(axis3) self.plane = Geom_Plane(self.gpPlane) # type: Geom_Plane self.Trsf = gp_Trsf() self.Trsf.SetTransformation(axis3) self.Trsf.Invert() self.origin = origin self.uDir = uDir self.vDir = vDir self.wDir = wDir self.face = face self.size = size self.border = self.makeWpBorder(self.size) self.clList = [] # List of 'native' construction lines self.clineList = [] # List of pyOCC construction lines self.ccircList = [] # List of pyOCC construction circles self.wireList = [] # List of pyOCC wires self.wire = None self.hvcl((0, 0)) # Make H-V clines through origin self.accuracy = 0.001 # min distance between two points
def __init__(self, size, face=None, faceU=None, ax3=None): # gp_Ax3 of XYZ coord system origin = gp_Pnt(0, 0, 0) wDir = gp_Dir(0, 0, 1) uDir = gp_Dir(1, 0, 0) vDir = gp_Dir(0, 1, 0) xyzAx3 = gp_Ax3(origin, wDir, uDir) if (not face and not ax3): # create default wp (in XY plane at 0,0,0) axis3 = xyzAx3 gpPlane = gp_Pln(xyzAx3) self.gpPlane = gpPlane # type: gp_Pln self.plane = Geom_Plane(gpPlane) # type: Geom_Plane elif face: # create workplane on face, uDir defined by faceU wDir = face_normal(face) # from OCCUtils.Construct module props = GProp_GProps() brepgprop_SurfaceProperties(face, props) origin = props.CentreOfMass() uDir = face_normal(faceU) # from OCCUtils.Construct module axis3 = gp_Ax3(origin, wDir, uDir) vDir = axis3.YDirection() self.gpPlane = gp_Pln(axis3) self.plane = Geom_Plane(self.gpPlane) # type: Geom_Plane elif ax3: axis3 = ax3 uDir = axis3.XDirection() vDir = axis3.YDirection() wDir = axis3.Axis().Direction() origin = axis3.Location() self.gpPlane = gp_Pln(axis3) self.plane = Geom_Plane(self.gpPlane) # type: Geom_Plane self.Trsf = gp_Trsf() self.Trsf.SetTransformation(axis3) self.Trsf.Invert() self.origin = origin self.uDir = uDir self.vDir = vDir self.wDir = wDir self.wVec = gp_Vec(wDir) self.face = face self.size = size self.border = self.makeWpBorder(self.size) self.clines = set() # set of c-lines with (a, b, c) coefficients self.ccircs = set() # set of c-circs with (pc, r) coefficients self.edgeList = [] # List of profile lines type: <TopoDS_Edge> self.wire = None self.accuracy = 1e-6 # min distance between two points self.hvcl((0, 0)) # Make H-V clines through origin
def test_points_from_intersection(self): '''Test: points from intersection''' PL = gp_Pln(gp_Ax3(gp_XOY())) MinorRadius, MajorRadius = 5, 8 EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius) ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(), precision_Confusion()) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt) aPlane = GC_MakePlane(PL).Value() aSurface = Geom_RectangularTrimmedSurface(aPlane, -8., 8., -12., 12., True, True) self.assertIsNotNone(aSurface) self.assertFalse(aSurface.IsNull()) anEllips = GC_MakeEllipse(EL).Value() self.assertIsInstance(anEllips, Geom_Ellipse) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt)
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 points_from_intersection(): ''' @param display: ''' plane = gp_Pln(gp_Ax3(gp_XOY())) minor_radius, major_radius = 5., 8. ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius) intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(), precision_Confusion()) a_plane = GC_MakePlane(plane).Value() a_surface = Geom_RectangularTrimmedSurface(a_plane, -8., 8., -12., 12., True, True) display.DisplayShape(a_surface, update=True) anEllips = GC_MakeEllipse(ellips).Value() display.DisplayShape(anEllips) if intersection.IsDone(): nb_results = intersection.NbPoints() if nb_results > 0: for i in range(1, nb_results + 1): P = intersection.Point(i) pstring = "P%i" % i display.DisplayShape(P) display.DisplayMessage(P, pstring)
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 MakePentagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 upX = tubeRadius * math.cos( 18 * math.pi / 180. ) upY = tubeRadius * math.sin( 18 * math.pi / 180. ) downX = tubeRadius * math.sin( 36 * math.pi / 180. ) downY = tubeRadius * math.cos( 36 * math.pi / 180. ) p1 = gp_Pnt( 0., tubeRadius, 0. ) p2 = gp_Pnt( upX, upY, 0. ) p3 = gp_Pnt( downX, -downY, 0. ) p4 = gp_Pnt( -downX, -downY, 0. ) p5 = gp_Pnt( -upX, upY, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p5 ) ed5 = make_edge( p5, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed5, pln, Radius ) cur5 = self.__MakeFillet( ed5, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5] wire = make_wire( edgeList ) return make_face( wire )
def MakeSquareFace(self, Width: float, High: float, Radius: float) -> TopoDS_Face: xDis = Width / 2.0 yDis = High / 2.0 p1 = gp_Pnt( xDis, yDis, 0. ) p2 = gp_Pnt( xDis, -yDis, 0. ) p3 = gp_Pnt( -xDis, -yDis, 0. ) p4 = gp_Pnt( -xDis, yDis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4] wire = make_wire( edgeList ) return make_face( wire )
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 MakeTriangleFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 degree = 30 * math.pi / 180. sindis = tubeRadius * math.sin( degree ) cosdis = tubeRadius * math.cos( degree ) p1 = gp_Pnt( 0., tubeRadius, 0. ) p2 = gp_Pnt( -cosdis, -sindis, 0. ) p3 = gp_Pnt( cosdis, -sindis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3] wire = make_wire( edgeList ) return make_face( wire )
def MakeHexagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 degree = 60 * math.pi / 180. sindis = tubeRadius * math.sin( degree ) cosdis = tubeRadius * math.cos( degree ) p1 = gp_Pnt( cosdis, sindis, 0. ) p2 = gp_Pnt( tubeRadius, 0., 0. ) p3 = gp_Pnt( cosdis, -sindis, 0. ) p4 = gp_Pnt( -cosdis, -sindis, 0. ) p5 = gp_Pnt( -tubeRadius, 0., 0. ) p6 = gp_Pnt( -cosdis, sindis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p5 ) ed5 = make_edge( p5, p6 ) ed6 = make_edge( p6, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed5, pln, Radius ) cur5 = self.__MakeFillet( ed5, ed6, pln, Radius ) cur6 = self.__MakeFillet( ed6, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5, ed6, cur6] wire = make_wire( edgeList ) return make_face( wire )
def split_run(self, num=5): for i in range(num): pnt = gp_Pnt(*np.random.rand(3) * 100) vec = gp_Vec(*np.random.randn(3)) pln = gp_Pln(pnt, vec_to_dir(vec)) fce = make_face(pln, -10000, 10000, -10000, 10000) self.splitter.AddTool(fce) self.splitter.Perform()
def to_edge(self, l1, l2): if (self.edge == None): f = ChFi2d_AnaFilletAlgo() f.Init(l1.to_edge(), l2.to_edge(), gp_Pln()) f.Perform(self.radius) self.edge = f.Result(l1.to_edge(), l2.to_edge()) self.l1 = l1 self.l2 = l2 return self.edge
def holes_in_face(): aPlane = gp_Pln() print(type(gp_Pln())) print(type(gp_XOY())) aCircle1 = gp_Circ(gp_XOY(), 1.0) aCircle2 = gp_Circ(gp_XOY(), 1.0) aCircle3 = gp_Circ(gp_XOY(), 1.0) aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0)) aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0)) aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0)) anEdgeMaker1 = BRepBuilderAPI_MakeEdge(aCircle1) anEdgeMaker2 = BRepBuilderAPI_MakeEdge(aCircle2) anEdgeMaker3 = BRepBuilderAPI_MakeEdge(aCircle3) aWireMaker1 = BRepBuilderAPI_MakeWire(anEdgeMaker1.Edge()) aWireMaker2 = BRepBuilderAPI_MakeWire(anEdgeMaker2.Edge()) aWireMaker3 = BRepBuilderAPI_MakeWire(anEdgeMaker3.Edge()) aFaceMaker = BRepBuilderAPI_MakeFace(aPlane, 0.0, 10.0, 0.0, 10.0) if aWireMaker1.IsDone(): aWire1 = aWireMaker1.Wire() aWire1.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire1) if aWireMaker2.IsDone(): aWire2 = aWireMaker2.Wire() aWire2.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire2) if aWireMaker3.IsDone(): aWire3 = aWireMaker3.Wire() aWire3.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire3) if not aFaceMaker.IsDone(): raise AssertionError("shape not Done.") return aFaceMaker.Shape()
def generate_planar_slices(nozz_dia, sur_nozz_dia): xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(part_shape) print(xmax - xmin, ",", ymax - ymin, ",", zmax - zmin) wires = [] slices = [] contours = [] for z in numpy.arange(zmin+(nozz_dia/2)+(sur_nozz_dia/2), \ zmax-(nozz_dia/2)-(sur_nozz_dia/2), nozz_dia): plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) slices.append(Slicing.plane_shape_intersection(plane, part_shape)) for s in range(0, len(slices)): wire = [] wires.append([]) while len(slices[s]) != 0: for i in range(0, len(slices[s])): if len(wire) == 0: wire.append(slices[s][i]) slices[s].remove(slices[s][i]) break elif Slicing.do_edges_connect(slices[s][i], wire[-1]): wire.append(slices[s][i]) slices[s].remove(slices[s][i]) break if Slicing.do_edges_connect(wire[0], wire[-1]): if len(wire) > 2: wires[s].append(wire) wire = [] elif len(wire) == 2 and Slicing.do_edges_loop( wire[0], wire[-1]): wires[s].append(wire) wire = [] for k in range(0, len(wires)): contours.append([]) for l in range(0, len(wires[k])): make_wire = BRepBuilderAPI_MakeWire() for edge in wires[k][l]: make_wire.Add(edge) try: made_wire = make_wire.Wire() contours[k].append(made_wire) except: print("Skipped a contour!") continue contour_faces = [] for contour in contours: if len(contour) == 1: contour_faces.append( BRepBuilderAPI_MakeFace(contour[0]).Face()) else: contour_faces.extend(Slicing.get_layer_faces(contour)) # for l in range(0,len(contour_faces)): # display.DisplayShape(contour_faces[l], color=colour[l%5],\ # transparency=0.95, update=True) return contour_faces
def __init__(self, parent=None, display=None): super(Sketch_NewSketchEditor, self).__init__(parent) self.ui = newSketchProperty.Ui_newSketchEditor() self.ui.setupUi(self) self.ui.uiXYPlane.setChecked(True) self._display = display self.ui.uiOk.accepted.connect(self.constructGrid) self.ui.uiOk.rejected.connect(self.close) self.setWindowModality(Qt.ApplicationModal) self._plane = gp_Pln(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)) self.show()
def faircurve(self, event=None): pl = Geom_Plane(gp_Pln()) for i in range(0, 40): # TODO: the parameter slope needs to be visualized slope = i / 100. bc = self.batten_curve(slope, math.radians(i), math.radians(-i)) self.display.EraseAll() edge = BRepBuilderAPI_MakeEdge(bc, pl).Edge() self.display.DisplayShape(edge, update=True) time.sleep(0.21)
def _set_shape(self): self._shape = BRepPrimAPI_MakeBox(self._length, self._section[0], self._section[1]).Shape() if self._saw_start is not None: if -90+1e-6 < self._saw_start < 90-1e-6: ra = radians(self._saw_start) sina = sin(ra) cosa = cos(ra) if ra > 0: pnt = gp_Pnt(0, 0, 0) pln = gp_Pln(pnt, gp_Dir(-sina, 0, cosa)) pnt_out = gp_Pnt(0, 0, self._section[1]) else: pnt = gp_Pnt(0, 0, self._section[1]) pln = gp_Pln(pnt, gp_Dir(sina, 0, -cosa)) pnt_out = gp_Pnt(0, 0, 0) face = BRepBuilderAPI_MakeFace(pln).Shape() tool = BRepPrimAPI_MakeHalfSpace(face, pnt_out).Solid() self._shape = BRepAlgoAPI_Cut(self._shape, tool).Shape() if self._saw_end is not None: if -90 + 1e-6 < self._saw_end < 90-1e-6: ra = radians(self._saw_end) sina = sin(ra) cosa = cos(ra) if ra > 0: pnt = gp_Pnt(self._length, 0, 0) pln = gp_Pln(pnt, gp_Dir(sina, 0, cosa)) pnt_out = gp_Pnt(self._length, 0, self._section[1]) else: pnt = gp_Pnt(self._length, 0, self._section[1]) pln = gp_Pln(pnt, gp_Dir(-sina, 0, -cosa)) pnt_out = gp_Pnt(self._length, 0, 0) face = BRepBuilderAPI_MakeFace(pln).Shape() tool = BRepPrimAPI_MakeHalfSpace(face, pnt_out).Solid() self._shape = BRepAlgoAPI_Cut(self._shape, tool).Shape()
def make_plane(center=gp_Pnt(0, 0, 0), vec_normal=gp_Vec(0, 0, 1), extent_x_min=-100., extent_x_max=100., extent_y_min=-100., extent_y_max=100., depth=0.): if depth != 0: center = center.add_vec(gp_Vec(0, 0, depth)) PL = gp_Pln(center, vec_normal.as_dir()) face = make_face(PL, extent_x_min, extent_x_max, extent_y_min, extent_y_max) return face
def GetSectionShape(z, shapes): # the mid z value of the storey, list of the storey shapes if isinstance(shapes, list): shapes_compound, if_all_compound = list_of_shapes_to_compound(shapes) plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shapes_compound, face) section.Build() if section.IsDone(): print("Successfully get the section shape") return section.Shape() else: print("ERROR, the section shape cannot be built") else: plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shapes, face) section.Build() if section.IsDone(): print("Successfully get the section shape") return section.Shape()
def vectorized_slicer(li): # Create Plane defined by a point and the perpendicular direction z_values, shape = li _slices = [] for z in z_values: #print 'slicing index:', z, 'sliced by process:', os.getpid() plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shape, face) section.Build() if section.IsDone(): _slices.append(section.Shape()) return _slices
def faircurve(event=None): pt1 = gp_Pnt2d(0., 0.) pt2 = gp_Pnt2d(0., 120.) height = 100. pl = Geom_Plane(gp_Pln()) for i in range(0, 40): # TODO: the parameter slope needs to be visualized slope = i/100. bc = batten_curve(pt1, pt2, height, slope, math.radians(i), math.radians(-i)) display.EraseAll() edge = BRepBuilderAPI_MakeEdge(bc, pl).Edge() display.DisplayShape(edge, update=True) time.sleep(0.21)
def convertClickToPoint(self, x, y): view: V3d_View = self._display.View xEye, yEye, zEye = view.Eye() xAt, yAt, zAt = view.At() eyePoint = gp_Pnt(xEye, yEye, zEye) atPoint = gp_Pnt(xAt, yAt, zAt) eyeVec = gp_Vec(eyePoint, atPoint) eyeDir = gp_Dir(eyeVec) planeOfView = gp_Pln(atPoint, eyeDir) X, Y, Z = view.Convert(x, y) convertedPoint = gp_Pnt(X, Y, Z) ConvertedPointOnPlane = projlib.Project(planeOfView, convertedPoint) resultPoint = elslib.Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), planeOfView) print(resultPoint.X(),resultPoint.Y(),resultPoint.Z()) return resultPoint
def constructGrid(self): self.dir = gp_Dir() if self.ui.uiXYPlane.isChecked(): self.dir = gp_Dir(0.0, 0.0, 1.0) self._display.View_Top() if self.ui.uiXZPlane.isChecked(): self.dir = gp_Dir(0.0, 1.0, 0.0) self._display.View_Front() if self.ui.uiYZPlane.isChecked(): self.dir = gp_Dir(1.0, 0.0, 0.0) self._display.View_Right() self._plane = gp_Pln(gp_Pnt(0.0, 0.0, 0.0), self.dir) ax3 = gp_Ax3(self._plane.Location(), self._plane.Axis().Direction()) self._display.Viewer.SetPrivilegedPlane(ax3) self.close()
def draft_angle(event=None): S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape() adraft = BRepOffsetAPI_DraftAngle(S) topExp = TopExp_Explorer() topExp.Init(S, TopAbs_FACE) while topExp.More(): face = topods_Face(topExp.Current()) surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject() dirf = surf.Pln().Axis().Direction() ddd = gp_Dir(0, 0, 1) if dirf.IsNormal(ddd, precision_Angular()): adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY()))) topExp.Next() adraft.Build() display.DisplayShape(adraft.Shape(), update=True)
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 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 split_face_with_edge(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 face as an argument and the edge as a tool. This will split # the face with the edge. splitter.AddArgument(face) splitter.AddTool(edge) splitter.Perform() display.DisplayShape(splitter.Shape()) display.FitAll()
def test_points_from_intersection(self): '''Test: points from intersection''' PL = gp_Pln(gp_Ax3(gp_XOY())) MinorRadius, MajorRadius = 5, 8 EL = gp_Elips(gp_YOZ(), MajorRadius, MinorRadius) ICQ = IntAna_IntConicQuad(EL, PL, precision_Angular(), precision_Confusion()) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt) aPlane = GC_MakePlane(PL).Value() aSurface = Geom_RectangularTrimmedSurface(aPlane, - 8., 8., - 12., 12., True, True) self.assertIsNotNone(aSurface) self.assertFalse(aSurface.IsNull()) anEllips = GC_MakeEllipse(EL).Value() self.assertIsInstance(anEllips, Geom_Ellipse) if ICQ.IsDone(): NbResults = ICQ.NbPoints() if NbResults > 0: for i in range(1, NbResults + 1): P = ICQ.Point(i) self.assertIsInstance(P, gp_Pnt)