From: vsv Date: Fri, 8 Dec 2017 10:57:33 +0000 (+0300) Subject: Issue #2353: Correct misprint and provide undo/redo by selection in Undo/Redo list X-Git-Tag: V_2.10.0RC~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f475d232b555ee699df9c314eff2a870b0ab8404;p=modules%2Fshaper.git Issue #2353: Correct misprint and provide undo/redo by selection in Undo/Redo list --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index b1b612da8..585bcb4e6 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -96,6 +96,8 @@ SET(PROJECT_HEADERS ModuleBase_IconFactory.h ModuleBase_Dialog.h ModuleBase_ModelDialogWidget.h + ModuleBase_ActionParameter.h + ModuleBase_ActionIntParameter.h ) SET(PROJECT_MOC_HEADERS diff --git a/src/ModuleBase/ModuleBase_ActionIntParameter.h b/src/ModuleBase/ModuleBase_ActionIntParameter.h new file mode 100644 index 000000000..a49b90966 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ActionIntParameter.h @@ -0,0 +1,39 @@ +// 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 ModuleBase_ActionIntParameter_H_ +#define ModuleBase_ActionIntParameter_H_ + +#include "ModuleBase_ActionParameter.h" + +class ModuleBase_ActionIntParameter : public ModuleBase_ActionParameter +{ +public: + ModuleBase_ActionIntParameter(int theVal):ModuleBase_ActionParameter(), myVal(theVal) {} + + int value() const { return myVal; } + +private: + int myVal; +}; + +typedef std::shared_ptr ActionIntParamPtr; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_ActionParameter.h b/src/ModuleBase/ModuleBase_ActionParameter.h new file mode 100644 index 000000000..d24e6e126 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ActionParameter.h @@ -0,0 +1,35 @@ +// 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 ModuleBase_ActionParameter_H_ +#define ModuleBase_ActionParameter_H_ + +#include + +class ModuleBase_ActionParameter +{ +public: + /// Destuctor is added in order to virtualize the class + virtual ~ModuleBase_ActionParameter() {} +}; + +typedef std::shared_ptr ActionParamPtr; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_ActionType.h b/src/ModuleBase/ModuleBase_ActionType.h index 7228e98ea..5a12e0efd 100644 --- a/src/ModuleBase/ModuleBase_ActionType.h +++ b/src/ModuleBase/ModuleBase_ActionType.h @@ -21,12 +21,10 @@ #ifndef ModuleBase_ActionType_H_ #define ModuleBase_ActionType_H_ -#include - /*! * Structure to describe widget processed types of actions. */ -enum MODULEBASE_EXPORT ModuleBase_ActionType +enum ModuleBase_ActionType { ActionEnter, ActionEscape, diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index ff4f88a9d..54a2511cb 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -421,7 +421,8 @@ bool ModuleBase_ModelWidget::canProcessAction(ModuleBase_ActionType theActionTyp } } -bool ModuleBase_ModelWidget::processAction(ModuleBase_ActionType theActionType) +bool ModuleBase_ModelWidget::processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam) { switch (theActionType) { case ActionEnter: diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 18a201a39..c6a475889 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -251,7 +252,8 @@ Q_OBJECT virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled); /// Returns true if the event is processed. The default implementation is empty, returns false. - virtual bool processAction(ModuleBase_ActionType theActionType); + virtual bool processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam = ActionParamPtr()); /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list. /// \param theActionType type of action. It can be ActionUndo or ActionRedo. diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 3b3cfc82d..b04e20983 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -368,12 +368,12 @@ bool ModuleBase_OperationFeature::commit() afterCommitOperation(); #ifdef DEBUG_OPERATION_START - qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit"); + qDebug("ModuleBase_OperationFeature::commit -- end"); #endif return true; } #ifdef DEBUG_OPERATION_START - qDebug("ModuleBase_OperationFeature::commit -- end"); + qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit"); #endif return false; } diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp index a378b0a04..88e482ada 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp @@ -118,12 +118,13 @@ void ModuleBase_WidgetFeatureSelector::deactivate() } //******************************************************************** -bool ModuleBase_WidgetFeatureSelector::processAction(ModuleBase_ActionType theActionType) +bool ModuleBase_WidgetFeatureSelector::processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam) { if (theActionType == ActionSelection) onSelectionChanged(); else - return ModuleBase_WidgetValidated::processAction(theActionType); + return ModuleBase_WidgetValidated::processAction(theActionType, theParam); return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.h b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.h index dc47862a9..39014f247 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.h @@ -80,7 +80,8 @@ Q_OBJECT virtual void deactivate(); /// Processes Selection action. - virtual bool processAction(ModuleBase_ActionType theActionType); + virtual bool processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam = ActionParamPtr()); protected: /// The method called when widget is activated diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index d532cf153..56565ef55 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -296,15 +297,19 @@ bool ModuleBase_WidgetMultiSelector::canProcessAction(ModuleBase_ActionType theA } //******************************************************************** -bool ModuleBase_WidgetMultiSelector::processAction(ModuleBase_ActionType theActionType) +bool ModuleBase_WidgetMultiSelector::processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam) { switch (theActionType) { case ActionUndo: case ActionRedo: { + ActionIntParamPtr aParam = + std::dynamic_pointer_cast(theParam); + int aNb = aParam->value(); if (theActionType == ActionUndo) - myCurrentHistoryIndex--; + myCurrentHistoryIndex -= aNb; else - myCurrentHistoryIndex++; + myCurrentHistoryIndex += aNb; QList aSelected = mySelectedHistoryValues[myCurrentHistoryIndex]; // equal vertices should not be used here ModuleBase_ISelection::filterSelectionOnEqualPoints(aSelected); @@ -320,7 +325,7 @@ bool ModuleBase_WidgetMultiSelector::processAction(ModuleBase_ActionType theActi return true; } default: - return ModuleBase_ModelWidget::processAction(theActionType); + return ModuleBase_ModelWidget::processAction(theActionType, theParam); } } @@ -890,21 +895,35 @@ QList if (myCurrentHistoryIndex > -1) { int i = 0; QString aTitle("Selection %1 items"); + QString aTit("Selection %1 item"); QIcon aIcon(":pictures/selection.png"); + int aNb; switch (theActionType) { case ActionUndo: i = 1; while (i <= myCurrentHistoryIndex) { - ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count())); - aList.append(aInfo); + aNb = mySelectedHistoryValues.at(i).count(); + if (aNb == 1) { + ActionInfo aInfo(aIcon, aTit.arg(aNb)); + aList.insert(0, aInfo); + } else { + ActionInfo aInfo(aIcon, aTitle.arg(aNb)); + aList.insert(0, aInfo); + } i++; } break; case ActionRedo: i = mySelectedHistoryValues.length() - 1; while (i > myCurrentHistoryIndex) { - ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count())); - aList.append(aInfo); + aNb = mySelectedHistoryValues.at(i).count(); + if (aNb == 1) { + ActionInfo aInfo(aIcon, aTit.arg(mySelectedHistoryValues.at(i).count())); + aList.insert(0, aInfo); + } else { + ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count())); + aList.insert(0, aInfo); + } i--; } break; diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 96542e3f2..1faf7fdd9 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -92,7 +92,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled); /// Returns true if the event is processed. The default implementation is empty, returns false. - virtual bool processAction(ModuleBase_ActionType theActionType); + virtual bool processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam = ActionParamPtr()); /// Activate or deactivate selection and selection filters /// \return true if the selection filter of the widget is activated in viewer context diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index bbf6e2b66..d91cb5c26 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -452,12 +452,13 @@ bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& the } //******************************************************************** -bool PartSet_WidgetSketchLabel::processAction(ModuleBase_ActionType theActionType) +bool PartSet_WidgetSketchLabel::processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam) { if (theActionType == ActionSelection) onSelectionChanged(); else - return ModuleBase_WidgetValidated::processAction(theActionType); + return ModuleBase_WidgetValidated::processAction(theActionType, theParam); return true; } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index eb5327061..af0b81f84 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -96,7 +96,8 @@ public: static bool canFillSketch(const std::shared_ptr& thePrs); /// Processes Selection action. - virtual bool processAction(ModuleBase_ActionType theActionType); + virtual bool processAction(ModuleBase_ActionType theActionType, + const ActionParamPtr& theParam); signals: /// Signal on plane selection diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d93b451c6..495ecfc29 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -100,6 +100,7 @@ #include #include #include +#include #include #include @@ -1023,8 +1024,11 @@ bool XGUI_Workshop::onSaveAs() void XGUI_Workshop::onUndo(int theTimes) { ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget(); - if (anActiveWidget && anActiveWidget->processAction(ActionUndo)) - return; + if (anActiveWidget) { + ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes)); + if (anActiveWidget->processAction(ActionUndo, aParam)) + return; + } objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); SessionPtr aMgr = ModelAPI_Session::get(); @@ -1051,8 +1055,11 @@ void XGUI_Workshop::onUndo(int theTimes) void XGUI_Workshop::onRedo(int theTimes) { ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget(); - if (anActiveWidget && anActiveWidget->processAction(ActionRedo)) - return; + if (anActiveWidget) { + ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes)); + if (anActiveWidget->processAction(ActionRedo, aParam)) + return; + } // the viewer update should be blocked in order to avoid the features blinking. For the created // feature a results are created, the flush of the created signal caused the viewer redisplay for