1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISUConvertor.cxx
24 // Author: Alexey PETROV
27 #include "VISU_Convertor.hxx"
28 #include "VISU_ConvertorUtils.hxx"
30 #include "VISU_Convertor_impl.hxx"
31 #include "VISU_TableReader.hxx"
37 #include <vtkCellType.h>
38 #include <vtkUnstructuredGrid.h>
42 #include <QStringList>
45 #include "utilities.h"
50 static int MYDEBUG = 1;
52 static int MYDEBUG = 0;
55 //#define _DEBUG_ID_MAPPING_
58 typedef vtkUnstructuredGrid TOutput;
60 void ParseMEDFile(const char* theFileName)
65 MSG(MYDEBUG,"'"<<theFileName<<"'...");
66 //theFileName = "Apointe.med";
67 auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
70 aCon->BuildEntities();
74 const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
76 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
77 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
80 const string& aMeshName = aMeshMapIter->first;
81 const VISU::PMesh& aMesh = aMeshMapIter->second;
82 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
83 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
86 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
87 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
88 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
89 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
90 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
91 VISU::TFieldMap::const_reverse_iterator aFieldMapIter = aFieldMap.rbegin();
92 for(; aFieldMapIter != aFieldMap.rend(); aFieldMapIter++){
93 const string& aFieldName = aFieldMapIter->first;
94 const VISU::PField& aField = aFieldMapIter->second;
95 const VISU::TValField& aValField = aField->myValField;
96 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
97 for(; aValFieldIter != aValField.end(); aValFieldIter++){
98 int aTimeStamp = aValFieldIter->first;
100 if(anEntity != VISU::NODE_ENTITY){
101 VISU::PGaussPtsIDMapper aGaussMesh =
102 aCon->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp);
103 #ifdef _DEBUG_ID_MAPPING_
104 vtkDataSet* aDataSet = aGaussMesh->GetOutput();
106 int aNbCells = aDataSet->GetNumberOfCells();
107 MESSAGE("aNbCells = "<<aNbCells);
108 for(int anCellId = 0; anCellId < aNbCells; anCellId++){
109 VISU::TGaussPointID anObjID = aGaussMesh->GetObjID(anCellId);
110 cout<<anObjID.first<<"; "<<anObjID.second<<"; "<<aGaussMesh->GetNodeVTKID(anObjID.first)<<endl;
111 vtkFloatingPointType* aCoord = aGaussMesh->GetNodeCoord(anCellId);
112 cout<<aCoord[0]<<"; "<<aCoord[1]<<"; "<<aCoord[2]<<endl;
117 VISU::PIDMapper anIDMapper =
118 aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
119 #ifdef _DEBUG_ID_MAPPING_
120 vtkDataSet* aDataSet = anIDMapper->GetOutput();
122 int aNbCells = aDataSet->GetNumberOfCells();
123 for(int anCellId = 0; anCellId < aNbCells; anCellId++){
124 int anObjID = anIDMapper->GetElemObjID(anCellId);
125 int aVTKID = anIDMapper->GetElemVTKID(anObjID);
126 cout<<anObjID<<"; "<<aVTKID<<endl;
136 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
137 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
138 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
139 const string& aGroupName = aGroupMapIter->first;
140 aCon->GetMeshOnGroup(aMeshName,aGroupName);
145 //Import mesh on entity
146 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
147 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
148 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
149 VISU::PIDMapper anIDMapper = aCon->GetMeshOnEntity(aMeshName,anEntity);
150 #ifdef _DEBUG_ID_MAPPING_
151 vtkDataSet* aDataSet = anIDMapper->GetOutput();
152 int aNbCells, anCellId, anObjID, aVTKID;
153 aNbCells = aDataSet->GetNumberOfCells();
154 for(anCellId = 0; anCellId < aNbCells; anCellId++){
155 anObjID = anIDMapper->GetElemObjID(anCellId);
156 aVTKID = anIDMapper->GetElemVTKID(anObjID);
157 MESSAGE(anObjID<<"; "<<aVTKID);
163 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
164 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
165 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
166 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
167 //aCon->GetMeshOnEntity(aMeshName,anEntity);
168 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
169 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
170 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
171 const string& aFamilyName = aFamilyMapIter->first;
172 aCon->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
179 }catch(std::exception& exc){
180 MSG(MYDEBUG,"Follow exception was occured in file:"<<theFileName<<"\n"<<exc.what());
182 MSG(MYDEBUG,"Unknown exception was occured in VISU_Convertor_impl in file:"<<theFileName);
187 void ParseXLSFile(const char* theFileName)
189 VISU::TTableContainer aContainer;
190 VISU::ImportTables( theFileName, aContainer );
194 main( int argc, char** argv )
197 QFileInfo aFileInfo( argv[1] );
198 for ( int i = 0; i < 1; i++ ) {
199 if ( aFileInfo.exists() ) {
200 if ( aFileInfo.isDir() ) {
201 QDir aDir( aFileInfo.absoluteFilePath() );
202 QStringList wildcards; wildcards << "*.med";
203 QStringList aStringList = aDir.entryList( wildcards, QDir::Files );
204 int jEnd = aStringList.count();
205 for ( int j = 0; j < jEnd; j++ ) {
206 ParseMEDFile( aDir.filePath( aStringList[j] ).toLatin1().data() );
209 QString anExtension = aFileInfo.suffix();
210 if ( anExtension == "med" )
211 ParseMEDFile( argv[1] );
212 else if ( anExtension == "xls" || anExtension == "txt" )
213 ParseXLSFile( argv[1] );