]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_TreeNodes.cpp
Salome HOME
Redevelopment of object browser data model
[modules/shaper.git] / src / PartSet / PartSet_TreeNodes.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSet_TreeNodes.h"
22
23 #include <ModuleBase_IconFactory.h>
24 #include <ModuleBase_IWorkshop.h>
25
26 #include <PartSetPlugin_Part.h>
27
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_ResultParameter.h>
30 #include <ModelAPI_ResultField.h>
31 #include <ModelAPI_ResultGroup.h>
32 #include <ModelAPI_ResultConstruction.h>
33 #include <ModelAPI_ResultPart.h>
34 #include <ModelAPI_ResultBody.h>
35 #include <ModelAPI_Feature.h>
36 #include <ModelAPI_Tools.h>
37 #include <ModelAPI_ResultCompSolid.h>
38 #include <ModelAPI_CompositeFeature.h>
39 #include <ModelAPI_AttributeDouble.h>
40
41
42 #include <QBrush>
43
44
45 #define ACTIVE_COLOR QColor(Qt::black)
46 #define SELECTABLE_COLOR QColor(100, 100, 100)
47 #define DISABLED_COLOR QColor(200, 200, 200)
48
49 Qt::ItemFlags aNullFlag;
50 Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
51 Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
52
53
54 ResultPartPtr getPartResult(const ObjectPtr& theObj)
55 {
56   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
57   if (aFeature) {
58     ResultPtr aRes = aFeature->firstResult();
59     if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
60       ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
61       // Use only original parts, not a placement results
62       if (aPartRes == aPartRes->original())
63         return aPartRes;
64     }
65   }
66   return ResultPartPtr();
67 }
68
69 bool isCurrentFeature(const ObjectPtr& theObj)
70 {
71   SessionPtr aSession = ModelAPI_Session::get();
72   DocumentPtr aCurDoc = aSession->activeDocument();
73   FeaturePtr aFeature = aCurDoc->currentFeature(true);
74   return aFeature == theObj;
75 }
76
77 //////////////////////////////////////////////////////////////////////////////////
78 QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
79 {
80   if ((theColumn == 1) && (theRole == Qt::ForegroundRole)) {
81     Qt::ItemFlags aFlags = flags(theColumn);
82     if (aFlags == Qt::ItemFlags())
83       return QBrush(DISABLED_COLOR);
84     if (!aFlags.testFlag(Qt::ItemIsEditable))
85       return QBrush(SELECTABLE_COLOR);
86     return ACTIVE_COLOR;
87   }
88   return ModuleBase_ITreeNode::data(theColumn, theRole);
89 }
90
91
92 //////////////////////////////////////////////////////////////////////////////////
93 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
94 {
95   switch (theRole) {
96   case Qt::DisplayRole:
97     if (theColumn == 1) {
98       if (myObject->groupName() == ModelAPI_ResultParameter::group()) {
99         ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myObject);
100         AttributeDoublePtr aValueAttribute =
101           aParam->data()->real(ModelAPI_ResultParameter::VALUE());
102         QString aVal = QString::number(aValueAttribute->value());
103         QString aTitle = QString(myObject->data()->name().c_str());
104         return aTitle + " = " + aVal;
105       }
106       return myObject->data()->name().c_str();
107     }
108     break;
109   case Qt::DecorationRole:
110     switch (theColumn) {
111     case 0:
112       switch (getVisibilityState()) {
113       case NoneState:
114         return QIcon();
115       case Visible:
116         return QIcon(":pictures/eyeopen.png");
117       case SemiVisible:
118         return QIcon(":pictures/eyemiclosed.png");
119       case Hidden:
120         return QIcon(":pictures/eyeclosed.png");
121       }
122     case 1:
123       return ModuleBase_IconFactory::get()->getIcon(myObject);
124     case 2:
125       if (isCurrentFeature(myObject))
126         return QIcon(":pictures/arrow.png");
127     }
128   }
129   return PartSet_TreeNode::data(theColumn, theRole);
130 }
131
132 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
133 {
134   if (!myObject->isDisabled()) {
135     DocumentPtr aDoc = myObject->document();
136     SessionPtr aSession = ModelAPI_Session::get();
137     if (aSession->activeDocument() == aDoc)
138       return aEditingFlag;
139   }
140   return aDefaultFlag;
141 }
142
143 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::getVisibilityState() const
144 {
145   Qt::ItemFlags aFlags = flags(1);
146   if (aFlags == Qt::ItemFlags())
147     return NoneState;
148
149   if (myObject->groupName() == ModelAPI_ResultParameter::group())
150     return NoneState;
151   ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
152   if (aResObj.get()) {
153     ModuleBase_IWorkshop* aWork = workshop();
154     ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
155     if (aCompRes.get()) {
156       VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
157         (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
158       for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
159         ResultPtr aSubRes = aCompRes->subResult(i, true);
160         VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
161         if (aState == NoneState)
162           aState = aS;
163         else if (aState != aS) {
164           aState = SemiVisible;
165           break;
166         }
167       }
168       return aState;
169     } else {
170       if (aWork->isVisible(aResObj))
171         return Visible;
172       else
173         return Hidden;
174     }
175   }
176   return NoneState;
177 }
178
179
180 //////////////////////////////////////////////////////////////////////////////////
181 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
182   FolderType theType)
183   : PartSet_TreeNode(theParent), myType(theType)
184 {
185 }
186
187 PartSet_FolderNode::~PartSet_FolderNode()
188 {
189   while (myChildren.length() > 0) {
190     ModuleBase_ITreeNode* aNode = myChildren.last();
191     myChildren.removeAll(aNode);
192     delete aNode;
193   }
194 }
195
196 QString PartSet_FolderNode::name() const
197 {
198   switch (myType) {
199   case ParametersFolder:
200     return QObject::tr("Parameters");
201   case ConstructionFolder:
202     return QObject::tr("Constructions");
203   case PartsFolder:
204     return QObject::tr("Parts");
205   case ResultsFolder:
206     return QObject::tr("Results");
207   case FieldsFolder:
208     return QObject::tr("Fields");
209   case GroupsFolder:
210     return QObject::tr("Groups");
211   }
212   return "NoName";
213 }
214
215
216 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
217 {
218   static QIcon aParamsIco(":pictures/params_folder.png");
219   static QIcon aConstrIco(":pictures/constr_folder.png");
220
221   if (theColumn == 1) {
222     switch (theRole) {
223     case Qt::DisplayRole:
224       return name() + QString(" (%1)").arg(childrenCount());
225     case Qt::DecorationRole:
226       switch (myType) {
227       case ParametersFolder:
228         return aParamsIco;
229       case ConstructionFolder:
230         return aConstrIco;
231       case PartsFolder:
232         return aConstrIco;
233       case ResultsFolder:
234         return aConstrIco;
235       case FieldsFolder:
236         return aConstrIco;
237       case GroupsFolder:
238         return aConstrIco;
239       }
240     }
241   }
242   return PartSet_TreeNode::data(theColumn, theRole);
243 }
244
245 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
246 {
247   SessionPtr aSession = ModelAPI_Session::get();
248   DocumentPtr aActiveDoc = aSession->activeDocument();
249   if (theColumn == 1) {
250     if (document() == aActiveDoc)
251       return aEditingFlag;
252   }
253   return aDefaultFlag;
254 }
255
256 void PartSet_FolderNode::update()
257 {
258   DocumentPtr aDoc = document();
259   if (!aDoc.get())
260     return;
261
262   // Remove extra sub-nodes
263   QTreeNodesList aDelList;
264   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
265     if (aDoc->index(aNode->object()) == -1)
266       aDelList.append(aNode);
267   }
268   foreach(ModuleBase_ITreeNode* aNode, aDelList) {
269     myChildren.removeAll(aNode);
270     delete aNode;
271   }
272
273   // Add new nodes
274   std::string aGroup = groupName();
275   int aSize = aDoc->size(aGroup);
276   for (int i = 0; i < aSize; i++) {
277     ObjectPtr aObj = aDoc->object(aGroup, i);
278     if (i < myChildren.size()) {
279       if (myChildren.at(i)->object() != aObj) {
280         PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
281         myChildren.insert(i, aNode);
282       }
283     } else {
284       PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
285       myChildren.append(aNode);
286     }
287   }
288 }
289
290 std::string PartSet_FolderNode::groupName() const
291 {
292   switch (myType) {
293   case ParametersFolder:
294     return ModelAPI_ResultParameter::group();
295   case ConstructionFolder:
296     return ModelAPI_ResultConstruction::group();
297   case PartsFolder:
298     return ModelAPI_ResultPart::group();
299   case ResultsFolder:
300     return ModelAPI_ResultBody::group();
301   case FieldsFolder:
302     return ModelAPI_ResultField::group();
303   case GroupsFolder:
304     return ModelAPI_ResultGroup::group();
305   }
306   return "";
307 }
308
309 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
310 {
311   QTreeNodesList aResult;
312   std::string aName = groupName();
313   DocumentPtr aDoc = document();
314   int aIdx = -1;
315   foreach(ObjectPtr aObj, theObjects) {
316     if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
317       aIdx = aDoc->index(aObj);
318       if (aIdx != -1) {
319         bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
320         if (!aHasObject) {
321           PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
322           aResult.append(aNode);
323           if (aIdx < myChildren.size())
324             myChildren.insert(aIdx, aNode);
325           else
326             myChildren.append(aNode);
327         }
328       }
329     }
330   }
331   return aResult;
332 }
333
334 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
335   const QString& theGroup)
336 {
337   DocumentPtr aDoc = document();
338   QTreeNodesList aResult;
339   if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
340     QTreeNodesList aDelList;
341     foreach(ModuleBase_ITreeNode* aNode, myChildren) {
342       if (aDoc->index(aNode->object()) == -1)
343         aDelList.append(aNode);
344     }
345     if (aDelList.size() > 0) {
346       foreach(ModuleBase_ITreeNode* aNode, aDelList) {
347         myChildren.removeAll(aNode);
348         delete aNode;
349       }
350       aResult.append(this);
351     }
352   }
353   return aResult;
354 }
355
356 //////////////////////////////////////////////////////////////////////////////////
357 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
358 {
359   QTreeNodesList aResult;
360   // Process all folders
361   ModuleBase_ITreeNode* aFoder = 0;
362   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
363     aFoder = dynamic_cast<PartSet_FolderNode*>(aNode);
364     if (!aFoder)
365       aFoder = dynamic_cast<PartSet_FeatureFolderNode*>(aNode);
366
367     if (aFoder) { // aFolder node
368       QTreeNodesList aList = aNode->objectCreated(theObjects);
369       if (aList.size() > 0)
370         aResult.append(aList);
371     }
372   }
373   // Process the root sub-objects
374   DocumentPtr aDoc = document();
375   int aIdx = -1;
376   int aNb = numberOfFolders();
377   foreach(ObjectPtr aObj, theObjects) {
378     if (aDoc == aObj->document()) {
379       if (aObj->groupName() == ModelAPI_Feature::group()) {
380         ModuleBase_ITreeNode* aNode = createNode(aObj);
381         aIdx = aDoc->index(aObj) + aNb;
382         bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
383         if (!aHasObject) {
384           if (aIdx < myChildren.size())
385             myChildren.insert(aIdx, aNode);
386           else
387             myChildren.append(aNode);
388           aResult.append(aNode);
389         }
390       }
391     }
392   }
393   return aResult;
394 }
395
396 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
397   const QString& theGroup)
398 {
399   QTreeNodesList aResult;
400   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
401     if (aNode->childrenCount() > 0) { // aFolder node
402       QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
403       if (aList.size() > 0)
404         aResult.append(aList);
405     }
406   }
407   DocumentPtr aDoc = document();
408   if ((theDoc == aDoc) && (theGroup.toStdString() == ModelAPI_Feature::group())) {
409     QTreeNodesList aDelList;
410     foreach(ModuleBase_ITreeNode* aNode, myChildren) {
411       if (aNode->object().get()) {
412         if (aDoc->index(aNode->object()) == -1)
413           aDelList.append(aNode);
414       }
415     }
416     if (aDelList.size() > 0) {
417       foreach(ModuleBase_ITreeNode* aNode, aDelList) {
418         myChildren.removeAll(aNode);
419         delete aNode;
420       }
421       aResult.append(this);
422     }
423   }
424   return aResult;
425 }
426
427 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
428   QString theGroup)
429 {
430   ModuleBase_ITreeNode* aResult = 0;
431   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
432     aResult = aNode->findParent(theDoc, theGroup);
433     if (aResult) {
434       return aResult;
435     }
436   }
437   if ((theDoc == document()) && (theGroup.toStdString() == ModelAPI_Feature::group()))
438     return this;
439   return 0;
440 }
441
442
443 //////////////////////////////////////////////////////////////////////////////////
444 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
445 {
446   SessionPtr aSession = ModelAPI_Session::get();
447   DocumentPtr aDoc = aSession->moduleDocument();
448
449   myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
450   myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
451   myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
452
453   myChildren.append(myParamsFolder);
454   myChildren.append(myConstrFolder);
455   myChildren.append(myPartsFolder);
456
457   update();
458 }
459
460 PartSet_RootNode::~PartSet_RootNode()
461 {
462   delete myParamsFolder;
463   delete myConstrFolder;
464   delete myPartsFolder;
465 }
466
467
468 void PartSet_RootNode::update()
469 {
470   myParamsFolder->update();
471   myConstrFolder->update();
472   myPartsFolder->update();
473
474   // Update features content
475   DocumentPtr aDoc = document();
476
477   // Remove extra sub-nodes
478   QTreeNodesList aDelList;
479   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
480     if (aNode->object().get()) {
481       if (aDoc->index(aNode->object()) == -1)
482         aDelList.append(aNode);
483     }
484   }
485   foreach(ModuleBase_ITreeNode* aNode, aDelList) {
486     myChildren.removeAll(aNode);
487     delete aNode;
488   }
489
490   // Add new nodes
491   std::string aGroup = ModelAPI_Feature::group();
492   int aSize = aDoc->size(aGroup);
493   int aId;
494   FeaturePtr aFeature;
495   int aNb = numberOfFolders();
496   for (int i = 0; i < aSize; i++) {
497     ObjectPtr aObj = aDoc->object(aGroup, i);
498     aId = i + aNb; // Take into account existing folders
499     if (aId < myChildren.size()) {
500       if (myChildren.at(aId)->object() != aObj) {
501         aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
502         ModuleBase_ITreeNode* aNode;
503         if (aFeature->getKind() == PartSetPlugin_Part::ID())
504           aNode = new PartSet_PartRootNode(aObj, this);
505         else
506           aNode = new PartSet_ObjectNode(aObj, this);
507         myChildren.insert(aId, aNode);
508       }
509     } else {
510       aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
511       ModuleBase_ITreeNode* aNode;
512       if (aFeature->getKind() == PartSetPlugin_Part::ID())
513         aNode = new PartSet_PartRootNode(aObj, this);
514       else
515         aNode = new PartSet_ObjectNode(aObj, this);
516       myChildren.append(aNode);
517     }
518   }
519   // Update sub-folders
520   ModuleBase_ITreeNode* aSubFolder = 0;
521   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
522     aSubFolder = dynamic_cast<PartSet_PartRootNode*>(aNode);
523     if (aSubFolder)
524       aSubFolder->update();
525   }
526 }
527
528 DocumentPtr PartSet_RootNode::document() const
529 {
530   return ModelAPI_Session::get()->moduleDocument();
531 }
532
533 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
534 {
535   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
536   if (aFeature->getKind() == PartSetPlugin_Part::ID())
537     return new PartSet_PartRootNode(theObj, this);
538   else
539     return new PartSet_ObjectNode(theObj, this);
540 }
541
542 //////////////////////////////////////////////////////////////////////////////////
543 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
544   : PartSet_FeatureFolderNode(theParent), myObject(theObj)
545 {
546   myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
547   myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
548   myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
549   myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
550   myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
551
552   myChildren.append(myParamsFolder);
553   myChildren.append(myConstrFolder);
554   myChildren.append(myResultsFolder);
555
556   update();
557 }
558
559 PartSet_PartRootNode::~PartSet_PartRootNode()
560 {
561   delete myParamsFolder;
562   delete myConstrFolder;
563   delete myResultsFolder;
564   delete myFieldsFolder;
565   delete myGroupsFolder;
566 }
567
568
569 void PartSet_PartRootNode::update()
570 {
571   DocumentPtr aDoc = document();
572   if (!aDoc.get())
573     return;
574
575   myParamsFolder->update();
576   myConstrFolder->update();
577   myResultsFolder->update();
578   myFieldsFolder->update();
579   myGroupsFolder->update();
580
581   bool aHasFields = myFieldsFolder->childrenCount() > 0;
582   bool aHasGroups = myGroupsFolder->childrenCount() > 0;
583   if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
584     myChildren.insert(3, myFieldsFolder);
585   }
586   if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
587     myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
588   }
589
590   // Update features content
591   int aRows = numberOfFolders();
592
593   // Remove extra sub-nodes
594   QTreeNodesList aDelList;
595   int aIndex = -1;
596   int aId = -1;
597   foreach(ModuleBase_ITreeNode* aNode, myChildren) {
598     aId++;
599     if (aNode->object().get()) {
600       aIndex = aDoc->index(aNode->object());
601       if ((aIndex == -1) || (aId != (aIndex + aRows)))
602         aDelList.append(aNode);
603     }
604   }
605   foreach(ModuleBase_ITreeNode* aNode, aDelList) {
606     myChildren.removeAll(aNode);
607     delete aNode;
608   }
609
610   std::string aGroup = ModelAPI_Feature::group();
611   int aSize = aDoc->size(aGroup);
612   FeaturePtr aFeature;
613   for (int i = 0; i < aSize; i++) {
614     ObjectPtr aObj = aDoc->object(aGroup, i);
615     aId = i + aRows; // Take into account existing folders
616     if (aId < myChildren.size()) {
617       if (myChildren.at(aId)->object() != aObj) {
618         ModuleBase_ITreeNode* aNode = new PartSet_ObjectNode(aObj, this);
619         myChildren.insert(aId, aNode);
620       }
621     } else {
622       ModuleBase_ITreeNode* aNode = new PartSet_ObjectNode(aObj, this);
623       myChildren.append(aNode);
624     }
625   }
626 }
627
628 DocumentPtr PartSet_PartRootNode::document() const
629 {
630   ResultPartPtr aPartRes = getPartResult(myObject);
631   if (aPartRes.get())
632     return aPartRes->partDoc();
633   return DocumentPtr();
634 }
635
636 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
637 {
638   switch (theColumn) {
639   case 1:
640     switch (theRole) {
641     case Qt::DisplayRole:
642       return QString(myObject->data()->name().c_str());
643     case Qt::DecorationRole:
644       return ModuleBase_IconFactory::get()->getIcon(myObject);
645     }
646   case 2:
647     if (theRole == Qt::DecorationRole)
648       if (isCurrentFeature(myObject))
649         return QIcon(":pictures/arrow.png");
650   }
651   return PartSet_TreeNode::data(theColumn, theRole);
652 }
653
654 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
655 {
656   SessionPtr aSession = ModelAPI_Session::get();
657   DocumentPtr aActiveDoc = aSession->activeDocument();
658   if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
659     return aEditingFlag;
660   return aDefaultFlag;
661 }
662
663 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
664 {
665   return new PartSet_ObjectNode(theObj, this);
666 }
667
668 int PartSet_PartRootNode::numberOfFolders() const
669 {
670   int aNb = 3;
671   if (myFieldsFolder->childrenCount() > 0)
672     aNb++;
673   if (myGroupsFolder->childrenCount() > 0)
674     aNb++;
675   return aNb;
676 }
677
678 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
679 {
680   QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
681   if (!myFieldsFolder->childrenCount()) {
682     QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
683     if (aList.size()) {
684       myChildren.insert(3, myFieldsFolder);
685       aResult.append(myFieldsFolder);
686       aResult.append(aList);
687     }
688   }
689   if (!myGroupsFolder->childrenCount()) {
690     QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
691     if (aList.size()) {
692       myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
693       aResult.append(myGroupsFolder);
694       aResult.append(aList);
695     }
696   }
697   return aResult;
698 }
699
700 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
701   const QString& theGroup)
702 {
703   QTreeNodesList aResult;
704   if (myFieldsFolder->childrenCount()) {
705     QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
706     if (aList.size()) {
707       aResult.append(aList);
708       if (!myFieldsFolder->childrenCount())
709         myChildren.removeAll(myFieldsFolder);
710     }
711   }
712   if (myGroupsFolder->childrenCount()) {
713     QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
714     if (aList.size()) {
715       aResult.append(aList);
716       if (!myGroupsFolder->childrenCount())
717         myChildren.removeAll(myGroupsFolder);
718     }
719   }
720   aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
721   return aResult;
722 }