1 // Copyright (C) 2014-2022 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;
41 // Returns color of the Item when it is active
42 virtual QColor activeItemColor() const;
47 * Implementation of a node for object repesentation
49 class PartSet_ObjectNode : public PartSet_TreeNode
52 PartSet_ObjectNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent = 0)
53 : PartSet_TreeNode(theParent), myObject(theObj) {}
55 static std::string typeId()
57 static std::string myType = "Object";
61 virtual std::string type() const { return typeId(); }
63 /// Returns the node representation according to theRole.
64 virtual QVariant data(int theColumn, int theRole) const;
66 /// Returns properties flag of the item
67 virtual Qt::ItemFlags flags(int theColumn) const;
69 /// Returns object referenced by the node (can be null)
70 virtual ObjectPtr object() const { return myObject; }
72 /// Sets an object to the node
73 /// theObj a new object
74 void setObject(ObjectPtr theObj) { myObject = theObj; }
76 virtual VisibilityState visibilityState() const;
78 /// Updates sub-nodes of the node
79 virtual void update();
81 /// Process creation of objects.
82 /// \param theObjects a list of created objects
83 /// \return a list of nodes which corresponds to the created objects
84 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
86 /// Process deletion of objects.
87 /// \param theDoc a document where objects were deleted
88 /// \param theGroup a name of group where objects were deleted
89 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
91 /// Returns number of sub-objects of the current object
92 virtual int numberOfSubs() const;
94 virtual ObjectPtr subObject(int theId) const;
96 // Returns color of the Item when it is active
97 virtual QColor activeItemColor() const;
105 * Implementation of aFolder node in data tree
107 class PartSet_FolderNode : public PartSet_TreeNode
119 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
121 static std::string typeId()
123 static std::string myType = "Folder";
127 virtual std::string type() const { return typeId(); }
129 /// Returns the node representation according to theRole.
130 virtual QVariant data(int theColumn, int theRole) const;
132 /// Returns properties flag of the item
133 virtual Qt::ItemFlags flags(int theColumn) const;
135 /// Updates sub-nodes of the node
136 virtual void update();
138 /// Process creation of objects.
139 /// \param theObjects a list of created objects
140 /// \return a list of nodes which corresponds to the created objects
141 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
143 /// Process deletion of objects.
144 /// \param theDoc a document where objects were deleted
145 /// \param theGroup a name of group where objects were deleted
146 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
148 QString name() const;
150 /// Returns a node which belongs to the given document and contains objects of the given group
151 /// \param theDoc a document
152 /// \param theGroup a name of objects group
153 /// \return a parent node if it is found
154 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
156 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
162 std::string groupName() const;
164 ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
169 /////////////////////////////////////////////////////////////////////
172 * A base class for root folders
174 class PartSet_FeatureFolderNode : public PartSet_TreeNode
177 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
179 /// Process creation of objects.
180 /// \param theObjects a list of created objects
181 /// \return a list of nodes which corresponds to the created objects
182 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
184 /// Process deletion of objects.
185 /// \param theDoc a document where objects were deleted
186 /// \param theGroup a name of group where objects were deleted
187 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
189 /// Returns a node which belongs to the given document and contains objects of the given group
190 /// \param theDoc a document
191 /// \param theGroup a name of objects group
192 /// \return a parent node if it is found
193 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
196 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
198 virtual int numberOfFolders() const { return 0; }
202 /////////////////////////////////////////////////////////////////////
205 * Implementation of Root node in data tree
207 class PartSet_RootNode : public PartSet_FeatureFolderNode
212 static std::string typeId()
214 static std::string myType = "PartSetRoot";
218 virtual std::string type() const { return typeId(); }
220 /// Updates sub-nodes of the node
221 virtual void update();
223 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
225 /// Returns document object of the sub-tree.
226 virtual DocumentPtr document() const;
228 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
231 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
233 virtual int numberOfFolders() const { return 3; }
236 PartSet_FolderNode* myParamsFolder;
237 PartSet_FolderNode* myConstrFolder;
238 PartSet_FolderNode* myPartsFolder;
240 ModuleBase_IWorkshop* myWorkshop;
243 /////////////////////////////////////////////////////////////////////
246 * Implementation of Root node of a Part document in data tree
248 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
251 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
253 static std::string typeId()
255 static std::string myType = "PartRoot";
259 virtual std::string type() const { return typeId(); }
261 /// Returns object referenced by the node (can be null)
262 virtual ObjectPtr object() const { return myObject; }
264 /// Returns document object of the sub-tree.
265 virtual DocumentPtr document() const;
267 /// Updates sub-nodes of the node
268 virtual void update();
270 /// Returns the node representation according to theRole.
271 virtual QVariant data(int theColumn, int theRole) const;
273 /// Returns properties flag of the item
274 virtual Qt::ItemFlags flags(int theColumn) const;
276 /// Process creation of objects.
277 /// \param theObjects a list of created objects
278 /// \return a list of nodes which corresponds to the created objects
279 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
281 /// Process deletion of objects.
282 /// \param theDoc a document where objects were deleted
283 /// \param theGroup a name of group where objects were deleted
284 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
287 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
289 virtual int numberOfFolders() const;
291 virtual void deleteChildren();
294 PartSet_FolderNode* myParamsFolder;
295 PartSet_FolderNode* myConstrFolder;
296 PartSet_FolderNode* myResultsFolder;
297 PartSet_FolderNode* myFieldsFolder;
298 PartSet_FolderNode* myGroupsFolder;
303 /////////////////////////////////////////////////////////////////////
306 * Implementation of a folder which corresponds to ModelAPI_Folder object
308 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
311 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
312 : PartSet_ObjectNode(theObj, theParent) {}
314 static std::string typeId()
316 static std::string myType = "ObjectFolder";
320 virtual std::string type() const { return typeId(); }
322 /// Updates sub-nodes of the node
323 virtual void update();
325 /// Process creation of objects.
326 /// \param theObjects a list of created objects
327 /// \return a list of nodes which corresponds to the created objects
328 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
330 /// Process deletion of objects.
331 /// \param theDoc a document where objects were deleted
332 /// \param theGroup a name of group where objects were deleted
333 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
335 /// Returns the node representation according to theRole.
336 virtual QVariant data(int theColumn, int theRole) const;
340 /////////////////////////////////////////////////////////////////////
343 * Implementation of a node for compsolid representation
345 class PartSet_StepNode : public PartSet_ObjectNode
348 PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
349 PartSet_ObjectNode(theObj, theParent) {}
351 static std::string typeId()
353 static std::string myType = "FieldStep";
357 virtual std::string type() const { return typeId(); }
359 /// Returns the node representation according to theRole.
360 virtual QVariant data(int theColumn, int theRole) const;
362 virtual VisibilityState visibilityState() const;