def Bulk_stptoimag(self): pass self.file_list = os.listdir(self.chose_document) print(self.file_list) for file in self.file_list: self.canva._display.EraseAll() self.canva._display.hide_triedron() self.canva._display.display_triedron() if "stp" in file or "step" in file or "iges" in file: try: if file == "iseg": continue else: read_path = os.path.join(self.chose_document, file) the_shape = read_step_file(read_path) name = file.split(".") ais_shape = AIS_ColoredShape(the_shape) for e in TopologyExplorer(the_shape).solids(): rnd_color = (random(), random(), random()) ais_shape.SetCustomColor(e, rgb_color(0.5, 0.5, 0.5)) self.canva._display.Context.Display(ais_shape, True) self.canva._display.FitAll() path = self.chose_document + "\\" + name[0] + ".bmp" self.canva._display.ExportToImage(path) except: pass self.statusbar.showMessage("状态:表格生成成功")
def handleSelection(self): inspected_items = self.inspected_items self.sigRemoveObjects.emit(inspected_items) inspected_items.clear() items = self.selectedItems() if len(items) == 0: return item = items[-1] if type(item) is CQStackItem: cq_plane = item.workplane.plane dim = item.workplane.largestDimension() plane = gp_Ax3(cq_plane.origin.toPnt(), cq_plane.zDir.toDir(), cq_plane.xDir.toDir()) self.sigChangePlane.emit(plane) self.sigShowPlane[bool, float].emit(True, dim) for child in (item.child(i) for i in range(item.childCount())): obj = child.cq_item if hasattr(obj, 'wrapped') and type(obj) != Vector: ais = AIS_ColoredShape(obj.wrapped) inspected_items.append(ais) else: self.sigShowPlane.emit(False) obj = item.cq_item if hasattr(obj, 'wrapped') and type(obj) != Vector: ais = AIS_ColoredShape(obj.wrapped) inspected_items.append(ais) self.sigDisplayObjects.emit(inspected_items, False)
def make_AIS(obj: Union[cq.Workplane, cq.Shape], options={}): if isinstance(obj, cq.Shape): obj = to_workplane(obj) shape = to_compound(obj) ais = AIS_ColoredShape(shape.wrapped) if 'alpha' in options: ais.SetTransparency(options['alpha']) if 'color' in options: ais.SetColor(to_occ_color(options['color'])) if 'rgba' in options: r, g, b, a = options['rgba'] ais.SetColor(to_occ_color((r, g, b))) ais.SetTransparency(a) return ais, shape
from OCC.Core.Bnd import Bnd_Box from OCC.Core.BRepBndLib import brepbndlib_Add from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh from OCC.Core.Quantity import Quantity_Color from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB from OCC.Display.SimpleGui import init_display from OCC.Display.OCCViewer import Viewer3d from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox the_shape = read_step_file('SFU01610-4.step') print(type(the_shape)) # loads brep shape #cylinder_head = TopoDS_Shape() #builder = BRep_Builder() #breptools_Read(cylinder_head, './models/cylinder_head.brep', builder) # render cylinder head in x3dom my_renderer = x3dom_renderer.X3DomRenderer(path="d:\\123") ais_shape = AIS_ColoredShape(the_shape) #display.DisplayShape(my_box,update=True) #display.Context.Display(cube,True) for e in TopologyExplorer(the_shape).shells(): rnd_color = (random(), random(), random()) ais_shape.SetCustomColor(e, rgb_color(random(), random(), random())) my_renderer.DisplayShape(e, export_edges=True, color=(random(), random(), random())) my_renderer.render()
def set_selected(self, ais): ctx = self._get_context() ctx.ClearSelected(False) for obj in ais: ctx.AddOrRemoveSelected(obj, False) self.redraw() if __name__ == "__main__": import sys from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox app = QApplication(sys.argv) viewer = OCCViewer() viewer.show_line() dlg = QDialog() dlg.setFixedHeight(400) dlg.setFixedWidth(600) layout(dlg, (viewer, ), dlg) dlg.show() box = BRepPrimAPI_MakeBox(20, 20, 30) box_ais = AIS_ColoredShape(box.Shape()) viewer.display(box_ais) sys.exit(app.exec_())
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. ## # You should have received a copy of the GNU Lesser General Public License # along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from __future__ import print_function from random import random from OCC.Core.AIS import AIS_ColoredShape from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Display.OCCViewer import rgb_color from OCC.Display.SimpleGui import init_display from OCC.Extend.TopologyUtils import TopologyExplorer display, start_display, add_menu, add_function_to_menu = init_display() my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() ais_shp = AIS_ColoredShape(my_box) for fc in TopologyExplorer(my_box).faces(): # set a custom color per-face ais_shp.SetCustomColor(fc, rgb_color(random(), random(), random())) display.Context.Display(ais_shp) display.FitAll() start_display()
def get_occ_color(ais: AIS_ColoredShape) -> QColor: color = Quantity_Color() ais.Color(color) return QColor.fromRgbF(color.Red(), color.Green(), color.Blue())
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. ## # You should have received a copy of the GNU Lesser General Public License # along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from __future__ import print_function from random import random from OCC.Core.AIS import AIS_ColoredShape from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Display.OCCViewer import rgb_color from OCC.Display.SimpleGui import init_display from OCC.Extend.TopologyUtils import TopologyExplorer display, start_display, add_menu, add_function_to_menu = init_display() my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() ais = AIS_ColoredShape(my_box) for fc in TopologyExplorer(my_box).faces(): # set a custom color per-face ais.SetCustomColor(fc, rgb_color(random(), random(), random())) display.Context.Display(ais.GetHandle()) display.FitAll() start_display()
def make_AIS(obj: cq.Workplane): shape = to_compound(obj) ais = AIS_ColoredShape(shape.wrapped) return ais, shape