]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Store/restore filters state
authorvsv <vsv@opencascade.com>
Fri, 7 Jun 2019 14:45:30 +0000 (17:45 +0300)
committervsv <vsv@opencascade.com>
Fri, 7 Jun 2019 14:45:30 +0000 (17:45 +0300)
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.h

index 819634fe5216acc85d7b2fa736a264ed56a7b2db..5c304db25f06e91d437020d30bee03cc958da748 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "ModelAPI_AttributeSelection.h"
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Filter.h>
 
 class GeomAPI_Pnt;
 class GeomAPI_Shape;
@@ -114,9 +115,15 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelectionList();
 
- protected:
+  MODELAPI_EXPORT FiltersFeaturePtr filters() const { return myFilters; }
+  MODELAPI_EXPORT void setFilters(FiltersFeaturePtr theFeature) { myFilters = theFeature; }
+
+protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_AttributeSelectionList();
+
+protected:
+  FiltersFeaturePtr myFilters;
 };
 
 //! Pointer on double attribute
index 05546bf54f1bc4efa251bc067021876bfae42f19..44079aea40e1af052f6cfdf2518495b333b6f3ed 100644 (file)
@@ -130,6 +130,11 @@ void ModuleBase_FilterStarter::onFiltersLaunch()
   // Launch Filters operation
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
     (myWorkshop->module()->createOperation(myFeatureName));
+
+  AttributeSelectionListPtr aAttrList = SelectorFeature->selectionList(AttributeId);
+  FiltersFeaturePtr aFilters = aAttrList->filters();
+  if (aFilters.get())
+    aFOperation->setFeature(aFilters);
   myWorkshop->processLaunchOperation(aFOperation);
 }
 
@@ -238,11 +243,9 @@ ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theP
   mySelectorAttribute(AttributeId)
 {
   // Clear Old selection
-  AttributePtr aAttr = SelectorFeature->attribute(AttributeId);
-  AttributeSelectionListPtr aSelListAttr =
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
-  mySelectionType = selectionType(aSelListAttr->selectionType().c_str());
-  aSelListAttr->clear();
+  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+  mySelectionType = selectionType(aAttrList->selectionType().c_str());
+  aAttrList->clear();
 
   // Define widgets
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
@@ -344,28 +347,39 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
   for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) {
     if (i == (theIndex - 1)) {
       aFilter = (*aIt);
-      myFilters.erase(aIt);
       break;
     }
   }
-  if (!aFilter.empty()) {
-    myUseFilters.push_back(aFilter);
-    ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(aFilter, this);
-    connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
-      SLOT(onDeleteItem(ModuleBase_FilterItem*)));
-    connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
-      SLOT(onReverseItem(ModuleBase_FilterItem*)));
-    myFiltersLayout->addWidget(aItem);
-
-    FiltersFeaturePtr aFiltersFeature =
-      std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
-    aFiltersFeature->addFilter(aFilter);
+  onAddFilter(aFilter);
+  FiltersFeaturePtr aFiltersFeature =
+    std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+  aFiltersFeature->addFilter(aFilter);
+
+  myFiltersCombo->setCurrentIndex(0);
+  myFiltersCombo->removeItem(theIndex);
+}
+
+void ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
+{
+  if (theFilter.length() == 0)
+    return;
+  std::list<std::string>::const_iterator aIt;
+  for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) {
+    if (theFilter == (*aIt))
+      return;
   }
+  myFilters.remove(theFilter);
+  myUseFilters.push_back(theFilter);
+  ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
+  connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
+    SLOT(onDeleteItem(ModuleBase_FilterItem*)));
+  connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
+    SLOT(onReverseItem(ModuleBase_FilterItem*)));
+  myFiltersLayout->addWidget(aItem);
+
   updateSelectBtn();
   clearCurrentSelection(true);
   updateNumberSelected();
-  myFiltersCombo->setCurrentIndex(0);
-  myFiltersCombo->removeItem(theIndex);
 }
 
 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
@@ -554,13 +568,38 @@ void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
 
 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
 {
+  ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
+  if (aActive)
+    return aActive->storeValue();
   return true;
 }
 
 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
 {
+  FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+  std::list<std::string> aFilters = aFiltersFeature->filters();
+  std::list<std::string>::const_iterator aIt;
+  for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
+    std::string aStr = (*aIt);
+    onAddFilter(aStr);
+    myFiltersCombo->removeItem(myFiltersCombo->findText(aStr.c_str()));
+  }
+  // Init filters member of the parent attribute
+  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+  if (aAttrList->filters() != aFiltersFeature) {
+    aAttrList->setFilters(aFiltersFeature);
+  }
+
   ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
   if (aActive)
     return aActive->restoreValue();
+  QList<QWidget*> aWidgets;
+  QList<ModuleBase_FilterItem*> aItems = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
+  foreach(ModuleBase_FilterItem* aItem, aItems) {
+    QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
+    foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
+      aWgt->restoreValue();
+    }
+  }
   return true;
 }
index 10c039faa16dc849904db302d8872a9a51332cb3..d2535d662158f99224413765b5976f4990b4f2b5 100644 (file)
@@ -130,6 +130,7 @@ protected:
 
 private slots:
   void onAddFilter(int);
+  void onAddFilter(const std::string& theFilter);
   void onDeleteItem(ModuleBase_FilterItem* theItem);
   void onReverseItem(ModuleBase_FilterItem* theItem);
   void onSelect();