def _renderShapeObj(self, aShape): shapeTr = BRepBuilderAPI_Transform(aShape, self.aMove.getTrsf()).Shape() ais = AIS_Shape(shapeTr) r, g, b = self.aStyle.getNormedColor() aisColor = Quantity_Color( r, g, b, Quantity_TypeOfColor(Quantity_TypeOfColor.Quantity_TOC_RGB)) ais.SetColor(aisColor) ais.SetTransparency(self.aStyle.getNormedTransparency()) aspect = Graphic3d_MaterialAspect( MATERIAL_CONSTS[self.aStyle.getMaterial()]) ais.SetMaterial(aspect) self.display.Context.Display(ais, False)
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) #context.register_select_callback(print_xy_click) except: context.DisplayShape(component)
def draw_wp(self, uid): """Draw the workplane with uid.""" context = self.canvas._display.Context if uid: wp = self.wp_dict[uid] border = wp.border if uid == self.activeWpUID: borderColor = Quantity_Color(Quantity_NOC_DARKGREEN) else: borderColor = Quantity_Color(Quantity_NOC_GRAY) aisBorder = AIS_Shape(border) context.Display(aisBorder, True) context.SetColor(aisBorder, borderColor, True) transp = 0.8 # 0.0 <= transparency <= 1.0 context.SetTransparency(aisBorder, transp, True) drawer = aisBorder.DynamicHilightAttributes() context.HilightWithColor(aisBorder, drawer, True) clClr = Quantity_Color(Quantity_NOC_MAGENTA1) for cline in wp.clines: geomline = wp.geomLineBldr(cline) aisline = AIS_Line(geomline) aisline.SetOwner(geomline) drawer = aisline.Attributes() # asp parameters: (color, type, width) asp = Prs3d_LineAspect(clClr, 2, 1.0) drawer.SetLineAspect(asp) aisline.SetAttributes(drawer) context.Display(aisline, False) # (see comment below) # 'False' above enables 'context' mode display & selection pntlist = wp.intersectPts() # type <gp_Pnt> for point in pntlist: self.canvas._display.DisplayShape(point) for ccirc in wp.ccircs: aiscirc = AIS_Circle(wp.convert_circ_to_geomCirc(ccirc)) drawer = aisline.Attributes() # asp parameters: (color, type, width) asp = Prs3d_LineAspect(clClr, 2, 1.0) drawer.SetLineAspect(asp) aiscirc.SetAttributes(drawer) context.Display(aiscirc, False) # (see comment below) # 'False' above enables 'context' mode display & selection for edge in wp.edgeList: self.canvas._display.DisplayShape(edge, color="WHITE") self.canvas._display.Repaint()
def __init__(self, shape, color, border_color=Color(0, 0, 0), wire_color=None): self.shape = shape super().__init__(AIS_Shape(self.shape._shp), color=color, border_color=border_color, wire_color=wire_color)
def display_shape(self, shape, rgb=None, transparency=None, material=None): """ Display a shape. :param OCC.Core.TopoDS.TopoDS_Shape shape: The shape. :param rgb: The RGB color (r, g, b). :type rgb: collections.Sequence(float) or OCC.Core.Quantity.Quantity_Color :param float transparency: The transparency (0 to 1). :param OCC.Core.Graphic3d.Graphic3d_NameOfMaterial material: The material. :return: The AIS_Shape created for the part. :rtype: OCC.Core.AIS.AIS_Shape """ ais_shape = AIS_Shape(shape) if isinstance(rgb, (tuple, list)): r, g, b = rgb if r > 1.: r /= 255. if g > 1.: g /= 255. if b > 1.: b /= 255. color = Quantity_Color(r, g, b, Quantity_TOC_RGB) ais_shape.SetColor(color) elif isinstance(rgb, Quantity_Color): ais_shape.SetColor(rgb) if transparency is not None: ais_shape.SetTransparency(transparency) if material is not None: ma = Graphic3d_MaterialAspect(material) ais_shape.SetMaterial(ma) self._my_context.Display(ais_shape, True) return ais_shape
def draw_shape(self, uid): """Draw the part (shape) with uid.""" context = self.canvas._display.Context if uid: if uid in self.transparency_dict: transp = self.transparency_dict[uid] else: transp = 0.0 part_data = doc.part_dict[uid] shape = part_data["shape"] color = part_data["color"] try: aisShape = AIS_Shape(shape) self.ais_shape_dict[uid] = aisShape context.Display(aisShape, True) context.SetColor(aisShape, color, True) # Set shape transparency, a float from 0.0 to 1.0 context.SetTransparency(aisShape, transp, True) drawer = aisShape.DynamicHilightAttributes() context.HilightWithColor(aisShape, drawer, True) except AttributeError as e: print(e)
def intersect_point(self, x, y): self.Select(x, y) viewLine = self.viewline(x, y) for i in range(len(self.selected_shapes)): hShape = AIS_Shape.DownCast(self.selected_ishapes[i]) shape = hShape.Shape() loc = self.Context.Location(hShape) loc_shape = shape.Located(loc) shapeIntersector = IntCurvesFace_ShapeIntersector() shapeIntersector.Load(loc_shape, precision_Confusion()) shapeIntersector.Perform(viewLine, float("-inf"), float("+inf")) if shapeIntersector.NbPnt() >= 1: ip = shapeIntersector.Pnt(1) return point3(ip), True else: continue return point3(), False
def display(self, writer=None): debug("shape Display") if self.shape != None: if (writer != None): writer.Transfer(self.shape) else: debug("Line style is %s" % (self.style, )) ais_context = Singleton.sd.display.GetContext() if (self.style == 'hidden'): ais_shp = AIS_Shape(self.shape) ais_shp.SetWidth(0.1) ais_shp.SetTransparency(0.10) ais_shp.SetColor(rgb_color(0, 0, 0)) aspect = ais_shp.Attributes().WireAspect() aspect.SetColor(rgb_color(0, 0, 0)) aspect.SetTypeOfLine(1) ais_context.Display(ais_shp, True) elif (self.style == 'main_projection'): ais_shp = AIS_Shape(self.shape) ais_shp.SetWidth(5) #ais_shp.SetTransparency(0) #ais_shp.SetColor(rgb_color(0,0,0)) aspect = ais_shp.Attributes().WireAspect() aspect.SetColor(rgb_color(0, 0, 0)) aspect.SetTypeOfLine(0) ais_context.Display(ais_shp, True) else: ais_context = Singleton.sd.display.GetContext() ais_shp = AIS_Shape(self.shape) ais_shp.SetWidth(2.0) ais_shp.SetTypeOfHLR(2) if (is_var_set(self.shape_color)): ais_shp.SetColor(self.shape_color) else: ais_shp.SetColor(Quantity_Color(Quantity_NOC_PERU)) if (self.display_mode == DISP_MODE_WIREFRAME): ais_context.SetDisplayMode(ais_shp, AIS_WireFrame, True) else: ais_context.SetDisplayMode(ais_shp, AIS_Shaded, True) ais_context.Display(ais_shp, True) else: warning("Empty shape")
##(at your option) any later version. ## ##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.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.AIS import AIS_Shape from OCC.Core.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) context.Display(aisShape) # Set shape transparency, a float number from 0.0 to 1.0 context.SetTransparency(aisShape, 0.6) context.HilightWithColor(aisShape, Quantity_NOC_BLACK) display.View_Iso() display.FitAll() start_display()
##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.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.AIS import AIS_Shape 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) context.Display(aisShape, True) # Set shape transparency, a float number from 0.0 to 1.0 context.SetTransparency(aisShape, 0.6, True) owner = aisShape.GetOwner() drawer = aisShape.DynamicHilightAttributes() # TODO: how do we set the color ? Quantity_NOC_RED context.HilightWithColor(aisShape, drawer, True) 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.Core.AIS import AIS_Shape from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere from OCC.Core.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX, Graphic3d_TOS_FRAGMENT, Graphic3d_ShaderObject) from OCC.Core.TCollection import TCollection_AsciiString from OCC.Display.SimpleGui import init_display 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 _drawShape(self, shape, style): ais = AIS_Shape(shape) self._drawAis(ais, style)
##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.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.AIS import AIS_Shape from OCC.Core.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()
def redraw(self): context = self.canva._display.Context if not self.registeredCallback: self.canva._display.SetSelectionModeNeutral() context.SetAutoActivateSelection(True) context.RemoveAll(True) for uid in self.drawList: if uid in self._partDict.keys(): if uid in self._transparencyDict.keys(): transp = self._transparencyDict[uid] else: transp = 0.0 color = self._colorDict[uid] aisShape = AIS_Shape(self._partDict[uid]) context.Display(aisShape, True) context.SetColor(aisShape, color, True) # Set shape transparency, a float from 0.0 to 1.0 context.SetTransparency(aisShape, transp, True) drawer = aisShape.DynamicHilightAttributes() context.HilightWithColor(aisShape, drawer, True) elif uid in self._wpDict.keys(): wp = self._wpDict[uid] border = wp.border if uid == self.activeWpUID: borderColor = Quantity_Color(Quantity_NOC_DARKGREEN) else: borderColor = Quantity_Color(Quantity_NOC_GRAY) aisBorder = AIS_Shape(border) context.Display(aisBorder, True) context.SetColor(aisBorder, borderColor, True) transp = 0.8 # 0.0 <= transparency <= 1.0 context.SetTransparency(aisBorder, transp, True) drawer = aisBorder.DynamicHilightAttributes() context.HilightWithColor(aisBorder, drawer, True) clClr = Quantity_Color(Quantity_NOC_MAGENTA1) for cline in wp.clines: geomline = wp.geomLineBldr(cline) aisline = AIS_Line(geomline) aisline.SetOwner(geomline) drawer = aisline.Attributes() # asp parameters: (color, type, width) asp = Prs3d_LineAspect(clClr, 2, 1.0) drawer.SetLineAspect(asp) aisline.SetAttributes(drawer) context.Display(aisline, False) # (see comment below) # 'False' above enables 'context' mode display & selection pntlist = wp.intersectPts() # type <gp_Pnt> for point in pntlist: self.canva._display.DisplayShape(point) for ccirc in wp.ccircs: aiscirc = AIS_Circle(wp.convert_circ_to_geomCirc(ccirc)) drawer = aisline.Attributes() # asp parameters: (color, type, width) asp = Prs3d_LineAspect(clClr, 2, 1.0) drawer.SetLineAspect(asp) aiscirc.SetAttributes(drawer) context.Display(aiscirc, False) # (see comment below) # 'False' above enables 'context' mode display & selection for edge in wp.edgeList: self.canva._display.DisplayShape(edge, color="WHITE") self.canva._display.Repaint()
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): """ display one or a set of displayable objects """ SOLO = False # assume multiple instances by default # 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 ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(V3d_TEX_ALL) shape_to_display = 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 ais_shp in ais_shapes: # TODO : following line crashes with oce-0.18 # why ? fix ? #shape_to_display.Connect(i) self.Context.Display(ais_shp, False) shape_to_display = ais_shapes return shape_to_display # 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
cut = cutFactory.MakeTrianglelePattern(90., 30, 4.) cut = transform.TransformShape(0., 5., 120., 40., 0., 120., cut) tube = BRepAlgoAPI_Cut(tube, cut).Shape() cut = cutFactory.MakeCirclePatern( 90., 30, ) cut = transform.TransformShape(0., 0., 30., 0., -90., 0., cut) tube = BRepAlgoAPI_Cut(tube, cut).Shape() cut = cutFactory.MakePentagonPattern(90., 30., 2.) cut = transform.TransformShape(0., 0., 80., 0., -90., 0., cut) tube = BRepAlgoAPI_Cut(tube, cut).Shape() aisCut = AIS_Shape(cut) context.Display(aisCut, True) aisTube = AIS_Shape(tube) context.Display(aisTube, True) stepWriter = STEPControl_Writer() Interface_Static_SetCVal("write.step.schema", "AP203") stepWriter.Transfer(aisTube.Shape(), STEPControl_AsIs) status = stepWriter.Write("Test3.stp") # menu_name = 'Tube Maker' # add_menu( menu_name ) # add_function_to_menu( menu_name, TestFunction )
## ##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.Core.AIS import AIS_Shape from OCC.Core.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()