From f0c48976f5082a5377f3b224fd83c18f40f4cf52 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 12 Nov 2018 11:58:01 +0300 Subject: [PATCH] Implement launch/close filters operation --- .../CollectionPlugin_GroupFilters.h | 54 +++++++++++++++ .../CollectionPlugin_Plugin.cpp | 5 +- src/CollectionPlugin/group_widget.xml | 2 +- src/CollectionPlugin/plugin-Collection.xml | 7 ++ src/Config/Config_Keywords.h | 1 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 + .../ModuleBase_WidgetMultiSelector.cpp | 6 +- .../ModuleBase_WidgetSelectionFilter.cpp | 65 +++++++++++++++++-- .../ModuleBase_WidgetSelectionFilter.h | 42 +++++++++++- src/XGUI/XGUI_PropertyPanel.cpp | 18 +++-- src/XGUI/XGUI_PropertyPanel.h | 2 + src/XGUI/XGUI_Workshop.cpp | 6 ++ 12 files changed, 195 insertions(+), 16 deletions(-) create mode 100644 src/CollectionPlugin/CollectionPlugin_GroupFilters.h diff --git a/src/CollectionPlugin/CollectionPlugin_GroupFilters.h b/src/CollectionPlugin/CollectionPlugin_GroupFilters.h new file mode 100644 index 000000000..a7ec756ee --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_GroupFilters.h @@ -0,0 +1,54 @@ +// 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 +// + +#ifndef COLLECTIONPLUGIN_GROUPFILTERS_H_ +#define COLLECTIONPLUGIN_GROUPFILTERS_H_ + +#include "CollectionPlugin.h" +#include + +class CollectionPlugin_GroupFilters : public ModelAPI_Feature +{ +public: + /// Extrusion kind + inline static const std::string& ID() + { + static const std::string MY_GROUP_ID("GroupFilters"); + return MY_GROUP_ID; + } + + /// Returns the kind of a feature + COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = CollectionPlugin_GroupFilters::ID(); + return MY_KIND; + } + + /// Creates a new group result if needed + COLLECTIONPLUGIN_EXPORT virtual void execute() {} + + /// Request for initialization of data model of the object: adding all attributes + virtual void initAttributes() {} + + /// Use plugin manager for features creation + CollectionPlugin_GroupFilters() {} +}; + +#endif \ No newline at end of file diff --git a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp index 9ef0bd736..f639d79c1 100644 --- a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -55,8 +56,10 @@ FeaturePtr CollectionPlugin_Plugin::createFeature(std::string theFeatureID) { if (theFeatureID == CollectionPlugin_Group::ID()) { return FeaturePtr(new CollectionPlugin_Group); - }else if (theFeatureID == CollectionPlugin_Field::ID()) { + } else if (theFeatureID == CollectionPlugin_Field::ID()) { return FeaturePtr(new CollectionPlugin_Field); + } else if (theFeatureID == CollectionPlugin_GroupFilters::ID()) { + return FeaturePtr(new CollectionPlugin_GroupFilters); } diff --git a/src/CollectionPlugin/group_widget.xml b/src/CollectionPlugin/group_widget.xml index 7f1f874cd..affd3562b 100644 --- a/src/CollectionPlugin/group_widget.xml +++ b/src/CollectionPlugin/group_widget.xml @@ -28,7 +28,7 @@ email : webmaster.salome@opencascade.com diff --git a/src/CollectionPlugin/plugin-Collection.xml b/src/CollectionPlugin/plugin-Collection.xml index 4adfdf218..cd6ab3914 100644 --- a/src/CollectionPlugin/plugin-Collection.xml +++ b/src/CollectionPlugin/plugin-Collection.xml @@ -42,6 +42,13 @@ email : webmaster.salome@opencascade.com + + + + + diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index beb599b20..dc7f04b37 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -53,6 +53,7 @@ const static char* WDG_EXPR_EDITOR = "expr_editor"; const static char* WDG_PLACE_HOLDER = "placeholder"; const static char* WDG_ACTION = "action"; const static char* WDG_POINT_INPUT = "point_input"; +const static char* WDG_SELECTION_FILTERS = "selection_filters"; // Containers const static char* WDG_GROUP = "groupbox"; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index af75ebd12..293482260 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -345,6 +346,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: result = new ModuleBase_WidgetAction(theParent, myWidgetApi); } else if (theType == WDG_POINT_INPUT) { result = new ModuleBase_WidgetPointInput(theParent, myWorkshop, myWidgetApi); + } else if (theType == WDG_SELECTION_FILTERS) { + result = new ModuleBase_WidgetSelectionFilter(theParent, myWorkshop, myWidgetApi); } else { result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi); if (!result) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 548342f58..450ce3466 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -157,9 +157,9 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen } } } - bool aUseFilters = theData->getBooleanAttribute("use_filters", false); - if (aUseFilters) { - myFiltersWgt = new ModuleBase_FilterStarter(this, theWorkshop); + std::string aUseFilters = theData->getProperty("use_filters"); + if (aUseFilters.length() > 0) { + myFiltersWgt = new ModuleBase_FilterStarter(aUseFilters.c_str(), this, theWorkshop); aMainLay->addWidget(myFiltersWgt); } diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 3120487ab..4e777a337 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -21,15 +21,21 @@ #include "ModuleBase_WidgetSelectionFilter.h" #include "ModuleBase_Tools.h" #include "ModuleBase_IWorkshop.h" +#include "ModuleBase_IModule.h" +#include "ModuleBase_IPropertyPanel.h" +#include "ModuleBase_PageWidget.h" #include #include #include -#include +#include +#include +#include -ModuleBase_FilterStarter::ModuleBase_FilterStarter(QWidget* theParent, - ModuleBase_IWorkshop* theWorkshop) +ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature, + QWidget* theParent, ModuleBase_IWorkshop* theWorkshop) : QWidget(theParent), + myFeatureName(theFeature), myWorkshop(theWorkshop) { QHBoxLayout* aMainLayout = new QHBoxLayout(this); @@ -55,5 +61,56 @@ ModuleBase_FilterStarter::ModuleBase_FilterStarter(QWidget* theParent, void ModuleBase_FilterStarter::onFiltersLaunch() { + // ModuleBase_OperationFiltering* aOperation = new ModuleBase_OperationFiltering(myWorkshop, this); + // myWorkshop->processLaunchOperation(aOperation); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (myWorkshop->module()->createOperation(myFeatureName)); + myWorkshop->processLaunchOperation(aFOperation); +} + + + +//***************************************************************************** +//***************************************************************************** +//***************************************************************************** +ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) + : ModuleBase_ModelWidget(theParent, theData), + myWorkshop(theWorkshop) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout(this); + ModuleBase_Tools::adjustMargins(aMainLayout); + + myFiltersGroup = new QGroupBox(tr("Dynamic Filters"), this); + QVBoxLayout* aGroupLayout = new QVBoxLayout(myFiltersGroup); + + QWidget* aFiltersWgt = new QWidget(myFiltersGroup); + QHBoxLayout* aFiltersLay = new QHBoxLayout(aFiltersWgt); + + QLabel* aFilterLbl = new QLabel(aFiltersWgt); + aFilterLbl->setPixmap(QPixmap(":pictures/filter.png")); + + myFiltersCombo = new QComboBox(aFiltersWgt); + + QPushButton* aAddBtn = new QPushButton(tr("Add"), aFiltersWgt); + connect(aAddBtn, SIGNAL(clicked()), SLOT(onAddFilter())); -} \ No newline at end of file + aFiltersLay->addWidget(aFilterLbl); + aFiltersLay->addWidget(myFiltersCombo); + aFiltersLay->addWidget(aAddBtn); + + aGroupLayout->addWidget(aFiltersWgt); + + aMainLayout->addWidget(myFiltersGroup); + aMainLayout->addStretch(1); +} + +void ModuleBase_WidgetSelectionFilter::onAddFilter() +{ + +} + +QList ModuleBase_WidgetSelectionFilter::getControls() const +{ + return QList(); +} diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 24a01ee3a..6be5cc0be 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -21,17 +21,22 @@ #ifndef ModuleBase_WidgetSelectionFilter_H #define ModuleBase_WidgetSelectionFilter_H -#include +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + #include class QLabel; +class QComboBox; +class QGroupBox; class ModuleBase_IWorkshop; class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget { Q_OBJECT public: - ModuleBase_FilterStarter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop); + ModuleBase_FilterStarter(const std::string& theFeature, QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop); ~ModuleBase_FilterStarter() {} @@ -39,11 +44,42 @@ private slots: void onFiltersLaunch(); private: + std::string myFeatureName; + ModuleBase_IWorkshop* myWorkshop; + QLabel* myFilterLbl; QLabel* myModifyLbl; - ModuleBase_IWorkshop* myWorkshop; }; +class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + +protected: + /// Saves the internal parameters to the given feature (not ussed for this widget) + /// \return True in success + virtual bool storeValueCustom() { return true; } + + /// Restore value from attribute data to the widget's control (not ussed for this widget) + virtual bool restoreValueCustom() { return true; } + +private slots: + void onAddFilter(); + +private: + ModuleBase_IWorkshop* myWorkshop; + + QComboBox* myFiltersCombo; + QGroupBox* myFiltersGroup; +}; + #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 3ce0ed171..b93da6e5d 100755 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -226,10 +226,20 @@ void XGUI_PropertyPanel::createContentPanel(FeaturePtr theFeature) /// Apply button should be update if the feature was modified by the panel myOperationMgr->onValidateOperation(); } - std::shared_ptr aFeatureInfo = - myOperationMgr->workshop()->featureInfo(theFeature->getKind().c_str()); - if (aFeatureInfo.get()) - findButton(PROP_PANEL_OK_PLUS)->setVisible(aFeatureInfo->isApplyContinue()); + updateApplyPlusButton(theFeature); +} + +void XGUI_PropertyPanel::updateApplyPlusButton(FeaturePtr theFeature) +{ + if (theFeature.get()) { + std::shared_ptr aFeatureInfo = + myOperationMgr->workshop()->featureInfo(theFeature->getKind().c_str()); + if (aFeatureInfo.get()) { + findButton(PROP_PANEL_OK_PLUS)->setVisible(aFeatureInfo->isApplyContinue()); + return; + } + } + findButton(PROP_PANEL_OK_PLUS)->setVisible(false); } ModuleBase_ModelWidget* XGUI_PropertyPanel::activeWidget(const bool isUseCustomWidget) const diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 62b87e9be..053b71062 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -145,6 +145,8 @@ Q_OBJECT /// \param theWidget a widget control to store as internal active widget void setInternalActiveWidget(ModuleBase_ModelWidget* theWidget); + void updateApplyPlusButton(FeaturePtr theFeature); + public slots: /// \brief Update all widgets in property panel with values from the given feature /// \param theFeature a Feature to update values in widgets diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 2e135c8d9..e13ddacc7 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -781,6 +781,12 @@ void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation) if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel fillPropertyPanel(theOperation); connectToPropertyPanel(true); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (theOperation); + if (aFOperation) + myPropertyPanel->updateApplyPlusButton(aFOperation->feature()); + else + myPropertyPanel->updateApplyPlusButton(FeaturePtr()); } updateCommandStatus(); -- 2.39.2