Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 55e16fcf87b21e2ba6806da2ed3e3930df466fe0..d92350a07d418b7ffb5fd7c293ce5c2922914400 100644 (file)
@@ -1,4 +1,5 @@
 #include "XGUI_Module.h"
+#include "XGUI_Constants.h"
 #include "XGUI_Command.h"
 #include "XGUI_MainMenu.h"
 #include "XGUI_MainWindow.h"
 #include "XGUI_Viewer.h"
 #include "XGUI_WidgetFactory.h"
 
+#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDocRef.h>
+
 #include <Event_Loop.h>
+#include <ModuleBase_Operation.h>
 #include <Config_FeatureMessage.h>
-#include <Config_WidgetMessage.h>
+#include <Config_PointerMessage.h>
 
 #include <QApplication>
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QMdiSubWindow>
+#include <QPushButton>
+#include <QDockWidget>
 
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
 XGUI_Workshop::XGUI_Workshop()
-    : QObject()
+  : QObject(), 
+  myCurrentOperation(NULL),
+  myPartSetModule(NULL)
 {
   myMainWindow = new XGUI_MainWindow();
-  myPartSetModule = NULL;
 }
 
 //******************************************************
@@ -56,6 +66,18 @@ void XGUI_Workshop::startApplication()
   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
   aWnd->showMaximized();
   myMainWindow->showPythonConsole();
+
+  // Testing of document creation
+  std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  std::shared_ptr<ModelAPI_Feature> aPoint1 = aMgr->rootDocument()->addFeature("Point");
+  std::shared_ptr<ModelAPI_Feature> aPart = aMgr->rootDocument()->addFeature("Part");
+  aPart->execute();
+  aMgr->setCurrentDocument(aPart->data()->docRef("PartDocument")->value());
+  std::shared_ptr<ModelAPI_Feature> aPoint2 = aMgr->rootDocument()->addFeature("Point");
+  aPoint2 = aMgr->rootDocument()->addFeature("Point");
+
+  aPart = aMgr->rootDocument()->addFeature("Part");
+  aPart->execute();
 }
 
 //******************************************************
@@ -68,34 +90,34 @@ void XGUI_Workshop::initMenu()
 
   XGUI_Command* aCommand;
 
-  aCommand = aGroup->addFeature("SAVE_CMD", tr("SAVE_MENU"), tr("SAVE_MENU_TIP"),
+  aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
                                 QIcon(":pictures/save.png"), QKeySequence::Save);
   aCommand->connectTo(this, SLOT(onSave()));
   //aCommand->disable();
 
-  aCommand = aGroup->addFeature("UNDO_CMD", tr("UNDO_MENU"), tr("UNDO_MENU_TIP"),
+  aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
 
-  aCommand = aGroup->addFeature("REDO_CMD", tr("REDO_MENU"), tr("REDO_MENU_TIP"),
+  aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
 
-  aCommand = aGroup->addFeature("REBUILD_CMD", tr("REBUILD_MENU"), tr("REBUILD_MENU_TIP"),
+  aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
                                 QIcon(":pictures/rebuild.png"));
 
-  aCommand = aGroup->addFeature("SAVEAS_CMD", tr("SAVEAS_MENU"), tr("SAVEAS_MENU_TIP"),
+  aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
                                 QIcon(":pictures/save.png"));
   aCommand->connectTo(this, SLOT(onSaveAs()));
   //aCommand->disable();
 
-  aCommand = aGroup->addFeature("OPEN_CMD", tr("OPEN_MENU"), tr("OPEN_MENU_TIP"),
+  aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
                                 QIcon(":pictures/open.png"), QKeySequence::Open);
   aCommand->connectTo(this, SLOT(onOpen()));
 
-  aCommand = aGroup->addFeature("NEW_CMD", tr("NEW_MENU"), tr("NEW_MENU_TIP"),
+  aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
                                 QIcon(":pictures/new.png"), QKeySequence::New);
   aCommand->connectTo(this, SLOT(onNew()));
 
-  aCommand = aGroup->addFeature("EXIT_CMD", tr("EXIT_MENU"), tr("EXIT_MENU_TIP"),
+  aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
                                 QIcon(":pictures/close.png"), QKeySequence::Close);
   aCommand->connectTo(this, SLOT(onExit()));
 
@@ -117,9 +139,17 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage)
     addFeature(aFeatureMsg);
     return;
   }
-  const Config_WidgetMessage* aPartSetMsg = dynamic_cast<const Config_WidgetMessage*>(theMessage);
+  const Config_PointerMessage* aPartSetMsg =
+      dynamic_cast<const Config_PointerMessage*>(theMessage);
   if (aPartSetMsg) {
-    fillPropertyPanel(aPartSetMsg);
+    ModuleBase_Operation* aOperation = (ModuleBase_Operation*)(aPartSetMsg->pointer());
+    setCurrentOperation(aOperation);
+    if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+      myCurrentOperation->start();
+      myCurrentOperation->commit();
+    } else {
+      fillPropertyPanel(aOperation);
+    }
     return;
   }
 
@@ -168,21 +198,46 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
 /*
  *
  */
-void XGUI_Workshop::fillPropertyPanel(const Config_WidgetMessage* theMessage)
+void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
 {
-  QWidget* aPropWidget = myMainWindow->findChild<QWidget*>("PropertyPanelWidget");
-  if (!aPropWidget) {
-    #ifdef _DEBUG
-    qDebug() << "XGUI_Workshop::fillPropertyPanel: " << "Unable to find property panel";
-    #endif
-    return;
-  }
+  connectToPropertyPanel(theOperation);
+  QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
   qDeleteAll(aPropWidget->children());
-  std::string aXml = theMessage->xmlRepresentation();
-  XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aXml);
+  theOperation->start();
+  XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(theOperation);
   aFactory.fillWidget(aPropWidget);
 }
 
+void XGUI_Workshop::setCurrentOperation(ModuleBase_Operation* theOperation)
+{
+  //FIXME: Ask user about aborting of current operation?
+  if (myCurrentOperation) {
+    //TODO get isOperation from document
+    if (myCurrentOperation->isRunning())
+      myCurrentOperation->abort();
+
+    myCurrentOperation->deleteLater();
+  }
+  myCurrentOperation = theOperation;
+}
+
+/*
+ * Makes a signal/slot connections between Property Panel
+ * and given operation. The given operation becomes a
+ * current operation and previous operation if exists
+ */
+void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation)
+{
+  QDockWidget* aPanel = myMainWindow->findChild<QDockWidget*>(XGUI::PROP_PANEL);
+  QPushButton* aOkBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
+  connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
+  QPushButton* aCancelBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
+  connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
+
+  connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel()));
+  connect(theOperation, SIGNAL(stopped()), myMainWindow, SLOT(hidePropertyPanel()));
+}
+
 //******************************************************
 void XGUI_Workshop::onExit()
 {