]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_Convertor.hxx
Salome HOME
Merge with OCC_development_01
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.hxx
1 //  VISU CONVERTOR :
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   : VISU_Convertor.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #ifndef VISU_Convertor_HeaderFile
28 #define VISU_Convertor_HeaderFile
29
30 #include <stdio.h>
31
32 #include <list>
33 #include <map>
34 #include <set>
35 #include <utility>
36 #include <vector>
37 #include <string>
38 #include <stdexcept>
39
40 #include <boost/shared_ptr.hpp>
41
42 class vtkUnstructuredGrid;
43
44 namespace VISU{
45
46   template<class T> class shared_ptr: public boost::shared_ptr<T>
47   {
48   public:
49     shared_ptr() {}
50
51     template<class Y>
52     explicit shared_ptr(Y * p)
53     {
54       reset(p);
55     }
56
57     template<class Y>
58     shared_ptr(shared_ptr<Y> const & r):
59       boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag())
60     {}
61
62     template<class Y>
63     shared_ptr & operator=(shared_ptr<Y> const & r)
64     {
65       shared_ptr<T>(r).swap(*this);
66       return *this;
67     }
68
69     template<class Y> shared_ptr& operator()(Y * p) // Y must be complete
70     {
71       if(T* pt = dynamic_cast<T*>(p))
72         boost::shared_ptr<T>::reset(pt);
73       else
74         boost::throw_exception(std::bad_cast());
75       return *this;
76     }
77
78   };
79
80
81   enum  TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
82
83   typedef std::pair<std::string,TEntity> TFamilyAndEntity;
84   typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
85   typedef std::set<std::string> TBindGroups;
86
87   typedef std::pair<double,std::string> TTime;
88
89   struct TMesh;
90   typedef shared_ptr<TMesh> PMesh;
91   typedef std::map<std::string,PMesh> TMeshMap;
92
93   struct TMeshOnEntity;
94   typedef shared_ptr<TMeshOnEntity> PMeshOnEntity;
95   typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
96
97   struct TFamily;
98   typedef shared_ptr<TFamily> PFamily;
99   typedef std::map<std::string,PFamily> TFamilyMap;
100
101   struct TGroup;
102   typedef shared_ptr<TGroup> PGroup;
103   typedef std::map<std::string,PGroup> TGroupMap;
104
105   struct TField;
106   typedef shared_ptr<TField> PField;
107   typedef std::map<std::string,PField> TFieldMap;
108
109   struct TValForTime;
110   typedef shared_ptr<TValForTime> PValForTime;
111   typedef std::map<int,PValForTime> TValField;
112
113   struct TBaseStructure{
114     virtual ~TBaseStructure(){}
115   };
116
117   typedef std::vector<std::string> TNames;
118
119   struct TMesh: TBaseStructure{
120     int myDim, myNbPoints;
121     std::string myName;
122
123     TMeshOnEntityMap myMeshOnEntityMap;
124     TGroupMap myGroupMap;
125
126     TMesh() : myDim(0), myNbPoints(0) {}
127     const PField GetField(const std::string& theFieldName) const;
128   };
129
130   struct TMeshOnEntity: TBaseStructure{
131     std::string myMeshName;
132     TEntity myEntity;
133     int myNbCells, myCellsSize;
134     TFamilyMap myFamilyMap;
135     TFieldMap myFieldMap;
136     TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
137
138     std::pair<int,int> 
139     GetCellsDims(const std::string& theFamilyName = "") const;
140   };
141
142   struct TFamily: TBaseStructure{
143     int myId;
144     std::string myName;
145     TEntity myEntity;
146     TBindGroups myGroups;
147     int myNbCells, myCellsSize;
148     TFamily() : myNbCells(0), myCellsSize(0) {}
149   };
150
151   struct TGroup: TBaseStructure{
152     std::string myName;
153     std::string myMeshName;
154     int myNbCells, myCellsSize;
155     TFamilyAndEntitySet myFamilyAndEntitySet;
156     TGroup() : myNbCells(0), myCellsSize(0) {}
157   };
158
159   struct TField: TBaseStructure{
160     int myId;
161     TEntity myEntity;
162     bool myIsTrimmed;
163     std::string myName;
164     std::string myMeshName;
165     int myNbComp, myDataSize;
166     TValField myValField;
167     TNames myCompNames;
168     TNames myUnitNames;
169     TField() : myNbComp(0), myDataSize(0), myIsTrimmed(0) {}
170   };
171  
172   struct TValForTime: TBaseStructure{
173     int myId;
174     TEntity myEntity;
175     std::string myMeshName;
176     std::string myFieldName;
177     int myNbComp;
178     TTime myTime;
179
180     TValForTime() : myNbComp(0) {}
181   };
182
183   PFamily FindFamily(VISU::PMesh theMesh, 
184                      const std::string& theFamilyName);
185
186   PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, 
187                     const std::string& theFamilyName);
188
189   void WriteToFile(vtkUnstructuredGrid* theDataSet, 
190                    const std::string& theFileName);
191
192 };
193
194 class VISU_Convertor{
195 protected:
196   std::string myName;
197   VISU::TMeshMap myMeshMap;
198   int myIsDone;
199 public:
200   virtual ~VISU_Convertor(){};
201   virtual const std::string& GetName() { return myName;}
202   virtual int IsDone() const { return myIsDone;}
203   typedef vtkUnstructuredGrid TOutput;
204
205   virtual VISU_Convertor* Build() = 0;
206   virtual const VISU::TMeshMap& GetMeshMap() ;
207   virtual float GetSize() = 0;
208
209   virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, 
210                                    const VISU::TEntity& theEntity,
211                                    const std::string& theFamilyName = "") = 0;
212     
213   virtual float GetMeshOnEntitySize(const std::string& theMeshName, 
214                                     const VISU::TEntity& theEntity,
215                                     const std::string& theFamilyName = "") = 0;
216   
217   virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, 
218                                   const std::string& theGroupName) = 0;
219
220   virtual float GetMeshOnGroupSize(const std::string& theMeshName, 
221                                    const std::string& theGroupName) = 0;
222
223   virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, 
224                                       const VISU::TEntity& theEntity,
225                                       const std::string& theFieldName,
226                                       int theStampsNum) = 0;
227    
228   virtual float GetTimeStampSize(const std::string& theMeshName, 
229                                  const VISU::TEntity& theEntity,
230                                  const std::string& theFieldName,
231                                  int theStampsNum) = 0;
232     
233   virtual float GetFieldOnMeshSize(const std::string& theMeshName, 
234                                    const VISU::TEntity& theEntity,
235                                    const std::string& theFieldName) = 0;
236  
237   virtual const VISU::PField GetField(const std::string& theMeshName, 
238                                       VISU::TEntity theEntity, 
239                                       const std::string& theFieldName) = 0;
240
241   virtual const VISU::PValForTime GetTimeStamp(const std::string& theMeshName, 
242                                                const VISU::TEntity& theEntity,
243                                                const std::string& theFieldName,
244                                                int theStampsNum) = 0;
245     
246   static std::string GenerateName(const VISU::TTime& aTime);
247   static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
248 };
249
250 extern "C"{
251   VISU_Convertor* CreateConvertor(const std::string& theFileName) ;
252 };
253
254 #endif