1 #ifndef OcctWindow_H 2 #define OcctWindow_H 3 4 #include <Aspect_Window.hxx> 5 6 #include <Standard_WarningsDisable.hxx> 7 #include <QWidget> 8 #include <Standard_WarningsRestore.hxx> 9 10 class OcctWindow; 11 12 /* 13 OcctWindow class implements Aspect_Window interface using Qt API 14 as a platform-independent source of window geometry information. 15 A similar class should be used instead of platform-specific OCCT 16 classes (WNT_Window, Xw_Window) in any Qt 5 application using OCCT 17 3D visualization. 18 19 With Qt 5, the requirement for a Qt-based application to rely fully 20 on Qt public API and stop using platform-specific APIs looks mandatory. 21 An example of this is changed QWidget event sequence: when a widget is 22 first shown on the screen, a resize event is generated before the 23 underlying native window is resized correctly, however the QWidget instance 24 already holds correct size information at that moment. The OCCT classes 25 acting as a source of window geometry for V3d_View class (WNT_Window, Xw_Window) 26 are no longer compatible with changed Qt behavior because they rely on 27 platform-specific API that cannot return correct window geometry information 28 in some cases. A reasonable solution is to provide a Qt-based implementation 29 of Aspect_Window interface at application level. 30 */ 31 32 class OcctWindow : public Aspect_Window 33 { 34 public: 35 36 //! Constructor 37 OcctWindow( QWidget* theWidget, const Quantity_NameOfColor theBackColor = Quantity_NOC_MATRAGRAY ); 38 39 virtual void Destroy(); 40 41 //! Destructor ~OcctWindow()42 ~OcctWindow() 43 { 44 Destroy(); 45 } 46 47 //! Returns native Window handle 48 virtual Aspect_Drawable NativeHandle() const; 49 50 //! Returns parent of native Window handle. 51 virtual Aspect_Drawable NativeParentHandle() const; 52 53 //! Applies the resizing to the window <me> 54 virtual Aspect_TypeOfResize DoResize(); 55 56 //! Returns True if the window <me> is opened 57 //! and False if the window is closed. 58 virtual Standard_Boolean IsMapped() const; 59 60 //! Apply the mapping change to the window <me> 61 //! and returns TRUE if the window is mapped at screen. DoMapping()62 virtual Standard_Boolean DoMapping() const { return Standard_True; } 63 64 //! Opens the window <me>. 65 virtual void Map() const; 66 67 //! Closes the window <me>. 68 virtual void Unmap() const; 69 70 virtual void Position( Standard_Integer& theX1, Standard_Integer& theY1, 71 Standard_Integer& theX2, Standard_Integer& theY2 ) const; 72 73 //! Returns The Window RATIO equal to the physical 74 //! WIDTH/HEIGHT dimensions. 75 virtual Standard_Real Ratio() const; 76 77 virtual void Size( Standard_Integer& theWidth, Standard_Integer& theHeight ) const; 78 NativeFBConfig()79 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; } 80 81 DEFINE_STANDARD_RTTIEXT(OcctWindow,Aspect_Window) 82 83 protected: 84 Standard_Integer myXLeft; 85 Standard_Integer myYTop; 86 Standard_Integer myXRight; 87 Standard_Integer myYBottom; 88 QWidget* myWidget; 89 }; 90 91 92 #endif // OcctWindow_H