Salome HOME
Get rid of compilation warnings. Part I.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetConcealedObjects.cpp
index 660d69f3fedd78aa73281ba01e28cd51474d3723..425e60ae6a11f29078708577d6dc05be78cb2f01 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  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 <ModuleBase_WidgetConcealedObjects.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Session.h>
@@ -38,6 +38,8 @@
 #include <QCheckBox>
 #include <QVBoxLayout>
 
+#include <algorithm>
+
 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
 
 ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
@@ -45,6 +47,10 @@ ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* th
 : ModuleBase_ModelWidget(theParent, theData)
 {
   myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
+  std::string aPickParents = theData->getProperty("pick_concealed_parents");
+  std::transform(aPickParents.begin(), aPickParents.end(), aPickParents.begin(), ::tolower);
+  myPickConcealedParents = aPickParents == "1" || aPickParents == "true" || aPickParents == "yes";
+
   QGridLayout* aMainLay = new QGridLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
 
@@ -67,14 +73,12 @@ bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
   DataPtr aData = myFeature->data();
   AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
   anAttributeList->clear();
-  int aSize1 = anAttributeList->size(false);
   for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
     QCheckBox* aButton =
         dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
     if (aButton->isChecked())
       anAttributeList->append(myConcealedResults[i]);
   }
-  int aSize = anAttributeList->size(false);
   return true;
 }
 
@@ -93,11 +97,24 @@ bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
     myBaseFeature = aBaseFeature;
     if (myBaseFeature.get()) {
       std::list<std::shared_ptr<ModelAPI_Result> > aResults;
+      std::set<ResultBodyPtr> aParents;
       ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
       std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
                                                                    aLast = aResults.end();
       for (; anIt != aLast; anIt++) {
         ResultPtr aResult = *anIt;
+        if (myPickConcealedParents) {
+          // pick the parent result of the concealed object
+          ResultBodyPtr aRootParent = ModelAPI_Tools::bodyOwner(aResult, true);
+          if (aRootParent) {
+            if (aParents.find(aRootParent) == aParents.end()) {
+              aResult = aRootParent;
+              aParents.insert(aRootParent);
+            }
+            else // do not add parent compound once again
+              continue;
+          }
+        }
 
         int aRowId = myView->rowCount();
         addViewRow(aResult);
@@ -108,7 +125,6 @@ bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
 
   DataPtr aData = myFeature->data();
   AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
-  int aSize = anAttributeList->size();
   for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
     ResultPtr aResult = myConcealedResults[i];
     QCheckBox* aButton =