示例#1
0
    def set_selection_mode(self, mode):
        """ Set the selection mode.

        Parameters
        ----------
        mode: String
            The mode to use (Face, Edge, Vertex, Shell, or Solid)

        """
        ais_context = self.ais_context
        ais_context.Deactivate()
        if mode == 'any':
            for mode in (TopAbs.TopAbs_SHAPE, TopAbs.TopAbs_SHELL,
                         TopAbs.TopAbs_FACE, TopAbs.TopAbs_EDGE,
                         TopAbs.TopAbs_WIRE, TopAbs.TopAbs_VERTEX):
                ais_context.Activate(AIS_Shape.SelectionMode_(mode))
            return
        attr = 'TopAbs_%s' % mode.upper()
        mode = getattr(TopAbs, attr, TopAbs.TopAbs_SHAPE)
        ais_context.Activate(AIS_Shape.SelectionMode_(mode))
示例#2
0
    def _default_ais_shape(self):
        """ Generate the AIS shape for the viewer to display.
        This is only invoked when the viewer wants to display the shape.

        """
        d = self.declaration

        if d.texture is not None:
            texture = d.texture
            ais_shape = AIS_TexturedShape(self.shape)

            if os.path.exists(texture.path):
                path = TCollection_AsciiString(texture.path)
                ais_shape.SetTextureFileName(path)
                params = texture.repeat
                ais_shape.SetTextureRepeat(params.enabled, params.u, params.v)
                params = texture.origin
                ais_shape.SetTextureOrigin(params.enabled, params.u, params.v)
                params = texture.scale
                ais_shape.SetTextureScale(params.enabled, params.u, params.v)
                ais_shape.SetTextureMapOn()
                ais_shape.SetDisplayMode(3)
        else:
            ais_shape = AIS_Shape(self.shape)

        ais_shape.SetTransparency(d.transparency)
        if d.color:
            c, a = color_to_quantity_color(d.color)
            ais_shape.SetColor(c)
            if a is not None:
                ais_shape.SetTransparency(a)
        if d.material.name:
            ma = material_to_material_aspect(d.material)
            ais_shape.SetMaterial(ma)
        ais_shape.SetLocalTransformation(self.location.Transformation())
        return ais_shape
示例#3
0
    def display_shape(self,
                      shape,
                      rgb=None,
                      transparency=None,
                      material=Graphic3d_NOM_DEFAULT):
        """
        Display a shape.

        :param OCCT.TopoDS.TopoDS_Shape shape: The shape.
        :param rgb: The RGB color (r, g, b).
        :type rgb: collections.Sequence[float] or OCCT.Quantity.Quantity_Color
        :param float transparency: The transparency (0 to 1).
        :param OCCT.Graphic3d.Graphic3d_NameOfMaterial material: The material.

        :return: The AIS_Shape created for the part.
        :rtype: OCCT.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)

        ma = Graphic3d_MaterialAspect(material)
        ais_shape.SetMaterial(ma)

        self.my_context.Display(ais_shape, True)
        return ais_shape
##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 OCCT.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCCT.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()
示例#5
0
    def display_shape(self,
                      shape,
                      color=None,
                      transparency=None,
                      material=None,
                      texture=None,
                      update=True):
        """ Display a shape.

        Parameters
        ----------
        shape: OCCT.TopoDS.TopoDS_Shape
            The shape to display
        color: collections.Sequence(float) or OCCT.Quantity.Quantity_Color
            The enaml color
        transparency: float
            The transparency (0 to 1).
        material: String
            The material to render the shape.
        texture: declaracad.occ.shape.Texture
            The texture to apply to the shape.

        Returns
        -------
        ais_shape: OCCT.AIS.AIS_Shape
            The AIS_Shape created for the part.
        """
        if texture is not None:
            ais_shape = AIS_TexturedShape(shape)

            if os.path.exists(texture.path):

                ais_shape.SetTextureFileName(
                    TCollection_AsciiString(texture.path))

                params = texture.repeat
                ais_shape.SetTextureRepeat(params.enabled, params.u, params.v)

                params = texture.origin
                ais_shape.SetTextureOrigin(params.enabled, params.u, params.v)

                params = texture.scale
                ais_shape.SetTextureScale(params.enabled, params.u, params.v)

                ais_shape.SetTextureMapOn()
                ais_shape.SetDisplayMode(3)

        else:
            ais_shape = AIS_Shape(shape)

        if color:
            color, alpha = color_to_quantity_color(color)
            ais_shape.SetColor(color)
            if alpha is not None:
                ais_shape.SetTransparency(alpha)
        elif material is None and texture is None:
            color, alpha = self.shape_color
            ais_shape.SetColor(color)
            if alpha is not None:
                ais_shape.SetTransparency(alpha)

        if transparency is not None:
            ais_shape.SetTransparency(transparency)

        if material is not None:
            ma = material_to_material_aspect(material)
            ais_shape.SetMaterial(ma)

        self.ais_context.Display(ais_shape, update)
        return ais_shape
示例#6
0
##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 OCCT.AIS import AIS_Shape
from OCCT.BRepPrimAPI import BRepPrimAPI_MakeSphere
from OCCT.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX,
                            Graphic3d_TOS_FRAGMENT, Graphic3d_ShaderObject)
from OCCT.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, True)

# 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;
示例#7
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 OCCT.AIS import AIS_Shape
from OCCT.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, True)

display.View_Iso()
display.FitAll()
start_display()
示例#8
0
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(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 OCCT.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt
from OCCT.AIS import AIS_Shape, AIS_RadiusDimension
from OCCT.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Display.SimpleGui import init_display

display, start_display, add_menu, add_function_to_menu = init_display()

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, True)

rd = AIS_RadiusDimension(ec)
#rd.SetArrowSize(12)
display.Context.Display(rd, True)
display.FitAll()
start_display()