]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #6 Disable commands on operation start
authorsbh <sergey.belash@opencascade.com>
Wed, 23 Apr 2014 11:10:24 +0000 (15:10 +0400)
committersbh <sergey.belash@opencascade.com>
Wed, 23 Apr 2014 11:10:24 +0000 (15:10 +0400)
15 files changed:
src/Config/Config_FeatureMessage.cpp
src/Config/Config_FeatureMessage.h
src/Config/Config_FeatureReader.cpp
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_Command.h
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_MenuGroupPanel.cpp
src/XGUI/XGUI_MenuGroupPanel.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 85102857bea420483f1c2a7ef2f33cb9f9887ea6..209bb7aa2fef6119f383c7b4d26ca4b8ceea64ad 100644 (file)
@@ -95,3 +95,13 @@ void Config_FeatureMessage::setPluginLibrary(const std::string& myPluginLibrary)
 {
   this->myPluginLibrary = myPluginLibrary;
 }
+
+bool Config_FeatureMessage::isUseInput() const
+{
+  return myUseInput;
+}
+
+void Config_FeatureMessage::setUseInput(bool isUseInput)
+{
+  myUseInput = isUseInput;
+}
index 4185b4b9620831fa1bd01133e06b903339d6a530..900d547d3474239b9a8827a823c79aa6cc0b4867 100644 (file)
@@ -23,6 +23,8 @@ class Config_FeatureMessage: public Event_Message
   std::string myWorkbenchId;  //Id of feature's workbench\r
   std::string myPluginLibrary;  //Name of feature's library\r
 \r
+  bool myUseInput; //Action is being checked until user commit the operation\r
+\r
 public:\r
   //const Event_ID theID, const void* theSender = 0\r
   CONFIG_EXPORT Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);\r
@@ -50,6 +52,8 @@ public:
   CONFIG_EXPORT void setGroupId(const std::string& groupId);\r
   CONFIG_EXPORT void setWorkbenchId(const std::string& workbenchId);\r
   CONFIG_EXPORT void setPluginLibrary(const std::string& thePluginLibrary);\r
+  CONFIG_EXPORT bool isUseInput() const;\r
+  CONFIG_EXPORT void setUseInput(bool isUseInput);\r
 };\r
 \r
 #endif // CONFIG_MESSAGE_H
index bb52b413fa964c3ecdf95c9b275ddd4a6a7b2fe6..50d72e99230ebcc07bf48e30e017140644a6d25d 100644 (file)
@@ -43,6 +43,8 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
     Event_Loop* aEvLoop = Event_Loop::loop();
     Config_FeatureMessage aMessage(aMenuItemEvent, this);
     fillFeature(theNode, aMessage);
+    //If a feature has xml definition for it's widget:
+    aMessage.setUseInput(hasChild(theNode));
     aEvLoop->send(aMessage);
   }
   //The m_last* variables always defined before fillFeature() call. XML is a tree.
index a6afc4d5f2f0dd246ae7ade945f065ac6f621309..912f930d0e9630e24bb18e23b76fb3dd551cb39c 100644 (file)
@@ -247,6 +247,19 @@ void ModuleBase_Operation::commit()
   emit stopped();
 }
 
