Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.cxx
index c08d9a6122a46ecc94e955509b7745b49a0125cd..7a334552fc7f374dd793556cb7c493bb082f38e3 100644 (file)
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  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 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 <qstring.h>
-
-using namespace std;
-
-namespace VISU{
-
-  inline int GetNbOfPoints(int theVTKCellType){
-    switch(theVTKCellType){
-    case VTK_VERTEX : return 1;
-    case VTK_LINE : return 2;
-    case VTK_TRIANGLE : return 3;
-    case VTK_QUAD : return 4;
-    case VTK_TETRA : return 4;
-    case VTK_HEXAHEDRON : return 8;
-    case VTK_WEDGE : return 6;
-    case VTK_PYRAMID : return 5;
-    default: return -1;
-    }
-  }
-
-  pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
-  {
-    if(theFamilyName == "")
-      return make_pair(myNbCells,myCellsSize);
-    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 PFamily& aFamily = aFamilyMapIter->second; 
-    return make_pair(aFamily->myNbCells,aFamily->myCellsSize);
-  }
-  
-  const PField 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 PField();
-  }
-
-
-  PFamily FindFamily(VISU::PMesh theMesh, const string& theFamilyName)
-  {
-    PFamily aFamily;
-    const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
-    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
-    for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
-      const PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
-      aFamily = GetFamily(aMeshOnEntity,theFamilyName);
-      if(aFamily)
-       break;
-    }
-    return aFamily;
-  }
-  
-
-  PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, const string& theFamilyName)
-  {
-    PFamily aFamily;
-    if(theFamilyName != ""){
-      TFamilyMap& aFamilyMap = theMeshOnEntity->myFamilyMap;
-      TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
-      if(aFamilyMapIter != aFamilyMap.end())
-       aFamily = aFamilyMapIter->second;
-    }
-    return aFamily;
-  }
+#include <QString>
+
+#include <utility>
+
+
+//---------------------------------------------------------------
+VISU_Convertor
+::VISU_Convertor():
+  myIsDone(false)
+{}
+
+
+//---------------------------------------------------------------
+const std::string& 
+VISU_Convertor
+::GetName()
+{
+  return myName;
 }
 
 
-const VISU::TMeshMap& VISU_Convertor::GetMeshMap() { 
-  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::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();
 }
+
+
+//---------------------------------------------------------------