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
|
/*=========================================================================
Program: ParaView
Module: vtkSMDeserializerProtobuf.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 "vtkSMDeserializerProtobuf.h"
#include "vtkObjectFactory.h"
#include "vtkPVXMLElement.h"
#include "vtkSmartPointer.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyLocator.h"
#include "vtkSMProxyManager.h"
#include "vtkSMSession.h"
#include "vtkSMStateLocator.h"
#include "vtkSMMessage.h"
#define BEFORE_LOAD(proxy) \
if (session && session->IsProcessingRemoteNotification()) \
{ proxy->EnableLocalPushOnly(); }
#define AFTER_LOAD(proxy) \
if (session && session->IsProcessingRemoteNotification()) \
{ proxy->DisableLocalPushOnly(); }
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkSMDeserializerProtobuf);
vtkCxxSetObjectMacro(vtkSMDeserializerProtobuf, StateLocator, vtkSMStateLocator);
//----------------------------------------------------------------------------
vtkSMDeserializerProtobuf::vtkSMDeserializerProtobuf()
{
this->StateLocator = 0;
}
//----------------------------------------------------------------------------
vtkSMDeserializerProtobuf::~vtkSMDeserializerProtobuf()
{
this->SetStateLocator(0);
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMDeserializerProtobuf::NewProxy(vtkTypeUInt32 id, vtkSMProxyLocator* locator)
{
vtkSMSession* session = this->GetSession();
// Make sure that the requested proxy does not already exist
assert( "SMDeserializer should not create a proxy if that proxy exist" &&
(session == NULL || session->GetRemoteObject(id) == NULL));
vtkSMMessage msg;
// First extract state for the requested proxy
// Did not find the proxy, start the creation procedure
if (!this->StateLocator || !this->StateLocator->FindState(id, &msg))
{
return 0;
}
// ** isn't this unused code especially after the assert(..) above? Commenting
// out as a result. ***
//// Try to NOT create a new proxy if already exist and just load the state
//vtkSMProxy* proxy =
// vtkSMProxy::SafeDownCast(this->Session->GetRemoteObject(id));
//if(proxy)
// {
// if(this->StateLocator->FindState(id, &msg))
// {
// BEFORE_LOAD(proxy)
// proxy->LoadState(&msg, locator);
// proxy->UpdateVTKObjects();
// AFTER_LOAD(proxy)
// }
// return proxy;
// }
const char* group = msg.GetExtension(ProxyState::xml_group).c_str();
const char* type = msg.GetExtension(ProxyState::xml_name).c_str();
const char* subProxyName = (msg.HasExtension(ProxyState::xml_sub_proxy_name))
? msg.GetExtension(ProxyState::xml_sub_proxy_name).c_str():
NULL;
if (!type)
{
vtkErrorMacro("Could not create proxy from element, missing 'type'.");
return 0;
}
// Create Proxy based on its XML definition
vtkSMProxy* proxy = this->CreateProxy(group, type, subProxyName);
if (!proxy)
{
vtkErrorMacro("Could not create a proxy of group: "
<< (group ? group : "(null)")
<< " type: " << type
<< " subProxyName: "
<< (subProxyName ? subProxyName : "(null)"));
return 0;
}
// Load the state of the proxy now
BEFORE_LOAD(proxy)
proxy->LoadState(&msg, locator);
proxy->UpdateVTKObjects();
AFTER_LOAD(proxy)
return proxy;
}
//----------------------------------------------------------------------------
void vtkSMDeserializerProtobuf::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|