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"
22 #include "PartSet_Tools.h"
24 #include <ModuleBase_IconFactory.h>
25 #include <ModuleBase_IWorkshop.h>
26 #include <ModuleBase_Tools.h>
28 #include <PartSetPlugin_Part.h>
30 #include <ModelAPI_Session.h>
31 #include <ModelAPI_ResultParameter.h>
32 #include <ModelAPI_ResultField.h>
33 #include <ModelAPI_ResultGroup.h>
34 #include <ModelAPI_ResultConstruction.h>
35 #include <ModelAPI_ResultPart.h>
36 #include <ModelAPI_ResultBody.h>
37 #include <ModelAPI_Tools.h>
38 #include <ModelAPI_ResultBody.h>
39 #include <ModelAPI_CompositeFeature.h>
40 #include <ModelAPI_AttributeDouble.h>
41 #include <ModelAPI_Folder.h>
42 #include <ModelAPI_AttributeReference.h>
48 #define ACTIVE_COLOR QColor(Qt::black)
49 #define SELECTABLE_COLOR QColor(100, 100, 100)
50 #define DISABLED_COLOR QColor(200, 200, 200)
52 Qt::ItemFlags aNullFlag;
53 Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
54 Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
57 ResultPartPtr getPartResult(const ObjectPtr& theObj)
59 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
61 ResultPtr aRes = aFeature->firstResult();
62 if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
63 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
64 // Use only original parts, not a placement results
65 if (aPartRes == aPartRes->original())
69 return ResultPartPtr();
72 bool isCurrentFeature(const ObjectPtr& theObj)
74 SessionPtr aSession = ModelAPI_Session::get();
75 DocumentPtr aCurDoc = aSession->activeDocument();
76 FeaturePtr aFeature = aCurDoc->currentFeature(true);
77 return aFeature == theObj;
80 //////////////////////////////////////////////////////////////////////////////////
81 QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
83 if ((theColumn == 1) && (theRole == Qt::ForegroundRole)) {
84 Qt::ItemFlags aFlags = flags(theColumn);
85 if (aFlags == Qt::ItemFlags())
86 return QBrush(DISABLED_COLOR);
87 if (!aFlags.testFlag(Qt::ItemIsEditable))
88 return QBrush(SELECTABLE_COLOR);
91 return ModuleBase_ITreeNode::data(theColumn, theRole);
95 //////////////////////////////////////////////////////////////////////////////////
96 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
100 if (theColumn == 1) {
101 if (myObject->groupName() == ModelAPI_ResultParameter::group()) {
102 ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myObject);
103 AttributeDoublePtr aValueAttribute =
104 aParam->data()->real(ModelAPI_ResultParameter::VALUE());
105 QString aVal = QString::number(aValueAttribute->value());
106 QString aTitle = QString(myObject->data()->name().c_str());
107 return aTitle + " = " + aVal;
109 return myObject->data()->name().c_str();
112 case Qt::DecorationRole:
115 switch (visibilityState()) {
119 return QIcon(":pictures/eyeopen.png");
121 return QIcon(":pictures/eyemiclosed.png");
123 return QIcon(":pictures/eyeclosed.png");
126 return ModuleBase_IconFactory::get()->getIcon(myObject);
128 if (isCurrentFeature(myObject))
129 return QIcon(":pictures/arrow.png");
134 return PartSet_TreeNode::data(theColumn, theRole);
137 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
139 if (myObject->isDisabled()) {
140 return (theColumn == 2) ? Qt::ItemIsSelectable : aNullFlag;
142 DocumentPtr aDoc = myObject->document();
143 SessionPtr aSession = ModelAPI_Session::get();
144 if (aSession->activeDocument() == aDoc)
150 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
152 Qt::ItemFlags aFlags = flags(1);
153 if (aFlags == Qt::ItemFlags())
156 if (myObject->groupName() == ModelAPI_ResultParameter::group())
158 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
160 ModuleBase_IWorkshop* aWork = workshop();
161 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResObj);
162 if (aCompRes.get()) {
163 std::list<ResultPtr> aResultsList;
164 ModelAPI_Tools::allSubs(aCompRes, aResultsList);
165 VisibilityState aState = aResultsList.size() == 0 ?
166 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
168 std::list<ResultPtr>::const_iterator aIt;
169 ResultBodyPtr aCompSub;
170 for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
171 ResultPtr aSubRes = (*aIt);
172 aCompSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aSubRes);
173 if (!(aCompSub.get() && aCompSub->numberOfSubs() > 0)) {
174 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
175 if (aState == NoneState)
177 else if (aState != aS) {
178 aState = SemiVisible;
185 if (aWork->isVisible(aResObj))
194 int PartSet_ObjectNode::numberOfSubs() const
196 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
198 return aCompRes->numberOfSubs(true);
200 CompositeFeaturePtr aCompFeature =
201 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
202 if (aCompFeature.get() && aCompFeature->data()->isValid())
203 return aCompFeature->numberOfSubs(true);
205 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
207 return aFieldRes->stepsSize();
214 ObjectPtr PartSet_ObjectNode::subObject(int theId) const
216 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
218 return aCompRes->subResult(theId, true);
220 CompositeFeaturePtr aCompFeature =
221 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myObject);
222 if (aCompFeature.get())
223 return aCompFeature->subFeature(theId, true);
228 void PartSet_ObjectNode::update()
230 int aNb = numberOfSubs();
232 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
234 // If the object is a field result then delete extra sub-objects
235 if (aFieldRes.get()) {
236 while (myChildren.size() > aNb) {
237 ModuleBase_ITreeNode* aNode = myChildren.last();
238 myChildren.removeAll(aNode);
244 ModuleBase_ITreeNode* aNode;
246 while (aId < myChildren.size()) {
247 aNode = myChildren.at(aId);
248 aObj = subObject(aId);
249 if (aNode->object() != aObj) {
250 myChildren.removeAll(aNode);
258 ModuleBase_ITreeNode* aNode;
261 for (i = 0; i < aNb; i++) {
262 aBody = subObject(i);
264 if (i < myChildren.size()) {
265 aNode = myChildren.at(i);
266 if (aNode->object() != aBody) {
267 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
271 aNode = new PartSet_ObjectNode(aBody, this);
272 myChildren.append(aNode);
275 else if (aFieldRes.get()) {
276 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
277 if (i < myChildren.size()) {
278 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
279 if (aStepNode->entity() != aStep) {
280 aStepNode->setEntity(aStep);
284 aNode = new PartSet_StepNode(aStep, this);
285 myChildren.append(aNode);
289 // Delete extra objects
290 while (myChildren.size() > aNb) {
291 aNode = myChildren.takeLast();
294 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
303 QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
305 QTreeNodesList aResult;
306 int aNb = numberOfSubs();
308 ModuleBase_ITreeNode* aNode;
309 ResultFieldPtr aFieldRes = std::dynamic_pointer_cast<ModelAPI_ResultField>(myObject);
312 for (i = 0; i < aNb; i++) {
313 aBody = subObject(i);
315 if (i < myChildren.size()) {
316 aNode = myChildren.at(i);
317 if (aNode->object() != aBody) {
318 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
319 aResult.append(aNode);
323 aNode = new PartSet_ObjectNode(aBody, this);
324 myChildren.append(aNode);
325 aResult.append(aNode);
330 ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
331 if (i < myChildren.size()) {
332 PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
333 if (aStepNode->entity() != aStep) {
334 aStepNode->setEntity(aStep);
338 aNode = new PartSet_StepNode(aStep, this);
339 myChildren.append(aNode);
343 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
344 aResult.append(aNode->objectCreated(theObjects));
350 QTreeNodesList PartSet_ObjectNode::objectsDeleted(
351 const DocumentPtr& theDoc, const QString& theGroup)
353 QTreeNodesList aResult;
354 int aNb = numberOfSubs();
355 if (aNb != myChildren.size()) {
358 aResult.append(this);
361 // Delete extra objects
362 bool isDeleted = false;
364 ModuleBase_ITreeNode* aNode;
366 while (aId < myChildren.size()) {
367 aNode = myChildren.at(aId);
368 aObj = subObject(aId);
369 if (aNode->object() != aObj) {
370 myChildren.removeAll(aNode);
378 aResult.append(this);
381 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
382 aBody = subObject(i);
383 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
384 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
391 //////////////////////////////////////////////////////////////////////////////////
392 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
394 : PartSet_TreeNode(theParent), myType(theType)
398 QString PartSet_FolderNode::name() const
401 case ParametersFolder:
402 return QObject::tr("Parameters");
403 case ConstructionFolder:
404 return QObject::tr("Constructions");
406 return QObject::tr("Parts");
408 return QObject::tr("Results");
410 return QObject::tr("Fields");
412 return QObject::tr("Groups");
418 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
420 static QIcon aParamsIco(":pictures/params_folder.png");
421 static QIcon aConstrIco(":pictures/constr_folder.png");
423 if (theColumn == 1) {
425 case Qt::DisplayRole:
426 return name() + QString(" (%1)").arg(childrenCount());
427 case Qt::DecorationRole:
429 case ParametersFolder:
431 case ConstructionFolder:
444 if ((theColumn == 2) && (theRole == Qt::DecorationRole)) {
445 if (document().get()) {
446 SessionPtr aSession = ModelAPI_Session::get();
447 if (document() != aSession->activeDocument())
450 FeaturePtr aFeature = document()->currentFeature(true);
451 if (!aFeature.get()) { // There is no current feature
452 ModuleBase_ITreeNode* aLastFolder = 0;
453 foreach(ModuleBase_ITreeNode* aNode, parent()->children()) {
454 if (aNode->type() == PartSet_FolderNode::typeId())
459 if (aLastFolder == this)
460 return QIcon(":pictures/arrow.png");
466 return PartSet_TreeNode::data(theColumn, theRole);
469 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
471 SessionPtr aSession = ModelAPI_Session::get();
472 DocumentPtr aActiveDoc = aSession->activeDocument();
473 if (theColumn == 1) {
474 if (document() == aActiveDoc)
480 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
482 //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
483 //if (aCompRes.get())
484 // return new PartSet_CompsolidNode(theObj, this);
485 return new PartSet_ObjectNode(theObj, this);
488 void PartSet_FolderNode::update()
490 DocumentPtr aDoc = document();
494 // Remove extra sub-nodes
497 while (aId < myChildren.size()) {
498 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
499 aIndex = aDoc->index(aNode->object(), true);
500 if ((aIndex == -1) || (aId != aIndex)) {
501 myChildren.removeAll(aNode);
508 std::string aGroup = groupName();
509 int aSize = aDoc->size(aGroup, true);
510 for (int i = 0; i < aSize; i++) {
511 ObjectPtr aObj = aDoc->object(aGroup, i, true);
512 if (i < myChildren.size()) {
513 if (myChildren.at(i)->object() != aObj) {
514 ModuleBase_ITreeNode* aNode = createNode(aObj);
515 myChildren.insert(i, aNode);
518 ModuleBase_ITreeNode* aNode = createNode(aObj);
519 myChildren.append(aNode);
523 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
528 std::string PartSet_FolderNode::groupName() const
531 case ParametersFolder:
532 return ModelAPI_ResultParameter::group();
533 case ConstructionFolder:
534 return ModelAPI_ResultConstruction::group();
536 return ModelAPI_ResultPart::group();
538 return ModelAPI_ResultBody::group();
540 return ModelAPI_ResultField::group();
542 return ModelAPI_ResultGroup::group();
547 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
549 QTreeNodesList aResult;
550 std::string aName = groupName();
551 DocumentPtr aDoc = document();
553 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
554 foreach(ObjectPtr aObj, theObjects) {
555 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
556 aIdx = aDoc->index(aObj, true);
558 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
560 ModuleBase_ITreeNode* aNode = createNode(aObj);
561 aNewNodes[aIdx] = aNode;
562 aResult.append(aNode);
568 // Add nodes in correct order
570 for (i = 0; i < myChildren.size(); i++) {
571 if (aNewNodes.contains(i)) {
572 myChildren.insert(i, aNewNodes[i]);
576 while (aNewNodes.size()) {
577 i = myChildren.size();
578 myChildren.append(aNewNodes[i]);
581 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
582 aResult.append(aNode->objectCreated(theObjects));
587 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
588 const QString& theGroup)
590 DocumentPtr aDoc = document();
591 QTreeNodesList aResult;
592 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
593 QTreeNodesList aDelList;
596 bool aRemoved = false;
597 bool aToSort = false;
598 while (aId < myChildren.size()) {
599 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
600 aIndex = aDoc->index(aNode->object(), true);
601 aToSort |= ((aIndex != -1) && (aId != aIndex));
603 myChildren.removeAll(aNode);
611 aResult.append(this);
614 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
615 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
621 //////////////////////////////////////////////////////////////////////////////////
622 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
624 QTreeNodesList aResult;
625 // Process the root sub-objects
626 DocumentPtr aDoc = document();
628 int aNb = numberOfFolders();
629 QMap<int, ModuleBase_ITreeNode*> aNewNodes;
630 foreach(ObjectPtr aObj, theObjects) {
631 if (aDoc == aObj->document()) {
632 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
633 (aObj->groupName() == ModelAPI_Folder::group())){
634 aIdx = aDoc->index(aObj, true);
636 ModuleBase_ITreeNode* aNode = createNode(aObj);
638 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
640 aNewNodes[aIdx] = aNode;
641 aResult.append(aNode);
648 // To add in correct order
650 for (i = 0; i < myChildren.size(); i++) {
651 if (aNewNodes.contains(i)) {
652 myChildren.insert(i, aNewNodes[i]);
656 while (aNewNodes.size()) {
657 i = myChildren.size();
658 myChildren.append(aNewNodes[i]);
662 // Update sub-folders
663 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
664 aResult.append(aNode->objectCreated(theObjects));
669 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
670 const QString& theGroup)
672 QTreeNodesList aResult;
674 // Process sub-folders
675 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
676 if (aNode->childrenCount() > 0) { // aFolder node
677 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
678 if (aList.size() > 0)
679 aResult.append(aList);
684 DocumentPtr aDoc = document();
685 int aNb = numberOfFolders();
686 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
687 (theGroup.toStdString() == ModelAPI_Folder::group()));
688 if ((theDoc == aDoc) && isGroup) {
691 bool aRemoved = false;
692 bool aToSort = false;
693 while (aId < myChildren.size()) {
694 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
695 if (aNode->object().get()) {
696 aIndex = aDoc->index(aNode->object(), true);
697 aToSort |= ((aIndex != -1) && (aId != (aIndex + aNb)));
699 myChildren.removeAll(aNode);
708 aResult.append(this);
715 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
718 ModuleBase_ITreeNode* aResult = 0;
719 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
720 aResult = aNode->findParent(theDoc, theGroup);
725 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
726 (theGroup.toStdString() == ModelAPI_Folder::group()));
727 if ((theDoc == document()) && isGroup)
733 //////////////////////////////////////////////////////////////////////////////////
734 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
736 SessionPtr aSession = ModelAPI_Session::get();
737 DocumentPtr aDoc = aSession->moduleDocument();
739 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
740 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
741 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
743 myChildren.append(myParamsFolder);
744 myChildren.append(myConstrFolder);
745 myChildren.append(myPartsFolder);
751 void PartSet_RootNode::update()
753 myParamsFolder->update();
754 myConstrFolder->update();
755 myPartsFolder->update();
757 // Update features content
758 DocumentPtr aDoc = document();
759 int aNb = numberOfFolders();
761 // Remove extra sub-nodes
764 while (aId < myChildren.size()) {
765 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
766 if (aNode->object().get()) {
767 aIndex = aDoc->index(aNode->object(), true);
768 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
769 myChildren.removeAll(aNode);
778 std::string aGroup = ModelAPI_Feature::group();
779 int aSize = aDoc->size(aGroup, true);
781 for (int i = 0; i < aSize; i++) {
782 ObjectPtr aObj = aDoc->object(aGroup, i, true);
783 aId = i + aNb; // Take into account existing folders
784 if (aId < myChildren.size()) {
785 if (myChildren.at(aId)->object() != aObj) {
786 ModuleBase_ITreeNode* aNode = createNode(aObj);
787 myChildren.insert(aId, aNode);
790 ModuleBase_ITreeNode* aNode = createNode(aObj);
791 myChildren.append(aNode);
794 // Update sub-folders
795 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
796 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
797 (aNode->type() == PartSet_PartRootNode::typeId()))
802 DocumentPtr PartSet_RootNode::document() const
804 return ModelAPI_Session::get()->moduleDocument();
807 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
809 if (theObj->groupName() == ModelAPI_Folder::group())
810 return new PartSet_ObjectFolderNode(theObj, this);
812 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
813 if (aFeature->getKind() == PartSetPlugin_Part::ID())
814 return new PartSet_PartRootNode(theObj, this);
816 return new PartSet_ObjectNode(theObj, this);
819 //////////////////////////////////////////////////////////////////////////////////
820 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
821 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
823 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
824 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
825 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
826 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
827 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
829 myChildren.append(myParamsFolder);
830 myChildren.append(myConstrFolder);
831 myChildren.append(myResultsFolder);
836 void PartSet_PartRootNode::deleteChildren()
838 if (!myFieldsFolder->childrenCount()) {
839 delete myFieldsFolder;
841 if (!myGroupsFolder->childrenCount()) {
842 delete myGroupsFolder;
844 PartSet_FeatureFolderNode::deleteChildren();
848 void PartSet_PartRootNode::update()
850 DocumentPtr aDoc = document();
854 myParamsFolder->update();
855 myConstrFolder->update();
856 myResultsFolder->update();
857 myFieldsFolder->update();
858 myGroupsFolder->update();
860 bool aHasFields = myFieldsFolder->childrenCount() > 0;
861 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
862 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
863 myChildren.insert(3, myFieldsFolder);
865 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
866 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
869 // Update features content
870 int aRows = numberOfFolders();
872 // Remove extra sub-nodes
875 while (aId < myChildren.size()) {
876 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
877 if (aNode->object().get()) {
878 aIndex = aDoc->index(aNode->object(), true);
879 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
880 myChildren.removeAll(aNode);
888 std::string aGroup = ModelAPI_Feature::group();
889 int aSize = aDoc->size(aGroup, true);
891 for (int i = 0; i < aSize; i++) {
892 ObjectPtr aObj = aDoc->object(aGroup, i, true);
893 aId = i + aRows; // Take into account existing folders
894 if (aId < myChildren.size()) {
895 if (myChildren.at(aId)->object() != aObj) {
896 ModuleBase_ITreeNode* aNode = createNode(aObj);
897 myChildren.insert(aId, aNode);
900 ModuleBase_ITreeNode* aNode = createNode(aObj);
901 myChildren.append(aNode);
904 // Update sub-folders
905 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
906 if (aNode->type() == PartSet_ObjectFolderNode::typeId())
911 DocumentPtr PartSet_PartRootNode::document() const
913 ResultPartPtr aPartRes = getPartResult(myObject);
915 return aPartRes->partDoc();
916 return DocumentPtr();
919 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
924 case Qt::DisplayRole:
926 ResultPartPtr aPartRes = getPartResult(myObject);
927 if (aPartRes.get()) {
928 if (aPartRes->partDoc().get() == NULL)
929 return QString(myObject->data()->name().c_str()) + " (Not loaded)";
931 return QString(myObject->data()->name().c_str());
933 case Qt::DecorationRole:
934 return ModuleBase_IconFactory::get()->getIcon(myObject);
937 if (theRole == Qt::DecorationRole) {
938 if (isCurrentFeature(myObject))
939 return QIcon(":pictures/arrow.png");
944 return PartSet_TreeNode::data(theColumn, theRole);
947 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
949 if (myObject->isDisabled())
950 return (theColumn == 2) ? Qt::ItemIsSelectable : aDefaultFlag;
952 SessionPtr aSession = ModelAPI_Session::get();
953 DocumentPtr aActiveDoc = aSession->activeDocument();
954 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
959 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
961 if (theObj->groupName() == ModelAPI_Folder::group())
962 return new PartSet_ObjectFolderNode(theObj, this);
963 return new PartSet_ObjectNode(theObj, this);
966 int PartSet_PartRootNode::numberOfFolders() const
969 if (myFieldsFolder->childrenCount() > 0)
971 if (myGroupsFolder->childrenCount() > 0)
976 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
978 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
979 if (!myFieldsFolder->childrenCount()) {
980 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
982 myChildren.insert(3, myFieldsFolder);
983 aResult.append(myFieldsFolder);
984 aResult.append(aList);
987 if (!myGroupsFolder->childrenCount()) {
988 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
990 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
991 aResult.append(myGroupsFolder);
992 aResult.append(aList);
998 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
999 const QString& theGroup)
1001 QTreeNodesList aResult;
1002 if (myFieldsFolder->childrenCount()) {
1003 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
1005 aResult.append(aList);
1006 if (!myFieldsFolder->childrenCount())
1007 myChildren.removeAll(myFieldsFolder);
1010 if (myGroupsFolder->childrenCount()) {
1011 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
1013 aResult.append(aList);
1014 if (!myGroupsFolder->childrenCount())
1015 myChildren.removeAll(myGroupsFolder);
1018 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
1022 //////////////////////////////////////////////////////////////////////////////////
1023 void PartSet_ObjectFolderNode::update()
1025 int aFirst = -1, aLast = -1;
1026 PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
1027 if ((aFirst == -1) || (aLast == -1)) {
1032 int aNbItems = aLast - aFirst + 1;
1038 DocumentPtr aDoc = myObject->document();
1039 if (aNbItems < myChildren.size()) {
1040 // Delete obsolete nodes
1042 int aNbOfFeatures = aDoc->size(ModelAPI_Feature::group(), true);
1043 while (aId < myChildren.size()) {
1044 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1045 if ((aFirst + aId) < aNbOfFeatures) {
1046 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1047 myChildren.removeAll(aNode);
1053 myChildren.removeAll(aNode);
1060 if (aNbItems > myChildren.size()) {
1062 ModuleBase_ITreeNode* aNode;
1063 for (int i = 0; i < aNbItems; i++) {
1064 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1065 if (i < myChildren.size()) {
1066 if (aObj != myChildren.at(i)->object()) {
1067 aNode = new PartSet_ObjectNode(aObj, this);
1068 myChildren.insert(i, aNode);
1072 aNode = new PartSet_ObjectNode(aObj, this);
1073 myChildren.append(aNode);
1079 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
1081 QTreeNodesList aResult;
1082 int aFirst = -1, aLast = -1;
1083 PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
1084 if ((aFirst == -1) || (aLast == -1)) {
1087 int aNbItems = aLast - aFirst + 1;
1091 DocumentPtr aDoc = myObject->document();
1093 ModuleBase_ITreeNode* aNode;
1094 for (int i = 0; i < aNbItems; i++) {
1095 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
1096 if (i < myChildren.size()) {
1097 if (aObj != myChildren.at(i)->object()) {
1098 aNode = new PartSet_ObjectNode(aObj, this);
1099 myChildren.insert(i, aNode);
1100 aResult.append(aNode);
1103 aNode = new PartSet_ObjectNode(aObj, this);
1104 myChildren.append(aNode);
1105 aResult.append(aNode);
1111 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
1112 const QString& theGroup)
1114 QTreeNodesList aResult;
1115 int aFirst = -1, aLast = -1;
1116 PartSet_Tools::getFirstAndLastIndexInFolder(myObject, aFirst, aLast);
1117 if ((aFirst == -1) || (aLast == -1)) {
1120 int aNbItems = aLast - aFirst + 1;
1124 if (aNbItems >= myChildren.size()) // Nothing was deleted here
1127 DocumentPtr aDoc = myObject->document();
1128 // Delete obsolete nodes
1129 bool aRemoved = false;
1131 int aNbOfFeatures = aDoc->size(ModelAPI_Feature::group(), true);
1132 while (aId < myChildren.size()) {
1133 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
1134 if ((aFirst + aId) < aNbOfFeatures) {
1135 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
1136 myChildren.removeAll(aNode);
1143 myChildren.removeAll(aNode);
1151 aResult.append(this);
1158 //////////////////////////////////////////////////////////////////////////////////
1159 QVariant PartSet_StepNode::data(int theColumn, int theRole) const
1161 if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
1162 ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
1163 dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
1165 return "Step " + QString::number(aStep->id() + 1) + " " +
1166 aStep->field()->textLine(aStep->id()).c_str();
1168 return PartSet_TreeNode::data(theColumn, theRole);