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 std::list<ResultPtr> aResultsList;
163 ModelAPI_Tools::allSubs(aCompRes, aResultsList);
164 VisibilityState aState = aResultsList.size() == 0 ?
165 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
167 std::list<ResultPtr>::const_iterator aIt;
168 ResultBodyPtr aCompSub;
169 for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
170 ResultPtr aSubRes = (*aIt);
171 aCompSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aSubRes);
172 if (!(aCompSub.get() && aCompSub->numberOfSubs() > 0)) {
173 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
174 if (aState == NoneState)
176 else if (aState != aS) {
177 aState = SemiVisible;
184 if (aWork->isVisible(aResObj))
193 int PartSet_ObjectNode::numberOfSubs() const
195 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
197 return aCompRes->numberOfSubs(true);
199 CompositeFeaturePtr aCompFeature =
200 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
201 if (aCompFeature.get() && aCompFeature->data()->isValid())
202 return aCompFeature->numberOfSubs(true);
204 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
206 return aFieldRes->stepsSize();
213 ObjectPtr PartSet_ObjectNode::subObject(int theId) const
215 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
217 return aCompRes->subResult(theId, true);
219 CompositeFeaturePtr aCompFeature =
220 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
221 if (aCompFeature.get())
222 return aCompFeature->subFeature(theId, true);
227 void PartSet_ObjectNode::update()
229 int aNb = numberOfSubs();
231 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
233 // If the object is a field result then delete extra sub-objects
234 if (aFieldRes.get()) {
235 while (myChildren.size() > aNb) {
236 ModuleBase_ITreeNode* aNode = myChildren.last();
237 myChildren.removeAll(aNode);
243 ModuleBase_ITreeNode* aNode;
245 while (aId < myChildren.size()) {
246 aNode = myChildren.at(aId);
247 aObj = subObject(aId);
248 if (aNode->object() != aObj) {
249 myChildren.removeAll(aNode);
257 ModuleBase_ITreeNode* aNode;
260 for (i = 0; i < aNb; i++) {
261 aBody = subObject(i);
263 if (i < myChildren.size()) {
264 aNode = myChildren.at(i);
265 if (aNode->object() != aBody) {
266 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
270 aNode = new PartSet_ObjectNode(aBody, this);
271 myChildren.append(aNode);
274 else if (aFieldRes.get()) {
275 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
276 if (i < myChildren.size()) {
277 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
278 if (aStepNode->entity() != aStep) {
279 aStepNode->setEntity(aStep);
283 aNode = new PartSet_StepNode(aStep, this);
284 myChildren.append(aNode);
288 // Delete extra objects
289 while (myChildren.size() > aNb) {
290 aNode = myChildren.takeLast();
293 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
302 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
304 QTreeNodesList aResult;
305 int aNb = numberOfSubs();
307 ModuleBase_ITreeNode* aNode;
308 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
311 for (i = 0; i < aNb; i++) {
312 aBody = subObject(i);
314 if (i < myChildren.size()) {
315 aNode = myChildren.at(i);
316 if (aNode->object() != aBody) {
317 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
318 aResult.append(aNode);
322 aNode = new PartSet_ObjectNode(aBody, this);
323 myChildren.append(aNode);
324 aResult.append(aNode);
329 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
330 if (i < myChildren.size()) {
331 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
332 if (aStepNode->entity() != aStep) {
333 aStepNode->setEntity(aStep);
337 aNode = new PartSet_StepNode(aStep, this);
338 myChildren.append(aNode);
342 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
343 aResult.append(aNode->objectCreated(theObjects));
349 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
350 const DocumentPtr& theDoc, const QString& theGroup)
352 QTreeNodesList aResult;
353 int aNb = numberOfSubs();
354 if (aNb != myChildren.size()) {
357 aResult.append(this);
360 // Delete extra objects
361 bool isDeleted = false;
363 ModuleBase_ITreeNode* aNode;
365 while (aId < myChildren.size()) {
366 aNode = myChildren.at(aId);
367 aObj = subObject(aId);
368 if (aNode->object() != aObj) {
369 myChildren.removeAll(aNode);
377 aResult.append(this);
380 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
381 aBody = subObject(i);
382 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
383 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
390 //////////////////////////////////////////////////////////////////////////////////
391 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
393 : PartSet_TreeNode(theParent), myType(theType)
397 QString PartSet_FolderNode::name() const
400 case ParametersFolder:
401 return QObject::tr("Parameters");
402 case ConstructionFolder:
403 return QObject::tr("Constructions");
405 return QObject::tr("Parts");
407 return QObject::tr("Results");
409 return QObject::tr("Fields");
411 return QObject::tr("Groups");
417 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
419 static QIcon aParamsIco(":pictures/params_folder.png");
420 static QIcon aConstrIco(":pictures/constr_folder.png");
422 if (theColumn == 1) {
424 case Qt::DisplayRole:
425 return name() + QString(" (%1)").arg(childrenCount());
426 case Qt::DecorationRole:
428 case ParametersFolder:
430 case ConstructionFolder:
443 return PartSet_TreeNode::data(theColumn, theRole);
446 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
448 SessionPtr aSession = ModelAPI_Session::get();
449 DocumentPtr aActiveDoc = aSession->activeDocument();
450 if (theColumn == 1) {
451 if (document() == aActiveDoc)
457 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
459 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
460 //if (aCompRes.get())
461 // return new PartSet_CompsolidNode(theObj, this);
462 return new PartSet_ObjectNode(theObj, this);
465 void PartSet_FolderNode::update()
467 DocumentPtr aDoc = document();
471 // Remove extra sub-nodes
474 while (aId < myChildren.size()) {
475 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
476 aIndex = aDoc->index(aNode->object(), true);
477 if ((aIndex == -1) || (aId != aIndex)) {
478 myChildren.removeAll(aNode);
485 std::string aGroup = groupName();
486 int aSize = aDoc->size(aGroup, true);
487 for (int i = 0; i < aSize; i++) {
488 ObjectPtr aObj = aDoc->object(aGroup, i, true);
489 if (i < myChildren.size()) {
490 if (myChildren.at(i)->object() != aObj) {
491 ModuleBase_ITreeNode* aNode = createNode(aObj);
492 myChildren.insert(i, aNode);
495 ModuleBase_ITreeNode* aNode = createNode(aObj);
496 myChildren.append(aNode);
500 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
505 std::string PartSet_FolderNode::groupName() const
508 case ParametersFolder:
509 return ModelAPI_ResultParameter::group();
510 case ConstructionFolder:
511 return ModelAPI_ResultConstruction::group();
513 return ModelAPI_ResultPart::group();
515 return ModelAPI_ResultBody::group();
517 return ModelAPI_ResultField::group();
519 return ModelAPI_ResultGroup::group();
524 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
526 QTreeNodesList aResult;
527 std::string aName = groupName();
528 DocumentPtr aDoc = document();
530 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
531 foreach(ObjectPtr aObj, theObjects) {
532 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
533 aIdx = aDoc->index(aObj, true);
535 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
537 ModuleBase_ITreeNode* aNode = createNode(aObj);
538 aNewNodes[aIdx] = aNode;
539 aResult.append(aNode);
545 // Add nodes in correct order
547 for (i = 0; i < myChildren.size(); i++) {
548 if (aNewNodes.contains(i)) {
549 myChildren.insert(i, aNewNodes[i]);
553 while (aNewNodes.size()) {
554 i = myChildren.size();
555 myChildren.append(aNewNodes[i]);
558 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
559 aResult.append(aNode->objectCreated(theObjects));
564 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
565 const QString& theGroup)
567 DocumentPtr aDoc = document();
568 QTreeNodesList aResult;
569 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
570 QTreeNodesList aDelList;
573 bool aRemoved = false;
574 bool aToSort = false;
575 while (aId < myChildren.size()) {
576 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
577 aIndex = aDoc->index(aNode->object(), true);
578 aToSort |= ((aIndex != -1) && (aId != aIndex));
580 myChildren.removeAll(aNode);
588 aResult.append(this);
591 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
592 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
598 //////////////////////////////////////////////////////////////////////////////////
599 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
601 QTreeNodesList aResult;
602 // Process the root sub-objects
603 DocumentPtr aDoc = document();
605 int aNb = numberOfFolders();
606 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
607 foreach(ObjectPtr aObj, theObjects) {
608 if (aDoc == aObj->document()) {
609 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
610 (aObj->groupName() == ModelAPI_Folder::group())){
611 aIdx = aDoc->index(aObj, true);
613 ModuleBase_ITreeNode* aNode = createNode(aObj);
615 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
617 aNewNodes[aIdx] = aNode;
618 aResult.append(aNode);
625 // To add in correct order
627 for (i = 0; i < myChildren.size(); i++) {
628 if (aNewNodes.contains(i)) {
629 myChildren.insert(i, aNewNodes[i]);
633 while (aNewNodes.size()) {
634 i = myChildren.size();
635 myChildren.append(aNewNodes[i]);
639 // Update sub-folders
640 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
641 aResult.append(aNode->objectCreated(theObjects));
646 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
647 const QString& theGroup)
649 QTreeNodesList aResult;
651 // Process sub-folders
652 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
653 if (aNode->childrenCount() > 0) { // aFolder node
654 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
655 if (aList.size() > 0)
656 aResult.append(aList);
661 DocumentPtr aDoc = document();
662 int aNb = numberOfFolders();
663 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
664 (theGroup.toStdString() == ModelAPI_Folder::group()));
665 if ((theDoc == aDoc) && isGroup) {
668 bool aRemoved = false;
669 bool aToSort = false;
670 while (aId < myChildren.size()) {
671 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
672 if (aNode->object().get()) {
673 aIndex = aDoc->index(aNode->object(), true);
674 aToSort |= ((aIndex != -1) && (aId != (aIndex + aNb)));
676 myChildren.removeAll(aNode);
685 aResult.append(this);
692 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
695 ModuleBase_ITreeNode* aResult = 0;
696 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
697 aResult = aNode->findParent(theDoc, theGroup);
702 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
703 (theGroup.toStdString() == ModelAPI_Folder::group()));
704 if ((theDoc == document()) && isGroup)
710 //////////////////////////////////////////////////////////////////////////////////
711 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
713 SessionPtr aSession = ModelAPI_Session::get();
714 DocumentPtr aDoc = aSession->moduleDocument();
716 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
717 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
718 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
720 myChildren.append(myParamsFolder);
721 myChildren.append(myConstrFolder);
722 myChildren.append(myPartsFolder);
728 void PartSet_RootNode::update()
730 myParamsFolder->update();
731 myConstrFolder->update();
732 myPartsFolder->update();
734 // Update features content
735 DocumentPtr aDoc = document();
736 int aNb = numberOfFolders();
738 // Remove extra sub-nodes
741 while (aId < myChildren.size()) {
742 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
743 if (aNode->object().get()) {
744 aIndex = aDoc->index(aNode->object(), true);
745 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
746 myChildren.removeAll(aNode);
755 std::string aGroup = ModelAPI_Feature::group();
756 int aSize = aDoc->size(aGroup, true);
758 for (int i = 0; i < aSize; i++) {
759 ObjectPtr aObj = aDoc->object(aGroup, i, true);
760 aId = i + aNb; // Take into account existing folders
761 if (aId < myChildren.size()) {
762 if (myChildren.at(aId)->object() != aObj) {
763 ModuleBase_ITreeNode* aNode = createNode(aObj);
764 myChildren.insert(aId, aNode);
767 ModuleBase_ITreeNode* aNode = createNode(aObj);
768 myChildren.append(aNode);
771 // Update sub-folders
772 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
773 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
774 (aNode->type() == PartSet_PartRootNode::typeId()))
779 DocumentPtr PartSet_RootNode::document() const
781 return ModelAPI_Session::get()->moduleDocument();
784 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
786 if (theObj->groupName() == ModelAPI_Folder::group())
787 return new PartSet_ObjectFolderNode(theObj, this);
789 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
790 if (aFeature->getKind() == PartSetPlugin_Part::ID())
791 return new PartSet_PartRootNode(theObj, this);
793 return new PartSet_ObjectNode(theObj, this);
796 //////////////////////////////////////////////////////////////////////////////////
797 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
798 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
800 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
801 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
802 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
803 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
804 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
806 myChildren.append(myParamsFolder);
807 myChildren.append(myConstrFolder);
808 myChildren.append(myResultsFolder);
813 void PartSet_PartRootNode::deleteChildren()
815 if (!myFieldsFolder->childrenCount()) {
816 delete myFieldsFolder;
818 if (!myGroupsFolder->childrenCount()) {
819 delete myGroupsFolder;
821 PartSet_FeatureFolderNode::deleteChildren();
825 void PartSet_PartRootNode::update()
827 DocumentPtr aDoc = document();
831 myParamsFolder->update();
832 myConstrFolder->update();
833 myResultsFolder->update();
834 myFieldsFolder->update();
835 myGroupsFolder->update();
837 bool aHasFields = myFieldsFolder->childrenCount() > 0;
838 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
839 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
840 myChildren.insert(3, myFieldsFolder);
842 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
843 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
846 // Update features content
847 int aRows = numberOfFolders();
849 // Remove extra sub-nodes
852 while (aId < myChildren.size()) {
853 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
854 if (aNode->object().get()) {
855 aIndex = aDoc->index(aNode->object(), true);
856 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
857 myChildren.removeAll(aNode);
865 std::string aGroup = ModelAPI_Feature::group();
866 int aSize = aDoc->size(aGroup, true);
868 for (int i = 0; i < aSize; i++) {
869 ObjectPtr aObj = aDoc->object(aGroup, i, true);
870 aId = i + aRows; // Take into account existing folders
871 if (aId < myChildren.size()) {
872 if (myChildren.at(aId)->object() != aObj) {
873 ModuleBase_ITreeNode* aNode = createNode(aObj);
874 myChildren.insert(aId, aNode);
877 ModuleBase_ITreeNode* aNode = createNode(aObj);
878 myChildren.append(aNode);
881 // Update sub-folders
882 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
883 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
888 DocumentPtr PartSet_PartRootNode::document() const
890 ResultPartPtr aPartRes = getPartResult(myObject);
892 return aPartRes->partDoc();
893 return DocumentPtr();
896 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
901 case Qt::DisplayRole:
902 return QString(myObject->data()->name().c_str());
903 case Qt::DecorationRole:
904 return ModuleBase_IconFactory::get()->getIcon(myObject);
907 if (theRole == Qt::DecorationRole)
908 if (isCurrentFeature(myObject))
909 return QIcon(":pictures/arrow.png");
911 return PartSet_TreeNode::data(theColumn, theRole);
914 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
916 SessionPtr aSession = ModelAPI_Session::get();
917 DocumentPtr aActiveDoc = aSession->activeDocument();
918 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
923 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
925 if (theObj->groupName() == ModelAPI_Folder::group())
926 return new PartSet_ObjectFolderNode(theObj, this);
927 return new PartSet_ObjectNode(theObj, this);
930 int PartSet_PartRootNode::numberOfFolders() const
933 if (myFieldsFolder->childrenCount() > 0)
935 if (myGroupsFolder->childrenCount() > 0)
940 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
942 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
943 if (!myFieldsFolder->childrenCount()) {
944 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
946 myChildren.insert(3, myFieldsFolder);
947 aResult.append(myFieldsFolder);
948 aResult.append(aList);
951 if (!myGroupsFolder->childrenCount()) {
952 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
954 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
955 aResult.append(myGroupsFolder);
956 aResult.append(aList);
962 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
963 const QString& theGroup)
965 QTreeNodesList aResult;
966 if (myFieldsFolder->childrenCount()) {
967 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
969 aResult.append(aList);
970 if (!myFieldsFolder->childrenCount())
971 myChildren.removeAll(myFieldsFolder);
974 if (myGroupsFolder->childrenCount()) {
975 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
977 aResult.append(aList);
978 if (!myGroupsFolder->childrenCount())
979 myChildren.removeAll(myGroupsFolder);
982 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
986 //////////////////////////////////////////////////////////////////////////////////
987 void PartSet_ObjectFolderNode::update()
990 getFirstAndLastIndex(aFirst, aLast);
991 if ((aFirst == -1) || (aLast == -1)) {
996 int aNbItems = aLast - aFirst + 1;
1002 DocumentPtr aDoc = myObject->document();
1003 // Delete obsolete nodes
1005 while (aId < myChildren.size()) {
1006 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1007 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
1008 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1009 myChildren.removeAll(aNode);
1018 ModuleBase_ITreeNode* aNode;
1019 for (int i = 0; i < aNbItems; i++) {
1020 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1021 if (i < myChildren.size()) {
1022 if (aObj != myChildren.at(i)->object()) {
1023 aNode = new PartSet_ObjectNode(aObj, this);
1024 myChildren.insert(i, aNode);
1027 aNode = new PartSet_ObjectNode(aObj, this);
1028 myChildren.append(aNode);
1033 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
1035 QTreeNodesList aResult;
1037 getFirstAndLastIndex(aFirst, aLast);
1038 if ((aFirst == -1) || (aLast == -1)) {
1041 int aNbItems = aLast - aFirst + 1;
1045 DocumentPtr aDoc = myObject->document();
1047 ModuleBase_ITreeNode* aNode;
1048 for (int i = 0; i < aNbItems; i++) {
1049 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1050 if (i < myChildren.size()) {
1051 if (aObj != myChildren.at(i)->object()) {
1052 aNode = new PartSet_ObjectNode(aObj, this);
1053 myChildren.insert(i, aNode);
1054 aResult.append(aNode);
1057 aNode = new PartSet_ObjectNode(aObj, this);
1058 myChildren.append(aNode);
1059 aResult.append(aNode);
1065 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
1066 const QString& theGroup)
1068 QTreeNodesList aResult;
1070 getFirstAndLastIndex(aFirst, aLast);
1071 if ((aFirst == -1) || (aLast == -1)) {
1074 int aNbItems = aLast - aFirst + 1;
1078 DocumentPtr aDoc = myObject->document();
1079 // Delete obsolete nodes
1080 bool aRemoved = false;
1082 while (aId < myChildren.size()) {
1083 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1084 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
1085 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1086 myChildren.removeAll(aNode);
1095 aResult.append(this);
1100 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
1102 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1103 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
1105 return ModelAPI_Feature::feature(aFeatAttr->value());
1106 return FeaturePtr();
1109 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
1111 DocumentPtr aDoc = myObject->document();
1112 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1114 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1115 if (!aFirstFeatureInFolder.get()) {
1119 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1120 if (!aLastFeatureInFolder.get()) {
1125 theFirst = aDoc->index(aFirstFeatureInFolder);
1126 theLast = aDoc->index(aLastFeatureInFolder);
1130 //////////////////////////////////////////////////////////////////////////////////
1131 QVariant PartSet_StepNode::data(int theColumn, int theRole) const
1133 if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
1134 ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
1135 dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
1137 return "Step " + QString::number(aStep->id() + 1) + " " +
1138 aStep->field()->textLine(aStep->id()).c_str();
1140 return PartSet_TreeNode::data(theColumn, theRole);