def __init__(self, touch=False, file=False): dispocc.__init__(self, touch=touch) self.prop = GProp_GProps() self.base = make_box(100, 100, 100) self.base_vol = self.cal_vol(self.base) self.splitter = BOPAlgo_Splitter() self.splitter.AddArgument(self.base) print(self.cal_vol(self.base))
def show_box(self, axs=gp_Ax3(), lxyz=[100, 100, 100]): box = make_box(*lxyz) ax1 = gp_Ax3(gp_Pnt(-lxyz[0] / 2, -lxyz[1] / 2, -lxyz[2] / 2), gp_Dir(0, 0, 1)) trf = gp_Trsf() trf.SetTransformation(axs, gp_Ax3()) trf.SetTransformation(ax1, gp_Ax3()) box.Location(TopLoc_Location(trf)) self.display.DisplayShape(axs.Location()) self.show_axs_pln(axs, scale=lxyz[0]) self.display.DisplayShape(box, transparency=0.7)
def __init__(self): plotocc.__init__(self) self.prop = GProp_GProps() self.base = make_box(100, 100, 100) self.base_vol = self.cal_vol(self.base) self.splitter = BOPAlgo_Splitter() self.splitter.AddArgument(self.base) print(self.cal_vol(self.base)) from OCC.Display.qtDisplay import qtViewer3d self.app = self.get_app() self.wi = self.app.topLevelWidgets()[0] self.vi = self.wi.findChild(qtViewer3d, "qt_viewer_3d") self.on_select()
def __init__(self): plotocc.__init__(self) self.axis = gp_Ax3(gp_Pnt(1000, 1000, 1000), gp_Dir(0, 0, 1)) self.trsf = set_trf(ax2=self.axis) self.box = make_box(gp_Pnt(), 250, 250, 250) self.box.Location(set_loc(ax2=self.axis)) self.beam1 = gp_Ax3() rot_axs(self.beam1, [100, 100, -500], [0, 0, 0]) self.beam1.Transform(self.trsf) self.Reflect(self.beam1, self.box) self.beam2 = gp_Ax3() rot_axs(self.beam2, [0, 0, -500], [0, 1, 0]) self.beam2.Transform(self.trsf) self.beam3 = gp_Ax3() rot_axs(self.beam3, [-100, -100, -500], [0, 2, 0]) self.beam3.Transform(self.trsf)
beam1 = gp_Ax3(p1, vec_to_dir(v0.Reversed()), vec_to_dir(v1.Reversed())) norm1 = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) if tr == 0: beam1.Mirror(norm1.Ax2()) if beam1.Direction().Dot(norm1.Direction()) < 0: beam1.ZReverse() elif tr == 1: beam1.ZReverse() return beam1 if __name__ == '__main__': obj = dispocc() obj.show_axs_pln() obj.display.DisplayShape(make_box(100, 100, 100)) obj.display.FitAll() obj.export_cap() obj.wi.close() print(obj.base_axs) obj = dispocc(touch=True) obj.show_axs_pln() obj.display.DisplayShape(make_box(100, 100, 100), material=Graphic3d_NOM_ALUMINIUM) obj.display.DisplayShape(obj.make_plane_axs(), material=Graphic3d_NOM_COPPER) obj.show() print(obj.base_axs)
import numpy as np from OCC.Core.gp import gp_Pnt from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Extend.DataExchange import write_iges_file, write_step_file, write_stl_file from OCCUtils.Construct import make_box shp = make_box(gp_Pnt(-50, -50, -50), 100, 100, 100) write_iges_file(shp, "box.iges") write_step_file(shp, "box.stp") write_stl_file(shp, "box.stl")
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()
import time import os import glob import shutil import datetime from optparse import OptionParser from OCC.Display.SimpleGui import init_display from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3 from OCC.Core.gp import gp_Pnt2d from OCC.Core.MeshVS import MeshVS_Mesh, MeshVS_PrsBuilder from OCC.Core.IMeshTools import IMeshTools_MeshAlgoFactory from OCCUtils.Construct import make_box from OCCUtils.Construct import make_line, make_wire, make_edge from src.base import plotocc, write_stl_file_mesh1, write_stl_file_mesh2 if __name__ == '__main__': argvs = sys.argv parser = OptionParser() opt, argc = parser.parse_args(argvs) print(opt, argc) obj = plotocc() axs = gp_Ax3() box = make_box(axs.Ax2(), 200, 200, 200) obj.display.DisplayShape(box) obj.show_axs_pln(axs, scale=250) obj.show()
def Test(self): self.display.DisplayShape(make_box(100, 100, 100)) self.display.DisplayShape(gp_Pnt()) self.display.FitAll() self.start_display()
from src.base import plotocc, write_stl_file_mesh1, write_stl_file_mesh2 if __name__ == '__main__': argvs = sys.argv parser = OptionParser() opt, argc = parser.parse_args(argvs) print(opt, argc) obj = plotocc() # # https://www.opencascade.com/doc/occt-7.4.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_6 # https://www.opencascade.com/doc/occt-7.5.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_6 # axs = gp_Ax3() box = make_box(200, 200, 200) chf = BRepFilletAPI_MakeChamfer(box) # chf.Build() fil = BRepFilletAPI_MakeFillet(box) fil.SetFilletShape(ChFi3d_Rational) par = TColgp_Array1OfPnt2d(1, 2) par.SetValue(1, gp_Pnt2d(-1000, 10)) par.SetValue(2, gp_Pnt2d(1000, 10)) top = TopExp_Explorer(box, TopAbs_EDGE) fil.Add(par, top.Current()) top.Next() fil.Add(par, top.Current()) top.Next() fil.Add(par, top.Current())
return _slices def get_brep(): cylinder_head = TopoDS_Shape() builder = BRep_Builder() breptools_Read(cylinder_head, './core_example/cylinder_head.brep', builder) return cylinder_head if __name__ == '__main__': shp = get_brep() xyz_min_max = get_boundingbox(shp) p1 = gp_Pnt(*xyz_min_max[0:3]) p2 = gp_Pnt(*xyz_min_max[3:]) box = make_box(p1, p2) obj = plotocc() obj.display.DisplayShape(box, transparency=0.9) obj.display.DisplayShape(shp) z_delta = abs(xyz_min_max[2] - xyz_min_max[5]) for z in np.linspace(xyz_min_max[2], xyz_min_max[5], 5): print(z) plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0.0, 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shp, face) section.Build() if section.IsDone(): obj.display.DisplayShape(section.Shape(), color="BLUE")
import logging logging.getLogger('matplotlib').setLevel(logging.ERROR) sys.path.append(os.path.join("./")) from src.base import plot2d, plotocc from OCC.Core.gp import gp_Ax3, gp_Pnt, gp_Vec, gp_Dir from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCCUtils.Construct import make_box if __name__ == '__main__': argvs = sys.argv parser = argparse.ArgumentParser() parser.add_argument("--dir", dest="dir", default="./") parser.add_argument("--pxyz", dest="point", default=[0.0, 0.0, 0.0], type=float, nargs=3) opt = parser.parse_args() print(opt, argvs) obj = plotocc() obj.SaveMenu() box1 = make_box(gp_Pnt(0, 0, 0), gp_Pnt(100, 100, 100)) obj.export_stp(box1, stpname="./shp/box_001.stp") box2 = make_box(gp_Pnt(50, 50, 50), gp_Pnt(200, 200, 200)) obj.export_stp(box2, stpname="./shp/box_002.stp")
from OCC.Core.TopoDS import TopoDS_Compound from OCC.Core.BRep import BRep_Builder from OCC.Core.BRepGProp import brepgprop_LinearProperties from OCC.Core.BOPAlgo import BOPAlgo_Splitter, BOPAlgo_MakerVolume, BOPAlgo_Builder from OCC.Core.TopAbs import TopAbs_EDGE, TopAbs_SHAPE, TopAbs_SOLID from OCC.Core.TopTools import TopTools_ListOfShape from OCC.Core.TopExp import TopExp_Explorer from OCC.Core.GProp import GProp_GProps from OCC.Extend.DataExchange import write_step_file, write_stl_file from OCCUtils.Topology import Topo from OCCUtils.Construct import make_box, make_face from OCCUtils.Construct import vec_to_dir if __name__ == "__main__": num = 0 box = make_box(100, 100, 100) stpname = "{}/shp_{:04d}.stp".format("./shp/", num) write_step_file(box, stpname) splitter = BOPAlgo_Splitter() splitter.AddArgument(box) for i in range(7): 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, -1000, 1000, -1000, 1000) splitter.AddTool(fce) splitter.Perform()
import time import os from unwrap.unwrap import unwrap from mpl_toolkits.axes_grid1 import make_axes_locatable from linecache import getline, clearcache from scipy.integrate import simps from scipy.constants import * from optparse import OptionParser sys.path.append(os.path.join('..')) from OCCUtils.Construct import vec_to_dir from OCCUtils.Topology import Topo from OCCUtils.Construct import make_box, make_face from OCC.BRep import BRep_Builder from OCC.BOPAlgo import BOPAlgo_MakerVolume, BOPAlgo_Builder from OCC.TopoDS import TopoDS_Compound from OCC.gp import gp_Pnt, gp_Vec, gp_Ax1, gp_Ax2, gp_Ax3 from OCC.gp import gp_Pln from OCC.Display.SimpleGui import init_display if __name__ == "__main__": from src.pyocc.OCCQt import Viewer from src.pyocc.OCCDisplay import OCCDisplay display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape(make_box(10, 10, 10)) display.FitAll() start_display()
import numpy as np import matplotlib.pyplot as plt import os import sys sys.path.append(os.path.join("../")) from src.base_occ import dispocc from OCC.Display.SimpleGui import init_display from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3 from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir from OCC.Core.gp import gp_Pln, gp_Trsf, gp_Lin #from OCC.Extend.ShapeFactory import make_box from OCCUtils.Construct import make_box if __name__ == "__main__": display, start_display, add_menu, add_function_to_menu = init_display() pnt = gp_Pnt() dispocc.make_EllipWire(None) display.DisplayShape(pnt) display.DisplayShape(make_box(pnt, 100, 100, 100), transparency=0.01) display.DisplayShape(make_box(gp_Pnt(50, 50, 50), 10, 10, 10)) display.FitAll() start_display()