ccDBRoot.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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_DB_ROOT_HEADER
  18. #define CC_DB_ROOT_HEADER
  19. //Qt
  20. #include "ccPointCloud.h"
  21. #include <QAbstractItemModel>
  22. #include <QPoint>
  23. #include <QTreeView>
  24. //qCC_db
  25. #include <ccHObject.h>
  26. //System
  27. #include <unordered_set>
  28. class QAction;
  29. class QStandardItemModel;
  30. class ccPropertiesTreeDelegate;
  31. class ccHObject;
  32. //! Precise statistics about current selection
  33. struct dbTreeSelectionInfo
  34. {
  35. size_t selCount = 0;
  36. size_t sfCount = 0;
  37. size_t colorCount = 0;
  38. size_t normalsCount = 0;
  39. size_t octreeCount = 0;
  40. size_t cloudCount = 0;
  41. size_t gridCound = 0;
  42. size_t groupCount = 0;
  43. size_t polylineCount = 0;
  44. size_t planeCount = 0;
  45. size_t meshCount = 0;
  46. size_t primitiveCount = 0;
  47. size_t imageCount = 0;
  48. size_t sensorCount = 0;
  49. size_t gblSensorCount = 0;
  50. size_t cameraSensorCount = 0;
  51. size_t kdTreeCount = 0;
  52. };
  53. //! Custom QTreeView widget (for advanced selection behavior)
  54. class ccCustomQTreeView : public QTreeView
  55. {
  56. Q_OBJECT
  57. public:
  58. //! Default constructor
  59. explicit ccCustomQTreeView(QWidget* parent) : QTreeView(parent) {}
  60. protected:
  61. //inherited from QTreeView
  62. QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex& index, const QEvent* event=nullptr) const override;
  63. };
  64. //! GUI database tree root
  65. class ccDBRoot : public QAbstractItemModel
  66. {
  67. Q_OBJECT
  68. public:
  69. //! Default constructor
  70. /** \param dbTreeWidget widget for DB tree display
  71. \param propertiesTreeWidget widget for selected entity's properties tree display
  72. \param parent widget QObject parent
  73. **/
  74. ccDBRoot(ccCustomQTreeView* dbTreeWidget, QTreeView* propertiesTreeWidget, QObject* parent = nullptr);
  75. //! Destructor
  76. ~ccDBRoot() override;
  77. //! Returns associated root object
  78. ccHObject* getRootEntity();
  79. //! Hides properties view
  80. void hidePropertiesView();
  81. //! Updates properties view
  82. void updatePropertiesView();
  83. //! Adds an element to the DB tree
  84. void addElement(ccHObject* object, bool autoExpand = true);
  85. //! Removes an element from the DB tree
  86. /** Automatically calls prepareDisplayForRefresh on the object.
  87. **/
  88. void removeElement(ccHObject* object);
  89. //! Removes several elements at once from the DB tree
  90. /** Faster than multiple calls to removeElement.
  91. Automatically calls prepareDisplayForRefresh on the objects.
  92. \warning The input container will be cleared.
  93. **/
  94. void removeElements(ccHObject::Container& objects);
  95. //! Finds an element in DB
  96. ccHObject* find(int uniqueID) const;
  97. //! Returns the number of selected entities in DB tree (optionally with a given type)
  98. int countSelectedEntities(CC_CLASS_ENUM filter = CC_TYPES::OBJECT);
  99. //! Returns selected entities in DB tree (optionally with a given type and additional information)
  100. size_t getSelectedEntities( ccHObject::Container& selectedEntities,
  101. CC_CLASS_ENUM filter = CC_TYPES::OBJECT,
  102. dbTreeSelectionInfo* info = nullptr);
  103. //! Expands tree at a given node
  104. void expandElement(ccHObject* object, bool state);
  105. //! Unselects a given entity
  106. void unselectEntity(ccHObject* obj);
  107. //! Unselects all entities
  108. void unselectAllEntities();
  109. //! Unloads all entities
  110. void unloadAll();
  111. //inherited from QAbstractItemModel
  112. QVariant data(const QModelIndex &index, int role) const override;
  113. QModelIndex index(int row, int column, const QModelIndex &parentIndex = QModelIndex()) const override;
  114. QModelIndex index(ccHObject* object);
  115. QModelIndex parent(const QModelIndex &index) const override;
  116. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  117. int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  118. Qt::ItemFlags flags(const QModelIndex &index) const override;
  119. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
  120. Qt::DropActions supportedDropActions() const override;
  121. bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
  122. QMap<int,QVariant> itemData(const QModelIndex& index) const override;
  123. Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
  124. void changeSelection(const QItemSelection & selected, const QItemSelection & deselected);
  125. void reflectObjectPropChange(ccHObject* obj);
  126. void redrawCCObject(ccHObject* object);
  127. void redrawCCObjectAndChildren(ccHObject* object);
  128. void updateCCObject(ccHObject* object);
  129. void deleteSelectedEntities();
  130. //! Selects a given entity
  131. /** If ctrl is pressed by the user at the same time,
  132. previous selection will be simply updated accordingly.
  133. \param obj entity to select
  134. \param forceAdditiveSelection whether to force additive selection (just as if CTRL key is pressed) or not
  135. **/
  136. void selectEntity(ccHObject* obj, bool forceAdditiveSelection = false);
  137. //! Selects multiple entities at once (shortcut to the other version)
  138. /** \param entIDs list of the IDs of the entities to select
  139. **/
  140. void selectEntities(std::unordered_set<int> entIDs);
  141. //! Selects multiple entities at once
  142. /** \param entities set of the entities to 'select'
  143. \param incremental whether to 'add' the input set to the selected entities set or to use it as replacement
  144. **/
  145. void selectEntities(const ccHObject::Container& entities, bool incremental = false);
  146. private:
  147. //! Entity property that can be toggled
  148. enum TOGGLE_PROPERTY { TG_ENABLE,
  149. TG_VISIBLE,
  150. TG_COLOR,
  151. TG_SF,
  152. TG_NORMAL,
  153. TG_MATERIAL,
  154. TG_3D_NAME };
  155. //! Toggles a given property (enable state, visibility, normal, color, SF, etc.) on selected entities
  156. void toggleSelectedEntitiesProperty(TOGGLE_PROPERTY prop);
  157. void showContextMenu(const QPoint&);
  158. void expandBranch();
  159. void collapseBranch();
  160. void gatherRecursiveInformation();
  161. void sortChildrenAZ();
  162. void sortChildrenZA();
  163. void sortChildrenType();
  164. void selectByTypeAndName();
  165. inline void toggleSelectedEntities() { toggleSelectedEntitiesProperty(TG_ENABLE); }
  166. inline void toggleSelectedEntitiesVisibility() { toggleSelectedEntitiesProperty(TG_VISIBLE); }
  167. inline void toggleSelectedEntitiesColor() { toggleSelectedEntitiesProperty(TG_COLOR); }
  168. inline void toggleSelectedEntitiesNormals() { toggleSelectedEntitiesProperty(TG_NORMAL); }
  169. inline void toggleSelectedEntitiesSF() { toggleSelectedEntitiesProperty(TG_SF); }
  170. inline void toggleSelectedEntitiesMat() { toggleSelectedEntitiesProperty(TG_MATERIAL); }
  171. inline void toggleSelectedEntities3DName() { toggleSelectedEntitiesProperty(TG_3D_NAME); }
  172. void addEmptyGroup();
  173. void alignCameraWithEntityDirect() { alignCameraWithEntity(false); }
  174. void alignCameraWithEntityIndirect() { alignCameraWithEntity(true); }
  175. void enableBubbleViewMode();
  176. void editLabelScalarValue();
  177. Q_SIGNALS:
  178. void selectionChanged();
  179. void dbIsEmpty();
  180. void dbIsNotEmptyAnymore();
  181. protected:
  182. //! Aligns the camera with the currently selected entity
  183. /** \param reverse whether to use the entity's normal (false) or its inverse (true)
  184. **/
  185. void alignCameraWithEntity(bool reverse);
  186. //! Shows properties view for a given element
  187. void showPropertiesView(ccHObject* obj);
  188. //! Entities sorting schemes
  189. enum SortRules { SORT_A2Z, SORT_Z2A, SORT_BY_TYPE };
  190. //! Sorts selected entities children
  191. void sortSelectedEntitiesChildren(SortRules rule);
  192. //! Expands or collapses hovered item
  193. void expandOrCollapseHoveredBranch(bool expand);
  194. //! Selects objects by type and/or name
  195. void selectChildrenByTypeAndName(CC_CLASS_ENUM type,
  196. bool typeIsExclusive = true,
  197. QString name = QString(),
  198. bool nameIsRegex = false);
  199. //! Associated DB root
  200. ccHObject* m_treeRoot;
  201. //! Associated widget for DB tree
  202. QTreeView* m_dbTreeWidget;
  203. //! Associated widget for selected entity's properties tree
  204. QTreeView* m_propertiesTreeWidget;
  205. //! Selected entity's properties data model
  206. QStandardItemModel* m_propertiesModel;
  207. //! Selected entity's properties delegate
  208. ccPropertiesTreeDelegate* m_ccPropDelegate;
  209. //! Context menu action: expand tree branch
  210. QAction* m_expandBranch;
  211. //! Context menu action: collapse tree branch
  212. QAction* m_collapseBranch;
  213. //! Context menu action: gather (recursive) information on selected entities
  214. QAction* m_gatherInformation;
  215. //! Context menu action: sort children in alphabetical order
  216. QAction* m_sortChildrenAZ;
  217. //! Context menu action: sort children in reverse alphabetical order
  218. QAction* m_sortChildrenZA;
  219. //! Context menu action: sort children by type
  220. QAction* m_sortChildrenType;
  221. //! Context menu action: select object by type and/or by name
  222. QAction* m_selectByTypeAndName;
  223. //! Context menu action: delete selected entities
  224. QAction* m_deleteSelectedEntities;
  225. //! Context menu action: enabled/disable selected entities
  226. QAction* m_toggleSelectedEntities;
  227. //! Context menu action: hide/show selected entities
  228. QAction* m_toggleSelectedEntitiesVisibility;
  229. //! Context menu action: hide/show selected entities color
  230. QAction* m_toggleSelectedEntitiesColor;
  231. //! Context menu action: hide/show selected entities normals
  232. QAction* m_toggleSelectedEntitiesNormals;
  233. //! Context menu action: hide/show selected entities materials/textures
  234. QAction* m_toggleSelectedEntitiesMat;
  235. //! Context menu action: hide/show selected entities SF
  236. QAction* m_toggleSelectedEntitiesSF;
  237. //! Context menu action: hide/show selected entities 3D name
  238. QAction* m_toggleSelectedEntities3DName;
  239. //! Context menu action: add empty group
  240. QAction* m_addEmptyGroup;
  241. //! Context menu action: use 3-points labels or planes to orient camera
  242. QAction* m_alignCameraWithEntity;
  243. //! Context menu action: reverse of m_alignCameraWithEntity
  244. QAction* m_alignCameraWithEntityReverse;
  245. //! Context menu action: enable bubble-view (on a sensor)
  246. QAction* m_enableBubbleViewMode;
  247. //! Context menu action: change current scalar value (via a 2D label)
  248. QAction* m_editLabelScalarValue;
  249. //! Last context menu pos
  250. QPoint m_contextMenuPos;
  251. };
  252. #endif