Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/visu.git] / src / CONVERTOR / VISUConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File:    VISUConvertor.cxx
24 //  Author:  Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Convertor.hxx"
28 #include "VISU_ConvertorUtils.hxx"
29
30 #include <fstream>      
31 #include <strstream>
32 #include <vtkCellType.h>
33 #include <qdir.h>
34 #include <qfileinfo.h>
35 #include <qstringlist.h>
36 #include <memory>       
37
38 using namespace std;
39
40 #ifdef DEBUG
41 static int MYDEBUG = 1;
42 #else
43 static int MYDEBUG = 0;
44 #endif
45
46 void parseFile(const char* theFileName) {
47   try{
48     MESSAGE("'"<<theFileName<<"'...");
49     auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
50     //aCon->GetSize();
51     //return;
52     const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
53     VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
54     for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
55       const string& aMeshName = aMeshMapIter->first;
56       const VISU::TMesh& aMesh = aMeshMapIter->second;
57       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
58       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
59       //Import fields
60       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
61       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
62         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
63         const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
64         const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
65         VISU::TFieldMap::const_reverse_iterator aFieldMapIter = aFieldMap.rbegin();
66         for(; aFieldMapIter != aFieldMap.rend(); aFieldMapIter++){
67           const string& aFieldName = aFieldMapIter->first;
68           const VISU::TField& aField = aFieldMapIter->second;
69           const VISU::TField::TValField& aValField = aField.myValField;
70           VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
71           for(; aValFieldIter != aValField.end(); aValFieldIter++){
72             int aTimeStamp = aValFieldIter->first;
73             aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
74             //goto OK;
75           }
76         }
77       }
78       //continue;
79       //Importing groups
80       const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
81       VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
82       for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
83         const string& aGroupName = aGroupMapIter->first;
84         aCon->GetMeshOnGroup(aMeshName,aGroupName);
85       }
86       //Import families
87       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
88       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
89         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
90         const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
91         //aCon->GetMeshOnEntity(aMeshName,anEntity);
92         const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
93         VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
94         for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
95           const string& aFamilyName = aFamilyMapIter->first;
96           aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
97         }
98       }
99       //Import mesh on entity
100       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
101       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
102         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
103         aCon->GetMeshOnEntity(aMeshName,anEntity);
104       }
105     }
106   OK:
107     MESSAGE("OK");
108   }catch(std::exception& exc){
109     MESSAGE("Follow exception was occured in file:"<<theFileName<<"\n"<<exc.what());
110   }catch(...){
111     MESSAGE("Unknown exception was occured in VISU_Convertor_impl in file:"<<theFileName);
112   } 
113 }
114
115 int main(int argc, char** argv){ 
116   try{
117     if(argc > 1){
118       QFileInfo fi(argv[1]);
119       for(int i = 0; i < 1; i++){
120         if(fi.exists()){
121           if(fi.isDir()){
122             QDir aDir(fi.absFilePath());
123             QStringList aStringList = aDir.entryList("*.med",QDir::Files);
124             int jEnd = aStringList.count();
125             for(int j = 0; j < jEnd; j++){
126               parseFile(aDir.filePath(aStringList[j]).latin1());
127             }
128           }else{
129             parseFile(argv[1]);
130           }
131         }
132       }
133       return 0;
134     }
135   }catch(std::exception& exc){
136     MESSAGE("Follow exception was occured :\n"<<exc.what());
137   }catch(...){
138     MESSAGE("Unknown exception was occured in VISU_Convertor_impl");
139   } 
140   return 1;
141 }