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);
95 * Implementation of aFolder node in data tree
97 class PartSet_FolderNode : public PartSet_TreeNode
109 PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType);
111 static std::string typeId()
113 static std::string myType = "Folder";
117 virtual std::string type() const { return typeId(); }
119 /// Returns the node representation according to theRole.
120 virtual QVariant data(int theColumn, int theRole) const;
122 /// Returns properties flag of the item
123 virtual Qt::ItemFlags flags(int theColumn) const;
125 /// Updates sub-nodes of the node
126 virtual void update();
128 /// Process creation of objects.
129 /// \param theObjects a list of created objects
130 /// \return a list of nodes which corresponds to the created objects
131 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
133 /// Process deletion of objects.
134 /// \param theDoc a document where objects were deleted
135 /// \param theGroup a name of group where objects were deleted
136 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
138 QString name() const;
140 /// Returns a node which belongs to the given document and contains objects of the given group
141 /// \param theDoc a document
142 /// \param theGroup a name of objects group
143 /// \return a parent node if it is found
144 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup)
146 if ((theDoc == document()) && (theGroup.toStdString() == groupName()))
152 std::string groupName() const;
154 ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
159 /////////////////////////////////////////////////////////////////////
162 * A base class for root folders
164 class PartSet_FeatureFolderNode : public PartSet_TreeNode
167 PartSet_FeatureFolderNode(ModuleBase_ITreeNode* theParent = 0) : PartSet_TreeNode(theParent) {}
169 /// Process creation of objects.
170 /// \param theObjects a list of created objects
171 /// \return a list of nodes which corresponds to the created objects
172 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
174 /// Process deletion of objects.
175 /// \param theDoc a document where objects were deleted
176 /// \param theGroup a name of group where objects were deleted
177 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
179 /// Returns a node which belongs to the given document and contains objects of the given group
180 /// \param theDoc a document
181 /// \param theGroup a name of objects group
182 /// \return a parent node if it is found
183 virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup);
186 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj) = 0;
188 virtual int numberOfFolders() const { return 0; }
192 /////////////////////////////////////////////////////////////////////
195 * Implementation of Root node in data tree
197 class PartSet_RootNode : public PartSet_FeatureFolderNode
202 static std::string typeId()
204 static std::string myType = "PartSetRoot";
208 virtual std::string type() const { return typeId(); }
210 /// Updates sub-nodes of the node
211 virtual void update();
213 virtual ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
215 /// Returns document object of the sub-tree.
216 virtual DocumentPtr document() const;
218 void setWorkshop(ModuleBase_IWorkshop* theWork) { myWorkshop = theWork; }
221 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
223 virtual int numberOfFolders() const { return 3; }
226 PartSet_FolderNode* myParamsFolder;
227 PartSet_FolderNode* myConstrFolder;
228 PartSet_FolderNode* myPartsFolder;
230 ModuleBase_IWorkshop* myWorkshop;
233 /////////////////////////////////////////////////////////////////////
236 * Implementation of Root node of a Part document in data tree
238 class PartSet_PartRootNode : public PartSet_FeatureFolderNode
241 PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
243 static std::string typeId()
245 static std::string myType = "PartRoot";
249 virtual std::string type() const { return typeId(); }
251 /// Returns object referenced by the node (can be null)
252 virtual ObjectPtr object() const { return myObject; }
254 /// Returns document object of the sub-tree.
255 virtual DocumentPtr document() const;
257 /// Updates sub-nodes of the node
258 virtual void update();
260 /// Returns the node representation according to theRole.
261 virtual QVariant data(int theColumn, int theRole) const;
263 /// Returns properties flag of the item
264 virtual Qt::ItemFlags flags(int theColumn) const;
266 /// Process creation of objects.
267 /// \param theObjects a list of created objects
268 /// \return a list of nodes which corresponds to the created objects
269 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
271 /// Process deletion of objects.
272 /// \param theDoc a document where objects were deleted
273 /// \param theGroup a name of group where objects were deleted
274 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
277 virtual ModuleBase_ITreeNode* createNode(const ObjectPtr& theObj);
279 virtual int numberOfFolders() const;
281 virtual void deleteChildren();
284 PartSet_FolderNode* myParamsFolder;
285 PartSet_FolderNode* myConstrFolder;
286 PartSet_FolderNode* myResultsFolder;
287 PartSet_FolderNode* myFieldsFolder;
288 PartSet_FolderNode* myGroupsFolder;
293 /////////////////////////////////////////////////////////////////////
296 * Implementation of a folder which corresponds to ModelAPI_Folder object
298 class PartSet_ObjectFolderNode : public PartSet_ObjectNode
301 PartSet_ObjectFolderNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
302 : PartSet_ObjectNode(theObj, theParent) {}
304 static std::string typeId()
306 static std::string myType = "ObjectFolder";
310 virtual std::string type() const { return typeId(); }
312 /// Updates sub-nodes of the node
313 virtual void update();
315 /// Process creation of objects.
316 /// \param theObjects a list of created objects
317 /// \return a list of nodes which corresponds to the created objects
318 virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
320 /// Process deletion of objects.
321 /// \param theDoc a document where objects were deleted
322 /// \param theGroup a name of group where objects were deleted
323 virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);
326 FeaturePtr getFeature(const std::string& theId) const;
328 void getFirstAndLastIndex(int& theFirst, int& theLast) const;
332 /////////////////////////////////////////////////////////////////////
335 * Implementation of a node for compsolid representation
337 //class PartSet_CompsolidNode : public PartSet_ObjectNode
340 // PartSet_CompsolidNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent);
342 // static std::string typeId()
344 // static std::string myType = "CompSolid";
348 // virtual std::string type() const { return typeId(); }
350 // /// Updates sub-nodes of the node
351 // virtual void update();
353 // /// Process creation of objects.
354 // /// \param theObjects a list of created objects
355 // /// \return a list of nodes which corresponds to the created objects
356 // virtual QTreeNodesList objectCreated(const QObjectPtrList& theObjects);
358 // /// Process deletion of objects.
359 // /// \param theDoc a document where objects were deleted
360 // /// \param theGroup a name of group where objects were deleted
361 // virtual QTreeNodesList objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup);