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();
213 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
215 QTreeNodesList aResult;
217 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
218 if (aCompRes.get()) {
219 int aNb = aCompRes->numberOfSubs(true);
220 ModuleBase_ITreeNode* aNode;
223 for (i = 0; i < aNb; i++) {
224 aBody = aCompRes->subResult(i, true);
225 if (i < myChildren.size()) {
226 aNode = myChildren.at(i);
227 if (aNode->object() != aBody) {
228 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
229 aResult.append(aNode);
232 aNode = new PartSet_ObjectNode(aBody, this);
233 myChildren.append(aNode);
234 aResult.append(aNode);
241 QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
243 QTreeNodesList aResult;
244 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
245 if (aCompRes.get()) {
246 int aNb = aCompRes->numberOfSubs(true);
247 ModuleBase_ITreeNode* aNode;
248 // Delete extra objects
249 bool isDeleted = false;
250 while (myChildren.size() > aNb) {
251 aNode = myChildren.takeLast();
256 aResult.append(this);
260 //////////////////////////////////////////////////////////////////////////////////
261 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
263 : PartSet_TreeNode(theParent), myType(theType)
267 QString PartSet_FolderNode::name() const
270 case ParametersFolder:
271 return QObject::tr("Parameters");
272 case ConstructionFolder:
273 return QObject::tr("Constructions");
275 return QObject::tr("Parts");
277 return QObject::tr("Results");
279 return QObject::tr("Fields");
281 return QObject::tr("Groups");
287 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
289 static QIcon aParamsIco(":pictures/params_folder.png");
290 static QIcon aConstrIco(":pictures/constr_folder.png");
292 if (theColumn == 1) {
294 case Qt::DisplayRole:
295 return name() + QString(" (%1)").arg(childrenCount());
296 case Qt::DecorationRole:
298 case ParametersFolder:
300 case ConstructionFolder:
313 return PartSet_TreeNode::data(theColumn, theRole);
316 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
318 SessionPtr aSession = ModelAPI_Session::get();
319 DocumentPtr aActiveDoc = aSession->activeDocument();
320 if (theColumn == 1) {
321 if (document() == aActiveDoc)
327 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
329 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
330 //if (aCompRes.get())
331 // return new PartSet_CompsolidNode(theObj, this);
332 return new PartSet_ObjectNode(theObj, this);
335 void PartSet_FolderNode::update()
337 DocumentPtr aDoc = document();
341 // Remove extra sub-nodes
344 while (aId < myChildren.size()) {
345 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
346 aIndex = aDoc->index(aNode->object(), true);
347 if ((aIndex == -1) || (aId != aIndex)) {
348 myChildren.removeAll(aNode);
355 std::string aGroup = groupName();
356 int aSize = aDoc->size(aGroup, true);
357 for (int i = 0; i < aSize; i++) {
358 ObjectPtr aObj = aDoc->object(aGroup, i, true);
359 if (i < myChildren.size()) {
360 if (myChildren.at(i)->object() != aObj) {
361 ModuleBase_ITreeNode* aNode = createNode(aObj);
362 myChildren.insert(i, aNode);
365 ModuleBase_ITreeNode* aNode = createNode(aObj);
366 myChildren.append(aNode);
370 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
375 std::string PartSet_FolderNode::groupName() const
378 case ParametersFolder:
379 return ModelAPI_ResultParameter::group();
380 case ConstructionFolder:
381 return ModelAPI_ResultConstruction::group();
383 return ModelAPI_ResultPart::group();
385 return ModelAPI_ResultBody::group();
387 return ModelAPI_ResultField::group();
389 return ModelAPI_ResultGroup::group();
394 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
396 QTreeNodesList aResult;
397 std::string aName = groupName();
398 DocumentPtr aDoc = document();
400 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
401 foreach(ObjectPtr aObj, theObjects) {
402 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
403 aIdx = aDoc->index(aObj, true);
405 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
407 ModuleBase_ITreeNode* aNode = createNode(aObj);
408 aNewNodes[aIdx] = aNode;
409 aResult.append(aNode);
414 // Add nodes in correct order
416 for (i = 0; i < myChildren.size(); i++) {
417 if (aNewNodes.contains(i)) {
418 myChildren.insert(i, aNewNodes[i]);
422 while (aNewNodes.size()) {
423 i = myChildren.size();
424 myChildren.append(aNewNodes[i]);
427 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
428 aResult.append(aNode->objectCreated(theObjects));
433 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
434 const QString& theGroup)
436 DocumentPtr aDoc = document();
437 QTreeNodesList aResult;
438 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
439 QTreeNodesList aDelList;
442 bool aRemoved = false;
443 while (aId < myChildren.size()) {
444 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
445 aIndex = aDoc->index(aNode->object(), true);
446 if ((aIndex == -1) || (aId != aIndex)) {
447 myChildren.removeAll(aNode);
454 aResult.append(this);
456 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
457 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
463 //////////////////////////////////////////////////////////////////////////////////
464 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
466 QTreeNodesList aResult;
467 // Process all folders
468 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
469 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
470 aResult.append(aNode->objectCreated(theObjects));
473 // Process the root sub-objects
474 DocumentPtr aDoc = document();
476 int aNb = numberOfFolders();
477 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
478 foreach(ObjectPtr aObj, theObjects) {
479 if (aDoc == aObj->document()) {
480 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
481 (aObj->groupName() == ModelAPI_Folder::group())){
482 ModuleBase_ITreeNode* aNode = createNode(aObj);
483 aIdx = aDoc->index(aObj, true);
486 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
488 aNewNodes[aIdx] = aNode;
489 aResult.append(aNode);
495 // To add in correct order
497 for (i = 0; i < myChildren.size(); i++) {
498 if (aNewNodes.contains(i)) {
499 myChildren.insert(i, aNewNodes[i]);
503 while (aNewNodes.size()) {
504 i = myChildren.size();
505 myChildren.append(aNewNodes[i]);
509 // Update sub-folders
510 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
511 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
512 (aNode->type() == PartSet_PartRootNode::typeId()))
513 aResult.append(aNode->objectCreated(theObjects));
518 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
519 const QString& theGroup)
521 QTreeNodesList aResult;
523 // Process sub-folders
524 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
525 if (aNode->childrenCount() > 0) { // aFolder node
526 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
527 if (aList.size() > 0)
528 aResult.append(aList);
533 DocumentPtr aDoc = document();
534 int aNb = numberOfFolders();
535 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
536 (theGroup.toStdString() == ModelAPI_Folder::group()));
537 if ((theDoc == aDoc) && isGroup) {
540 bool aRemoved = false;
541 while (aId < myChildren.size()) {
542 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
543 if (aNode->object().get()) {
544 aIndex = aDoc->index(aNode->object(), true);
545 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
546 myChildren.removeAll(aNode);
555 aResult.append(this);
560 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
563 ModuleBase_ITreeNode* aResult = 0;
564 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
565 aResult = aNode->findParent(theDoc, theGroup);
570 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
571 (theGroup.toStdString() == ModelAPI_Folder::group()));
572 if ((theDoc == document()) && isGroup)
578 //////////////////////////////////////////////////////////////////////////////////
579 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
581 SessionPtr aSession = ModelAPI_Session::get();
582 DocumentPtr aDoc = aSession->moduleDocument();
584 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
585 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
586 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
588 myChildren.append(myParamsFolder);
589 myChildren.append(myConstrFolder);
590 myChildren.append(myPartsFolder);
596 void PartSet_RootNode::update()
598 myParamsFolder->update();
599 myConstrFolder->update();
600 myPartsFolder->update();
602 // Update features content
603 DocumentPtr aDoc = document();
604 int aNb = numberOfFolders();
606 // Remove extra sub-nodes
609 while (aId < myChildren.size()) {
610 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
611 if (aNode->object().get()) {
612 aIndex = aDoc->index(aNode->object(), true);
613 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
614 myChildren.removeAll(aNode);
623 std::string aGroup = ModelAPI_Feature::group();
624 int aSize = aDoc->size(aGroup, true);
626 for (int i = 0; i < aSize; i++) {
627 ObjectPtr aObj = aDoc->object(aGroup, i, true);
628 aId = i + aNb; // Take into account existing folders
629 if (aId < myChildren.size()) {
630 if (myChildren.at(aId)->object() != aObj) {
631 ModuleBase_ITreeNode* aNode = createNode(aObj);
632 myChildren.insert(aId, aNode);
635 ModuleBase_ITreeNode* aNode = createNode(aObj);
636 myChildren.append(aNode);
639 // Update sub-folders
640 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
641 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
642 (aNode->type() == PartSet_PartRootNode::typeId()))
647 DocumentPtr PartSet_RootNode::document() const
649 return ModelAPI_Session::get()->moduleDocument();
652 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
654 if (theObj->groupName() == ModelAPI_Folder::group())
655 return new PartSet_ObjectFolderNode(theObj, this);
657 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
658 if (aFeature->getKind() == PartSetPlugin_Part::ID())
659 return new PartSet_PartRootNode(theObj, this);
661 return new PartSet_ObjectNode(theObj, this);
664 //////////////////////////////////////////////////////////////////////////////////
665 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
666 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
668 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
669 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
670 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
671 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
672 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
674 myChildren.append(myParamsFolder);
675 myChildren.append(myConstrFolder);
676 myChildren.append(myResultsFolder);
681 void PartSet_PartRootNode::deleteChildren()
683 if (!myFieldsFolder->childrenCount()) {
684 delete myFieldsFolder;
686 if (!myGroupsFolder->childrenCount()) {
687 delete myGroupsFolder;
689 PartSet_FeatureFolderNode::deleteChildren();
693 void PartSet_PartRootNode::update()
695 DocumentPtr aDoc = document();
699 myParamsFolder->update();
700 myConstrFolder->update();
701 myResultsFolder->update();
702 myFieldsFolder->update();
703 myGroupsFolder->update();
705 bool aHasFields = myFieldsFolder->childrenCount() > 0;
706 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
707 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
708 myChildren.insert(3, myFieldsFolder);
710 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
711 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
714 // Update features content
715 int aRows = numberOfFolders();
717 // Remove extra sub-nodes
720 while (aId < myChildren.size()) {
721 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
722 if (aNode->object().get()) {
723 aIndex = aDoc->index(aNode->object(), true);
724 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
725 myChildren.removeAll(aNode);
733 std::string aGroup = ModelAPI_Feature::group();
734 int aSize = aDoc->size(aGroup, true);
736 for (int i = 0; i < aSize; i++) {
737 ObjectPtr aObj = aDoc->object(aGroup, i, true);
738 aId = i + aRows; // Take into account existing folders
739 if (aId < myChildren.size()) {
740 if (myChildren.at(aId)->object() != aObj) {
741 ModuleBase_ITreeNode* aNode = createNode(aObj);
742 myChildren.insert(aId, aNode);
745 ModuleBase_ITreeNode* aNode = createNode(aObj);
746 myChildren.append(aNode);
749 // Update sub-folders
750 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
751 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
756 DocumentPtr PartSet_PartRootNode::document() const
758 ResultPartPtr aPartRes = getPartResult(myObject);
760 return aPartRes->partDoc();
761 return DocumentPtr();
764 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
769 case Qt::DisplayRole:
770 return QString(myObject->data()->name().c_str());
771 case Qt::DecorationRole:
772 return ModuleBase_IconFactory::get()->getIcon(myObject);
775 if (theRole == Qt::DecorationRole)
776 if (isCurrentFeature(myObject))
777 return QIcon(":pictures/arrow.png");
779 return PartSet_TreeNode::data(theColumn, theRole);
782 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
784 SessionPtr aSession = ModelAPI_Session::get();
785 DocumentPtr aActiveDoc = aSession->activeDocument();
786 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
791 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
793 if (theObj->groupName() == ModelAPI_Folder::group())
794 return new PartSet_ObjectFolderNode(theObj, this);
795 return new PartSet_ObjectNode(theObj, this);
798 int PartSet_PartRootNode::numberOfFolders() const
801 if (myFieldsFolder->childrenCount() > 0)
803 if (myGroupsFolder->childrenCount() > 0)
808 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
810 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
811 if (!myFieldsFolder->childrenCount()) {
812 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
814 myChildren.insert(3, myFieldsFolder);
815 aResult.append(myFieldsFolder);
816 aResult.append(aList);
819 if (!myGroupsFolder->childrenCount()) {
820 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
822 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
823 aResult.append(myGroupsFolder);
824 aResult.append(aList);
830 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
831 const QString& theGroup)
833 QTreeNodesList aResult;
834 if (myFieldsFolder->childrenCount()) {
835 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
837 aResult.append(aList);
838 if (!myFieldsFolder->childrenCount())
839 myChildren.removeAll(myFieldsFolder);
842 if (myGroupsFolder->childrenCount()) {
843 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
845 aResult.append(aList);
846 if (!myGroupsFolder->childrenCount())
847 myChildren.removeAll(myGroupsFolder);
850 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
854 //////////////////////////////////////////////////////////////////////////////////
855 void PartSet_ObjectFolderNode::update()
858 getFirstAndLastIndex(aFirst, aLast);
859 if ((aFirst == -1) || (aLast == -1)) {
864 int aNbItems = aLast - aFirst + 1;
870 DocumentPtr aDoc = myObject->document();
871 // Delete obsolete nodes
873 while (aId < myChildren.size()) {
874 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
875 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
876 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
877 myChildren.removeAll(aNode);
886 ModuleBase_ITreeNode* aNode;
887 for (int i = 0; i < aNbItems; i++) {
888 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
889 if (i < myChildren.size()) {
890 if (aObj != myChildren.at(i)->object()) {
891 aNode = new PartSet_ObjectNode(aObj, this);
892 myChildren.insert(i, aNode);
895 aNode = new PartSet_ObjectNode(aObj, this);
896 myChildren.append(aNode);
901 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
903 QTreeNodesList aResult;
905 getFirstAndLastIndex(aFirst, aLast);
906 if ((aFirst == -1) || (aLast == -1)) {
909 int aNbItems = aLast - aFirst + 1;
913 DocumentPtr aDoc = myObject->document();
915 ModuleBase_ITreeNode* aNode;
916 for (int i = 0; i < aNbItems; i++) {
917 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
918 if (i < myChildren.size()) {
919 if (aObj != myChildren.at(i)->object()) {
920 aNode = new PartSet_ObjectNode(aObj, this);
921 myChildren.insert(i, aNode);
922 aResult.append(aNode);
925 aNode = new PartSet_ObjectNode(aObj, this);
926 myChildren.append(aNode);
927 aResult.append(aNode);
933 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
934 const QString& theGroup)
936 QTreeNodesList aResult;
938 getFirstAndLastIndex(aFirst, aLast);
939 if ((aFirst == -1) || (aLast == -1)) {
942 int aNbItems = aLast - aFirst + 1;
946 DocumentPtr aDoc = myObject->document();
947 // Delete obsolete nodes
948 bool aRemoved = false;
950 while (aId < myChildren.size()) {
951 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
952 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
953 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
954 myChildren.removeAll(aNode);
963 aResult.append(this);
968 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
970 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
971 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
973 return ModelAPI_Feature::feature(aFeatAttr->value());
977 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
979 DocumentPtr aDoc = myObject->document();
980 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
982 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
983 if (!aFirstFeatureInFolder.get()) {
987 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
988 if (!aLastFeatureInFolder.get()) {
993 theFirst = aDoc->index(aFirstFeatureInFolder);
994 theLast = aDoc->index(aLastFeatureInFolder);
998 //////////////////////////////////////////////////////////////////////////////////
999 //PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
1000 // ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
1005 //void PartSet_CompsolidNode::update()
1007 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1008 // int aNb = aCompRes->numberOfSubs(true);
1009 // ModuleBase_ITreeNode* aNode;
1010 // ResultBodyPtr aBody;
1012 // for (i = 0; i < aNb; i++) {
1013 // aBody = aCompRes->subResult(i, true);
1014 // if (i < myChildren.size()) {
1015 // aNode = myChildren.at(i);
1016 // if (aNode->object() != aBody) {
1017 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1020 // aNode = new PartSet_ObjectNode(aBody, this);
1021 // myChildren.append(aNode);
1024 // // Delete extra objects
1025 // while (myChildren.size() > aNb) {
1026 // aNode = myChildren.takeLast();
1031 //QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
1033 // QTreeNodesList aResult;
1035 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1036 // int aNb = aCompRes->numberOfSubs(true);
1037 // ModuleBase_ITreeNode* aNode;
1038 // ResultBodyPtr aBody;
1040 // for (i = 0; i < aNb; i++) {
1041 // aBody = aCompRes->subResult(i, true);
1042 // if (i < myChildren.size()) {
1043 // aNode = myChildren.at(i);
1044 // if (aNode->object() != aBody) {
1045 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1046 // aResult.append(aNode);
1049 // aNode = new PartSet_ObjectNode(aBody, this);
1050 // myChildren.append(aNode);
1051 // aResult.append(aNode);
1057 //QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
1059 // QTreeNodesList aResult;
1060 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1061 // int aNb = aCompRes->numberOfSubs(true);
1062 // ModuleBase_ITreeNode* aNode;
1063 // // Delete extra objects
1064 // bool isDeleted = false;
1065 // while (myChildren.size() > aNb) {
1066 // aNode = myChildren.takeLast();
1068 // isDeleted = true;
1071 // aResult.append(this);