1 // Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkMedFile.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkDataArraySelection.h"
24 #include "vtkSmartPointer.h"
26 #include "vtkMedMesh.h"
27 #include "vtkMedField.h"
28 #include "vtkMedProfile.h"
29 #include "vtkMedLocalization.h"
30 #include "vtkMedUtilities.h"
31 #include "vtkMedLink.h"
32 #include "vtkMedDriver.h"
33 #include "vtkMedFactory.h"
34 #include "vtkMedStructElement.h"
36 vtkCxxGetObjectVectorMacro(vtkMedFile, Mesh, vtkMedMesh);
37 vtkCxxSetObjectVectorMacro(vtkMedFile, Mesh, vtkMedMesh);
39 vtkCxxGetObjectVectorMacro(vtkMedFile, Field, vtkMedField);
40 vtkCxxSetObjectVectorMacro(vtkMedFile, Field, vtkMedField);
42 vtkCxxGetObjectVectorMacro(vtkMedFile, Profile, vtkMedProfile);
43 vtkCxxSetObjectVectorMacro(vtkMedFile, Profile, vtkMedProfile);
45 vtkCxxGetObjectVectorMacro(vtkMedFile, Localization, vtkMedLocalization);
46 vtkCxxSetObjectVectorMacro(vtkMedFile, Localization, vtkMedLocalization);
48 vtkCxxGetObjectVectorMacro(vtkMedFile, Link, vtkMedLink);
49 vtkCxxSetObjectVectorMacro(vtkMedFile, Link, vtkMedLink);
51 vtkCxxGetObjectVectorMacro(vtkMedFile, StructElement, vtkMedStructElement);
52 vtkCxxSetObjectVectorMacro(vtkMedFile, StructElement, vtkMedStructElement);
54 vtkCxxGetObjectVectorMacro(vtkMedFile, SupportMesh, vtkMedMesh);
55 vtkCxxSetObjectVectorMacro(vtkMedFile, SupportMesh, vtkMedMesh);
57 vtkCxxSetObjectMacro(vtkMedFile, MedDriver, vtkMedDriver);
59 //vtkCxxRevisionMacro(vtkMedFile, "$Revision$")
60 vtkStandardNewMacro(vtkMedFile)
62 vtkMedFile::vtkMedFile()
65 this->Mesh = new vtkObjectVector<vtkMedMesh> ();
66 this->Field = new vtkObjectVector<vtkMedField> ();
67 this->Profile = new vtkObjectVector<vtkMedProfile> ();
68 this->Localization = new vtkObjectVector<vtkMedLocalization> ();
69 this->Link = new vtkObjectVector<vtkMedLink> ();
70 this->StructElement = new vtkObjectVector<vtkMedStructElement>();
71 this->SupportMesh = new vtkObjectVector<vtkMedMesh>();
72 this->FileName = NULL;
73 this->MedDriver = NULL;
74 this->VersionMajor = -1;
75 this->VersionMinor = -1;
76 this->VersionRelease = -1;
79 vtkMedFile::~vtkMedFile()
81 this->SetComment(NULL);
85 delete this->Localization;
87 delete this->StructElement;
88 delete this->SupportMesh;
89 this->SetFileName(NULL);
90 this->SetMedDriver(NULL);
93 int vtkMedFile::CreateDriver()
95 int major, minor, release;
96 vtkMedDriver* driver=vtkMedDriver::New();
97 driver->SetMedFile(this);
98 bool canRead=driver->CanReadFile();
102 this->SetMedDriver(NULL);
105 driver->ReadFileVersion(&major, &minor, &release);
107 vtkMedFactory* factory=vtkMedFactory::New();
108 driver=factory->NewMedDriver(major, minor, release);
110 this->SetMedDriver(driver);
113 driver->SetMedFile(this);
119 void vtkMedFile::ReadInformation()
121 if(this->MedDriver == NULL)
123 if(!this->CreateDriver())
127 // at this point, we know that we have a valid driver.
128 this->MedDriver->ReadFileInformation(this);
131 vtkMedMesh* vtkMedFile::GetMesh(const char* str)
133 for (int m = 0; m < this->Mesh->size(); m++)
135 vtkMedMesh* mesh = this->Mesh->at(m);
136 if (strcmp(mesh->GetName(), str) == 0)
144 vtkMedProfile* vtkMedFile::GetProfile(const char* str)
146 for (int profId = 0; profId < this->Profile->size(); profId++)
148 vtkMedProfile* profile = this->Profile->at(profId);
149 if (strcmp(profile->GetName(), str) == 0)
158 vtkMedLocalization* vtkMedFile::GetLocalization(const char* str)
160 for (int quadId = 0; quadId < this->Localization->size(); quadId++)
162 vtkMedLocalization* loc = this->Localization->at(quadId);
163 if (strcmp(loc->GetName(), str) == 0)
171 vtkMedStructElement* vtkMedFile::GetStructElement(const vtkMedEntity& entity)
173 if(entity.EntityType != MED_STRUCT_ELEMENT)
176 for(int selemit = 0; selemit < this->GetNumberOfStructElement(); selemit++)
178 vtkMedStructElement* structelem = this->GetStructElement(selemit);
179 if(structelem->GetGeometryType() == entity.GeometryType)
185 void vtkMedFile::PrintSelf(ostream& os, vtkIndent indent)
187 this->Superclass::PrintSelf(os, indent);
189 PRINT_OBJECT_VECTOR(os, indent, Mesh);
190 PRINT_OBJECT_VECTOR(os, indent, Field);
191 PRINT_OBJECT_VECTOR(os, indent, Profile);
192 PRINT_OBJECT_VECTOR(os, indent, Localization);
193 PRINT_OBJECT_VECTOR(os, indent, Link);