Exemple #1
0
    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
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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")
Exemple #5
0
##
##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()
ais_context.Display(ais_shp)

display.View_Iso()
display.FitAll()
start_display()