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_ResultCompSolid.h>
37 #include <ModelAPI_CompositeFeature.h>
38 #include <ModelAPI_AttributeDouble.h>
39 #include <ModelAPI_Folder.h>
40 #include <ModelAPI_AttributeReference.h>
45 #define ACTIVE_COLOR QColor(Qt::black)
46 #define SELECTABLE_COLOR QColor(100, 100, 100)
47 #define DISABLED_COLOR QColor(200, 200, 200)
49 Qt::ItemFlags aNullFlag;
50 Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
51 Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
54 ResultPartPtr getPartResult(const ObjectPtr& theObj)
56 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
58 ResultPtr aRes = aFeature->firstResult();
59 if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
60 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
61 // Use only original parts, not a placement results
62 if (aPartRes == aPartRes->original())
66 return ResultPartPtr();
69 bool isCurrentFeature(const ObjectPtr& theObj)
71 SessionPtr aSession = ModelAPI_Session::get();
72 DocumentPtr aCurDoc = aSession->activeDocument();
73 FeaturePtr aFeature = aCurDoc->currentFeature(true);
74 return aFeature == theObj;
77 //////////////////////////////////////////////////////////////////////////////////
78 QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
80 if ((theColumn == 1) && (theRole == Qt::ForegroundRole)) {
81 Qt::ItemFlags aFlags = flags(theColumn);
82 if (aFlags == Qt::ItemFlags())
83 return QBrush(DISABLED_COLOR);
84 if (!aFlags.testFlag(Qt::ItemIsEditable))
85 return QBrush(SELECTABLE_COLOR);
88 return ModuleBase_ITreeNode::data(theColumn, theRole);
92 //////////////////////////////////////////////////////////////////////////////////
93 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
98 if (myObject->groupName() == ModelAPI_ResultParameter::group()) {
99 ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myObject);
100 AttributeDoublePtr aValueAttribute =
101 aParam->data()->real(ModelAPI_ResultParameter::VALUE());
102 QString aVal = QString::number(aValueAttribute->value());
103 QString aTitle = QString(myObject->data()->name().c_str());
104 return aTitle + " = " + aVal;
106 return myObject->data()->name().c_str();
109 case Qt::DecorationRole:
112 switch (visibilityState()) {
116 return QIcon(":pictures/eyeopen.png");
118 return QIcon(":pictures/eyemiclosed.png");
120 return QIcon(":pictures/eyeclosed.png");
123 if (myObject->groupName() == ModelAPI_Folder::group())
124 return QIcon(":pictures/features_folder.png");
126 return ModuleBase_IconFactory::get()->getIcon(myObject);
128 if (isCurrentFeature(myObject))
129 return QIcon(":pictures/arrow.png");
132 return PartSet_TreeNode::data(theColumn, theRole);
135 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
137 if (!myObject->isDisabled()) {
138 DocumentPtr aDoc = myObject->document();
139 SessionPtr aSession = ModelAPI_Session::get();
140 if (aSession->activeDocument() == aDoc)
146 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
148 Qt::ItemFlags aFlags = flags(1);
149 if (aFlags == Qt::ItemFlags())
152 if (myObject->groupName() == ModelAPI_ResultParameter::group())
154 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
156 ModuleBase_IWorkshop* aWork = workshop();
157 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
158 if (aCompRes.get()) {
159 VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
160 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
161 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
162 ResultPtr aSubRes = aCompRes->subResult(i, true);
163 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
164 if (aState == NoneState)
166 else if (aState != aS) {
167 aState = SemiVisible;
173 if (aWork->isVisible(aResObj))
183 //////////////////////////////////////////////////////////////////////////////////
184 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
186 : PartSet_TreeNode(theParent), myType(theType)
190 QString PartSet_FolderNode::name() const
193 case ParametersFolder:
194 return QObject::tr("Parameters");
195 case ConstructionFolder:
196 return QObject::tr("Constructions");
198 return QObject::tr("Parts");
200 return QObject::tr("Results");
202 return QObject::tr("Fields");
204 return QObject::tr("Groups");
210 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
212 static QIcon aParamsIco(":pictures/params_folder.png");
213 static QIcon aConstrIco(":pictures/constr_folder.png");
215 if (theColumn == 1) {
217 case Qt::DisplayRole:
218 return name() + QString(" (%1)").arg(childrenCount());
219 case Qt::DecorationRole:
221 case ParametersFolder:
223 case ConstructionFolder:
236 return PartSet_TreeNode::data(theColumn, theRole);
239 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
241 SessionPtr aSession = ModelAPI_Session::get();
242 DocumentPtr aActiveDoc = aSession->activeDocument();
243 if (theColumn == 1) {
244 if (document() == aActiveDoc)
250 void PartSet_FolderNode::update()
252 DocumentPtr aDoc = document();
256 // Remove extra sub-nodes
257 QTreeNodesList aDelList;
260 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
262 aIndex = aDoc->index(aNode->object(), true);
263 if ((aIndex == -1) || (aId != aIndex))
264 aDelList.append(aNode);
266 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
267 myChildren.removeAll(aNode);
272 std::string aGroup = groupName();
273 int aSize = aDoc->size(aGroup, true);
274 for (int i = 0; i < aSize; i++) {
275 ObjectPtr aObj = aDoc->object(aGroup, i, true);
276 if (i < myChildren.size()) {
277 if (myChildren.at(i)->object() != aObj) {
278 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
279 myChildren.insert(i, aNode);
282 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
283 myChildren.append(aNode);
288 std::string PartSet_FolderNode::groupName() const
291 case ParametersFolder:
292 return ModelAPI_ResultParameter::group();
293 case ConstructionFolder:
294 return ModelAPI_ResultConstruction::group();
296 return ModelAPI_ResultPart::group();
298 return ModelAPI_ResultBody::group();
300 return ModelAPI_ResultField::group();
302 return ModelAPI_ResultGroup::group();
307 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
309 QTreeNodesList aResult;
310 std::string aName = groupName();
311 DocumentPtr aDoc = document();
313 foreach(ObjectPtr aObj, theObjects) {
314 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
315 aIdx = aDoc->index(aObj, true);
317 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
319 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
320 aResult.append(aNode);
321 if (aIdx < myChildren.size())
322 myChildren.insert(aIdx, aNode);
324 myChildren.append(aNode);
332 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
333 const QString& theGroup)
335 DocumentPtr aDoc = document();
336 QTreeNodesList aResult;
337 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
338 QTreeNodesList aDelList;
341 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
343 aIndex = aDoc->index(aNode->object(), true);
344 if ((aIndex == -1) || (aId != aIndex))
345 aDelList.append(aNode);
347 if (aDelList.size() > 0) {
348 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
349 myChildren.removeAll(aNode);
352 aResult.append(this);
358 //////////////////////////////////////////////////////////////////////////////////
359 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
361 QTreeNodesList aResult;
362 // Process all folders
363 ModuleBase_ITreeNode* aFoder = 0;
364 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
365 aFoder = dynamic_cast<PartSet_FolderNode*>(aNode);
367 aFoder = dynamic_cast<PartSet_FeatureFolderNode*>(aNode);
369 if (aFoder) { // aFolder node
370 QTreeNodesList aList = aNode->objectCreated(theObjects);
371 if (aList.size() > 0)
372 aResult.append(aList);
375 // Process the root sub-objects
376 DocumentPtr aDoc = document();
378 int aNb = numberOfFolders();
379 foreach(ObjectPtr aObj, theObjects) {
380 if (aDoc == aObj->document()) {
381 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
382 (aObj->groupName() == ModelAPI_Folder::group())){
383 ModuleBase_ITreeNode* aNode = createNode(aObj);
384 aIdx = aDoc->index(aObj, true) + aNb;
385 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
387 if (aIdx < myChildren.size())
388 myChildren.insert(aIdx, aNode);
390 myChildren.append(aNode);
391 aResult.append(aNode);
396 // Update sub-folders
397 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
398 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
399 (aNode->type() == PartSet_PartRootNode::typeId()))
400 aResult.append(aNode->objectCreated(theObjects));
405 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
406 const QString& theGroup)
408 QTreeNodesList aResult;
410 // Process sub-folders
411 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
412 if (aNode->childrenCount() > 0) { // aFolder node
413 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
414 if (aList.size() > 0)
415 aResult.append(aList);
420 DocumentPtr aDoc = document();
421 int aNb = numberOfFolders();
422 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
423 (theGroup.toStdString() == ModelAPI_Folder::group()));
424 if ((theDoc == aDoc) && isGroup) {
425 QTreeNodesList aDelList;
428 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
430 if (aNode->object().get()) {
431 aIndex = aDoc->index(aNode->object(), true);
432 if ((aIndex == -1) || (aId != aIndex))
433 aDelList.append(aNode);
436 if (aDelList.size() > 0) {
437 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
438 myChildren.removeAll(aNode);
441 aResult.append(this);
447 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
450 ModuleBase_ITreeNode* aResult = 0;
451 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
452 aResult = aNode->findParent(theDoc, theGroup);
457 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
458 (theGroup.toStdString() == ModelAPI_Folder::group()));
459 if ((theDoc == document()) && isGroup)
465 //////////////////////////////////////////////////////////////////////////////////
466 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
468 SessionPtr aSession = ModelAPI_Session::get();
469 DocumentPtr aDoc = aSession->moduleDocument();
471 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
472 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
473 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
475 myChildren.append(myParamsFolder);
476 myChildren.append(myConstrFolder);
477 myChildren.append(myPartsFolder);
483 void PartSet_RootNode::update()
485 myParamsFolder->update();
486 myConstrFolder->update();
487 myPartsFolder->update();
489 // Update features content
490 DocumentPtr aDoc = document();
491 int aNb = numberOfFolders();
493 // Remove extra sub-nodes
494 QTreeNodesList aDelList;
497 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
499 if (aNode->object().get()) {
500 aIndex = aDoc->index(aNode->object(), true);
501 if ((aIndex == -1) || (aId != (aIndex + aNb)))
502 aDelList.append(aNode);
505 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
506 myChildren.removeAll(aNode);
511 std::string aGroup = ModelAPI_Feature::group();
512 int aSize = aDoc->size(aGroup, true);
514 for (int i = 0; i < aSize; i++) {
515 ObjectPtr aObj = aDoc->object(aGroup, i, true);
516 aId = i + aNb; // Take into account existing folders
517 if (aId < myChildren.size()) {
518 if (myChildren.at(aId)->object() != aObj) {
519 ModuleBase_ITreeNode* aNode = createNode(aObj);
520 myChildren.insert(aId, aNode);
523 ModuleBase_ITreeNode* aNode = createNode(aObj);
524 myChildren.append(aNode);
527 // Update sub-folders
528 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
529 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
530 (aNode->type() == PartSet_PartRootNode::typeId()))
535 DocumentPtr PartSet_RootNode::document() const
537 return ModelAPI_Session::get()->moduleDocument();
540 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
542 if (theObj->groupName() == ModelAPI_Folder::group())
543 return new PartSet_ObjectFolderNode(theObj, this);
545 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
546 if (aFeature->getKind() == PartSetPlugin_Part::ID())
547 return new PartSet_PartRootNode(theObj, this);
549 return new PartSet_ObjectNode(theObj, this);
552 //////////////////////////////////////////////////////////////////////////////////
553 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
554 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
556 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
557 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
558 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
559 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
560 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
562 myChildren.append(myParamsFolder);
563 myChildren.append(myConstrFolder);
564 myChildren.append(myResultsFolder);
569 void PartSet_PartRootNode::deleteChildren()
571 if (!myFieldsFolder->childrenCount()) {
572 delete myFieldsFolder;
574 if (!myGroupsFolder->childrenCount()) {
575 delete myGroupsFolder;
577 PartSet_FeatureFolderNode::deleteChildren();
581 void PartSet_PartRootNode::update()
583 DocumentPtr aDoc = document();
587 myParamsFolder->update();
588 myConstrFolder->update();
589 myResultsFolder->update();
590 myFieldsFolder->update();
591 myGroupsFolder->update();
593 bool aHasFields = myFieldsFolder->childrenCount() > 0;
594 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
595 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
596 myChildren.insert(3, myFieldsFolder);
598 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
599 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
602 // Update features content
603 int aRows = numberOfFolders();
605 // Remove extra sub-nodes
606 QTreeNodesList aDelList;
609 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
611 if (aNode->object().get()) {
612 aIndex = aDoc->index(aNode->object(), true);
613 if ((aIndex == -1) || (aId != (aIndex + aRows)))
614 aDelList.append(aNode);
617 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
618 myChildren.removeAll(aNode);
622 std::string aGroup = ModelAPI_Feature::group();
623 int aSize = aDoc->size(aGroup, true);
625 for (int i = 0; i < aSize; i++) {
626 ObjectPtr aObj = aDoc->object(aGroup, i, true);
627 aId = i + aRows; // Take into account existing folders
628 if (aId < myChildren.size()) {
629 if (myChildren.at(aId)->object() != aObj) {
630 ModuleBase_ITreeNode* aNode = createNode(aObj);
631 myChildren.insert(aId, aNode);
634 ModuleBase_ITreeNode* aNode = createNode(aObj);
635 myChildren.append(aNode);
638 // Update sub-folders
639 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
640 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
645 DocumentPtr PartSet_PartRootNode::document() const
647 ResultPartPtr aPartRes = getPartResult(myObject);
649 return aPartRes->partDoc();
650 return DocumentPtr();
653 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
658 case Qt::DisplayRole:
659 return QString(myObject->data()->name().c_str());
660 case Qt::DecorationRole:
661 return ModuleBase_IconFactory::get()->getIcon(myObject);
664 if (theRole == Qt::DecorationRole)
665 if (isCurrentFeature(myObject))
666 return QIcon(":pictures/arrow.png");
668 return PartSet_TreeNode::data(theColumn, theRole);
671 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
673 SessionPtr aSession = ModelAPI_Session::get();
674 DocumentPtr aActiveDoc = aSession->activeDocument();
675 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
680 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
682 if (theObj->groupName() == ModelAPI_Folder::group())
683 return new PartSet_ObjectFolderNode(theObj, this);
684 return new PartSet_ObjectNode(theObj, this);
687 int PartSet_PartRootNode::numberOfFolders() const
690 if (myFieldsFolder->childrenCount() > 0)
692 if (myGroupsFolder->childrenCount() > 0)
697 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
699 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
700 if (!myFieldsFolder->childrenCount()) {
701 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
703 myChildren.insert(3, myFieldsFolder);
704 aResult.append(myFieldsFolder);
705 aResult.append(aList);
708 if (!myGroupsFolder->childrenCount()) {
709 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
711 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
712 aResult.append(myGroupsFolder);
713 aResult.append(aList);
719 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
720 const QString& theGroup)
722 QTreeNodesList aResult;
723 if (myFieldsFolder->childrenCount()) {
724 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
726 aResult.append(aList);
727 if (!myFieldsFolder->childrenCount())
728 myChildren.removeAll(myFieldsFolder);
731 if (myGroupsFolder->childrenCount()) {
732 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
734 aResult.append(aList);
735 if (!myGroupsFolder->childrenCount())
736 myChildren.removeAll(myGroupsFolder);
739 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
743 //////////////////////////////////////////////////////////////////////////////////
744 void PartSet_ObjectFolderNode::update()
747 getFirstAndLastIndex(aFirst, aLast);
748 if ((aFirst == -1) || (aLast == -1)) {
753 int aNbItems = aLast - aFirst + 1;
759 DocumentPtr aDoc = myObject->document();
760 // Delete obsolete nodes
761 QTreeNodesList aDelList;
763 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
765 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
766 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
767 aDelList.append(aNode);
770 aDelList.append(aNode);
773 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
774 myChildren.removeAll(aNode);
779 ModuleBase_ITreeNode* aNode;
780 for (int i = 0; i < aNbItems; i++) {
781 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
782 if (i < myChildren.size()) {
783 if (aObj != myChildren.at(i)->object()) {
784 aNode = new PartSet_ObjectNode(aObj, this);
785 myChildren.insert(i, aNode);
788 aNode = new PartSet_ObjectNode(aObj, this);
789 myChildren.append(aNode);
794 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
796 QTreeNodesList aResult;
798 getFirstAndLastIndex(aFirst, aLast);
799 if ((aFirst == -1) || (aLast == -1)) {
802 int aNbItems = aLast - aFirst + 1;
806 DocumentPtr aDoc = myObject->document();
808 ModuleBase_ITreeNode* aNode;
809 for (int i = 0; i < aNbItems; i++) {
810 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
811 if (i < myChildren.size()) {
812 if (aObj != myChildren.at(i)->object()) {
813 aNode = new PartSet_ObjectNode(aObj, this);
814 myChildren.insert(i, aNode);
815 aResult.append(aNode);
818 aNode = new PartSet_ObjectNode(aObj, this);
819 myChildren.append(aNode);
820 aResult.append(aNode);
826 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
827 const QString& theGroup)
829 QTreeNodesList aResult;
831 getFirstAndLastIndex(aFirst, aLast);
832 if ((aFirst == -1) || (aLast == -1)) {
835 int aNbItems = aLast - aFirst + 1;
839 DocumentPtr aDoc = myObject->document();
840 // Delete obsolete nodes
841 QTreeNodesList aDelList;
843 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
845 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
846 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
847 aDelList.append(aNode);
850 aDelList.append(aNode);
853 if (aDelList.size() > 0) {
854 aResult.append(this);
855 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
856 myChildren.removeAll(aNode);
863 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
865 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
866 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
868 return ModelAPI_Feature::feature(aFeatAttr->value());
872 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
874 DocumentPtr aDoc = myObject->document();
875 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
877 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
878 if (!aFirstFeatureInFolder.get()) {
882 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
883 if (!aLastFeatureInFolder.get()) {
888 theFirst = aDoc->index(aFirstFeatureInFolder);
889 theLast = aDoc->index(aLastFeatureInFolder);