+/*
+ * \brief Alias for start/abort slots
+ *
+ * Public slot. Aborts operation if false, else does nothing.
+ * Provided for S/S compatibility with QAction's toggle(bool)
+ */
+void ModuleBase_Operation::setRunning(bool on)
+{
+  if (!on) {
+    abort();
+  }
+}
+
 /*!
  * \brief Stores a real value in model.
  * \param theValue - to store
index 5daf8e6c66d974db3824dd9ccc599056bb26de7c..8789e577ede567f39e129147fd2fff3315557793 100644 (file)
@@ -106,6 +106,10 @@ public slots:
   void abort();
   void commit();
 
+  //true = do nothing, false = abort()
+  //Provided for S/S compatibility with QAction's toggle(bool)
+  void setRunning(bool);
+
   // Data model operations.
   void storeReal(double);
 
index fb437c5ba52b712363473543f534ef9691f0c6e8..4c1bcfbde26abe997e67a875f361aa391912331f 100644 (file)
@@ -32,36 +32,45 @@ PartSet_Module::~PartSet_Module()
 
 void PartSet_Module::createFeatures()
 {
-  Config_ModuleReader* aXMLReader = new Config_ModuleReader();
-  aXMLReader->setAutoImport(true);
-  aXMLReader->readAll();
-  delete aXMLReader;
+  Config_ModuleReader aXMLReader = Config_ModuleReader();
+  aXMLReader.setAutoImport(true);
+  aXMLReader.readAll();
 }
 
 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
 {
-  QString aFtId = theFeature->id();
   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
 }
 
-void PartSet_Module::onFeatureTriggered()
+std::string PartSet_Module::modulePlugin()
 {
   Config_ModuleReader aModuleReader = Config_ModuleReader();
   aModuleReader.readAll();
-  std::map<std::string, std::string> aPluginMap = aModuleReader.plugins();
+  std::map < std::string, std::string > aPluginMap = aModuleReader.plugins();
   std::string aPluginName = aPluginMap["PartSetPlugin"];
+  return aPluginName;
+}
+
+/*
+ *
+ */
+void PartSet_Module::onFeatureTriggered()
+{
+  std::string aPluginName = modulePlugin();
   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
   aWdgReader.readAll();
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
   QString aCmdId = aCmd->id();
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
   std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
-  //TODO(sbh): Implement static method to extract event id [SEID]
-  static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
-  Config_PointerMessage aMessage(aModuleEvent, this);
+
   ModuleBase_PropPanelOperation* aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
   aPartSetOp->setDescription(QString::fromStdString(aDescription));
+
+  //TODO(sbh): Implement static method to extract event id [SEID]
+  static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
+  Config_PointerMessage aMessage(aModuleEvent, this);
   aMessage.setPointer(aPartSetOp);
   Event_Loop::loop()->send(aMessage);
 }
index f4894e239868544517f7f7d0695b5d28065d3f21..c6b895b90f230b93a872d4d0d2b6ef909da67a33 100644 (file)
@@ -11,6 +11,8 @@
 class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
 {
 Q_OBJECT
+  std::string modulePlugin();
+
 public:
   PartSet_Module(XGUI_Workshop* theWshop);
   virtual ~PartSet_Module();
index 5e9ffb8fb8113df363de9eaa668aa6cb2d5a669d..ffd6ab103f7338b833a05020b60e635534532867 100644 (file)
@@ -2,14 +2,14 @@
 
 #include <QPushButton>
 
-XGUI_Command::XGUI_Command(const QString& theId, QObject * parent)
-    : QWidgetAction(parent), myId(theId)
+XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
+    : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
 {
 }
 
 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
-                           QObject* parent)
-    : QWidgetAction(parent), myId(theId)
+                           QObject* parent, bool isCheckable)
+    : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
 {
   setIcon(icon);
   setText(text);
@@ -22,22 +22,26 @@ XGUI_Command::~XGUI_Command()
 QWidget* XGUI_Command::createWidget(QWidget* theParent)
 {
   if (theParent->inherits("XGUI_MenuGroupPanel")) {
-    QPushButton* aBtn = new QPushButton(theParent);
-    aBtn->setIcon(icon());
-    aBtn->setText(text());
-    aBtn->setStyleSheet("text-align: left");
+    QPushButton* aButton = new QPushButton(theParent);
+    aButton->setIcon(icon());
+    aButton->setText(text());
+    aButton->setStyleSheet("text-align: left");
     QKeySequence aKeys = shortcut();
     QString aToolTip = toolTip();
     if (!aKeys.isEmpty())
       aToolTip = aToolTip + " (" + aKeys.toString() + ")";
     if (!aToolTip.isEmpty())
-      aBtn->setToolTip(aToolTip);
+      aButton->setToolTip(aToolTip);
 
-    aBtn->addAction(this);
-    connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger()));
-    aBtn->setFlat(true);
-    aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
-    return aBtn;
+    aButton->addAction(this);
+    connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
+    connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
+    aButton->setFlat(true);
+    aButton->setCheckable(myCheckable);
+    this->setCheckable(myCheckable);
+    aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
+
+    return aButton;
   }
   return QWidgetAction::createWidget(theParent);
 }
@@ -59,5 +63,15 @@ void XGUI_Command::disable()
 
 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
 {
-  connect(this, SIGNAL(triggered()), theResiver, theSlot);
+    connect(this, SIGNAL(triggered()), theResiver, theSlot);
+}
+
+const QStringList& XGUI_Command::unblockableCommands() const
+{
+  return myUnblockableCommands;
+}
+
+void XGUI_Command::setUnblockableCommands(const QStringList& myUnblockableCommands)
+{
+  this->myUnblockableCommands = myUnblockableCommands;
 }
