File: vtkXMLVVFileInstanceReader.cxx

package info (click to toggle)
volview 3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 25,204 kB
  • sloc: cpp: 132,585; ansic: 11,612; tcl: 236; sh: 64; makefile: 25; xml: 8
file content (153 lines) | stat: -rw-r--r-- 4,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*=========================================================================

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "XML/vtkXMLVVFileInstanceReader.h"

#include "vtkObjectFactory.h"
#include "vtkVVFileInstance.h"
#include "vtkXMLDataElement.h"
#include "vtkStringArray.h"
#include "vtkKWOpenFileProperties.h"

#include "XML/vtkXMLVVFileInstanceWriter.h"
#include "XML/vtkXMLKWOpenFilePropertiesReader.h"

#include <vtksys/stl/string>
#include <vtksys/SystemTools.hxx>

vtkStandardNewMacro(vtkXMLVVFileInstanceReader);
vtkCxxRevisionMacro(vtkXMLVVFileInstanceReader, "$Revision: 1.17 $");

//----------------------------------------------------------------------------
const char* vtkXMLVVFileInstanceReader::GetRootElementName()
{
  return "VVFileInstance";
}

//----------------------------------------------------------------------------
int vtkXMLVVFileInstanceReader::Parse(vtkXMLDataElement *elem)
{
  if (!this->Superclass::Parse(elem))
    {
    return 0;
    }

  vtkVVFileInstance *obj = vtkVVFileInstance::SafeDownCast(this->Object);
  if (!obj)
    {
    vtkWarningMacro(<< "The VVFileInstance is not set!");
    return 0;
    }

  // Get Attributes

  obj->SetName(elem->GetAttribute("Name"));
  
  // Get nested elements

  vtkXMLDataElement *nested_elem;

  // Try to relocate the files on the fly if they are "dead" (i.e. if the
  // absolute path does not exist, try to find the files relative to the XML 
  // file we are parsing, if any)

  const char *parsed_from_file = elem->GetRoot()->GetAttribute(
    vtkXMLObjectReader::GetParsedFromFileAttributeName());
  if (parsed_from_file)
    {
    vtksys_stl::string path = 
      vtksys::SystemTools::GetFilenamePath(parsed_from_file);
    if (vtksys::SystemTools::FileExists(path.c_str()) &&
        vtksys::SystemTools::FileIsDirectory(path.c_str()))
      {
      obj->SetRelocationDirectory(path.c_str());
      }
    }

  // File Names

  obj->DeleteAllFileNames();
  
  int idx, nb_nested_elems = elem->GetNumberOfNestedElements();
  for (idx = 0; idx < nb_nested_elems; idx++)
    {
    nested_elem = elem->GetNestedElement(idx);
    if (!strcmp(nested_elem->GetName(), 
                vtkXMLVVFileInstanceWriter::GetFileNameElementName()))
      {
      const char *value = nested_elem->GetAttribute("Value");
      if (value)
        {
        obj->AddFileName(value);
        }

      // A URI for remote downloading - optional

      const char *sourceURI = 
        nested_elem->GetAttribute("SourceURI");
      const char *destinationURI = 
        nested_elem->GetAttribute("DestinationURI");
      if (sourceURI && destinationURI)
        {
        obj->SetFileNameURI(value, sourceURI, destinationURI);
        }

      // A Preview URI for remote downloading - optional

      const char *previewFile = 
        nested_elem->GetAttribute("PreviewFile");
      const char *previewSourceURI = 
        nested_elem->GetAttribute("PreviewSourceURI");
      const char *previewDestinationURI = 
        nested_elem->GetAttribute("PreviewDestinationURI");
      if (previewSourceURI && previewDestinationURI && previewFile)
        {
        obj->AddFileNamePreviewURI(value, previewFile, 
                                          previewSourceURI, 
                                          previewDestinationURI);
        }
      }
    }

  // Open File Properties

  vtksys_stl::string dir;
  if (obj->GetFileName())
    {
    dir = vtksys::SystemTools::GetFilenamePath(obj->GetFileName());
    }

  vtkKWOpenFileProperties *open_prop = vtkKWOpenFileProperties::New();
  vtkXMLKWOpenFilePropertiesReader *xmlr = 
    vtkXMLKWOpenFilePropertiesReader::SafeDownCast(
      open_prop->GetNewXMLReader());
  if (xmlr->ParseInElement(elem))
    {
    if (obj->GetOpenFileProperties())
      {
      obj->GetOpenFileProperties()->DeepCopy(open_prop);
      }
    else
      {
      obj->SetOpenFileProperties(open_prop); // ref counted
      }
    }
  open_prop->Delete();
  xmlr->Delete();

  return 1;
}

//----------------------------------------------------------------------------
void vtkXMLVVFileInstanceReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}