File: vtkSMSelfGeneratingSourceProxy.cxx

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (198 lines) | stat: -rw-r--r-- 5,948 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMSelfGeneratingSourceProxy.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 "vtkSMSelfGeneratingSourceProxy.h"

#include "vtkClientServerStream.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVXMLElement.h"
#include "vtkPVXMLParser.h"
#include "vtkSMProxyInternals.h"
#include "vtkSmartPointer.h"

#include <cassert>
#include <sstream>
#include <string>
#include <vector>

class vtkSMSelfGeneratingSourceProxy::vtkInternals
{
public:
  std::vector<vtkSmartPointer<vtkPVXMLElement> > ExtendedDefinitionXMLs;

  // This is fairly simplistic, but then we don't expect this to be called too
  // frequently.
  bool Contains(vtkPVXMLElement* other)
  {
    assert(other);
    for (size_t cc = 0; cc < this->ExtendedDefinitionXMLs.size(); ++cc)
    {
      if (other->Equals(this->ExtendedDefinitionXMLs[cc]))
      {
        return true;
      }
    }
    return false;
  }
};

vtkStandardNewMacro(vtkSMSelfGeneratingSourceProxy);
//----------------------------------------------------------------------------
vtkSMSelfGeneratingSourceProxy::vtkSMSelfGeneratingSourceProxy()
{
  this->Internals = new vtkSMSelfGeneratingSourceProxy::vtkInternals();
}

//----------------------------------------------------------------------------
vtkSMSelfGeneratingSourceProxy::~vtkSMSelfGeneratingSourceProxy()
{
  delete this->Internals;
  this->Internals = NULL;
}

//----------------------------------------------------------------------------
bool vtkSMSelfGeneratingSourceProxy::ExtendDefinition(const char* additional_properties_definition)
{
  vtkNew<vtkPVXMLParser> parser;
  if (!parser->Parse(additional_properties_definition))
  {
    vtkErrorMacro("Failed to parse extended proxy definition. Not a valid XML.");
    return false;
  }

  return this->ExtendDefinition(parser->GetRootElement());
}

//----------------------------------------------------------------------------
bool vtkSMSelfGeneratingSourceProxy::ExtendDefinition(vtkPVXMLElement* xml)
{
  if (this->CreateSubProxiesAndProperties(this->GetSessionProxyManager(), xml) == 0)
  {
    return false;
  }

  if (this->ObjectsCreated != 0 && this->ExtendDefinitionOnSIProxy(xml) == false)
  {
    return false;
  }

  if (this->ObjectsCreated)
  {
    this->RebuildStateForProperties();
  }

  this->Internals->ExtendedDefinitionXMLs.push_back(xml);
  return true;
}

//----------------------------------------------------------------------------
void vtkSMSelfGeneratingSourceProxy::CreateVTKObjects()
{
  if (this->ObjectsCreated)
  {
    return;
  }
  this->Superclass::CreateVTKObjects();
  if (!this->ObjectsCreated)
  {
    return;
  }

  for (size_t cc = 0; cc < this->Internals->ExtendedDefinitionXMLs.size(); ++cc)
  {
    this->ExtendDefinitionOnSIProxy(this->Internals->ExtendedDefinitionXMLs[cc]);
  }
}

//----------------------------------------------------------------------------
bool vtkSMSelfGeneratingSourceProxy::ExtendDefinitionOnSIProxy(vtkPVXMLElement* xml)
{
  std::ostringstream str;
  xml->PrintXML(str, vtkIndent());

  // Notify SIProxy about the extended definition so when the property values
  // are pushed it knows what to do.
  vtkClientServerStream stream;
  stream << vtkClientServerStream::Invoke << SIPROXY(this) << "ExtendDefinition"
         << str.str().c_str() << vtkClientServerStream::End;
  this->ExecuteStream(stream);

  vtkClientServerStream result = this->GetLastResult();
  int tmp;
  if (result.GetNumberOfMessages() != 1 || result.GetNumberOfArguments(0) != 1 ||
    !result.GetArgument(0, 0, &tmp) || tmp == 0)
  {
    // failed on server side to load the definition. Should not happen
    // generally, but it may in some weird cases.
    return false;
  }
  return true;
}

//----------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSelfGeneratingSourceProxy::SaveXMLState(
  vtkPVXMLElement* root, vtkSMPropertyIterator* iter)
{
  if (vtkPVXMLElement* xml = this->Superclass::SaveXMLState(root, iter))
  {
    if (xml->FindNestedElementByName("ExtendedDefinition") == NULL)
    {
      vtkNew<vtkPVXMLElement> node;
      node->SetName("ExtendedDefinition");
      for (size_t cc = 0; cc < this->Internals->ExtendedDefinitionXMLs.size(); ++cc)
      {
        node->AddNestedElement(this->Internals->ExtendedDefinitionXMLs[cc]);
      }
      xml->AddNestedElement(node.GetPointer());
    }
    return xml;
  }

  return NULL;
}

//----------------------------------------------------------------------------
int vtkSMSelfGeneratingSourceProxy::LoadXMLState(
  vtkPVXMLElement* element, vtkSMProxyLocator* locator)
{
  std::vector<vtkPVXMLElement*> extensions;
  vtkPVXMLElement* defs = element ? element->FindNestedElementByName("ExtendedDefinition") : NULL;

  for (unsigned int cc = 0, max = (defs ? defs->GetNumberOfNestedElements() : 0); cc < max; ++cc)
  {
    vtkPVXMLElement* node = defs->GetNestedElement(cc);
    if (node && !this->Internals->Contains(node))
    {
      extensions.push_back(node);
    }
  }

  for (size_t cc = 0; cc < extensions.size(); ++cc)
  {
    if (!this->ExtendDefinition(extensions[cc]))
    {
      vtkErrorMacro("Failed to extend definition!");
      return 0;
    }
  }

  return this->Superclass::LoadXMLState(element, locator);
}

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