From: vsv Date: Fri, 7 Jun 2019 14:45:30 +0000 (+0300) Subject: Store/restore filters state X-Git-Tag: VEDF2019Lot4~101^2~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=02c42a23aa420e2f81ac425f7b7207507dda95e9;p=modules%2Fshaper.git Store/restore filters state --- diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 819634fe5..5c304db25 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -22,6 +22,7 @@ #include "ModelAPI_AttributeSelection.h" #include +#include 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 diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 05546bf54..44079aea4 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -130,6 +130,11 @@ void ModuleBase_FilterStarter::onFiltersLaunch() // Launch Filters operation ModuleBase_OperationFeature* aFOperation = dynamic_cast (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(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(myFeature); - aFiltersFeature->addFilter(aFilter); + onAddFilter(aFilter); + FiltersFeaturePtr aFiltersFeature = + std::dynamic_pointer_cast(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::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(myFeature); + std::list aFilters = aFiltersFeature->filters(); + std::list::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 aWidgets; + QList aItems = myFiltersWgt->findChildren(); + foreach(ModuleBase_FilterItem* aItem, aItems) { + QList aSubList = aItem->widgets(); + foreach(ModuleBase_ModelWidget* aWgt, aSubList) { + aWgt->restoreValue(); + } + } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 10c039faa..d2535d662 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -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();