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);
242 ModuleBase_ITreeNode* aNode;
245 for (i = 0; i < aNb; i++) {
246 aBody = subObject(i);
248 if (i < myChildren.size()) {
249 aNode = myChildren.at(i);
250 if (aNode->object() != aBody) {
251 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
255 aNode = new PartSet_ObjectNode(aBody, this);
256 myChildren.append(aNode);
259 else if (aFieldRes.get()) {
260 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
261 if (i < myChildren.size()) {
262 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
263 if (aStepNode->entity() != aStep) {
264 aStepNode->setEntity(aStep);
268 aNode = new PartSet_StepNode(aStep, this);
269 myChildren.append(aNode);
273 // Delete extra objects
274 while (myChildren.size() > aNb) {
275 aNode = myChildren.takeLast();
278 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
287 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
289 QTreeNodesList aResult;
290 int aNb = numberOfSubs();
292 ModuleBase_ITreeNode* aNode;
293 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
296 for (i = 0; i < aNb; i++) {
297 aBody = subObject(i);
299 if (i < myChildren.size()) {
300 aNode = myChildren.at(i);
301 if (aNode->object() != aBody) {
302 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
303 aResult.append(aNode);
307 aNode = new PartSet_ObjectNode(aBody, this);
308 myChildren.append(aNode);
309 aResult.append(aNode);
314 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
315 if (i < myChildren.size()) {
316 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
317 if (aStepNode->entity() != aStep) {
318 aStepNode->setEntity(aStep);
322 aNode = new PartSet_StepNode(aStep, this);
323 myChildren.append(aNode);
327 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
328 aResult.append(aNode->objectCreated(theObjects));
334 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
335 const DocumentPtr& theDoc, const QString& theGroup)
337 QTreeNodesList aResult;
338 int aNb = numberOfSubs();
340 ModuleBase_ITreeNode* aNode;
341 // Delete extra objects
342 bool isDeleted = false;
343 while (myChildren.size() > aNb) {
344 aNode = myChildren.takeLast();
349 aResult.append(this);
352 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
353 aBody = subObject(i);
354 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
355 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
361 //////////////////////////////////////////////////////////////////////////////////
362 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
364 : PartSet_TreeNode(theParent), myType(theType)
368 QString PartSet_FolderNode::name() const
371 case ParametersFolder:
372 return QObject::tr("Parameters");
373 case ConstructionFolder:
374 return QObject::tr("Constructions");
376 return QObject::tr("Parts");
378 return QObject::tr("Results");
380 return QObject::tr("Fields");
382 return QObject::tr("Groups");
388 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
390 static QIcon aParamsIco(":pictures/params_folder.png");
391 static QIcon aConstrIco(":pictures/constr_folder.png");
393 if (theColumn == 1) {
395 case Qt::DisplayRole:
396 return name() + QString(" (%1)").arg(childrenCount());
397 case Qt::DecorationRole:
399 case ParametersFolder:
401 case ConstructionFolder:
414 return PartSet_TreeNode::data(theColumn, theRole);
417 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
419 SessionPtr aSession = ModelAPI_Session::get();
420 DocumentPtr aActiveDoc = aSession->activeDocument();
421 if (theColumn == 1) {
422 if (document() == aActiveDoc)
428 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
430 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
431 //if (aCompRes.get())
432 // return new PartSet_CompsolidNode(theObj, this);
433 return new PartSet_ObjectNode(theObj, this);
436 void PartSet_FolderNode::update()
438 DocumentPtr aDoc = document();
442 // Remove extra sub-nodes
445 while (aId < myChildren.size()) {
446 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
447 aIndex = aDoc->index(aNode->object(), true);
448 if ((aIndex == -1) || (aId != aIndex)) {
449 myChildren.removeAll(aNode);
456 std::string aGroup = groupName();
457 int aSize = aDoc->size(aGroup, true);
458 for (int i = 0; i < aSize; i++) {
459 ObjectPtr aObj = aDoc->object(aGroup, i, true);
460 if (i < myChildren.size()) {
461 if (myChildren.at(i)->object() != aObj) {
462 ModuleBase_ITreeNode* aNode = createNode(aObj);
463 myChildren.insert(i, aNode);
466 ModuleBase_ITreeNode* aNode = createNode(aObj);
467 myChildren.append(aNode);
471 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
476 std::string PartSet_FolderNode::groupName() const
479 case ParametersFolder:
480 return ModelAPI_ResultParameter::group();
481 case ConstructionFolder:
482 return ModelAPI_ResultConstruction::group();
484 return ModelAPI_ResultPart::group();
486 return ModelAPI_ResultBody::group();
488 return ModelAPI_ResultField::group();
490 return ModelAPI_ResultGroup::group();
495 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
497 QTreeNodesList aResult;
498 std::string aName = groupName();
499 DocumentPtr aDoc = document();
501 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
502 foreach(ObjectPtr aObj, theObjects) {
503 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
504 aIdx = aDoc->index(aObj, true);
506 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
508 ModuleBase_ITreeNode* aNode = createNode(aObj);
509 aNewNodes[aIdx] = aNode;
510 aResult.append(aNode);
516 // Add nodes in correct order
518 for (i = 0; i < myChildren.size(); i++) {
519 if (aNewNodes.contains(i)) {
520 myChildren.insert(i, aNewNodes[i]);
524 while (aNewNodes.size()) {
525 i = myChildren.size();
526 myChildren.append(aNewNodes[i]);
529 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
530 aResult.append(aNode->objectCreated(theObjects));
535 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
536 const QString& theGroup)
538 DocumentPtr aDoc = document();
539 QTreeNodesList aResult;
540 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
541 QTreeNodesList aDelList;
544 bool aRemoved = false;
545 while (aId < myChildren.size()) {
546 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
547 aIndex = aDoc->index(aNode->object(), true);
548 if ((aIndex == -1) || (aId != aIndex)) {
549 myChildren.removeAll(aNode);
556 aResult.append(this);
558 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
559 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
565 //////////////////////////////////////////////////////////////////////////////////
566 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
568 QTreeNodesList aResult;
569 // Process the root sub-objects
570 DocumentPtr aDoc = document();
572 int aNb = numberOfFolders();
573 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
574 foreach(ObjectPtr aObj, theObjects) {
575 if (aDoc == aObj->document()) {
576 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
577 (aObj->groupName() == ModelAPI_Folder::group())){
578 aIdx = aDoc->index(aObj, true);
580 ModuleBase_ITreeNode* aNode = createNode(aObj);
582 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
584 aNewNodes[aIdx] = aNode;
585 aResult.append(aNode);
592 // To add in correct order
594 for (i = 0; i < myChildren.size(); i++) {
595 if (aNewNodes.contains(i)) {
596 myChildren.insert(i, aNewNodes[i]);
600 while (aNewNodes.size()) {
601 i = myChildren.size();
602 myChildren.append(aNewNodes[i]);
606 // Update sub-folders
607 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
608 aResult.append(aNode->objectCreated(theObjects));
613 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
614 const QString& theGroup)
616 QTreeNodesList aResult;
618 // Process sub-folders
619 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
620 if (aNode->childrenCount() > 0) { // aFolder node
621 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
622 if (aList.size() > 0)
623 aResult.append(aList);
628 DocumentPtr aDoc = document();
629 int aNb = numberOfFolders();
630 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
631 (theGroup.toStdString() == ModelAPI_Folder::group()));
632 if ((theDoc == aDoc) && isGroup) {
635 bool aRemoved = false;
636 while (aId < myChildren.size()) {
637 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
638 if (aNode->object().get()) {
639 aIndex = aDoc->index(aNode->object(), true);
640 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
641 myChildren.removeAll(aNode);
650 aResult.append(this);
655 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
658 ModuleBase_ITreeNode* aResult = 0;
659 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
660 aResult = aNode->findParent(theDoc, theGroup);
665 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
666 (theGroup.toStdString() == ModelAPI_Folder::group()));
667 if ((theDoc == document()) && isGroup)
673 //////////////////////////////////////////////////////////////////////////////////
674 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
676 SessionPtr aSession = ModelAPI_Session::get();
677 DocumentPtr aDoc = aSession->moduleDocument();
679 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
680 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
681 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
683 myChildren.append(myParamsFolder);
684 myChildren.append(myConstrFolder);
685 myChildren.append(myPartsFolder);
691 void PartSet_RootNode::update()
693 myParamsFolder->update();
694 myConstrFolder->update();
695 myPartsFolder->update();
697 // Update features content
698 DocumentPtr aDoc = document();
699 int aNb = numberOfFolders();
701 // Remove extra sub-nodes
704 while (aId < myChildren.size()) {
705 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
706 if (aNode->object().get()) {
707 aIndex = aDoc->index(aNode->object(), true);
708 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
709 myChildren.removeAll(aNode);
718 std::string aGroup = ModelAPI_Feature::group();
719 int aSize = aDoc->size(aGroup, true);
721 for (int i = 0; i < aSize; i++) {
722 ObjectPtr aObj = aDoc->object(aGroup, i, true);
723 aId = i + aNb; // Take into account existing folders
724 if (aId < myChildren.size()) {
725 if (myChildren.at(aId)->object() != aObj) {
726 ModuleBase_ITreeNode* aNode = createNode(aObj);
727 myChildren.insert(aId, aNode);
730 ModuleBase_ITreeNode* aNode = createNode(aObj);
731 myChildren.append(aNode);
734 // Update sub-folders
735 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
736 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
737 (aNode->type() == PartSet_PartRootNode::typeId()))
742 DocumentPtr PartSet_RootNode::document() const
744 return ModelAPI_Session::get()->moduleDocument();
747 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
749 if (theObj->groupName() == ModelAPI_Folder::group())
750 return new PartSet_ObjectFolderNode(theObj, this);
752 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
753 if (aFeature->getKind() == PartSetPlugin_Part::ID())
754 return new PartSet_PartRootNode(theObj, this);
756 return new PartSet_ObjectNode(theObj, this);
759 //////////////////////////////////////////////////////////////////////////////////
760 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
761 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
763 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
764 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
765 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
766 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
767 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
769 myChildren.append(myParamsFolder);
770 myChildren.append(myConstrFolder);
771 myChildren.append(myResultsFolder);
776 void PartSet_PartRootNode::deleteChildren()
778 if (!myFieldsFolder->childrenCount()) {
779 delete myFieldsFolder;
781 if (!myGroupsFolder->childrenCount()) {
782 delete myGroupsFolder;
784 PartSet_FeatureFolderNode::deleteChildren();
788 void PartSet_PartRootNode::update()
790 DocumentPtr aDoc = document();
794 myParamsFolder->update();
795 myConstrFolder->update();
796 myResultsFolder->update();
797 myFieldsFolder->update();
798 myGroupsFolder->update();
800 bool aHasFields = myFieldsFolder->childrenCount() > 0;
801 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
802 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
803 myChildren.insert(3, myFieldsFolder);
805 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
806 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
809 // Update features content
810 int aRows = numberOfFolders();
812 // Remove extra sub-nodes
815 while (aId < myChildren.size()) {
816 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
817 if (aNode->object().get()) {
818 aIndex = aDoc->index(aNode->object(), true);
819 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
820 myChildren.removeAll(aNode);
828 std::string aGroup = ModelAPI_Feature::group();
829 int aSize = aDoc->size(aGroup, true);
831 for (int i = 0; i < aSize; i++) {
832 ObjectPtr aObj = aDoc->object(aGroup, i, true);
833 aId = i + aRows; // Take into account existing folders
834 if (aId < myChildren.size()) {
835 if (myChildren.at(aId)->object() != aObj) {
836 ModuleBase_ITreeNode* aNode = createNode(aObj);
837 myChildren.insert(aId, aNode);
840 ModuleBase_ITreeNode* aNode = createNode(aObj);
841 myChildren.append(aNode);
844 // Update sub-folders
845 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
846 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
851 DocumentPtr PartSet_PartRootNode::document() const
853 ResultPartPtr aPartRes = getPartResult(myObject);
855 return aPartRes->partDoc();
856 return DocumentPtr();
859 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
864 case Qt::DisplayRole:
865 return QString(myObject->data()->name().c_str());
866 case Qt::DecorationRole:
867 return ModuleBase_IconFactory::get()->getIcon(myObject);
870 if (theRole == Qt::DecorationRole)
871 if (isCurrentFeature(myObject))
872 return QIcon(":pictures/arrow.png");
874 return PartSet_TreeNode::data(theColumn, theRole);
877 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
879 SessionPtr aSession = ModelAPI_Session::get();
880 DocumentPtr aActiveDoc = aSession->activeDocument();
881 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
886 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
888 if (theObj->groupName() == ModelAPI_Folder::group())
889 return new PartSet_ObjectFolderNode(theObj, this);
890 return new PartSet_ObjectNode(theObj, this);
893 int PartSet_PartRootNode::numberOfFolders() const
896 if (myFieldsFolder->childrenCount() > 0)
898 if (myGroupsFolder->childrenCount() > 0)
903 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
905 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
906 if (!myFieldsFolder->childrenCount()) {
907 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
909 myChildren.insert(3, myFieldsFolder);
910 aResult.append(myFieldsFolder);
911 aResult.append(aList);
914 if (!myGroupsFolder->childrenCount()) {
915 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
917 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
918 aResult.append(myGroupsFolder);
919 aResult.append(aList);
925 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
926 const QString& theGroup)
928 QTreeNodesList aResult;
929 if (myFieldsFolder->childrenCount()) {
930 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
932 aResult.append(aList);
933 if (!myFieldsFolder->childrenCount())
934 myChildren.removeAll(myFieldsFolder);
937 if (myGroupsFolder->childrenCount()) {
938 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
940 aResult.append(aList);
941 if (!myGroupsFolder->childrenCount())
942 myChildren.removeAll(myGroupsFolder);
945 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
949 //////////////////////////////////////////////////////////////////////////////////
950 void PartSet_ObjectFolderNode::update()
953 getFirstAndLastIndex(aFirst, aLast);
954 if ((aFirst == -1) || (aLast == -1)) {
959 int aNbItems = aLast - aFirst + 1;
965 DocumentPtr aDoc = myObject->document();
966 // Delete obsolete nodes
968 while (aId < myChildren.size()) {
969 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
970 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
971 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
972 myChildren.removeAll(aNode);
981 ModuleBase_ITreeNode* aNode;
982 for (int i = 0; i < aNbItems; i++) {
983 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
984 if (i < myChildren.size()) {
985 if (aObj != myChildren.at(i)->object()) {
986 aNode = new PartSet_ObjectNode(aObj, this);
987 myChildren.insert(i, aNode);
990 aNode = new PartSet_ObjectNode(aObj, this);
991 myChildren.append(aNode);
996 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
998 QTreeNodesList aResult;
1000 getFirstAndLastIndex(aFirst, aLast);
1001 if ((aFirst == -1) || (aLast == -1)) {
1004 int aNbItems = aLast - aFirst + 1;
1008 DocumentPtr aDoc = myObject->document();
1010 ModuleBase_ITreeNode* aNode;
1011 for (int i = 0; i < aNbItems; i++) {
1012 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1013 if (i < myChildren.size()) {
1014 if (aObj != myChildren.at(i)->object()) {
1015 aNode = new PartSet_ObjectNode(aObj, this);
1016 myChildren.insert(i, aNode);
1017 aResult.append(aNode);
1020 aNode = new PartSet_ObjectNode(aObj, this);
1021 myChildren.append(aNode);
1022 aResult.append(aNode);
1028 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
1029 const QString& theGroup)
1031 QTreeNodesList aResult;
1033 getFirstAndLastIndex(aFirst, aLast);
1034 if ((aFirst == -1) || (aLast == -1)) {
1037 int aNbItems = aLast - aFirst + 1;
1041 DocumentPtr aDoc = myObject->document();
1042 // Delete obsolete nodes
1043 bool aRemoved = false;
1045 while (aId < myChildren.size()) {
1046 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1047 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
1048 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1049 myChildren.removeAll(aNode);
1058 aResult.append(this);
1063 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
1065 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1066 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
1068 return ModelAPI_Feature::feature(aFeatAttr->value());
1069 return FeaturePtr();
1072 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
1074 DocumentPtr aDoc = myObject->document();
1075 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1077 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1078 if (!aFirstFeatureInFolder.get()) {
1082 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1083 if (!aLastFeatureInFolder.get()) {
1088 theFirst = aDoc->index(aFirstFeatureInFolder);
1089 theLast = aDoc->index(aLastFeatureInFolder);
1093 //////////////////////////////////////////////////////////////////////////////////
1094 QVariant PartSet_StepNode::data(int theColumn, int theRole) const
1096 if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
1097 ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
1098 dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
1100 return "Step " + QString::number(aStep->id() + 1) + " " +
1101 aStep->field()->textLine(aStep->id()).c_str();
1103 return PartSet_TreeNode::data(theColumn, theRole);