Salome HOME
Copyright update 2022
[modules/shaper.git] / src / PartSet / PartSet_TreeNodes.h
1 // Copyright (C) 2014-2022  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   // Returns color of the Item when it is active
42   virtual QColor activeItemColor() const;
43 };
44
45 /**
46 * \ingroup Modules
47 * Implementation of a node for object repesentation
48 */
49 class PartSet_ObjectNode : public PartSet_TreeNode
50 {
51 public:
52   PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
53     : PartSet_TreeNode(theParent), myObject(theObj) {}
54
55   static std::string typeId()
56   {
57     static std::string myType = "Object";
58     return myType;
59   }
60
61   virtual std::string type() const { return typeId(); }
62
63   /// Returns the node representation according to theRole.
64   virtual QVariant data(int theColumn, int theRole) const;
65
66   /// Returns properties flag of the item
67   virtual Qt::ItemFlags flags(int theColumn) const;
68
69   /// Returns object referenced by the node (can be null)
70   virtual ObjectPtr object() const { return myObject; }
71
72   /// Sets an object to the node
73   /// theObj a new object
74   void setObject(ObjectPtr theObj) { myObject = theObj; }
75
76   virtual VisibilityState visibilityState() const;
77
78   /// Updates sub-nodes of the node
79   virtual void update();
80
81   /// Process creation of objects.
82   /// \param theObjects a list of created objects
83   /// \return a list of nodes which corresponds to the created objects
84   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
85
86   /// Process deletion of objects.
87   /// \param theDoc a document where objects were deleted
88   /// \param theGroup a name of group where objects were deleted
89   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
90
91   /// Returns number of sub-objects of the current object
92   virtual int numberOfSubs() const;
93
94   virtual ObjectPtr subObject(int theId) const;
95
96   // Returns color of the Item when it is active
97   virtual QColor activeItemColor() const;
98
99 protected:
100   ObjectPtr myObject;
101 };
102
103 /**
104 * \ingroup Modules
105 * Implementation of aFolder node in data tree
106 */
107 class PartSet_FolderNode : public PartSet_TreeNode
108 {
109 public:
110   enum FolderType {
111     ParametersFolder,
112     ConstructionFolder,
113     PartsFolder,
114     ResultsFolder,
115     FieldsFolder,
116     GroupsFolder
117   };
118
119   PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
120
121   static std::string typeId()
122   {
123     static std::string myType = "Folder";
124     return myType;
125   }
126
127   virtual std::string type() const { return typeId(); }
128
129   /// Returns the node representation according to theRole.
130   virtual QVariant data(int theColumn, int theRole) const;
131
132   /// Returns properties flag of the item
133   virtual Qt::ItemFlags flags(int theColumn) const;
134
135   /// Updates sub-nodes of the node
136   virtual void update();
137
138   /// Process creation of objects.
139   /// \param theObjects a list of created objects
140   /// \return a list of nodes which corresponds to the created objects
141   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
142
143   /// Process deletion of objects.
144   /// \param theDoc a document where objects were deleted
145   /// \param theGroup a name of group where objects were deleted
146   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
147
148   QString name() const;
149
150   /// Returns a node which belongs to the given document and contains objects of the given group
151   /// \param theDoc a document
152   /// \param theGroup a name of objects group
153   /// \return a parent node if it is found
154   virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
155   {
156     if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
157       return this;
158     return 0;
159   }
160
161 private:
162   std::string groupName() const;
163
164   ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
165
166   FolderType myType;
167 };
168
169 /////////////////////////////////////////////////////////////////////
170 /**
171 * \ingroup Modules
172 * A base class for root folders
173 */
174 class PartSet_FeatureFolderNode : public PartSet_TreeNode
175 {
176 public:
177   PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
178
179   /// Process creation of objects.
180   /// \param theObjects a list of created objects
181   /// \return a list of nodes which corresponds to the created objects
182   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
183
184   /// Process deletion of objects.
185   /// \param theDoc a document where objects were deleted
186   /// \param theGroup a name of group where objects were deleted
187   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
188
189   /// Returns a node which belongs to the given document and contains objects of the given group
190   /// \param theDoc a document
191   /// \param theGroup a name of objects group
192   /// \return a parent node if it is found
193   virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
194
195 protected:
196   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
197
198   virtual int numberOfFolders() const { return 0; }
199 };
200
201
202 /////////////////////////////////////////////////////////////////////
203 /**
204 * \ingroup Modules
205 * Implementation of Root node in data tree
206 */
207 class PartSet_RootNode : public PartSet_FeatureFolderNode
208 {
209 public:
210   PartSet_RootNode();
211
212   static std::string typeId()
213   {
214     static std::string myType = "PartSetRoot";
215     return myType;
216   }
217
218   virtual std::string type() const { return typeId(); }
219
220   /// Updates sub-nodes of the node
221   virtual void update();
222
223   virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
224
225   /// Returns document object of the sub-tree.
226   virtual DocumentPtr document() const;
227
228   void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
229
230 protected:
231   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
232
233   virtual int numberOfFolders() const { return 3; }
234
235 private:
236   PartSet_FolderNode* myParamsFolder;
237   PartSet_FolderNode* myConstrFolder;
238   PartSet_FolderNode* myPartsFolder;
239
240   ModuleBase_IWorkshop* myWorkshop;
241 };
242
243 /////////////////////////////////////////////////////////////////////
244 /**
245 * \ingroup Modules
246 * Implementation of Root node of a Part document in data tree
247 */
248 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
249 {
250 public:
251   PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
252
253   static std::string typeId()
254   {
255     static std::string myType = "PartRoot";
256     return myType;
257   }
258
259   virtual std::string type() const { return typeId(); }
260
261   /// Returns object referenced by the node (can be null)
262   virtual ObjectPtr object() const { return myObject; }
263
264   /// Returns document object of the sub-tree.
265   virtual DocumentPtr document() const;
266
267   /// Updates sub-nodes of the node
268   virtual void update();
269
270   /// Returns the node representation according to theRole.
271   virtual QVariant data(int theColumn, int theRole) const;
272
273   /// Returns properties flag of the item
274   virtual Qt::ItemFlags flags(int theColumn) const;
275
276   /// Process creation of objects.
277   /// \param theObjects a list of created objects
278   /// \return a list of nodes which corresponds to the created objects
279   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
280
281   /// Process deletion of objects.
282   /// \param theDoc a document where objects were deleted
283   /// \param theGroup a name of group where objects were deleted
284   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
285
286 protected:
287   virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
288
289   virtual int numberOfFolders() const;
290
291   virtual void deleteChildren();
292
293 private:
294   PartSet_FolderNode* myParamsFolder;
295   PartSet_FolderNode* myConstrFolder;
296   PartSet_FolderNode* myResultsFolder;
297   PartSet_FolderNode* myFieldsFolder;
298   PartSet_FolderNode* myGroupsFolder;
299
300   ObjectPtr myObject;
301 };
302
303 /////////////////////////////////////////////////////////////////////
304 /**
305 * \ingroup Modules
306 * Implementation of a folder which corresponds to ModelAPI_Folder object
307 */
308 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
309 {
310 public:
311   PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
312     : PartSet_ObjectNode(theObj, theParent) {}
313
314   static std::string typeId()
315   {
316     static std::string myType = "ObjectFolder";
317     return myType;
318   }
319
320   virtual std::string type() const { return typeId(); }
321
322   /// Updates sub-nodes of the node
323   virtual void update();
324
325   /// Process creation of objects.
326   /// \param theObjects a list of created objects
327   /// \return a list of nodes which corresponds to the created objects
328   virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
329
330   /// Process deletion of objects.
331   /// \param theDoc a document where objects were deleted
332   /// \param theGroup a name of group where objects were deleted
333   virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
334
335   /// Returns the node representation according to theRole.
336   virtual QVariant data(int theColumn, int theRole) const;
337 };
338
339
340 /////////////////////////////////////////////////////////////////////
341 /**
342 * \ingroup Modules
343 * Implementation of a node for compsolid representation
344 */
345 class PartSet_StepNode : public PartSet_ObjectNode
346 {
347 public:
348   PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
349     PartSet_ObjectNode(theObj, theParent) {}
350
351   static std::string typeId()
352   {
353     static std::string myType = "FieldStep";
354     return myType;
355   }
356
357   virtual std::string type() const { return typeId(); }
358
359   /// Returns the node representation according to theRole.
360   virtual QVariant data(int theColumn, int theRole) const;
361
362   virtual VisibilityState visibilityState() const;
363 };
364
365 #endif