Salome HOME
Fix test case hang-up
[modules/paravis.git] / src / Plugins / MedReader / IO / vtkMedLink.cxx
1 // Copyright (C) 2010-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "vtkMedLink.h"
21
22 #include "vtkObjectFactory.h"
23
24 #include "vtkMedUtilities.h"
25
26 #include <string>
27 using namespace std;
28
29 // vtkCxxRevisionMacro(vtkMedLink, "$Revision$")
30 vtkStandardNewMacro(vtkMedLink)
31
32 vtkMedLink::vtkMedLink()
33 {
34   this->MedIterator = -1;
35   this->MeshName = NULL;
36   this->Link = NULL;
37 }
38
39 vtkMedLink::~vtkMedLink()
40 {
41   this->SetMeshName(NULL);
42   this->SetLink(NULL);
43 }
44
45 const char* vtkMedLink::GetFullLink(const char* originalFileName)
46 {
47 #ifdef _WIN32
48   static const char sep = '\\';
49 #else
50   static const char sep = '/';
51 #endif
52
53   if(this->Link == NULL)
54     {
55     return NULL;
56     }
57
58   // First test if the Link is a full path, then return it.
59   if(this->Link != NULL && this->Link[0] == sep)
60     {
61     return this->Link;
62     }
63
64   string name = string(originalFileName);
65   size_t pos = name.find_last_of(sep);
66   if(pos == string::npos)
67     {
68     return this->Link;
69     }
70
71   string clean_link = this->Link;
72   string to_remove = string(".") + sep;
73   int to_remove_size = to_remove.size();
74   while(clean_link.substr(0, to_remove_size) == to_remove)
75     clean_link = clean_link.substr(to_remove_size, string::npos);
76
77   string path = name.substr(0, pos+1);
78   this->FullLinkPath = path + clean_link;
79   return this->FullLinkPath.c_str();
80 }
81
82 void   vtkMedLink::SetMountedIterator(med_class what, med_int mit)
83 {
84   this->MountedIterator[what] = mit;
85 }
86
87 med_int  vtkMedLink::GetMountedIterator(med_class what)
88 {
89   if(this->MountedIterator.find(what) == this->MountedIterator.end())
90     return -1;
91
92   return this->MountedIterator[what];
93 }
94
95 void vtkMedLink::PrintSelf(ostream& os, vtkIndent indent)
96 {
97   this->Superclass::PrintSelf(os, indent);
98   PRINT_IVAR(os, indent, MedIterator);
99 }