ccGraphicalTransformationTool.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_GRAPHICAL_TRANSFORMATION_TOOL_HEADER
  18. #define CC_GRAPHICAL_TRANSFORMATION_TOOL_HEADER
  19. //Local
  20. #include <ccOverlayDialog.h>
  21. #include <ui_graphicalTransformationDlg.h>
  22. //qCC_db
  23. #include <ccHObject.h>
  24. class ccGLWindowInterface;
  25. //! Dialog + mechanism for graphical transformation of entities
  26. /** Mouse driven rotation and translation of selected entities at screen.
  27. **/
  28. class ccGraphicalTransformationTool : public ccOverlayDialog, public Ui::GraphicalTransformationDlg
  29. {
  30. Q_OBJECT
  31. public:
  32. //! Default constructor
  33. explicit ccGraphicalTransformationTool(QWidget* parent);
  34. //! Default destructor
  35. virtual ~ccGraphicalTransformationTool();
  36. //inherited from ccOverlayDialog
  37. virtual bool linkWith(ccGLWindowInterface* win) override;
  38. virtual bool start() override;
  39. virtual void stop(bool state) override;
  40. //! unselect all advanced mode references
  41. void clearAdvModeEntities();
  42. //! Adds an entity to the 'selected' entities set
  43. /** Only the 'selected' entities are moved.
  44. \return success, if the entity is eligible for graphical transformation
  45. **/
  46. bool addEntity(ccHObject* anObject);
  47. //! Returns the number of valid entities (see addEntity)
  48. unsigned getNumberOfValidEntities() const;
  49. //! Returns the 'to be transformed' entities set (see addEntity)
  50. const ccHObject& getValidEntities() const { return m_toTransform; }
  51. //! Sets the rotation center
  52. void setRotationCenter(CCVector3d& center);
  53. //! Returns the transform for translating along an arbitrary vector
  54. ccGLMatrixd arbitraryVectorTranslation(const CCVector3& vec);
  55. //! Returns the transform for rotation around an arbitrary vector
  56. ccGLMatrixd arbitraryVectorRotation(double angle, const CCVector3d&);
  57. protected:
  58. //! rotComboBox enum
  59. enum rotComboBoxItems { XYZ, X, Y, Z, NONE };
  60. //! Applies transformation to selected entities
  61. void apply();
  62. //! Resets transformation
  63. void reset();
  64. //! Cancels (no transformation is applied)
  65. void cancel();
  66. //! Pauses the transformation mode
  67. void pause(bool);
  68. //! Togggles the visibility of the advanced mode ui
  69. void advModeToggle(bool state);
  70. //! Updates the transform for advanced mode rotation when translate ref changed
  71. void advTranslateRefUpdate(int index);
  72. //! Updates the transform for advanced mode rotation when rotate ref changed
  73. void advRotateRefUpdate(int index);
  74. void advRotateComboBoxUpdate(int index);
  75. //! Updates the axis center of rotation to the ref object in adv rotate/translate mode
  76. void advRefAxisRadioToggled(bool state);
  77. //! Enables/disables incremental translation field in accordance with the state of tx/ty/tz checkboxes
  78. void incrementalTranslationToggle();
  79. //! Enables/disables incremental rotation field in accordance with the state of the rotComboBox
  80. void incrementalRotationToggle(const rotComboBoxItems & selectedRotationItem);
  81. //! Updates the axis center of rotation to the object center in adv rotate/translate mode
  82. void advObjectAxisRadioToggled(bool state);
  83. //! Updates the top center display message according to the mode
  84. void updateDisplayMessage();
  85. //! Applies translation (graphically) to selected entities
  86. void glTranslate(const CCVector3d&);
  87. //! Applies rotation (graphically) to selected entities
  88. void glRotate(const ccGLMatrixd&);
  89. //! Applies rotation and translation factors set on incremental Spin boxes to selected entities
  90. void incrementalTransform();
  91. //! To capture overridden shortcuts (pause button, etc.)
  92. void onShortcutTriggered(int);
  93. //! Clear all variables and 'unlink' dialog
  94. void clear();
  95. //! Updates all selected entities GL transformation matrices
  96. void updateAllGLTransformations();
  97. //! Sets Advanced translate/rotation mode reference items
  98. void populateAdvModeItems();
  99. //! Sets the translation transform used in advanced translate/rotate mode
  100. bool setAdvTranslationTransform(ccHObject* translateRef);
  101. //! Sets the rotation transform used in advanced translate/rotate mode
  102. bool setAdvRotationAxis(ccHObject* rotateRef, rotComboBoxItems selectedAxis);
  103. //! Check if the entitry is in m_toTransform
  104. bool entityInTransformList(ccHObject* entity);
  105. //! Flag for advanced mode
  106. bool m_advMode;
  107. //! Flag if the rotation reference object is in m_toTransform
  108. bool m_advRotateRefIsChild;
  109. //! Flag if the translate reference object is in m_toTransform
  110. bool m_advTranslateRefIsChild;
  111. //! List of entities to be transformed
  112. ccHObject m_toTransform;
  113. //! Current advanced translate mode ref object
  114. ccHObject* m_advTranslateRef = nullptr;
  115. //! Current advanced rotate mode ref object
  116. ccHObject* m_advRotateRef = nullptr;
  117. //! Current rotation
  118. ccGLMatrixd m_rotation;
  119. //! Current translation
  120. CCVector3d m_translation;
  121. //! Current position
  122. ccGLMatrixd m_position;
  123. //! Transform used in advanced translate/rotate mode
  124. ccGLMatrixd m_advTranslationTransform;
  125. //! Current rotation axis vector for adv translate/rotate mode (not neccesarily rotation center)
  126. CCVector3d m_advRotationAxis;
  127. //! Current reference object for rotation center point
  128. CCVector3d m_advRotationRefObjCenter;
  129. //! Rotation center
  130. /** The rotation center is actually the center of gravity of the selected 'entities'
  131. **/
  132. CCVector3d m_rotationCenter;
  133. //! Objects found in the dbtree for adv transate/rotate
  134. ccHObject::Container m_advancedModeObjectList;
  135. };
  136. #endif //CC_GRAPHICAL_TRANSFORMATION_TOOL_HEADER