Back to index

salome-paravis  6.5.0
vtkMedFile.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "vtkMedFile.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkDataArraySelection.h"
00024 #include "vtkSmartPointer.h"
00025 
00026 #include "vtkMedMesh.h"
00027 #include "vtkMedField.h"
00028 #include "vtkMedProfile.h"
00029 #include "vtkMedLocalization.h"
00030 #include "vtkMedUtilities.h"
00031 #include "vtkMedLink.h"
00032 #include "vtkMedDriver.h"
00033 #include "vtkMedFactory.h"
00034 #include "vtkMedStructElement.h"
00035 
00036 vtkCxxGetObjectVectorMacro(vtkMedFile, Mesh, vtkMedMesh);
00037 vtkCxxSetObjectVectorMacro(vtkMedFile, Mesh, vtkMedMesh);
00038 
00039 vtkCxxGetObjectVectorMacro(vtkMedFile, Field, vtkMedField);
00040 vtkCxxSetObjectVectorMacro(vtkMedFile, Field, vtkMedField);
00041 
00042 vtkCxxGetObjectVectorMacro(vtkMedFile, Profile, vtkMedProfile);
00043 vtkCxxSetObjectVectorMacro(vtkMedFile, Profile, vtkMedProfile);
00044 
00045 vtkCxxGetObjectVectorMacro(vtkMedFile, Localization, vtkMedLocalization);
00046 vtkCxxSetObjectVectorMacro(vtkMedFile, Localization, vtkMedLocalization);
00047 
00048 vtkCxxGetObjectVectorMacro(vtkMedFile, Link, vtkMedLink);
00049 vtkCxxSetObjectVectorMacro(vtkMedFile, Link, vtkMedLink);
00050 
00051 vtkCxxGetObjectVectorMacro(vtkMedFile, StructElement, vtkMedStructElement);
00052 vtkCxxSetObjectVectorMacro(vtkMedFile, StructElement, vtkMedStructElement);
00053 
00054 vtkCxxGetObjectVectorMacro(vtkMedFile, SupportMesh, vtkMedMesh);
00055 vtkCxxSetObjectVectorMacro(vtkMedFile, SupportMesh, vtkMedMesh);
00056 
00057 vtkCxxSetObjectMacro(vtkMedFile, MedDriver, vtkMedDriver);
00058 
00059 vtkCxxRevisionMacro(vtkMedFile, "$Revision: 1.1.4.6.12.1 $")
00060 vtkStandardNewMacro(vtkMedFile)
00061 
00062 vtkMedFile::vtkMedFile()
00063 {
00064   this->Comment = NULL;
00065   this->Mesh = new vtkObjectVector<vtkMedMesh> ();
00066   this->Field = new vtkObjectVector<vtkMedField> ();
00067   this->Profile = new vtkObjectVector<vtkMedProfile> ();
00068   this->Localization = new vtkObjectVector<vtkMedLocalization> ();
00069   this->Link = new vtkObjectVector<vtkMedLink> ();
00070   this->StructElement = new vtkObjectVector<vtkMedStructElement>();
00071   this->SupportMesh = new vtkObjectVector<vtkMedMesh>();
00072   this->FileName = NULL;
00073   this->MedDriver = NULL;
00074   this->VersionMajor = -1;
00075   this->VersionMinor = -1;
00076   this->VersionRelease = -1;
00077 }
00078 
00079 vtkMedFile::~vtkMedFile()
00080 {
00081   this->SetComment(NULL);
00082   delete this->Mesh;
00083   delete this->Field;
00084   delete this->Profile;
00085   delete this->Localization;
00086   delete this->Link;
00087   delete this->StructElement;
00088   delete this->SupportMesh;
00089   this->SetFileName(NULL);
00090   this->SetMedDriver(NULL);
00091 }
00092 
00093 int vtkMedFile::CreateDriver()
00094 {
00095   int major, minor, release;
00096   vtkMedDriver* driver=vtkMedDriver::New();
00097   driver->SetMedFile(this);
00098   bool canRead=driver->CanReadFile();
00099   if(!canRead)
00100     {
00101     driver->Delete();
00102     this->SetMedDriver(NULL);
00103     return 0;
00104     }
00105   driver->ReadFileVersion(&major, &minor, &release);
00106   driver->Delete();
00107   vtkMedFactory* factory=vtkMedFactory::New();
00108   driver=factory->NewMedDriver(major, minor, release);
00109   factory->Delete();
00110   this->SetMedDriver(driver);
00111   if (driver)
00112     {
00113     driver->SetMedFile(this);
00114     return 1;
00115     }
00116   return 0;
00117 }
00118 
00119 void  vtkMedFile::ReadInformation()
00120 {
00121   if(this->MedDriver == NULL)
00122     {
00123     if(!this->CreateDriver())
00124       return;
00125     }
00126 
00127   // at this point, we know that we have a valid driver.
00128   this->MedDriver->ReadFileInformation(this);
00129 }
00130 
00131 vtkMedMesh* vtkMedFile::GetMesh(const char* str)
00132 {
00133   for (int m = 0; m < this->Mesh->size(); m++)
00134     {
00135     vtkMedMesh* mesh = this->Mesh->at(m);
00136     if (strcmp(mesh->GetName(), str) == 0)
00137       {
00138       return mesh;
00139       }
00140     }
00141   return NULL;
00142 }
00143 
00144 vtkMedProfile* vtkMedFile::GetProfile(const char* str)
00145 {
00146   for (int profId = 0; profId < this->Profile->size(); profId++)
00147     {
00148     vtkMedProfile* profile = this->Profile->at(profId);
00149     if (strcmp(profile->GetName(), str) == 0)
00150       {
00151       return profile;
00152       }
00153     }
00154   return NULL;
00155 
00156 }
00157 
00158 vtkMedLocalization* vtkMedFile::GetLocalization(const char* str)
00159 {
00160   for (int quadId = 0; quadId < this->Localization->size(); quadId++)
00161     {
00162     vtkMedLocalization* loc = this->Localization->at(quadId);
00163     if (strcmp(loc->GetName(), str) == 0)
00164       {
00165       return loc;
00166       }
00167     }
00168   return NULL;
00169 }
00170 
00171 vtkMedStructElement* vtkMedFile::GetStructElement(const vtkMedEntity& entity)
00172 {
00173   if(entity.EntityType != MED_STRUCT_ELEMENT)
00174     return NULL;
00175 
00176   for(int selemit = 0; selemit < this->GetNumberOfStructElement(); selemit++)
00177     {
00178     vtkMedStructElement* structelem = this->GetStructElement(selemit);
00179     if(structelem->GetGeometryType() == entity.GeometryType)
00180       return structelem;
00181     }
00182   return NULL;
00183 }
00184 
00185 void vtkMedFile::PrintSelf(ostream& os, vtkIndent indent)
00186 {
00187   this->Superclass::PrintSelf(os, indent);
00188 
00189   PRINT_OBJECT_VECTOR(os, indent, Mesh);
00190   PRINT_OBJECT_VECTOR(os, indent, Field);
00191   PRINT_OBJECT_VECTOR(os, indent, Profile);
00192   PRINT_OBJECT_VECTOR(os, indent, Localization);
00193   PRINT_OBJECT_VECTOR(os, indent, Link);
00194 }