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
|
/*=========================================================================
Program: ParaView
Module: vtkSMLink.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 "vtkSMLink.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkSMMessage.h"
#include "vtkSMProperty.h"
#include "vtkSMProxy.h"
#include "vtkPVSession.h"
#include <list>
//-----------------------------------------------------------------------------
class vtkSMLinkObserver : public vtkCommand
{
public:
static vtkSMLinkObserver* New()
{
return new vtkSMLinkObserver;
}
vtkSMLinkObserver()
{
this->Link = 0;
this->InProgress = false;
}
~vtkSMLinkObserver()
{
this->Link = 0;
}
virtual void Execute(vtkObject *c, unsigned long event, void* pname)
{
if(this->InProgress)
{
return;
}
if (this->Link && !this->Link->GetEnabled())
{
return;
}
this->InProgress = true;
vtkSMProxy* caller = vtkSMProxy::SafeDownCast(c);
if (this->Link && caller)
{
if (event == vtkCommand::UpdateEvent &&
this->Link->GetPropagateUpdateVTKObjects())
{
this->Link->UpdateVTKObjects(caller);
}
else if (event == vtkCommand::PropertyModifiedEvent)
{
this->Link->PropertyModified(caller, (const char*)pname);
}
else if (event == vtkCommand::UpdatePropertyEvent)
{
this->Link->UpdateProperty(caller, reinterpret_cast<char*>(pname));
}
}
this->InProgress = false;
}
vtkSMLink* Link;
bool InProgress;
};
//-----------------------------------------------------------------------------
vtkSMLink::vtkSMLink()
{
vtkSMLinkObserver* obs = vtkSMLinkObserver::New();
obs->Link = this;
this->Observer = obs;
this->PropagateUpdateVTKObjects = 1;
this->Enabled = true;
this->State = new vtkSMMessage();
this->SetLocation(vtkPVSession::CLIENT);
this->State->SetExtension(DefinitionHeader::server_class, "vtkSIObject"); // Dummy SIObject
}
//-----------------------------------------------------------------------------
vtkSMLink::~vtkSMLink()
{
((vtkSMLinkObserver*)this->Observer)->Link = NULL;
this->Observer->Delete();
this->Observer = NULL;
delete this->State; this->State = NULL;
}
//-----------------------------------------------------------------------------
void vtkSMLink::ObserveProxyUpdates(vtkSMProxy* proxy)
{
proxy->AddObserver(vtkCommand::PropertyModifiedEvent, this->Observer);
proxy->AddObserver(vtkCommand::UpdateEvent, this->Observer);
proxy->AddObserver(vtkCommand::UpdatePropertyEvent, this->Observer);
}
//-----------------------------------------------------------------------------
void vtkSMLink::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Enabled: " << this->Enabled << endl;
os << indent << "PropagateUpdateVTKObjects: " <<
this->PropagateUpdateVTKObjects << endl;
}
//-----------------------------------------------------------------------------
void vtkSMLink::PushStateToSession()
{
if(!this->IsLocalPushOnly() && this->GetSession())
{
this->State->SetExtension(DefinitionHeader::client_class, this->GetClassName());
this->State->SetExtension(LinkState::propagate_update, (this->PropagateUpdateVTKObjects != 0));
this->State->SetExtension(LinkState::enabled, this->Enabled);
this->PushState(this->State);
}
}
//-----------------------------------------------------------------------------
const vtkSMMessage* vtkSMLink::GetFullState()
{
return this->State;
}
//-----------------------------------------------------------------------------
void vtkSMLink::LoadState(const vtkSMMessage *msg, vtkSMProxyLocator *locator)
{
this->Superclass::LoadState(msg, locator);
this->SetPropagateUpdateVTKObjects(msg->GetExtension(LinkState::propagate_update) ? 1 : 0);
this->SetEnabled(msg->GetExtension(LinkState::enabled) ? 1 : 0);
}
|