Salome HOME
Fix of 0021175: EDF 1692 VISU: Scalar bar range is not good.
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.hxx
index bebb26f096e3f5f67ab41d21ed26f03d0741a983..99e778c587ce2994076116b7ac3de80ecee3c005 100644 (file)
-//  VISU CONVERTOR :
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  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.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  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. 
-// 
-//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  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
+//
+
+//  VISU CONVERTOR :
 //  File   : VISU_Convertor.hxx
 //  Author : Alexey PETROV
 //  Module : VISU
-
+//
 #ifndef VISU_Convertor_HeaderFile
 #define VISU_Convertor_HeaderFile
 
-#include <stdio.h>
-
-#include <list>
-#include <map>
-#include <set>
-#include <utility>
-#include <vector>
-#include <string>
-#include <stdexcept>
-
-#include <boost/shared_ptr.hpp>
-
-class vtkUnstructuredGrid;
-
-namespace VISU{
-
-  template<class T> class shared_ptr: public boost::shared_ptr<T>
-  {
-  public:
-    shared_ptr() {}
-
-    template<class Y>
-    explicit shared_ptr(Y * p)
-    {
-      reset(p);
-    }
-
-    template<class Y>
-    shared_ptr(shared_ptr<Y> const & r):
-      boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag())
-    {}
-
-    template<class Y>
-    shared_ptr & operator=(shared_ptr<Y> const & r)
-    {
-      shared_ptr<T>(r).swap(*this);
-      return *this;
-    }
-
-    template<class Y> shared_ptr& operator()(Y * p) // Y must be complete
-    {
-      if(T* pt = dynamic_cast<T*>(p))
-       boost::shared_ptr<T>::reset(pt);
-      else
-       boost::throw_exception(std::bad_cast());
-      return *this;
-    }
-
-  };
-
-
-  enum  TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
-
-  typedef std::pair<std::string,TEntity> TFamilyAndEntity;
-  typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
-  typedef std::set<std::string> TBindGroups;
-
-  typedef std::pair<double,std::string> TTime;
-
-  struct TMesh;
-  typedef shared_ptr<TMesh> PMesh;
-  typedef std::map<std::string,PMesh> TMeshMap;
-
-  struct TMeshOnEntity;
-  typedef shared_ptr<TMeshOnEntity> PMeshOnEntity;
-  typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
-
-  struct TFamily;
-  typedef shared_ptr<TFamily> PFamily;
-  typedef std::map<std::string,PFamily> TFamilyMap;
-
-  struct TGroup;
-  typedef shared_ptr<TGroup> PGroup;
-  typedef std::map<std::string,PGroup> TGroupMap;
-
-  struct TField;
-  typedef shared_ptr<TField> PField;
-  typedef std::map<std::string,PField> TFieldMap;
-
-  struct TValForTime;
-  typedef shared_ptr<TValForTime> PValForTime;
-  typedef std::map<int,PValForTime> TValField;
-
-  struct TBaseStructure{
-    virtual ~TBaseStructure(){}
-  };
-
-  typedef std::vector<std::string> TNames;
-
-  struct TMesh: TBaseStructure{
-    int myDim, myNbPoints;
-    std::string myName;
-
-    TMeshOnEntityMap myMeshOnEntityMap;
-    TGroupMap myGroupMap;
-
-    TMesh() : myDim(0), myNbPoints(0) {}
-    const PField GetField(const std::string& theFieldName) const;
-  };
-
-  struct TMeshOnEntity: TBaseStructure{
-    std::string myMeshName;
-    TEntity myEntity;
-    int myNbCells, myCellsSize;
-    TFamilyMap myFamilyMap;
-    TFieldMap myFieldMap;
-    TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
-
-    std::pair<int,int> 
-    GetCellsDims(const std::string& theFamilyName = "") const;
-  };
-
-  struct TFamily: TBaseStructure{
-    int myId;
-    std::string myName;
-    TEntity myEntity;
-    TBindGroups myGroups;
-    int myNbCells, myCellsSize;
-    TFamily() : myNbCells(0), myCellsSize(0) {}
-  };
-
-  struct TGroup: TBaseStructure{
-    std::string myName;
-    std::string myMeshName;
-    int myNbCells, myCellsSize;
-    TFamilyAndEntitySet myFamilyAndEntitySet;
-    TGroup() : myNbCells(0), myCellsSize(0) {}
-  };
-
-  struct TField: TBaseStructure{
-    int myId;
-    TEntity myEntity;
-    bool myIsTrimmed;
-    std::string myName;
-    std::string myMeshName;
-    int myNbComp, myDataSize;
-    TValField myValField;
-    TNames myCompNames;
-    TNames myUnitNames;
-    TField() : myNbComp(0), myDataSize(0), myIsTrimmed(0) {}
-  };
-  struct TValForTime: TBaseStructure{
-    int myId;
-    TEntity myEntity;
-    std::string myMeshName;
-    std::string myFieldName;
-    int myNbComp;
-    TTime myTime;
-
-    TValForTime() : myNbComp(0) {}
-  };
-
-  PFamily FindFamily(VISU::PMesh theMesh, 
-                    const std::string& theFamilyName);
-
-  PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, 
-                   const std::string& theFamilyName);
-
-  void WriteToFile(vtkUnstructuredGrid* theDataSet, 
-                  const std::string& theFileName);
+/*! 
+  \file VISU_Convertor.hxx
+  \brief The file represents definition of basic interface of the VISU CONVERTER package
+*/
+
+#include "VISU_Structures.hxx"
+
+
+//---------------------------------------------------------------
+//! This class defines interface to read VTK interpretation of MED entities
+/*!
+  It is the main class of the VISU CONVERTER package.
+  Following MED entities can be retrived from any MED file:
+  - mesh from corresponding MED ENTITIES;
+  - MED TIMESTAMPS;
+  - MED FAMILIES;
+  - MED GROUPS.
+  The class produce its work in two main steps:
+  1. Perfrom parsing of MED file to get known what MED entities are pressent in it
+  2. Get VTK representation for any existing MED entity
+  Also, it can perform some additional work to calculate expected amount of memory to build defined VTK representation
+*/
+class VISU_CONVERTOR_EXPORT VISU_Convertor
+{
+public:
+  //! Get brief name of the corresponding source MED file
+  virtual
+  const std::string& 
+  GetName();
+
+  //! Let known whether the source MED file parsed or not
+  virtual
+  int
+  IsDone() const;
+
+  //! This method perform first parsing of MED file to get known what MED entities are pressent in it
+  virtual
+  VISU_Convertor* 
+  Build() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED mesh entities are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildEntities() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED fields are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildFields() = 0;
+
+  //! This min /max calculation over existing MED fields
+  virtual
+  VISU_Convertor* 
+  BuildMinMax() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED groups are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildGroups() = 0;
+
+  //! This method allow to get known what MED entities are present is the MED file
+  virtual
+  const VISU::TMeshMap& 
+  GetMeshMap();
+
+  //! Get amount of memory to build VTK representations for all existing MED entities
+  virtual
+  size_t
+  GetSize() = 0;
+
+  //! Get mesh for corresponding MED ENTITY
+  virtual
+  VISU::PNamedIDMapper 
+  GetMeshOnEntity(const std::string& theMeshName, 
+                  const VISU::TEntity& theEntity) = 0;
+  
+  //! Get amount of memory to build mesh for corresponding MED ENTITY
+  virtual
+  size_t
+  GetMeshOnEntitySize(const std::string& theMeshName, 
+                      const VISU::TEntity& theEntity) = 0;
+  
+  //! Get mesh for corresponding MED FAMILY
+  virtual 
+  VISU::PUnstructuredGridIDMapper 
+  GetFamilyOnEntity(const std::string& theMeshName, 
+                    const VISU::TEntity& theEntity,
+                    const std::string& theFamilyName) = 0;
+
+  //! Get amount of memory to build mesh for corresponding MED FAMILY
+  virtual 
+  size_t 
+  GetFamilyOnEntitySize(const std::string& theMeshName, 
+                        const VISU::TEntity& theEntity,
+                        const std::string& theFamilyName) = 0;
+
+  //! Get mesh for corresponding MED GROUP
+  virtual
+  VISU::PUnstructuredGridIDMapper
+  GetMeshOnGroup(const std::string& theMeshName, 
+                 const std::string& theGroupName) = 0;
+  
+  //! Get amount of memory to build mesh for corresponding MED GROUP
+  virtual
+  size_t
+  GetMeshOnGroupSize(const std::string& theMeshName, 
+                     const std::string& theGroupName) = 0;
+  
+  //! Get mesh with attached values for corresponding MED TIMESTAMP
+  virtual
+  VISU::PUnstructuredGridIDMapper 
+  GetTimeStampOnMesh(const std::string& theMeshName, 
+                     const VISU::TEntity& theEntity,
+                     const std::string& theFieldName,
+                     int theTimeStampNumber) = 0;
+
+  //! Get Gauss Points mesh with attached values for corresponding MED TIMESTAMP
+  virtual
+  VISU::PGaussPtsIDMapper 
+  GetTimeStampOnGaussPts(const std::string& theMeshName, 
+                         const VISU::TEntity& theEntity,
+                         const std::string& theFieldName,
+                         int theTimeStampNumber) = 0;
+   
+  //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on mesh
+  virtual 
+  size_t
+  GetTimeStampOnMeshSize(const std::string& theMeshName, 
+                         const VISU::TEntity& theEntity,
+                         const std::string& theFieldName,
+                         int theTimeStampNumber,
+                         bool& theIsEstimated) = 0;
+    
+  //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on Gauss Points
+  virtual 
+  size_t
+  GetTimeStampOnGaussPtsSize(const std::string& theMeshName, 
+                             const VISU::TEntity& theEntity,
+                             const std::string& theFieldName,
+                             int theTimeStampNumber,
+                             bool& theIsEstimated) = 0;
+    
+  //! Get amount of memory to build all MED TIMESTAMPS for corresponding MED FIELD
+  virtual 
+  size_t
+  GetFieldOnMeshSize(const std::string& theMeshName, 
+                     const VISU::TEntity& theEntity,
+                     const std::string& theFieldName) = 0;
+  
+  //! Find MED FIELD container
+  virtual
+  const VISU::PField 
+  GetField(const std::string& theMeshName, 
+           VISU::TEntity theEntity, 
+           const std::string& theFieldName) = 0;
+  
+  //! Find MED TIMESTAMP container
+  virtual
+  const VISU::PValForTime 
+  GetTimeStamp(const std::string& theMeshName, 
+               const VISU::TEntity& theEntity,
+               const std::string& theFieldName,
+               int theTimeStampNumber) = 0;
+    
+  //! Allow to generate pretty name for MED TIMESTAMP
+  static 
+  std::string 
+  GenerateName(const VISU::TTime& aTime);
 
-};
+  static 
+  std::string 
+  GenerateName(const std::string& theName, unsigned int theTimeId);
 
