Back to index

salome-paravis  6.5.0
vtkMedLink.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 "vtkMedLink.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 
00024 #include "vtkMedUtilities.h"
00025 
00026 #include <string>
00027 using namespace std;
00028 
00029 vtkCxxRevisionMacro(vtkMedLink, "$Revision: 1.1.4.5.2.1 $")
00030 vtkStandardNewMacro(vtkMedLink)
00031 
00032 vtkMedLink::vtkMedLink()
00033 {
00034   this->MedIterator = -1;
00035   this->MeshName = NULL;
00036   this->Link = NULL;
00037 }
00038 
00039 vtkMedLink::~vtkMedLink()
00040 {
00041   this->SetMeshName(NULL);
00042   this->SetLink(NULL);
00043 }
00044 
00045 const char* vtkMedLink::GetFullLink(const char* originalFileName)
00046 {
00047 #ifdef _WIN32
00048   static const char sep = '\\';
00049 #else
00050   static const char sep = '/';
00051 #endif
00052 
00053   if(this->Link == NULL)
00054     {
00055     return NULL;
00056     }
00057 
00058   // First test if the Link is a full path, then return it.
00059   if(this->Link != NULL && this->Link[0] == sep)
00060     {
00061     return this->Link;
00062     }
00063 
00064   string name = string(originalFileName);
00065   size_t pos = name.find_last_of(sep);
00066   if(pos == string::npos)
00067     {
00068     return this->Link;
00069     }
00070 
00071   string clean_link = this->Link;
00072   string to_remove = string(".") + sep;
00073   int to_remove_size = to_remove.size();
00074   while(clean_link.substr(0, to_remove_size) == to_remove)
00075     clean_link = clean_link.substr(to_remove_size, string::npos);
00076 
00077   string path = name.substr(0, pos+1);
00078   this->FullLinkPath = path + clean_link;
00079   return this->FullLinkPath.c_str();
00080 }
00081 
00082 void   vtkMedLink::SetMountedIterator(med_class what, med_int mit)
00083 {
00084   this->MountedIterator[what] = mit;
00085 }
00086 
00087 med_int  vtkMedLink::GetMountedIterator(med_class what)
00088 {
00089   if(this->MountedIterator.find(what) == this->MountedIterator.end())
00090     return -1;
00091 
00092   return this->MountedIterator[what];
00093 }
00094 
00095 void vtkMedLink::PrintSelf(ostream& os, vtkIndent indent)
00096 {
00097   this->Superclass::PrintSelf(os, indent);
00098   PRINT_IVAR(os, indent, MedIterator);
00099 }