1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File: VISU_Convertor.cxx
24 // Author: Alexey PETROV
27 #include "VISU_Convertor.hxx"
28 #include "VISU_ConvertorUtils.hxx"
33 static int MYDEBUG = 0;
35 static int MYDEBUG = 0;
39 VISU_Convertor* CreateConvertor(const string& theFileName) {
40 if(QFileInfo(theFileName.c_str()).extension(false) == "med")
41 return CreateMedConvertor(theFileName);
43 return CreateDatConvertor(theFileName);
48 inline int GetNbOfPoints(int theVTKCellType){
49 switch(theVTKCellType){
50 case VTK_VERTEX : return 1;
51 case VTK_LINE : return 2;
52 case VTK_TRIANGLE : return 3;
53 case VTK_QUAD : return 4;
54 case VTK_TETRA : return 4;
55 case VTK_HEXAHEDRON : return 8;
56 case VTK_WEDGE : return 6;
57 case VTK_PYRAMID : return 5;
62 pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
64 bool isFamilyPresent = (theFamilyName != "");
65 int aNbCells = 0, aCellsSize = 0;
67 TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
68 for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
69 const TConnForCellType& aConnForCellType = aCellsConnIter->second;
70 if(!aConnForCellType.empty()){
71 aNbCells += aConnForCellType.size();
72 aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
76 TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
77 if(aFamilyMapIter == myFamilyMap.end())
78 throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
79 const TFamily& aFamily = aFamilyMapIter->second;
80 const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
81 TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
82 for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
83 const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
84 if(!aSubMeshOnCellType.empty()){
85 int tmp = aSubMeshOnCellType.size();
87 int aVtkType = aSubMeshIter->first;
88 int aVtkSize = GetNbOfPoints(aVtkType);
89 aCellsSize += tmp*(aVtkSize+1);
93 return make_pair(aNbCells,aCellsSize);
96 const TField* TMesh::GetField(const string& theFieldName) const {
97 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
98 for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
99 const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
100 TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
101 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
102 if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
107 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
109 if(theFamilyName == "") return NULL;
110 const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
111 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
112 if(aFamilyMapIter == aFamilyMap.end())
113 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
114 const VISU::TFamily& aFamily = aFamilyMapIter->second;
118 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
120 if(theFamilyName == "") return NULL;
121 VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
122 VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
123 if(aFamilyMapIter == aFamilyMap.end())
124 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
125 VISU::TFamily& aFamily = aFamilyMapIter->second;
129 void TField::ShallowCopy(const TField& aField){
130 myEntity = aField.myEntity;
131 myMeshName = aField.myMeshName;
132 myNbComp = aField.myNbComp;
133 VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
134 for(; iter != aField.myValField.end(); iter++)
135 myValField[iter->first];
140 const VISU::TMeshMap& VISU_Convertor::GetMeshMap() {
141 if(!myIsDone) { myIsDone = true; Build();}
146 string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
147 static QString aName;
148 const string aUnits = aTime.second, tmp(aUnits.size(),' ');
149 if(aUnits == "" || aUnits == tmp)
150 aName.sprintf("%g, -",aTime.first);
152 aName.sprintf("%g, %s",aTime.first,aTime.second.c_str());
153 aName = aName.simplifyWhiteSpace();
154 return aName.latin1();
157 string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) {
158 static QString aName;
159 aName = QString(theName.c_str()).simplifyWhiteSpace();
160 int iEnd = strlen(aName);
161 static int VtkHighLevelLength = 12; //25
162 if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength;
163 char aNewName[iEnd+1];
164 aNewName[iEnd] = '\0';
165 strncpy(aNewName,aName,iEnd);
166 replace(aNewName,aNewName+iEnd,' ','_');
167 if(true || theTimeId == 0)
170 aName.sprintf("%s_%d",aNewName,theTimeId);
171 return aName.latin1();