def _update(self): """ """ # TODO: perhaps should take an argument until which topological level # topological entities bound to the vertex should be updated too... reshape = ShapeBuild_ReShape() reshape.Replace(self._vertex, make_vertex(self._pnt))
def build_surface(self): ''' builds and renders the plate ''' self.plate = build_plate([self.poly], [self.pnt]) self.display.EraseAll() self.display.DisplayShape(self.plate) vert = make_vertex(self.pnt) self.display.DisplayShape(vert, update=True)
def __init__(self, x, y, z): super(Vertex, self).__init__() """Constructor for KbeVertex""" BaseObject.__init__(self, name='Vertex #{0}'.format(self._n)) self._n += 1 # should be a property of KbeObject self._pnt = gp_Pnt(x, y, z) self._vertex = make_vertex(self._pnt) TopoDS_Vertex.__init__(self, self._vertex)
def geom_plate(event=None): display.EraseAll() p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(0, 10, 0) p3 = gp_Pnt(0, 10, 10) p4 = gp_Pnt(0, 0, 10) p5 = gp_Pnt(5, 5, 5) poly = make_closed_polygon([p1, p2, p3, p4]) edges = [i for i in Topo(poly).edges()] face = make_n_sided(edges, [p5]) display.DisplayShape(edges) display.DisplayShape(make_vertex(p5)) display.DisplayShape(face, update=True)
STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity. STEPControl_GeometricCurveSet translates an Open CASCADE shape into a STEP geometric_curve_set entity. """ label = self.shape_tool.AddShape(shape) self.step.Transfer(self.h_doc, STEPControl_AsIs) def Write(self, filename=None): if not filename: filename = self.name path, ext = os.path.splitext(filename) if not ext: ext = ".stp" status = self.step.Write(path + ext) assert (status == IFSelect_RetDone) if __name__ == "__main__": display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape(gp_Pnt()) root = ExportCAFMethod(name="root") root.Add(make_vertex(gp_Pnt()), name="pnt") root.Add(make_plane(center=gp_Pnt(0, 0, 0)), name="pln0") root.Add(make_plane(center=gp_Pnt(0, 0, 100)), name="pln1") root.Add(make_plane(center=gp_Pnt(0, 0, 200)), name="pln2") root.Add(make_circle(gp_Pnt(0, 0, 0), 100), name="circle") root.Add(make_box(100, 100, 100), name="box001") root.Write() display.FitAll() # start_display()
def build(self): if self.name.startswith('Vertex'): self = make_vertex(self)
def __init__(self): plotocc.__init__(self) self.compound = TopoDS_Compound() self.builder = BRep_Builder() self.builder.MakeCompound(self.compound) self.beam = gp_Ax3() self.beam.SetLocation(gp_Pnt(0.5, 0.5, 0.0)) self.beam.SetDirection(gp_Dir(0.0, 0.5, 1.0)) self.beam_line = line_from_axs(self.beam, length=20) self.builder.Add(self.compound, self.beam_line) ax = gp_Ax3(gp_Pnt(0, 0, 10), gp_Dir(0, 0, -1)) px = np.linspace(-1, 1, 10) * 10 py = np.linspace(-1, 1, 10) * 10 mesh = np.meshgrid(px, py) surf = mesh[0]**2 / 100 + mesh[1]**2 / 150 self.surf = spl_face(*mesh, surf, ax) self.surf_bound = self.make_PolySurf(radi=5, axs=ax) self.beam_glin = Geom_Line(self.beam.Location(), self.beam.Direction()) self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf)) print(self.ics.NbPoints()) # print(self.ics.Point(1)) self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf_bound)) print(self.ics.NbPoints()) #self.display.DisplayShape(self.surf, transparency=0.7) self.display.DisplayShape(self.surf_bound, transparency=0.7) self.plns = TopoDS_Shell() self.builder.MakeShell(self.plns) for ix in np.linspace(0, 1, 5): for iy in np.linspace(0, 1, 5): p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(self.surf), ix, iy, p1, vx, vy) vz = vx.Crossed(vy) axs = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) pln = self.make_PolyPlane(axs=axs, radi=2.5, shft=15.0) print(pln) self.builder.Add(self.compound, make_vertex(p1)) self.builder.Add(self.plns, pln) self.builder.Add(self.compound, self.plns) for face in Topo(self.plns).faces(): self.ics.Perform(self.beam_glin, BRep_Tool.Surface(face)) uvw = self.ics.Parameters(1) u, v, w = uvw p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(face), u, v, p1, vx, vy) vz = vx.Crossed(vy) if u > 0 and v > 0: print(u, v) print(p1) print(self.ics.Point(1)) self.display.DisplayShape(p1) self.display.DisplayShape(face, color="BLUE") else: print(u, v)
# initialize the STEP exporter step_writer = STEPControl_Writer() Interface_Static_SetCVal("write.step.schema", "AP214") # Use default? # transfer shapes for shape in shapes: step_writer.Transfer(shape, STEPControl_AsIs) status = step_writer.Write(filename) assert (status == IFSelect_RetDone) return status if __name__ == "__main__": from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() p0 = make_vertex(gp_Pnt(0, 0, 0)) p1 = make_vertex(gp_Pnt(0, 0, 1)) p2 = make_vertex(gp_Pnt(0, 1, 1)) shape = Part() shape["line_1"] = make_line(p0, p1) shape["line_2"] = make_line(p1, p2) shape["line_3"] = make_line(p2, p0) shape.Display(display) shape.Write("lines.stp", True) display.FitAll() start_display()