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
|
/*=========================================================================
Program: ParaView
Module: vtkSIPVRepresentationProxy.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 "vtkSIPVRepresentationProxy.h"
#include "vtkClientServerInterpreter.h"
#include "vtkClientServerStream.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkPVCompositeRepresentation.h"
#include "vtkPVXMLElement.h"
#include "vtkSelectionRepresentation.h"
#include "vtkSmartPointer.h"
#include "vtkSISourceProxy.h"
#include <map>
#include <string>
#include <assert.h>
class vtkSIPVRepresentationProxy::vtkInternals
{
public:
struct vtkValue
{
vtkSmartPointer<vtkSIProxy> SubProxy;
std::string SubText;
};
typedef std::map<std::string, vtkValue> RepresentationProxiesType;
RepresentationProxiesType RepresentationProxies;
};
vtkStandardNewMacro(vtkSIPVRepresentationProxy);
//----------------------------------------------------------------------------
vtkSIPVRepresentationProxy::vtkSIPVRepresentationProxy()
{
this->Internals = new vtkInternals();
}
//----------------------------------------------------------------------------
vtkSIPVRepresentationProxy::~vtkSIPVRepresentationProxy()
{
delete this->Internals;
this->Internals = 0;
}
//----------------------------------------------------------------------------
bool vtkSIPVRepresentationProxy::ReadXMLAttributes(vtkPVXMLElement* element)
{
vtkPVCompositeRepresentation* pvrepresentation =
vtkPVCompositeRepresentation::SafeDownCast(this->GetVTKObject());
// Pass on the cube-axes and selection-represenations
vtkSelectionRepresentation* selection =
vtkSelectionRepresentation::SafeDownCast(
this->GetSubSIProxy("SelectionRepresentation")->GetVTKObject());
pvrepresentation->SetSelectionRepresentation(selection);
// Update internal data-structures for the types of representations provided
// by this instance.
// <RepresentationType subproxy="OutlineRepresentation" text="Outline"
// subtype="0"/>
unsigned int numElements = element->GetNumberOfNestedElements();
for (unsigned int cc=0; cc < numElements; cc++)
{
vtkPVXMLElement* child = element->GetNestedElement(cc);
if (child && child->GetName() &&
strcmp(child->GetName(), "RepresentationType") == 0)
{
const char* name = child->GetAttribute("subproxy");
vtkSIProxy* subproxy = this->GetSubSIProxy(name);
if (!subproxy)
{
vtkErrorMacro("Missing data representation subproxy '"
<< (name? name : "<null>")
<< "' when processing RepresentationType element.");
return false;
}
const char* text = child->GetAttribute("text");
if (!text)
{
vtkErrorMacro(
"Missing required 'text' attribute on RepresentationType element");
return false;
}
// Add each of the sub-representations to the composite representation.
pvrepresentation->AddRepresentation(text,
vtkPVDataRepresentation::SafeDownCast(subproxy->GetVTKObject()));
//// read optional subtype.
const char* sub_text = child->GetAttribute("subtype");
this->Internals->RepresentationProxies[text].SubProxy = subproxy;
if (sub_text)
{
this->Internals->RepresentationProxies[text].SubText = sub_text;
}
}
}
// We add observer to the vtkCompositeRepresentation so that every time it's
// modified, we ensure that the representation type is up-to-date.
vtkObject::SafeDownCast(this->GetVTKObject())->AddObserver(
vtkCommand::ModifiedEvent,
this, &vtkSIPVRepresentationProxy::OnVTKObjectModified);
return this->Superclass::ReadXMLAttributes(element);
}
//----------------------------------------------------------------------------
void vtkSIPVRepresentationProxy::OnVTKObjectModified()
{
vtkCompositeRepresentation* repr = vtkCompositeRepresentation::SafeDownCast(
this->GetVTKObject());
const char* key = repr->GetActiveRepresentationKey();
vtkInternals::RepresentationProxiesType::iterator iter = key?
this->Internals->RepresentationProxies.find(key) :
this->Internals->RepresentationProxies.end();
if (iter != this->Internals->RepresentationProxies.end() &&
iter->second.SubText != "")
{
vtkClientServerStream stream;
stream << vtkClientServerStream::Invoke
<< iter->second.SubProxy->GetVTKObject()
<< "SetRepresentation"
<< iter->second.SubText.c_str()
<< vtkClientServerStream::End;
this->Interpreter->ProcessStream(stream);
}
}
//----------------------------------------------------------------------------
void vtkSIPVRepresentationProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkSIPVRepresentationProxy::AboutToDelete()
{
this->Internals->RepresentationProxies.clear();
this->Superclass::AboutToDelete();
}
|