From 04870cb81f8b0574fba4e57af3636a68fdf2bbf6 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 31 Jul 2018 17:11:05 +0300 Subject: [PATCH] Initial implementation of support of any level of hierarchy in Result Bodies. Removed ResultCompSolid class. Instead ResultBody may have any number of subs, or not. --- src/GeomAPI/GeomAPI_Interface.cpp | 36 ---- src/Model/Model_AttributeSelection.cpp | 1 - src/PartSet/PartSet_TreeNodes.cpp | 251 ++++++++----------------- src/XGUI/XGUI_SelectionMgr.cpp | 10 +- 4 files changed, 85 insertions(+), 213 deletions(-) delete mode 100644 src/GeomAPI/GeomAPI_Interface.cpp diff --git a/src/GeomAPI/GeomAPI_Interface.cpp b/src/GeomAPI/GeomAPI_Interface.cpp deleted file mode 100644 index 025a4d4f9..000000000 --- a/src/GeomAPI/GeomAPI_Interface.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2014-2017 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 -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// 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 -// -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com -// - -#include - -GeomAPI_Interface::GeomAPI_Interface() -{ - -} - -GeomAPI_Interface::~GeomAPI_Interface() -{ - -} - -bool GeomAPI_Interface::empty() const -{ - return myImpl.get() == 0; -} diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index fa8e7e490..a57ba24b3 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -414,7 +414,6 @@ void Model_AttributeSelection::setID(const std::string theID) } ResultPtr Model_AttributeSelection::context() -{ if (!ModelAPI_AttributeSelection::isInitialized() && !myTmpContext.get() && !myTmpSubShape.get()) return ResultPtr(); diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 5e642c691..6219084db 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -161,13 +161,8 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const if (aCompRes.get()) { VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ? (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState; - std::list aResultsList; - ModelAPI_Tools::allSubs(aCompRes, aResultsList); - - std::list::const_iterator aIt; - //for (int i = 0; i < aCompRes->numberOfSubs(true); i++) { - for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) { - ResultPtr aSubRes = (*aIt); // aCompRes->subResult(i, true); + for (int i = 0; i < aCompRes->numberOfSubs(true); i++) { + ResultPtr aSubRes = aCompRes->subResult(i, true); VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden; if (aState == NoneState) aState = aS; @@ -187,93 +182,7 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const return NoneState; } -void PartSet_ObjectNode::update() -{ - ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); - if (aCompRes.get()) { - int aNb = aCompRes->numberOfSubs(true); - ModuleBase_ITreeNode* aNode; - ResultBodyPtr aBody; - int i; - for (i = 0; i < aNb; i++) { - aBody = aCompRes->subResult(i, true); - if (i < myChildren.size()) { - aNode = myChildren.at(i); - if (aNode->object() != aBody) { - ((PartSet_ObjectNode*)aNode)->setObject(aBody); - } - } else { - aNode = new PartSet_ObjectNode(aBody, this); - myChildren.append(aNode); - } - } - // Delete extra objects - while (myChildren.size() > aNb) { - aNode = myChildren.takeLast(); - delete aNode; - } - foreach(ModuleBase_ITreeNode* aNode, myChildren) { - aNode->update(); - } - } -} - -QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects) -{ - QTreeNodesList aResult; - - ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); - if (aCompRes.get()) { - int aNb = aCompRes->numberOfSubs(true); - ModuleBase_ITreeNode* aNode; - ResultBodyPtr aBody; - int i; - for (i = 0; i < aNb; i++) { - aBody = aCompRes->subResult(i, true); - if (i < myChildren.size()) { - aNode = myChildren.at(i); - if (aNode->object() != aBody) { - ((PartSet_ObjectNode*)aNode)->setObject(aBody); - aResult.append(aNode); - } - } else { - aNode = new PartSet_ObjectNode(aBody, this); - myChildren.append(aNode); - aResult.append(aNode); - } - } - foreach(ModuleBase_ITreeNode* aNode, myChildren) { - aResult.append(aNode->objectCreated(theObjects)); - } - } - return aResult; -} -QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup) -{ - QTreeNodesList aResult; - ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); - if (aCompRes.get()) { - int aNb = aCompRes->numberOfSubs(true); - ModuleBase_ITreeNode* aNode; - // Delete extra objects - bool isDeleted = false; - while (myChildren.size() > aNb) { - aNode = myChildren.takeLast(); - delete aNode; - isDeleted = true; - } - if (isDeleted) - aResult.append(this); - int i = 0; - foreach(ModuleBase_ITreeNode* aNode, myChildren) { - ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true)); - aResult.append(aNode->objectsDeleted(theDoc, theGroup)); - i++; - } - } - return aResult; -} ////////////////////////////////////////////////////////////////////////////////// PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent, FolderType theType) @@ -343,9 +252,9 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj) { - //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(theObj); - //if (aCompRes.get()) - // return new PartSet_CompsolidNode(theObj, this); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(theObj); + if (aCompRes.get()) + return new PartSet_CompsolidNode(theObj, this); return new PartSet_ObjectNode(theObj, this); } @@ -1013,78 +922,78 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast) ////////////////////////////////////////////////////////////////////////////////// -//PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj, -// ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent) -//{ -// update(); -//} - -//void PartSet_CompsolidNode::update() -//{ -// ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); -// int aNb = aCompRes->numberOfSubs(true); -// ModuleBase_ITreeNode* aNode; -// ResultBodyPtr aBody; -// int i; -// for (i = 0; i < aNb; i++) { -// aBody = aCompRes->subResult(i, true); -// if (i < myChildren.size()) { -// aNode = myChildren.at(i); -// if (aNode->object() != aBody) { -// ((PartSet_ObjectNode*)aNode)->setObject(aBody); -// } -// } else { -// aNode = new PartSet_ObjectNode(aBody, this); -// myChildren.append(aNode); -// } -// } -// // Delete extra objects -// while (myChildren.size() > aNb) { -// aNode = myChildren.takeLast(); -// delete aNode; -// } -//} -// -//QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects) -//{ -// QTreeNodesList aResult; -// -// ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); -// int aNb = aCompRes->numberOfSubs(true); -// ModuleBase_ITreeNode* aNode; -// ResultBodyPtr aBody; -// int i; -// for (i = 0; i < aNb; i++) { -// aBody = aCompRes->subResult(i, true); -// if (i < myChildren.size()) { -// aNode = myChildren.at(i); -// if (aNode->object() != aBody) { -// ((PartSet_ObjectNode*)aNode)->setObject(aBody); -// aResult.append(aNode); -// } -// } else { -// aNode = new PartSet_ObjectNode(aBody, this); -// myChildren.append(aNode); -// aResult.append(aNode); -// } -// } -// return aResult; -//} -// -//QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup) -//{ -// QTreeNodesList aResult; -// ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(myObject); -// int aNb = aCompRes->numberOfSubs(true); -// ModuleBase_ITreeNode* aNode; -// // Delete extra objects -// bool isDeleted = false; -// while (myChildren.size() > aNb) { -// aNode = myChildren.takeLast(); -// delete aNode; -// isDeleted = true; -// } -// if (isDeleted) -// aResult.append(this); -// return aResult; -//} \ No newline at end of file +PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj, + ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent) +{ + update(); +} + +void PartSet_CompsolidNode::update() +{ + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + ResultBodyPtr aBody; + int i; + for (i = 0; i < aNb; i++) { + aBody = aCompRes->subResult(i, true); + if (i < myChildren.size()) { + aNode = myChildren.at(i); + if (aNode->object() != aBody) { + ((PartSet_ObjectNode*)aNode)->setObject(aBody); + } + } else { + aNode = new PartSet_ObjectNode(aBody, this); + myChildren.append(aNode); + } + } + // Delete extra objects + while (myChildren.size() > aNb) { + aNode = myChildren.takeLast(); + delete aNode; + } +} + +QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects) +{ + QTreeNodesList aResult; + + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + ResultBodyPtr aBody; + int i; + for (i = 0; i < aNb; i++) { + aBody = aCompRes->subResult(i, true); + if (i < myChildren.size()) { + aNode = myChildren.at(i); + if (aNode->object() != aBody) { + ((PartSet_ObjectNode*)aNode)->setObject(aBody); + aResult.append(aNode); + } + } else { + aNode = new PartSet_ObjectNode(aBody, this); + myChildren.append(aNode); + aResult.append(aNode); + } + } + return aResult; +} + +QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup) +{ + QTreeNodesList aResult; + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); + int aNb = aCompRes->numberOfSubs(true); + ModuleBase_ITreeNode* aNode; + // Delete extra objects + bool isDeleted = false; + while (myChildren.size() > aNb) { + aNode = myChildren.takeLast(); + delete aNode; + isDeleted = true; + } + if (isDeleted) + aResult.append(this); + return aResult; +} \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index db0987efa..5c42eb189 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -111,11 +111,11 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() if (aObject.get()) { aFeature = std::dynamic_pointer_cast(aObject); if (aFeature.get()) { - std::list allRes; - ModelAPI_Tools::allResults(aFeature, allRes); - for (std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { - aTmpList.append(std::shared_ptr( - new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL))); + std::list allRes; + ModelAPI_Tools::allResults(aFeature, allRes); + for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + aSelectedPrs.append(std::shared_ptr( + new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL))); } } } -- 2.39.2