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