Commit 5edb803f authored by Sebastien Jourdain's avatar Sebastien Jourdain

Add property level filtering in undo state

- Now properties can be escaped from the GetFullState() method that is
  used for the undo/redo state by providing an extra attribute inside
  xml proxy definition.

   <Proxy name="ComparativeViewBase">
      <DoubleVectorProperty name="ViewTime"
        command="SetViewTime"
        number_of_elements="1"
        state_ignored="1" <---------------------- NEW FLAG
        default_values="none">
        <DoubleRangeDomain name="range"/>
        <Documentation>
          The pipeline update time for this view.
          This gets passed to all representations added to this view.
        </Documentation>
      </DoubleVectorProperty>
   ...

- Some code clean up by removing the undo element used to create/delete proxy
  as well as the associated methods.

- Some debug code removed as well
parent 0d654f6c
......@@ -73,15 +73,18 @@ void pqUndoStackBuilder::SetUndoStack(vtkSMUndoStack* stack)
this->Superclass::SetUndoStack(stack);
}
//-----------------------------------------------------------------------------
void pqUndoStackBuilder::OnCreation( vtkSMSession *session,
vtkTypeUInt32 globalId,
const vtkSMMessage *creationState)
void pqUndoStackBuilder::OnStateChange( vtkSMSession *session,
vtkTypeUInt32 globalId,
const vtkSMMessage *oldState,
const vtkSMMessage *newState)
{
vtkSMRemoteObject* proxy = session->GetRemoteObject(globalId);
// FIXME make sure we don't escape too much (Utkarsh)
// FIXME COLLABORATION make sure we don't escape too much (Utkarsh)
// We filter proxy type that must not be involved in undo/redo state.
// The property themselves are already filtered based on a flag in the XML.
// XML Flag: state_ignored="1"
if( !proxy || (proxy && (
proxy->IsA("vtkSMViewProxy") ||
proxy->IsA("vtkSMCameraProxy") ||
proxy->IsA("vtkSMTimeKeeperProxy") ||
proxy->IsA("vtkSMAnimationScene") ||
......@@ -102,92 +105,7 @@ void pqUndoStackBuilder::OnCreation( vtkSMSession *session,
this->Begin(stream.str().c_str());
}
this->Superclass::OnCreation(session, globalId, creationState);
if (auto_element)
{
this->End();
if (this->UndoSet->GetNumberOfElements() > 0)
{
this->PushToStack();
}
}
}
//-----------------------------------------------------------------------------
void pqUndoStackBuilder::OnDeletion( vtkSMSession *session,
vtkTypeUInt32 globalId,
const vtkSMMessage *previousState)
{
vtkSMRemoteObject* proxy = session->GetRemoteObject(globalId);
// FIXME make sure we don't escape too much (Utkarsh)
if( !proxy || (proxy && (
//proxy->IsA("vtkSMViewProxy") ||
proxy->IsA("vtkSMCameraProxy") ||
proxy->IsA("vtkSMTimeKeeperProxy") ||
proxy->IsA("vtkSMAnimationScene") ||
proxy->IsA("vtkSMAnimationSceneProxy") ||
proxy->IsA("vtkSMNewWidgetRepresentationProxy") ||
proxy->IsA("vtkSMScalarBarWidgetRepresentationProxy"))))
{
return;
}
bool auto_element = !this->IgnoreAllChanges &&
!this->IgnoreIsolatedChanges && !this->UndoRedoing;
if (auto_element)
{
vtksys_ios::ostringstream stream;
stream << "Changed '" << proxy->GetClassName() <<"'";
this->Begin(stream.str().c_str());
}
this->Superclass::OnDeletion(session, globalId, previousState);
if (auto_element)
{
this->End();
if (this->UndoSet->GetNumberOfElements() > 0)
{
this->PushToStack();
}
}
}
//-----------------------------------------------------------------------------
void pqUndoStackBuilder::OnUpdate( vtkSMSession *session,
vtkTypeUInt32 globalId,
const vtkSMMessage *oldState,
const vtkSMMessage *newState)
{
vtkSMRemoteObject* proxy = session->GetRemoteObject(globalId);
// FIXME make sure we don't escape too much (Utkarsh)
if( !proxy || (proxy && (
//proxy->IsA("vtkSMViewProxy") ||
proxy->IsA("vtkSMCameraProxy") ||
proxy->IsA("vtkSMTimeKeeperProxy") ||
proxy->IsA("vtkSMAnimationScene") ||
proxy->IsA("vtkSMAnimationSceneProxy") ||
proxy->IsA("vtkSMNewWidgetRepresentationProxy") ||
proxy->IsA("vtkSMScalarBarWidgetRepresentationProxy"))))
{
return;
}
bool auto_element = !this->IgnoreAllChanges &&
!this->IgnoreIsolatedChanges && !this->UndoRedoing;
if (auto_element)
{
vtksys_ios::ostringstream stream;
stream << "Changed '" << proxy->GetClassName() <<"'";
this->Begin(stream.str().c_str());
}
this->Superclass::OnUpdate(session, globalId, oldState, newState);
this->Superclass::OnStateChange(session, globalId, oldState, newState);
if (auto_element)
{
......
......@@ -87,13 +87,9 @@ public:
virtual void SetUndoStack(vtkSMUndoStack*);
/// Overridden to filter unwanted event and manage auto undoset creation
virtual void OnCreation(vtkSMSession *session, vtkTypeUInt32 globalId,
const vtkSMMessage *creationState);
virtual void OnUpdate(vtkSMSession *session, vtkTypeUInt32 globalId,
const vtkSMMessage *previousState,
const vtkSMMessage *newState);
virtual void OnDeletion(vtkSMSession *session, vtkTypeUInt32 globalId,
const vtkSMMessage *previousState);
virtual void OnStateChange(vtkSMSession *session, vtkTypeUInt32 globalId,
const vtkSMMessage *previousState,
const vtkSMMessage *newState);
protected:
pqUndoStackBuilder();
......
......@@ -41,7 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkUndoSet.h"
#include "vtkSMUndoElement.h"
#include "vtkSMProxyUndoElement.h"
#include "vtkSMRemoteObjectUpdateUndoElement.h"
......
......@@ -94,7 +94,7 @@ int vtkUndoSet::Redo()
elem->SetUndoSetWorkingContext(this->TmpWorkingCollection);
if (!elem->Redo())
{
cout << "Failing !!! >>>" << endl;
vtkDebugMacro("Redo Action is failing. Start redoing the actions.");
// redo failed, undo the half redone operations.
for (int rr=cc-1; rr >=0; --rr)
{
......@@ -106,7 +106,6 @@ int vtkUndoSet::Redo()
}
// Release ref of tmp objects
this->TmpWorkingCollection->RemoveAllItems();
cout << "<<<< Failing !!!" << endl;
return 0;
}
elem->SetUndoSetWorkingContext(0); // Clear Working context
......@@ -130,7 +129,7 @@ int vtkUndoSet::Undo()
elem->SetUndoSetWorkingContext(this->TmpWorkingCollection);
if (!elem->Undo())
{
cout << "Failing !!! >>>" << endl;
vtkDebugMacro("Undo Action is failing. Start redoing the actions.");
// undo failed, redo the half undone operations.
for (int rr=0; rr <cc; ++rr)
{
......@@ -142,7 +141,6 @@ int vtkUndoSet::Undo()
}
// Release ref of tmp objects
this->TmpWorkingCollection->RemoveAllItems();
cout << "<<<< Failing !!!" << endl;
return 0;
}
elem->SetUndoSetWorkingContext(0); // Clear Working context
......
......@@ -106,7 +106,6 @@ SET (Kit_SRCS
vtkSMProxyManager.cxx
vtkSMProxyProperty.cxx
vtkSMProxySelectionModel.cxx
vtkSMProxyUndoElement.cxx
vtkSMPSWriterProxy.cxx
vtkSMPVRepresentationProxy.cxx
vtkSMPWriterProxy.cxx
......
......@@ -852,6 +852,7 @@
command="AddViewProxy"
clean_command="RemoveAllViewProxies"
repeat_command="1"
state_ignored="1"
argument_type="SMProxy" >
<ProxyGroupDomain name="groups">
<Group name="views" />
......@@ -2018,6 +2019,7 @@
command="AddView"
remove_command="RemoveView"
argument_type="SMProxy"
state_ignored="1"
repeatable="1">
<Documentation>
Views with their view time linked with this time keeper.
......
......@@ -9,6 +9,7 @@
<DoubleVectorProperty name="ViewTime"
command="SetViewTime"
number_of_elements="1"
state_ignored="1"
default_values="none">
<DoubleRangeDomain name="range"/>
<Documentation>
......@@ -52,6 +53,7 @@
<IntVectorProperty name="ViewSize"
command="SetSize"
number_of_elements="2"
state_ignored="1"
default_values="400 400" >
<Documentation>
Set the size of this view in the multiview configuration.
......@@ -4073,6 +4075,7 @@
<DoubleVectorProperty name="ViewTime"
command="SetViewTime"
number_of_elements="1"
state_ignored="1"
default_values="none">
<DoubleRangeDomain name="range"/>
<Documentation>
......@@ -4114,6 +4117,7 @@
<IntVectorProperty name="ViewSize"
command="SetViewSize"
number_of_elements="2"
state_ignored="1"
default_values="400 400" >
<Documentation>
Set the size of this view in the multiview configuration.
......
......@@ -81,9 +81,5 @@ bool vtkPMTimeStepsProperty::Pull(vtkSMMessage* msgToFill)
}
return true;
}
else
{
outInfo->PrintSelf(cout, vtkIndent(5));
}
return false;
}
......@@ -64,10 +64,6 @@ void vtkSMIdTypeVectorProperty::WriteTo(vtkSMMessage* msg)
//---------------------------------------------------------------------------
void vtkSMIdTypeVectorProperty::ReadFrom(const vtkSMMessage* msg, int offset)
{
//cout << ">>>>>>>>>>>>" << endl;
//msg->PrintDebugString();
//cout << "<<<<<<<<<<<<" << endl;
assert(msg->ExtensionSize(ProxyState::property) > offset);
const ProxyState_Property *prop = &msg->GetExtension(ProxyState::property,
......
......@@ -42,6 +42,7 @@ int vtkSMProperty::CheckDomains = 0;
//---------------------------------------------------------------------------
vtkSMProperty::vtkSMProperty()
{
this->StateIgnored = false;
this->Command = 0;
this->ImmediateUpdate = 0;
this->Animateable = 2; // By default Animateable in advanced mode only.
......@@ -313,9 +314,20 @@ int vtkSMProperty::ReadXMLAttributes(vtkSMProxy* vtkNotUsed(proxy),
int immediate_update;
retVal = element->GetScalarAttribute("immediate_update", &immediate_update);
if(retVal)
{
this->SetImmediateUpdate(immediate_update);
if(retVal)
{
this->SetImmediateUpdate(immediate_update);
}
int state_ignored;
retVal = element->GetScalarAttribute("state_ignored", &state_ignored);
if(retVal)
{
this->SetStateIgnored( state_ignored );
}
else
{
this->StateIgnoredOff(); // Default value
}
int update_self;
......
......@@ -247,6 +247,10 @@ public:
vtkSMProxy* GetParent()
{ return this->Proxy; }
// Flag used to ignore property when building Proxy state for Undo/Redo state.
// The default value is false.
virtual bool IsStateIgnored() { return this->StateIgnored; }
//BTX
protected:
vtkSMProperty();
......@@ -385,6 +389,12 @@ protected:
vtkSMProxy* Proxy;
// Flag used to ignore property when building Proxy state for Undo/Redo state.
// The default value is false.
bool StateIgnored;
vtkSetMacro(StateIgnored, bool);
vtkBooleanMacro(StateIgnored, bool);
private:
vtkSMProperty(const vtkSMProperty&); // Not implemented
void operator=(const vtkSMProperty&); // Not implemented
......
......@@ -561,7 +561,7 @@ void vtkSMProxy::UpdateVTKObjects()
vtkSMProperty* property = iter->second.Property;
if (property && !property->GetInformationOnly())
{
if (property->GetIsInternal() ||
if (property->GetIsInternal() || property->IsStateIgnored() ||
strcmp(property->GetClassName(), "vtkSMProperty") == 0)
{
// Push only modified properties
......@@ -708,7 +708,7 @@ void vtkSMProxy::CreateVTKObjects()
vtkSMProperty* property = iter->second.Property;
if (property && !property->GetInformationOnly())
{
if (property->GetIsInternal() ||
if (property->GetIsInternal() || property->IsStateIgnored() ||
strcmp(property->GetClassName(), "vtkSMProperty") == 0)
{
// No state for vtkSMProperty
......@@ -1239,7 +1239,7 @@ vtkSMProperty* vtkSMProxy::NewProperty(const char* name,
// Otherwise, properties like ForceUpdate get pushed and
// cause problems.
int is_internal;
if (property->GetIsInternal() ||
if (property->GetIsInternal() || property->IsStateIgnored() ||
strcmp(property->GetClassName(), "vtkSMProperty") == 0)
{
this->DoNotModifyProperty = 1;
......
......@@ -866,10 +866,10 @@ void vtkSMProxyDefinitionManager::MergeProxyDefinition(vtkPVXMLElement* element,
{
if (!subProxySrc[name]->GetAttribute("override"))
{
cout << "#####################################" << endl;
cout << "Find conflict between 2 SubProxy name. ("
<< name.c_str() << ")" << endl;
cout << "#####################################" << endl;
vtkWarningMacro("#####################################" << endl
<< "Find conflict between 2 SubProxy name. ("
<< name.c_str() << ")" << endl
<< "#####################################" << endl);
return;
}
else
......@@ -891,10 +891,10 @@ void vtkSMProxyDefinitionManager::MergeProxyDefinition(vtkPVXMLElement* element,
{
if (!propertiesSrc[name]->GetAttribute("override") )
{
cout << "#####################################" << endl;
cout << "Find conflict between 2 property name. ("
<< name.c_str() << ")" << endl;
cout << "#####################################" << endl;
vtkWarningMacro("#####################################" << endl
<< "Find conflict between 2 property name. ("
<< name.c_str() << ")" << endl
<< "#####################################" << endl);
return;
}
else
......
/*=========================================================================
Program: ParaView
Module: vtkSMProxyUndoElement.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 "vtkSMProxyUndoElement.h"
#include "vtkObjectFactory.h"
#include "vtkSMSession.h"
#include "vtkSMMessage.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyManager.h"
#include "vtkCollection.h"
vtkStandardNewMacro(vtkSMProxyUndoElement);
//-----------------------------------------------------------------------------
vtkSMProxyUndoElement::vtkSMProxyUndoElement()
{
this->CreateElement = true;
this->State = new vtkSMMessage();
}
//-----------------------------------------------------------------------------
vtkSMProxyUndoElement::~vtkSMProxyUndoElement()
{
delete this->State;
this->State = NULL;
}
//-----------------------------------------------------------------------------
void vtkSMProxyUndoElement::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
int vtkSMProxyUndoElement::Undo()
{
if(this->CreateElement)
{
// undo create => DELETE
return this->DeleteProxy();
}
else
{
return this->CreateProxy();
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkSMProxyUndoElement::Redo()
{
if(this->CreateElement)
{
// redo create => CREATE
return this->CreateProxy();
}
else
{
return this->DeleteProxy();
}
return 1;
}
//-----------------------------------------------------------------------------
void vtkSMProxyUndoElement::SetCreationState(const vtkSMMessage* state)
{
this->State->Clear();
if(!state)
{
vtkErrorMacro("No state provided in SetCreationState");
}
else
{
this->State->CopyFrom(*state);
}
}
//-----------------------------------------------------------------------------
int vtkSMProxyUndoElement::CreateProxy()
{
vtkTypeUInt32 globalId = this->State->global_id();
if(this->Session->GetRemoteObject(globalId))
{
// A parent proxy already create it, so do nothing
return 1;
}
//this->State.PrintDebugString();
vtkSMProxy *proxy = vtkSMObject::GetProxyManager()->NewProxy(this->State);
this->UndoSetWorkingContext->AddItem(proxy);
proxy->Delete();
return proxy ? 1 : 0;
}
//-----------------------------------------------------------------------------
int vtkSMProxyUndoElement::DeleteProxy()
{
this->Session->DeletePMObject(this->State);
//vtkSMRemoteObject *obj = this->Session->GetRemoteObject(this->State.global_id());
// // 1 because all remoteObject refs are kept during the UndoSet processing
// if(obj && obj->GetReferenceCount() > 1)
// {
// cout << "ERROR should have deleted Remote object as well "
// << this->State.global_id() << " ref count: " << obj->GetReferenceCount()
// << endl;
// }
return 1; // OK
}
//-----------------------------------------------------------------------------
vtkTypeUInt32 vtkSMProxyUndoElement::GetGlobalId()
{
return this->State->global_id();
}
/*=========================================================================
Program: ParaView
Module: vtkSProxyMUndoElement.h
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.
=========================================================================*/
// .NAME vtkSMProxyUndoElement - vtkSMProxy undo element.
// .SECTION Description
// This class deals with Proxy creation and deletion
#ifndef __vtkSMProxyUndoElement_h
#define __vtkSMProxyUndoElement_h
#include "vtkSMUndoElement.h"
#include "vtkSMMessageMinimal.h" // needed for vtkSMMessage
class VTK_EXPORT vtkSMProxyUndoElement : public vtkSMUndoElement
{
public:
static vtkSMProxyUndoElement* New();
vtkTypeMacro(vtkSMProxyUndoElement, vtkSMUndoElement);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Undo the operation encapsulated by this element.
// \return the status of the operation, 1 on success, 0 otherwise.
virtual int Undo();
// Description:
// Redo the operation encaspsulated by this element.
// \return the status of the operation, 1 on success, 0 otherwise.
virtual int Redo();
// Description:
// If set to true, the Redo action will create the proxy and the undo will
// delete it.
vtkSetMacro(CreateElement, bool);
vtkGetMacro(CreateElement, bool);
//BTX
// Description:
// Set the state of the UndoElement
virtual void SetCreationState(const vtkSMMessage* createState);
virtual vtkTypeUInt32 GetGlobalId();
protected:
vtkSMProxyUndoElement();
~vtkSMProxyUndoElement();
// Internal method used to re-create a proxy based on its state
int CreateProxy();
// Internal method used to delete the proxy based on the state informations
int DeleteProxy();
// Current full state for the creation
vtkSMMessage *State;
// Undo type.
bool CreateElement;
//ETX
private:
vtkSMProxyUndoElement(const vtkSMProxyUndoElement&); // Not implemented.
void operator=(const vtkSMProxyUndoElement&); // Not implemented.
};
#endif
......@@ -77,20 +77,6 @@ int vtkSMRemoteObjectUpdateUndoElement::UpdateState(const vtkSMMessage* state)
vtkWarningMacro(
"Unable to update RemoteObject state since no remote object with id "
<< state->global_id() << " were found.");
vtkCollection *remoteObjects = vtkCollection::New();
this->Session->GetAllRemoteObjects(remoteObjects);
cout << "List of availabe remote objects: ";
for(int i=0;i<remoteObjects->GetNumberOfItems();i++)
{
cout << " "
<< vtkSMRemoteObject::SafeDownCast(
remoteObjects->GetItemAsObject(i))->GetGlobalID();
}
cout << endl;
state->PrintDebugString();
remoteObjects->Delete();
}
}
return 0; // ERROR
......
......@@ -174,7 +174,6 @@ const char* vtkSMRenderViewProxy::IsSelectVisibleCellsAvailable()
return "Selection not supported due to insufficient color depth.";
}
//cout << "yes" << endl;
return NULL;
}
......@@ -490,8 +489,6 @@ void vtkSMRenderViewProxy::MarkDirty(vtkSMProxy* modifiedProxy)
if (this->IsSelectionCached)
{
this->IsSelectionCached = false;
// cout << "InvalidateCachedSelection" << endl;
vtkSMMessage message;
message << pvstream::InvokeRequest() << "InvalidateCachedSelection";
this->Invoke(&message);
......@@ -566,7 +563,6 @@ namespace
//-----------------------------------------------------------------------------
static void vtkShrinkSelection(vtkSelection* sel)
{
// sel->Print(cout);
vtkstd::map<int, int> pixelCounts;
unsigned int numNodes = sel->GetNumberOfNodes();
int choosen = -1;
......
......@@ -116,7 +116,6 @@ void vtkSMRepresentationProxy::MarkDirty(vtkSMProxy* modifiedProxy)
{
if (!this->MarkedModified)
{
//cout << "MarkModified" << endl;
this->MarkedModified = true;
vtkSMMessage message;
message << pvstream::InvokeRequest() << "MarkModified";
......@@ -129,7 +128,6 @@ void vtkSMRepresentationProxy::MarkDirty(vtkSMProxy* modifiedProxy)
//----------------------------------------------------------------------------
void vtkSMRepresentationProxy::RepresentationUpdated()
{
///cout << "RepresentationUpdated" << endl;
this->MarkedModified = false;
this->PostUpdateData();
// PostUpdateData will call InvalidateDataInformation() which will mark
......
......@@ -180,7 +180,8 @@ void vtkSMSession::PushState(vtkSMMessage* msg)
// Update
if(oldState.SerializeAsString() != newState.SerializeAsString())
{
this->UndoStackBuilder->OnUpdate(this, globalId, &oldState, &newState);
this->UndoStackBuilder->OnStateChange( this, globalId,
&oldState, &newState);
}
}
}
......
......@@ -366,7 +366,6 @@ void vtkSMSessionCore::PushState(vtkSMMessage* message)
//----------------------------------------------------------------------------
void vtkSMSessionCore::PushStateSatelliteCallback()
{
cout << "PushStateSatelliteCallback" << endl;
int byte_size = 0;
this->ParallelController->Broadcast(&byte_size, 1, 0);
......@@ -389,7 +388,6 @@ void vtkSMSessionCore::PushStateSatelliteCallback()
void vtkSMSessionCore::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
this->Internals->PrintRemoteMap();
}
//----------------------------------------------------------------------------
......
......@@ -273,14 +273,6 @@ void vtkSMUndoStack::FillWithRemoteObjects( vtkUndoSet *undoSet,
iter->GetPointer()->GetAllRemoteObjects(collection);
iter++;
}
// cout << "List of availabe remote objects: ";
// for(int i=0;i<collection->GetNumberOfItems();i++)
// {
// vtkSMRemoteObject *obj = vtkSMRemoteObject::SafeDownCast(collection->GetItemAsObject(i));
// cout << " " << obj->GetGlobalID();
// }
// cout << endl;
}
//-----------------------------------------------------------------------------
......
......@@ -23,7 +23,6 @@
#include "vtkSMProperty.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyManager.h"
#include "vtkSMProxyUndoElement.h"
#include "vtkSMRemoteObjectUpdateUndoElement.h"
#include "vtkSMSession.h"
#include "vtkSMUndoStack.h"
......@@ -120,43 +119,10 @@ void vtkSMUndoStackBuilder::Add(vtkUndoElement* element)
this->UndoSet->AddElement(element);
}
//-----------------------------------------------------------------------------
void vtkSMUndoStackBuilder::OnCreation( vtkSMSession *session,
vtkTypeUInt32 globalId,
const vtkSMMessage *creationState)
{
if (this->IgnoreAllChanges || !this->HandleChangeEvents() || !this->UndoStack)
{
return;
}
// No creation event for special remote object (i.e.: PipelineState...)
if(globalId < 10)
{
this->OnUpdate(session, globalId, creationState, creationState);