OSGWidget.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. void renderBaseMesh(const osg::ref_ptr<osg::Vec3Array> vertices, const osg::ref_ptr<osg::Vec3Array> normals);
  28. static void fixMaterialState(osg::ref_ptr<osg::Node> node);
  29. protected:
  30. virtual void paintEvent(QPaintEvent* paintEvent);
  31. virtual void paintGL();
  32. virtual void resizeGL(int width, int height);
  33. virtual void keyPressEvent(QKeyEvent* event);
  34. virtual void keyReleaseEvent(QKeyEvent* event);
  35. virtual void mouseMoveEvent(QMouseEvent* event);
  36. virtual void mousePressEvent(QMouseEvent* event);
  37. virtual void mouseReleaseEvent(QMouseEvent* event);
  38. virtual void wheelEvent(QWheelEvent* event);
  39. virtual bool event(QEvent* event);
  40. private:
  41. virtual void onHome();
  42. virtual void onResize(int width, int height);
  43. osgGA::EventQueue* getEventQueue() const;
  44. osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> graphicsWindow_;
  45. osg::ref_ptr<osgWidget::Viewer> _viewer;
  46. osgViewer::View* _view;
  47. osg::ref_ptr<osg::Group> _root;
  48. osg::ref_ptr<osg::Geode> _coordinateAxes;
  49. osg::ref_ptr<osg::Geode> _axesNode;
  50. QPoint selectionStart_;
  51. QPoint selectionEnd_;
  52. bool selectionActive_;
  53. bool selectionFinished_;
  54. StoreHandler* _storeHandler;
  55. OpenScadRenderer* _openScadRenderer;
  56. ThreeMFWriter* _threeMFWriter;
  57. };