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