1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "MEDMEM_VtkMedDriver.hxx"
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Field.hxx"
29 #include "MEDMEM_Support.hxx"
30 #include "MEDMEM_Mesh.hxx"
31 #include "MEDMEM_CellModel.hxx"
34 using namespace MEDMEM;
35 using namespace MED_EN;
37 VTK_MED_DRIVER::VTK_MED_DRIVER(): GENDRIVER(VTK_DRIVER), _fields(0)
42 VTK_MED_DRIVER::VTK_MED_DRIVER(const string & fileName,
43 const vector< const FIELD_* >& fields):
44 GENDRIVER(fileName, MED_EN::RDWR, VTK_DRIVER), _fields( fields )
48 VTK_MED_DRIVER::VTK_MED_DRIVER(const VTK_MED_DRIVER & driver):
49 GENDRIVER(driver), _fields(driver._fields)
53 VTK_MED_DRIVER::~VTK_MED_DRIVER()
55 const char* LOC = "VTK_MED_DRIVER::~VTK_MED_DRIVER()";
61 GENDRIVER * VTK_MED_DRIVER::copy() const
63 return new VTK_MED_DRIVER(*this) ;
66 void VTK_MED_DRIVER::openConst() const
68 const char * LOC ="VTK_MED_DRIVER::open() : ";
71 if ( _fileName == "" )
72 throw MED_EXCEPTION( LOCALIZED( STRING(LOC)
73 << "_fileName is |\"\"|, please set a correct fileName before calling open()"));
75 // check if can open the file
77 _vtkFile.open(_fileName.c_str());
79 throw MED_EXCEPTION( LOCALIZED( STRING(LOC) << "Could not open file "<< _fileName));
84 void VTK_MED_DRIVER::open() {
88 void VTK_MED_DRIVER::closeConst() const {
90 const char* LOC = "VTK_MED_DRIVER::close() : ";
95 void VTK_MED_DRIVER::close() {
100 void VTK_MED_DRIVER::write() const
102 const char* LOC = "VTK_MED_DRIVER::write() : ";
105 // VTK supports only one dataset per a file (in Simple Legacy Formats)
106 // so we write the first mesh only
108 const int NumberOfMeshes = ( !_fields.empty() ) ? 1 : 0;
110 for (int i=0; i<NumberOfMeshes; i++)
112 const GMESH * myMesh = _fields.at(i)->getSupport()->getMesh();
114 for (unsigned j=0; j<_fields.size(); j++)
116 const FIELD_ * myField = _fields.at(j);
117 if( myMesh == myField->getSupport()->getMesh() )
119 if (MED_NODE == myField->getSupport()->getEntity())
121 if (myField->getSupport()->isOnAllElements())
123 writeField(myField,STRING(myField->getName()) << "_" << myField->getIterationNumber() << "_" << myField->getOrderNumber() ) ;
127 MESSAGE_MED(PREFIX_MED << "Could not write field "<<myField->getName()<<" which is not on all nodes !");
133 // second : field on cell
134 for (unsigned j=0; j<_fields.size(); j++)
136 const FIELD_ * myField = _fields.at(j);
137 if( myMesh == myField->getSupport()->getMesh() )
138 if (MED_CELL == myField->getSupport()->getEntity())
140 if (myField->getSupport()->isOnAllElements())
142 writeField(myField,STRING(myField->getName()) << "_" << myField->getIterationNumber() << "_" << myField->getOrderNumber() );
146 MESSAGE_MED(PREFIX_MED << "Could not write field "<<myField->getName()<<" which is not on all cells !");
155 void VTK_MED_DRIVER::writeMesh(const GMESH * myMesh) const
157 const char * LOC = "VTK_MED_DRIVER::writeMesh() : ";
160 VTK_MESH_DRIVER meshDriver( _fileName, myMesh );
166 void VTK_MED_DRIVER::writeField(const FIELD_ * myField,string name) const
168 const char* LOC = "VTK_MED_DRIVER::writeField() : ";
171 med_type_champ type = myField->getValueType() ;
172 GENDRIVER* driver = 0;
177 if ( myField->getInterlacingType() == MED_FULL_INTERLACE )
178 driver = new VTK_FIELD_DRIVER<int>(_fileName,
179 static_cast< const FIELD<int,FullInterlace>* >(myField));
181 else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE )
182 driver = new VTK_FIELD_DRIVER<int>(_fileName,
183 static_cast< const FIELD<int,NoInterlaceByType>* >(myField));
186 driver = new VTK_FIELD_DRIVER<int>(_fileName,
187 static_cast< const FIELD<int,NoInterlace>* >(myField));
192 if ( myField->getInterlacingType() == MED_FULL_INTERLACE )
193 driver = new VTK_FIELD_DRIVER<double>(_fileName,
194 static_cast< const FIELD<double,FullInterlace>* >(myField));
196 else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE )
197 driver = new VTK_FIELD_DRIVER<double>(_fileName,
198 static_cast< const FIELD<double,NoInterlaceByType>*>(myField));
201 driver = new VTK_FIELD_DRIVER<double>(_fileName,
202 static_cast< const FIELD<double,NoInterlace>* >(myField));
207 MESSAGE_MED(PREFIX_MED << "Could not write field "<<name<<" the type is not int or double !");
213 driver->writeAppend();
219 // void VTK_MED_DRIVER::writeSupport(SUPPORT * mySupport) const {
220 // const char* LOC = "VTK_MED_DRIVER::writeSupport(SUPPORT *) : ";
221 // BEGIN_OF_MED(LOC);
222 // MESSAGE_MED(PREFIX_MED << "Not yet implemented, acting on the object " << *mySupport);