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 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))
185 void PartSet_ObjectNode::update()
187 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
188 if (aCompRes.get()) {
189 int aNb = aCompRes->numberOfSubs(true);
190 ModuleBase_ITreeNode* aNode;
193 for (i = 0; i < aNb; i++) {
194 aBody = aCompRes->subResult(i, true);
195 if (i < myChildren.size()) {
196 aNode = myChildren.at(i);
197 if (aNode->object() != aBody) {
198 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
201 aNode = new PartSet_ObjectNode(aBody, this);
202 myChildren.append(aNode);
205 // Delete extra objects
206 while (myChildren.size() > aNb) {
207 aNode = myChildren.takeLast();
210 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
216 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
218 QTreeNodesList aResult;
220 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
221 if (aCompRes.get()) {
222 int aNb = aCompRes->numberOfSubs(true);
223 ModuleBase_ITreeNode* aNode;
226 for (i = 0; i < aNb; i++) {
227 aBody = aCompRes->subResult(i, true);
228 if (i < myChildren.size()) {
229 aNode = myChildren.at(i);
230 if (aNode->object() != aBody) {
231 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
232 aResult.append(aNode);
235 aNode = new PartSet_ObjectNode(aBody, this);
236 myChildren.append(aNode);
237 aResult.append(aNode);
240 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
241 aResult.append(aNode->objectCreated(theObjects));
247 QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
249 QTreeNodesList aResult;
250 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
251 if (aCompRes.get()) {
252 int aNb = aCompRes->numberOfSubs(true);
253 ModuleBase_ITreeNode* aNode;
254 // Delete extra objects
255 bool isDeleted = false;
256 while (myChildren.size() > aNb) {
257 aNode = myChildren.takeLast();
262 aResult.append(this);
264 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
265 ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true));
266 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
272 //////////////////////////////////////////////////////////////////////////////////
273 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
275 : PartSet_TreeNode(theParent), myType(theType)
279 QString PartSet_FolderNode::name() const
282 case ParametersFolder:
283 return QObject::tr("Parameters");
284 case ConstructionFolder:
285 return QObject::tr("Constructions");
287 return QObject::tr("Parts");
289 return QObject::tr("Results");
291 return QObject::tr("Fields");
293 return QObject::tr("Groups");
299 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
301 static QIcon aParamsIco(":pictures/params_folder.png");
302 static QIcon aConstrIco(":pictures/constr_folder.png");
304 if (theColumn == 1) {
306 case Qt::DisplayRole:
307 return name() + QString(" (%1)").arg(childrenCount());
308 case Qt::DecorationRole:
310 case ParametersFolder:
312 case ConstructionFolder:
325 return PartSet_TreeNode::data(theColumn, theRole);
328 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
330 SessionPtr aSession = ModelAPI_Session::get();
331 DocumentPtr aActiveDoc = aSession->activeDocument();
332 if (theColumn == 1) {
333 if (document() == aActiveDoc)
339 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
341 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
342 //if (aCompRes.get())
343 // return new PartSet_CompsolidNode(theObj, this);
344 return new PartSet_ObjectNode(theObj, this);
347 void PartSet_FolderNode::update()
349 DocumentPtr aDoc = document();
353 // Remove extra sub-nodes
356 while (aId < myChildren.size()) {
357 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
358 aIndex = aDoc->index(aNode->object(), true);
359 if ((aIndex == -1) || (aId != aIndex)) {
360 myChildren.removeAll(aNode);
367 std::string aGroup = groupName();
368 int aSize = aDoc->size(aGroup, true);
369 for (int i = 0; i < aSize; i++) {
370 ObjectPtr aObj = aDoc->object(aGroup, i, true);
371 if (i < myChildren.size()) {
372 if (myChildren.at(i)->object() != aObj) {
373 ModuleBase_ITreeNode* aNode = createNode(aObj);
374 myChildren.insert(i, aNode);
377 ModuleBase_ITreeNode* aNode = createNode(aObj);
378 myChildren.append(aNode);
382 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
387 std::string PartSet_FolderNode::groupName() const
390 case ParametersFolder:
391 return ModelAPI_ResultParameter::group();
392 case ConstructionFolder:
393 return ModelAPI_ResultConstruction::group();
395 return ModelAPI_ResultPart::group();
397 return ModelAPI_ResultBody::group();
399 return ModelAPI_ResultField::group();
401 return ModelAPI_ResultGroup::group();
406 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
408 QTreeNodesList aResult;
409 std::string aName = groupName();
410 DocumentPtr aDoc = document();
412 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
413 foreach(ObjectPtr aObj, theObjects) {
414 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
415 aIdx = aDoc->index(aObj, true);
417 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
419 ModuleBase_ITreeNode* aNode = createNode(aObj);
420 aNewNodes[aIdx] = aNode;
421 aResult.append(aNode);
426 // Add nodes in correct order
428 for (i = 0; i < myChildren.size(); i++) {
429 if (aNewNodes.contains(i)) {
430 myChildren.insert(i, aNewNodes[i]);
434 while (aNewNodes.size()) {
435 i = myChildren.size();
436 myChildren.append(aNewNodes[i]);
439 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
440 aResult.append(aNode->objectCreated(theObjects));
445 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
446 const QString& theGroup)
448 DocumentPtr aDoc = document();
449 QTreeNodesList aResult;
450 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
451 QTreeNodesList aDelList;
454 bool aRemoved = false;
455 while (aId < myChildren.size()) {
456 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
457 aIndex = aDoc->index(aNode->object(), true);
458 if ((aIndex == -1) || (aId != aIndex)) {
459 myChildren.removeAll(aNode);
466 aResult.append(this);
468 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
469 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
475 //////////////////////////////////////////////////////////////////////////////////
476 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
478 QTreeNodesList aResult;
479 // Process all folders
480 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
481 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
482 aResult.append(aNode->objectCreated(theObjects));
485 // Process the root sub-objects
486 DocumentPtr aDoc = document();
488 int aNb = numberOfFolders();
489 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
490 foreach(ObjectPtr aObj, theObjects) {
491 if (aDoc == aObj->document()) {
492 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
493 (aObj->groupName() == ModelAPI_Folder::group())){
494 ModuleBase_ITreeNode* aNode = createNode(aObj);
495 aIdx = aDoc->index(aObj, true);
498 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
500 aNewNodes[aIdx] = aNode;
501 aResult.append(aNode);
507 // To add in correct order
509 for (i = 0; i < myChildren.size(); i++) {
510 if (aNewNodes.contains(i)) {
511 myChildren.insert(i, aNewNodes[i]);
515 while (aNewNodes.size()) {
516 i = myChildren.size();
517 myChildren.append(aNewNodes[i]);
521 // Update sub-folders
522 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
523 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
524 (aNode->type() == PartSet_PartRootNode::typeId()))
525 aResult.append(aNode->objectCreated(theObjects));
530 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
531 const QString& theGroup)
533 QTreeNodesList aResult;
535 // Process sub-folders
536 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
537 if (aNode->childrenCount() > 0) { // aFolder node
538 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
539 if (aList.size() > 0)
540 aResult.append(aList);
545 DocumentPtr aDoc = document();
546 int aNb = numberOfFolders();
547 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
548 (theGroup.toStdString() == ModelAPI_Folder::group()));
549 if ((theDoc == aDoc) && isGroup) {
552 bool aRemoved = false;
553 while (aId < myChildren.size()) {
554 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
555 if (aNode->object().get()) {
556 aIndex = aDoc->index(aNode->object(), true);
557 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
558 myChildren.removeAll(aNode);
567 aResult.append(this);
572 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
575 ModuleBase_ITreeNode* aResult = 0;
576 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
577 aResult = aNode->findParent(theDoc, theGroup);
582 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
583 (theGroup.toStdString() == ModelAPI_Folder::group()));
584 if ((theDoc == document()) && isGroup)
590 //////////////////////////////////////////////////////////////////////////////////
591 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
593 SessionPtr aSession = ModelAPI_Session::get();
594 DocumentPtr aDoc = aSession->moduleDocument();
596 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
597 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
598 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
600 myChildren.append(myParamsFolder);
601 myChildren.append(myConstrFolder);
602 myChildren.append(myPartsFolder);
608 void PartSet_RootNode::update()
610 myParamsFolder->update();
611 myConstrFolder->update();
612 myPartsFolder->update();
614 // Update features content
615 DocumentPtr aDoc = document();
616 int aNb = numberOfFolders();
618 // Remove extra sub-nodes
621 while (aId < myChildren.size()) {
622 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
623 if (aNode->object().get()) {
624 aIndex = aDoc->index(aNode->object(), true);
625 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
626 myChildren.removeAll(aNode);
635 std::string aGroup = ModelAPI_Feature::group();
636 int aSize = aDoc->size(aGroup, true);
638 for (int i = 0; i < aSize; i++) {
639 ObjectPtr aObj = aDoc->object(aGroup, i, true);
640 aId = i + aNb; // Take into account existing folders
641 if (aId < myChildren.size()) {
642 if (myChildren.at(aId)->object() != aObj) {
643 ModuleBase_ITreeNode* aNode = createNode(aObj);
644 myChildren.insert(aId, aNode);
647 ModuleBase_ITreeNode* aNode = createNode(aObj);
648 myChildren.append(aNode);
651 // Update sub-folders
652 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
653 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
654 (aNode->type() == PartSet_PartRootNode::typeId()))
659 DocumentPtr PartSet_RootNode::document() const
661 return ModelAPI_Session::get()->moduleDocument();
664 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
666 if (theObj->groupName() == ModelAPI_Folder::group())
667 return new PartSet_ObjectFolderNode(theObj, this);
669 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
670 if (aFeature->getKind() == PartSetPlugin_Part::ID())
671 return new PartSet_PartRootNode(theObj, this);
673 return new PartSet_ObjectNode(theObj, this);
676 //////////////////////////////////////////////////////////////////////////////////
677 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
678 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
680 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
681 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
682 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
683 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
684 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
686 myChildren.append(myParamsFolder);
687 myChildren.append(myConstrFolder);
688 myChildren.append(myResultsFolder);
693 void PartSet_PartRootNode::deleteChildren()
695 if (!myFieldsFolder->childrenCount()) {
696 delete myFieldsFolder;
698 if (!myGroupsFolder->childrenCount()) {
699 delete myGroupsFolder;
701 PartSet_FeatureFolderNode::deleteChildren();
705 void PartSet_PartRootNode::update()
707 DocumentPtr aDoc = document();
711 myParamsFolder->update();
712 myConstrFolder->update();
713 myResultsFolder->update();
714 myFieldsFolder->update();
715 myGroupsFolder->update();
717 bool aHasFields = myFieldsFolder->childrenCount() > 0;
718 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
719 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
720 myChildren.insert(3, myFieldsFolder);
722 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
723 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
726 // Update features content
727 int aRows = numberOfFolders();
729 // Remove extra sub-nodes
732 while (aId < myChildren.size()) {
733 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
734 if (aNode->object().get()) {
735 aIndex = aDoc->index(aNode->object(), true);
736 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
737 myChildren.removeAll(aNode);
745 std::string aGroup = ModelAPI_Feature::group();
746 int aSize = aDoc->size(aGroup, true);
748 for (int i = 0; i < aSize; i++) {
749 ObjectPtr aObj = aDoc->object(aGroup, i, true);
750 aId = i + aRows; // Take into account existing folders
751 if (aId < myChildren.size()) {
752 if (myChildren.at(aId)->object() != aObj) {
753 ModuleBase_ITreeNode* aNode = createNode(aObj);
754 myChildren.insert(aId, aNode);
757 ModuleBase_ITreeNode* aNode = createNode(aObj);
758 myChildren.append(aNode);
761 // Update sub-folders
762 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
763 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
768 DocumentPtr PartSet_PartRootNode::document() const
770 ResultPartPtr aPartRes = getPartResult(myObject);
772 return aPartRes->partDoc();
773 return DocumentPtr();
776 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
781 case Qt::DisplayRole:
782 return QString(myObject->data()->name().c_str());
783 case Qt::DecorationRole:
784 return ModuleBase_IconFactory::get()->getIcon(myObject);
787 if (theRole == Qt::DecorationRole)
788 if (isCurrentFeature(myObject))
789 return QIcon(":pictures/arrow.png");
791 return PartSet_TreeNode::data(theColumn, theRole);
794 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
796 SessionPtr aSession = ModelAPI_Session::get();
797 DocumentPtr aActiveDoc = aSession->activeDocument();
798 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
803 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
805 if (theObj->groupName() == ModelAPI_Folder::group())
806 return new PartSet_ObjectFolderNode(theObj, this);
807 return new PartSet_ObjectNode(theObj, this);
810 int PartSet_PartRootNode::numberOfFolders() const
813 if (myFieldsFolder->childrenCount() > 0)
815 if (myGroupsFolder->childrenCount() > 0)
820 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
822 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
823 if (!myFieldsFolder->childrenCount()) {
824 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
826 myChildren.insert(3, myFieldsFolder);
827 aResult.append(myFieldsFolder);
828 aResult.append(aList);
831 if (!myGroupsFolder->childrenCount()) {
832 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
834 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
835 aResult.append(myGroupsFolder);
836 aResult.append(aList);
842 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
843 const QString& theGroup)
845 QTreeNodesList aResult;
846 if (myFieldsFolder->childrenCount()) {
847 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
849 aResult.append(aList);
850 if (!myFieldsFolder->childrenCount())
851 myChildren.removeAll(myFieldsFolder);
854 if (myGroupsFolder->childrenCount()) {
855 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
857 aResult.append(aList);
858 if (!myGroupsFolder->childrenCount())
859 myChildren.removeAll(myGroupsFolder);
862 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
866 //////////////////////////////////////////////////////////////////////////////////
867 void PartSet_ObjectFolderNode::update()
870 getFirstAndLastIndex(aFirst, aLast);
871 if ((aFirst == -1) || (aLast == -1)) {
876 int aNbItems = aLast - aFirst + 1;
882 DocumentPtr aDoc = myObject->document();
883 // Delete obsolete nodes
885 while (aId < myChildren.size()) {
886 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
887 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
888 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
889 myChildren.removeAll(aNode);
898 ModuleBase_ITreeNode* aNode;
899 for (int i = 0; i < aNbItems; i++) {
900 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
901 if (i < myChildren.size()) {
902 if (aObj != myChildren.at(i)->object()) {
903 aNode = new PartSet_ObjectNode(aObj, this);
904 myChildren.insert(i, aNode);
907 aNode = new PartSet_ObjectNode(aObj, this);
908 myChildren.append(aNode);
913 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
915 QTreeNodesList aResult;
917 getFirstAndLastIndex(aFirst, aLast);
918 if ((aFirst == -1) || (aLast == -1)) {
921 int aNbItems = aLast - aFirst + 1;
925 DocumentPtr aDoc = myObject->document();
927 ModuleBase_ITreeNode* aNode;
928 for (int i = 0; i < aNbItems; i++) {
929 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
930 if (i < myChildren.size()) {
931 if (aObj != myChildren.at(i)->object()) {
932 aNode = new PartSet_ObjectNode(aObj, this);
933 myChildren.insert(i, aNode);
934 aResult.append(aNode);
937 aNode = new PartSet_ObjectNode(aObj, this);
938 myChildren.append(aNode);
939 aResult.append(aNode);
945 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
946 const QString& theGroup)
948 QTreeNodesList aResult;
950 getFirstAndLastIndex(aFirst, aLast);
951 if ((aFirst == -1) || (aLast == -1)) {
954 int aNbItems = aLast - aFirst + 1;
958 DocumentPtr aDoc = myObject->document();
959 // Delete obsolete nodes
960 bool aRemoved = false;
962 while (aId < myChildren.size()) {
963 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
964 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
965 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
966 myChildren.removeAll(aNode);
975 aResult.append(this);
980 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
982 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
983 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
985 return ModelAPI_Feature::feature(aFeatAttr->value());
989 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
991 DocumentPtr aDoc = myObject->document();
992 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
994 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
995 if (!aFirstFeatureInFolder.get()) {
999 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1000 if (!aLastFeatureInFolder.get()) {
1005 theFirst = aDoc->index(aFirstFeatureInFolder);
1006 theLast = aDoc->index(aLastFeatureInFolder);
1010 //////////////////////////////////////////////////////////////////////////////////
1011 //PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
1012 // ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
1017 //void PartSet_CompsolidNode::update()
1019 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1020 // int aNb = aCompRes->numberOfSubs(true);
1021 // ModuleBase_ITreeNode* aNode;
1022 // ResultBodyPtr aBody;
1024 // for (i = 0; i < aNb; i++) {
1025 // aBody = aCompRes->subResult(i, true);
1026 // if (i < myChildren.size()) {
1027 // aNode = myChildren.at(i);
1028 // if (aNode->object() != aBody) {
1029 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1032 // aNode = new PartSet_ObjectNode(aBody, this);
1033 // myChildren.append(aNode);
1036 // // Delete extra objects
1037 // while (myChildren.size() > aNb) {
1038 // aNode = myChildren.takeLast();
1043 //QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
1045 // QTreeNodesList aResult;
1047 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1048 // int aNb = aCompRes->numberOfSubs(true);
1049 // ModuleBase_ITreeNode* aNode;
1050 // ResultBodyPtr aBody;
1052 // for (i = 0; i < aNb; i++) {
1053 // aBody = aCompRes->subResult(i, true);
1054 // if (i < myChildren.size()) {
1055 // aNode = myChildren.at(i);
1056 // if (aNode->object() != aBody) {
1057 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1058 // aResult.append(aNode);
1061 // aNode = new PartSet_ObjectNode(aBody, this);
1062 // myChildren.append(aNode);
1063 // aResult.append(aNode);
1069 //QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
1071 // QTreeNodesList aResult;
1072 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1073 // int aNb = aCompRes->numberOfSubs(true);
1074 // ModuleBase_ITreeNode* aNode;
1075 // // Delete extra objects
1076 // bool isDeleted = false;
1077 // while (myChildren.size() > aNb) {
1078 // aNode = myChildren.takeLast();
1080 // isDeleted = true;
1083 // aResult.append(this);