OSGWidget.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "StoreHandler.hpp"
  3. #include "OpenScadRenderer.hpp"
  4. #include "ThreeMFWriter.hpp"
  5. #include <QPoint>
  6. #include <QOpenGLWidget>
  7. #include <osg/ref_ptr>
  8. #include <osgViewer/GraphicsWindow>
  9. #include <osgViewer/CompositeViewer>
  10. namespace osgWidget {
  11. //! The subclass of osgViewer::CompositeViewer we use
  12. /*!
  13. * This subclassing allows us to remove the annoying automatic
  14. * setting of the CPU affinity to core 0 by osgViewer::ViewerBase,
  15. * osgViewer::CompositeViewer's base class.
  16. */
  17. class Viewer: public osgViewer::CompositeViewer {
  18. public:
  19. virtual void setupThreading();
  20. };
  21. }
  22. class OSGWidget : public QOpenGLWidget {
  23. Q_OBJECT
  24. public:
  25. OSGWidget(QWidget* parent = nullptr);
  26. virtual ~OSGWidget();
  27. protected:
  28. virtual void paintEvent( QPaintEvent* paintEvent );
  29. virtual void paintGL();
  30. virtual void resizeGL( int width, int height );
  31. virtual void keyPressEvent( QKeyEvent* event );
  32. virtual void keyReleaseEvent( QKeyEvent* event );
  33. virtual void mouseMoveEvent( QMouseEvent* event );
  34. virtual void mousePressEvent( QMouseEvent* event );
  35. virtual void mouseReleaseEvent( QMouseEvent* event );
  36. virtual void wheelEvent( QWheelEvent* event );
  37. virtual bool event( QEvent* event );
  38. private:
  39. virtual void onHome();
  40. virtual void onResize( int width, int height );
  41. osgGA::EventQueue* getEventQueue() const;
  42. osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> graphicsWindow_;
  43. osg::ref_ptr<osgWidget::Viewer> _viewer;
  44. osgViewer::View* _view;
  45. osg::ref_ptr<osg::Group> _root;
  46. osg::ref_ptr<osg::Node> _axesNode;
  47. QPoint selectionStart_;
  48. QPoint selectionEnd_;
  49. bool selectionActive_;
  50. bool selectionFinished_;
  51. StoreHandler* _storeHandler;
  52. OpenScadRenderer* _openScadRenderer;
  53. ThreeMFWriter* _threeMFWriter;
  54. };