From a11a9010eba4cd1a327427a9aab7ea58ba48a986 Mon Sep 17 00:00:00 2001 From: Melanie <melanie.carriere@kitware.com> Date: Tue, 24 Nov 2020 10:56:52 +0100 Subject: [PATCH] [fix] Allow applying a property to a proxy of the same group in LoadLidarState During loadLidarState function, the property was applied only if a proxy of the same name of the one saved was found in the pipeline. For exemple : If you save the LidarState with a LidarPacketInterpreter i1 and you open a file using a LidarPacketInterpreter i2 The properties saved from i1 couldn't be applied to i2. This commit allows applying the property to a proxy of the same group. If the property is not found in this proxy, the message is still display to the user. --- .../lqLoadLidarStateReaction.cxx | 8 +++++ ApplicationComponents/lqHelper.cxx | 35 +++++++++++++++++++ ApplicationComponents/lqHelper.h | 8 +++++ 3 files changed, 51 insertions(+) diff --git a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx index 41ae3f8b2..512d1bc2f 100644 --- a/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx +++ b/ApplicationComponents/SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx @@ -91,6 +91,14 @@ void lqLoadLidarStateReaction::onTriggered() std::string propertyName = currentProp.propertyName; vtkSMProxy* lidarProxy = SearchProxyByName(lidarCurrentProxy, proxyName); + // If the proxy is not found, search proxy from the same proxygroup + // ex : Apply a property from an other LidarPacketInterpreter to the current one + if (lidarProxy == nullptr) + { + std::string proxyGroupName = GetGroupName(lidarCurrentProxy, proxyName); + lidarProxy = SearchProxyByGroupName(lidarCurrentProxy, proxyGroupName); + } + if (lidarProxy == nullptr) { std::string message = "No matching proxy found. Property " + propertyName + " of the proxy " + proxyName + " not applied"; diff --git a/ApplicationComponents/lqHelper.cxx b/ApplicationComponents/lqHelper.cxx index 0d2fb69b9..361a6bd0d 100644 --- a/ApplicationComponents/lqHelper.cxx +++ b/ApplicationComponents/lqHelper.cxx @@ -6,9 +6,13 @@ #include "vtkLidarReader.h" #include "vtkLidarStream.h" +#include <vtkSMSessionProxyManager.h> #include <vtkSMBooleanDomain.h> #include <vtkSMPropertyIterator.h> #include <vtkSMPropertyHelper.h> +#include <vtkSMProxyDefinitionManager.h> +#include <vtkSMSessionProxyManager.h> +#include <vtkPVProxyDefinitionIterator.h> #include <pqApplicationCore.h> #include <pqPipelineSource.h> @@ -206,3 +210,34 @@ void UpdateProperty(vtkSMProxy * proxy, const std::string &propNameToFind, } } } + +//----------------------------------------------------------------------------- +std::string GetGroupName(vtkSMProxy * existingProxy, const std::string & proxyToFindName) +{ + vtkSMSessionProxyManager* pxm = existingProxy->GetSessionProxyManager(); + + if(!pxm) + { + std::cout << "Couldn't get the SM Session Proxy Manager" << std::endl; + return ""; + } + + vtkSMProxyDefinitionManager* pxdm = pxm->GetProxyDefinitionManager(); + + if(!pxdm) + { + std::cout << "Couldn't get the SM Proxy Definition Manager" << std::endl; + return ""; + } + + vtkPVProxyDefinitionIterator* iter = pxdm->NewIterator(); + for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) + { + if(strcmp(iter->GetProxyName(), proxyToFindName.c_str()) == 0) + { + return iter->GetGroupName(); + } + } + return ""; +} + diff --git a/ApplicationComponents/lqHelper.h b/ApplicationComponents/lqHelper.h index 66f3d47d1..6c068de9c 100644 --- a/ApplicationComponents/lqHelper.h +++ b/ApplicationComponents/lqHelper.h @@ -60,4 +60,12 @@ vtkSMProperty* GetPropertyFromProxy(vtkSMProxy * proxy, const std::string &propN void UpdateProperty(vtkSMProxy * proxy, const std::string & propNameToFind, const std::vector<std::string> & values); +/** + * @brief GetGroupName Get the name of the first group where appear a proxy + * @param existingProxy a proxy of the pipeline, use to get the ProxyDefinitionManager + * @param proxyToFindName name of the proxy to look for + * @return the name of the first group where a corresponding proxy is found + */ +std::string GetGroupName(vtkSMProxy * existingProxy, const std::string & proxyToFindName); + #endif // LQHELPER_H -- GitLab