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 std::list<ResultPtr> aResultsList;
165 ModelAPI_Tools::allSubs(aCompRes, aResultsList);
167 std::list<ResultPtr>::const_iterator aIt;
168 //for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
169 for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
170 ResultPtr aSubRes = (*aIt); // aCompRes->subResult(i, true);
171 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
172 if (aState == NoneState)
174 else if (aState != aS) {
175 aState = SemiVisible;
181 if (aWork->isVisible(aResObj))
190 void PartSet_ObjectNode::update()
192 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
193 if (aCompRes.get()) {
194 int aNb = aCompRes->numberOfSubs(true);
195 ModuleBase_ITreeNode* aNode;
198 for (i = 0; i < aNb; i++) {
199 aBody = aCompRes->subResult(i, true);
200 if (i < myChildren.size()) {
201 aNode = myChildren.at(i);
202 if (aNode->object() != aBody) {
203 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
206 aNode = new PartSet_ObjectNode(aBody, this);
207 myChildren.append(aNode);
210 // Delete extra objects
211 while (myChildren.size() > aNb) {
212 aNode = myChildren.takeLast();
215 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
221 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
223 QTreeNodesList aResult;
225 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
226 if (aCompRes.get()) {
227 int aNb = aCompRes->numberOfSubs(true);
228 ModuleBase_ITreeNode* aNode;
231 for (i = 0; i < aNb; i++) {
232 aBody = aCompRes->subResult(i, true);
233 if (i < myChildren.size()) {
234 aNode = myChildren.at(i);
235 if (aNode->object() != aBody) {
236 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
237 aResult.append(aNode);
240 aNode = new PartSet_ObjectNode(aBody, this);
241 myChildren.append(aNode);
242 aResult.append(aNode);
245 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
246 aResult.append(aNode->objectCreated(theObjects));
252 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
253 const DocumentPtr& theDoc, const QString& theGroup)
255 QTreeNodesList aResult;
256 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
257 if (aCompRes.get()) {
258 int aNb = aCompRes->numberOfSubs(true);
259 ModuleBase_ITreeNode* aNode;
260 // Delete extra objects
261 bool isDeleted = false;
262 while (myChildren.size() > aNb) {
263 aNode = myChildren.takeLast();
268 aResult.append(this);
270 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
271 ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true));
272 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
278 //////////////////////////////////////////////////////////////////////////////////
279 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
281 : PartSet_TreeNode(theParent), myType(theType)
285 QString PartSet_FolderNode::name() const
288 case ParametersFolder:
289 return QObject::tr("Parameters");
290 case ConstructionFolder:
291 return QObject::tr("Constructions");
293 return QObject::tr("Parts");
295 return QObject::tr("Results");
297 return QObject::tr("Fields");
299 return QObject::tr("Groups");
305 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
307 static QIcon aParamsIco(":pictures/params_folder.png");
308 static QIcon aConstrIco(":pictures/constr_folder.png");
310 if (theColumn == 1) {
312 case Qt::DisplayRole:
313 return name() + QString(" (%1)").arg(childrenCount());
314 case Qt::DecorationRole:
316 case ParametersFolder:
318 case ConstructionFolder:
331 return PartSet_TreeNode::data(theColumn, theRole);
334 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
336 SessionPtr aSession = ModelAPI_Session::get();
337 DocumentPtr aActiveDoc = aSession->activeDocument();
338 if (theColumn == 1) {
339 if (document() == aActiveDoc)
345 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
347 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
348 //if (aCompRes.get())
349 // return new PartSet_CompsolidNode(theObj, this);
350 return new PartSet_ObjectNode(theObj, this);
353 void PartSet_FolderNode::update()
355 DocumentPtr aDoc = document();
359 // Remove extra sub-nodes
362 while (aId < myChildren.size()) {
363 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
364 aIndex = aDoc->index(aNode->object(), true);
365 if ((aIndex == -1) || (aId != aIndex)) {
366 myChildren.removeAll(aNode);
373 std::string aGroup = groupName();
374 int aSize = aDoc->size(aGroup, true);
375 for (int i = 0; i < aSize; i++) {
376 ObjectPtr aObj = aDoc->object(aGroup, i, true);
377 if (i < myChildren.size()) {
378 if (myChildren.at(i)->object() != aObj) {
379 ModuleBase_ITreeNode* aNode = createNode(aObj);
380 myChildren.insert(i, aNode);
383 ModuleBase_ITreeNode* aNode = createNode(aObj);
384 myChildren.append(aNode);
388 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
393 std::string PartSet_FolderNode::groupName() const
396 case ParametersFolder:
397 return ModelAPI_ResultParameter::group();
398 case ConstructionFolder:
399 return ModelAPI_ResultConstruction::group();
401 return ModelAPI_ResultPart::group();
403 return ModelAPI_ResultBody::group();
405 return ModelAPI_ResultField::group();
407 return ModelAPI_ResultGroup::group();
412 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
414 QTreeNodesList aResult;
415 std::string aName = groupName();
416 DocumentPtr aDoc = document();
418 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
419 foreach(ObjectPtr aObj, theObjects) {
420 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
421 aIdx = aDoc->index(aObj, true);
423 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
425 ModuleBase_ITreeNode* aNode = createNode(aObj);
426 aNewNodes[aIdx] = aNode;
427 aResult.append(aNode);
432 // Add nodes in correct order
434 for (i = 0; i < myChildren.size(); i++) {
435 if (aNewNodes.contains(i)) {
436 myChildren.insert(i, aNewNodes[i]);
440 while (aNewNodes.size()) {
441 i = myChildren.size();
442 myChildren.append(aNewNodes[i]);
445 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
446 aResult.append(aNode->objectCreated(theObjects));
451 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
452 const QString& theGroup)
454 DocumentPtr aDoc = document();
455 QTreeNodesList aResult;
456 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
457 QTreeNodesList aDelList;
460 bool aRemoved = false;
461 while (aId < myChildren.size()) {
462 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
463 aIndex = aDoc->index(aNode->object(), true);
464 if ((aIndex == -1) || (aId != aIndex)) {
465 myChildren.removeAll(aNode);
472 aResult.append(this);
474 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
475 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
481 //////////////////////////////////////////////////////////////////////////////////
482 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
484 QTreeNodesList aResult;
485 // Process all folders
486 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
487 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
488 aResult.append(aNode->objectCreated(theObjects));
491 // Process the root sub-objects
492 DocumentPtr aDoc = document();
494 int aNb = numberOfFolders();
495 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
496 foreach(ObjectPtr aObj, theObjects) {
497 if (aDoc == aObj->document()) {
498 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
499 (aObj->groupName() == ModelAPI_Folder::group())){
500 ModuleBase_ITreeNode* aNode = createNode(aObj);
501 aIdx = aDoc->index(aObj, true);
504 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
506 aNewNodes[aIdx] = aNode;
507 aResult.append(aNode);
513 // To add in correct order
515 for (i = 0; i < myChildren.size(); i++) {
516 if (aNewNodes.contains(i)) {
517 myChildren.insert(i, aNewNodes[i]);
521 while (aNewNodes.size()) {
522 i = myChildren.size();
523 myChildren.append(aNewNodes[i]);
527 // Update sub-folders
528 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
529 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
530 (aNode->type() == PartSet_PartRootNode::typeId()))
531 aResult.append(aNode->objectCreated(theObjects));
536 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
537 const QString& theGroup)
539 QTreeNodesList aResult;
541 // Process sub-folders
542 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
543 if (aNode->childrenCount() > 0) { // aFolder node
544 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
545 if (aList.size() > 0)
546 aResult.append(aList);
551 DocumentPtr aDoc = document();
552 int aNb = numberOfFolders();
553 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
554 (theGroup.toStdString() == ModelAPI_Folder::group()));
555 if ((theDoc == aDoc) && isGroup) {
558 bool aRemoved = false;
559 while (aId < myChildren.size()) {
560 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
561 if (aNode->object().get()) {
562 aIndex = aDoc->index(aNode->object(), true);
563 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
564 myChildren.removeAll(aNode);
573 aResult.append(this);
578 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
581 ModuleBase_ITreeNode* aResult = 0;
582 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
583 aResult = aNode->findParent(theDoc, theGroup);
588 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
589 (theGroup.toStdString() == ModelAPI_Folder::group()));
590 if ((theDoc == document()) && isGroup)
596 //////////////////////////////////////////////////////////////////////////////////
597 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
599 SessionPtr aSession = ModelAPI_Session::get();
600 DocumentPtr aDoc = aSession->moduleDocument();
602 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
603 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
604 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
606 myChildren.append(myParamsFolder);
607 myChildren.append(myConstrFolder);
608 myChildren.append(myPartsFolder);
614 void PartSet_RootNode::update()
616 myParamsFolder->update();
617 myConstrFolder->update();
618 myPartsFolder->update();
620 // Update features content
621 DocumentPtr aDoc = document();
622 int aNb = numberOfFolders();
624 // Remove extra sub-nodes
627 while (aId < myChildren.size()) {
628 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
629 if (aNode->object().get()) {
630 aIndex = aDoc->index(aNode->object(), true);
631 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
632 myChildren.removeAll(aNode);
641 std::string aGroup = ModelAPI_Feature::group();
642 int aSize = aDoc->size(aGroup, true);
644 for (int i = 0; i < aSize; i++) {
645 ObjectPtr aObj = aDoc->object(aGroup, i, true);
646 aId = i + aNb; // Take into account existing folders
647 if (aId < myChildren.size()) {
648 if (myChildren.at(aId)->object() != aObj) {
649 ModuleBase_ITreeNode* aNode = createNode(aObj);
650 myChildren.insert(aId, aNode);
653 ModuleBase_ITreeNode* aNode = createNode(aObj);
654 myChildren.append(aNode);
657 // Update sub-folders
658 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
659 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
660 (aNode->type() == PartSet_PartRootNode::typeId()))
665 DocumentPtr PartSet_RootNode::document() const
667 return ModelAPI_Session::get()->moduleDocument();
670 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
672 if (theObj->groupName() == ModelAPI_Folder::group())
673 return new PartSet_ObjectFolderNode(theObj, this);
675 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
676 if (aFeature->getKind() == PartSetPlugin_Part::ID())
677 return new PartSet_PartRootNode(theObj, this);
679 return new PartSet_ObjectNode(theObj, this);
682 //////////////////////////////////////////////////////////////////////////////////
683 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
684 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
686 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
687 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
688 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
689 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
690 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
692 myChildren.append(myParamsFolder);
693 myChildren.append(myConstrFolder);
694 myChildren.append(myResultsFolder);
699 void PartSet_PartRootNode::deleteChildren()
701 if (!myFieldsFolder->childrenCount()) {
702 delete myFieldsFolder;
704 if (!myGroupsFolder->childrenCount()) {
705 delete myGroupsFolder;
707 PartSet_FeatureFolderNode::deleteChildren();
711 void PartSet_PartRootNode::update()
713 DocumentPtr aDoc = document();
717 myParamsFolder->update();
718 myConstrFolder->update();
719 myResultsFolder->update();
720 myFieldsFolder->update();
721 myGroupsFolder->update();
723 bool aHasFields = myFieldsFolder->childrenCount() > 0;
724 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
725 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
726 myChildren.insert(3, myFieldsFolder);
728 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
729 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
732 // Update features content
733 int aRows = numberOfFolders();
735 // Remove extra sub-nodes
738 while (aId < myChildren.size()) {
739 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
740 if (aNode->object().get()) {
741 aIndex = aDoc->index(aNode->object(), true);
742 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
743 myChildren.removeAll(aNode);
751 std::string aGroup = ModelAPI_Feature::group();
752 int aSize = aDoc->size(aGroup, true);
754 for (int i = 0; i < aSize; i++) {
755 ObjectPtr aObj = aDoc->object(aGroup, i, true);
756 aId = i + aRows; // Take into account existing folders
757 if (aId < myChildren.size()) {
758 if (myChildren.at(aId)->object() != aObj) {
759 ModuleBase_ITreeNode* aNode = createNode(aObj);
760 myChildren.insert(aId, aNode);
763 ModuleBase_ITreeNode* aNode = createNode(aObj);
764 myChildren.append(aNode);
767 // Update sub-folders
768 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
769 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
774 DocumentPtr PartSet_PartRootNode::document() const
776 ResultPartPtr aPartRes = getPartResult(myObject);
778 return aPartRes->partDoc();
779 return DocumentPtr();
782 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
787 case Qt::DisplayRole:
788 return QString(myObject->data()->name().c_str());
789 case Qt::DecorationRole:
790 return ModuleBase_IconFactory::get()->getIcon(myObject);
793 if (theRole == Qt::DecorationRole)
794 if (isCurrentFeature(myObject))
795 return QIcon(":pictures/arrow.png");
797 return PartSet_TreeNode::data(theColumn, theRole);
800 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
802 SessionPtr aSession = ModelAPI_Session::get();
803 DocumentPtr aActiveDoc = aSession->activeDocument();
804 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
809 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
811 if (theObj->groupName() == ModelAPI_Folder::group())
812 return new PartSet_ObjectFolderNode(theObj, this);
813 return new PartSet_ObjectNode(theObj, this);
816 int PartSet_PartRootNode::numberOfFolders() const
819 if (myFieldsFolder->childrenCount() > 0)
821 if (myGroupsFolder->childrenCount() > 0)
826 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
828 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
829 if (!myFieldsFolder->childrenCount()) {
830 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
832 myChildren.insert(3, myFieldsFolder);
833 aResult.append(myFieldsFolder);
834 aResult.append(aList);
837 if (!myGroupsFolder->childrenCount()) {
838 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
840 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
841 aResult.append(myGroupsFolder);
842 aResult.append(aList);
848 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
849 const QString& theGroup)
851 QTreeNodesList aResult;
852 if (myFieldsFolder->childrenCount()) {
853 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
855 aResult.append(aList);
856 if (!myFieldsFolder->childrenCount())
857 myChildren.removeAll(myFieldsFolder);
860 if (myGroupsFolder->childrenCount()) {
861 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
863 aResult.append(aList);
864 if (!myGroupsFolder->childrenCount())
865 myChildren.removeAll(myGroupsFolder);
868 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
872 //////////////////////////////////////////////////////////////////////////////////
873 void PartSet_ObjectFolderNode::update()
876 getFirstAndLastIndex(aFirst, aLast);
877 if ((aFirst == -1) || (aLast == -1)) {
882 int aNbItems = aLast - aFirst + 1;
888 DocumentPtr aDoc = myObject->document();
889 // Delete obsolete nodes
891 while (aId < myChildren.size()) {
892 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
893 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
894 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
895 myChildren.removeAll(aNode);
904 ModuleBase_ITreeNode* aNode;
905 for (int i = 0; i < aNbItems; i++) {
906 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
907 if (i < myChildren.size()) {
908 if (aObj != myChildren.at(i)->object()) {
909 aNode = new PartSet_ObjectNode(aObj, this);
910 myChildren.insert(i, aNode);
913 aNode = new PartSet_ObjectNode(aObj, this);
914 myChildren.append(aNode);
919 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
921 QTreeNodesList aResult;
923 getFirstAndLastIndex(aFirst, aLast);
924 if ((aFirst == -1) || (aLast == -1)) {
927 int aNbItems = aLast - aFirst + 1;
931 DocumentPtr aDoc = myObject->document();
933 ModuleBase_ITreeNode* aNode;
934 for (int i = 0; i < aNbItems; i++) {
935 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
936 if (i < myChildren.size()) {
937 if (aObj != myChildren.at(i)->object()) {
938 aNode = new PartSet_ObjectNode(aObj, this);
939 myChildren.insert(i, aNode);
940 aResult.append(aNode);
943 aNode = new PartSet_ObjectNode(aObj, this);
944 myChildren.append(aNode);
945 aResult.append(aNode);
951 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
952 const QString& theGroup)
954 QTreeNodesList aResult;
956 getFirstAndLastIndex(aFirst, aLast);
957 if ((aFirst == -1) || (aLast == -1)) {
960 int aNbItems = aLast - aFirst + 1;
964 DocumentPtr aDoc = myObject->document();
965 // Delete obsolete nodes
966 bool aRemoved = false;
968 while (aId < myChildren.size()) {
969 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
970 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
971 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
972 myChildren.removeAll(aNode);
981 aResult.append(this);
986 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
988 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
989 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
991 return ModelAPI_Feature::feature(aFeatAttr->value());
995 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
997 DocumentPtr aDoc = myObject->document();
998 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
1000 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
1001 if (!aFirstFeatureInFolder.get()) {
1005 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
1006 if (!aLastFeatureInFolder.get()) {
1011 theFirst = aDoc->index(aFirstFeatureInFolder);
1012 theLast = aDoc->index(aLastFeatureInFolder);
1016 //////////////////////////////////////////////////////////////////////////////////
1017 //PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
1018 // ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
1023 //void PartSet_CompsolidNode::update()
1025 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1026 // int aNb = aCompRes->numberOfSubs(true);
1027 // ModuleBase_ITreeNode* aNode;
1028 // ResultBodyPtr aBody;
1030 // for (i = 0; i < aNb; i++) {
1031 // aBody = aCompRes->subResult(i, true);
1032 // if (i < myChildren.size()) {
1033 // aNode = myChildren.at(i);
1034 // if (aNode->object() != aBody) {
1035 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1038 // aNode = new PartSet_ObjectNode(aBody, this);
1039 // myChildren.append(aNode);
1042 // // Delete extra objects
1043 // while (myChildren.size() > aNb) {
1044 // aNode = myChildren.takeLast();
1049 //QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
1051 // QTreeNodesList aResult;
1053 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1054 // int aNb = aCompRes->numberOfSubs(true);
1055 // ModuleBase_ITreeNode* aNode;
1056 // ResultBodyPtr aBody;
1058 // for (i = 0; i < aNb; i++) {
1059 // aBody = aCompRes->subResult(i, true);
1060 // if (i < myChildren.size()) {
1061 // aNode = myChildren.at(i);
1062 // if (aNode->object() != aBody) {
1063 // ((PartSet_ObjectNode*)aNode)->setObject(aBody);
1064 // aResult.append(aNode);
1067 // aNode = new PartSet_ObjectNode(aBody, this);
1068 // myChildren.append(aNode);
1069 // aResult.append(aNode);
1075 //QTreeNodesList PartSet_CompsolidNode::objectsDeleted(
1076 // const DocumentPtr& theDoc, const QString& theGroup)
1078 // QTreeNodesList aResult;
1079 // ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
1080 // int aNb = aCompRes->numberOfSubs(true);
1081 // ModuleBase_ITreeNode* aNode;
1082 // // Delete extra objects
1083 // bool isDeleted = false;
1084 // while (myChildren.size() > aNb) {
1085 // aNode = myChildren.takeLast();
1087 // isDeleted = true;
1090 // aResult.append(this);