def axs_line(axs): p0, dx, dy = axs.Location(), axs.XDirection(), axs.YDirection() px = gp_Pnt((gp_Vec(p0.XYZ()) + dir_to_vec(dx) * 50).XYZ()) py = gp_Pnt((gp_Vec(p0.XYZ()) + dir_to_vec(dy) * 100).XYZ()) lx = make_line(p0, px) ly = make_line(p0, py) return lx, ly
def axs_pln(axs): pnt = axs.Location() vx = dir_to_vec(axs.XDirection()).Scaled(10) vy = dir_to_vec(axs.YDirection()).Scaled(20) vz = dir_to_vec(axs.Direction()).Scaled(30) lx = make_line(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vx).XYZ())) ly = make_line(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vy).XYZ())) lz = make_line(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vz).XYZ())) return lx, ly, lz
def show_axs_pln(self, axs=gp_Ax3(), scale=100): pnt = axs.Location() dx = axs.XDirection() dy = axs.YDirection() dz = axs.Direction() vx = dir_to_vec(dx).Scaled(1 * scale) vy = dir_to_vec(dy).Scaled(2 * scale) vz = dir_to_vec(dz).Scaled(3 * scale) pnt_x = pnt_trf_vec(pnt, vx) pnt_y = pnt_trf_vec(pnt, vy) pnt_z = pnt_trf_vec(pnt, vz) self.display.DisplayShape(pnt) self.display.DisplayShape(make_line(pnt, pnt_x), color="RED") self.display.DisplayShape(make_line(pnt, pnt_y), color="GREEN") self.display.DisplayShape(make_line(pnt, pnt_z), color="BLUE")
def display_obj(self, name, size=100): self.display_shapes(self.obj[name], "pts") self.display.DisplayMessage(self.obj[name]["pnt"], name) self.display.DisplayVector(self.obj[name]["xyz"][0].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayVector(self.obj[name]["xyz"][1].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayVector(self.obj[name]["xyz"][2].Scaled(size), self.obj[name]["pnt"]) self.display.DisplayShape(self.obj[name]["frm"]) self.display.DisplayShape(self.obj[name]["pln"]) p = self.obj[name]["pnt"] v0 = gp_Vec(p.XYZ()) + self.obj[name]["xyz"][0].Scaled(50) v1 = gp_Vec(p.XYZ()) + self.obj[name]["xyz"][1].Scaled(100) self.display.DisplayShape(make_line(p, gp_Pnt(v0.XYZ()))) self.display.DisplayShape(make_line(p, gp_Pnt(v1.XYZ())))
def Display_Shape(self, colors=["BLUE", "YELLOW"]): self.display.DisplayShape(axs_pln(gp_Ax3())) self.display.DisplayShape(axs_pln(self.srf.axs), color=colors[0]) self.display.DisplayShape(axs_pln(self.ini.axs), color=colors[0]) self.display.DisplayShape(axs_pln(self.tar.axs), color=colors[1]) self.display.DisplayShape(self.ini.srf, color=colors[0]) self.display.DisplayShape(self.srf.srf, color=colors[0]) self.display.DisplayShape(self.tar.srf) self.display.DisplayShape(self.ini.beam.Location(), color=colors[0]) self.display.DisplayShape(self.srf.beam.Location(), color=colors[0]) self.display.DisplayShape(self.tar.beam.Location(), color=colors[1]) self.display.DisplayShape(make_line(self.ini.beam.Location(), self.srf.beam.Location()), color=colors[0]) self.display.DisplayShape(make_line(self.srf.beam.Location(), self.tar.beam.Location()), color=colors[0]) self.display.FitAll()
def Display_Shape(self, colors=["BLUE", "YELLOW"]): dispocc.show_axs_pln(self, gp_Ax3(), scale=50) dispocc.show_axs_pln(self, self.ini.axs, scale=50) dispocc.show_axs_pln(self, self.tar.axs, scale=50) self.display.DisplayShape(self.ini.srf, color=colors[0]) self.display.DisplayShape(self.tar.srf, color=colors[1]) self.display.DisplayShape( make_line(self.ini.beam.Location(), self.tar.beam.Location())) self.display.DisplayShape(self.ini.beam.Location(), color=colors[0]) self.display.DisplayShape(self.tar.beam.Location(), color=colors[1]) self.display.FitAll()
def Display_Update(self): self.display.EraseAll() self.display.DisplayShape(axs_pln(gp_Ax3())) self.display.DisplayShape(axs_pln(self.ini.axs)) self.display.DisplayShape(axs_pln(self.tar.axs)) self.display.DisplayShape(self.ini.srf) self.display.DisplayShape(self.tar.srf) self.display.DisplayShape(self.ini.sxy, color="BLUE") self.display.DisplayShape(self.tar.sxy, color="YELLOW") self.display.DisplayShape(make_line(self.ini.sxy, self.tar.sxy)) self.display.FitAll() self.start_display()
if __name__ == "__main__": argvs = sys.argv parser = OptionParser() parser.add_option("--dir", dest="dir", default="./") opt, argc = parser.parse_args(argvs) print(argc, opt) display, start_display, add_menu, add_function_to_menu = init_display() beam = get_axs("./beam_cyl.cor") surf = set_surface("./cylinder.stp") display.DisplayShape(surf) # display.DisplayShape(axs_pln(gp_Ax3())) # display.DisplayShape(axs_pln(beam)) axs1 = beam val = 1 while val != None: axs0 = axs1 axs1, axs, val = reflect_axs2(axs0, surf, indx=2) get_deg(axs, dir_to_vec(axs1.Direction())) if val != None: display.DisplayShape( make_line(axs0.Location(), axs1.Location()), color="GREEN") # display.DisplayShape(axs_pln(axs1)) display.FitAll() start_display()
if __name__ == "__main__": argvs = sys.argv parser = argparse.ArgumentParser() parser.add_argument("--dir", dest="dir", default="./") opt = parser.parse_args() print(opt, argvs) display, start_display, add_menu, add_function_to_menu = init_display() beam = get_axs("../input/beam_cyl.cor") surf = set_surface("../input/cylinder.stp") display.DisplayShape(surf) # display.DisplayShape(axs_pln(gp_Ax3())) # display.DisplayShape(axs_pln(beam)) axs1 = beam val = 1 while val != None: axs0 = axs1 axs1, axs, val = reflect_axs2(axs0, surf, indx=2) get_deg(axs, dir_to_vec(axs1.Direction())) if val != None: display.DisplayShape(make_line(axs0.Location(), axs1.Location()), color="GREEN") # display.DisplayShape(axs_pln(axs1)) display.FitAll() start_display()
# 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()