def __init__(self, parent=None): if not has_pyside: raise ModuleNotFoundError("PySide was not found and is required.") super(View, self).__init__(parent) # Qt settings self.setBackgroundRole(QPalette.NoRole) self.setMouseTracking(True) # Values for mouse movement self._x0, self._y0 = 0., 0. # Some default settings self._white = Quantity_Color(Quantity_NOC_WHITE) self._black = Quantity_Color(Quantity_NOC_BLACK) # Get window handle self.window_handle = self.winId() # Display connection self.display_connect = Aspect_DisplayConnection() # Graphics driver self._graphics_driver = OpenGl_GraphicDriver(self.display_connect) # Create viewer and view self.my_viewer = V3d_Viewer(self._graphics_driver) self.my_view = self.my_viewer.CreateView() self.wind = Xw_Window(self.display_connect, self.window_handle) self.my_view.SetWindow(self.wind) # Map window if not self.wind.IsMapped(): self.wind.Map() # AIS interactive context self.my_context = AIS_InteractiveContext(self.my_viewer) self.my_context.SetAutomaticHilight(True) self.my_viewer.SetDefaultLights() self.my_viewer.SetLightOn() self.my_view.SetBackgroundColor(Quantity_TOC_RGB, 0.5, 0.5, 0.5) self.my_context.SetDisplayMode(AIS_Shaded, True) self.my_drawer = self.my_context.DefaultDrawer() self.my_drawer.SetFaceBoundaryDraw(True) self.my_view.TriedronDisplay(Aspect_TOTP_RIGHT_LOWER, self._black, 0.08) self.my_view.SetProj(V3d_TypeOfOrientation.V3d_XposYposZpos) # Mesh display mode self._mesh_mode = 1
def _init(self): """ Initialize the viewer. """ # Icon ico = wx.Icon(_icon, wx.BITMAP_TYPE_PNG) self.SetIcon(ico) # Store some defaults self._x0, self._y0 = 0., 0. self._black = Quantity_Color(Quantity_NOC_BLACK) # Display connection self.display_connect = Aspect_DisplayConnection() # Graphics driver graphics_driver = OpenGl_GraphicDriver(self.display_connect) # Create viewer and view self._my_viewer = V3d_Viewer(graphics_driver) self._my_view = self._my_viewer.CreateView() # AIS interactive context self._my_context = AIS_InteractiveContext(self._my_viewer) # Initial settings self._my_viewer.SetDefaultLights() self._my_viewer.SetLightOn() self._my_view.SetBackgroundColor(Quantity_TOC_RGB, 0.5, 0.5, 0.5) self._my_context.SetDisplayMode(AIS_Shaded, True) self._my_drawer = self._my_context.DefaultDrawer() self._my_drawer.SetFaceBoundaryDraw(True) self._my_view.TriedronDisplay(Aspect_TOTP_LEFT_LOWER, self._black, 0.08) self._my_view.SetProj(V3d_TypeOfOrientation.V3d_XposYposZpos) # Events self.Bind(wx.EVT_PAINT, self._evt_paint) self.Bind(wx.EVT_SIZE, self._evt_size) self.Bind(wx.EVT_CHAR, self._evt_char) self.Bind(wx.EVT_CLOSE, self._evt_close) self.Bind(wx.EVT_MOUSE_EVENTS, self._evt_mouse_events) self.Bind(wx.EVT_MOUSEWHEEL, self._evt_mousewheel)
# This library 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 this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import unittest from OCCT.Aspect import Aspect_DisplayConnection from OCCT.OpenGl import OpenGl_GraphicDriver from OCCT.V3d import V3d_Viewer try: display_connection = Aspect_DisplayConnection() except RuntimeError: display_connection = None @unittest.skipIf(display_connection is None, "No display connection") class Test_V3d_View(unittest.TestCase): """ Test for V3d_View class. """ @classmethod def setUpClass(cls): """ Set up with a V3d_View. """ driver = cls._driver = OpenGl_GraphicDriver(display_connection)
def __init__(self, parent=None): super(QOpenCascadeWidget, self).__init__(parent) # Qt settings self.setBackgroundRole(QPalette.NoRole) self.setMouseTracking(True) # Values for mouse movement self._x0, self._y0 = 0., 0. # Some default settings self._white = Quantity_Color(Quantity_NOC_WHITE) self._black = Quantity_Color(Quantity_NOC_BLACK) # Display connection self.display_connect = Aspect_DisplayConnection() # Graphics driver self._graphics_driver = OpenGl_GraphicDriver(self.display_connect) # Create viewer and view self.my_viewer = V3d_Viewer(self._graphics_driver) self.my_view = self.my_viewer.CreateView() hwnd = self.winId() if sys.platform.startswith('win'): import ctypes from OCCT.WNT import WNT_Window ctypes.pythonapi.PyCapsule_New.restype = ctypes.py_object ctypes.pythonapi.PyCapsule_New.argtypes = [ ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p ] hwnd = ctypes.pythonapi.PyCapsule_New(hwnd, None, None) window = WNT_Window(hwnd) elif sys.platform.startswith('darwin'): from OCCT.Cocoa import Cocoa_Window window = Cocoa_Window(hwnd) elif sys.platform.startswith('linux'): from OCCT.Xw import Xw_Window window = Xw_Window(self.display_connection, hwnd) else: raise NotImplementedError( 'Support platform not found for visualization.') self.wind = window self.my_view.SetWindow(self.wind) # Map window if not self.wind.IsMapped(): self.wind.Map() # AIS interactive context self.my_context = AIS_InteractiveContext(self.my_viewer) self.my_context.SetAutomaticHilight(True) self.my_viewer.SetDefaultLights() self.my_viewer.SetLightOn() self.my_view.SetBackgroundColor(Quantity_TOC_RGB, 0.5, 0.5, 0.5) self.my_context.SetDisplayMode(AIS_Shaded, True) self.my_drawer = self.my_context.DefaultDrawer() self.my_drawer.SetFaceBoundaryDraw(True) self.my_view.TriedronDisplay(Aspect_TOTP_RIGHT_LOWER, self._black, 0.08) self.my_view.SetProj(V3d_TypeOfOrientation.V3d_XposYposZpos) # Mesh display mode self._mesh_mode = 1
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()
def setUpClass(cls): """ Set up graphic driver. """ aspect_display_connection = Aspect_DisplayConnection() cls._graphic_driver = OpenGl_GraphicDriver(aspect_display_connection)