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 PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
51 : PartSet_TreeNode(theParent), myObject(theObj) {}
53 static std::string typeId()
55 static std::string myType = "Object";
59 virtual std::string type() const { return typeId(); }
61 /// Returns the node representation according to theRole.
62 virtual QVariant data(int theColumn, int theRole) const;
64 /// Returns properties flag of the item
65 virtual Qt::ItemFlags flags(int theColumn) const;
67 /// Returns object referenced by the node (can be null)
68 virtual ObjectPtr object() const { return myObject; }
70 /// Updates sub-nodes of the node
71 virtual void update() {}
73 virtual VisibilityState visibilityState() const;
81 * Implementation of aFolder node in data tree
83 class PartSet_FolderNode : public PartSet_TreeNode
95 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
97 static std::string typeId()
99 static std::string myType = "Folder";
103 virtual std::string type() const { return typeId(); }
105 /// Returns the node representation according to theRole.
106 virtual QVariant data(int theColumn, int theRole) const;
108 /// Returns properties flag of the item
109 virtual Qt::ItemFlags flags(int theColumn) const;
111 /// Updates sub-nodes of the node
112 virtual void update();
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);
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);
124 QString name() const;
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)
132 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
138 std::string groupName() const;
143 /////////////////////////////////////////////////////////////////////
146 * A base class for root folders
148 class PartSet_FeatureFolderNode : public PartSet_TreeNode
151 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
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);
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);
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);
170 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
172 virtual int numberOfFolders() const { return 0; }
176 /////////////////////////////////////////////////////////////////////
179 * Implementation of Root node in data tree
181 class PartSet_RootNode : public PartSet_FeatureFolderNode
186 static std::string typeId()
188 static std::string myType = "PartSetRoot";
192 virtual std::string type() const { return typeId(); }
194 /// Updates sub-nodes of the node
195 virtual void update();
197 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
199 /// Returns document object of the sub-tree.
200 virtual DocumentPtr document() const;
202 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
205 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
207 virtual int numberOfFolders() const { return 3; }
210 PartSet_FolderNode* myParamsFolder;
211 PartSet_FolderNode* myConstrFolder;
212 PartSet_FolderNode* myPartsFolder;
214 ModuleBase_IWorkshop* myWorkshop;
217 /////////////////////////////////////////////////////////////////////
220 * Implementation of Root node of a Part document in data tree
222 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
225 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
227 static std::string typeId()
229 static std::string myType = "PartRoot";
233 virtual std::string type() const { return typeId(); }
235 /// Returns object referenced by the node (can be null)
236 virtual ObjectPtr object() const { return myObject; }
238 /// Returns document object of the sub-tree.
239 virtual DocumentPtr document() const;
241 /// Updates sub-nodes of the node
242 virtual void update();
244 /// Returns the node representation according to theRole.
245 virtual QVariant data(int theColumn, int theRole) const;
247 /// Returns properties flag of the item
248 virtual Qt::ItemFlags flags(int theColumn) const;
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);
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);
261 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
263 virtual int numberOfFolders() const;
265 virtual void deleteChildren();
268 PartSet_FolderNode* myParamsFolder;
269 PartSet_FolderNode* myConstrFolder;
270 PartSet_FolderNode* myResultsFolder;
271 PartSet_FolderNode* myFieldsFolder;
272 PartSet_FolderNode* myGroupsFolder;
277 /////////////////////////////////////////////////////////////////////
280 * Implementation of a folder which corresponds to ModelAPI_Folder object
282 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
285 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
286 : PartSet_ObjectNode(theObj, theParent) {}
288 static std::string typeId()
290 static std::string myType = "ObjectFolder";
294 virtual std::string type() const { return typeId(); }
296 /// Updates sub-nodes of the node
297 virtual void update();
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);
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);
310 FeaturePtr getFeature(const std::string& theId) const;
312 void getFirstAndLastIndex(int& theFirst, int& theLast) const;