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 return (theColumn == 2) ? Qt::ItemIsSelectable : aNullFlag;
140 DocumentPtr aDoc = myObject->document();
141 SessionPtr aSession = ModelAPI_Session::get();
142 if (aSession->activeDocument() == aDoc)
148 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
150 Qt::ItemFlags aFlags = flags(1);
151 if (aFlags == Qt::ItemFlags())
154 if (myObject->groupName() == ModelAPI_ResultParameter::group())
156 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
158 ModuleBase_IWorkshop* aWork = workshop();
159 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
160 if (aCompRes.get()) {
161 VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
162 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
163 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
164 ResultPtr aSubRes = aCompRes->subResult(i, true);
165 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
166 if (aState == NoneState)
168 else if (aState != aS) {
169 aState = SemiVisible;
175 if (aWork->isVisible(aResObj))
185 //////////////////////////////////////////////////////////////////////////////////
186 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
188 : PartSet_TreeNode(theParent), myType(theType)
192 QString PartSet_FolderNode::name() const
195 case ParametersFolder:
196 return QObject::tr("Parameters");
197 case ConstructionFolder:
198 return QObject::tr("Constructions");
200 return QObject::tr("Parts");
202 return QObject::tr("Results");
204 return QObject::tr("Fields");
206 return QObject::tr("Groups");
212 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
214 static QIcon aParamsIco(":pictures/params_folder.png");
215 static QIcon aConstrIco(":pictures/constr_folder.png");
217 if (theColumn == 1) {
219 case Qt::DisplayRole:
220 return name() + QString(" (%1)").arg(childrenCount());
221 case Qt::DecorationRole:
223 case ParametersFolder:
225 case ConstructionFolder:
238 return PartSet_TreeNode::data(theColumn, theRole);
241 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
243 SessionPtr aSession = ModelAPI_Session::get();
244 DocumentPtr aActiveDoc = aSession->activeDocument();
245 if (theColumn == 1) {
246 if (document() == aActiveDoc)
252 void PartSet_FolderNode::update()
254 DocumentPtr aDoc = document();
258 // Remove extra sub-nodes
259 QTreeNodesList aDelList;
262 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
264 aIndex = aDoc->index(aNode->object(), true);
265 if ((aIndex == -1) || (aId != aIndex))
266 aDelList.append(aNode);
268 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
269 myChildren.removeAll(aNode);
274 std::string aGroup = groupName();
275 int aSize = aDoc->size(aGroup, true);
276 for (int i = 0; i < aSize; i++) {
277 ObjectPtr aObj = aDoc->object(aGroup, i, true);
278 if (i < myChildren.size()) {
279 if (myChildren.at(i)->object() != aObj) {
280 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
281 myChildren.insert(i, aNode);
284 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
285 myChildren.append(aNode);
290 std::string PartSet_FolderNode::groupName() const
293 case ParametersFolder:
294 return ModelAPI_ResultParameter::group();
295 case ConstructionFolder:
296 return ModelAPI_ResultConstruction::group();
298 return ModelAPI_ResultPart::group();
300 return ModelAPI_ResultBody::group();
302 return ModelAPI_ResultField::group();
304 return ModelAPI_ResultGroup::group();
309 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
311 QTreeNodesList aResult;
312 std::string aName = groupName();
313 DocumentPtr aDoc = document();
315 foreach(ObjectPtr aObj, theObjects) {
316 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
317 aIdx = aDoc->index(aObj, true);
319 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
321 PartSet_ObjectNode* aNode = new PartSet_ObjectNode(aObj, this);
322 aResult.append(aNode);
323 if (aIdx < myChildren.size())
324 myChildren.insert(aIdx, aNode);
326 myChildren.append(aNode);
334 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
335 const QString& theGroup)
337 DocumentPtr aDoc = document();
338 QTreeNodesList aResult;
339 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
340 QTreeNodesList aDelList;
343 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
345 aIndex = aDoc->index(aNode->object(), true);
346 if ((aIndex == -1) || (aId != aIndex))
347 aDelList.append(aNode);
349 if (aDelList.size() > 0) {
350 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
351 myChildren.removeAll(aNode);
354 aResult.append(this);
360 //////////////////////////////////////////////////////////////////////////////////
361 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
363 QTreeNodesList aResult;
364 // Process all folders
365 ModuleBase_ITreeNode* aFoder = 0;
366 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
367 if ((aNode->type() == PartSet_FolderNode::typeId()) ||
368 (aNode->type() == PartSet_PartRootNode::typeId())) { // aFolder node
369 QTreeNodesList aList = aNode->objectCreated(theObjects);
370 if (aList.size() > 0)
371 aResult.append(aList);
374 // Process the root sub-objects
375 DocumentPtr aDoc = document();
377 int aNb = numberOfFolders();
378 foreach(ObjectPtr aObj, theObjects) {
379 if (aDoc == aObj->document()) {
380 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
381 (aObj->groupName() == ModelAPI_Folder::group())){
382 ModuleBase_ITreeNode* aNode = createNode(aObj);
383 aIdx = aDoc->index(aObj, true);
386 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
388 if (aIdx < myChildren.size())
389 myChildren.insert(aIdx, aNode);
391 myChildren.append(aNode);
392 aResult.append(aNode);
398 // Update sub-folders
399 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
400 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
401 (aNode->type() == PartSet_PartRootNode::typeId()))
402 aResult.append(aNode->objectCreated(theObjects));
407 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
408 const QString& theGroup)
410 QTreeNodesList aResult;
412 // Process sub-folders
413 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
414 if (aNode->childrenCount() > 0) { // aFolder node
415 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
416 if (aList.size() > 0)
417 aResult.append(aList);
422 DocumentPtr aDoc = document();
423 int aNb = numberOfFolders();
424 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
425 (theGroup.toStdString() == ModelAPI_Folder::group()));
426 if ((theDoc == aDoc) && isGroup) {
427 QTreeNodesList aDelList;
430 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
432 if (aNode->object().get()) {
433 aIndex = aDoc->index(aNode->object(), true);
434 if ((aIndex == -1) || (aId != (aIndex + aNb)))
435 aDelList.append(aNode);
438 if (aDelList.size() > 0) {
439 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
440 myChildren.removeAll(aNode);
443 aResult.append(this);
449 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
452 ModuleBase_ITreeNode* aResult = 0;
453 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
454 aResult = aNode->findParent(theDoc, theGroup);
459 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
460 (theGroup.toStdString() == ModelAPI_Folder::group()));
461 if ((theDoc == document()) && isGroup)
467 //////////////////////////////////////////////////////////////////////////////////
468 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
470 SessionPtr aSession = ModelAPI_Session::get();
471 DocumentPtr aDoc = aSession->moduleDocument();
473 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
474 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
475 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
477 myChildren.append(myParamsFolder);
478 myChildren.append(myConstrFolder);
479 myChildren.append(myPartsFolder);
485 void PartSet_RootNode::update()
487 myParamsFolder->update();
488 myConstrFolder->update();
489 myPartsFolder->update();
491 // Update features content
492 DocumentPtr aDoc = document();
493 int aNb = numberOfFolders();
495 // Remove extra sub-nodes
496 QTreeNodesList aDelList;
499 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
501 if (aNode->object().get()) {
502 aIndex = aDoc->index(aNode->object(), true);
503 if ((aIndex == -1) || (aId != (aIndex + aNb)))
504 aDelList.append(aNode);
507 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
508 myChildren.removeAll(aNode);
513 std::string aGroup = ModelAPI_Feature::group();
514 int aSize = aDoc->size(aGroup, true);
516 for (int i = 0; i < aSize; i++) {
517 ObjectPtr aObj = aDoc->object(aGroup, i, true);
518 aId = i + aNb; // Take into account existing folders
519 if (aId < myChildren.size()) {
520 if (myChildren.at(aId)->object() != aObj) {
521 ModuleBase_ITreeNode* aNode = createNode(aObj);
522 myChildren.insert(aId, aNode);
525 ModuleBase_ITreeNode* aNode = createNode(aObj);
526 myChildren.append(aNode);
529 // Update sub-folders
530 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
531 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
532 (aNode->type() == PartSet_PartRootNode::typeId()))
537 DocumentPtr PartSet_RootNode::document() const
539 return ModelAPI_Session::get()->moduleDocument();
542 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
544 if (theObj->groupName() == ModelAPI_Folder::group())
545 return new PartSet_ObjectFolderNode(theObj, this);
547 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
548 if (aFeature->getKind() == PartSetPlugin_Part::ID())
549 return new PartSet_PartRootNode(theObj, this);
551 return new PartSet_ObjectNode(theObj, this);
554 //////////////////////////////////////////////////////////////////////////////////
555 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
556 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
558 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
559 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
560 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
561 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
562 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
564 myChildren.append(myParamsFolder);
565 myChildren.append(myConstrFolder);
566 myChildren.append(myResultsFolder);
571 void PartSet_PartRootNode::deleteChildren()
573 if (!myFieldsFolder->childrenCount()) {
574 delete myFieldsFolder;
576 if (!myGroupsFolder->childrenCount()) {
577 delete myGroupsFolder;
579 PartSet_FeatureFolderNode::deleteChildren();
583 void PartSet_PartRootNode::update()
585 DocumentPtr aDoc = document();
589 myParamsFolder->update();
590 myConstrFolder->update();
591 myResultsFolder->update();
592 myFieldsFolder->update();
593 myGroupsFolder->update();
595 bool aHasFields = myFieldsFolder->childrenCount() > 0;
596 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
597 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
598 myChildren.insert(3, myFieldsFolder);
600 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
601 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
604 // Update features content
605 int aRows = numberOfFolders();
607 // Remove extra sub-nodes
608 QTreeNodesList aDelList;
611 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
613 if (aNode->object().get()) {
614 aIndex = aDoc->index(aNode->object(), true);
615 if ((aIndex == -1) || (aId != (aIndex + aRows)))
616 aDelList.append(aNode);
619 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
620 myChildren.removeAll(aNode);
624 std::string aGroup = ModelAPI_Feature::group();
625 int aSize = aDoc->size(aGroup, true);
627 for (int i = 0; i < aSize; i++) {
628 ObjectPtr aObj = aDoc->object(aGroup, i, true);
629 aId = i + aRows; // Take into account existing folders
630 if (aId < myChildren.size()) {
631 if (myChildren.at(aId)->object() != aObj) {
632 ModuleBase_ITreeNode* aNode = createNode(aObj);
633 myChildren.insert(aId, aNode);
636 ModuleBase_ITreeNode* aNode = createNode(aObj);
637 myChildren.append(aNode);
640 // Update sub-folders
641 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
642 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
647 DocumentPtr PartSet_PartRootNode::document() const
649 ResultPartPtr aPartRes = getPartResult(myObject);
651 return aPartRes->partDoc();
652 return DocumentPtr();
655 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
660 case Qt::DisplayRole:
661 return QString(myObject->data()->name().c_str());
662 case Qt::DecorationRole:
663 return ModuleBase_IconFactory::get()->getIcon(myObject);
666 if (theRole == Qt::DecorationRole)
667 if (isCurrentFeature(myObject))
668 return QIcon(":pictures/arrow.png");
670 return PartSet_TreeNode::data(theColumn, theRole);
673 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
675 SessionPtr aSession = ModelAPI_Session::get();
676 DocumentPtr aActiveDoc = aSession->activeDocument();
677 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
682 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
684 if (theObj->groupName() == ModelAPI_Folder::group())
685 return new PartSet_ObjectFolderNode(theObj, this);
686 return new PartSet_ObjectNode(theObj, this);
689 int PartSet_PartRootNode::numberOfFolders() const
692 if (myFieldsFolder->childrenCount() > 0)
694 if (myGroupsFolder->childrenCount() > 0)
699 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
701 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
702 if (!myFieldsFolder->childrenCount()) {
703 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
705 myChildren.insert(3, myFieldsFolder);
706 aResult.append(myFieldsFolder);
707 aResult.append(aList);
710 if (!myGroupsFolder->childrenCount()) {
711 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
713 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
714 aResult.append(myGroupsFolder);
715 aResult.append(aList);
721 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
722 const QString& theGroup)
724 QTreeNodesList aResult;
725 if (myFieldsFolder->childrenCount()) {
726 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
728 aResult.append(aList);
729 if (!myFieldsFolder->childrenCount())
730 myChildren.removeAll(myFieldsFolder);
733 if (myGroupsFolder->childrenCount()) {
734 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
736 aResult.append(aList);
737 if (!myGroupsFolder->childrenCount())
738 myChildren.removeAll(myGroupsFolder);
741 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
745 //////////////////////////////////////////////////////////////////////////////////
746 void PartSet_ObjectFolderNode::update()
749 getFirstAndLastIndex(aFirst, aLast);
750 if ((aFirst == -1) || (aLast == -1)) {
755 int aNbItems = aLast - aFirst + 1;
761 DocumentPtr aDoc = myObject->document();
762 // Delete obsolete nodes
763 QTreeNodesList aDelList;
765 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
767 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
768 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
769 aDelList.append(aNode);
772 aDelList.append(aNode);
775 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
776 myChildren.removeAll(aNode);
781 ModuleBase_ITreeNode* aNode;
782 for (int i = 0; i < aNbItems; i++) {
783 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
784 if (i < myChildren.size()) {
785 if (aObj != myChildren.at(i)->object()) {
786 aNode = new PartSet_ObjectNode(aObj, this);
787 myChildren.insert(i, aNode);
790 aNode = new PartSet_ObjectNode(aObj, this);
791 myChildren.append(aNode);
796 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
798 QTreeNodesList aResult;
800 getFirstAndLastIndex(aFirst, aLast);
801 if ((aFirst == -1) || (aLast == -1)) {
804 int aNbItems = aLast - aFirst + 1;
808 DocumentPtr aDoc = myObject->document();
810 ModuleBase_ITreeNode* aNode;
811 for (int i = 0; i < aNbItems; i++) {
812 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
813 if (i < myChildren.size()) {
814 if (aObj != myChildren.at(i)->object()) {
815 aNode = new PartSet_ObjectNode(aObj, this);
816 myChildren.insert(i, aNode);
817 aResult.append(aNode);
820 aNode = new PartSet_ObjectNode(aObj, this);
821 myChildren.append(aNode);
822 aResult.append(aNode);
828 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
829 const QString& theGroup)
831 QTreeNodesList aResult;
833 getFirstAndLastIndex(aFirst, aLast);
834 if ((aFirst == -1) || (aLast == -1)) {
837 int aNbItems = aLast - aFirst + 1;
841 DocumentPtr aDoc = myObject->document();
842 // Delete obsolete nodes
843 QTreeNodesList aDelList;
845 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
847 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
848 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
849 aDelList.append(aNode);
852 aDelList.append(aNode);
855 if (aDelList.size() > 0) {
856 aResult.append(this);
857 foreach(ModuleBase_ITreeNode* aNode, aDelList) {
858 myChildren.removeAll(aNode);
865 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
867 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
868 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
870 return ModelAPI_Feature::feature(aFeatAttr->value());
874 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
876 DocumentPtr aDoc = myObject->document();
877 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
879 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
880 if (!aFirstFeatureInFolder.get()) {
884 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
885 if (!aLastFeatureInFolder.get()) {
890 theFirst = aDoc->index(aFirstFeatureInFolder);
891 theLast = aDoc->index(aLastFeatureInFolder);