3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_Convertor.hxx
24 // Author : Alexey PETROV
27 #ifndef VISU_Convertor_HeaderFile
28 #define VISU_Convertor_HeaderFile
40 #include <boost/shared_ptr.hpp>
42 class vtkUnstructuredGrid;
46 template<class T> class shared_ptr: public boost::shared_ptr<T>
52 explicit shared_ptr(Y * p)
58 shared_ptr(shared_ptr<Y> const & r):
59 boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag())
63 shared_ptr & operator=(shared_ptr<Y> const & r)
65 shared_ptr<T>(r).swap(*this);
69 template<class Y> shared_ptr& operator()(Y * p) // Y must be complete
71 if(T* pt = dynamic_cast<T*>(p))
72 boost::shared_ptr<T>::reset(pt);
74 boost::throw_exception(std::bad_cast());
81 enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
83 typedef std::pair<std::string,TEntity> TFamilyAndEntity;
84 typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
85 typedef std::set<std::string> TBindGroups;
87 typedef std::pair<double,std::string> TTime;
90 typedef shared_ptr<TMesh> PMesh;
91 typedef std::map<std::string,PMesh> TMeshMap;
94 typedef shared_ptr<TMeshOnEntity> PMeshOnEntity;
95 typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
98 typedef shared_ptr<TFamily> PFamily;
99 typedef std::map<std::string,PFamily> TFamilyMap;
102 typedef shared_ptr<TGroup> PGroup;
103 typedef std::map<std::string,PGroup> TGroupMap;
106 typedef shared_ptr<TField> PField;
107 typedef std::map<std::string,PField> TFieldMap;
110 typedef shared_ptr<TValForTime> PValForTime;
111 typedef std::map<int,PValForTime> TValField;
113 struct TBaseStructure{
114 virtual ~TBaseStructure(){}
117 typedef std::vector<std::string> TNames;
119 struct TMesh: TBaseStructure{
120 int myDim, myNbPoints;
123 TMeshOnEntityMap myMeshOnEntityMap;
124 TGroupMap myGroupMap;
126 TMesh() : myDim(0), myNbPoints(0) {}
127 const PField GetField(const std::string& theFieldName) const;
130 struct TMeshOnEntity: TBaseStructure{
131 std::string myMeshName;
133 int myNbCells, myCellsSize;
134 TFamilyMap myFamilyMap;
135 TFieldMap myFieldMap;
136 TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
139 GetCellsDims(const std::string& theFamilyName = "") const;
142 struct TFamily: TBaseStructure{
146 TBindGroups myGroups;
147 int myNbCells, myCellsSize;
148 TFamily() : myNbCells(0), myCellsSize(0) {}
151 struct TGroup: TBaseStructure{
153 std::string myMeshName;
154 int myNbCells, myCellsSize;
155 TFamilyAndEntitySet myFamilyAndEntitySet;
156 TGroup() : myNbCells(0), myCellsSize(0) {}
159 struct TField: TBaseStructure{
164 std::string myMeshName;
165 int myNbComp, myDataSize;
166 TValField myValField;
169 TField() : myNbComp(0), myDataSize(0), myIsTrimmed(0) {}
172 struct TValForTime: TBaseStructure{
175 std::string myMeshName;
176 std::string myFieldName;
180 TValForTime() : myNbComp(0) {}
183 PFamily FindFamily(VISU::PMesh theMesh,
184 const std::string& theFamilyName);
186 PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity,
187 const std::string& theFamilyName);
189 void WriteToFile(vtkUnstructuredGrid* theDataSet,
190 const std::string& theFileName);
194 class VISU_Convertor{
197 VISU::TMeshMap myMeshMap;
200 virtual ~VISU_Convertor(){};
201 virtual const std::string& GetName() { return myName;}
202 virtual int IsDone() const { return myIsDone;}
203 typedef vtkUnstructuredGrid TOutput;
205 virtual VISU_Convertor* Build() = 0;
206 virtual const VISU::TMeshMap& GetMeshMap() ;
207 virtual float GetSize() = 0;
209 virtual TOutput* GetMeshOnEntity(const std::string& theMeshName,
210 const VISU::TEntity& theEntity,
211 const std::string& theFamilyName = "") = 0;
213 virtual float GetMeshOnEntitySize(const std::string& theMeshName,
214 const VISU::TEntity& theEntity,
215 const std::string& theFamilyName = "") = 0;
217 virtual TOutput* GetMeshOnGroup(const std::string& theMeshName,
218 const std::string& theGroupName) = 0;
220 virtual float GetMeshOnGroupSize(const std::string& theMeshName,
221 const std::string& theGroupName) = 0;
223 virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName,
224 const VISU::TEntity& theEntity,
225 const std::string& theFieldName,
226 int theStampsNum) = 0;
228 virtual float GetTimeStampSize(const std::string& theMeshName,
229 const VISU::TEntity& theEntity,
230 const std::string& theFieldName,
231 int theStampsNum) = 0;
233 virtual float GetFieldOnMeshSize(const std::string& theMeshName,
234 const VISU::TEntity& theEntity,
235 const std::string& theFieldName) = 0;
237 virtual const VISU::PField GetField(const std::string& theMeshName,
238 VISU::TEntity theEntity,
239 const std::string& theFieldName) = 0;
241 virtual const VISU::PValForTime GetTimeStamp(const std::string& theMeshName,
242 const VISU::TEntity& theEntity,
243 const std::string& theFieldName,
244 int theStampsNum) = 0;
246 static std::string GenerateName(const VISU::TTime& aTime);
247 static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
251 VISU_Convertor* CreateConvertor(const std::string& theFileName) ;