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 /// Sets an object to the node
71 /// theObj a new object
72 void setObject(ObjectPtr theObj) { myObject = theObj; }
74 virtual VisibilityState visibilityState() const;
76 /// Updates sub-nodes of the node
77 virtual void update();
79 /// Process creation of objects.
80 /// \param theObjects a list of created objects
81 /// \return a list of nodes which corresponds to the created objects
82 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
84 /// Process deletion of objects.
85 /// \param theDoc a document where objects were deleted
86 /// \param theGroup a name of group where objects were deleted
87 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
89 /// Returns number of sub-objects of the current object
90 virtual int numberOfSubs() const;
92 virtual ObjectPtr subObject(int theId) const;
100 * Implementation of aFolder node in data tree
102 class PartSet_FolderNode : public PartSet_TreeNode
114 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
116 static std::string typeId()
118 static std::string myType = "Folder";
122 virtual std::string type() const { return typeId(); }
124 /// Returns the node representation according to theRole.
125 virtual QVariant data(int theColumn, int theRole) const;
127 /// Returns properties flag of the item
128 virtual Qt::ItemFlags flags(int theColumn) const;
130 /// Updates sub-nodes of the node
131 virtual void update();
133 /// Process creation of objects.
134 /// \param theObjects a list of created objects
135 /// \return a list of nodes which corresponds to the created objects
136 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
138 /// Process deletion of objects.
139 /// \param theDoc a document where objects were deleted
140 /// \param theGroup a name of group where objects were deleted
141 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
143 QString name() const;
145 /// Returns a node which belongs to the given document and contains objects of the given group
146 /// \param theDoc a document
147 /// \param theGroup a name of objects group
148 /// \return a parent node if it is found
149 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
151 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
157 std::string groupName() const;
159 ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
164 /////////////////////////////////////////////////////////////////////
167 * A base class for root folders
169 class PartSet_FeatureFolderNode : public PartSet_TreeNode
172 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
174 /// Process creation of objects.
175 /// \param theObjects a list of created objects
176 /// \return a list of nodes which corresponds to the created objects
177 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
179 /// Process deletion of objects.
180 /// \param theDoc a document where objects were deleted
181 /// \param theGroup a name of group where objects were deleted
182 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
184 /// Returns a node which belongs to the given document and contains objects of the given group
185 /// \param theDoc a document
186 /// \param theGroup a name of objects group
187 /// \return a parent node if it is found
188 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
191 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
193 virtual int numberOfFolders() const { return 0; }
197 /////////////////////////////////////////////////////////////////////
200 * Implementation of Root node in data tree
202 class PartSet_RootNode : public PartSet_FeatureFolderNode
207 static std::string typeId()
209 static std::string myType = "PartSetRoot";
213 virtual std::string type() const { return typeId(); }
215 /// Updates sub-nodes of the node
216 virtual void update();
218 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
220 /// Returns document object of the sub-tree.
221 virtual DocumentPtr document() const;
223 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
226 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
228 virtual int numberOfFolders() const { return 3; }
231 PartSet_FolderNode* myParamsFolder;
232 PartSet_FolderNode* myConstrFolder;
233 PartSet_FolderNode* myPartsFolder;
235 ModuleBase_IWorkshop* myWorkshop;
238 /////////////////////////////////////////////////////////////////////
241 * Implementation of Root node of a Part document in data tree
243 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
246 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
248 static std::string typeId()
250 static std::string myType = "PartRoot";
254 virtual std::string type() const { return typeId(); }
256 /// Returns object referenced by the node (can be null)
257 virtual ObjectPtr object() const { return myObject; }
259 /// Returns document object of the sub-tree.
260 virtual DocumentPtr document() const;
262 /// Updates sub-nodes of the node
263 virtual void update();
265 /// Returns the node representation according to theRole.
266 virtual QVariant data(int theColumn, int theRole) const;
268 /// Returns properties flag of the item
269 virtual Qt::ItemFlags flags(int theColumn) const;
271 /// Process creation of objects.
272 /// \param theObjects a list of created objects
273 /// \return a list of nodes which corresponds to the created objects
274 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
276 /// Process deletion of objects.
277 /// \param theDoc a document where objects were deleted
278 /// \param theGroup a name of group where objects were deleted
279 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
282 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
284 virtual int numberOfFolders() const;
286 virtual void deleteChildren();
289 PartSet_FolderNode* myParamsFolder;
290 PartSet_FolderNode* myConstrFolder;
291 PartSet_FolderNode* myResultsFolder;
292 PartSet_FolderNode* myFieldsFolder;
293 PartSet_FolderNode* myGroupsFolder;
298 /////////////////////////////////////////////////////////////////////
301 * Implementation of a folder which corresponds to ModelAPI_Folder object
303 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
306 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
307 : PartSet_ObjectNode(theObj, theParent) {}
309 static std::string typeId()
311 static std::string myType = "ObjectFolder";
315 virtual std::string type() const { return typeId(); }
317 /// Updates sub-nodes of the node
318 virtual void update();
320 /// Process creation of objects.
321 /// \param theObjects a list of created objects
322 /// \return a list of nodes which corresponds to the created objects
323 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
325 /// Process deletion of objects.
326 /// \param theDoc a document where objects were deleted
327 /// \param theGroup a name of group where objects were deleted
328 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
332 /////////////////////////////////////////////////////////////////////
335 * Implementation of a node for compsolid representation
337 class PartSet_StepNode : public PartSet_TreeNode
340 PartSet_StepNode(ModelAPI_Entity* theEnt, ModuleBase_ITreeNode* theParent) :
341 PartSet_TreeNode(theParent), myEntity(theEnt) {}
343 static std::string typeId()
345 static std::string myType = "FieldStep";
349 virtual std::string type() const { return typeId(); }
351 /// Returns the node representation according to theRole.
352 virtual QVariant data(int theColumn, int theRole) const;
354 ModelAPI_Entity* entity() const {
358 void setEntity(ModelAPI_Entity* theEnt) {
363 ModelAPI_Entity* myEntity;