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 /// Updates sub-nodes of the node
75 virtual void update() {}
77 virtual VisibilityState visibilityState() const;
85 * Implementation of aFolder node in data tree
87 class PartSet_FolderNode : public PartSet_TreeNode
99 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
101 static std::string typeId()
103 static std::string myType = "Folder";
107 virtual std::string type() const { return typeId(); }
109 /// Returns the node representation according to theRole.
110 virtual QVariant data(int theColumn, int theRole) const;
112 /// Returns properties flag of the item
113 virtual Qt::ItemFlags flags(int theColumn) const;
115 /// Updates sub-nodes of the node
116 virtual void update();
118 /// Process creation of objects.
119 /// \param theObjects a list of created objects
120 /// \return a list of nodes which corresponds to the created objects
121 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
123 /// Process deletion of objects.
124 /// \param theDoc a document where objects were deleted
125 /// \param theGroup a name of group where objects were deleted
126 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
128 QString name() const;
130 /// Returns a node which belongs to the given document and contains objects of the given group
131 /// \param theDoc a document
132 /// \param theGroup a name of objects group
133 /// \return a parent node if it is found
134 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
136 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
142 std::string groupName() const;
144 ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
149 /////////////////////////////////////////////////////////////////////
152 * A base class for root folders
154 class PartSet_FeatureFolderNode : public PartSet_TreeNode
157 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
159 /// Process creation of objects.
160 /// \param theObjects a list of created objects
161 /// \return a list of nodes which corresponds to the created objects
162 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
164 /// Process deletion of objects.
165 /// \param theDoc a document where objects were deleted
166 /// \param theGroup a name of group where objects were deleted
167 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
169 /// Returns a node which belongs to the given document and contains objects of the given group
170 /// \param theDoc a document
171 /// \param theGroup a name of objects group
172 /// \return a parent node if it is found
173 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
176 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
178 virtual int numberOfFolders() const { return 0; }
182 /////////////////////////////////////////////////////////////////////
185 * Implementation of Root node in data tree
187 class PartSet_RootNode : public PartSet_FeatureFolderNode
192 static std::string typeId()
194 static std::string myType = "PartSetRoot";
198 virtual std::string type() const { return typeId(); }
200 /// Updates sub-nodes of the node
201 virtual void update();
203 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
205 /// Returns document object of the sub-tree.
206 virtual DocumentPtr document() const;
208 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
211 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
213 virtual int numberOfFolders() const { return 3; }
216 PartSet_FolderNode* myParamsFolder;
217 PartSet_FolderNode* myConstrFolder;
218 PartSet_FolderNode* myPartsFolder;
220 ModuleBase_IWorkshop* myWorkshop;
223 /////////////////////////////////////////////////////////////////////
226 * Implementation of Root node of a Part document in data tree
228 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
231 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
233 static std::string typeId()
235 static std::string myType = "PartRoot";
239 virtual std::string type() const { return typeId(); }
241 /// Returns object referenced by the node (can be null)
242 virtual ObjectPtr object() const { return myObject; }
244 /// Returns document object of the sub-tree.
245 virtual DocumentPtr document() const;
247 /// Updates sub-nodes of the node
248 virtual void update();
250 /// Returns the node representation according to theRole.
251 virtual QVariant data(int theColumn, int theRole) const;
253 /// Returns properties flag of the item
254 virtual Qt::ItemFlags flags(int theColumn) const;
256 /// Process creation of objects.
257 /// \param theObjects a list of created objects
258 /// \return a list of nodes which corresponds to the created objects
259 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
261 /// Process deletion of objects.
262 /// \param theDoc a document where objects were deleted
263 /// \param theGroup a name of group where objects were deleted
264 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
267 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
269 virtual int numberOfFolders() const;
271 virtual void deleteChildren();
274 PartSet_FolderNode* myParamsFolder;
275 PartSet_FolderNode* myConstrFolder;
276 PartSet_FolderNode* myResultsFolder;
277 PartSet_FolderNode* myFieldsFolder;
278 PartSet_FolderNode* myGroupsFolder;
283 /////////////////////////////////////////////////////////////////////
286 * Implementation of a folder which corresponds to ModelAPI_Folder object
288 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
291 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
292 : PartSet_ObjectNode(theObj, theParent) {}
294 static std::string typeId()
296 static std::string myType = "ObjectFolder";
300 virtual std::string type() const { return typeId(); }
302 /// Updates sub-nodes of the node
303 virtual void update();
305 /// Process creation of objects.
306 /// \param theObjects a list of created objects
307 /// \return a list of nodes which corresponds to the created objects
308 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
310 /// Process deletion of objects.
311 /// \param theDoc a document where objects were deleted
312 /// \param theGroup a name of group where objects were deleted
313 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
316 FeaturePtr getFeature(const std::string& theId) const;
318 void getFirstAndLastIndex(int& theFirst, int& theLast) const;
322 /////////////////////////////////////////////////////////////////////
325 * Implementation of a node for compsolid representation
327 class PartSet_CompsolidNode : public PartSet_ObjectNode
330 PartSet_CompsolidNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
332 static std::string typeId()
334 static std::string myType = "CompSolid";
338 virtual std::string type() const { return typeId(); }
340 /// Updates sub-nodes of the node
341 virtual void update();
343 /// Process creation of objects.
344 /// \param theObjects a list of created objects
345 /// \return a list of nodes which corresponds to the created objects
346 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
348 /// Process deletion of objects.
349 /// \param theDoc a document where objects were deleted
350 /// \param theGroup a name of group where objects were deleted
351 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);