]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update command status method added
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 11 Apr 2014 08:29:45 +0000 (12:29 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 11 Apr 2014 08:29:45 +0000 (12:29 +0400)
12 files changed:
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Command.h
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_MenuGroupPanel.cpp
src/XGUI/XGUI_MenuGroupPanel.h
src/XGUI/XGUI_Workbench.cpp
src/XGUI/XGUI_Workbench.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 409e38484871b43be35dd85042f6c838a0fc099f..3a24568f49a2bd9d81e75632b0a6d2bd93364cff 100644 (file)
@@ -40,7 +40,7 @@ void PartSet_Module::createFeatures()
 
 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
 {
-  QString aFtId = theFeature->getId();
+  QString aFtId = theFeature->id();
   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
 }
 
@@ -53,7 +53,7 @@ void PartSet_Module::onFeatureTriggered()
   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
   aWdgReader.readAll();
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
-  QString aCmdId = aCmd->getId();
+  QString aCmdId = aCmd->id();
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
   //TODO(sbh): Implement static method to extract event id [SEID]
   static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
index 1bef9e0db1be7a0dc491ed15ff600baa1d6721f3..b1227ba2e88335a0636ee9c3416141477ddf516d 100644 (file)
@@ -28,7 +28,7 @@ public:
   virtual void disable();
 
   //! Returns Id of the command
-  virtual QString getId() const
+  virtual QString id() const
   {
     return myId;
   }
index efce9ab2c0bca4aacc50089f752d041dd8094ab4..7d8e81f351779bb8b9ffa40c29b44deccf5dfd11 100644 (file)
@@ -6,12 +6,15 @@
 #include <QTabWidget>
 #include <QLabel>
 #include <QDockWidget>
+#include <QEvent>
 
 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
     : QObject(parent), myDesktop(parent)
 {
   parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
   myGeneralPage = addWorkbench(tr("General"));
+  myGeneralPage->parentWidget()->setMaximumWidth(200);
+  myGeneralPage->installEventFilter(this);
 }
 
 XGUI_MainMenu::~XGUI_MainMenu(void)
@@ -51,3 +54,38 @@ XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
 {
   return myDesktop->findChild<XGUI_Workbench*>(theObjName);
 }
+
+
+bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
+{
+  if (theWatched == myGeneralPage) {
+    if (theEvent->type() == QEvent::Show) {
+      myGeneralPage->parentWidget()->setMaximumWidth(16777215);
+      myGeneralPage->removeEventFilter(this);
+    }
+  }
+  return QObject::eventFilter(theWatched, theEvent);
+}
+
+XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
+{
+  QList<QDockWidget*>::const_iterator aIt;
+  for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+    XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+    XGUI_Command* aCmd = aWbn->feature(theId);
+    if (aCmd)
+      return aCmd;
+  }
+  return 0;
+}
+
+QList<XGUI_Command*> XGUI_MainMenu::features() const
+{
+  QList<XGUI_Command*> aList;
+  QList<QDockWidget*>::const_iterator aIt;
+  for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+    XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+    aList.append(aWbn->features());
+  }
+  return aList;
+}
\ No newline at end of file
index 028f73b12a87c24c5225017196633afc41044f08..b683fc99edbafab754a041947c2bcf25472a15b2 100644 (file)
@@ -13,6 +13,7 @@ class QTabWidget;
 class QLabel;
 class QAction;
 class QDockWidget;
