Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 1a11dca832d2f22f545eea46e1305eaef5722ffd..40c545b2c2567000db3f10b3f75d8d6357be071b 100644 (file)
@@ -92,6 +92,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myViewerProxy = new XGUI_ViewerProxy(this);
 
   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
+  connect(myOperationMgr, SIGNAL(operationResumed()),  this, SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
@@ -127,18 +128,20 @@ void XGUI_Workshop::startApplication()
 //******************************************************
 void XGUI_Workshop::initMenu()
 {
+  myContextMenuMgr->createActions();
+
   if (isSalomeMode()) {
     // Create only Undo, Redo commands
-    salomeConnector()->addEditCommand("UNDO_CMD", 
+    QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD", 
                                       tr("Undo"), tr("Undo last command"),
                                       QIcon(":pictures/undo.png"), 
-                                      false, this, SLOT(onUndo()),
-                                      QKeySequence::Undo);
-    salomeConnector()->addEditCommand("REDO_CMD", 
+                                      QKeySequence::Undo, false);
+    connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
+    aAction = salomeConnector()->addEditCommand("REDO_CMD", 
                                       tr("Redo"), tr("Redo last command"),
                                       QIcon(":pictures/redo.png"), 
-                                      false, this, SLOT(onRedo()),
-                                      QKeySequence::Redo);
+                                      QKeySequence::Redo, false);
+    connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
     salomeConnector()->addEditMenuSeparator();
     return;
   }
@@ -181,8 +184,6 @@ void XGUI_Workshop::initMenu()
   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
                                 QIcon(":pictures/close.png"), QKeySequence::Close);
   aCommand->connectTo(this, SLOT(onExit()));
-
-  myContextMenuMgr->createActions();
 }
 
 //******************************************************
@@ -297,16 +298,15 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
   bool isUsePropPanel = theMessage->isUseInput();
   if (isSalomeMode()) {
     QString aId = QString::fromStdString(theMessage->id());
-    salomeConnector()->addFeature(aWchName,
-                                  QString::fromStdString(theMessage->id()),
-                                  aId,
-                                  QString::fromStdString(theMessage->tooltip()),
-                                  QIcon(theMessage->icon().c_str()),
-                                  isUsePropPanel, this, 
-                                  SLOT(onFeatureTriggered()), QKeySequence());
-    myActionsMgr->addCommand(aId, salomeConnector()->command(aId));
+    QAction* aAction = salomeConnector()->addFeature(aWchName,
+                              aId,
+                              QString::fromStdString(theMessage->text()),
+                              QString::fromStdString(theMessage->tooltip()),
+                              QIcon(theMessage->icon().c_str()),
+                              QKeySequence(), isUsePropPanel);
+    myActionsMgr->addCommand(aAction);
     salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
-
+    myPartSetModule->featureCreated(aAction);
   } else {
 
     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
@@ -563,36 +563,39 @@ bool XGUI_Workshop::activateModule()
 //******************************************************
 void XGUI_Workshop::updateCommandStatus()
 {
-  if (isSalomeMode()) // TODO: update commands in SALOME
-    return;
-  XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
-
-  QList<XGUI_Command*> aCommands = aMenuBar->features();
-  QList<XGUI_Command*>::const_iterator aIt;
-
+  QList<QAction*> aCommands;
+  if (isSalomeMode()) { // update commands in SALOME mode
+    aCommands = salomeConnector()->commandList();
+  } else {
+    XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+    foreach (XGUI_Command* aCmd, aMenuBar->features())
+      aCommands.append(aCmd);
+  }
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   if (aMgr->hasRootDocument()) {
-    XGUI_Command* aUndoCmd;
-    XGUI_Command* aRedoCmd;
-    foreach(XGUI_Command* aCmd, aCommands) {
-      if (aCmd->id() == "UNDO_CMD")
+    QAction* aUndoCmd;
+    QAction* aRedoCmd;
+    foreach(QAction* aCmd, aCommands) {
+      QString aId = aCmd->data().toString();
+      if (aId == "UNDO_CMD")
         aUndoCmd = aCmd;
-      else if (aCmd->id() == "REDO_CMD")
+      else if (aId == "REDO_CMD")
         aRedoCmd = aCmd;
       else // Enable all commands
-        aCmd->enable();
+        aCmd->setEnabled(true);
     }
     DocumentPtr aDoc = aMgr->rootDocument();
     aUndoCmd->setEnabled(aDoc->canUndo());
     aRedoCmd->setEnabled(aDoc->canRedo());
   } else {
-    foreach(XGUI_Command* aCmd, aCommands) {
-      if (aCmd->id() == "NEW_CMD")
-        aCmd->enable();
-      else if (aCmd->id() == "EXIT_CMD")
-        aCmd->enable();
+    foreach(QAction* aCmd, aCommands) {
+      QString aId = aCmd->data().toString();
+      if (aId == "NEW_CMD")
+        aCmd->setEnabled(true);
+      else if (aId == "EXIT_CMD")
+        aCmd->setEnabled(true);
       else 
-        aCmd->disable();
+        aCmd->setEnabled(false);
     }
   }
 }