1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef PartSet_TreeNodes_H
22 #define PartSet_TreeNodes_H
26 #include <ModuleBase_ITreeNode.h>
27 #include <ModelAPI_Feature.h>
32 * Implementation of base node for the module data tree
34 class PartSet_TreeNode : public ModuleBase_ITreeNode
37 PartSet_TreeNode(ModuleBase_ITreeNode* theParent = 0) : ModuleBase_ITreeNode(theParent) {}
39 /// Returns the node representation according to theRole.
40 virtual QVariant data(int theColumn, int theRole) const;
45 * Implementation of a node for object repesentation
47 class PartSet_ObjectNode : public PartSet_TreeNode
50 enum VisibilityState {
57 PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
58 : PartSet_TreeNode(theParent), myObject(theObj) {}
60 static std::string typeId()
62 static std::string myType = "Object";
66 virtual std::string type() const { return typeId(); }
68 /// Returns the node representation according to theRole.
69 virtual QVariant data(int theColumn, int theRole) const;
71 /// Returns properties flag of the item
72 virtual Qt::ItemFlags flags(int theColumn) const;
74 /// Returns object referenced by the node (can be null)
75 virtual ObjectPtr object() const { return myObject; }
77 /// Updates sub-nodes of the node
78 virtual void update() {}
80 VisibilityState getVisibilityState() const;
88 * Implementation of aFolder node in data tree
90 class PartSet_FolderNode : public PartSet_TreeNode
102 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
104 static std::string typeId()
106 static std::string myType = "Folder";
110 virtual std::string type() const { return typeId(); }
112 /// Returns the node representation according to theRole.
113 virtual QVariant data(int theColumn, int theRole) const;
115 /// Returns properties flag of the item
116 virtual Qt::ItemFlags flags(int theColumn) const;
118 /// Updates sub-nodes of the node
119 virtual void update();
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);
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);
131 QString name() const;
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)
139 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
145 std::string groupName() const;
150 /////////////////////////////////////////////////////////////////////
153 * A base class for root folders
155 class PartSet_FeatureFolderNode : public PartSet_TreeNode
158 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
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);
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);
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);
177 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
179 virtual int numberOfFolders() const { return 0; }
183 /////////////////////////////////////////////////////////////////////
186 * Implementation of Root node in data tree
188 class PartSet_RootNode : public PartSet_FeatureFolderNode
193 static std::string typeId()
195 static std::string myType = "PartSetRoot";
199 virtual std::string type() const { return typeId(); }
201 /// Updates sub-nodes of the node
202 virtual void update();
204 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
206 /// Returns document object of the sub-tree.
207 virtual DocumentPtr document() const;
209 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
212 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
214 virtual int numberOfFolders() const { return 3; }
217 PartSet_FolderNode* myParamsFolder;
218 PartSet_FolderNode* myConstrFolder;
219 PartSet_FolderNode* myPartsFolder;
221 ModuleBase_IWorkshop* myWorkshop;
224 /////////////////////////////////////////////////////////////////////
227 * Implementation of Root node of a Part document in data tree
229 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
232 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
234 static std::string typeId()
236 static std::string myType = "PartRoot";
240 virtual std::string type() const { return typeId(); }
242 /// Returns object referenced by the node (can be null)
243 virtual ObjectPtr object() const { return myObject; }
245 /// Returns document object of the sub-tree.
246 virtual DocumentPtr document() const;
248 /// Updates sub-nodes of the node
249 virtual void update();
251 /// Returns the node representation according to theRole.
252 virtual QVariant data(int theColumn, int theRole) const;
254 /// Returns properties flag of the item
255 virtual Qt::ItemFlags flags(int theColumn) const;
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);
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);
268 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
270 virtual int numberOfFolders() const;
272 virtual void deleteChildren();
275 PartSet_FolderNode* myParamsFolder;
276 PartSet_FolderNode* myConstrFolder;
277 PartSet_FolderNode* myResultsFolder;
278 PartSet_FolderNode* myFieldsFolder;
279 PartSet_FolderNode* myGroupsFolder;
284 /////////////////////////////////////////////////////////////////////
287 * Implementation of a folder which corresponds to ModelAPI_Folder object
289 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
292 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
293 : PartSet_ObjectNode(theObj, theParent) {}
295 static std::string typeId()
297 static std::string myType = "ObjectFolder";
301 virtual std::string type() const { return typeId(); }
303 /// Updates sub-nodes of the node
304 virtual void update();
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);
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);
317 FeaturePtr getFeature(const std::string& theId) const;
319 void getFirstAndLastIndex(int& theFirst, int& theLast) const;