index 34c5f63f6dee6b8c0d55ac06211d1a1fc50804d3..380b64ae4b8ce90eb1761995cc724d67dc5f81ca 100644 (file)
@@ -15,8 +15,8 @@ class XGUI_EXPORT XGUI_Command: public QWidgetAction
 {
 Q_OBJECT
 public:
-  XGUI_Command(const QString& theId, QObject * parent);
-  XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent);
+  XGUI_Command(const QString& theId, QObject * parent, bool isCheckable = false);
+  XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, bool isCheckable = false);
   ~XGUI_Command();
 
   //! Returns true if the command is enabled
@@ -34,6 +34,9 @@ public:
     return myId;
   }
 
+  const QStringList& unblockableCommands() const;
+  void setUnblockableCommands(const QStringList& myUnblockableCommands);
+
   //! Connect the command to a slot
   virtual void connectTo(const QObject* theResiver, const char* theSlot);
 
@@ -43,6 +46,9 @@ protected:
 
 private:
   QString myId;
+  bool myCheckable;
+  //! List of Ids of commands which WILL NOT be blocked when the command is on.
+  QStringList myUnblockableCommands;
 };
 
 #endif
index 7d8e81f351779bb8b9ffa40c29b44deccf5dfd11..96106a9111357da303ce4d14993cd204893aa057 100644 (file)
@@ -1,6 +1,7 @@
-#include "XGUI_MainMenu.h"
-#include "XGUI_Workbench.h"
-#include "XGUI_MainWindow.h"
+#include <XGUI_MainMenu.h>
+#include <XGUI_Workbench.h>
+#include <XGUI_MainWindow.h>
+#include <XGUI_Command.h>
 
 #include <QLayout>
 #include <QTabWidget>
@@ -88,4 +89,50 @@ QList<XGUI_Command*> XGUI_MainMenu::features() const
     aList.append(aWbn->features());
   }
   return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_MainMenu::onFeatureChecked(bool isChecked)
+{
+  if (!isChecked) {
+    restoreCommandState();
+    return;
+  }
+
+  saveCommandsState();
+  QStringList aSkippedIds;
+  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+  aSkippedIds.append(aToggledFeature->unblockableCommands());
+//  aSkippedIds.append(aToggledFeature->id());
+  XGUI_Workbench* aGeneralWB = findWorkbench(tr("General"));
+  foreach(XGUI_Command* eachFeature, aGeneralWB->features()) {
+    aSkippedIds.append(eachFeature->id());
+  }
+  QList<XGUI_Command*> allFeatures = features();
+  foreach(XGUI_Command* eachFeature, allFeatures) {
+    QString aFeatureId = eachFeature->id();
+    if (aSkippedIds.removeAll(aFeatureId) > 0) {
+      continue;
+    }
+    eachFeature->setEnabled(false);
+  }
+}
+
+void XGUI_MainMenu::saveCommandsState()
+{
+  myCommandState.clear();
+  QList<XGUI_Command*> allFeatures = features();
+  XGUI_Command* eachFeature = NULL;
+  foreach(eachFeature, allFeatures) {
+    myCommandState.insert(eachFeature, eachFeature->enabled());
+  }
+}
+
+void XGUI_MainMenu::restoreCommandState()
+{
+  QList<XGUI_Command*> allFeatures = features();
+  XGUI_Command* eachFeature = NULL;
+  foreach(eachFeature, allFeatures) {
+    eachFeature->setChecked(false);
+    eachFeature->setEnabled(myCommandState[eachFeature]);
+  }
+}
index c281422a6ba8f1c9bf51c646ef2a5391cca553e6..0fed1a07ff64a11c83d68665cd2b1e11b11aac21 100644 (file)
@@ -4,6 +4,7 @@
 #include "XGUI.h"
 #include <QObject>
 #include <QList>
+#include <QMap>
 
 class XGUI_Command;
 class XGUI_MainWindow;
@@ -16,6 +17,7 @@ class QAction;
 class QDockWidget;
 class QEvent;
 
