Salome HOME
Merge 'abn/V8_1_fix' branch into V8_1_BR.
[modules/med.git] / src / MEDCalc / gui / WorkspaceController.cxx
index 3137c82d2a84ecfd3a11c2e6f3dec1da05c07868..a2c442aa4b68e7a8644f7da7b01b325d252e8482 100644 (file)
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
 
+#include <QTimer>
+#include <QMessageBox>
+
 /*!
  * This class defines a DockWidget plugged in the SALOME application,
  * and containing a tree view for rendering a hierarchical data
  * model. This datamodel contains the objects used in the workspace.
  */
-//WorkspaceController::WorkspaceController(StandardApp_Module* salomeModule)
 WorkspaceController::WorkspaceController(MEDModule* salomeModule)
   : TreeGuiManager(salomeModule->getApp(), "Workspace")
 {
@@ -100,7 +102,7 @@ WorkspaceController::WorkspaceController(MEDModule* salomeModule)
 }
 
 WorkspaceController::~WorkspaceController() {
-  std::cout << "WorkspaceController::~WorkspaceController()\n";
+  STDLOG("WorkspaceController::~WorkspaceController()");
   MEDEventListener_i::release();
 }
 
@@ -118,14 +120,12 @@ void WorkspaceController::createActions() {
   QString tooltip = tr("TIP_SAVE_WORKSPACE");
   QString icon    = tr("ICO_WORKSPACE_SAVE");
   int actionId = _salomeModule->createStandardAction(label,this,SLOT(OnSaveWorkspace()),icon,tooltip);
-  //_salomeModule->addActionInToolbar(actionId);
   _salomeModule->createTool(actionId, toolbarId);
 
   label   = tr("LAB_CLEAN_WORKSPACE");
   tooltip = tr("TIP_CLEAN_WORKSPACE");
   icon    = tr("ICO_WORKSPACE_CLEAN");
   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnCleanWorkspace()),icon,tooltip);
-//_salomeModule->addActionInToolbar(actionId);
   _salomeModule->createTool(actionId, toolbarId);
 }
 
@@ -309,9 +309,26 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) {
     emit workspaceSignal(event); // forward to DatasourceController
   }
   else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
-    emit workspaceSignal(event); // forward to DatasourceController
+    emit workspaceSignal(event); // forward to PresentationController
   }
-
+  else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
+    emit workspaceSignal(event); // forward to PresentationController
+  }
+  else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
+      emit workspaceSignal(event); // forward to PresentationController
+  }
+  else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) {
+    emit workspaceSignal(event); // forward to TestController
+  }
+  else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
+    emit workspaceSignal(event); // forward to TestController
+  }
+  else if ( event->type == MEDCALC::EVENT_ERROR ) {
+      std::string msg(event->msg);
+      QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg));
+  }
+  else
+    STDLOG("WorkspaceController::processMedEvent(): Unhandled event!!!");
 }
 
 /*!
@@ -461,17 +478,6 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) {
   _consoleDriver->exec(commands);
 }
 
-QString
-WorkspaceController::_getViewMode() {
-  MEDCALC::MEDPresentationViewMode viewMode = _salomeModule->getSelectedViewMode();
-  switch(viewMode) {
-  case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
-  case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
-  case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
-  case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
-  }
-}
-
 /**
  * This slot can process the event coming from the
  * DatasourceController. The connection between the datasource signal
@@ -518,24 +524,30 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) {
   }
   else if ( event->eventtype == DatasourceEvent::EVENT_ADD_DATASOURCE ) {
     QStringList commands;
-    commands += QString("medcalc.LoadDataSource('%1')").arg(event->objectalias);
+    commands += QString("source_id = medcalc.LoadDataSource('%1')").arg(event->objectalias);
+    commands += QString("source_id");
     _consoleDriver->exec(commands);
+
+    // Create a default presentation when loading a file
+    MEDCALC::MedEvent* evt = new MEDCALC::MedEvent();
+    evt->type = MEDCALC::EVENT_ADD_PRESENTATION;
+    evt->dataId = -1;
+    emit workspaceSignal(evt); // forward to PresentationController
   }
   else if ( event->eventtype == DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE ) {
     QStringList commands;
-    commands += QString("medcalc.LoadImageAsDataSource('%1')").arg(event->objectalias);
+    commands += QString("source_id = medcalc.LoadImageAsDataSource('%1')").arg(event->objectalias);
+    commands += QString("source_id");
     _consoleDriver->exec(commands);
   }
   else {
     STDLOG("The event "<<event->eventtype<<" is not implemented yet");
   }
 }
-/**
- * This slot can process the event coming from the
- * DatasourceController. The connection between the datasource signal
- * and this slot is realized by the main class MEDModule.
- */
-void WorkspaceController::processPresentationEvent(const PresentationEvent* event) {
+
+void
+WorkspaceController::processProcessingEvent(const ProcessingEvent* event)
+{
   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
   if ( dataModel == NULL ) {
     STDLOG("No data model associated to this tree view");
@@ -551,50 +563,14 @@ void WorkspaceController::processPresentationEvent(const PresentationEvent* even
 
   XmedDataObject* dataObject = event->objectdata;
 
-  if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeScalarMap(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
-    QString viewMode = _getViewMode();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-    _consoleDriver->exec(commands);
-  }
-  else {
-    STDLOG("The event "<<event->eventtype<<" is not implemented yet");
+  if ( event->eventtype == ProcessingEvent::EVENT_IMPORT_OBJECT ) {
+    std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl;
+    STDLOG("IMPORT object in workspace:\n"<<dataObject->toString());
+    // _GBO_ QUESTION: tag automatically the object as a peristant object ??
+    // We first add the data object to the internal data model
+    dataModel->addDataObject(dataObject);
+    // Then we request the tree view to consider this new object
+    this->getDataTreeModel()->addData(dataObject);
   }
 }