]> SALOME platform Git repositories - modules/visu.git/blobdiff - src/CONVERTOR/VISU_Convertor.cxx
Salome HOME
Update copyright information
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.cxx
index 82f2463dbc06b5f78cd7bcdc0bf0e8515d112f86..ca6019bdb56533c01cce254e98efc2d3680d5ec7 100644 (file)
-//  VISU OBJECT : interactive object for VISU entities implementation
+// Copyright (C) 2007-2012  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.
+//
+// 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.
 //
-//  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 
+// 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 OBJECT : interactive object for VISU entities implementation
 //  File:    VISU_Convertor.cxx
 //  Author:  Alexey PETROV
 //  Module : VISU
-
+//
 #include "VISU_Convertor.hxx"
 #include "VISU_ConvertorUtils.hxx"
 
-#include <vtkUnstructuredGridWriter.h>
+#include <QString>
 
-using namespace std;
+#include <utility>
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
 
-extern "C" {
-  VISU_Convertor* CreateConvertor(const string& theFileName) throw(std::runtime_error&){
-    if(QFileInfo(theFileName.c_str()).extension(false) == "med")
-      return CreateMedConvertor(theFileName);
-    else
-      return CreateDatConvertor(theFileName);
-  }
-}
+//---------------------------------------------------------------
+VISU_Convertor
+::VISU_Convertor():
+  myIsDone(false)
+{}
 
-void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){
-//  vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
-//  //aWriter->DebugOn();
-//  //aWriter->SetFileType(VTK_BINARY);
-//  aWriter->SetFileName(theFileName.c_str());
-//  aWriter->SetInput(theDataSet);
-//  //aWriter->Print(cout);
-//  aWriter->Write();
-//  aWriter->Delete();
-}
 
-namespace VISU{
-  TVtkCellInfoMap aVtkCellInfoMap;
-  static int INIT = (
-                    aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1),
-                    aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2),
-                    aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3),
-                    aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4),
-                    aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4),
-                    aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8),
-                    aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6),
-                    aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5),
-                    1);
-
-  pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
-    throw(std::runtime_error&)
-  {
-    bool isFamilyPresent = (theFamilyName != "");
-    int aNbCells = 0, aCellsSize = 0;
-    if(!isFamilyPresent){
-      TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
-      for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
-       const TConnForCellType& aConnForCellType = aCellsConnIter->second;
-       if(!aConnForCellType.empty()){
-         aNbCells += aConnForCellType.size();
-         aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
-       }
-      }
-    }else{
-      TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
-      if(aFamilyMapIter == myFamilyMap.end())
-       throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
-      const TFamily& aFamily = aFamilyMapIter->second; 
-      const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
-      TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
-      for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
-       const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
-       if(!aSubMeshOnCellType.empty()){
-         int tmp = aSubMeshOnCellType.size();
-         aNbCells += tmp;
-         int aVtkType = aSubMeshIter->first;
-         int aVtkSize = aVtkCellInfoMap[aVtkType].mySize;
-         aCellsSize += tmp*(aVtkSize+1);
-       }
-      }
-    }
-    return make_pair(aNbCells,aCellsSize);
-  }
-  
-  const TField* TMesh::GetField(const string& theFieldName) const {
-    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
-    for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
-      const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
-      TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
-      for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
-       if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
-    }
-    return NULL;
-  }
-
-  const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
-    throw(std::runtime_error&) 
-  {
-    if(theFamilyName == "") return NULL;
-    const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
-    VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
-    if(aFamilyMapIter == aFamilyMap.end())
-      throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
-    const VISU::TFamily& aFamily = aFamilyMapIter->second;
-       return &aFamily;
-  }
-  
-  TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
-    throw(std::runtime_error&) 
-  {
-    if(theFamilyName == "") return NULL;
-    VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
-    VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
-    if(aFamilyMapIter == aFamilyMap.end())
-      throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
-    VISU::TFamily& aFamily = aFamilyMapIter->second;
-    return &aFamily;
-  }
-  
-  void TField::ShallowCopy(const TField& aField){
-    myEntity = aField.myEntity;
-    myMeshName = aField.myMeshName;
-    myNbComp = aField.myNbComp;
-    VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
-    for(; iter != aField.myValField.end(); iter++)
-      myValField[iter->first];
-  }
+//---------------------------------------------------------------
+const std::string& 
+VISU_Convertor
+::GetName()
+{
+  return myName;
 }
 
 
-const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){ 
-  if(!myIsDone) { myIsDone = true;  Build();}
+//---------------------------------------------------------------
+int
+VISU_Convertor
+::IsDone() const 
+{
+  return myIsDone; 
+}
+
+//---------------------------------------------------------------
+const VISU::TMeshMap& 
+VISU_Convertor
+::GetMeshMap() 
+{ 
   return myMeshMap;
 }
 
 
-string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
+//---------------------------------------------------------------
+std::string
+VISU_Convertor
+::GenerateName(const VISU::TTime& aTime)
+{
   static QString aName;
-  const string aUnits = aTime.second, tmp(aUnits.size(),' ');
+  const std::string aUnits = aTime.second, tmp(aUnits.size(), ' ');
   if(aUnits == "" || aUnits == tmp)
-    aName.sprintf("%g, -",aTime.first);
+    aName.sprintf("%g, -", aTime.first);
   else
-    aName.sprintf("%g, %s",aTime.first,aTime.second.c_str());
-  aName = aName.simplifyWhiteSpace();
-  return aName.latin1();
+    aName.sprintf("%g, %s", aTime.first, aTime.second.c_str());
+  aName = aName.simplified();
+  return (const char*)aName.toLatin1();
 }
 
-string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) {
+
+//---------------------------------------------------------------
+std::string
+VISU_Convertor
+::GenerateName(const std::string& theName, 
+               unsigned int theTimeId) 
+{
   static QString aName;
-  aName = QString(theName.c_str()).simplifyWhiteSpace();
-  int iEnd = strlen(aName);
+  aName = QString(theName.c_str()).simplified();
+  int iEnd = strlen((const char*)aName.toLatin1());
   static int VtkHighLevelLength = 12; //25
   if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength;
-  char aNewName[iEnd+1];
+  char* aNewName = new char[iEnd+1];
   aNewName[iEnd] = '\0';
-  strncpy(aNewName,aName,iEnd);
-  replace(aNewName,aNewName+iEnd,' ','_');
+  strncpy(aNewName, (const char*)aName.toLatin1(), iEnd);
+  std::replace(aNewName, aNewName + iEnd, ' ', '_');
   if(true || theTimeId == 0)
     aName = aNewName;
   else
     aName.sprintf("%s_%d",aNewName,theTimeId);
-  return aName.latin1();
+  delete[] aNewName;
+  return (const char*)aName.toLatin1();
 }
+
+
+//---------------------------------------------------------------