Salome HOME
Issue #3180: Visual separation for features
[modules/shaper.git] / src / PartSet / PartSet_TreeNodes.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef PartSet_TreeNodes_H
21 #define PartSet_TreeNodes_H
22
23 #include "PartSet.h"
24
25 #include <ModuleBase_ITreeNode.h>
26 #include <ModelAPI_Feature.h>
27
28
29 /**
30 * \ingroup Modules
31 * Implementation of base node for the module data tree
32 */
33 class PartSet_TreeNode : public ModuleBase_ITreeNode
34 {
35 public:
36   PartSet_TreeNode(ModuleBase_ITreeNode* theParent = 0) : ModuleBase_ITreeNode(theParent) {}
37
38   /// Returns the node representation according to theRole.
39   virtual QVariant data(int theColumn, int theRole) const;
40 };
41
42 /**
43 * \ingroup Modules
44 * Implementation of a node for object repesentation
45 */
46 class PartSet_ObjectNode : public PartSet_TreeNode
47 {
48 public:
49   PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
50     : PartSet_TreeNode(theParent), myObject(theObj) {}
51
52   static std::string typeId()
53   {
54     static std::string myType = "Object";
55     return myType;
56   }
57
58   virtual std::string type() const { return typeId(); }
59
60   /// Returns the node representation according to theRole.
61   virtual QVariant data(int theColumn, int theRole) const;
62
63   /// Returns properties flag of the item
64   virtual Qt::ItemFlags flags(int theColumn) const;
65
66   /// Returns object referenced by the node (can be null)
67   virtual ObjectPtr object() const { return myObject; }
68
69   /// Sets an object to the node
70   /// theObj a new object
71   void setObject(ObjectPtr theObj) { myObject = theObj; }
72
73   virtual VisibilityState visibilityState() const;
74
75   /// Updates sub-nodes of the node
76   virtual void update();
77
78   /// Process creation of objects.
79   /// \param theObjects a list of created objects
80   /// \return a list of nodes which corresponds to the created objects
81   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
82
83   /// Process deletion of objects.
84   /// \param theDoc a document where objects were deleted
85   /// \param theGroup a name of group where objects were deleted
86   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
87
88   /// Returns number of sub-objects of the current object
89   virtual int numberOfSubs() const;
90
91   virtual ObjectPtr subObject(int theId) const;
92
93 protected:
94   ObjectPtr myObject;
95 };
96
97 /**
98 * \ingroup Modules
99 * Implementation of aFolder node in data tree
100 */
101 class PartSet_FolderNode : public PartSet_TreeNode
102 {
103 public:
104   enum FolderType {
105     ParametersFolder,
106     ConstructionFolder,
107     PartsFolder,
108     ResultsFolder,
109     FieldsFolder,
110     GroupsFolder
111   };
112
113   PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
114
115   static std::string typeId()
116   {
117     static std::string myType = "Folder";
118     return myType;
119   }
120
121   virtual std::string type() const { return typeId(); }
122
123   /// Returns the node representation according to theRole.
124   virtual QVariant data(int theColumn, int theRole) const;
125
126   /// Returns properties flag of the item
127   virtual Qt::ItemFlags flags(int theColumn) const;
128
129   /// Updates sub-nodes of the node
130   virtual void update();
131
132   /// Process creation of objects.
133   /// \param theObjects a list of created objects
134   /// \return a list of nodes which corresponds to the created objects
135   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
136
137   /// Process deletion of objects.
138   /// \param theDoc a document where objects were deleted
139   /// \param theGroup a name of group where objects were deleted
140   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
141
142   QString name() const;
143
144   /// Returns a node which belongs to the given document and contains objects of the given group
145   /// \param theDoc a document
146   /// \param theGroup a name of objects group
147   /// \return a parent node if it is found
148   virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
149   {
150     if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
151       return this;
152     return 0;
153   }
154
155 private:
156   std::string groupName() const;
157
158   ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
159
160   FolderType myType;
161 };
162
163 /////////////////////////////////////////////////////////////////////
164 /**
165 * \ingroup Modules
166 * A base class for root folders
167 */
168 class PartSet_FeatureFolderNode : public PartSet_TreeNode
169 {
170 public:
171   PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
172
173   /// Process creation of objects.
174   /// \param theObjects a list of created objects
175   /// \return a list of nodes which corresponds to the created objects
176   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
177
178   /// Process deletion of objects.
179   /// \param theDoc a document where objects were deleted
180   /// \param theGroup a name of group where objects were deleted
181   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
182
183   /// Returns a node which belongs to the given document and contains objects of the given group
184   /// \param theDoc a document
185   /// \param theGroup a name of objects group
186   /// \return a parent node if it is found
187   virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
188
189 protected:
190   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
191
192   virtual int numberOfFolders() const { return 0; }
193 };
194
195
196 /////////////////////////////////////////////////////////////////////
197 /**
198 * \ingroup Modules
199 * Implementation of Root node in data tree
200 */
201 class PartSet_RootNode : public PartSet_FeatureFolderNode
202 {
203 public:
204   PartSet_RootNode();
205
206   static std::string typeId()
207   {
208     static std::string myType = "PartSetRoot";
209     return myType;
210   }
211
212   virtual std::string type() const { return typeId(); }
213
214   /// Updates sub-nodes of the node
215   virtual void update();
216
217   virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
218
219   /// Returns document object of the sub-tree.
220   virtual DocumentPtr document() const;
221
222   void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
223
224 protected:
225   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
226
227   virtual int numberOfFolders() const { return 3; }
228
229 private:
230   PartSet_FolderNode* myParamsFolder;
231   PartSet_FolderNode* myConstrFolder;
232   PartSet_FolderNode* myPartsFolder;
233
234   ModuleBase_IWorkshop* myWorkshop;
235 };
236
237 /////////////////////////////////////////////////////////////////////
238 /**
239 * \ingroup Modules
240 * Implementation of Root node of a Part document in data tree
241 */
242 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
243 {
244 public:
245   PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
246
247   static std::string typeId()
248   {
249     static std::string myType = "PartRoot";
250     return myType;
251   }
252
253   virtual std::string type() const { return typeId(); }
254
255   /// Returns object referenced by the node (can be null)
256   virtual ObjectPtr object() const { return myObject; }
257
258   /// Returns document object of the sub-tree.
259   virtual DocumentPtr document() const;
260
261   /// Updates sub-nodes of the node
262   virtual void update();
263
264   /// Returns the node representation according to theRole.
265   virtual QVariant data(int theColumn, int theRole) const;
266
267   /// Returns properties flag of the item
268   virtual Qt::ItemFlags flags(int theColumn) const;
269
270   /// Process creation of objects.
271   /// \param theObjects a list of created objects
272   /// \return a list of nodes which corresponds to the created objects
273   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
274
275   /// Process deletion of objects.
276   /// \param theDoc a document where objects were deleted
277   /// \param theGroup a name of group where objects were deleted
278   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
279
280 protected:
281   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
282
283   virtual int numberOfFolders() const;
284
285   virtual void deleteChildren();
286
287 private:
288   PartSet_FolderNode* myParamsFolder;
289   PartSet_FolderNode* myConstrFolder;
290   PartSet_FolderNode* myResultsFolder;
291   PartSet_FolderNode* myFieldsFolder;
292   PartSet_FolderNode* myGroupsFolder;
293
294   ObjectPtr myObject;
295 };
296
297 /////////////////////////////////////////////////////////////////////
298 /**
299 * \ingroup Modules
300 * Implementation of a folder which corresponds to ModelAPI_Folder object
301 */
302 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
303 {
304 public:
305   PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
306     : PartSet_ObjectNode(theObj, theParent) {}
307
308   static std::string typeId()
309   {
310     static std::string myType = "ObjectFolder";
311     return myType;
312   }
313
314   virtual std::string type() const { return typeId(); }
315
316   /// Updates sub-nodes of the node
317   virtual void update();
318
319   /// Process creation of objects.
320   /// \param theObjects a list of created objects
321   /// \return a list of nodes which corresponds to the created objects
322   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
323
324   /// Process deletion of objects.
325   /// \param theDoc a document where objects were deleted
326   /// \param theGroup a name of group where objects were deleted
327   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
328
329   /// Returns the node representation according to theRole.
330   virtual QVariant data(int theColumn, int theRole) const;
331 };
332
333
334 /////////////////////////////////////////////////////////////////////
335 /**
336 * \ingroup Modules
337 * Implementation of a node for compsolid representation
338 */
339 class PartSet_StepNode : public PartSet_ObjectNode
340 {
341 public:
342   PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
343     PartSet_ObjectNode(theObj, theParent) {}
344
345   static std::string typeId()
346   {
347     static std::string myType = "FieldStep";
348     return myType;
349   }
350
351   virtual std::string type() const { return typeId(); }
352
353   /// Returns the node representation according to theRole.
354   virtual QVariant data(int theColumn, int theRole) const;
355
356   virtual VisibilityState visibilityState() const;
357 };
358
359 #endif