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>
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 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
161 if (aCompRes.get()) {
162 VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
163 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
164 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
165 ResultPtr aSubRes = aCompRes->subResult(i, true);
166 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
167 if (aState == NoneState)
169 else if (aState != aS) {
170 aState = SemiVisible;
176 if (aWork->isVisible(aResObj))
186 //////////////////////////////////////////////////////////////////////////////////
187 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
189 : PartSet_TreeNode(theParent), myType(theType)
193 QString PartSet_FolderNode::name() const
196 case ParametersFolder:
197 return QObject::tr("Parameters");
198 case ConstructionFolder:
199 return QObject::tr("Constructions");
201 return QObject::tr("Parts");
203 return QObject::tr("Results");
205 return QObject::tr("Fields");
207 return QObject::tr("Groups");
213 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
215 static QIcon aParamsIco(":pictures/params_folder.png");
216 static QIcon aConstrIco(":pictures/constr_folder.png");
218 if (theColumn == 1) {
220 case Qt::DisplayRole:
221 return name() + QString(" (%1)").arg(childrenCount());
222 case Qt::DecorationRole:
224 case ParametersFolder:
226 case ConstructionFolder:
239 return PartSet_TreeNode::data(theColumn, theRole);
242 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
244 SessionPtr aSession = ModelAPI_Session::get();
245 DocumentPtr aActiveDoc = aSession->activeDocument();
246 if (theColumn == 1) {
247 if (document() == aActiveDoc)
253 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
255 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
257 return new PartSet_CompsolidNode(theObj, this);
258 return new PartSet_ObjectNode(theObj, this);
261 void PartSet_FolderNode::update()
263 DocumentPtr aDoc = document();
267 // Remove extra sub-nodes
270 while (aId < myChildren.size()) {
271 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
272 aIndex = aDoc->index(aNode->object(), true);
273 if ((aIndex == -1) || (aId != aIndex)) {
274 myChildren.removeAll(aNode);
281 std::string aGroup = groupName();
282 int aSize = aDoc->size(aGroup, true);
283 for (int i = 0; i < aSize; i++) {
284 ObjectPtr aObj = aDoc->object(aGroup, i, true);
285 if (i < myChildren.size()) {
286 if (myChildren.at(i)->object() != aObj) {
287 ModuleBase_ITreeNode* aNode = createNode(aObj);
288 myChildren.insert(i, aNode);
291 ModuleBase_ITreeNode* aNode = createNode(aObj);
292 myChildren.append(aNode);
296 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
301 std::string PartSet_FolderNode::groupName() const
304 case ParametersFolder:
305 return ModelAPI_ResultParameter::group();
306 case ConstructionFolder:
307 return ModelAPI_ResultConstruction::group();
309 return ModelAPI_ResultPart::group();
311 return ModelAPI_ResultBody::group();
313 return ModelAPI_ResultField::group();
315 return ModelAPI_ResultGroup::group();
320 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
322 QTreeNodesList aResult;
323 std::string aName = groupName();
324 DocumentPtr aDoc = document();
326 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
327 foreach(ObjectPtr aObj, theObjects) {
328 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
329 aIdx = aDoc->index(aObj, true);
331 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
333 ModuleBase_ITreeNode* aNode = createNode(aObj);
334 aNewNodes[aIdx] = aNode;
335 aResult.append(aNode);
340 // Add nodes in correct order
342 for (i = 0; i < myChildren.size(); i++) {
343 if (aNewNodes.contains(i)) {
344 myChildren.insert(i, aNewNodes[i]);
348 while (aNewNodes.size()) {
349 i = myChildren.size();
350 myChildren.append(aNewNodes[i]);
353 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
354 aResult.append(aNode->objectCreated(theObjects));
359 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
360 const QString& theGroup)
362 DocumentPtr aDoc = document();
363 QTreeNodesList aResult;
364 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
365 QTreeNodesList aDelList;
368 bool aRemoved = false;
369 while (aId < myChildren.size()) {
370 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
371 aIndex = aDoc->index(aNode->object(), true);
372 if ((aIndex == -1) || (aId != aIndex)) {
373 myChildren.removeAll(aNode);
380 aResult.append(this);
382 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
383 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
389 //////////////////////////////////////////////////////////////////////////////////
390 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
392 QTreeNodesList aResult;
393 // Process all folders
394 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
395 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
396 aResult.append(aNode->objectCreated(theObjects));
399 // Process the root sub-objects
400 DocumentPtr aDoc = document();
402 int aNb = numberOfFolders();
403 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
404 foreach(ObjectPtr aObj, theObjects) {
405 if (aDoc == aObj->document()) {
406 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
407 (aObj->groupName() == ModelAPI_Folder::group())){
408 ModuleBase_ITreeNode* aNode = createNode(aObj);
409 aIdx = aDoc->index(aObj, true);
412 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
414 aNewNodes[aIdx] = aNode;
415 aResult.append(aNode);
421 // To add in correct order
423 for (i = 0; i < myChildren.size(); i++) {
424 if (aNewNodes.contains(i)) {
425 myChildren.insert(i, aNewNodes[i]);
429 while (aNewNodes.size()) {
430 i = myChildren.size();
431 myChildren.append(aNewNodes[i]);
435 // Update sub-folders
436 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
437 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
438 (aNode->type() == PartSet_PartRootNode::typeId()))
439 aResult.append(aNode->objectCreated(theObjects));
444 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
445 const QString& theGroup)
447 QTreeNodesList aResult;
449 // Process sub-folders
450 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
451 if (aNode->childrenCount() > 0) { // aFolder node
452 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
453 if (aList.size() > 0)
454 aResult.append(aList);
459 DocumentPtr aDoc = document();
460 int aNb = numberOfFolders();
461 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
462 (theGroup.toStdString() == ModelAPI_Folder::group()));
463 if ((theDoc == aDoc) && isGroup) {
466 bool aRemoved = false;
467 while (aId < myChildren.size()) {
468 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
469 if (aNode->object().get()) {
470 aIndex = aDoc->index(aNode->object(), true);
471 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
472 myChildren.removeAll(aNode);
481 aResult.append(this);
486 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
489 ModuleBase_ITreeNode* aResult = 0;
490 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
491 aResult = aNode->findParent(theDoc, theGroup);
496 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
497 (theGroup.toStdString() == ModelAPI_Folder::group()));
498 if ((theDoc == document()) && isGroup)
504 //////////////////////////////////////////////////////////////////////////////////
505 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
507 SessionPtr aSession = ModelAPI_Session::get();
508 DocumentPtr aDoc = aSession->moduleDocument();
510 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
511 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
512 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
514 myChildren.append(myParamsFolder);
515 myChildren.append(myConstrFolder);
516 myChildren.append(myPartsFolder);
522 void PartSet_RootNode::update()
524 myParamsFolder->update();
525 myConstrFolder->update();
526 myPartsFolder->update();
528 // Update features content
529 DocumentPtr aDoc = document();
530 int aNb = numberOfFolders();
532 // Remove extra sub-nodes
535 while (aId < myChildren.size()) {
536 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
537 if (aNode->object().get()) {
538 aIndex = aDoc->index(aNode->object(), true);
539 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
540 myChildren.removeAll(aNode);
549 std::string aGroup = ModelAPI_Feature::group();
550 int aSize = aDoc->size(aGroup, true);
552 for (int i = 0; i < aSize; i++) {
553 ObjectPtr aObj = aDoc->object(aGroup, i, true);
554 aId = i + aNb; // Take into account existing folders
555 if (aId < myChildren.size()) {
556 if (myChildren.at(aId)->object() != aObj) {
557 ModuleBase_ITreeNode* aNode = createNode(aObj);
558 myChildren.insert(aId, aNode);
561 ModuleBase_ITreeNode* aNode = createNode(aObj);
562 myChildren.append(aNode);
565 // Update sub-folders
566 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
567 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
568 (aNode->type() == PartSet_PartRootNode::typeId()))
573 DocumentPtr PartSet_RootNode::document() const
575 return ModelAPI_Session::get()->moduleDocument();
578 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
580 if (theObj->groupName() == ModelAPI_Folder::group())
581 return new PartSet_ObjectFolderNode(theObj, this);
583 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
584 if (aFeature->getKind() == PartSetPlugin_Part::ID())
585 return new PartSet_PartRootNode(theObj, this);
587 return new PartSet_ObjectNode(theObj, this);
590 //////////////////////////////////////////////////////////////////////////////////
591 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
592 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
594 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
595 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
596 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
597 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
598 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
600 myChildren.append(myParamsFolder);
601 myChildren.append(myConstrFolder);
602 myChildren.append(myResultsFolder);
607 void PartSet_PartRootNode::deleteChildren()
609 if (!myFieldsFolder->childrenCount()) {
610 delete myFieldsFolder;
612 if (!myGroupsFolder->childrenCount()) {
613 delete myGroupsFolder;
615 PartSet_FeatureFolderNode::deleteChildren();
619 void PartSet_PartRootNode::update()
621 DocumentPtr aDoc = document();
625 myParamsFolder->update();
626 myConstrFolder->update();
627 myResultsFolder->update();
628 myFieldsFolder->update();
629 myGroupsFolder->update();
631 bool aHasFields = myFieldsFolder->childrenCount() > 0;
632 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
633 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
634 myChildren.insert(3, myFieldsFolder);
636 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
637 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
640 // Update features content
641 int aRows = numberOfFolders();
643 // Remove extra sub-nodes
646 while (aId < myChildren.size()) {
647 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
648 if (aNode->object().get()) {
649 aIndex = aDoc->index(aNode->object(), true);
650 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
651 myChildren.removeAll(aNode);
659 std::string aGroup = ModelAPI_Feature::group();
660 int aSize = aDoc->size(aGroup, true);
662 for (int i = 0; i < aSize; i++) {
663 ObjectPtr aObj = aDoc->object(aGroup, i, true);
664 aId = i + aRows; // Take into account existing folders
665 if (aId < myChildren.size()) {
666 if (myChildren.at(aId)->object() != aObj) {
667 ModuleBase_ITreeNode* aNode = createNode(aObj);
668 myChildren.insert(aId, aNode);
671 ModuleBase_ITreeNode* aNode = createNode(aObj);
672 myChildren.append(aNode);
675 // Update sub-folders
676 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
677 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
682 DocumentPtr PartSet_PartRootNode::document() const
684 ResultPartPtr aPartRes = getPartResult(myObject);
686 return aPartRes->partDoc();
687 return DocumentPtr();
690 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
695 case Qt::DisplayRole:
696 return QString(myObject->data()->name().c_str());
697 case Qt::DecorationRole:
698 return ModuleBase_IconFactory::get()->getIcon(myObject);
701 if (theRole == Qt::DecorationRole)
702 if (isCurrentFeature(myObject))
703 return QIcon(":pictures/arrow.png");
705 return PartSet_TreeNode::data(theColumn, theRole);
708 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
710 SessionPtr aSession = ModelAPI_Session::get();
711 DocumentPtr aActiveDoc = aSession->activeDocument();
712 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
717 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
719 if (theObj->groupName() == ModelAPI_Folder::group())
720 return new PartSet_ObjectFolderNode(theObj, this);
721 return new PartSet_ObjectNode(theObj, this);
724 int PartSet_PartRootNode::numberOfFolders() const
727 if (myFieldsFolder->childrenCount() > 0)
729 if (myGroupsFolder->childrenCount() > 0)
734 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
736 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
737 if (!myFieldsFolder->childrenCount()) {
738 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
740 myChildren.insert(3, myFieldsFolder);
741 aResult.append(myFieldsFolder);
742 aResult.append(aList);
745 if (!myGroupsFolder->childrenCount()) {
746 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
748 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
749 aResult.append(myGroupsFolder);
750 aResult.append(aList);
756 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
757 const QString& theGroup)
759 QTreeNodesList aResult;
760 if (myFieldsFolder->childrenCount()) {
761 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
763 aResult.append(aList);
764 if (!myFieldsFolder->childrenCount())
765 myChildren.removeAll(myFieldsFolder);
768 if (myGroupsFolder->childrenCount()) {
769 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
771 aResult.append(aList);
772 if (!myGroupsFolder->childrenCount())
773 myChildren.removeAll(myGroupsFolder);
776 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
780 //////////////////////////////////////////////////////////////////////////////////
781 void PartSet_ObjectFolderNode::update()
784 getFirstAndLastIndex(aFirst, aLast);
785 if ((aFirst == -1) || (aLast == -1)) {
790 int aNbItems = aLast - aFirst + 1;
796 DocumentPtr aDoc = myObject->document();
797 // Delete obsolete nodes
799 while (aId < myChildren.size()) {
800 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
801 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
802 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
803 myChildren.removeAll(aNode);
812 ModuleBase_ITreeNode* aNode;
813 for (int i = 0; i < aNbItems; i++) {
814 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
815 if (i < myChildren.size()) {
816 if (aObj != myChildren.at(i)->object()) {
817 aNode = new PartSet_ObjectNode(aObj, this);
818 myChildren.insert(i, aNode);
821 aNode = new PartSet_ObjectNode(aObj, this);
822 myChildren.append(aNode);
827 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
829 QTreeNodesList aResult;
831 getFirstAndLastIndex(aFirst, aLast);
832 if ((aFirst == -1) || (aLast == -1)) {
835 int aNbItems = aLast - aFirst + 1;
839 DocumentPtr aDoc = myObject->document();
841 ModuleBase_ITreeNode* aNode;
842 for (int i = 0; i < aNbItems; i++) {
843 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
844 if (i < myChildren.size()) {
845 if (aObj != myChildren.at(i)->object()) {
846 aNode = new PartSet_ObjectNode(aObj, this);
847 myChildren.insert(i, aNode);
848 aResult.append(aNode);
851 aNode = new PartSet_ObjectNode(aObj, this);
852 myChildren.append(aNode);
853 aResult.append(aNode);
859 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
860 const QString& theGroup)
862 QTreeNodesList aResult;
864 getFirstAndLastIndex(aFirst, aLast);
865 if ((aFirst == -1) || (aLast == -1)) {
868 int aNbItems = aLast - aFirst + 1;
872 DocumentPtr aDoc = myObject->document();
873 // Delete obsolete nodes
874 bool aRemoved = false;
876 while (aId < myChildren.size()) {
877 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
878 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
879 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
880 myChildren.removeAll(aNode);
889 aResult.append(this);
894 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
896 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
897 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
899 return ModelAPI_Feature::feature(aFeatAttr->value());
903 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
905 DocumentPtr aDoc = myObject->document();
906 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
908 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
909 if (!aFirstFeatureInFolder.get()) {
913 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
914 if (!aLastFeatureInFolder.get()) {
919 theFirst = aDoc->index(aFirstFeatureInFolder);
920 theLast = aDoc->index(aLastFeatureInFolder);
924 //////////////////////////////////////////////////////////////////////////////////
925 PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
926 ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
931 void PartSet_CompsolidNode::update()
933 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
934 int aNb = aCompRes->numberOfSubs(true);
935 ModuleBase_ITreeNode* aNode;
938 for (i = 0; i < aNb; i++) {
939 aBody = aCompRes->subResult(i, true);
940 if (i < myChildren.size()) {
941 aNode = myChildren.at(i);
942 if (aNode->object() != aBody) {
943 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
946 aNode = new PartSet_ObjectNode(aBody, this);
947 myChildren.append(aNode);
950 // Delete extra objects
951 while (myChildren.size() > aNb) {
952 aNode = myChildren.takeLast();
957 QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
959 QTreeNodesList aResult;
961 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
962 int aNb = aCompRes->numberOfSubs(true);
963 ModuleBase_ITreeNode* aNode;
966 for (i = 0; i < aNb; i++) {
967 aBody = aCompRes->subResult(i, true);
968 if (i < myChildren.size()) {
969 aNode = myChildren.at(i);
970 if (aNode->object() != aBody) {
971 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
972 aResult.append(aNode);
975 aNode = new PartSet_ObjectNode(aBody, this);
976 myChildren.append(aNode);
977 aResult.append(aNode);
983 QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
985 QTreeNodesList aResult;
986 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
987 int aNb = aCompRes->numberOfSubs(true);
988 ModuleBase_ITreeNode* aNode;
989 // Delete extra objects
990 bool isDeleted = false;
991 while (myChildren.size() > aNb) {
992 aNode = myChildren.takeLast();
997 aResult.append(this);