Salome HOME
Update copyrights
[modules/med.git] / src / MEDCalc / gui / MEDModule.cxx
index 1501c32b102dd4fc0e387875955f985435bbc9d5..81f42e91915665f1f6bf8ccfaecdfc1781759242 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <SALOMEDS_Study.hxx>
 
 #ifndef DISABLE_PVVIEWER
-#include "PVViewer_ViewModel.h"
-#include "PVViewer_GUIElements.h"
+#include <PVViewer_ViewModel.h>
+#include <PVViewer_GUIElements.h>
 #endif
 
-
 #include "MEDFactoryClient.hxx"
 #include "MEDPresentationManager_i.hxx"
-#include <QTimer>
 
+#include <QTimer>
 #include <sstream>
 
 #include <pqAnimationManager.h>
 #include <pqPVApplicationCore.h>
 
-
 //! The only instance of the reference to engine
 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
-//! The only instance of the MEDPresentationManager
-MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager;
 
 MEDModule::MEDModule() :
-  SalomeApp_Module("MED"), _studyEditor(0),
+  SalomeApp_Module("FIELDS"), _studyEditor(0),
   _datasourceController(0), _workspaceController(0), _presentationController(0),
   _processingController(0), _pvGuiElements(0)
 {
+  STDLOG("MEDModule::MEDModule()");
   // Note also that we can't use the getApp() function here because
   // the initialize(...) function has not been called yet.
 
@@ -74,6 +71,12 @@ MEDModule::MEDModule() :
 
 MEDModule::~MEDModule()
 {
+  // Clean up engine:
+  STDLOG("MEDModule::~MEDModule(): cleaning up engine side.");
+  _MED_engine->cleanUp();
+  MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
+  MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
+
   if (_studyEditor)
     delete _studyEditor;
   if (_datasourceController)
@@ -96,17 +99,16 @@ MEDModule::engine()
 void
 MEDModule::init()
 {
-  // initialize MED module engine (load, if necessary)
+  // initialize FIELDS module engine (load, if necessary)
   if ( CORBA::is_nil( _MED_engine ) ) {
     Engines::EngineComponent_var comp =
-      SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
+      SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "FIELDS" );
+    if (CORBA::is_nil( comp ))
+        STDLOG("Could not FindOrLoad_Component FIELDS");
     _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
+    if (CORBA::is_nil( _MED_engine ))
+        STDLOG("Could not narrow FIELDS engine");
   }
-
-  // Retrieve MEDFactory to get MEDPresentationManager (sometimes
-  if ( ! _presManager ) {
-      _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
-    }
 }
 
 //void MEDModule::onEventLoopStarted()
@@ -121,9 +123,13 @@ MEDModule::init()
 void
 MEDModule::initialize( CAM_Application* app )
 {
+  STDLOG("MEDModule::initialize()");
   // call the parent implementation
   SalomeApp_Module::initialize( app );
 
+  if (! getApp()->objectBrowser())
+    getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser);
+
   getApp()->objectBrowser()->setAutoOpenLevel(5);
 
   if (app && app->desktop()) {
@@ -136,6 +142,10 @@ MEDModule::initialize( CAM_Application* app )
   // The following initializes the GUI widget and associated actions
   this->createModuleWidgets();
   this->createModuleActions();
+
+  // Now that the workspace controller is created, ParaView core application has normally been started,
+  // and hidden GUI elements have been created.  We can fire the VCR toolbar activation:
+  initToolbars();
 }
 
 QString
@@ -155,6 +165,7 @@ MEDModule::iconName() const
 void
 MEDModule::windows( QMap<int, int>& theMap ) const
 {
+  STDLOG("MEDModule::windows()");
   // want Object browser, in the left area
   theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
                  Qt::LeftDockWidgetArea );
@@ -194,6 +205,7 @@ MEDModule::createPreferences()
 bool
 MEDModule::activateModule( SUIT_Study* theStudy )
 {
+  STDLOG("MEDModule::activateModule()");
   if ( CORBA::is_nil( _MED_engine ) )
     return false;
 
@@ -223,6 +235,7 @@ MEDModule::activateModule( SUIT_Study* theStudy )
 bool
 MEDModule::deactivateModule( SUIT_Study* theStudy )
 {
+  STDLOG("MEDModule::deactivateModule()");
   _workspaceController->showDockWidgets(false);
   _presentationController->showDockWidgets(false);
   //this->unsetDockLayout();
@@ -257,6 +270,8 @@ MEDModule::createModuleWidgets() {
   _xmedDataModel  = new XmedDataModel();
   _workspaceController->setDataModel(_xmedDataModel);
   _presentationController = new PresentationController(this);
+  // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
+  _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
   _processingController = new ProcessingController(this);
 #ifdef MED_HAS_QTTESTING
   _testController = new TestController(this);
@@ -266,7 +281,7 @@ MEDModule::createModuleWidgets() {
     _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
 
   connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
-    _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
+    _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
 
   connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
     _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
@@ -276,11 +291,6 @@ MEDModule::createModuleWidgets() {
 
   connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
     _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
-
-
-  // Now that the workspace controller is created, ParaView core application has normally been started,
-  // and hidden GUI elements have been created.  We can fire the VCR toolbar activation:
-  initToolbars();
 }
 
 void
@@ -335,7 +345,7 @@ MEDModule::createStandardAction(const QString& label,
   if (iconName.isEmpty())
     ico = QIcon();
   else
-    ico = QIcon(resMgr->loadPixmap("MED", iconName));
+    ico = QIcon(resMgr->loadPixmap("FIELDS", iconName));
 
   QAction* action = createAction(-1,
                                  label,
@@ -367,20 +377,31 @@ MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString&
   mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
 }
 
-MEDCALC::MEDPresentationViewMode
-MEDModule::getSelectedViewMode()
-{
-  return _presentationController->getSelectedViewMode();
-}
+//MEDCALC::ViewModeType
+//MEDModule::getSelectedViewMode() const
+//{
+//  return _presentationController->getSelectedViewMode();
+//}
+//
+//MEDCALC::ColorMapType
+//MEDModule::getSelectedColorMap() const
+//{
+//  return _presentationController->getSelectedColorMap();
+//}
+//
+//MEDCALC::ScalarBarRangeType
+//MEDModule::getSelectedScalarBarRange() const
+//{
+//  return _presentationController->getSelectedScalarBarRange();
+//}
 
-MEDCALC::MEDPresentationColorMap
-MEDModule::getSelectedColorMap()
-{
-  return _presentationController->getSelectedColorMap();
-}
 
+/**
+ * Returns presentation name, type and ID from the currently selected presentation in the object
+ * browser.
+ */
 bool
-MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const
+MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
 {
   DataObjectList dol = getApp()->objectBrowser()->getSelected();
   if (dol.isEmpty())
@@ -392,7 +413,7 @@ MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int &
   if (!model)
     return false;
 
-  if (item->componentDataType().toStdString() != "MED")
+  if (item->componentDataType().toStdString() != "FIELDS")
     return false;
   _PTR(SObject) obj = item->object();
   _PTR(GenericAttribute) anAttribute;
@@ -409,55 +430,57 @@ MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int &
       || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
       return false;
   }
-  if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
-    return false;
-  fieldId = attrParam->GetInt(FIELD_ID);
+//  if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
+//    return false;
+//  fieldId = attrParam->GetInt(FIELD_ID);
   if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
       return false;
   presId = attrParam->GetInt(PRESENTATION_ID);
+  if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
+    return false;
+  type = attrParam->GetString(PRESENTATION_TYPE);
   return true;
 }
 
 void
 MEDModule::onClick(const QModelIndex & index)
 {
-  int fieldId, presId;
-  std::string name;
-  if (!itemClickGeneric(index, name, fieldId, presId))
-    return;
+  int presId;
+  std::string name, type;
+  if (!itemClickGeneric(name, type, presId))
+    {
+      // Not a presentation - clear widget:
+      emit presentationSelected(-1, QString(""), QString(""));
+      return;
+    }
 
-  STDLOG("Presentation selection (activate view)");
-  std::ostringstream oss;
-  oss << fieldId << " / " << presId;
-  STDLOG("    - Field id / pres id:   " + oss.str());
-  STDLOG("    - Presentation name: " + name);
+//  STDLOG("Presentation selection");
+//  std::ostringstream oss;
+//  oss << fieldId << " / " << presId;
+//  STDLOG("    - Field id / pres id:   " + oss.str());
+//  STDLOG("    - Presentation type: " + type);
+//  STDLOG("    - Presentation name: " + name);
 
-  _presManager->activateView(presId);
+  emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) );  // caught by PresentationController
 }
 
 void
 MEDModule::onDblClick(const QModelIndex& index)
 {
-  int fieldId, presId;
-  std::string name;
-  if (!itemClickGeneric(index, name, fieldId, presId))
+  int presId;
+  std::string name, type;
+  if (!itemClickGeneric(name, type, presId))
     return;
 
-  STDLOG("Presentation edition: NOT IMPLEMENTED YET");
-  STDLOG("  Presention infos:");
+//  STDLOG("Presentation double click");
+//  STDLOG("  Presentation infos:");
 //  STDLOG("    - Component:         " + item->componentDataType().toStdString());
 //  STDLOG("    - Item entry:        " + item->entry().toStdString());
 //  STDLOG("    - Item name:         " + item->name().toStdString());
-  std::ostringstream oss;
-  oss << fieldId;
-  STDLOG("    - Field id:          " + oss.str());
-  STDLOG("    - Presentation name: " + name);
-
-  // :TODO:
-  // get edited values from a popup widget
-  // get presentation
-  // call presentation edit function
-
+//  std::ostringstream oss;
+//  oss << fieldId;
+//  STDLOG("    - Field id:          " + oss.str());
+//  STDLOG("    - Presentation name: " + name);
 }
 
 void
@@ -472,3 +495,19 @@ MEDModule::requestSALOMETermination() const
 //{
 //  return _eventLoopStarted;
 //}
+
+int
+MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name)
+{
+  if (obj->_is_nil())
+    return -1;
+
+  SALOMEDS::GenericAttribute_var anAttr;
+  SALOMEDS::AttributeParameter_var aParam;
+  if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
+    aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
+    if (aParam->IsSet(name, PT_INTEGER))
+      return aParam->GetInt(name);
+  }
+  return -1;
+}