Skip to content
Snippets Groups Projects
Commit d55a0ef4 authored by Nick Draper's avatar Nick Draper
Browse files

Ensure AlgorithmProxy keeps everything up to date

with CopyPropertiesfrom

re #13925
parent 4e24cdfc
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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
//----------------------------------------------------------------------
......
......@@ -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_*/
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment