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: vtkSMProxyLocator.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 "vtkSMProxyLocator.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkSMDeserializer.h"
#include "vtkSMSession.h"
#include "vtkSMProxy.h"
#include "vtkCollection.h"
#include <map>
class vtkSMProxyLocator::vtkInternal
{
public:
typedef std::map<vtkTypeUInt32, vtkSmartPointer<vtkSMProxy> > ProxiesType;
ProxiesType Proxies;
ProxiesType AssignedProxies;
};
vtkStandardNewMacro(vtkSMProxyLocator);
vtkCxxSetObjectMacro(vtkSMProxyLocator, Deserializer, vtkSMDeserializer);
//----------------------------------------------------------------------------
vtkSMProxyLocator::vtkSMProxyLocator()
{
this->Internal = new vtkInternal();
this->Deserializer = 0;
this->Session = 0;
this->LocateProxyWithSessionToo = false;
}
//----------------------------------------------------------------------------
vtkSMProxyLocator::~vtkSMProxyLocator()
{
delete this->Internal;
this->SetDeserializer(0);
this->SetSession(0);
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMProxyLocator::LocateProxy(vtkTypeUInt32 id)
{
// Look in the cache first
vtkInternal::ProxiesType::iterator iter = this->Internal->Proxies.find(id);
if (iter != this->Internal->Proxies.end())
{
return iter->second.GetPointer();
}
// if custom assignments are specified, use those.
iter = this->Internal->AssignedProxies.find(id);
if (iter != this->Internal->AssignedProxies.end())
{
if (iter->second.GetPointer() != NULL)
{
// add to the Proxies map.
this->Internal->Proxies[id] = iter->second;
}
return iter->second.GetPointer();
}
// Try to lookup in session (if we setup the locator to use the session too)
vtkSMProxy* proxy;
if(this->LocateProxyWithSessionToo && this->Session)
{
proxy = vtkSMProxy::SafeDownCast(this->Session->GetRemoteObject(id));
if(proxy)
{
this->Internal->Proxies[id] = proxy;
return proxy;
}
}
// Create a brand new proxy
proxy = this->NewProxy(id);
if (proxy)
{
this->Internal->Proxies[id].TakeReference(proxy);
}
return proxy;
}
//----------------------------------------------------------------------------
void vtkSMProxyLocator::Clear()
{
this->Internal->Proxies.clear();
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMProxyLocator::NewProxy(vtkTypeUInt32 id)
{
if (this->Deserializer)
{
// Ask the deserializer to create a new proxy with the given id. The
// deserializer will locate the State(XML/Protobuf) for the proxy with
// that id, and load the state on it and then return this fresh proxy, if possible.
return this->Deserializer->NewProxy(id, this);
}
return 0;
}
//----------------------------------------------------------------------------
void vtkSMProxyLocator::AssignProxy(vtkTypeUInt32 gid, vtkSMProxy* proxy)
{
this->Internal->AssignedProxies[gid] = proxy;
}
//----------------------------------------------------------------------------
void vtkSMProxyLocator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Deserializer: " << this->Deserializer << endl;
}
//----------------------------------------------------------------------------
void vtkSMProxyLocator::GetLocatedProxies(vtkCollection* collectionToFill)
{
if(!collectionToFill)
{
return;
}
vtkInternal::ProxiesType::iterator iter = this->Internal->Proxies.begin();
while(iter != this->Internal->Proxies.end())
{
collectionToFill->AddItem(iter->second.GetPointer());
iter++;
}
}
//----------------------------------------------------------------------------
vtkSMSession* vtkSMProxyLocator::GetSession()
{
return this->Session.GetPointer();
}
//----------------------------------------------------------------------------
void vtkSMProxyLocator::SetSession(vtkSMSession* s)
{
this->Session = s;
if (this->Deserializer)
{
this->Deserializer->SetSessionProxyManager(
s? s->GetSessionProxyManager() : NULL);
}
}
|