Salome HOME
Issue #2353: Correct misprint and provide undo/redo by selection in Undo/Redo list
authorvsv <vsv@opencascade.com>
Fri, 8 Dec 2017 10:57:33 +0000 (13:57 +0300)
committervsv <vsv@opencascade.com>
Fri, 8 Dec 2017 10:57:33 +0000 (13:57 +0300)
14 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ActionIntParameter.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ActionParameter.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ActionType.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp
src/ModuleBase/ModuleBase_WidgetFeatureSelector.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/XGUI/XGUI_Workshop.cpp

index b1b612da8d35dddba374cfcaf523fd19e2e2ef71..585bcb4e6c110cfde2fbfbc849cea0dd1188c78b 100644 (file)
@@ -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 (file)
index 0000000..a49b909
--- /dev/null
@@ -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<mailto: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<ModuleBase_ActionIntParameter> 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 (file)
index 0000000..d24e6e1
--- /dev/null
@@ -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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef ModuleBase_ActionParameter_H_
+#define ModuleBase_ActionParameter_H_
+
+#include <memory>
+
+class ModuleBase_ActionParameter
+{
+public:
+  /// Destuctor is added in order to virtualize the class
+  virtual ~ModuleBase_ActionParameter() {}
+};
+
+typedef std::shared_ptr<ModuleBase_ActionParameter> ActionParamPtr;
+
+#endif
\ No newline at end of file
index 7228e98ea8f9e06297574117d6e484af86796405..5a12e0efd232b2ee738200a0dac93bfa9cbad38c 100644 (file)
 #ifndef ModuleBase_ActionType_H_
 #define ModuleBase_ActionType_H_
 
-#include <ModuleBase.h>
-
 /*!
  * Structure to describe widget processed types of actions.
  */
-enum MODULEBASE_EXPORT ModuleBase_ActionType
+enum ModuleBase_ActionType
 {
   ActionEnter,
   ActionEscape,
index ff4f88a9dc1b875f95a3f3ce23a1505da7afa2b2..54a2511cb368613e33eef4c5d16eb77e842f1957 100644 (file)
@@ -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:
index 18a201a39870749351b2ac003c3bea1f4ee9f210..c6a475889282c57fcc4addc0681c4eb519c2a6d9 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModuleBase_ActionType.h>
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_ActionInfo.h>
+#include <ModuleBase_ActionParameter.h>
 #include <ModelAPI_Feature.h>
 
 #include <QWidget>
@@ -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.
index 3b3cfc82db32ffba4b130efe30a9109ccf1acf43..b04e209830ec3d40ec4d09cf757a6f5b26d21212 100755 (executable)
@@ -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;
 }
index a378b0a04f46cd1d31f05d77cca223745ae1aa5b..88e482ada1f75badab4c0da6b9e7de1afd484447 100644 (file)
@@ -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;
 }
index dc47862a9c410081f1d7dd8509d71d56dbb2c5d7..39014f247fb8b33510fe6cffaed3eeab44ff2e3e 100644 (file)
@@ -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
index d532cf1535bec63216bff66692b484cb72995180..56565ef5587a4d9a1cdd54638fa52391e148f2dc 100755 (executable)
@@ -31,6 +31,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ActionIntParameter.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
@@ -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<ModuleBase_ActionIntParameter>(theParam);
+      int aNb = aParam->value();
       if (theActionType == ActionUndo)
-        myCurrentHistoryIndex--;
+        myCurrentHistoryIndex -= aNb;
       else
-        myCurrentHistoryIndex++;
+        myCurrentHistoryIndex += aNb;
       QList<ModuleBase_ViewerPrsPtr> 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<ActionInfo>
   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;
index 96542e3f20441de4892634aea2819869eda2c1f6..1faf7fdd978bdcb621a9a7775a1dc3504d153f71 100755 (executable)
@@ -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
index bbf6e2b667016b85655b00558cb0657218703ac0..d91cb5c26c4471329b86c1edf68b520d25d71043 100644 (file)
@@ -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;
 }
index eb532706152ea81d1ba498e787429bb6874e3efc..af0b81f841a6793d01eae0abf6978e3639364666 100644 (file)
@@ -96,7 +96,8 @@ public:
   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
 
   /// Processes Selection action.
-  virtual bool processAction(ModuleBase_ActionType theActionType);
+  virtual bool processAction(ModuleBase_ActionType theActionType,
+                             const ActionParamPtr& theParam);
 
 signals:
   /// Signal on plane selection
index d93b451c6d47512d9191adcb9e3150b69a0f49de..495ecfc29005968f092e473a11e34002e99d46d3 100755 (executable)
 #include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_ResultPrs.h>
+#include <ModuleBase_ActionIntParameter.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
@@ -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