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 int PartSet_ObjectNode::numberOfSubs() const
192 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
194 return aCompRes->numberOfSubs(true);
196 CompositeFeaturePtr aCompFeature =
197 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
198 if (aCompFeature.get() && aCompFeature->data()->isValid())
199 return aCompFeature->numberOfSubs(true);
201 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
203 return aFieldRes->stepsSize();
210 ObjectPtr PartSet_ObjectNode::subObject(int theId) const
212 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
214 return aCompRes->subResult(theId, true);
216 CompositeFeaturePtr aCompFeature =
217 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
218 if (aCompFeature.get())
219 return aCompFeature->subFeature(theId, true);
224 void PartSet_ObjectNode::update()
226 int aNb = numberOfSubs();
228 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
230 // If the object is a field result then delete extra sub-objects
231 if (aFieldRes.get()) {
232 while (myChildren.size() > aNb) {
233 ModuleBase_ITreeNode* aNode = myChildren.last();
234 myChildren.removeAll(aNode);
239 ModuleBase_ITreeNode* aNode;
242 for (i = 0; i < aNb; i++) {
243 aBody = subObject(i);
245 if (i < myChildren.size()) {
246 aNode = myChildren.at(i);
247 if (aNode->object() != aBody) {
248 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
252 aNode = new PartSet_ObjectNode(aBody, this);
253 myChildren.append(aNode);
256 else if (aFieldRes.get()) {
257 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
258 if (i < myChildren.size()) {
259 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
260 if (aStepNode->entity() != aStep) {
261 aStepNode->setEntity(aStep);
265 aNode = new PartSet_StepNode(aStep, this);
266 myChildren.append(aNode);
270 // Delete extra objects
271 while (myChildren.size() > aNb) {
272 aNode = myChildren.takeLast();
275 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
284 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
286 QTreeNodesList aResult;
287 int aNb = numberOfSubs();
289 ModuleBase_ITreeNode* aNode;
290 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
293 for (i = 0; i < aNb; i++) {
294 aBody = subObject(i);
296 if (i < myChildren.size()) {
297 aNode = myChildren.at(i);
298 if (aNode->object() != aBody) {
299 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
300 aResult.append(aNode);
304 aNode = new PartSet_ObjectNode(aBody, this);
305 myChildren.append(aNode);
306 aResult.append(aNode);
311 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
312 if (i < myChildren.size()) {
313 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
314 if (aStepNode->entity() != aStep) {
315 aStepNode->setEntity(aStep);
319 aNode = new PartSet_StepNode(aStep, this);
320 myChildren.append(aNode);
324 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
325 aResult.append(aNode->objectCreated(theObjects));
331 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
332 const DocumentPtr& theDoc, const QString& theGroup)
334 QTreeNodesList aResult;
335 int aNb = numberOfSubs();
337 ModuleBase_ITreeNode* aNode;
338 // Delete extra objects
339 bool isDeleted = false;
340 while (myChildren.size() > aNb) {
341 aNode = myChildren.takeLast();
346 aResult.append(this);
349 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
350 aBody = subObject(i);
351 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
352 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
358 //////////////////////////////////////////////////////////////////////////////////
359 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
361 : PartSet_TreeNode(theParent), myType(theType)
365 QString PartSet_FolderNode::name() const
368 case ParametersFolder:
369 return QObject::tr("Parameters");
370 case ConstructionFolder:
371 return QObject::tr("Constructions");
373 return QObject::tr("Parts");
375 return QObject::tr("Results");
377 return QObject::tr("Fields");
379 return QObject::tr("Groups");
385 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
387 static QIcon aParamsIco(":pictures/params_folder.png");
388 static QIcon aConstrIco(":pictures/constr_folder.png");
390 if (theColumn == 1) {
392 case Qt::DisplayRole:
393 return name() + QString(" (%1)").arg(childrenCount());
394 case Qt::DecorationRole:
396 case ParametersFolder:
398 case ConstructionFolder:
411 return PartSet_TreeNode::data(theColumn, theRole);
414 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
416 SessionPtr aSession = ModelAPI_Session::get();
417 DocumentPtr aActiveDoc = aSession->activeDocument();
418 if (theColumn == 1) {
419 if (document() == aActiveDoc)
425 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
427 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
428 //if (aCompRes.get())
429 // return new PartSet_CompsolidNode(theObj, this);
430 return new PartSet_ObjectNode(theObj, this);
433 void PartSet_FolderNode::update()
435 DocumentPtr aDoc = document();
439 // Remove extra sub-nodes
442 while (aId < myChildren.size()) {
443 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
444 aIndex = aDoc->index(aNode->object(), true);
445 if ((aIndex == -1) || (aId != aIndex)) {
446 myChildren.removeAll(aNode);
453 std::string aGroup = groupName();
454 int aSize = aDoc->size(aGroup, true);
455 for (int i = 0; i < aSize; i++) {
456 ObjectPtr aObj = aDoc->object(aGroup, i, true);
457 if (i < myChildren.size()) {
458 if (myChildren.at(i)->object() != aObj) {
459 ModuleBase_ITreeNode* aNode = createNode(aObj);
460 myChildren.insert(i, aNode);
463 ModuleBase_ITreeNode* aNode = createNode(aObj);
464 myChildren.append(aNode);
468 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
473 std::string PartSet_FolderNode::groupName() const
476 case ParametersFolder:
477 return ModelAPI_ResultParameter::group();
478 case ConstructionFolder:
479 return ModelAPI_ResultConstruction::group();
481 return ModelAPI_ResultPart::group();
483 return ModelAPI_ResultBody::group();
485 return ModelAPI_ResultField::group();
487 return ModelAPI_ResultGroup::group();
492 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
494 QTreeNodesList aResult;
495 std::string aName = groupName();
496 DocumentPtr aDoc = document();
498 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
499 foreach(ObjectPtr aObj, theObjects) {
500 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
501 aIdx = aDoc->index(aObj, true);
503 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
505 ModuleBase_ITreeNode* aNode = createNode(aObj);
506 aNewNodes[aIdx] = aNode;
507 aResult.append(aNode);
513 // Add nodes in correct order
515 for (i = 0; i < myChildren.size(); i++) {
516 if (aNewNodes.contains(i)) {
517 myChildren.insert(i, aNewNodes[i]);
521 while (aNewNodes.size()) {
522 i = myChildren.size();
523 myChildren.append(aNewNodes[i]);
526 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
527 aResult.append(aNode->objectCreated(theObjects));
532 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
533 const QString& theGroup)
535 DocumentPtr aDoc = document();
536 QTreeNodesList aResult;
537 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
538 QTreeNodesList aDelList;
541 bool aRemoved = false;
542 while (aId < myChildren.size()) {
543 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
544 aIndex = aDoc->index(aNode->object(), true);
545 if ((aIndex == -1) || (aId != aIndex)) {
546 myChildren.removeAll(aNode);
553 aResult.append(this);
555 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
556 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
562 //////////////////////////////////////////////////////////////////////////////////
563 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
565 QTreeNodesList aResult;
566 // Process the root sub-objects
567 DocumentPtr aDoc = document();
569 int aNb = numberOfFolders();
570 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
571 foreach(ObjectPtr aObj, theObjects) {
572 if (aDoc == aObj->document()) {
573 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
574 (aObj->groupName() == ModelAPI_Folder::group())){
575 aIdx = aDoc->index(aObj, true);
577 ModuleBase_ITreeNode* aNode = createNode(aObj);
579 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
581 aNewNodes[aIdx] = aNode;
582 aResult.append(aNode);
589 // To add in correct order
591 for (i = 0; i < myChildren.size(); i++) {
592 if (aNewNodes.contains(i)) {
593 myChildren.insert(i, aNewNodes[i]);
597 while (aNewNodes.size()) {
598 i = myChildren.size();
599 myChildren.append(aNewNodes[i]);
603 // Update sub-folders
604 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
605 aResult.append(aNode->objectCreated(theObjects));
610 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
611 const QString& theGroup)
613 QTreeNodesList aResult;
615 // Process sub-folders
616 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
617 if (aNode->childrenCount() > 0) { // aFolder node
618 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
619 if (aList.size() > 0)
620 aResult.append(aList);
625 DocumentPtr aDoc = document();
626 int aNb = numberOfFolders();
627 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
628 (theGroup.toStdString() == ModelAPI_Folder::group()));
629 if ((theDoc == aDoc) && isGroup) {
632 bool aRemoved = false;
633 while (aId < myChildren.size()) {
634 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
635 if (aNode->object().get()) {
636 aIndex = aDoc->index(aNode->object(), true);
637 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
638 myChildren.removeAll(aNode);
647 aResult.append(this);
652 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
655 ModuleBase_ITreeNode* aResult = 0;
656 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
657 aResult = aNode->findParent(theDoc, theGroup);
662 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
663 (theGroup.toStdString() == ModelAPI_Folder::group()));
664 if ((theDoc == document()) && isGroup)
670 //////////////////////////////////////////////////////////////////////////////////
671 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
673 SessionPtr aSession = ModelAPI_Session::get();
674 DocumentPtr aDoc = aSession->moduleDocument();
676 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
677 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
678 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
680 myChildren.append(myParamsFolder);
681 myChildren.append(myConstrFolder);
682 myChildren.append(myPartsFolder);
688 void PartSet_RootNode::update()
690 myParamsFolder->update();
691 myConstrFolder->update();
692 myPartsFolder->update();
694 // Update features content
695 DocumentPtr aDoc = document();
696 int aNb = numberOfFolders();
698 // Remove extra sub-nodes
701 while (aId < myChildren.size()) {
702 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
703 if (aNode->object().get()) {
704 aIndex = aDoc->index(aNode->object(), true);
705 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
706 myChildren.removeAll(aNode);
715 std::string aGroup = ModelAPI_Feature::group();
716 int aSize = aDoc->size(aGroup, true);
718 for (int i = 0; i < aSize; i++) {
719 ObjectPtr aObj = aDoc->object(aGroup, i, true);
720 aId = i + aNb; // Take into account existing folders
721 if (aId < myChildren.size()) {
722 if (myChildren.at(aId)->object() != aObj) {
723 ModuleBase_ITreeNode* aNode = createNode(aObj);
724 myChildren.insert(aId, aNode);
727 ModuleBase_ITreeNode* aNode = createNode(aObj);
728 myChildren.append(aNode);
731 // Update sub-folders
732 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
733 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
734 (aNode->type() == PartSet_PartRootNode::typeId()))
739 DocumentPtr PartSet_RootNode::document() const
741 return ModelAPI_Session::get()->moduleDocument();
744 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
746 if (theObj->groupName() == ModelAPI_Folder::group())
747 return new PartSet_ObjectFolderNode(theObj, this);
749 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
750 if (aFeature->getKind() == PartSetPlugin_Part::ID())
751 return new PartSet_PartRootNode(theObj, this);
753 return new PartSet_ObjectNode(theObj, this);
756 //////////////////////////////////////////////////////////////////////////////////
757 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
758 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
760 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
761 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
762 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
763 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
764 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
766 myChildren.append(myParamsFolder);
767 myChildren.append(myConstrFolder);
768 myChildren.append(myResultsFolder);
773 void PartSet_PartRootNode::deleteChildren()
775 if (!myFieldsFolder->childrenCount()) {
776 delete myFieldsFolder;
778 if (!myGroupsFolder->childrenCount()) {
779 delete myGroupsFolder;
781 PartSet_FeatureFolderNode::deleteChildren();
785 void PartSet_PartRootNode::update()
787 DocumentPtr aDoc = document();
791 myParamsFolder->update();
792 myConstrFolder->update();
793 myResultsFolder->update();
794 myFieldsFolder->update();
795 myGroupsFolder->update();
797 bool aHasFields = myFieldsFolder->childrenCount() > 0;
798 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
799 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
800 myChildren.insert(3, myFieldsFolder);
802 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
803 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
806 // Update features content
807 int aRows = numberOfFolders();
809 // Remove extra sub-nodes
812 while (aId < myChildren.size()) {
813 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
814 if (aNode->object().get()) {
815 aIndex = aDoc->index(aNode->object(), true);
816 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
817 myChildren.removeAll(aNode);
825 std::string aGroup = ModelAPI_Feature::group();
826 int aSize = aDoc->size(aGroup, true);
828 for (int i = 0; i < aSize; i++) {
829 ObjectPtr aObj = aDoc->object(aGroup, i, true);
830 aId = i + aRows; // Take into account existing folders
831 if (aId < myChildren.size()) {
832 if (myChildren.at(aId)->object() != aObj) {
833 ModuleBase_ITreeNode* aNode = createNode(aObj);
834 myChildren.insert(aId, aNode);
837 ModuleBase_ITreeNode* aNode = createNode(aObj);
838 myChildren.append(aNode);
841 // Update sub-folders
842 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
843 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
848 DocumentPtr PartSet_PartRootNode::document() const
850 ResultPartPtr aPartRes = getPartResult(myObject);
852 return aPartRes->partDoc();
853 return DocumentPtr();
856 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
861 case Qt::DisplayRole:
862 return QString(myObject->data()->name().c_str());
863 case Qt::DecorationRole:
864 return ModuleBase_IconFactory::get()->getIcon(myObject);
867 if (theRole == Qt::DecorationRole)
868 if (isCurrentFeature(myObject))
869 return QIcon(":pictures/arrow.png");
871 return PartSet_TreeNode::data(theColumn, theRole);
874 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
876 SessionPtr aSession = ModelAPI_Session::get();
877 DocumentPtr aActiveDoc = aSession->activeDocument();
878 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
883 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
885 if (theObj->groupName() == ModelAPI_Folder::group())
886 return new PartSet_ObjectFolderNode(theObj, this);
887 return new PartSet_ObjectNode(theObj, this);
890 int PartSet_PartRootNode::numberOfFolders() const
893 if (myFieldsFolder->childrenCount() > 0)
895 if (myGroupsFolder->childrenCount() > 0)
900 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
902 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
903 if (!myFieldsFolder->childrenCount()) {
904 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
906 myChildren.insert(3, myFieldsFolder);
907 aResult.append(myFieldsFolder);
908 aResult.append(aList);
911 if (!myGroupsFolder->childrenCount()) {
912 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
914 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
915 aResult.append(myGroupsFolder);
916 aResult.append(aList);
922 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
923 const QString& theGroup)
925 QTreeNodesList aResult;
926 if (myFieldsFolder->childrenCount()) {
927 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
929 aResult.append(aList);
930 if (!myFieldsFolder->childrenCount())
931 myChildren.removeAll(myFieldsFolder);
934 if (myGroupsFolder->childrenCount()) {
935 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
937 aResult.append(aList);
938 if (!myGroupsFolder->childrenCount())
939 myChildren.removeAll(myGroupsFolder);
942 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
946 //////////////////////////////////////////////////////////////////////////////////
947 void PartSet_ObjectFolderNode::update()
950 getFirstAndLastIndex(aFirst, aLast);
951 if ((aFirst == -1) || (aLast == -1)) {
956 int aNbItems = aLast - aFirst + 1;
962 DocumentPtr aDoc = myObject->document();
963 // Delete obsolete nodes
965 while (aId < myChildren.size()) {
966 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
967 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
968 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
969 myChildren.removeAll(aNode);
978 ModuleBase_ITreeNode* aNode;
979 for (int i = 0; i < aNbItems; i++) {
980 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
981 if (i < myChildren.size()) {
982 if (aObj != myChildren.at(i)->object()) {
983 aNode = new PartSet_ObjectNode(aObj, this);
984 myChildren.insert(i, aNode);
987 aNode = new PartSet_ObjectNode(aObj, this);
988 myChildren.append(aNode);
993 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
995 QTreeNodesList aResult;
997 getFirstAndLastIndex(aFirst, aLast);
998 if ((aFirst == -1) || (aLast == -1)) {
1001 int aNbItems = aLast - aFirst + 1;
1005 DocumentPtr aDoc = myObject->document();
1007 ModuleBase_ITreeNode* aNode;
1008 for (int i = 0; i < aNbItems; i++) {
1009 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1010 if (i < myChildren.size()) {
1011 if (aObj != myChildren.at(i)->object()) {
1012 aNode = new PartSet_ObjectNode(aObj, this);
1013 myChildren.insert(i, aNode);
1014 aResult.append(aNode);
1017 aNode = new PartSet_ObjectNode(aObj, this);
1018 myChildren.append(aNode);
1019 aResult.append(aNode);
1025 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
1026 const QString& theGroup)
1028 QTreeNodesList aResult;
1030 getFirstAndLastIndex(aFirst, aLast);
1031 if ((aFirst == -1) || (aLast == -1)) {
1034 int aNbItems = aLast - aFirst + 1;
1038 DocumentPtr aDoc = myObject->document();
1039 // Delete obsolete nodes
1040 bool aRemoved = false;
1042 while (aId < myChildren.size()) {
1043 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1044 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
1045 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1046 myChildren.removeAll(aNode);
1055 aResult.append(this);
1060 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
1062 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1063 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
1065 return ModelAPI_Feature::feature(aFeatAttr->value());
1066 return FeaturePtr();
1069 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
1071 DocumentPtr aDoc = myObject->document();
1072 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1074 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1075 if (!aFirstFeatureInFolder.get()) {
1079 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1080 if (!aLastFeatureInFolder.get()) {
1085 theFirst = aDoc->index(aFirstFeatureInFolder);
1086 theLast = aDoc->index(aLastFeatureInFolder);
1090 //////////////////////////////////////////////////////////////////////////////////
1091 QVariant PartSet_StepNode::data(int theColumn, int theRole) const
1093 if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
1094 ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
1095 dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
1097 return "Step " + QString::number(aStep->id() + 1) + " " +
1098 aStep->field()->textLine(aStep->id()).c_str();
1100 return PartSet_TreeNode::data(theColumn, theRole);