Commit 621558a6 authored by Berk Geveci's avatar Berk Geveci
Browse files

ENH: Added capability of keeping track of the order in which properties were added or exposed

parent f82e2037
/*=========================================================================
Program: ParaView
Module: vtkSMOrderedPropertyIterator.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 "vtkSMOrderedPropertyIterator.h"
#include "vtkObjectFactory.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyInternals.h"
vtkStandardNewMacro(vtkSMOrderedPropertyIterator);
vtkCxxRevisionMacro(vtkSMOrderedPropertyIterator, "1.1");
//---------------------------------------------------------------------------
vtkSMOrderedPropertyIterator::vtkSMOrderedPropertyIterator()
{
this->Proxy = 0;
this->Index = 0;
}
//---------------------------------------------------------------------------
vtkSMOrderedPropertyIterator::~vtkSMOrderedPropertyIterator()
{
this->SetProxy(0);
}
//---------------------------------------------------------------------------
void vtkSMOrderedPropertyIterator::SetProxy(vtkSMProxy* proxy)
{
if (this->Proxy != proxy)
{
if (this->Proxy != NULL) { this->Proxy->UnRegister(this); }
this->Proxy = proxy;
if (this->Proxy != NULL)
{
this->Proxy->Register(this);
this->Begin();
}
this->Modified();
}
}
//---------------------------------------------------------------------------
void vtkSMOrderedPropertyIterator::Begin()
{
if (!this->Proxy)
{
vtkErrorMacro("Proxy is not set. Can not perform operation: Begin()");
return;
}
this->Index = 0;
}
//---------------------------------------------------------------------------
int vtkSMOrderedPropertyIterator::IsAtEnd()
{
if (!this->Proxy)
{
vtkErrorMacro("Proxy is not set. Can not perform operation: IsAtEnd()");
return 1;
}
if (this->Index >=
this->Proxy->Internals->PropertyNamesInOrder.size())
{
return 1;
}
return 0;
}
//---------------------------------------------------------------------------
void vtkSMOrderedPropertyIterator::Next()
{
if (!this->Proxy)
{
vtkErrorMacro("Proxy is not set. Can not perform operation: Next()");
return;
}
this->Index++;
}
//---------------------------------------------------------------------------
const char* vtkSMOrderedPropertyIterator::GetKey()
{
if (!this->Proxy)
{
vtkErrorMacro("Proxy is not set. Can not perform operation: GetKey()");
return 0;
}
if (!this->IsAtEnd())
{
return this->Proxy->Internals->PropertyNamesInOrder[this->Index];
}
return 0;
}
//---------------------------------------------------------------------------
vtkSMProperty* vtkSMOrderedPropertyIterator::GetProperty()
{
if (!this->Proxy)
{
vtkErrorMacro("Proxy is not set. Can not perform operation: GetProperty()");
return 0;
}
if (!this->IsAtEnd())
{
return this->Proxy->GetProperty(
this->Proxy->Internals->PropertyNamesInOrder[this->Index]);
}
return 0;
}
//---------------------------------------------------------------------------
void vtkSMOrderedPropertyIterator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Proxy: " << this->Proxy << endl;
}
/*=========================================================================
Program: ParaView
Module: vtkSMOrderedPropertyIterator.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 vtkSMOrderedPropertyIterator - iterates over the properties of a proxy
// .SECTION Description
// vtkSMOrderedPropertyIterator is used to iterate over the properties of a
// proxy. The properties of the root proxies as well as sub-proxies are
// included in the iteration. For sub-proxies, only exposed properties are
// iterated over. vtkSMOrderedPropertyIterator iterates over properties in
// the order they appear in the xml or in the order they were added. This
// is possible because vtkSMProxy keeps track of the order in which properties
// were added or exposed in a PropertyNamesInOrder vector.
#ifndef __vtkSMOrderedPropertyIterator_h
#define __vtkSMOrderedPropertyIterator_h
#include "vtkSMObject.h"
class vtkSMProperty;
class vtkSMProxy;
class VTK_EXPORT vtkSMOrderedPropertyIterator : public vtkSMObject
{
public:
static vtkSMOrderedPropertyIterator* New();
vtkTypeRevisionMacro(vtkSMOrderedPropertyIterator, vtkSMObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Set the proxy to be used.
void SetProxy(vtkSMProxy* proxy);
// Description:
// Return the proxy.
vtkGetObjectMacro(Proxy, vtkSMProxy);
// Description:
// Go to the first property.
void Begin();
// Description:
// Returns true if iterator points past the end of the collection.
int IsAtEnd();
// Description:
// Move to the next property.
void Next();
// Description:
// Returns the key (name) at the current iterator position.
const char* GetKey();
// Description:
// Returns the property at the current iterator position.
vtkSMProperty* GetProperty();
protected:
vtkSMOrderedPropertyIterator();
~vtkSMOrderedPropertyIterator();
vtkSMProxy* Proxy;
int Index;
private:
vtkSMOrderedPropertyIterator(const vtkSMOrderedPropertyIterator&); // Not implemented
void operator=(const vtkSMOrderedPropertyIterator&); // Not implemented
};
#endif
......@@ -37,7 +37,7 @@
#include <vtkstd/string>
vtkStandardNewMacro(vtkSMProxy);
vtkCxxRevisionMacro(vtkSMProxy, "1.80");
vtkCxxRevisionMacro(vtkSMProxy, "1.81");
vtkCxxSetObjectMacro(vtkSMProxy, XMLElement, vtkPVXMLElement);
......@@ -520,6 +520,11 @@ void vtkSMProxy::AddProperty(const char* name, vtkSMProperty* prop)
//---------------------------------------------------------------------------
void vtkSMProxy::RemoveProperty(const char* name)
{
if (!name)
{
return;
}
vtkSMProxyInternals::ProxyMap::iterator it2 =
this->Internals->SubProxies.begin();
for( ; it2 != this->Internals->SubProxies.end(); it2++)
......@@ -533,6 +538,15 @@ void vtkSMProxy::RemoveProperty(const char* name)
{
this->Internals->Properties.erase(it);
}
vtkstd::vector<vtkStdString>::iterator iter =
vtkstd::find(this->Internals->PropertyNamesInOrder.begin(),
this->Internals->PropertyNamesInOrder.end(),
name);
if(iter != this->Internals->PropertyNamesInOrder.end())
{
this->Internals->PropertyNamesInOrder.erase(iter);
}
}
//---------------------------------------------------------------------------
......@@ -625,6 +639,11 @@ void vtkSMProxy::AddPropertyToSelf(
newEntry.Property = prop;
newEntry.ObserverTag = tag;
this->Internals->Properties[name] = newEntry;
// Add the property name to the vector of property names.
// This vector keeps track of the order in which properties
// were added.
this->Internals->PropertyNamesInOrder.push_back(name);
}
//---------------------------------------------------------------------------
......@@ -1844,14 +1863,17 @@ int vtkSMProxy::LoadRevivalState(vtkPVXMLElement* revivalElem,
}
else if (name && strcmp(name, "SubProxy") == 0)
{
vtkSMProxy* subProxy = this->GetSubProxy(currentElement->GetAttribute("name"));
vtkSMProxy* subProxy =
this->GetSubProxy(currentElement->GetAttribute("name"));
if (!subProxy)
{
vtkErrorMacro("Failed to load subproxy with name: " <<
currentElement->GetAttribute("name") << ". Cannot revive the subproxy.");
vtkErrorMacro("Failed to load subproxy with name: "
<< currentElement->GetAttribute("name")
<< ". Cannot revive the subproxy.");
return 0;
}
if (!subProxy->LoadRevivalState(currentElement->GetNestedElement(0), loader))
if (!subProxy->LoadRevivalState(
currentElement->GetNestedElement(0), loader))
{
return 0;
}
......@@ -2053,6 +2075,11 @@ void vtkSMProxy::ExposeSubProxyProperty(const char* subproxy_name,
info.SubProxyName = subproxy_name;
info.PropertyName = property_name;
this->Internals->ExposedProperties[exposed_name] = info;
// Add the exposed property name to the vector of property names.
// This vector keeps track of the order in which properties
// were added.
this->Internals->PropertyNamesInOrder.push_back(exposed_name);
}
//---------------------------------------------------------------------------
......
......@@ -392,6 +392,7 @@ protected:
friend class vtkSMProperty;
friend class vtkSMProxyManager;
friend class vtkSMInputProperty;
friend class vtkSMOrderedPropertyIterator;
friend class vtkSMPropertyIterator;
friend class vtkSMProxyObserver;
friend class vtkSMProxyProperty;
......
......@@ -46,13 +46,18 @@ struct vtkSMProxyInternals
int ModifiedFlag;
unsigned int ObserverTag;
};
vtkstd::vector<vtkClientServerID > IDs;
vtkstd::vector<int> ServerIDs;
// Note that the name of the property is the map key. That is the
// only place where name is stored
typedef vtkstd::map<vtkStdString, PropertyInfo> PropertyInfoMap;
PropertyInfoMap Properties;
// This vector keeps track of the order in which properties
// were added.
vtkstd::vector<vtkStdString> PropertyNamesInOrder;
vtkstd::vector<vtkClientServerID > IDs;
vtkstd::vector<int> ServerIDs;
typedef vtkstd::map<vtkStdString, vtkSmartPointer<vtkSMProxy> > ProxyMap;
ProxyMap SubProxies;
......
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