1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISUConvertor.cxx
25 // Author: Alexey PETROV
28 #include "VISU_Convertor.hxx"
29 #include "VISU_ConvertorUtils.hxx"
31 #include "VISU_Convertor_impl.hxx"
32 #include "VISU_TableReader.hxx"
38 #include <vtkCellType.h>
39 #include <vtkUnstructuredGrid.h>
43 #include <QStringList>
46 #include "utilities.h"
51 static int MYDEBUG = 1;
53 static int MYDEBUG = 0;
56 //#define _DEBUG_ID_MAPPING_
59 typedef vtkUnstructuredGrid TOutput;
61 void ParseMEDFile(const char* theFileName)
66 MSG(MYDEBUG,"'"<<theFileName<<"'...");
67 //theFileName = "Apointe.med";
68 auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
71 aCon->BuildEntities();
75 const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
77 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
78 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
81 const string& aMeshName = aMeshMapIter->first;
82 const VISU::PMesh& aMesh = aMeshMapIter->second;
83 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
84 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
87 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
88 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
89 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
90 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
91 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
92 VISU::TFieldMap::const_reverse_iterator aFieldMapIter = aFieldMap.rbegin();
93 for(; aFieldMapIter != aFieldMap.rend(); aFieldMapIter++){
94 const string& aFieldName = aFieldMapIter->first;
95 const VISU::PField& aField = aFieldMapIter->second;
96 const VISU::TValField& aValField = aField->myValField;
97 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
98 for(; aValFieldIter != aValField.end(); aValFieldIter++){
99 int aTimeStamp = aValFieldIter->first;
101 if(anEntity != VISU::NODE_ENTITY){
102 VISU::PGaussPtsIDMapper aGaussMesh =
103 aCon->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp);
104 #ifdef _DEBUG_ID_MAPPING_
105 vtkDataSet* aDataSet = aGaussMesh->GetOutput();
107 int aNbCells = aDataSet->GetNumberOfCells();
108 MESSAGE("aNbCells = "<<aNbCells);
109 for(int anCellId = 0; anCellId < aNbCells; anCellId++){
110 VISU::TGaussPointID anObjID = aGaussMesh->GetObjID(anCellId);
111 cout<<anObjID.first<<"; "<<anObjID.second<<"; "<<aGaussMesh->GetNodeVTKID(anObjID.first)<<endl;
112 vtkFloatingPointType* aCoord = aGaussMesh->GetNodeCoord(anCellId);
113 cout<<aCoord[0]<<"; "<<aCoord[1]<<"; "<<aCoord[2]<<endl;
118 VISU::PIDMapper anIDMapper =
119 aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
120 #ifdef _DEBUG_ID_MAPPING_
121 vtkDataSet* aDataSet = anIDMapper->GetOutput();
123 int aNbCells = aDataSet->GetNumberOfCells();
124 for(int anCellId = 0; anCellId < aNbCells; anCellId++){
125 int anObjID = anIDMapper->GetElemObjID(anCellId);
126 int aVTKID = anIDMapper->GetElemVTKID(anObjID);
127 cout<<anObjID<<"; "<<aVTKID<<endl;
137 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
138 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
139 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
140 const string& aGroupName = aGroupMapIter->first;
141 aCon->GetMeshOnGroup(aMeshName,aGroupName);
146 //Import mesh on entity
147 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
148 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
149 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
150 VISU::PIDMapper anIDMapper = aCon->GetMeshOnEntity(aMeshName,anEntity);
151 #ifdef _DEBUG_ID_MAPPING_
152 vtkDataSet* aDataSet = anIDMapper->GetOutput();
153 int aNbCells, anCellId, anObjID, aVTKID;
154 aNbCells = aDataSet->GetNumberOfCells();
155 for(anCellId = 0; anCellId < aNbCells; anCellId++){
156 anObjID = anIDMapper->GetElemObjID(anCellId);
157 aVTKID = anIDMapper->GetElemVTKID(anObjID);
158 MESSAGE(anObjID<<"; "<<aVTKID);
164 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
165 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
166 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
167 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
168 //aCon->GetMeshOnEntity(aMeshName,anEntity);
169 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
170 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
171 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
172 const string& aFamilyName = aFamilyMapIter->first;
173 aCon->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
180 }catch(std::exception& exc){
181 MSG(MYDEBUG,"Follow exception was occured in file:"<<theFileName<<"\n"<<exc.what());
183 MSG(MYDEBUG,"Unknown exception was occured in VISU_Convertor_impl in file:"<<theFileName);
188 void ParseXLSFile(const char* theFileName)
190 VISU::TTableContainer aContainer;
191 VISU::ImportTables( theFileName, aContainer );
195 main( int argc, char** argv )
198 QFileInfo aFileInfo( argv[1] );
199 for ( int i = 0; i < 1; i++ ) {
200 if ( aFileInfo.exists() ) {
201 if ( aFileInfo.isDir() ) {
202 QDir aDir( aFileInfo.absoluteFilePath() );
203 QStringList wildcards; wildcards << "*.med";
204 QStringList aStringList = aDir.entryList( wildcards, QDir::Files );
205 int jEnd = aStringList.count();
206 for ( int j = 0; j < jEnd; j++ ) {
207 ParseMEDFile( aDir.filePath( aStringList[j] ).toLatin1().data() );
210 QString anExtension = aFileInfo.suffix();
211 if ( anExtension == "med" )
212 ParseMEDFile( argv[1] );
213 else if ( anExtension == "xls" || anExtension == "txt" )
214 ParseXLSFile( argv[1] );