Commit 67830907 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Cleanup logic for setting default values.

Added mechanism on vtkSMProxy to set default values for all properties that
pqProxy now uses when a new proxy is created. We still have a few hacks lurking
around for dealing with compound proxies in pqPipelineSource.

Added support in vtkSMChartRepresentationProxy to correctly set UseIndexForXAxis
property's default value based on what XArray is picked.

Change-Id: If7e4ba6d40541e501a5524d2bbe55be8f992d646
parent a1cc509a
......@@ -150,6 +150,17 @@ void vtkSMProperty::AddDomain(const char* name, vtkSMDomain* domain)
}
this->PInternals->Domains[name] = domain;
if (domain)
{
domain->AddObserver(vtkCommand::DomainModifiedEvent,
this, &vtkSMProperty::InvokeDomainModifiedEvent);
}
}
//---------------------------------------------------------------------------
void vtkSMProperty::InvokeDomainModifiedEvent()
{
this->InvokeEvent(vtkCommand::DomainModifiedEvent);
}
//---------------------------------------------------------------------------
......
......@@ -58,6 +58,9 @@
// vtkCommand::UncheckedPropertyModifiedEvent must be fired every time
// vtkCommand::ModifiedEvent is fired.
//
// \li \b vtkCommand::DomainModifiedEvent : fired when any of this properties
// domain's fire the same event.
//
// Properties are typically constructed from ServerManager XML configuration
// files. Attributes available on a Property XML are as follows:
//
......@@ -510,6 +513,10 @@ private:
vtkSMProperty(const vtkSMProperty&); // Not implemented
void operator=(const vtkSMProperty&); // Not implemented
// Callback to fire vtkCommand::DomainModifiedEvent every time any of the
// domains change.
void InvokeDomainModifiedEvent();
// Description:
// Given the string, this method will create and set a well-formated
// string as XMLLabel.
......
......@@ -19,6 +19,7 @@
#include "vtkCommand.h"
#include "vtkDebugLeaks.h"
#include "vtkGarbageCollector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPVInstantiator.h"
......@@ -39,12 +40,12 @@
#include "vtkSMStateLocator.h"
#include <algorithm>
#include <assert.h>
#include <set>
#include <string>
#include <vector>
#include <vtksys/ios/sstream>
#include <vtksys/RegularExpression.hxx>
#include <assert.h>
#include <vtkNew.h>
//---------------------------------------------------------------------------
// Observer for modified event of the property
......@@ -463,6 +464,98 @@ void vtkSMProxy::MarkAllPropertiesAsModified()
}
}
namespace
{
// Used by ResetPropertiesToDefault() to monitor properties whose domains
// change.
class vtkDomainObserver
{
std::vector<std::pair<vtkSMProperty*, unsigned long> > MonitoredProperties;
std::set<vtkSMProperty*> PropertiesWithModifiedDomains;
void DomainModified(vtkObject* sender, unsigned long, void*)
{
vtkSMProperty* prop = vtkSMProperty::SafeDownCast(sender);
if (prop)
{
this->PropertiesWithModifiedDomains.insert(prop);
}
}
public:
vtkDomainObserver()
{
}
~vtkDomainObserver()
{
for (size_t cc=0; cc < this->MonitoredProperties.size(); cc++)
{
this->MonitoredProperties[cc].first->RemoveObserver(
this->MonitoredProperties[cc].second);
}
}
void Monitor(vtkSMProperty* prop)
{
assert(prop != NULL);
unsigned long oid = prop->AddObserver(vtkCommand::DomainModifiedEvent,
this, &vtkDomainObserver::DomainModified);
this->MonitoredProperties.push_back(
std::pair<vtkSMProperty*, unsigned long>(prop, oid));
}
const std::set<vtkSMProperty*>& GetPropertiesWithModifiedDomains() const
{
return this->PropertiesWithModifiedDomains;
}
};
}
//---------------------------------------------------------------------------
void vtkSMProxy::ResetPropertiesToDefault()
{
this->UpdateVTKObjects();
// Since domains depend on information properties, it's essential we update
// property information first.
this->UpdatePipelineInformation();
// In general, we don't reset properties on vtkSMCompoundProxy
vtkSmartPointer<vtkSMPropertyIterator> iter;
iter.TakeReference(this->NewPropertyIterator());
// iterate over properties and reset them to default. if any property says its
// domain is modified after we reset it, we need to reset it again since its
// default may have changed.
vtkDomainObserver observer;
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
{
vtkSMProperty* smproperty = iter->GetProperty();
if (!smproperty->GetInformationOnly())
{
vtkPVXMLElement* propHints = iter->GetProperty()->GetHints();
if (propHints && propHints->FindNestedElementByName("NoDefault"))
{
// Don't reset properties that request overriding of the default mechanism.
continue;
}
observer.Monitor(iter->GetProperty());
iter->GetProperty()->ResetToDefault();
}
}
const std::set<vtkSMProperty*> &props =
observer.GetPropertiesWithModifiedDomains();
for (std::set<vtkSMProperty*>::const_iterator iter = props.begin(); iter != props.end(); ++iter)
{
(*iter)->ResetToDefault();
}
this->UpdateVTKObjects();
}
//---------------------------------------------------------------------------
void vtkSMProxy::UpdatePropertyInformation(vtkSMProperty* prop)
{
......
......@@ -310,6 +310,16 @@ public:
// actual objects.
virtual void MarkAllPropertiesAsModified();
// Description:
// Use this method to set all properties on this proxy to their default
// values. This iterates over all properties on this proxy, thus if this proxy
// had subproxies, this method will iterate over only the exposed properties
// and call vtkSMProperty::ResetToDefault(). vtkSMProperty::ResetToDefault()
// defines what it means to "reset a property to its default value" which
// doesn't always correspond to the default_values specified in the XML
// configurations for the proxy.
virtual void ResetPropertiesToDefault();
//BTX
// Description:
// Flags used for the proxyPropertyCopyFlag argument to the Copy method.
......
......@@ -17,6 +17,9 @@
#include "vtkChartRepresentation.h"
#include "vtkClientServerStream.h"
#include "vtkObjectFactory.h"
#include "vtkSMChartSeriesListDomain.h"
#include "vtkSMDomain.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
vtkStandardNewMacro(vtkSMChartRepresentationProxy);
......@@ -112,3 +115,32 @@ void vtkSMChartRepresentationProxy::SetPropertyModifiedFlag(
}
this->Superclass::SetPropertyModifiedFlag(name, flag);
}
//----------------------------------------------------------------------------
void vtkSMChartRepresentationProxy::ResetPropertiesToDefault()
{
this->Superclass::ResetPropertiesToDefault();
vtkSMProperty* useIndex = this->GetProperty("UseIndexForXAxis");
vtkSMProperty* xarrayName = this->GetProperty("XArrayName");
if (useIndex && xarrayName)
{
vtkSMPropertyHelper helper(xarrayName);
const char* value = helper.GetAsString();
const char** known_names =
vtkSMChartSeriesListDomain::GetKnownSeriesNames();
for (int cc=0; known_names[cc] != NULL && value != NULL; cc++)
{
if (strcmp(known_names[cc], value) == 0)
{
vtkSMPropertyHelper(useIndex).Set(0);
this->UpdateProperty("UseIndexForXAxis");
return;
}
}
}
vtkSMPropertyHelper(useIndex).Set(0);
this->UpdateProperty("UseIndexForXAxis");
}
......@@ -39,6 +39,13 @@ public:
// Overridden to handle links with subproxy properties.
int ReadXMLAttributes(vtkSMSessionProxyManager* pm, vtkPVXMLElement* element);
// Description:
// Overridden to handle the default value for "UseIndexForXAxis" property, if
// any. UseIndexForXAxis needs to be OFF by default, if the required property
// i.e. XArrayName property has one of the known types of arrays, otherwise it
// must be ON.
virtual void ResetPropertiesToDefault();
//BTX
protected:
vtkSMChartRepresentationProxy();
......
......@@ -135,15 +135,22 @@ int vtkSMChartSeriesListDomain::ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLE
}
//----------------------------------------------------------------------------
int vtkSMChartSeriesListDomain::SetDefaultValues(vtkSMProperty* prop)
const char** vtkSMChartSeriesListDomain::GetKnownSeriesNames()
{
const char* strings_to_check[] =
static const char* strings_to_check[] =
{ "bin_extents",
"Time",
"time",
"arc_length",
NULL
};
return strings_to_check;
}
//----------------------------------------------------------------------------
int vtkSMChartSeriesListDomain::SetDefaultValues(vtkSMProperty* prop)
{
const char** strings_to_check =
vtkSMChartSeriesListDomain::GetKnownSeriesNames();
const std::vector<vtkStdString> domain_strings = this->GetStrings();
for (int cc=0; strings_to_check[cc] != NULL; cc++)
......
......@@ -55,6 +55,12 @@ public:
// Set the default values for the property.
virtual int SetDefaultValues(vtkSMProperty*);
// Description:
// Returns the list of series that are know to this domain are are given a
// priority when setting default values. This array is NULL terminated i.e.
// the last entry in this array will be NULL.
static const char** GetKnownSeriesNames();
//BTX
protected:
vtkSMChartSeriesListDomain();
......
......@@ -266,7 +266,7 @@ void pqPipelineSource::createProxiesForProxyListDomains()
continue;
}
vtkSMProxyListDomain* pld = vtkSMProxyListDomain::SafeDownCast(
prop->GetDomain("proxy_list"));
prop->FindDomain("vtkSMProxyListDomain"));
if (!pld)
{
continue;
......@@ -320,6 +320,9 @@ void pqPipelineSource::createProxiesForProxyListDomains()
// in the domains.
// NOTE: This method is called only in setDefaultPropertyValues()
// ensure that we are not changing any user set values.
// Another HACK: this seems to be needed to deal with the fact that we do
// need to reset some properties on a vtkSMCompoundSourceProxy (which is
// skipped by pqProxy::setDefaultPropertyValues).
prop->ResetToDefault();
}
iter->Delete();
......@@ -369,31 +372,11 @@ void pqPipelineSource::setDefaultPropertyValues()
this->createProxiesForProxyListDomains();
vtkSMProxy* proxy = this->getProxy();
if (proxy)
{
// if any properties were changed e.g. by
// createProxiesForProxyListDomains(), this will ensure that they are pushed
// correctly.
proxy->UpdateVTKObjects();
}
vtkSMSourceProxy* sp = vtkSMSourceProxy::SafeDownCast(this->getProxy());
if (sp)
{
// this updates the information which may be required to determine
// defaults of some property values (typically in case of readers).
// For this call to not produce VTK pipeline errors, it is
// essential that necessary properties on the proxy are already
// initialized correctly eg. FileName in case of readers,
// all Input/Source properties in case filters etc.
sp->UpdatePipelineInformation();
sp->CreateOutputPorts();
}
this->Superclass::setDefaultPropertyValues();
// Now initialize the proxies in the proxy list domains as well.
// Now initialize the proxies in the proxy list domains as well.
// This is a HACK. vtkSMProxy::ResetPropertiesToDefault() must handle this
// too, but it's too weird to move to servermanager right now.
foreach(vtkSMProxy* dproxy, this->Internal->ProxyListDomainProxies)
{
vtkSMPropertyIterator* diter = dproxy->NewPropertyIterator();
......
......@@ -318,56 +318,15 @@ void pqProxy::setModifiedState(ModifiedState modified)
void pqProxy::setDefaultPropertyValues()
{
vtkSMProxy* proxy = this->getProxy();
// If this is a compound proxy, its property values will be set from XML
// This seems like a hack. Need some graceful solution.
if(proxy->IsA("vtkSMCompoundSourceProxy"))
if (proxy->IsA("vtkSMCompoundSourceProxy"))
{
return;
// We don't reset properties on custom filter.
proxy->UpdateVTKObjects();
}
// since some domains rely on information properties,
// it is essential that we update the property information
// before resetting values.
proxy->UpdatePropertyInformation();
vtkSMPropertyIterator* iter = proxy->NewPropertyIterator();
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
else
{
vtkSMProperty* smproperty = iter->GetProperty();
if (!smproperty->GetInformationOnly())
{
vtkPVXMLElement* propHints = iter->GetProperty()->GetHints();
if (propHints && propHints->FindNestedElementByName("NoDefault"))
{
// Don't reset properties that request overriding of default mechanism.
continue;
}
iter->GetProperty()->ResetToDefault();
}
proxy->ResetPropertiesToDefault();
}
// Since domains may depend on defaul values of other properties to be set,
// we iterate over the properties once more. We need a better mechanism for this.
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
{
vtkSMProperty* smproperty = iter->GetProperty();
if (!smproperty->GetInformationOnly())
{
vtkPVXMLElement* propHints = iter->GetProperty()->GetHints();
if (propHints && propHints->FindNestedElementByName("NoDefault"))
{
// Don't reset properties that request overriding of default mechanism.
continue;
}
iter->GetProperty()->ResetToDefault();
}
}
iter->Delete();
proxy->UpdateVTKObjects();
}
//-----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment