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