How to add a property to a proxy upon its registration

I added to the vtkAlgorithm class an attribute “bool MyAttribute” with its getters and setters.

Basically, I need this attribute to be saved in the state files. I could add the property manually to every sources/filters xml definition but it’s not an option here because of having a large number of xml definitions.

I tried multiple things (e.g.: proxy SetAnnotation) and… I finally think that the best way to achieve this would be to add for each filter/source proxy a new property “MyAttribute” when the proxy has just been registered.

So I connect to the signal pqServerManagerObserver::proxyRegistered to a custom callback.
Within the callback I didn’t find a way to extend the proxy definition. Any suggestion?

I found the class vtkSMSelfGeneratingSourceProxy which allows to extend a proxy definition but couldn’t find a way to make it work with ParaView.
Here is how I implemented it:

void aProxyRegistrationReaction::onProxyRegistered(const QString& group, const QString& name, vtkSMProxy* proxy)
{
    if(std::strcmp(proxy->GetXMLGroup(), "sources") == 0 || std::strcmp(proxy->GetXMLGroup(), "filters") == 0)
    {
        std::string extension =
            " <Proxy> "
            "     <Property"
            "         command='SetMyAttribute'"
            "         default_values='0'"
            "         name='MyAttribute'"
            "         number_of_elements='1'"
            "         panel_visibility='never'>"
            "     </Property>"
            " </Proxy> ";
        
        vtkSmartPointer<vtkSMSelfGeneratingSourceProxy> sgProxy =
            vtkSmartPointer<vtkSMSelfGeneratingSourceProxy>::New();
        sgProxy->InitializeAndCopyFromProxy(proxy);
        
        if (!sgProxy->ExtendDefinition(extension.c_str()))
        {
            std::cerr << "Failed to extend proxy definition!" << endl;
        }
        
        sgProxy->UpdateVTKObjects();
    }
}

And at run time, I got the errors like:

 ERROR: In c:\git\paraview\paraviewcore\servermanager\core\vtksmproxy.cxx, line 2297
 vtkSMSelfGeneratingSourceProxy (000002E41553C500): Proxies on different sessions.

Thanks in advance.

vtkSMSelfGeneratingSourceProxy is not intended to be used to clone and extend any arbitrary proxy. It is intended for cases as this i.e. proxies that can be extended are defined as so in the XML itself.

In short, there’s no easy way that I can think of to extend the definition of all source and filter proxies. One potential (and convoluted) way is by using vtkSIProxyDefinitionManager::AddElement. If you look at the implementation, it provides a way to extend specific XML definitions. You can iterate over all source/filter definitions known, create a new XML config for extending each and the load that XML config using bool vtkSIProxyDefinitionManager::LoadConfigurationXML.