-class VISU_Convertor{
 protected:
+  VISU_Convertor();
+  
   std::string myName;
   VISU::TMeshMap myMeshMap;
   int myIsDone;
-public:
-  virtual ~VISU_Convertor(){};
-  virtual const std::string& GetName() { return myName;}
-  virtual int IsDone() const { return myIsDone;}
-  typedef vtkUnstructuredGrid TOutput;
-
-  virtual VISU_Convertor* Build() = 0;
-  virtual const VISU::TMeshMap& GetMeshMap() ;
-  virtual float GetSize() = 0;
-
-  virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFamilyName = "") = 0;
-    
-  virtual float GetMeshOnEntitySize(const std::string& theMeshName, 
-                                   const VISU::TEntity& theEntity,
-                                   const std::string& theFamilyName = "") = 0;
-  
-  virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, 
-                                 const std::string& theGroupName) = 0;
-
-  virtual float GetMeshOnGroupSize(const std::string& theMeshName, 
-                                  const std::string& theGroupName) = 0;
-
-  virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, 
-                                     const VISU::TEntity& theEntity,
-                                     const std::string& theFieldName,
-                                     int theStampsNum) = 0;
-   
-  virtual float GetTimeStampSize(const std::string& theMeshName, 
-                                const VISU::TEntity& theEntity,
-                                const std::string& theFieldName,
-                                int theStampsNum) = 0;
-    
-  virtual float GetFieldOnMeshSize(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFieldName) = 0;
-  virtual const VISU::PField GetField(const std::string& theMeshName, 
-                                     VISU::TEntity theEntity, 
-                                     const std::string& theFieldName) = 0;
-
-  virtual const VISU::PValForTime GetTimeStamp(const std::string& theMeshName, 
-                                              const VISU::TEntity& theEntity,
-                                              const std::string& theFieldName,
-                                              int theStampsNum) = 0;
-    
-  static std::string GenerateName(const VISU::TTime& aTime);
-  static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
 };
 
-extern "C"{
-  VISU_Convertor* CreateConvertor(const std::string& theFileName) ;
+extern "C"
+{
+  //! Instatiate proper VISU_Convertor subclass
+  VISU_CONVERTOR_EXPORT
+  VISU_Convertor*
+  CreateConvertor(const std::string& theFileName);
 };
 
+
 #endif