Salome HOME
Merge 'abn/V8_1_fix' branch into V8_1_BR.
[modules/med.git] / src / MEDCalc / gui / WorkspaceController.cxx
index ec6f3e2b29da43915b5f2a076c54f4460b1d1e51..a2c442aa4b68e7a8644f7da7b01b325d252e8482 100644 (file)
@@ -35,6 +35,9 @@
 #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
@@ -306,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!!!");
 }
 
 /*!
@@ -504,12 +524,20 @@ 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 {
@@ -517,34 +545,9 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) {
   }
 }
 
-QString
-WorkspaceController::_getViewMode()
+void
+WorkspaceController::processProcessingEvent(const ProcessingEvent* event)
 {
-  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";
-  }
-}
-
-QString
-WorkspaceController::_getColorMap()
-{
-  MEDCALC::MEDPresentationColorMap colorMap = _salomeModule->getSelectedColorMap();
-  switch(colorMap) {
-  case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
-  case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
-  }
-}
-
-/**
- * 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) {
   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
   if ( dataModel == NULL ) {
     STDLOG("No data model associated to this tree view");
@@ -560,54 +563,14 @@ void WorkspaceController::processPresentationEvent(const PresentationEvent* even
 
   XmedDataObject* dataObject = event->objectdata;
 
-  // --> Send commands to SALOME Python console
-  if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
-    QString viewMode = _getViewMode();
-    //QString displayedInfo = ; // from PresentationController combobox
-    //QString scalarBarRange = ; // from PresentationController spinbox
-    QString colorMap = _getColorMap();
-    MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
-    QStringList commands;
-    commands += QString("medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap);
-    _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);
   }
 }