OSGWidget.hpp 1.9 KB

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