1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_TreeNodes.h"
23 #include <ModuleBase_IconFactory.h>
24 #include <ModuleBase_IWorkshop.h>
26 #include <PartSetPlugin_Part.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_ResultParameter.h>
30 #include <ModelAPI_ResultField.h>
31 #include <ModelAPI_ResultGroup.h>
32 #include <ModelAPI_ResultConstruction.h>
33 #include <ModelAPI_ResultPart.h>
34 #include <ModelAPI_ResultBody.h>
35 #include <ModelAPI_Tools.h>
36 #include <ModelAPI_ResultCompSolid.h>
37 #include <ModelAPI_CompositeFeature.h>
38 #include <ModelAPI_AttributeDouble.h>
39 #include <ModelAPI_Folder.h>
40 #include <ModelAPI_AttributeReference.h>
45 #define ACTIVE_COLOR QColor(Qt::black)
46 #define SELECTABLE_COLOR QColor(100, 100, 100)
47 #define DISABLED_COLOR QColor(200, 200, 200)
49 Qt::ItemFlags aNullFlag;
50 Qt::ItemFlags aDefaultFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
51 Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
54 ResultPartPtr getPartResult(const ObjectPtr& theObj)
56 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
58 ResultPtr aRes = aFeature->firstResult();
59 if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
60 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
61 // Use only original parts, not a placement results
62 if (aPartRes == aPartRes->original())
66 return ResultPartPtr();
69 bool isCurrentFeature(const ObjectPtr& theObj)
71 SessionPtr aSession = ModelAPI_Session::get();
72 DocumentPtr aCurDoc = aSession->activeDocument();
73 FeaturePtr aFeature = aCurDoc->currentFeature(true);
74 return aFeature == theObj;
77 //////////////////////////////////////////////////////////////////////////////////
78 QVariant PartSet_TreeNode::data(int theColumn, int theRole) const
80 if ((theColumn == 1) && (theRole == Qt::ForegroundRole)) {
81 Qt::ItemFlags aFlags = flags(theColumn);
82 if (aFlags == Qt::ItemFlags())
83 return QBrush(DISABLED_COLOR);
84 if (!aFlags.testFlag(Qt::ItemIsEditable))
85 return QBrush(SELECTABLE_COLOR);
88 return ModuleBase_ITreeNode::data(theColumn, theRole);
92 //////////////////////////////////////////////////////////////////////////////////
93 QVariant PartSet_ObjectNode::data(int theColumn, int theRole) const
98 if (myObject->groupName() == ModelAPI_ResultParameter::group()) {
99 ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myObject);
100 AttributeDoublePtr aValueAttribute =
101 aParam->data()->real(ModelAPI_ResultParameter::VALUE());
102 QString aVal = QString::number(aValueAttribute->value());
103 QString aTitle = QString(myObject->data()->name().c_str());
104 return aTitle + " = " + aVal;
106 return myObject->data()->name().c_str();
109 case Qt::DecorationRole:
112 switch (visibilityState()) {
116 return QIcon(":pictures/eyeopen.png");
118 return QIcon(":pictures/eyemiclosed.png");
120 return QIcon(":pictures/eyeclosed.png");
123 if (myObject->groupName() == ModelAPI_Folder::group())
124 return QIcon(":pictures/features_folder.png");
126 return ModuleBase_IconFactory::get()->getIcon(myObject);
128 if (isCurrentFeature(myObject))
129 return QIcon(":pictures/arrow.png");
132 return PartSet_TreeNode::data(theColumn, theRole);
135 Qt::ItemFlags PartSet_ObjectNode::flags(int theColumn) const
137 if (myObject->isDisabled()) {
138 return (theColumn == 2) ? Qt::ItemIsSelectable : aNullFlag;
140 DocumentPtr aDoc = myObject->document();
141 SessionPtr aSession = ModelAPI_Session::get();
142 if (aSession->activeDocument() == aDoc)
148 PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
150 Qt::ItemFlags aFlags = flags(1);
151 if (aFlags == Qt::ItemFlags())
154 if (myObject->groupName() == ModelAPI_ResultParameter::group())
156 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
158 ModuleBase_IWorkshop* aWork = workshop();
159 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
160 if (aCompRes.get()) {
161 VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
162 (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
163 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
164 ResultPtr aSubRes = aCompRes->subResult(i, true);
165 VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
166 if (aState == NoneState)
168 else if (aState != aS) {
169 aState = SemiVisible;
175 if (aWork->isVisible(aResObj))
185 //////////////////////////////////////////////////////////////////////////////////
186 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
188 : PartSet_TreeNode(theParent), myType(theType)
192 QString PartSet_FolderNode::name() const
195 case ParametersFolder:
196 return QObject::tr("Parameters");
197 case ConstructionFolder:
198 return QObject::tr("Constructions");
200 return QObject::tr("Parts");
202 return QObject::tr("Results");
204 return QObject::tr("Fields");
206 return QObject::tr("Groups");
212 QVariant PartSet_FolderNode::data(int theColumn, int theRole) const
214 static QIcon aParamsIco(":pictures/params_folder.png");
215 static QIcon aConstrIco(":pictures/constr_folder.png");
217 if (theColumn == 1) {
219 case Qt::DisplayRole:
220 return name() + QString(" (%1)").arg(childrenCount());
221 case Qt::DecorationRole:
223 case ParametersFolder:
225 case ConstructionFolder:
238 return PartSet_TreeNode::data(theColumn, theRole);
241 Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
243 SessionPtr aSession = ModelAPI_Session::get();
244 DocumentPtr aActiveDoc = aSession->activeDocument();
245 if (theColumn == 1) {
246 if (document() == aActiveDoc)
252 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
254 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
256 return new PartSet_CompsolidNode(theObj, this);
257 return new PartSet_ObjectNode(theObj, this);
260 void PartSet_FolderNode::update()
262 DocumentPtr aDoc = document();
266 // Remove extra sub-nodes
269 while (aId < myChildren.size()) {
270 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
271 aIndex = aDoc->index(aNode->object(), true);
272 if ((aIndex == -1) || (aId != aIndex)) {
273 myChildren.removeAll(aNode);
280 std::string aGroup = groupName();
281 int aSize = aDoc->size(aGroup, true);
282 for (int i = 0; i < aSize; i++) {
283 ObjectPtr aObj = aDoc->object(aGroup, i, true);
284 if (i < myChildren.size()) {
285 if (myChildren.at(i)->object() != aObj) {
286 ModuleBase_ITreeNode* aNode = createNode(aObj);
287 myChildren.insert(i, aNode);
290 ModuleBase_ITreeNode* aNode = createNode(aObj);
291 myChildren.append(aNode);
295 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
300 std::string PartSet_FolderNode::groupName() const
303 case ParametersFolder:
304 return ModelAPI_ResultParameter::group();
305 case ConstructionFolder:
306 return ModelAPI_ResultConstruction::group();
308 return ModelAPI_ResultPart::group();
310 return ModelAPI_ResultBody::group();
312 return ModelAPI_ResultField::group();
314 return ModelAPI_ResultGroup::group();
319 QTreeNodesList PartSet_FolderNode::objectCreated(const QObjectPtrList& theObjects)
321 QTreeNodesList aResult;
322 std::string aName = groupName();
323 DocumentPtr aDoc = document();
325 foreach(ObjectPtr aObj, theObjects) {
326 if ((aObj->document() == aDoc) && (aObj->groupName() == aName)) {
327 aIdx = aDoc->index(aObj, true);
329 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
331 ModuleBase_ITreeNode* aNode = createNode(aObj);
332 aResult.append(aNode);
333 if (aIdx < myChildren.size())
334 myChildren.insert(aIdx, aNode);
336 myChildren.append(aNode);
341 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
342 aResult.append(aNode->objectCreated(theObjects));
347 QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc,
348 const QString& theGroup)
350 DocumentPtr aDoc = document();
351 QTreeNodesList aResult;
352 if ((theGroup.toStdString() == groupName()) && (theDoc == aDoc)) {
353 QTreeNodesList aDelList;
356 bool aRemoved = false;
357 while (aId < myChildren.size()) {
358 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
359 aIndex = aDoc->index(aNode->object(), true);
360 if ((aIndex == -1) || (aId != aIndex)) {
361 myChildren.removeAll(aNode);
368 aResult.append(this);
370 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
371 aResult.append(aNode->objectsDeleted(theDoc, theGroup));
377 //////////////////////////////////////////////////////////////////////////////////
378 QTreeNodesList PartSet_FeatureFolderNode::objectCreated(const QObjectPtrList& theObjects)
380 QTreeNodesList aResult;
381 // Process all folders
382 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
383 if (aNode->type() == PartSet_FolderNode::typeId()) { // aFolder node
384 aResult.append(aNode->objectCreated(theObjects));
387 // Process the root sub-objects
388 DocumentPtr aDoc = document();
390 int aNb = numberOfFolders();
391 foreach(ObjectPtr aObj, theObjects) {
392 if (aDoc == aObj->document()) {
393 if ((aObj->groupName() == ModelAPI_Feature::group()) ||
394 (aObj->groupName() == ModelAPI_Folder::group())){
395 ModuleBase_ITreeNode* aNode = createNode(aObj);
396 aIdx = aDoc->index(aObj, true);
399 bool aHasObject = (aIdx < myChildren.size()) && (myChildren.at(aIdx)->object() == aObj);
401 if (aIdx < myChildren.size())
402 myChildren.insert(aIdx, aNode);
404 myChildren.append(aNode);
405 aResult.append(aNode);
411 // Update sub-folders
412 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
413 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
414 (aNode->type() == PartSet_PartRootNode::typeId()))
415 aResult.append(aNode->objectCreated(theObjects));
420 QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theDoc,
421 const QString& theGroup)
423 QTreeNodesList aResult;
425 // Process sub-folders
426 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
427 if (aNode->childrenCount() > 0) { // aFolder node
428 QTreeNodesList aList = aNode->objectsDeleted(theDoc, theGroup);
429 if (aList.size() > 0)
430 aResult.append(aList);
435 DocumentPtr aDoc = document();
436 int aNb = numberOfFolders();
437 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
438 (theGroup.toStdString() == ModelAPI_Folder::group()));
439 if ((theDoc == aDoc) && isGroup) {
442 bool aRemoved = false;
443 while (aId < myChildren.size()) {
444 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
445 if (aNode->object().get()) {
446 aIndex = aDoc->index(aNode->object(), true);
447 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
448 myChildren.removeAll(aNode);
457 aResult.append(this);
462 ModuleBase_ITreeNode* PartSet_FeatureFolderNode::findParent(const DocumentPtr& theDoc,
465 ModuleBase_ITreeNode* aResult = 0;
466 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
467 aResult = aNode->findParent(theDoc, theGroup);
472 bool isGroup = ((theGroup.toStdString() == ModelAPI_Feature::group()) ||
473 (theGroup.toStdString() == ModelAPI_Folder::group()));
474 if ((theDoc == document()) && isGroup)
480 //////////////////////////////////////////////////////////////////////////////////
481 PartSet_RootNode::PartSet_RootNode() : PartSet_FeatureFolderNode(0), myWorkshop(0)
483 SessionPtr aSession = ModelAPI_Session::get();
484 DocumentPtr aDoc = aSession->moduleDocument();
486 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
487 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
488 myPartsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::PartsFolder);
490 myChildren.append(myParamsFolder);
491 myChildren.append(myConstrFolder);
492 myChildren.append(myPartsFolder);
498 void PartSet_RootNode::update()
500 myParamsFolder->update();
501 myConstrFolder->update();
502 myPartsFolder->update();
504 // Update features content
505 DocumentPtr aDoc = document();
506 int aNb = numberOfFolders();
508 // Remove extra sub-nodes
511 while (aId < myChildren.size()) {
512 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
513 if (aNode->object().get()) {
514 aIndex = aDoc->index(aNode->object(), true);
515 if ((aIndex == -1) || (aId != (aIndex + aNb))) {
516 myChildren.removeAll(aNode);
525 std::string aGroup = ModelAPI_Feature::group();
526 int aSize = aDoc->size(aGroup, true);
528 for (int i = 0; i < aSize; i++) {
529 ObjectPtr aObj = aDoc->object(aGroup, i, true);
530 aId = i + aNb; // Take into account existing folders
531 if (aId < myChildren.size()) {
532 if (myChildren.at(aId)->object() != aObj) {
533 ModuleBase_ITreeNode* aNode = createNode(aObj);
534 myChildren.insert(aId, aNode);
537 ModuleBase_ITreeNode* aNode = createNode(aObj);
538 myChildren.append(aNode);
541 // Update sub-folders
542 foreach(ModuleBase_ITreeNode* aNode, myChildren) {
543 if ((aNode->type() == PartSet_ObjectFolderNode::typeId()) ||
544 (aNode->type() == PartSet_PartRootNode::typeId()))
549 DocumentPtr PartSet_RootNode::document() const
551 return ModelAPI_Session::get()->moduleDocument();
554 ModuleBase_ITreeNode* PartSet_RootNode::createNode(const ObjectPtr& theObj)
556 if (theObj->groupName() == ModelAPI_Folder::group())
557 return new PartSet_ObjectFolderNode(theObj, this);
559 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
560 if (aFeature->getKind() == PartSetPlugin_Part::ID())
561 return new PartSet_PartRootNode(theObj, this);
563 return new PartSet_ObjectNode(theObj, this);
566 //////////////////////////////////////////////////////////////////////////////////
567 PartSet_PartRootNode::PartSet_PartRootNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent)
568 : PartSet_FeatureFolderNode(theParent), myObject(theObj)
570 myParamsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ParametersFolder);
571 myConstrFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ConstructionFolder);
572 myResultsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::ResultsFolder);
573 myFieldsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::FieldsFolder);
574 myGroupsFolder = new PartSet_FolderNode(this, PartSet_FolderNode::GroupsFolder);
576 myChildren.append(myParamsFolder);
577 myChildren.append(myConstrFolder);
578 myChildren.append(myResultsFolder);
583 void PartSet_PartRootNode::deleteChildren()
585 if (!myFieldsFolder->childrenCount()) {
586 delete myFieldsFolder;
588 if (!myGroupsFolder->childrenCount()) {
589 delete myGroupsFolder;
591 PartSet_FeatureFolderNode::deleteChildren();
595 void PartSet_PartRootNode::update()
597 DocumentPtr aDoc = document();
601 myParamsFolder->update();
602 myConstrFolder->update();
603 myResultsFolder->update();
604 myFieldsFolder->update();
605 myGroupsFolder->update();
607 bool aHasFields = myFieldsFolder->childrenCount() > 0;
608 bool aHasGroups = myGroupsFolder->childrenCount() > 0;
609 if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
610 myChildren.insert(3, myFieldsFolder);
612 if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
613 myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
616 // Update features content
617 int aRows = numberOfFolders();
619 // Remove extra sub-nodes
622 while (aId < myChildren.size()) {
623 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
624 if (aNode->object().get()) {
625 aIndex = aDoc->index(aNode->object(), true);
626 if ((aIndex == -1) || (aId != (aIndex + aRows))) {
627 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 + aRows; // 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())
658 DocumentPtr PartSet_PartRootNode::document() const
660 ResultPartPtr aPartRes = getPartResult(myObject);
662 return aPartRes->partDoc();
663 return DocumentPtr();
666 QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const
671 case Qt::DisplayRole:
672 return QString(myObject->data()->name().c_str());
673 case Qt::DecorationRole:
674 return ModuleBase_IconFactory::get()->getIcon(myObject);
677 if (theRole == Qt::DecorationRole)
678 if (isCurrentFeature(myObject))
679 return QIcon(":pictures/arrow.png");
681 return PartSet_TreeNode::data(theColumn, theRole);
684 Qt::ItemFlags PartSet_PartRootNode::flags(int theColumn) const
686 SessionPtr aSession = ModelAPI_Session::get();
687 DocumentPtr aActiveDoc = aSession->activeDocument();
688 if ((aActiveDoc == document()) || (myObject->document() == aActiveDoc))
693 ModuleBase_ITreeNode* PartSet_PartRootNode::createNode(const ObjectPtr& theObj)
695 if (theObj->groupName() == ModelAPI_Folder::group())
696 return new PartSet_ObjectFolderNode(theObj, this);
697 return new PartSet_ObjectNode(theObj, this);
700 int PartSet_PartRootNode::numberOfFolders() const
703 if (myFieldsFolder->childrenCount() > 0)
705 if (myGroupsFolder->childrenCount() > 0)
710 QTreeNodesList PartSet_PartRootNode::objectCreated(const QObjectPtrList& theObjects)
712 QTreeNodesList aResult = PartSet_FeatureFolderNode::objectCreated(theObjects);
713 if (!myFieldsFolder->childrenCount()) {
714 QTreeNodesList aList = myFieldsFolder->objectCreated(theObjects);
716 myChildren.insert(3, myFieldsFolder);
717 aResult.append(myFieldsFolder);
718 aResult.append(aList);
721 if (!myGroupsFolder->childrenCount()) {
722 QTreeNodesList aList = myGroupsFolder->objectCreated(theObjects);
724 myChildren.insert(myFieldsFolder->childrenCount()? 4 : 3, myGroupsFolder);
725 aResult.append(myGroupsFolder);
726 aResult.append(aList);
732 QTreeNodesList PartSet_PartRootNode::objectsDeleted(const DocumentPtr& theDoc,
733 const QString& theGroup)
735 QTreeNodesList aResult;
736 if (myFieldsFolder->childrenCount()) {
737 QTreeNodesList aList = myFieldsFolder->objectsDeleted(theDoc, theGroup);
739 aResult.append(aList);
740 if (!myFieldsFolder->childrenCount())
741 myChildren.removeAll(myFieldsFolder);
744 if (myGroupsFolder->childrenCount()) {
745 QTreeNodesList aList = myGroupsFolder->objectsDeleted(theDoc, theGroup);
747 aResult.append(aList);
748 if (!myGroupsFolder->childrenCount())
749 myChildren.removeAll(myGroupsFolder);
752 aResult.append(PartSet_FeatureFolderNode::objectsDeleted(theDoc, theGroup));
756 //////////////////////////////////////////////////////////////////////////////////
757 void PartSet_ObjectFolderNode::update()
760 getFirstAndLastIndex(aFirst, aLast);
761 if ((aFirst == -1) || (aLast == -1)) {
766 int aNbItems = aLast - aFirst + 1;
772 DocumentPtr aDoc = myObject->document();
773 // Delete obsolete nodes
775 while (aId < myChildren.size()) {
776 ModuleBase_ITreeNode* aNode = myChildren.at(aId);
777 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
778 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
779 myChildren.removeAll(aNode);
788 ModuleBase_ITreeNode* aNode;
789 for (int i = 0; i < aNbItems; i++) {
790 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
791 if (i < myChildren.size()) {
792 if (aObj != myChildren.at(i)->object()) {
793 aNode = new PartSet_ObjectNode(aObj, this);
794 myChildren.insert(i, aNode);
797 aNode = new PartSet_ObjectNode(aObj, this);
798 myChildren.append(aNode);
803 QTreeNodesList PartSet_ObjectFolderNode::objectCreated(const QObjectPtrList& theObjects)
805 QTreeNodesList aResult;
807 getFirstAndLastIndex(aFirst, aLast);
808 if ((aFirst == -1) || (aLast == -1)) {
811 int aNbItems = aLast - aFirst + 1;
815 DocumentPtr aDoc = myObject->document();
817 ModuleBase_ITreeNode* aNode;
818 for (int i = 0; i < aNbItems; i++) {
819 ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i);
820 if (i < myChildren.size()) {
821 if (aObj != myChildren.at(i)->object()) {
822 aNode = new PartSet_ObjectNode(aObj, this);
823 myChildren.insert(i, aNode);
824 aResult.append(aNode);
827 aNode = new PartSet_ObjectNode(aObj, this);
828 myChildren.append(aNode);
829 aResult.append(aNode);
835 QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDoc,
836 const QString& theGroup)
838 QTreeNodesList aResult;
840 getFirstAndLastIndex(aFirst, aLast);
841 if ((aFirst == -1) || (aLast == -1)) {
844 int aNbItems = aLast - aFirst + 1;
848 DocumentPtr aDoc = myObject->document();
849 // Delete obsolete nodes
850 bool aRemoved = false;
852 while (aId < myChildren.size()) {
853 ModuleBase_ITreeNode* aNode = myChildren.at(1);
854 if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) {
855 if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) {
856 myChildren.removeAll(aNode);
865 aResult.append(this);
870 FeaturePtr PartSet_ObjectFolderNode::getFeature(const std::string& theId) const
872 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
873 AttributeReferencePtr aFeatAttr = aFolder->data()->reference(theId);
875 return ModelAPI_Feature::feature(aFeatAttr->value());
879 void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) const
881 DocumentPtr aDoc = myObject->document();
882 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(myObject);
884 FeaturePtr aFirstFeatureInFolder = getFeature(ModelAPI_Folder::FIRST_FEATURE_ID());
885 if (!aFirstFeatureInFolder.get()) {
889 FeaturePtr aLastFeatureInFolder = getFeature(ModelAPI_Folder::LAST_FEATURE_ID());
890 if (!aLastFeatureInFolder.get()) {
895 theFirst = aDoc->index(aFirstFeatureInFolder);
896 theLast = aDoc->index(aLastFeatureInFolder);
900 //////////////////////////////////////////////////////////////////////////////////
901 PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
902 ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
907 void PartSet_CompsolidNode::update()
909 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
910 int aNb = aCompRes->numberOfSubs(true);
911 ModuleBase_ITreeNode* aNode;
914 for (i = 0; i < aNb; i++) {
915 aBody = aCompRes->subResult(i, true);
916 if (i < myChildren.size()) {
917 aNode = myChildren.at(i);
918 if (aNode->object() != aBody) {
919 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
922 aNode = new PartSet_ObjectNode(aBody, this);
923 myChildren.append(aNode);
926 // Delete extra objects
927 while (myChildren.size() > aNb) {
928 aNode = myChildren.takeLast();
933 QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
935 QTreeNodesList aResult;
937 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
938 int aNb = aCompRes->numberOfSubs(true);
939 ModuleBase_ITreeNode* aNode;
942 for (i = 0; i < aNb; i++) {
943 aBody = aCompRes->subResult(i, true);
944 if (i < myChildren.size()) {
945 aNode = myChildren.at(i);
946 if (aNode->object() != aBody) {
947 ((PartSet_ObjectNode*)aNode)->setObject(aBody);
948 aResult.append(aNode);
951 aNode = new PartSet_ObjectNode(aBody, this);
952 myChildren.append(aNode);
953 aResult.append(aNode);
959 QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
961 QTreeNodesList aResult;
962 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
963 int aNb = aCompRes->numberOfSubs(true);
964 ModuleBase_ITreeNode* aNode;
965 // Delete extra objects
966 bool isDeleted = false;
967 while (myChildren.size() > aNb) {
968 aNode = myChildren.takeLast();
973 aResult.append(this);