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 #include "PartSet_TreeNodes.h"
23 #include <ModuleBase_IconFactory.h>
24 #include <ModuleBase_IWorkshop.h>
26 #include <PartSetPlugin_Part.h>
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_Tools.h>
36 #include <ModelAPI_ResultBody.h>
37 #include <ModelAPI_CompositeFeature.h>
38 #include <ModelAPI_AttributeDouble.h>
39 #include <ModelAPI_Folder.h>
40 #include <ModelAPI_AttributeReference.h>
46 #define ACTIVE_COLOR QColor(Qt::black)
47 #define SELECTABLE_COLOR QColor(100, 100, 100)
48 #define DISABLED_COLOR QColor(200, 200, 200)
50 Qt::ItemFlags aNullFlag;
51 Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
52 Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
55 ResultPartPtr getPartResult(const ObjectPtr& theObj)
57 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
59 ResultPtr aRes = aFeature->firstResult();
60 if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
61 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
62 // Use only original parts, not a placement results
63 if (aPartRes == aPartRes->original())
67 return ResultPartPtr();
70 bool isCurrentFeature(const ObjectPtr& theObj)
72 SessionPtr aSession = ModelAPI_Session::get();
73 DocumentPtr aCurDoc = aSession->activeDocument();
74 FeaturePtr aFeature = aCurDoc->currentFeature(true);
75 return aFeature == theObj;
78 //////////////////////////////////////////////////////////////////////////////////
79 QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
81 if ((theColumn == 1) && (theRole == Qt::ForegroundRole)) {
82 Qt::ItemFlags aFlags = flags(theColumn);
83 if (aFlags == Qt::ItemFlags())
84 return QBrush(DISABLED_COLOR);
85 if (!aFlags.testFlag(Qt::ItemIsEditable))
86 return QBrush(SELECTABLE_COLOR);
89 return ModuleBase_ITreeNode::data(theColumn, theRole);
93 //////////////////////////////////////////////////////////////////////////////////
94 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
99 if (myObject->groupName() == ModelAPI_ResultParameter::group()) {
100 ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myObject);
101 AttributeDoublePtr aValueAttribute =
102 aParam->data()->real(ModelAPI_ResultParameter::VALUE());
103 QString aVal = QString::number(aValueAttribute->value());
104 QString aTitle = QString(myObject->data()->name().c_str());
105 return aTitle + " = " + aVal;
107 return myObject->data()->name().c_str();
110 case Qt::DecorationRole:
113 switch (visibilityState()) {
117 return QIcon(":pictures/eyeopen.png");
119 return QIcon(":pictures/eyemiclosed.png");
121 return QIcon(":pictures/eyeclosed.png");
124 if (myObject->groupName() == ModelAPI_Folder::group())
125 return QIcon(":pictures/features_folder.png");
127 return ModuleBase_IconFactory::get()->getIcon(myObject);
129 if (isCurrentFeature(myObject))
130 return QIcon(":pictures/arrow.png");
133 return PartSet_TreeNode::data(theColumn, theRole);
136 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
138 if (myObject->isDisabled()) {
139 return (theColumn == 2) ? Qt::ItemIsSelectable : aNullFlag;
141 DocumentPtr aDoc = myObject->document();
142 SessionPtr aSession = ModelAPI_Session::get();
143 if (aSession->activeDocument() == aDoc)
149 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
151 Qt::ItemFlags aFlags = flags(1);
152 if (aFlags == Qt::ItemFlags())
155 if (myObject->groupName() == ModelAPI_ResultParameter::group())
157 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
159 ModuleBase_IWorkshop* aWork = workshop();
160 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResObj);
161 if (aCompRes.get()) {
162 VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
163 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
164 std::list<ResultPtr> aResultsList;
165 ModelAPI_Tools::allSubs(aCompRes, aResultsList);
167 std::list<ResultPtr>::const_iterator aIt;
168 //for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
169 for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
170 ResultPtr aSubRes = (*aIt); // aCompRes->subResult(i, true);
171 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
172 if (aState == NoneState)
174 else if (aState != aS) {
175 aState = SemiVisible;
181 if (aWork->isVisible(aResObj))
190 void PartSet_ObjectNode::update()
192 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
193 if (aCompRes.get()) {
194 int aNb = aCompRes->numberOfSubs(true);
195 ModuleBase_ITreeNode* aNode;
198 for (i = 0; i < aNb; i++) {
199 aBody = aCompRes->subResult(i, true);
200 if (i < myChildren.size()) {
201 aNode = myChildren.at(i);
202 if (aNode->object() != aBody) {
203 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
206 aNode = new PartSet_ObjectNode(aBody, this);
207 myChildren.append(aNode);
210 // Delete extra objects
211 while (myChildren.size() > aNb) {
212 aNode = myChildren.takeLast();
215 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
221 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
223 QTreeNodesList aResult;
225 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
226 if (aCompRes.get()) {
227 int aNb = aCompRes->numberOfSubs(true);
228 ModuleBase_ITreeNode* aNode;
231 for (i = 0; i < aNb; i++) {
232 aBody = aCompRes->subResult(i, true);
233 if (i < myChildren.size()) {
234 aNode = myChildren.at(i);
235 if (aNode->object() != aBody) {
236 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
237 aResult.append(aNode);
240 aNode = new PartSet_ObjectNode(aBody, this);
241 myChildren.append(aNode);
242 aResult.append(aNode);
245 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
246 aResult.append(aNode->objectCreated(theObjects));
252 QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
254 QTreeNodesList aResult;
255 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
256 if (aCompRes.get()) {
257 int aNb = aCompRes->numberOfSubs(true);
258 ModuleBase_ITreeNode* aNode;
259 // Delete extra objects
260 bool isDeleted = false;
261 while (myChildren.size() > aNb) {
262 aNode = myChildren.takeLast();
267 aResult.append(this);
269 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
270 ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true));
271 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
277 //////////////////////////////////////////////////////////////////////////////////
278 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
280 : PartSet_TreeNode(theParent), myType(theType)
284 QString PartSet_FolderNode::name() const
287 case ParametersFolder:
288 return QObject::tr("Parameters");
289 case ConstructionFolder:
290 return QObject::tr("Constructions");
292 return QObject::tr("Parts");
294 return QObject::tr("Results");
296 return QObject::tr("Fields");
298 return QObject::tr("Groups");
304 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
306 static QIcon aParamsIco(":pictures/params_folder.png");
307 static QIcon aConstrIco(":pictures/constr_folder.png");
309 if (theColumn == 1) {
311 case Qt::DisplayRole:
312 return name() + QString(" (%1)").arg(childrenCount());
313 case Qt::DecorationRole:
315 case ParametersFolder:
317 case ConstructionFolder:
330 return PartSet_TreeNode::data(theColumn, theRole);
333 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
335 SessionPtr aSession = ModelAPI_Session::get();
336 DocumentPtr aActiveDoc = aSession->activeDocument();
337 if (theColumn == 1) {
338 if (document() == aActiveDoc)
344 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
346 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
347 //if (aCompRes.get())
348 // return new PartSet_CompsolidNode(theObj, this);
349 return new PartSet_ObjectNode(theObj, this);
352 void PartSet_FolderNode::update()
354 DocumentPtr aDoc = document();
358 // Remove extra sub-nodes
361 while (aId < myChildren.size()) {
362 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
363 aIndex = aDoc->index(aNode->object(), true);
364 if ((aIndex == -1) || (aId != aIndex)) {
365 myChildren.removeAll(aNode);
372 std::string aGroup = groupName();
373 int aSize = aDoc->size(aGroup, true);
374 for (int i = 0; i < aSize; i++) {
375 ObjectPtr aObj = aDoc->object(aGroup, i, true);
376 if (i < myChildren.size()) {
377 if (myChildren.at(i)->object() != aObj) {
378 ModuleBase_ITreeNode* aNode = createNode(aObj);
379 myChildren.insert(i, aNode);
382 ModuleBase_ITreeNode* aNode = createNode(aObj);
383 myChildren.append(aNode);
387 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
392 std::string PartSet_FolderNode::groupName() const
395 case ParametersFolder:
396 return ModelAPI_ResultParameter::group();
397 case ConstructionFolder:
398 return ModelAPI_ResultConstruction::group();
400 return ModelAPI_ResultPart::group();
402 return ModelAPI_ResultBody::group();
404 return ModelAPI_ResultField::group();
406 return ModelAPI_ResultGroup::group();
411 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
413 QTreeNodesList aResult;
414 std::string aName = groupName();
415 DocumentPtr aDoc = document();
417 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
418 foreach(ObjectPtr aObj, theObjects) {
419 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
420 aIdx = aDoc->index(aObj, true);
422 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
424 ModuleBase_ITreeNode* aNode = createNode(aObj);
425 aNewNodes[aIdx] = aNode;
426 aResult.append(aNode);
431 // Add nodes in correct order
433 for (i = 0; i < myChildren.size(); i++) {
434 if (aNewNodes.contains(i)) {
435 myChildren.insert(i, aNewNodes[i]);
439 while (aNewNodes.size()) {
440 i = myChildren.size();
441 myChildren.append(aNewNodes[i]);
444 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
445 aResult.append(aNode->objectCreated(theObjects));
450 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
451 const QString& theGroup)
453 DocumentPtr aDoc = document();
454 QTreeNodesList aResult;
455 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
456 QTreeNodesList aDelList;
459 bool aRemoved = false;
460 while (aId < myChildren.size()) {
461 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
462 aIndex = aDoc->index(aNode->object(), true);
463 if ((aIndex == -1) || (aId != aIndex)) {
464 myChildren.removeAll(aNode);
471 aResult.append(this);
473 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
474 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
480 //////////////////////////////////////////////////////////////////////////////////
481 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
483 QTreeNodesList aResult;
484 // Process all folders
485 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
486 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
487 aResult.append(aNode->objectCreated(theObjects));
490 // Process the root sub-objects
491 DocumentPtr aDoc = document();
493 int aNb = numberOfFolders();
494 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
495 foreach(ObjectPtr aObj, theObjects) {
496 if (aDoc == aObj->document()) {
497 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
498 (aObj->groupName() == ModelAPI_Folder::group())){
499 ModuleBase_ITreeNode* aNode = createNode(aObj);
500 aIdx = aDoc->index(aObj, true);
503 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
505 aNewNodes[aIdx] = aNode;
506 aResult.append(aNode);
512 // To add in correct order
514 for (i = 0; i < myChildren.size(); i++) {
515 if (aNewNodes.contains(i)) {
516 myChildren.insert(i, aNewNodes[i]);
520 while (aNewNodes.size()) {
521 i = myChildren.size();
522 myChildren.append(aNewNodes[i]);
526 // Update sub-folders
527 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
528 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
529 (aNode->type() == PartSet_PartRootNode::typeId()))
530 aResult.append(aNode->objectCreated(theObjects));
535 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
536 const QString& theGroup)
538 QTreeNodesList aResult;
540 // Process sub-folders
541 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
542 if (aNode->childrenCount() > 0) { // aFolder node
543 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
544 if (aList.size() > 0)
545 aResult.append(aList);
550 DocumentPtr aDoc = document();
551 int aNb = numberOfFolders();
552 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
553 (theGroup.toStdString() == ModelAPI_Folder::group()));
554 if ((theDoc == aDoc) && isGroup) {
557 bool aRemoved = false;
558 while (aId < myChildren.size()) {
559 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
560 if (aNode->object().get()) {
561 aIndex = aDoc->index(aNode->object(), true);
562 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
563 myChildren.removeAll(aNode);
572 aResult.append(this);
577 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
580 ModuleBase_ITreeNode* aResult = 0;
581 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
582 aResult = aNode->findParent(theDoc, theGroup);
587 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
588 (theGroup.toStdString() == ModelAPI_Folder::group()));
589 if ((theDoc == document()) && isGroup)
595 //////////////////////////////////////////////////////////////////////////////////
596 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
598 SessionPtr aSession = ModelAPI_Session::get();
599 DocumentPtr aDoc = aSession->moduleDocument();
601 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
602 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
603 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
605 myChildren.append(myParamsFolder);
606 myChildren.append(myConstrFolder);
607 myChildren.append(myPartsFolder);
613 void PartSet_RootNode::update()
615 myParamsFolder->update();
616 myConstrFolder->update();
617 myPartsFolder->update();
619 // Update features content
620 DocumentPtr aDoc = document();
621 int aNb = numberOfFolders();
623 // Remove extra sub-nodes
626 while (aId < myChildren.size()) {
627 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
628 if (aNode->object().get()) {
629 aIndex = aDoc->index(aNode->object(), true);
630 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
631 myChildren.removeAll(aNode);
640 std::string aGroup = ModelAPI_Feature::group();
641 int aSize = aDoc->size(aGroup, true);
643 for (int i = 0; i < aSize; i++) {
644 ObjectPtr aObj = aDoc->object(aGroup, i, true);
645 aId = i + aNb; // Take into account existing folders
646 if (aId < myChildren.size()) {
647 if (myChildren.at(aId)->object() != aObj) {
648 ModuleBase_ITreeNode* aNode = createNode(aObj);
649 myChildren.insert(aId, aNode);
652 ModuleBase_ITreeNode* aNode = createNode(aObj);
653 myChildren.append(aNode);
656 // Update sub-folders
657 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
658 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
659 (aNode->type() == PartSet_PartRootNode::typeId()))
664 DocumentPtr PartSet_RootNode::document() const
666 return ModelAPI_Session::get()->moduleDocument();
669 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
671 if (theObj->groupName() == ModelAPI_Folder::group())
672 return new PartSet_ObjectFolderNode(theObj, this);
674 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
675 if (aFeature->getKind() == PartSetPlugin_Part::ID())
676 return new PartSet_PartRootNode(theObj, this);
678 return new PartSet_ObjectNode(theObj, this);
681 //////////////////////////////////////////////////////////////////////////////////
682 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
683 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
685 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
686 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
687 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
688 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
689 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
691 myChildren.append(myParamsFolder);
692 myChildren.append(myConstrFolder);
693 myChildren.append(myResultsFolder);
698 void PartSet_PartRootNode::deleteChildren()
700 if (!myFieldsFolder->childrenCount()) {
701 delete myFieldsFolder;
703 if (!myGroupsFolder->childrenCount()) {
704 delete myGroupsFolder;
706 PartSet_FeatureFolderNode::deleteChildren();
710 void PartSet_PartRootNode::update()
712 DocumentPtr aDoc = document();
716 myParamsFolder->update();
717 myConstrFolder->update();
718 myResultsFolder->update();
719 myFieldsFolder->update();
720 myGroupsFolder->update();
722 bool aHasFields = myFieldsFolder->childrenCount() > 0;
723 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
724 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
725 myChildren.insert(3, myFieldsFolder);
727 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
728 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
731 // Update features content
732 int aRows = numberOfFolders();
734 // Remove extra sub-nodes
737 while (aId < myChildren.size()) {
738 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
739 if (aNode->object().get()) {
740 aIndex = aDoc->index(aNode->object(), true);
741 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
742 myChildren.removeAll(aNode);
750 std::string aGroup = ModelAPI_Feature::group();
751 int aSize = aDoc->size(aGroup, true);
753 for (int i = 0; i < aSize; i++) {
754 ObjectPtr aObj = aDoc->object(aGroup, i, true);
755 aId = i + aRows; // Take into account existing folders
756 if (aId < myChildren.size()) {
757 if (myChildren.at(aId)->object() != aObj) {
758 ModuleBase_ITreeNode* aNode = createNode(aObj);
759 myChildren.insert(aId, aNode);
762 ModuleBase_ITreeNode* aNode = createNode(aObj);
763 myChildren.append(aNode);
766 // Update sub-folders
767 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
768 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
773 DocumentPtr PartSet_PartRootNode::document() const
775 ResultPartPtr aPartRes = getPartResult(myObject);
777 return aPartRes->partDoc();
778 return DocumentPtr();
781 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
786 case Qt::DisplayRole:
787 return QString(myObject->data()->name().c_str());
788 case Qt::DecorationRole:
789 return ModuleBase_IconFactory::get()->getIcon(myObject);
792 if (theRole == Qt::DecorationRole)
793 if (isCurrentFeature(myObject))
794 return QIcon(":pictures/arrow.png");
796 return PartSet_TreeNode::data(theColumn, theRole);
799 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
801 SessionPtr aSession = ModelAPI_Session::get();
802 DocumentPtr aActiveDoc = aSession->activeDocument();
803 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
808 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
810 if (theObj->groupName() == ModelAPI_Folder::group())
811 return new PartSet_ObjectFolderNode(theObj, this);
812 return new PartSet_ObjectNode(theObj, this);
815 int PartSet_PartRootNode::numberOfFolders() const
818 if (myFieldsFolder->childrenCount() > 0)
820 if (myGroupsFolder->childrenCount() > 0)
825 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
827 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
828 if (!myFieldsFolder->childrenCount()) {
829 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
831 myChildren.insert(3, myFieldsFolder);
832 aResult.append(myFieldsFolder);
833 aResult.append(aList);
836 if (!myGroupsFolder->childrenCount()) {
837 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
839 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
840 aResult.append(myGroupsFolder);
841 aResult.append(aList);
847 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
848 const QString& theGroup)
850 QTreeNodesList aResult;
851 if (myFieldsFolder->childrenCount()) {
852 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
854 aResult.append(aList);
855 if (!myFieldsFolder->childrenCount())
856 myChildren.removeAll(myFieldsFolder);
859 if (myGroupsFolder->childrenCount()) {
860 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
862 aResult.append(aList);
863 if (!myGroupsFolder->childrenCount())
864 myChildren.removeAll(myGroupsFolder);
867 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
871 //////////////////////////////////////////////////////////////////////////////////
872 void PartSet_ObjectFolderNode::update()
875 getFirstAndLastIndex(aFirst, aLast);
876 if ((aFirst == -1) || (aLast == -1)) {
881 int aNbItems = aLast - aFirst + 1;
887 DocumentPtr aDoc = myObject->document();
888 // Delete obsolete nodes
890 while (aId < myChildren.size()) {
891 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
892 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
893 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
894 myChildren.removeAll(aNode);
903 ModuleBase_ITreeNode* aNode;
904 for (int i = 0; i < aNbItems; i++) {
905 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
906 if (i < myChildren.size()) {
907 if (aObj != myChildren.at(i)->object()) {
908 aNode = new PartSet_ObjectNode(aObj, this);
909 myChildren.insert(i, aNode);
912 aNode = new PartSet_ObjectNode(aObj, this);
913 myChildren.append(aNode);
918 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
920 QTreeNodesList aResult;
922 getFirstAndLastIndex(aFirst, aLast);
923 if ((aFirst == -1) || (aLast == -1)) {
926 int aNbItems = aLast - aFirst + 1;
930 DocumentPtr aDoc = myObject->document();
932 ModuleBase_ITreeNode* aNode;
933 for (int i = 0; i < aNbItems; i++) {
934 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
935 if (i < myChildren.size()) {
936 if (aObj != myChildren.at(i)->object()) {
937 aNode = new PartSet_ObjectNode(aObj, this);
938 myChildren.insert(i, aNode);
939 aResult.append(aNode);
942 aNode = new PartSet_ObjectNode(aObj, this);
943 myChildren.append(aNode);
944 aResult.append(aNode);
950 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
951 const QString& theGroup)
953 QTreeNodesList aResult;
955 getFirstAndLastIndex(aFirst, aLast);
956 if ((aFirst == -1) || (aLast == -1)) {
959 int aNbItems = aLast - aFirst + 1;
963 DocumentPtr aDoc = myObject->document();
964 // Delete obsolete nodes
965 bool aRemoved = false;
967 while (aId < myChildren.size()) {
968 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
969 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
970 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
971 myChildren.removeAll(aNode);
980 aResult.append(this);
985 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
987 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
988 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
990 return ModelAPI_Feature::feature(aFeatAttr->value());
994 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
996 DocumentPtr aDoc = myObject->document();
997 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
999 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1000 if (!aFirstFeatureInFolder.get()) {
1004 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1005 if (!aLastFeatureInFolder.get()) {
1010 theFirst = aDoc->index(aFirstFeatureInFolder);
1011 theLast = aDoc->index(aLastFeatureInFolder);
1015 //////////////////////////////////////////////////////////////////////////////////
1016 //PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
1017 // ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
1022 //void PartSet_CompsolidNode::update()
1024 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1025 // int aNb = aCompRes->numberOfSubs(true);
1026 // ModuleBase_ITreeNode* aNode;
1027 // ResultBodyPtr aBody;
1029 // for (i = 0; i < aNb; i++) {
1030 // aBody = aCompRes->subResult(i, true);
1031 // if (i < myChildren.size()) {
1032 // aNode = myChildren.at(i);
1033 // if (aNode->object() != aBody) {
1034 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1037 // aNode = new PartSet_ObjectNode(aBody, this);
1038 // myChildren.append(aNode);
1041 // // Delete extra objects
1042 // while (myChildren.size() > aNb) {
1043 // aNode = myChildren.takeLast();
1048 //QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
1050 // QTreeNodesList aResult;
1052 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1053 // int aNb = aCompRes->numberOfSubs(true);
1054 // ModuleBase_ITreeNode* aNode;
1055 // ResultBodyPtr aBody;
1057 // for (i = 0; i < aNb; i++) {
1058 // aBody = aCompRes->subResult(i, true);
1059 // if (i < myChildren.size()) {
1060 // aNode = myChildren.at(i);
1061 // if (aNode->object() != aBody) {
1062 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1063 // aResult.append(aNode);
1066 // aNode = new PartSet_ObjectNode(aBody, this);
1067 // myChildren.append(aNode);
1068 // aResult.append(aNode);
1074 //QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
1076 // QTreeNodesList aResult;
1077 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1078 // int aNb = aCompRes->numberOfSubs(true);
1079 // ModuleBase_ITreeNode* aNode;
1080 // // Delete extra objects
1081 // bool isDeleted = false;
1082 // while (myChildren.size() > aNb) {
1083 // aNode = myChildren.takeLast();
1085 // isDeleted = true;
1088 // aResult.append(this);