def Display(self, context, material=Graphic3d_NOM_ALUMINIUM, color=None): """Displays all components of this instance to input context Parameters ---------- context : OCC.Display.OCCViewer.Viewer3d or WebRenderer The display context - should have a Display or DisplayShape method meterial : OCC.Graphic3d_NOM_* type (default=ALUMINIUM) The material for display: note some renderers do not allow this color : string The color for all components in this shape """ for name, component in self.items(): ais = AIS_Shape(component) ais.SetMaterial(material) if color: try: from OCC.Display.OCCViewer import get_color_from_name color = get_color_from_name(color) except: pass ais.SetColor(color) try: context.Context.Display(ais.GetHandle()) except: context.DisplayShape(component)
def BBox_FromExtents(xmin, ymin, zmin, xmax, ymax, zmax): """Generates the Wire Edges defining the Bounding Box defined in the input arguments: Can be used to display the bounding box""" s = BRepPrimAPI_MakeBox(gp_Pnt(xmin, ymin, zmin), gp_Pnt(xmax, ymax, zmax)).Shape() ais_bbox = AIS_Shape(s) ais_bbox.SetDisplayMode(AIS_WireFrame) return ais_bbox.GetHandle()
def Display(self, context, material=Graphic3d_NOM_ALUMINIUM, color=None): print("display-Part") for name, component in self.items(): ais = AIS_Shape(component) ais.SetMaterial(material) if color: try: from OCC.Display.OCCViewer import get_color_from_name color = get_color_from_name(color) except: pass ais.SetColor(color) try: context.Context.Display(ais.GetHandle()) #context.register_select_callback(print_xy_click) except: context.DisplayShape(component)
def color_the_edges(shp, display, color, width): shapeList = [] Ex = TopExp_Explorer(shp, TopAbs_EDGE) ctx = display.Context while Ex.More(): aEdge = topods.Edge(Ex.Current()) ais_shape = AIS_Shape(aEdge).GetHandle() ctx.SetColor(ais_shape, color, False) ctx.SetWidth(ais_shape, width, False) ctx.Display(ais_shape, False) Ex.Next()
##pythonOCC is distributed in the hope that it will be useful, ##but WITHOUT ANY WARRANTY; without even the implied warranty of ##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 OCC.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.AIS import AIS_Shape from OCC.Quantity import Quantity_NOC_BLACK from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() myBox = BRepPrimAPI_MakeBox(60, 60, 50).Shape() context = display.Context context.SetAutoActivateSelection(False) aisShape = AIS_Shape(myBox) h_aisShape = aisShape.GetHandle() context.Display(h_aisShape) # Set shape transparency, a float number from 0.0 to 1.0 context.SetTransparency(h_aisShape, 0.6) context.HilightWithColor(h_aisShape, Quantity_NOC_BLACK) display.View_Iso() display.FitAll() start_display()
##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 OCC.AIS import AIS_Shape from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere from OCC.Display.SimpleGui import init_display from OCC.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX, Graphic3d_TOS_FRAGMENT, Graphic3d_ShaderObject) from OCC.TCollection import TCollection_AsciiString display, start_display, add_menu, add_function_to_menu = init_display() shape = BRepPrimAPI_MakeSphere(100).Shape() anIO = AIS_Shape(shape) display.Context.Display(anIO.GetHandle()) # gragment shader fs = """ void main(void) { gl_FragColor=vec4(0.0, 1.0, 0, 1.0); } """ # vertex shader vs = """ void main() { gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): ''' ''' # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, gp_Pnt): vertex = BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, gp_Pnt2d): vertex = BRepBuilderAPI_MakeVertex( gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, TopoDS_Shape): shapes = [shapes] SOLO = True else: SOLO = False ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(OCC.V3d.V3d_TEX_ALL) shape_to_display = OCC.AIS.AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive shape_to_display = AIS_MultipleConnectedInteractive() for i in ais_shapes: shape_to_display.Connect(i) # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(Graphic3d_NOM_NEON_GNC) if color: if isinstance(color, str): color = get_color_from_name(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display
##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 OCC.AIS import AIS_Shape from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() # # Create a box # s = BRepPrimAPI_MakeBox(200, 100, 50).Shape() # # Create an AIS_Shape from the previous shape # ais_shp = AIS_Shape(s) ais_shp.SetWidth(4) ais_shp.SetTransparency(0.10) # # Get context and display shape # # Get Context ais_context = display.GetContext().GetObject() ais_context.Display(ais_shp.GetHandle()) display.View_Iso() display.FitAll() start_display()
#!/usr/bin/python # coding: utf-8 r"""Core dimensions display example""" import os from OCC.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt from OCC.AIS import AIS_Shape, AIS_RadiusDimension from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display('wx') c = gp_Circ(gp_Ax2(gp_Pnt(200., 200., 0.), gp_Dir(0., 0., 1.)), 80) ec = BRepBuilderAPI_MakeEdge(c).Edge() ais_shp = AIS_Shape(ec) display.Context.Display(ais_shp.GetHandle()) # Does not solve problem !! # os.environ["OCE_LIB_PATH"] = \ # "C:/_Guillaume/__gf_files__/____Projets/5xx-Developpement/_Repositories/github/guillaume-florent/oce" os.environ["CASROOT"] = \ "C:/_Guillaume/__gf_files__/____Projets/5xx-Developpement/_Repositories/github/guillaume-florent/oce" os.environ["CSF_UnitsLexicon"] = \ os.environ["CASROOT"] + "/src/UnitsAPI/Lexi_Expr.dat" os.environ["CSF_UnitsDefinition"] = \ os.environ["CASROOT"] + "/src/UnitsAPI/Units.dat" rd = AIS_RadiusDimension(ec) # rd.SetArrowSize(12) handle = rd.GetHandle()