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 CompositeFeaturePtr aCompFeature;
193 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
196 aNb = aCompRes->numberOfSubs(true);
198 aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
199 if (aCompFeature.get())
200 aNb = aCompFeature->numberOfSubs(true);
204 ModuleBase_ITreeNode* aNode;
207 for (i = 0; i < aNb; i++) {
209 aBody = aCompRes->subResult(i, true);
211 aBody = aCompFeature->subFeature(i, true);
213 if (i < myChildren.size()) {
214 aNode = myChildren.at(i);
215 if (aNode->object() != aBody) {
216 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
219 aNode = new PartSet_ObjectNode(aBody, this);
220 myChildren.append(aNode);
223 // Delete extra objects
224 while (myChildren.size() > aNb) {
225 aNode = myChildren.takeLast();
228 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
237 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
239 QTreeNodesList aResult;
241 CompositeFeaturePtr aCompFeature;
242 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
245 aNb = aCompRes->numberOfSubs(true);
247 aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
248 if (aCompFeature.get())
249 aNb = aCompFeature->numberOfSubs(true);
253 ModuleBase_ITreeNode* aNode;
256 for (i = 0; i < aNb; i++) {
258 aBody = aCompRes->subResult(i, true);
260 aBody = aCompFeature->subFeature(i, true);
262 if (i < myChildren.size()) {
263 aNode = myChildren.at(i);
264 if (aNode->object() != aBody) {
265 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
266 aResult.append(aNode);
269 aNode = new PartSet_ObjectNode(aBody, this);
270 myChildren.append(aNode);
271 aResult.append(aNode);
275 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
276 aResult.append(aNode->objectCreated(theObjects));
282 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
283 const DocumentPtr& theDoc, const QString& theGroup)
285 QTreeNodesList aResult;
286 CompositeFeaturePtr aCompFeature;
287 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
290 aNb = aCompRes->numberOfSubs(true);
292 aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
293 if (aCompFeature.get())
294 aNb = aCompFeature->numberOfSubs(true);
298 ModuleBase_ITreeNode* aNode;
299 // Delete extra objects
300 bool isDeleted = false;
301 while (myChildren.size() > aNb) {
302 aNode = myChildren.takeLast();
307 aResult.append(this);
310 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
312 aBody = aCompRes->subResult(i, true);
314 aBody = aCompFeature->subFeature(i, true);
316 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
317 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
323 //////////////////////////////////////////////////////////////////////////////////
324 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
326 : PartSet_TreeNode(theParent), myType(theType)
330 QString PartSet_FolderNode::name() const
333 case ParametersFolder:
334 return QObject::tr("Parameters");
335 case ConstructionFolder:
336 return QObject::tr("Constructions");
338 return QObject::tr("Parts");
340 return QObject::tr("Results");
342 return QObject::tr("Fields");
344 return QObject::tr("Groups");
350 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
352 static QIcon aParamsIco(":pictures/params_folder.png");
353 static QIcon aConstrIco(":pictures/constr_folder.png");
355 if (theColumn == 1) {
357 case Qt::DisplayRole:
358 return name() + QString(" (%1)").arg(childrenCount());
359 case Qt::DecorationRole:
361 case ParametersFolder:
363 case ConstructionFolder:
376 return PartSet_TreeNode::data(theColumn, theRole);
379 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
381 SessionPtr aSession = ModelAPI_Session::get();
382 DocumentPtr aActiveDoc = aSession->activeDocument();
383 if (theColumn == 1) {
384 if (document() == aActiveDoc)
390 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
392 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
393 //if (aCompRes.get())
394 // return new PartSet_CompsolidNode(theObj, this);
395 return new PartSet_ObjectNode(theObj, this);
398 void PartSet_FolderNode::update()
400 DocumentPtr aDoc = document();
404 // Remove extra sub-nodes
407 while (aId < myChildren.size()) {
408 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
409 aIndex = aDoc->index(aNode->object(), true);
410 if ((aIndex == -1) || (aId != aIndex)) {
411 myChildren.removeAll(aNode);
418 std::string aGroup = groupName();
419 int aSize = aDoc->size(aGroup, true);
420 for (int i = 0; i < aSize; i++) {
421 ObjectPtr aObj = aDoc->object(aGroup, i, true);
422 if (i < myChildren.size()) {
423 if (myChildren.at(i)->object() != aObj) {
424 ModuleBase_ITreeNode* aNode = createNode(aObj);
425 myChildren.insert(i, aNode);
428 ModuleBase_ITreeNode* aNode = createNode(aObj);
429 myChildren.append(aNode);
433 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
438 std::string PartSet_FolderNode::groupName() const
441 case ParametersFolder:
442 return ModelAPI_ResultParameter::group();
443 case ConstructionFolder:
444 return ModelAPI_ResultConstruction::group();
446 return ModelAPI_ResultPart::group();
448 return ModelAPI_ResultBody::group();
450 return ModelAPI_ResultField::group();
452 return ModelAPI_ResultGroup::group();
457 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
459 QTreeNodesList aResult;
460 std::string aName = groupName();
461 DocumentPtr aDoc = document();
463 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
464 foreach(ObjectPtr aObj, theObjects) {
465 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
466 aIdx = aDoc->index(aObj, true);
468 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
470 ModuleBase_ITreeNode* aNode = createNode(aObj);
471 aNewNodes[aIdx] = aNode;
472 aResult.append(aNode);
478 // Add nodes in correct order
480 for (i = 0; i < myChildren.size(); i++) {
481 if (aNewNodes.contains(i)) {
482 myChildren.insert(i, aNewNodes[i]);
486 while (aNewNodes.size()) {
487 i = myChildren.size();
488 myChildren.append(aNewNodes[i]);
491 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
492 aResult.append(aNode->objectCreated(theObjects));
497 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
498 const QString& theGroup)
500 DocumentPtr aDoc = document();
501 QTreeNodesList aResult;
502 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
503 QTreeNodesList aDelList;
506 bool aRemoved = false;
507 while (aId < myChildren.size()) {
508 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
509 aIndex = aDoc->index(aNode->object(), true);
510 if ((aIndex == -1) || (aId != aIndex)) {
511 myChildren.removeAll(aNode);
518 aResult.append(this);
520 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
521 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
527 //////////////////////////////////////////////////////////////////////////////////
528 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
530 QTreeNodesList aResult;
531 // Process the root sub-objects
532 DocumentPtr aDoc = document();
534 int aNb = numberOfFolders();
535 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
536 foreach(ObjectPtr aObj, theObjects) {
537 if (aDoc == aObj->document()) {
538 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
539 (aObj->groupName() == ModelAPI_Folder::group())){
540 aIdx = aDoc->index(aObj, true);
542 ModuleBase_ITreeNode* aNode = createNode(aObj);
544 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
546 aNewNodes[aIdx] = aNode;
547 aResult.append(aNode);
554 // To add in correct order
556 for (i = 0; i < myChildren.size(); i++) {
557 if (aNewNodes.contains(i)) {
558 myChildren.insert(i, aNewNodes[i]);
562 while (aNewNodes.size()) {
563 i = myChildren.size();
564 myChildren.append(aNewNodes[i]);
568 // Update sub-folders
569 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
570 aResult.append(aNode->objectCreated(theObjects));
575 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
576 const QString& theGroup)
578 QTreeNodesList aResult;
580 // Process sub-folders
581 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
582 if (aNode->childrenCount() > 0) { // aFolder node
583 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
584 if (aList.size() > 0)
585 aResult.append(aList);
590 DocumentPtr aDoc = document();
591 int aNb = numberOfFolders();
592 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
593 (theGroup.toStdString() == ModelAPI_Folder::group()));
594 if ((theDoc == aDoc) && isGroup) {
597 bool aRemoved = false;
598 while (aId < myChildren.size()) {
599 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
600 if (aNode->object().get()) {
601 aIndex = aDoc->index(aNode->object(), true);
602 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
603 myChildren.removeAll(aNode);
612 aResult.append(this);
617 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
620 ModuleBase_ITreeNode* aResult = 0;
621 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
622 aResult = aNode->findParent(theDoc, theGroup);
627 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
628 (theGroup.toStdString() == ModelAPI_Folder::group()));
629 if ((theDoc == document()) && isGroup)
635 //////////////////////////////////////////////////////////////////////////////////
636 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
638 SessionPtr aSession = ModelAPI_Session::get();
639 DocumentPtr aDoc = aSession->moduleDocument();
641 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
642 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
643 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
645 myChildren.append(myParamsFolder);
646 myChildren.append(myConstrFolder);
647 myChildren.append(myPartsFolder);
653 void PartSet_RootNode::update()
655 myParamsFolder->update();
656 myConstrFolder->update();
657 myPartsFolder->update();
659 // Update features content
660 DocumentPtr aDoc = document();
661 int aNb = numberOfFolders();
663 // Remove extra sub-nodes
666 while (aId < myChildren.size()) {
667 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
668 if (aNode->object().get()) {
669 aIndex = aDoc->index(aNode->object(), true);
670 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
671 myChildren.removeAll(aNode);
680 std::string aGroup = ModelAPI_Feature::group();
681 int aSize = aDoc->size(aGroup, true);
683 for (int i = 0; i < aSize; i++) {
684 ObjectPtr aObj = aDoc->object(aGroup, i, true);
685 aId = i + aNb; // Take into account existing folders
686 if (aId < myChildren.size()) {
687 if (myChildren.at(aId)->object() != aObj) {
688 ModuleBase_ITreeNode* aNode = createNode(aObj);
689 myChildren.insert(aId, aNode);
692 ModuleBase_ITreeNode* aNode = createNode(aObj);
693 myChildren.append(aNode);
696 // Update sub-folders
697 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
698 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
699 (aNode->type() == PartSet_PartRootNode::typeId()))
704 DocumentPtr PartSet_RootNode::document() const
706 return ModelAPI_Session::get()->moduleDocument();
709 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
711 if (theObj->groupName() == ModelAPI_Folder::group())
712 return new PartSet_ObjectFolderNode(theObj, this);
714 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
715 if (aFeature->getKind() == PartSetPlugin_Part::ID())
716 return new PartSet_PartRootNode(theObj, this);
718 return new PartSet_ObjectNode(theObj, this);
721 //////////////////////////////////////////////////////////////////////////////////
722 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
723 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
725 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
726 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
727 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
728 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
729 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
731 myChildren.append(myParamsFolder);
732 myChildren.append(myConstrFolder);
733 myChildren.append(myResultsFolder);
738 void PartSet_PartRootNode::deleteChildren()
740 if (!myFieldsFolder->childrenCount()) {
741 delete myFieldsFolder;
743 if (!myGroupsFolder->childrenCount()) {
744 delete myGroupsFolder;
746 PartSet_FeatureFolderNode::deleteChildren();
750 void PartSet_PartRootNode::update()
752 DocumentPtr aDoc = document();
756 myParamsFolder->update();
757 myConstrFolder->update();
758 myResultsFolder->update();
759 myFieldsFolder->update();
760 myGroupsFolder->update();
762 bool aHasFields = myFieldsFolder->childrenCount() > 0;
763 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
764 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
765 myChildren.insert(3, myFieldsFolder);
767 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
768 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
771 // Update features content
772 int aRows = numberOfFolders();
774 // Remove extra sub-nodes
777 while (aId < myChildren.size()) {
778 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
779 if (aNode->object().get()) {
780 aIndex = aDoc->index(aNode->object(), true);
781 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
782 myChildren.removeAll(aNode);
790 std::string aGroup = ModelAPI_Feature::group();
791 int aSize = aDoc->size(aGroup, true);
793 for (int i = 0; i < aSize; i++) {
794 ObjectPtr aObj = aDoc->object(aGroup, i, true);
795 aId = i + aRows; // Take into account existing folders
796 if (aId < myChildren.size()) {
797 if (myChildren.at(aId)->object() != aObj) {
798 ModuleBase_ITreeNode* aNode = createNode(aObj);
799 myChildren.insert(aId, aNode);
802 ModuleBase_ITreeNode* aNode = createNode(aObj);
803 myChildren.append(aNode);
806 // Update sub-folders
807 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
808 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
813 DocumentPtr PartSet_PartRootNode::document() const
815 ResultPartPtr aPartRes = getPartResult(myObject);
817 return aPartRes->partDoc();
818 return DocumentPtr();
821 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
826 case Qt::DisplayRole:
827 return QString(myObject->data()->name().c_str());
828 case Qt::DecorationRole:
829 return ModuleBase_IconFactory::get()->getIcon(myObject);
832 if (theRole == Qt::DecorationRole)
833 if (isCurrentFeature(myObject))
834 return QIcon(":pictures/arrow.png");
836 return PartSet_TreeNode::data(theColumn, theRole);
839 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
841 SessionPtr aSession = ModelAPI_Session::get();
842 DocumentPtr aActiveDoc = aSession->activeDocument();
843 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
848 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
850 if (theObj->groupName() == ModelAPI_Folder::group())
851 return new PartSet_ObjectFolderNode(theObj, this);
852 return new PartSet_ObjectNode(theObj, this);
855 int PartSet_PartRootNode::numberOfFolders() const
858 if (myFieldsFolder->childrenCount() > 0)
860 if (myGroupsFolder->childrenCount() > 0)
865 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
867 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
868 if (!myFieldsFolder->childrenCount()) {
869 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
871 myChildren.insert(3, myFieldsFolder);
872 aResult.append(myFieldsFolder);
873 aResult.append(aList);
876 if (!myGroupsFolder->childrenCount()) {
877 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
879 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
880 aResult.append(myGroupsFolder);
881 aResult.append(aList);
887 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
888 const QString& theGroup)
890 QTreeNodesList aResult;
891 if (myFieldsFolder->childrenCount()) {
892 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
894 aResult.append(aList);
895 if (!myFieldsFolder->childrenCount())
896 myChildren.removeAll(myFieldsFolder);
899 if (myGroupsFolder->childrenCount()) {
900 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
902 aResult.append(aList);
903 if (!myGroupsFolder->childrenCount())
904 myChildren.removeAll(myGroupsFolder);
907 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
911 //////////////////////////////////////////////////////////////////////////////////
912 void PartSet_ObjectFolderNode::update()
915 getFirstAndLastIndex(aFirst, aLast);
916 if ((aFirst == -1) || (aLast == -1)) {
921 int aNbItems = aLast - aFirst + 1;
927 DocumentPtr aDoc = myObject->document();
928 // Delete obsolete nodes
930 while (aId < myChildren.size()) {
931 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
932 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
933 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
934 myChildren.removeAll(aNode);
943 ModuleBase_ITreeNode* aNode;
944 for (int i = 0; i < aNbItems; i++) {
945 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
946 if (i < myChildren.size()) {
947 if (aObj != myChildren.at(i)->object()) {
948 aNode = new PartSet_ObjectNode(aObj, this);
949 myChildren.insert(i, aNode);
952 aNode = new PartSet_ObjectNode(aObj, this);
953 myChildren.append(aNode);
958 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
960 QTreeNodesList aResult;
962 getFirstAndLastIndex(aFirst, aLast);
963 if ((aFirst == -1) || (aLast == -1)) {
966 int aNbItems = aLast - aFirst + 1;
970 DocumentPtr aDoc = myObject->document();
972 ModuleBase_ITreeNode* aNode;
973 for (int i = 0; i < aNbItems; i++) {
974 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
975 if (i < myChildren.size()) {
976 if (aObj != myChildren.at(i)->object()) {
977 aNode = new PartSet_ObjectNode(aObj, this);
978 myChildren.insert(i, aNode);
979 aResult.append(aNode);
982 aNode = new PartSet_ObjectNode(aObj, this);
983 myChildren.append(aNode);
984 aResult.append(aNode);
990 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
991 const QString& theGroup)
993 QTreeNodesList aResult;
995 getFirstAndLastIndex(aFirst, aLast);
996 if ((aFirst == -1) || (aLast == -1)) {
999 int aNbItems = aLast - aFirst + 1;
1003 DocumentPtr aDoc = myObject->document();
1004 // Delete obsolete nodes
1005 bool aRemoved = false;
1007 while (aId < myChildren.size()) {
1008 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1009 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
1010 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1011 myChildren.removeAll(aNode);
1020 aResult.append(this);
1025 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
1027 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1028 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
1030 return ModelAPI_Feature::feature(aFeatAttr->value());
1031 return FeaturePtr();
1034 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
1036 DocumentPtr aDoc = myObject->document();
1037 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1039 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1040 if (!aFirstFeatureInFolder.get()) {
1044 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1045 if (!aLastFeatureInFolder.get()) {
1050 theFirst = aDoc->index(aFirstFeatureInFolder);
1051 theLast = aDoc->index(aLastFeatureInFolder);