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