-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "PartSet_TreeNodes.h"
else {
aNode = new PartSet_ObjectNode(aBody, this);
myChildren.append(aNode);
+ aNode->update();
}
}
else if (aFieldRes.get()) {
//ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
//if (aCompRes.get())
// return new PartSet_CompsolidNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ ModuleBase_ITreeNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
void PartSet_FolderNode::update()
}
}
// Add nodes in correct order
- int i;
- for (i = 0; i < myChildren.size(); i++) {
- if (aNewNodes.contains(i)) {
- myChildren.insert(i, aNewNodes[i]);
+ if (aNewNodes.size() > 0) {
+ int i;
+ for (i = 0; i < myChildren.size(); i++) {
+ if (aNewNodes.contains(i)) {
+ myChildren.insert(i, aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
+ }
+ while (aNewNodes.size()) {
+ i = myChildren.size();
+ myChildren.append(aNewNodes[i]);
aNewNodes.remove(i);
}
}
- while (aNewNodes.size()) {
- i = myChildren.size();
- myChildren.append(aNewNodes[i]);
- aNewNodes.remove(i);
- }
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
aResult.append(aNode->objectCreated(theObjects));
}
}
}
// To add in correct order
- int i;
- for (i = 0; i < myChildren.size(); i++) {
- if (aNewNodes.contains(i)) {
- myChildren.insert(i, aNewNodes[i]);
- aNewNodes.remove(i);
+ if (aNewNodes.size() > 0) {
+ int i;
+ for (i = 0; i < myChildren.size(); i++) {
+ if (aNewNodes.contains(i)) {
+ myChildren.insert(i, aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
+ }
+ while (aNewNodes.size()) {
+ i = myChildren.size();
+ if (aNewNodes.contains(i)) {
+ myChildren.append(aNewNodes[i]);
+ aNewNodes.remove(i);
+ }
}
}
- while (aNewNodes.size()) {
- i = myChildren.size();
- myChildren.append(aNewNodes[i]);
- aNewNodes.remove(i);
- }
-
// Update sub-folders
foreach(ModuleBase_ITreeNode* aNode, myChildren) {
aResult.append(aNode->objectCreated(theObjects));
if (aFeature->getKind() == PartSetPlugin_Part::ID())
return new PartSet_PartRootNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ PartSet_ObjectNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
//////////////////////////////////////////////////////////////////////////////////
bool aHasFields = myFieldsFolder->childrenCount() > 0;
bool aHasGroups = myGroupsFolder->childrenCount() > 0;
- if (aHasFields && (!myChildren.contains(myFieldsFolder))) {
- myChildren.insert(3, myFieldsFolder);
+ if (aHasFields) {
+ if (!myChildren.contains(myFieldsFolder)) {
+ myChildren.insert(3, myFieldsFolder);
+ }
+ } else if (myChildren.contains(myFieldsFolder)) {
+ myChildren.removeAll(myFieldsFolder);
}
- if (aHasGroups && (!myChildren.contains(myGroupsFolder))) {
- myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
+ if (aHasGroups) {
+ if (!myChildren.contains(myGroupsFolder)) {
+ myChildren.insert(aHasFields ? 4 : 3, myGroupsFolder);
+ }
+ } else if (myChildren.contains(myGroupsFolder)) {
+ myChildren.removeAll(myGroupsFolder);
}
// Update features content
// Remove extra sub-nodes
int aIndex = -1;
int aId = aRows;
+ QMap<int, ModuleBase_ITreeNode*> aExistingNodes;
while (aId < myChildren.size()) {
ModuleBase_ITreeNode* aNode = myChildren.at(aId);
if (aNode->object().get()) {
aIndex = aDoc->index(aNode->object(), true);
if ((aIndex == -1) || (aId != (aIndex + aRows))) {
myChildren.removeAll(aNode);
- delete aNode;
+ if (aIndex == -1)
+ delete aNode;
+ else
+ aExistingNodes[aIndex + aRows] = aNode;
continue;
}
}
aId = i + aRows; // Take into account existing folders
if (aId < myChildren.size()) {
if (myChildren.at(aId)->object() != aObj) {
- ModuleBase_ITreeNode* aNode = createNode(aObj);
- myChildren.insert(aId, aNode);
+ if (aExistingNodes.contains(aId)) {
+ myChildren.insert(aId, aExistingNodes[aId]);
+ aExistingNodes.remove(aId);
+ }
+ else {
+ myChildren.insert(aId, createNode(aObj));
+ }
}
} else {
- ModuleBase_ITreeNode* aNode = createNode(aObj);
- myChildren.append(aNode);
+ if (aExistingNodes.contains(myChildren.size()))
+ myChildren.append(aExistingNodes[myChildren.size()]);
+ else
+ myChildren.append(createNode(aObj));
}
}
// Update sub-folders
{
if (theObj->groupName() == ModelAPI_Folder::group())
return new PartSet_ObjectFolderNode(theObj, this);
- return new PartSet_ObjectNode(theObj, this);
+ PartSet_ObjectNode* aNode = new PartSet_ObjectNode(theObj, this);
+ aNode->update();
+ return aNode;
}
int PartSet_PartRootNode::numberOfFolders() const
if (aObj != myChildren.at(i)->object()) {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.insert(i, aNode);
+ aNode->update();
}
}
else {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.append(aNode);
+ aNode->update();
}
}
}
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.insert(i, aNode);
aResult.append(aNode);
+ aNode->update();
}
} else {
aNode = new PartSet_ObjectNode(aObj, this);
myChildren.append(aNode);
aResult.append(aNode);
+ aNode->update();
}
}
return aResult;
}
else {
myChildren.removeAll(aNode);
+ aResult.removeAll(aNode);
delete aNode;
aRemoved = true;
continue;