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 154 155 156 157 158
|
/*=========================================================================
Program: ParaView
Module: vtkSMProxyConfigurationWriter.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkSMProxyConfigurationWriter.h"
#include "vtkObjectFactory.h"
#include "vtkSMProxy.h"
#include "vtkSMPropertyIterator.h"
#include "vtkSMNamedPropertyIterator.h"
#include "vtkSMProxyConfigurationFileInfo.h"
#include "vtkStringList.h"
#include "vtkPVXMLElement.h"
#include <fstream>
#include <iostream>
#define safeio(a) ((a)?(a):"NULL")
vtkStandardNewMacro(vtkSMProxyConfigurationWriter);
//---------------------------------------------------------------------------
vtkSMProxyConfigurationWriter::vtkSMProxyConfigurationWriter()
:
FileName(0),
Proxy(0),
PropertyIterator(0),
FileIdentifier(0),
FileDescription(0),
FileExtension(0)
{
vtkSMProxyConfigurationFileInfo info;
this->SetFileIdentifier(info.FileIdentifier);
this->SetFileDescription(info.FileDescription);
this->SetFileExtension(info.FileExtension);
}
//---------------------------------------------------------------------------
vtkSMProxyConfigurationWriter::~vtkSMProxyConfigurationWriter()
{
this->SetFileName(0);
this->SetProxy(0);
this->SetPropertyIterator(0);
this->SetFileIdentifier(0);
this->SetFileDescription(0);
this->SetFileExtension(0);
}
//---------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkSMProxyConfigurationWriter,PropertyIterator,vtkSMPropertyIterator);
//---------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkSMProxyConfigurationWriter,Proxy,vtkSMProxy);
//---------------------------------------------------------------------------
int vtkSMProxyConfigurationWriter::WriteConfiguration(std::ostream &os)
{
// The user didn't set a iterator, assume he wants all
// of the properties saved, use the default iterator.
int deleteIter=0;
vtkSMPropertyIterator *iter=this->PropertyIterator;
if (!iter)
{
iter=this->Proxy->NewPropertyIterator();
deleteIter=1;
}
os << "<?xml version=\"1.0\"?>" << endl;
vtkPVXMLElement* state=vtkPVXMLElement::New();
state->SetName(this->GetFileIdentifier());
state->AddAttribute("description",this->GetFileDescription());
state->AddAttribute("version",this->GetWriterVersion());
// We don't want Sub-proxy
this->Proxy->SaveXMLState(state, iter);
state->PrintXML(os, vtkIndent());
state->Delete();
// clean up the default iterator
if (deleteIter)
{
iter->Delete();
}
return 1;
}
//---------------------------------------------------------------------------
int vtkSMProxyConfigurationWriter::WriteConfiguration(const char *cFilename)
{
if (cFilename==0)
{
vtkErrorMacro("Cannot write filename NULL.");
return 0;
}
// If there client has set an extension then we add it if it's not
// present. To save with out th eextension, set it NULL.
const char *cExt=this->GetFileExtension();
cExt=(cExt==NULL?"":cExt);
std::string filename(cFilename);
std::string ext(cExt);
if (!ext.empty()
&& (filename.size()<=ext.size()
|| filename.find(ext,filename.size()-ext.size())==std::string::npos))
{
filename+=ext;
}
std::ofstream os(filename.c_str(), ios::out);
if (!os.good())
{
vtkErrorMacro("Failed to open " << filename.c_str() << " for writing.");
return 0;
}
this->WriteConfiguration(os);
os.close();
return 1;
}
//---------------------------------------------------------------------------
int vtkSMProxyConfigurationWriter::WriteConfiguration()
{
return this->WriteConfiguration(this->FileName);
}
//---------------------------------------------------------------------------
void vtkSMProxyConfigurationWriter::PrintSelf(std::ostream &os,
vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "FileName: " << safeio(this->FileName) << endl
<< indent << "Proxy: " << this->Proxy << endl
<< indent << "PropertyIterator: " << this->PropertyIterator << endl
<< indent << "Proxy: " << Proxy << endl
<< indent << "FileIdentifier: " << safeio(this->GetFileIdentifier()) << endl
<< indent << "FileDescription: " << safeio(this->GetFileDescription()) << endl
<< indent << "FileExtension: " << safeio(this->GetFileExtension()) << endl
<< indent << "WriterVersion: " << safeio(this->GetWriterVersion()) << endl;
}
|