Salome HOME
Update presentations
authorCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 21 Jan 2016 15:20:53 +0000 (16:20 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 21 Jan 2016 15:20:53 +0000 (16:20 +0100)
18 files changed:
src/MEDCalc/cmp/CMakeLists.txt
src/MEDCalc/cmp/MEDPresentation.cxx
src/MEDCalc/cmp/MEDPresentation.hxx
src/MEDCalc/cmp/MEDPresentationContour.hxx
src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx
src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx
src/MEDCalc/cmp/MEDPresentationException.hxx [new file with mode: 0644]
src/MEDCalc/cmp/MEDPresentationManager_i.cxx
src/MEDCalc/cmp/MEDPresentationManager_i.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.txx [new file with mode: 0644]
src/MEDCalc/cmp/MEDPresentationPointSprite.cxx
src/MEDCalc/cmp/MEDPresentationPointSprite.hxx
src/MEDCalc/cmp/MEDPresentationScalarMap.cxx
src/MEDCalc/cmp/MEDPresentationScalarMap.hxx
src/MEDCalc/cmp/MEDPresentationSlices.hxx
src/MEDCalc/cmp/MEDPresentationVectorField.cxx
src/MEDCalc/cmp/MEDPresentationVectorField.hxx
src/MEDCalc/tui/medpresentation.py

index 51ecc910463e66d1cf404598b83fc26af784874c..2ba66eb94eb9542d25fc9f4687db0599e5ca3da3 100644 (file)
@@ -88,6 +88,8 @@ INSTALL(TARGETS MEDEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME
 
 FILE(GLOB MEDCALC_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
 INSTALL(FILES ${MEDCALC_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
+FILE(GLOB MEDCALC_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
+INSTALL(FILES ${MEDCALC_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
 
 IF(SALOME_ENABLE_PYTHON)
   INSTALL(FILES test_medcalc_components.py PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${SALOME_INSTALL_BINS}/xmed)
index 5ce06a7071e86428e250262fc9e81bf9838cea55..846bac683af7d2ab48add376d726143af02c1573 100644 (file)
 
 #include "MEDFactoryClient.hxx"
 #include "MEDPresentation.hxx"
+#include "MEDPresentationException.hxx"
 #include "MEDCouplingRefCountObject.hxx"
 #include <iostream>
 
-MEDPresentation::MEDPresentation(MEDCALC::FieldHandler* fieldHdl, std::string name)
-    : _fieldHandler(fieldHdl), _pipeline(0), _display(0), _properties()
+MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name)
+    : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
 {
+  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
+  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
+  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
+  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
+
+  _fileName = dataSHandler->uri;
+  _fieldName = fieldHandler->fieldname;
+  _fieldType = getFieldTypeString((ParaMEDMEM::TypeOfField) fieldHandler->type);
+
+  if (_fileName.substr(0, 7) != std::string("file://")) {
+    const char* msg = "Data source is not a file! Can not proceed.";
+    throw MEDPresentationException(msg);
+  }
+  _fileName = _fileName.substr(7, _fileName.size());
+
   setProperty("name", name);
 }
 
@@ -75,15 +91,14 @@ PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var)
   return PyDict_GetItemString(global_dict, python_var);
 }
 
-std::string MEDPresentation::getFieldTypeString()
+std::string MEDPresentation::getFieldTypeString(ParaMEDMEM::TypeOfField fieldType)
 {
-  ParaMEDMEM::TypeOfField typ = (ParaMEDMEM::TypeOfField)_fieldHandler->type;
-  switch(typ)
+  switch(fieldType)
   {
     case ParaMEDMEM::ON_CELLS:
       return "CELLS";
     case ParaMEDMEM::ON_NODES:
-      return "NODES";
+      return "POINTS";
     default:
       std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?";
       return "";
index f99702a407f5cb1dc93240ab5cfebc2d206ef97e..9f5f3fdab779cf175482c442d60dd2eeac025d1b 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
 
+#include "MEDCouplingRefCountObject.hxx"
 #include <Python.h>
 #include "MEDCALC.hxx"
 
@@ -38,25 +39,35 @@ class MEDCALC_EXPORT MEDPresentation
 
 public:
 
+  typedef ::CORBA::Long TypeID;
+
   virtual ~MEDPresentation() {}
 
   void setProperty(const std::string& propName, const std::string& propValue);
   const std::string getProperty(const std::string& propName);
-  std::string getFieldTypeString();
 
 protected:
 
-  MEDPresentation(MEDCALC::FieldHandler* fieldHdl, std::string name);
+  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name);
 
-  void generatePipeline();
   virtual void internalGeneratePipeline() = 0;
   PyObject * getPythonObjectFromMain(const char * var);
   void pushInternal(PyObject * obj, PyObject * disp = NULL);
 
+private:
+
+  void generatePipeline(); // reserved to friend class MEDPresentationManager
+  std::string getFieldTypeString(ParaMEDMEM::TypeOfField fieldType);
+
 protected:
 
-  ///! field reference - borrowed.
-  MEDCALC::FieldHandler* _fieldHandler;
+  std::string _fileName;
+  std::string _fieldName;
+  std::string _fieldType;
+
+private:
+
+  MEDPresentation::TypeID _fieldHandlerId;
 
   ///! Pipeline elements
   std::vector< PyObject * > _pipeline;
index 56c7a01f6c5413760d9ed6542c50799e5187148b..9a800d783a7885856137078d7739024c3a8b2817 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation
 {
 public:
-  MEDPresentationContour(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationContour"),
-    _isWireframe(wireframe)
+  MEDPresentationContour(const MEDCALC::ContourParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationContour")
   {}
   virtual ~MEDPresentationContour() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::ContourParameters _params;
 };
 
 #endif
index ab15b5252a40be1ff79f52ace08f74285fd79cd3..491b0bc847d728f86d865c48dcf6c32cfe44db28 100644 (file)
@@ -1,7 +1,25 @@
 #include "MEDPresentationDeflectionShape.hxx"
-#include "MEDFactoryClient.hxx"
 
 void
 MEDPresentationDeflectionShape::internalGeneratePipeline()
 {
+  PyGILState_STATE _gil_state = PyGILState_Ensure();
+
+  std::string cmd = std::string("import pvsimple as pvs;");
+  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+  cmd += std::string("__warpByVector1 = pvs.WarpByVector(Input=__obj1);");
+  cmd += std::string("__disp1 = pvs.Show(__warpByVector1);");
+  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+  cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
+  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+
+  //std::cerr << "Python command:" << std::endl;
+  //std::cerr << cmd << std::endl;
+  PyRun_SimpleString(cmd.c_str());
+  // Retrieve Python object for internal storage:
+  PyObject * obj = getPythonObjectFromMain("__warpByVector1");
+  PyObject * disp = getPythonObjectFromMain("__disp1");
+  pushInternal(obj, disp);
+
+  PyGILState_Release(_gil_state);
 }
index b46db997c87a1adbeaddb7322fb5d1e7c412975e..60278e1ba539bb5552b246510750ffe31c6be789 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationDeflectionShape : public MEDPresentation
 {
 public:
-  MEDPresentationDeflectionShape(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationDeflectionShape"),
-    _isWireframe(wireframe)
+  MEDPresentationDeflectionShape(const MEDCALC::DeflectionShapeParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationDeflectionShape")
   {}
   virtual ~MEDPresentationDeflectionShape() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::DeflectionShapeParameters _params;
 };
 
 #endif
diff --git a/src/MEDCalc/cmp/MEDPresentationException.hxx b/src/MEDCalc/cmp/MEDPresentationException.hxx
new file mode 100644 (file)
index 0000000..542ce33
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2011-2016  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_EXCEPTION_HXX_
+#define SRC_MEDCALC_CMP_MEDPRESENTATION_EXCEPTION_HXX_
+
+#include "MEDCALC.hxx"
+#include <iostream>
+#include <sstream>
+#include <exception>
+
+class MEDCALC_EXPORT MEDPresentationException
+  : public std::exception
+{
+public:
+
+  MEDPresentationException(const char* msg) {
+    std::ostringstream oss;
+    oss << "Error: " << msg;
+    this->_msg = oss.str();
+  }
+
+  virtual ~MEDPresentationException() throw() {}
+
+  virtual const char* what() const throw() {
+    return this->_msg.c_str();
+  }
+
+private:
+
+  std::string _msg;
+
+};
+
+#endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_EXCEPTION_HXX_ */
index 35d6424ab44c9d03cc97a74815e27a7314f10e0b..b6c9ba970a8d378e7d0503d4a99a4a154646ecfb 100644 (file)
@@ -19,7 +19,8 @@
 
 #include "MEDPresentationManager_i.hxx"
 #include "MEDFactoryClient.hxx"
-#include "MEDPresentation.hxx"
+
+// presentations
 #include "MEDPresentationScalarMap.hxx"
 #include "MEDPresentationContour.hxx"
 #include "MEDPresentationVectorField.hxx"
@@ -27,6 +28,8 @@
 #include "MEDPresentationDeflectionShape.hxx"
 #include "MEDPresentationPointSprite.hxx"
 
+#include <iostream>
+
 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
 
 MEDPresentationManager_i*
@@ -52,17 +55,16 @@ MEDPresentationManager_i::~MEDPresentationManager_i()
   */
 }
 
-TypeID MEDPresentationManager_i::GenerateID()
+MEDPresentation::TypeID
+MEDPresentationManager_i::GenerateID()
 {
-  static TypeID START_ID = -1;
+  static MEDPresentation::TypeID START_ID = -1;
   START_ID++;
   return START_ID;
 }
 
-#include <iostream>
-
 void
-MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue)
+MEDPresentationManager_i::setPresentationProperty(MEDPresentation::TypeID presentationID, const char * propName, const char * propValue)
 {
   if (_presentations.find(presentationID) != _presentations.end())
     {
@@ -76,7 +78,7 @@ MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const c
 }
 
 char*
-MEDPresentationManager_i::getPresentationProperty(TypeID presentationID, const char* propName)
+MEDPresentationManager_i::getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName)
 {
   if (_presentations.find(presentationID) != _presentations.end()) {
     MEDPresentation* pres = _presentations[presentationID];
@@ -88,164 +90,38 @@ MEDPresentationManager_i::getPresentationProperty(TypeID presentationID, const c
   }
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationScalarMap * presentation = new MEDPresentationScalarMap(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationScalarMap>(params);
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationContour * presentation = new MEDPresentationContour(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationContour>(params);
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationVectorField * presentation = new MEDPresentationVectorField(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationVectorField>(params);
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationSlices * presentation = new MEDPresentationSlices(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationSlices>(params);
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationDeflectionShape * presentation = new MEDPresentationDeflectionShape(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationDeflectionShape>(params);
 }
 
-TypeID
+MEDPresentation::TypeID
 MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  TypeID fieldHandlerId = params.fieldHandlerId;
-  MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
-  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
-  std::cout << "\tviewMode: " << viewMode << std::endl;
-  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
-  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
-
-  // Create a new presentation instance
-  TypeID newID = MEDPresentationManager_i::GenerateID();
-  MEDPresentationPointSprite * presentation = new MEDPresentationPointSprite(fieldHandler, true);  // on stack or on heap?? stack for now
-  _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
-
-  presentation->generatePipeline();
-
-  return newID;
+  return _makePresentation<MEDPresentationPointSprite>(params);
 }
index 61349eb79ecdabfd4feb376d82a645efef5eb4fe..5af811002f60044a3aecea53b91a22df5e856bfe 100644 (file)
 #include "SALOME_GenericObj_i.hh"
 
 #include "MEDDataManager_i.hxx"
+#include "MEDPresentation.hxx"
 #include "MEDCALC.hxx"
 
 #include <vector>
 #include <string>
 
-typedef ::CORBA::Long TypeID;
-
-class MEDPresentation;
-
 class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
                                                public SALOME::GenericObj_i
 {
@@ -42,30 +39,37 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
 
   static MEDPresentationManager_i* getInstance();
 
-  MEDCALC_EXPORT TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&);
-  MEDCALC_EXPORT TypeID makeContour(const MEDCALC::ContourParameters&);
-  MEDCALC_EXPORT TypeID makeVectorField(const MEDCALC::VectorFieldParameters&);
-  MEDCALC_EXPORT TypeID makeSlices(const MEDCALC::SlicesParameters&);
-  MEDCALC_EXPORT TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&);
-  MEDCALC_EXPORT TypeID makePointSprite(const MEDCALC::PointSpriteParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&);
+  MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&);
 
-  MEDCALC_EXPORT void setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue);
-  MEDCALC_EXPORT char* getPresentationProperty(TypeID presentationID, const char* propName);
+  MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID presentationID, const char * propName, const char * propValue);
+  MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName);
 
  private:
   MEDPresentationManager_i();
   virtual ~MEDPresentationManager_i();
 
+  static MEDPresentation::TypeID GenerateID();
+
+  // Create a new presentation instance and return its unique ID
+  template<typename PresentationType, typename PresentationParameters>
+  MEDPresentation::TypeID _makePresentation(PresentationParameters params);
+
  private :
 
   // The MEDPresentationManager is a singleton, whose instance can be obtained
   // using the getInstance static method.
   static MEDPresentationManager_i * _instance;
-  static TypeID GenerateID();
 
   // Owns a list of MEDPresentation objects
-  std::map< TypeID, MEDPresentation * > _presentations;
+  std::map< MEDPresentation::TypeID, MEDPresentation * > _presentations;
 
 };
 
+#include "MEDPresentationManager_i.txx"
+
 #endif // _MED_PRESENTATION_MANAGER_I_HXX_
diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx
new file mode 100644 (file)
index 0000000..79eee1a
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2007-2016  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef _MED_PRESENTATION_MANAGER_I_TPP_
+#define _MED_PRESENTATION_MANAGER_I_TPP_
+
+template<typename PresentationType, typename PresentationParameters>
+MEDPresentation::TypeID
+MEDPresentationManager_i::_makePresentation(PresentationParameters params)
+{
+  // Create a new presentation instance
+  PresentationType* presentation = NULL;
+  try {
+    presentation = new PresentationType(params);  // on stack or on heap?? stack for now
+  }
+  catch (const std::exception& e) {
+    std::cerr << e.what() << std::endl;
+    return -1;
+  }
+
+  MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
+  _presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
+  presentation->generatePipeline();
+  return newID;
+}
+
+#endif // _MED_PRESENTATION_MANAGER_I_TPP_
index 06d8847c038d6348bd34cb38ec1133cafd79c92b..a65ebd82d89423019c12ac5d3b734c9d973a91d5 100644 (file)
@@ -1,7 +1,25 @@
 #include "MEDPresentationPointSprite.hxx"
-#include "MEDFactoryClient.hxx"
 
 void
 MEDPresentationPointSprite::internalGeneratePipeline()
 {
+  PyGILState_STATE _gil_state = PyGILState_Ensure();
+
+  std::string cmd = std::string("import pvsimple as pvs;");
+  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+  cmd += std::string("__disp1 = pvs.Show(__obj1);");
+  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+  cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
+  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+  cmd += std::string("__disp1.SetRepresentationType('Point Sprite');");
+
+  //std::cerr << "Python command:" << std::endl;
+  //std::cerr << cmd << std::endl;
+  PyRun_SimpleString(cmd.c_str());
+  // Retrieve Python object for internal storage:
+  PyObject * obj = getPythonObjectFromMain("__obj1");
+  PyObject * disp = getPythonObjectFromMain("__disp1");
+  pushInternal(obj, disp);
+
+  PyGILState_Release(_gil_state);
 }
index e84b8563e5638f6514d8832ed8582600406dd11b..2b3f081d4ba1786e251226e9c7e9a0c3c5952ef7 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationPointSprite : public MEDPresentation
 {
 public:
-  MEDPresentationPointSprite(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationPointSprite"),
-    _isWireframe(wireframe)
+  MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationPointSprite")
   {}
   virtual ~MEDPresentationPointSprite() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::PointSpriteParameters _params;
 };
 
 #endif
index 17caf4366d6b9d7f8fb2b0e76315e6f58bdf017c..0beac00ac6633b055eea35309173a9f0e6b137f5 100644 (file)
@@ -1,38 +1,32 @@
 #include "MEDPresentationScalarMap.hxx"
-#include "MEDFactoryClient.hxx"
-
-#include <iostream>
 
 void
 MEDPresentationScalarMap::internalGeneratePipeline()
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
+  //MEDPresentation::TypeID fieldHandlerId = params.fieldHandlerId;
+  //MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
 
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(_fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
+  // :TODO: consider viewMode
 
-  std::string fileName(dataSHandler->uri);
-  std::string fieldName(_fieldHandler->fieldname);
-  std::string fieldType = getFieldTypeString();
+  /*
+  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
+  MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
 
-  std::cout << "Generating pipeline for SCALAR MAP:" <<std::endl;
-  std::cout << "\tfileName: " <<  fileName << std::endl;
-  std::cout << "\tfiedName: " << fieldName << std::endl;
-  if (fileName.substr(0, 7) != std::string("file://"))
-    {
-      std::cerr << "\tData source is not a file! Can not proceed." << std::endl;
-      return;
-    }
+  std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
+  std::cout << "\tviewMode: " << viewMode << std::endl;
 
-  fileName = fileName.substr(7, fileName.size());
-  std::cout << "\tfileName: " <<  fileName << std::endl;
+  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
+  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
+  std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
+  std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
+  */
 
   PyGILState_STATE _gil_state = PyGILState_Ensure();
 
   std::string cmd = std::string("import pvsimple as pvs;");
-  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + fileName + std::string("');");
+  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
   cmd += std::string("__disp1 = pvs.Show(__obj1);");
-  cmd += std::string("pvs.ColorBy(__disp1, ('") + fieldType + std::string("', '") + fieldName + std::string("'));");
+  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
   cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
   cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
 
index ed9a4adcf613846e44528deef284da980191e2b9..d33f610267e244b87949e844f80ef744b701b7b9 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationScalarMap : public MEDPresentation
 {
 public:
-  MEDPresentationScalarMap(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationScalarMap"),
-    _isWireframe(wireframe)
+  MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationScalarMap")
   {}
   virtual ~MEDPresentationScalarMap() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::ScalarMapParameters _params;
 };
 
 #endif
index ed747a478418532db44bb30370ab0338f5bc544e..ebabec934d3b1cbd9d2b09af953c3bd798b659ca 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationSlices : public MEDPresentation
 {
 public:
-  MEDPresentationSlices(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationSlices"),
-    _isWireframe(wireframe)
+  MEDPresentationSlices(const MEDCALC::SlicesParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationSlices")
   {}
   virtual ~MEDPresentationSlices() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::SlicesParameters _params;
 };
 
 #endif
index 48cc1371a5d8182ad1ece723dcd762064e297031..f8d94a5e8792e60e1095a116b3a6075b15af5fbe 100644 (file)
@@ -1,7 +1,25 @@
 #include "MEDPresentationVectorField.hxx"
-#include "MEDFactoryClient.hxx"
 
 void
 MEDPresentationVectorField::internalGeneratePipeline()
 {
+  PyGILState_STATE _gil_state = PyGILState_Ensure();
+
+  std::string cmd = std::string("import pvsimple as pvs;");
+  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+  cmd += std::string("__disp1 = pvs.Show(__obj1);");
+  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+  cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
+  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+  cmd += std::string("__disp1.SetRepresentationType('3D Glyphs');");
+
+  //std::cerr << "Python command:" << std::endl;
+  //std::cerr << cmd << std::endl;
+  PyRun_SimpleString(cmd.c_str());
+  // Retrieve Python object for internal storage:
+  PyObject * obj = getPythonObjectFromMain("__obj1");
+  PyObject * disp = getPythonObjectFromMain("__disp1");
+  pushInternal(obj, disp);
+
+  PyGILState_Release(_gil_state);
 }
index a18816bbedd948ea2f3528a0e8d6e6424175695b..f67bd9b16ab4a3ed19ebd51486b382b26ab368d3 100644 (file)
@@ -25,9 +25,8 @@
 class MEDCALC_EXPORT MEDPresentationVectorField : public MEDPresentation
 {
 public:
-  MEDPresentationVectorField(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationVectorField"),
-    _isWireframe(wireframe)
+  MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params) :
+    MEDPresentation(params.fieldHandlerId, "MEDPresentationVectorField")
   {}
   virtual ~MEDPresentationVectorField() {}
 
@@ -35,7 +34,7 @@ protected:
   virtual void internalGeneratePipeline();
 
 private:
-  bool _isWireframe;
+  MEDCALC::VectorFieldParameters _params;
 };
 
 #endif
index a6177f730e996bf4dc46290f1e0a2948dcf62515..7c665b505220a0cc7075aae54d222d3e5fd29eb1 100644 (file)
@@ -44,10 +44,9 @@ def MakeContour(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
 #
 
 def MakeVectorField(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
-  print "Not implemented yet"
-  #params = MEDCALC.VectorFieldParameters(proxy.id, viewMode)
-  #presentation_id = __manager.makeVectorField(params)
-  #notifyGui_addPresentation(proxy.id, presentation_id)
+  params = MEDCALC.VectorFieldParameters(proxy.id, viewMode)
+  presentation_id = __manager.makeVectorField(params)
+  notifyGui_addPresentation(proxy.id, presentation_id)
 #
 
 def MakeSlices(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
@@ -58,15 +57,13 @@ def MakeSlices(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
 #
 
 def MakeDeflectionShape(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
-  print "Not implemented yet"
-  #params = MEDCALC.DeflectionShapeParameters(proxy.id, viewMode)
-  #presentation_id = __manager.makeDeflectionShape(params)
-  #notifyGui_addPresentation(proxy.id, presentation_id)
+  params = MEDCALC.DeflectionShapeParameters(proxy.id, viewMode)
+  presentation_id = __manager.makeDeflectionShape(params)
+  notifyGui_addPresentation(proxy.id, presentation_id)
 #
 
 def MakePointSprite(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE):
-  print "Not implemented yet"
-  #params = MEDCALC.PointSpriteParameters(proxy.id, viewMode)
-  #presentation_id = __manager.makePointSprite(params)
-  #notifyGui_addPresentation(proxy.id, presentation_id)
+  params = MEDCALC.PointSpriteParameters(proxy.id, viewMode)
+  presentation_id = __manager.makePointSprite(params)
+  notifyGui_addPresentation(proxy.id, presentation_id)
 #