ProjectStore.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. // Include modules
  3. #include "lib3mf_implicit.hpp"
  4. #include "OptiTrackPoint.hpp"
  5. #include "EMFTrackPoint.hpp"
  6. #include "SteamVRTrackPoint.hpp"
  7. #include "ActionPoint.hpp"
  8. #include "TrackSystemSettingsStructs.hpp"
  9. #include "OpenScadRenderer.hpp"
  10. #include "enums.hpp"
  11. // Include dependencies
  12. #include <string>
  13. #include <nlohmann/json.hpp>
  14. #include <QThread>
  15. using json = nlohmann::json;
  16. class ProjectStore: public QObject {
  17. Q_OBJECT
  18. public:
  19. // Create an empty project
  20. ProjectStore(QObject* parent = nullptr);
  21. // Destructor
  22. ~ProjectStore();
  23. // Load a mesh
  24. void loadMesh(std::string meshFile);
  25. // Load a project
  26. bool loadProject(std::string projectFile);
  27. // Save the project to the loaded file
  28. bool saveProject();
  29. // Save the project to a new file
  30. bool saveProject(std::string projectFile);
  31. // Export the project
  32. bool exportProject(std::string path, ExportSettings settings);
  33. // Is currently a project opened
  34. bool isProjectOpen();
  35. // Close the current project
  36. void closeProject();
  37. // Is current project modified
  38. bool isModified();
  39. // Is a rendering in progress
  40. bool isRendering();
  41. // Set project modification status
  42. void projectModified();
  43. // UNIVERSAL
  44. // Get trackpoint
  45. TrackPoint* getTrackPointById(int id, ActiveTrackingSystem activeTrackingSystem);
  46. // Add trackpoint
  47. void addTrackPoint(osg::Vec3 point, osg::Vec3 normal, ActiveTrackingSystem activeTrackingSystem);
  48. // Count trackpoints
  49. int getCount(ActiveTrackingSystem activeTrackingSystem);
  50. // Remove trackpoint
  51. void removeTrackPoint(int id, ActiveTrackingSystem activeTrackingSystem);
  52. // NORMAL MODIFIER
  53. // Update normal modifier
  54. void updateNormalModifier(osg::Vec3 modifier);
  55. // Return normal modifier
  56. osg::Vec3 getNormalModifier();
  57. // Update normal rotation
  58. void updateNormalRotation(float normalRotation);
  59. // Return normal rotation
  60. float getNormalRotation();
  61. // Update compensation
  62. void updateCompensation(bool compensation);
  63. // Return compensation
  64. bool getCompensation();
  65. // Get the minimum required trackpoint count for a given tracking system
  66. int getMinimumRequiredPoints(ActiveTrackingSystem activeTrackingSystem);
  67. // OPTITRACK
  68. // Get all OptiTrack points
  69. std::vector<OptiTrackPoint*> getOptiTrackPoints();
  70. // Update actual OptiTrack settings
  71. void updateOptiTrackSettings(OptiTrackSettings optiTrackSettings);
  72. // Return OptiTrack settings
  73. OptiTrackSettings getOptiTrackSettings();
  74. // EMF TRACK
  75. // Get all EMFTrack points
  76. std::vector<EMFTrackPoint*> getEMFTrackPoints();
  77. // Update actual EMFTrack settings
  78. void updateEMFTrackSettings(EMFTrackSettings emfTrackSettings);
  79. // Return EMFTrack settings
  80. EMFTrackSettings getEMFTrackSettings();
  81. // STEAM VR TRACK
  82. // Get all SteamVRTrack points
  83. std::vector<SteamVRTrackPoint*> getSteamVRTrackPoints();
  84. // Update actual SteamVRTrack settings
  85. void updateSteamVRTrackSettings(SteamVRTrackSettings steamVrTrackSettings);
  86. // Return SteamVRTrack settings
  87. SteamVRTrackSettings getSteamVRTrackSettings();
  88. // ACTION POINTS
  89. // Get all Action points
  90. std::vector<ActionPoint*> getActionPoints();
  91. // Update actual Action point settings
  92. void updateActionPointSettings(ActionPointSettings actionPointSettings);
  93. // Return Action point settings
  94. ActionPointSettings getActionPointSettings();
  95. // Check if an identifier is already in use
  96. unsigned int actionPointIdentifierInUse(std::string candidate, int current);
  97. private slots:
  98. void renderThreadDone();
  99. private:
  100. bool _projectLoaded;
  101. bool _projectModified;
  102. Lib3MF::PWrapper _wrapper;
  103. Lib3MF::PModel _project;
  104. std::string _projectFile;
  105. std::vector<OptiTrackPoint*> _optiTrackPoints;
  106. std::vector<EMFTrackPoint*> _emfTrackPoints;
  107. std::vector<SteamVRTrackPoint*> _steamVrTrackPoints;
  108. std::vector<ActionPoint*> _actionPoints;
  109. OptiTrackSettings _optiTrackSettings = OptiTrackSettings {OPTITRACK_DEFAULT_LENGTH, OPTITRACK_DEFAULT_RADIUS};
  110. EMFTrackSettings _emfTrackSettings = EMFTrackSettings {EMFTRACK_DEFAULT_WIDTH, EMFTRACK_DEFAULT_HEIGHT, EMFTRACK_DEFAULT_DEPTH};
  111. SteamVRTrackSettings _steamVrTrackSettings = SteamVRTrackSettings {STEAMVR_DEFAULT_LENGTH};
  112. ActionPointSettings _actionPointSettings = ActionPointSettings {ACTIONPOINT_DEFAULT_IDENFIFIER};
  113. osg::Vec3 _normalModifier = osg::Vec3(0.0f, 0.0f, 0.0f);
  114. float _normalRotation = 0.0f;
  115. bool _compensation = true;
  116. QThread* _optiTrackRenderThread;
  117. QThread* _emfTrackRenderThread;
  118. QThread* _steamVrTrackRenderThread;
  119. bool _exportRunning = false;
  120. ExportSettings _currentExportSettings;
  121. int _wantedExports;
  122. int _doneExports;
  123. std::string _exportPath;
  124. void load3mfLib();
  125. void reset();
  126. void render3MFMesh();
  127. void updateMetaData();
  128. void loadMetaData();
  129. static void renderOptiTrackInThread(std::vector<OptiTrackPoint*> optiTrackPoints);
  130. static void renderEMFTrackInThread(std::vector<EMFTrackPoint*> emfTrackPoints);
  131. static void renderSteamVRTrackInThread(std::vector<SteamVRTrackPoint*> steamVrTrackPoints);
  132. std::vector<float> osgVecToStdVec(osg::Vec3f input);
  133. osg::Vec3f stdVecToOsgVec(std::vector<float> input);
  134. };