1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef PartSet_TreeNodes_H
21 #define PartSet_TreeNodes_H
25 #include <ModuleBase_ITreeNode.h>
26 #include <ModelAPI_Feature.h>
31 * Implementation of base node for the module data tree
33 class PartSet_TreeNode : public ModuleBase_ITreeNode
36 PartSet_TreeNode(ModuleBase_ITreeNode* theParent = 0) : ModuleBase_ITreeNode(theParent) {}
38 /// Returns the node representation according to theRole.
39 virtual QVariant data(int theColumn, int theRole) const;
44 * Implementation of a node for object repesentation
46 class PartSet_ObjectNode : public PartSet_TreeNode
49 PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
50 : PartSet_TreeNode(theParent), myObject(theObj) {}
52 static std::string typeId()
54 static std::string myType = "Object";
58 virtual std::string type() const { return typeId(); }
60 /// Returns the node representation according to theRole.
61 virtual QVariant data(int theColumn, int theRole) const;
63 /// Returns properties flag of the item
64 virtual Qt::ItemFlags flags(int theColumn) const;
66 /// Returns object referenced by the node (can be null)
67 virtual ObjectPtr object() const { return myObject; }
69 /// Sets an object to the node
70 /// theObj a new object
71 void setObject(ObjectPtr theObj) { myObject = theObj; }
73 virtual VisibilityState visibilityState() const;
75 /// Updates sub-nodes of the node
76 virtual void update();
78 /// Process creation of objects.
79 /// \param theObjects a list of created objects
80 /// \return a list of nodes which corresponds to the created objects
81 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
83 /// Process deletion of objects.
84 /// \param theDoc a document where objects were deleted
85 /// \param theGroup a name of group where objects were deleted
86 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
88 /// Returns number of sub-objects of the current object
89 virtual int numberOfSubs() const;
91 virtual ObjectPtr subObject(int theId) const;
99 * Implementation of aFolder node in data tree
101 class PartSet_FolderNode : public PartSet_TreeNode
113 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
115 static std::string typeId()
117 static std::string myType = "Folder";
121 virtual std::string type() const { return typeId(); }
123 /// Returns the node representation according to theRole.
124 virtual QVariant data(int theColumn, int theRole) const;
126 /// Returns properties flag of the item
127 virtual Qt::ItemFlags flags(int theColumn) const;
129 /// Updates sub-nodes of the node
130 virtual void update();
132 /// Process creation of objects.
133 /// \param theObjects a list of created objects
134 /// \return a list of nodes which corresponds to the created objects
135 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
137 /// Process deletion of objects.
138 /// \param theDoc a document where objects were deleted
139 /// \param theGroup a name of group where objects were deleted
140 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
142 QString name() const;
144 /// Returns a node which belongs to the given document and contains objects of the given group
145 /// \param theDoc a document
146 /// \param theGroup a name of objects group
147 /// \return a parent node if it is found
148 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
150 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
156 std::string groupName() const;
158 ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
163 /////////////////////////////////////////////////////////////////////
166 * A base class for root folders
168 class PartSet_FeatureFolderNode : public PartSet_TreeNode
171 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
173 /// Process creation of objects.
174 /// \param theObjects a list of created objects
175 /// \return a list of nodes which corresponds to the created objects
176 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
178 /// Process deletion of objects.
179 /// \param theDoc a document where objects were deleted
180 /// \param theGroup a name of group where objects were deleted
181 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
183 /// Returns a node which belongs to the given document and contains objects of the given group
184 /// \param theDoc a document
185 /// \param theGroup a name of objects group
186 /// \return a parent node if it is found
187 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
190 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
192 virtual int numberOfFolders() const { return 0; }
196 /////////////////////////////////////////////////////////////////////
199 * Implementation of Root node in data tree
201 class PartSet_RootNode : public PartSet_FeatureFolderNode
206 static std::string typeId()
208 static std::string myType = "PartSetRoot";
212 virtual std::string type() const { return typeId(); }
214 /// Updates sub-nodes of the node
215 virtual void update();
217 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
219 /// Returns document object of the sub-tree.
220 virtual DocumentPtr document() const;
222 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
225 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
227 virtual int numberOfFolders() const { return 3; }
230 PartSet_FolderNode* myParamsFolder;
231 PartSet_FolderNode* myConstrFolder;
232 PartSet_FolderNode* myPartsFolder;
234 ModuleBase_IWorkshop* myWorkshop;
237 /////////////////////////////////////////////////////////////////////
240 * Implementation of Root node of a Part document in data tree
242 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
245 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
247 static std::string typeId()
249 static std::string myType = "PartRoot";
253 virtual std::string type() const { return typeId(); }
255 /// Returns object referenced by the node (can be null)
256 virtual ObjectPtr object() const { return myObject; }
258 /// Returns document object of the sub-tree.
259 virtual DocumentPtr document() const;
261 /// Updates sub-nodes of the node
262 virtual void update();
264 /// Returns the node representation according to theRole.
265 virtual QVariant data(int theColumn, int theRole) const;
267 /// Returns properties flag of the item
268 virtual Qt::ItemFlags flags(int theColumn) const;
270 /// Process creation of objects.
271 /// \param theObjects a list of created objects
272 /// \return a list of nodes which corresponds to the created objects
273 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
275 /// Process deletion of objects.
276 /// \param theDoc a document where objects were deleted
277 /// \param theGroup a name of group where objects were deleted
278 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
281 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
283 virtual int numberOfFolders() const;
285 virtual void deleteChildren();
288 PartSet_FolderNode* myParamsFolder;
289 PartSet_FolderNode* myConstrFolder;
290 PartSet_FolderNode* myResultsFolder;
291 PartSet_FolderNode* myFieldsFolder;
292 PartSet_FolderNode* myGroupsFolder;
297 /////////////////////////////////////////////////////////////////////
300 * Implementation of a folder which corresponds to ModelAPI_Folder object
302 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
305 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
306 : PartSet_ObjectNode(theObj, theParent) {}
308 static std::string typeId()
310 static std::string myType = "ObjectFolder";
314 virtual std::string type() const { return typeId(); }
316 /// Updates sub-nodes of the node
317 virtual void update();
319 /// Process creation of objects.
320 /// \param theObjects a list of created objects
321 /// \return a list of nodes which corresponds to the created objects
322 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
324 /// Process deletion of objects.
325 /// \param theDoc a document where objects were deleted
326 /// \param theGroup a name of group where objects were deleted
327 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
331 /////////////////////////////////////////////////////////////////////
334 * Implementation of a node for compsolid representation
336 class PartSet_StepNode : public PartSet_ObjectNode
339 PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
340 PartSet_ObjectNode(theObj, theParent) {}
342 static std::string typeId()
344 static std::string myType = "FieldStep";
348 virtual std::string type() const { return typeId(); }
350 /// Returns the node representation according to theRole.
351 virtual QVariant data(int theColumn, int theRole) const;
353 virtual VisibilityState visibilityState() const;