Salome HOME
Merge 'abn/V8_1_fix' branch into V8_1_BR.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.cxx
index 563979e1686ca94275cdea9f42ae200f5a38798e..6317ed3e44952dbcb99300aaa5add7b6fb89ee72 100644 (file)
 
 #include "MEDPresentationManager_i.hxx"
 #include "MEDFactoryClient.hxx"
+#include "Basics_Utils.hxx"
 
 // presentations
+#include "MEDPresentationMeshView.hxx"
 #include "MEDPresentationScalarMap.hxx"
 #include "MEDPresentationContour.hxx"
-#include "MEDPresentationVectorField.hxx"
 #include "MEDPresentationSlices.hxx"
+#include "MEDPresentationVectorField.hxx"
 #include "MEDPresentationDeflectionShape.hxx"
 #include "MEDPresentationPointSprite.hxx"
 
+#include <SALOME_KernelServices.hxx>
+
 #include <iostream>
+#include <sstream>
 
 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
 
@@ -39,7 +44,9 @@ MEDPresentationManager_i::getInstance() {
   return _instance;
 }
 
-MEDPresentationManager_i::MEDPresentationManager_i()
+MEDPresentationManager_i::MEDPresentationManager_i() :
+    _presentations(),
+    _activeViewPythonId(-1)
 {
 }
 
@@ -73,62 +80,156 @@ MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationI
 }
 
 void
-MEDPresentationManager_i::setPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
+MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
 {
   MEDPresentation* pres = _getPresentation(presentationID);
   if (pres)
-    pres->setProperty(propName, propValue);
+    pres->setStringProperty(propName, propValue);
   else
-    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
+    throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
 }
 
 char*
-MEDPresentationManager_i::getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName)
+MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
 {
   MEDPresentation* pres = _getPresentation(presentationID);
   if (pres) {
-    return (char*) pres->getProperty(propName).c_str();
+    return (char*) pres->getStringProperty(propName).c_str();
   }
-  else {
-    std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl;
-    return (char*) "";
+  else
+    throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
+}
+
+void
+MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
+                                                     const CORBA::Long propValue)
+{
+  MEDPresentation* pres = _getPresentation(presentationID);
+  if (pres)
+    pres->setIntProperty(propName, propValue);
+  else
+    throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
+}
+
+CORBA::Long
+MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
+{
+  MEDPresentation* pres = _getPresentation(presentationID);
+  if (pres) {
+    return (CORBA::Long) pres->getIntProperty(propName);
   }
+  else
+    throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
+
+}
+
+MEDPresentation::TypeID
+MEDPresentationManager_i::makeMeshView(const MEDCALC::MeshViewParameters& params, const MEDCALC::ViewModeType viewMode)
+{
+  return _makePresentation<MEDPresentationMeshView>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params)
+MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::ViewModeType viewMode)
 {
-  return _makePresentation<MEDPresentationScalarMap>(params);
+  return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
+MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::ViewModeType viewMode)
 {
-  return _makePresentation<MEDPresentationContour>(params);
+  return _makePresentation<MEDPresentationContour>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
+MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode)
 {
-  return _makePresentation<MEDPresentationVectorField>(params);
+  return _makePresentation<MEDPresentationVectorField>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
+MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::ViewModeType viewMode)
 {
-  return _makePresentation<MEDPresentationSlices>(params);
+  return _makePresentation<MEDPresentationSlices>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
+MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params, const MEDCALC::ViewModeType viewMode)
 {
-  return _makePresentation<MEDPresentationDeflectionShape>(params);
+  return _makePresentation<MEDPresentationDeflectionShape>(params, viewMode);
 }
 
 MEDPresentation::TypeID
-MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
+MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode)
+{
+  return _makePresentation<MEDPresentationPointSprite>(params, viewMode);
+}
+
+MEDCALC::MeshViewParameters
+MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::MeshViewParameters p;
+  _getParameters<MEDPresentationMeshView>(presentationID, p);
+  return p;
+}
+
+
+MEDCALC::ScalarMapParameters*
+MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
+  _getParameters<MEDPresentationScalarMap>(presentationID, *p);
+  MEDCALC::ScalarMapParameters_var tmp(p);
+  return tmp._retn();
+}
+
+MEDCALC::ContourParameters
+MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::ContourParameters p;
+  _getParameters<MEDPresentationContour>(presentationID, p);
+  return p;
+}
+
+MEDCALC::SlicesParameters*
+MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
+  _getParameters<MEDPresentationSlices>(presentationID, *p);
+  MEDCALC::SlicesParameters_var tmp(p);
+  return tmp._retn();
+}
+
+MEDCALC::VectorFieldParameters
+MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
 {
-  return _makePresentation<MEDPresentationPointSprite>(params);
+  MEDCALC::VectorFieldParameters p;
+  _getParameters<MEDPresentationVectorField>(presentationID, p);
+  return p;
+}
+
+MEDCALC::PointSpriteParameters*
+MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
+  _getParameters<MEDPresentationPointSprite>(presentationID, *p);
+  MEDCALC::PointSpriteParameters_var tmp(p);
+  return tmp._retn();
+}
+
+MEDCALC::DeflectionShapeParameters
+MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::DeflectionShapeParameters p;
+  _getParameters<MEDPresentationDeflectionShape>(presentationID, p);
+  return p;
+}
+
+
+void
+MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
+{
+  return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
 }
 
 void
@@ -179,6 +280,8 @@ MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentatio
   if (presentation)
     delete presentation;
   _presentations.erase(presentationID);
+
+  STDLOG("Presentation " << presentationID << " has been removed.");
   return true;
 }
 
@@ -187,19 +290,79 @@ MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
 {
   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
   if (citr == _presentations.end()) {
-    std::cerr << "getPresentationPyViewId(): presentation not found!!" << std::endl;
+    std::cerr << "activateView(): presentation not found!!" << std::endl;
     return false;
   }
   MEDPresentation* presentation = (*citr).second;
 
-  presentation->activateView();
+  if (!presentation->activateView())
+    {
+      // The view has been recreated - transfer all presentations that were in the deleted view to this new one
+      int viewId = presentation->getPyViewID();
+      std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator citr = _presentations.begin();
+      for (; citr != _presentations.end(); ++citr)
+        {
+          if(citr->second->getPyViewID() == viewId)
+            citr->second->recreateViewSetup();
+        }
+    }
+  _activeViewPythonId = presentation->getPyViewID();
+  STDLOG("Activated view " << _activeViewPythonId);
   return true;
 }
 
-MEDPresentation::TypeID
-MEDPresentationManager_i::_getActivePresentationId() const
+CORBA::Long
+MEDPresentationManager_i::getActiveViewPythonId()
+{
+  //TODO: should be more elaborate to re-identify the active ParaView view when another
+  //mechanism than MED module has activated another view.
+  // Idea: 1/ call Python to current active view
+  //       2/ compare with all id(__viewX) from currently existing presentations
+  return _activeViewPythonId;
+}
+
+
+//MEDCALC::ViewModeType
+//MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
+//{
+//  MEDPresentation* pres = _getPresentation(presentationID);
+//  if (pres) {
+//    return pres->getViewMode();
+//  } else {
+//    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
+//    return MEDCALC::VIEW_MODE_DEFAULT;
+//  }
+//}
+
+char *
+MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
+{
+  MEDPresentation* pres = _getPresentation(presentationID);
+  if (pres) {
+    return CORBA::string_dup(pres->paravisDump().c_str());
+  }
+  else
+    throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
+}
+
+MEDCALC::PresentationsList*
+MEDPresentationManager_i::getAllPresentations()
 {
-  // :TODO:
+  MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
+  presList->length(_presentations.size());
+  std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
+  int i;
+  for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
+    (*presList)[i] = it->first;
+  return presList;
+}
 
-  return -1;
+void
+MEDPresentationManager_i::cleanUp()
+{
+  _activeViewPythonId = -1;
+  std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator it;
+  for (it = _presentations.begin(); it != _presentations.end(); ++it)
+    delete(it->second);
+  _presentations.clear();
 }