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