+
 /**\class XGUI_MainMenu
  * \ingroup GUI
  * \brief Class for creation of main menu (set of workbenches)
@@ -45,13 +47,20 @@ public:
   //! Returns list of created commands
   QList<XGUI_Command*> features() const;
 
-protected:
+public slots:
+  void onFeatureChecked(bool);
+
+  void saveCommandsState();
+  void restoreCommandState();
+
   virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
 
 private:
   XGUI_MainWindow* myDesktop;
   QList<QDockWidget*> myMenuTabs;
   XGUI_Workbench* myGeneralPage;
+
+  QMap<XGUI_Command*, bool> myCommandState;
 };
 
 #endif
index 00d131278ca54b0036977d42da2d37a1bac2587f..4f4673470417dad3dcb02a3d1ac5f13080df9201 100644 (file)
@@ -7,6 +7,7 @@
 #include <QResizeEvent>
 
 #include <math.h>
+#include <iostream>
 
 XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent)
     : QWidget(parent), myNewRow(0), myNewCol(0), myMaxRow(1)
@@ -61,9 +62,9 @@ void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent)
 
 XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle,
                                               const QString& theTip, const QIcon& theIcon,
-                                              const QKeySequence& theKeys)
+                                              const QKeySequence& theKeys, bool isCheckable)
 {
-  XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this);
+  XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this, isCheckable);
   aCommand->setToolTip(theTip);
   if (!theKeys.isEmpty())
     aCommand->setShortcut(theKeys);
@@ -80,4 +81,4 @@ XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
     if ((*aIt)->id() == theId)
       return (*aIt);
   return 0;
-}
\ No newline at end of file
+}
index a1398132698b7bdcd5e4ad19055f80bf709181de..b43ef75c6e7175e3561c7294da3ee111c6791841 100644 (file)
@@ -20,7 +20,8 @@ public:
 
   //! Adding a new feature (Command) in the group
   XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip,
-                           const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence());
+                           const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence(),
+                           bool isCheckable = false);
 
   //! Returns already created command by its ID
   XGUI_Command* feature(const QString& theId) const;
index 48e3770cebdaee086a8120b7bc0115ab57301509..cc6e63875650377da0db63562d0449b9d560a175 100644 (file)
@@ -191,14 +191,16 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
   if (!aGroup) {
     aGroup = aPage->addGroup(aGroupName);
   }
+  bool isUsePropPanel = theMessage->isUseInput();
   //Create feature...
-  QString aFeatureId = QString::fromStdString(theMessage->id());
   XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()),
                                               QString::fromStdString(theMessage->text()),
                                               QString::fromStdString(theMessage->tooltip()),
-                                              QIcon(theMessage->icon().c_str())
-                                              //TODO(sbh): QKeySequence
-                                                  );
+                                              QIcon(theMessage->icon().c_str()),
+                                              QKeySequence(), isUsePropPanel);
+  
+  connect(aCommand,                   SIGNAL(toggled(bool)),
+          myMainWindow->menuObject(), SLOT(onFeatureChecked(bool)));
   myPartSetModule->featureCreated(aCommand);
 }
 
@@ -207,7 +209,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
  */
 void XGUI_Workshop::fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation)
 {
-  connectToPropertyPanel(theOperation);
+  connectWithOperation(theOperation);
   QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
   qDeleteAll(aPropWidget->children());
   theOperation->start();
@@ -234,7 +236,7 @@ void XGUI_Workshop::setCurrentOperation(ModuleBase_Operation* theOperation)
  * and given operation. The given operation becomes a
  * current operation and previous operation if exists
  */
-void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation)
+void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
 {
   QDockWidget* aPanel = myMainWindow->findChild<QDockWidget*>(XGUI::PROP_PANEL);
   QPushButton* aOkBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
@@ -245,6 +247,14 @@ void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation)
   connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel()));
   connect(theOperation, SIGNAL(stopped()), myMainWindow, SLOT(hidePropertyPanel()));
   connect(theOperation, SIGNAL(stopped()), this, SLOT(updateCommandStatus()));
+
+  XGUI_MainMenu* aMenu = myMainWindow->menuObject();
+  connect(theOperation, SIGNAL(stopped()), aMenu, SLOT(restoreCommandState()));
+
+  XGUI_Command* aCommand = aMenu->feature(theOperation->operationId());
+  //Abort operation on uncheck the command
+  connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool)));
+
 }
 
 //******************************************************
@@ -309,7 +319,6 @@ void XGUI_Workshop::onRedo()
   updateCommandStatus();
 }
 
-
 //******************************************************
 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
 {
index aff5c239bc90755867f18e9446a52f92d02e83b6..e0da527129a2c5a9ed2032b9dabe7d54f926e1dc 100644 (file)
@@ -65,7 +65,7 @@ protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
   void fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation);
-  void connectToPropertyPanel(ModuleBase_Operation* theOperation);
+  void connectWithOperation(ModuleBase_Operation* theOperation);
   void setCurrentOperation(ModuleBase_Operation* theOperation);
 
 private: