Beispiel #1
0
    def dump_gl_info(self):
        # Debug info
        try:
            ctx = self.graphics_driver.GetSharedContext()
            if ctx is None or not ctx.IsValid():
                return
            v1 = ctx.VersionMajor()
            v2 = ctx.VersionMinor()
            log.info("OpenGL version: {}.{}".format(v1, v2))
            log.info("GPU memory: {}".format(ctx.AvailableMemory()))
            log.info("GPU memory info: {}".format(
                ctx.MemoryInfo().ToCString()))
            log.info("Max MSAA samples: {}".format(ctx.MaxMsaaSamples()))

            supports_raytracing = ctx.HasRayTracing()
            log.info("Supports ray tracing: {}".format(supports_raytracing))
            if supports_raytracing:
                log.info("Supports textures: {}".format(
                    ctx.HasRayTracingTextures()))
                log.info("Supports adaptive sampling: {}".format(
                    ctx.HasRayTracingAdaptiveSampling()))
                log.info("Supports adaptive sampling atomic: {}".format(
                    ctx.HasRayTracingAdaptiveSamplingAtomic()))
            else:
                ver_too_low = ctx.IsGlGreaterEqual(3, 1)
                if not ver_too_low:
                    log.info("OpenGL version must be >= 3.1")
                else:
                    ext = "GL_ARB_texture_buffer_object_rgb32"
                    if not ctx.CheckExtension(ext):
                        log.info("OpenGL extension {} is missing".format(ext))
                    else:
                        log.info("OpenGL glBlitFramebuffer is missing")
        except Exception as e:
            log.exception(e)
Beispiel #2
0
    def update_dimension(self):
        """ Recreates the dimension catching any errors

        """
        try:
            self.create_dimension()
            self.init_dimension()
        except Exception as e:
            self.dimension = None
            log.exception(e)
Beispiel #3
0
    def update_item(self):
        """ Recreates the dimension catching any errors

        """
        if not self.context:
            return
        try:
            self.create_item(self.context)
        except Exception as e:
            log.exception(e)
Beispiel #4
0
    def init_widget(self):
        super().init_widget()
        d = self.declaration
        widget = self.widget
        widget.proxy = self

        # Create viewer
        graphics_driver = self.graphics_driver = OpenGl_GraphicDriver(
            self.display_connection)
        # 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

        # Setup viewer
        viewer = self.v3d_viewer = V3d_Viewer(graphics_driver)
        view = self.v3d_view = viewer.CreateView()
        self.v3d_view.SetWindow(window)
        ais_context = self.ais_context = AIS_InteractiveContext(viewer)
        drawer = self.prs3d_drawer = ais_context.DefaultDrawer()

        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
        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_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()
Beispiel #5
0
 def _fire_event(self, name, event):
     handled = False
     view = self.proxy.v3d_view
     for cb in self._callbacks.get(name, []):
         # Raise StopIteration to ignore the default handlers
         try:
             cb((view, event))
         except StopIteration:
             handled = True
         except Exception as e:
             log.exception(e)
     return handled
Beispiel #6
0
    async def main(self):
        """ Run any async deferred calls in the main ui loop.

        """
        while self.running:
            try:
                task = self.queue.get(block=False)
                await task
            except Empty:
                self.process_events()
                await asyncio.sleep(0.1)
            except Exception as e:
                if 'cannot enter context' in str(e):
                    # HACK: Something is jacked up
                    await asyncio.sleep(0.1)
                    continue
                log.exception(e)
Beispiel #7
0
    def _add_shape_to_display(self, occ_shape):
        """ Add an OccShape to the display

        """
        d = occ_shape.declaration
        if not d.display:
            return
        displayed_shapes = self._displayed_shapes
        display = self.ais_context.Display
        qt_app = self._qt_app
        occ_shape.displayed = True
        for s in occ_shape.walk_shapes():
            s.observe('ais_shape', self.on_ais_shape_changed)
            ais_shape = s.ais_shape
            if ais_shape is not None:
                try:
                    display(ais_shape, False)
                    s.displayed = True
                    displayed_shapes[s.shape] = s
                except RuntimeError as e:
                    log.exception(e)

                # Displaying can take a lot of time
                qt_app.processEvents()

        if isinstance(occ_shape, OccPart):
            for d in occ_shape.declaration.traverse():
                proxy = getattr(d, 'proxy', None)
                if proxy is None:
                    continue
                if isinstance(proxy, OccDimension):
                    self._add_dimension_to_display(proxy)
                elif isinstance(proxy, OccDisplayItem):
                    self._add_item_to_display(proxy)

        self._redisplay_timer.start()
Beispiel #8
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()