diff --git a/Framework/API/inc/MantidAPI/AlgorithmProxy.h b/Framework/API/inc/MantidAPI/AlgorithmProxy.h index ef45cafbbf59b8bce4303063b7ae87fb6a73fa05..cc2c06272044a8d3aee5889ffdb1da9975de73aa 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmProxy.h +++ b/Framework/API/inc/MantidAPI/AlgorithmProxy.h @@ -116,6 +116,8 @@ public: void setPropertyValue(const std::string &name, const std::string &value); /// Do something after a property was set void afterPropertySet(const std::string &); + /// Make m_properties point to the same PropertyManager as po. + void copyPropertiesFrom(const PropertyManagerOwner &po); //@} void cancel(); diff --git a/Framework/API/src/AlgorithmProxy.cpp b/Framework/API/src/AlgorithmProxy.cpp index a400d76b3943ccaab4a31a82474c523b4be6f1b9..e911da5ef3cd6d7036a55215ab2d66f588a15e03 100644 --- a/Framework/API/src/AlgorithmProxy.cpp +++ b/Framework/API/src/AlgorithmProxy.cpp @@ -218,7 +218,19 @@ void AlgorithmProxy::afterPropertySet(const std::string &name) { copyPropertiesFrom(*m_alg); } -//---------------------------------------------------------------------- +/** + * Copy properties from another property manager + * Making sure that the concrete alg is kept in sync + * @param po :: The property manager to copy + */ +void AlgorithmProxy::copyPropertiesFrom(const PropertyManagerOwner& po) +{ + PropertyManagerOwner::copyPropertiesFrom(po); + createConcreteAlg(true); + m_alg->copyPropertiesFrom(*this); +} + + //---------------------------------------------------------------------- // Private methods //---------------------------------------------------------------------- diff --git a/Framework/API/test/AlgorithmProxyTest.h b/Framework/API/test/AlgorithmProxyTest.h index 8c50e2e0dcd53e09f3d9ce26df5d78dd7f952dd2..25b2f27d24d2b8f79e5f5e4418bb8be41b4dc776 100644 --- a/Framework/API/test/AlgorithmProxyTest.h +++ b/Framework/API/test/AlgorithmProxyTest.h @@ -212,6 +212,30 @@ public: } TS_ASSERT_EQUALS("InputWorkspace", alg->workspaceMethodInputProperty()); } + + void test_copyPropertiesFrom() { + IAlgorithm_sptr alg = + AlgorithmManager::Instance().create("ToyAlgorithmProxy"); + alg->initialize(); + alg->setPropertyValue( "prop1", "string" ); + alg->setPropertyValue("prop2","1"); + IAlgorithm_sptr algCopy = + AlgorithmManager::Instance().create("ToyAlgorithmProxy"); + + auto algProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(alg); + auto algCopyProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(algCopy); + algCopyProxy->copyPropertiesFrom(*algProxy); + + int val = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2")); + + TS_ASSERT_EQUALS(val,1); + + //set another value and check the other value is unaffected + algCopy->setPropertyValue( "prop1", "A difference" ); + int val2 = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2")); + + TS_ASSERT_EQUALS(val,val2); + } }; #endif /*ALGORITHMPROXYTEST_H_*/ diff --git a/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h b/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h index 7a095862e9ce2aad426bcb01da21b7910b545aa2..87a4de60f33848e9103334085f80c14413daac34 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h @@ -65,7 +65,7 @@ public: void setPropertyOrdinal(const int &index, const std::string &value); /// Make m_properties point to the same PropertyManager as po. - void copyPropertiesFrom(const PropertyManagerOwner &po) { *this = po; } + virtual void copyPropertiesFrom(const PropertyManagerOwner &po) { *this = po; } bool existsProperty(const std::string &name) const; bool validateProperties() const;