]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISUConvertor.cxx
Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / CONVERTOR / VISUConvertor.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File:    VISUConvertor.cxx
25 //  Author:  Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_Convertor.hxx"
29 #include "VISU_ConvertorUtils.hxx"
30
31 #include "VISU_Convertor_impl.hxx"
32 #include "VISU_TableReader.hxx"
33
34 #include <fstream>      
35 #include <sstream>
36 #include <memory>       
37
38 #include <vtkCellType.h>
39 #include <vtkUnstructuredGrid.h>
40
41 #include <QDir>
42 #include <QFileInfo>
43 #include <QStringList>
44
45
46 #include "utilities.h"
47
48 using namespace std;
49
50 #ifdef DEBUG
51 static int MYDEBUG = 1;
52 #else
53 static int MYDEBUG = 0;
54 #endif
55
56 //#define _DEBUG_ID_MAPPING_
57 #define _DEXCEPT_
58
59 typedef vtkUnstructuredGrid TOutput;
60
61 void ParseMEDFile(const char* theFileName) 
62 {
63 #ifndef _DEXCEPT_
64   try{
65 #endif
66     MSG(MYDEBUG,"'"<<theFileName<<"'...");
67     //theFileName = "Apointe.med";
68     auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
69     //aCon->GetSize();
70     //return;
71     aCon->BuildEntities();
72     aCon->BuildGroups();
73     aCon->BuildFields();
74     aCon->BuildMinMax();
75     const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
76     //return;
77     VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
78     for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
79       //continue;
80
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;
85
86       //Import fields
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;
100
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();
106               aDataSet->Update();
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                 double* aCoord = aGaussMesh->GetNodeCoord(anCellId);
113                 cout<<aCoord[0]<<"; "<<aCoord[1]<<"; "<<aCoord[2]<<endl;
114               }
115 #endif
116             }else{
117               //continue;
118               VISU::PIDMapper anIDMapper = 
119                 aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
120 #ifdef _DEBUG_ID_MAPPING_
121               vtkDataSet* aDataSet = anIDMapper->GetOutput();
122               aDataSet->Update();
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;
128               }
129 #endif
130             }
131             //goto OK;
132           }
133         }
134       }
135
136       //Importing groups
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);
142       }
143
144       //continue;
145
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);
159         }
160 #endif
161       }
162
163       //Import families
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);
174         }
175       }
176     }
177   OK:
178     MSG(MYDEBUG,"OK");
179 #ifndef _DEXCEPT_
180   }catch(std::exception& exc){
181     MSG(MYDEBUG,"Follow exception was occured in file:"<<theFileName<<"\n"<<exc.what());
182   }catch(...){
183     MSG(MYDEBUG,"Unknown exception was occured in VISU_Convertor_impl in file:"<<theFileName);
184   } 
185 #endif
186 }
187
188 void ParseXLSFile(const char* theFileName) 
189 {
190   VISU::TTableContainer aContainer;
191   VISU::ImportTables( theFileName, aContainer );
192 }
193
194 int
195 main( int argc, char** argv )
196
197   if ( argc > 1 ) {
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() );
208           }
209         } else {
210           QString anExtension = aFileInfo.suffix();
211           if ( anExtension == "med" )
212             ParseMEDFile( argv[1] );
213           else if ( anExtension == "xls" || anExtension == "txt" )
214             ParseXLSFile( argv[1] );
215         }
216       }
217     }
218     return 0;
219   }
220   return 1;
221 }