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