Ejemplo n.º 1
0
    def test_Perform(self):
        """
        Test Font_BRepTextBuilder::Perform.
        """

        # Get a font (os dependent)
        font_names = TColStd_SequenceOfHAsciiString()
        font_mgr = Font_FontMgr.GetInstance_()
        font_mgr.GetAvailableFontsNames(font_names)
        self.assertGreater(font_names.Size(), 0)

        font_family = TCollection_AsciiString(font_names.First().ToCString())
        font_style = Font_FontAspect.Font_FA_Regular

        # Create the font
        font = Font_BRepFont()
        self.assertTrue(font.FindAndInit(font_family, font_style, 12.0))

        # Create builder
        builder = Font_BRepTextBuilder()

        # Parameters
        text = NCollection_String("pyOCCT".encode("utf-8"))
        pos = gp_Ax3()
        halign = Graphic3d_HTA_LEFT
        valign = Graphic3d_VTA_BOTTOM
        topods_shape = builder.Perform(font, text, pos, halign, valign)
        self.assertFalse(topods_shape.IsNull())
Ejemplo n.º 2
0
Archivo: xde.py Proyecto: trelau/AFEM
    def set_string(self, string):
        """
        Set label name.

        :param str string: The string.

        :return: None.
        """
        txt = TCollection_AsciiString(string)
        TDataStd_AsciiString.Set_(self._label, txt)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def init_viewer(self):
        """ Init viewer when the QOpenGLWidget is ready

        """
        d = self.declaration
        widget = self.widget
        if sys.platform == 'win32':
            display = Aspect_DisplayConnection()
        else:
            display_name = TCollection_AsciiString(
                os.environ.get('DISPLAY', '0'))
            display = Aspect_DisplayConnection(display_name)
        self.display_connection = display

        # Create viewer
        graphics_driver = self.graphics_driver = OpenGl_GraphicDriver(display)

        viewer = self.v3d_viewer = V3d_Viewer(graphics_driver)
        view = self.v3d_view = viewer.CreateView()

        # Setup window
        win_id = widget.get_window_id()
        if sys.platform == 'win32':
            window = WNT_Window(win_id)
        elif sys.platform == 'darwin':
            window = Cocoa_Window(win_id)
        else:
            window = Xw_Window(self.display_connection, win_id)
        if not window.IsMapped():
            window.Map()
        self.v3d_window = window
        view.SetWindow(window)
        view.MustBeResized()

        # Setup viewer
        ais_context = self.ais_context = AIS_InteractiveContext(viewer)
        drawer = self.prs3d_drawer = ais_context.DefaultDrawer()

        # Needed for displaying graphics
        prs_mgr = self.prs_mgr = ais_context.MainPrsMgr()
        gfx_mgr = self.gfx_structure_manager = prs_mgr.StructureManager()
        self.gfx_structure = Graphic3d_Structure(gfx_mgr)

        # Lights camera
        self.camera = view.Camera()

        try:
            self.set_lights(d.lights)
        except Exception as e:
            log.exception(e)
            viewer.SetDefaultLights()

        #viewer.DisplayPrivilegedPlane(True, 1)
        #view.SetShadingModel(Graphic3d_TypeOfShadingModel.V3d_PHONG)

        # background gradient
        with self.redraw_blocked():
            self.set_background_gradient(d.background_gradient)
            self.set_draw_boundaries(d.draw_boundaries)
            self.set_trihedron_mode(d.trihedron_mode)
            self.set_display_mode(d.display_mode)
            self.set_hidden_line_removal(d.hidden_line_removal)
            self.set_selection_mode(d.selection_mode)
            self.set_view_mode(d.view_mode)
            self.set_view_projection(d.view_projection)
            self.set_lock_rotation(d.lock_rotation)
            self.set_lock_zoom(d.lock_zoom)
            self.set_shape_color(d.shape_color)
            self.set_chordial_deviation(d.chordial_deviation)
            self._update_rendering_params()
            self.set_grid_mode(d.grid_mode)
            self.set_grid_colors(d.grid_colors)

            self.init_signals()
            self.dump_gl_info()

        self.redraw()

        qt_app = self._qt_app
        for child in self.children():
            self.child_added(child)
            qt_app.processEvents()
Ejemplo n.º 6
0
{
    gl_FragColor=vec4(0.0, 1.0, 0, 1.0);
}
"""

# vertex shader
vs = """
void main()
{
    gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}
"""

# construct the shader, load, compile and attach the GLSL programs
vs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_VERTEX, TCollection_AsciiString(vs))
fs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_FRAGMENT, TCollection_AsciiString(fs))
aProgram = Graphic3d_ShaderProgram()
aProgram.AttachShader(fs_shader)
aProgram.AttachShader(vs_shader)

# attach the shader to the AIS_Shape representation that renders the sphere
aspect = anIO.Attributes().ShadingAspect().Aspect()

if aProgram.IsDone():
    aspect.SetShaderProgram(aProgram)
else:
    raise AssertionError("no valid shader program found")

# when a shader fails to compile, raise an AssertionError