+class QEvent;
 
 /**\class XGUI_MainMenu
  * \ingroup GUI
@@ -37,6 +38,15 @@ public:
   //! Rerturns last created workbench in dock widget container
   QDockWidget* getLastDockWindow() const { return myMenuTabs.last(); }
 
+  //! Returns already created command by its ID
+  XGUI_Command* feature(const QString& theId) const;
+
+  //! Returns list of created commands
+  QList<XGUI_Command*> features() const;
+
+protected:
+  virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
+
 private:
   XGUI_MainWindow* myDesktop;
   QList<QDockWidget*> myMenuTabs;
index 25ea218c9519b3771d8e7507805341737061f50f..25516792e88563d54928306cbc6864767f5c9de3 100644 (file)
@@ -28,9 +28,9 @@
 
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
     : QMainWindow(parent), 
-    myObjectBrowser(NULL),
-    myPythonConsole(NULL),
-    myPropertyPanelDock(NULL)
+    myObjectBrowser(0),
+    myPythonConsole(0),
+    myPropertyPanelDock(0)
 {
   setWindowTitle(tr("New Geom"));
   myMenuBar = new XGUI_MainMenu(this);
@@ -40,7 +40,7 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
 
   myViewer = new XGUI_Viewer(this);
 
-  createDockWidgets();
+  //createDockWidgets();
 }
 
 XGUI_MainWindow::~XGUI_MainWindow(void)
@@ -75,11 +75,7 @@ void XGUI_MainWindow::showPythonConsole()
     aDoc->setMinimumHeight(0);
     aDoc->setWindowTitle("Console");
     myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
-    //myPythonConsole = new QTextEdit(aDoc);
-    //myPythonConsole->setGeometry(0,0,200, 50);
-    //myPythonConsole->setText(">>>");
     aDoc->setWidget(myPythonConsole);
-    //myPythonConsole->setMinimumHeight(0);
     addDockWidget(Qt::TopDockWidgetArea, aDoc);
     tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
   }
index 4cdbba52c77782110b8287065eea657d2632afec..4f99979c998549fbc9e5f10abf037217bd08cc3c 100644 (file)
@@ -43,6 +43,9 @@ public:
     return myViewer;
   }
 
+  // Creates Dock widgets: Object broewser and Property panel
+  void createDockWidgets();
+
 public slots:
   void showPythonConsole();
   void hidePythonConsole();
@@ -52,7 +55,6 @@ public slots:
   void hideObjectBrowser();
 
 private:
-  void createDockWidgets();
   QDockWidget* createObjectBrowser();
   QDockWidget* createPropertyPanel();
 
index 4f447117c97e1c6021f99d2aee9ba0a5777762e3..00d131278ca54b0036977d42da2d37a1bac2587f 100644 (file)
@@ -71,3 +71,13 @@ XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QStrin
   addCommand(aCommand);
   return aCommand;
 }
+
+
+XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
+{
+  QList<XGUI_Command*>::const_iterator aIt;
+  for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt)
+    if ((*aIt)->id() == theId)
+      return (*aIt);
+  return 0;
+}
\ No newline at end of file
index 58fd7a7975550847c69a2e14110e38ca98a49c73..fa3152ec075867fea4cf6ea51245fad28e65dca2 100644 (file)
@@ -21,6 +21,12 @@ public:
   XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip,
                            const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence());
 
+  //! Returns already created command by its ID
+  XGUI_Command* feature(const QString& theId) const;
+
+  //! Returns list of created commands
+  QList<XGUI_Command*> features() const { return myActions; }
+
 protected:
   virtual void resizeEvent(QResizeEvent *theEvent);
 
index 996d5a7aeffe9df3245cb776321c6d244a430dd2..468d8d0ce1f1fdfa4732aedf1243355e605bcca2 100644 (file)
@@ -170,4 +170,24 @@ bool XGUI_Workbench::eventFilter(QObject *theObj, QEvent *theEvent)
     }
   }
   return QWidget::eventFilter(theObj, theEvent);
+}
+
+XGUI_Command* XGUI_Workbench::feature(const QString& theId) const
+{
+  QList<XGUI_MenuGroupPanel*>::const_iterator aIt;
+  for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) {
+    XGUI_Command* aCmd = (*aIt)->feature(theId);
+    if (aCmd)
+      return aCmd;
+  }
+  return 0;
+}
+
+QList<XGUI_Command*> XGUI_Workbench::features() const
+{
+  QList<XGUI_Command*> aList;
+  QList<XGUI_MenuGroupPanel*>::const_iterator aIt;
+  for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) 
+    aList.append((*aIt)->features());
+  return aList;
 }
\ No newline at end of file
index 57b17d3bea7a58a963685c8737058d4508b7078a..3c7443b3bf0c2495c1acf06cce7a1dc7918fad4d 100644 (file)
@@ -21,6 +21,12 @@ public:
   XGUI_MenuGroupPanel* addGroup(const QString& theId);
   XGUI_MenuGroupPanel* findGroup(const QString& theName);
 
+  //! Returns already created command by its ID
+  XGUI_Command* feature(const QString& theId) const;
+
+  //! Returns list of created commands
+  QList<XGUI_Command*> features() const;
+
 private slots:
   void onLeftScroll();
   void onRightScroll();
@@ -29,6 +35,7 @@ protected:
   virtual void resizeEvent(QResizeEvent * theEvent);
   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
 
+
 private:
   void addSeparator();
   bool isExceedsLeft();
index 0aa5bde710846343163a4df7c4d99633bf027d40..4dbd97a532de5a6a1e3e2a0f73e4489d29724885 100644 (file)
@@ -66,6 +66,7 @@ void XGUI_Workshop::startApplication()
   activateModule();
   myMainWindow->show();
 
+  updateCommandStatus();
   // Testing of document creation
   //std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
   //std::shared_ptr<ModelAPI_Feature> aPoint1 = aMgr->rootDocument()->addFeature("Point");
@@ -96,9 +97,11 @@ void XGUI_Workshop::initMenu()
 
   aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
+  aCommand->connectTo(this, SLOT(onUndo()));
 
   aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
+  aCommand->connectTo(this, SLOT(onRedo()));
 
   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
                                 QIcon(":pictures/rebuild.png"));
@@ -146,6 +149,7 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage)
     if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
       myCurrentOperation->start();
       myCurrentOperation->commit();
+      updateCommandStatus();
     } else {
       fillPropertyPanel(aOperation);
     }
@@ -247,30 +251,55 @@ void XGUI_Workshop::onExit()
 void XGUI_Workshop::onNew()
 {
   QApplication::setOverrideCursor(Qt::WaitCursor);
+  if (myMainWindow->objectBrowser() == 0)
+    myMainWindow->createDockWidgets();
   myMainWindow->showObjectBrowser();
   myMainWindow->showPythonConsole();
   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
   aWnd->showMaximized();
+  updateCommandStatus();
   QApplication::restoreOverrideCursor();
 }
 
 //******************************************************
 void XGUI_Workshop::onOpen()
 {
-  QString aFileName = QFileDialog::getOpenFileName(mainWindow());
+  //QString aFileName = QFileDialog::getOpenFileName(mainWindow());
+  updateCommandStatus();
 }
 
 //******************************************************
 void XGUI_Workshop::onSave()
 {
+  updateCommandStatus();
 }
 
 //******************************************************
 void XGUI_Workshop::onSaveAs()
 {
-  QString aFileName = QFileDialog::getSaveFileName(mainWindow());
+  //QString aFileName = QFileDialog::getSaveFileName(mainWindow());
+  updateCommandStatus();
 }
 
+//******************************************************
+void XGUI_Workshop::onUndo()
+{
+  std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+  aDoc->undo();
+  updateCommandStatus();
+}
+
+//******************************************************
+void XGUI_Workshop::onRedo()
+{
+  std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+  aDoc->redo();
+  updateCommandStatus();
+}
+
+
 //******************************************************
 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
 {
@@ -340,3 +369,38 @@ bool XGUI_Workshop::activateModule()
   myPartSetModule->createFeatures();
   return true;
 }
+
+//******************************************************
+void XGUI_Workshop::updateCommandStatus()
+{
+  XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+
+  QList<XGUI_Command*> aCommands = aMenuBar->features();
+  QList<XGUI_Command*>::const_iterator aIt;
+
+  std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  if (aMgr->hasRootDocument()) {
+    XGUI_Command* aUndoCmd;
+    XGUI_Command* aRedoCmd;
+    for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
+      if ((*aIt)->id() == "UNDO_CMD")
+        aUndoCmd = (*aIt);
+      else if ((*aIt)->id() == "REDO_CMD")
+        aRedoCmd = (*aIt);
+      else // Enable all commands
+        (*aIt)->enable();
+    }
+    std::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+    aUndoCmd->setEnabled(aDoc->canUndo());
+    aRedoCmd->setEnabled(aDoc->canRedo());
+  } else {
+    for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
+      if ((*aIt)->id() == "NEW_CMD")
+        (*aIt)->enable();
+      else if ((*aIt)->id() == "EXIT_CMD")
+        (*aIt)->enable();
+      else 
+        (*aIt)->disable();
+    }
+  }
+}
\ No newline at end of file
index 16c5425431e84a38f96446511712afededd8fe71..31d87bbbc4d0a522b3d5a4520deb4c8898b78f09 100644 (file)
@@ -50,11 +50,15 @@ public:
   virtual void processEvent(const Event_Message* theMessage);
 
 public slots:
+  void updateCommandStatus();
+
   void onNew();
   void onOpen();
   void onSave();
   void onSaveAs();
   void onExit();
+  void onUndo();
+  void onRedo();
 
 protected:
   //Event-loop processing methods: