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 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")
def renderShapeObj(self, shape, transforms, styleName): color, transparency, materialName = self.getStyle(styleName) trsf = gp_Trsf() for tr in transforms: trsf *= tr.getTrsf() shape = BRepBuilderAPI_Transform(shape, trsf).Shape() ais = AIS_Shape(shape) r,g,b = color aisColor = Quantity_Color(r/256, g/256, b/256, Quantity_TypeOfColor(Quantity_TypeOfColor.Quantity_TOC_RGB)) ais.SetColor(aisColor) ais.SetTransparency(transparency/100) aspect = Graphic3d_MaterialAspect(getMaterialNameConst(materialName)) ais.SetMaterial(aspect) self.display.Context.Display(ais, False)
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)