Skip to content

Commit

Permalink
Re #11508 Exported accessors and mutators to python
Browse files Browse the repository at this point in the history
and it works.
  • Loading branch information
abuts committed Apr 21, 2015
1 parent 671ca69 commit 83602c7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ class MANTID_GEOMETRY_DLL Component : public virtual IComponent {
else
return std::string("");
}
/** Get a parameter's description */
/** Get this component parameter's description -- no recursive search within children*/
std::string getDescription() const;

/** Get description of a parameter attached to this component */
std::string getParDescription(const std::string &pname,
bool recursive = true) const;

/** Get this parameter's description -- no recursive search within children*/
std::string getParDescription() const;

/** Get a parameter's tooltip (short description) */
std::string getParTooltip(const std::string &pname,
bool recursive = true) const;
/** Get a parameter's tooltip (short description) -- no recursive search within children*/
std::string getParTooltip() const;
std::string getTooltip() const;
/**Set components description. Works for parameterized components only */
void setDescription(const std::string &descr);
/**
Expand Down
15 changes: 11 additions & 4 deletions Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ namespace Mantid {

std::string Component::getParDescription(const std::string &pname,
bool recursive) const {
if (!m_map){ // no description for non-parameterized components
return std::string("");
}
Parameter_sptr param = Parameter_sptr(); // Null shared pointer
if (recursive) {
param = m_map->getRecursive(this, pname);
Expand All @@ -579,7 +582,7 @@ namespace Mantid {
return std::string("");
}
/** Get this parameter's description -- no recursive search within children*/
std::string Component::getParDescription() const{
std::string Component::getDescription() const{
auto name = this->getName();
return this->getParDescription(name,false);

Expand All @@ -597,6 +600,9 @@ namespace Mantid {
*/
std::string Component::getParTooltip(const std::string &pname,
bool recursive) const {
if (!m_map){ // no tooltips for non-parameterized components
return std::string("");
}
Parameter_sptr param = Parameter_sptr(); // Null shared pointer
if (recursive) {
param = m_map->getRecursive(this, pname);
Expand All @@ -610,7 +616,7 @@ namespace Mantid {
}

/** Get a parameter's tooltip (short description) -- no recursive search within children*/
std::string Component::getParTooltip() const{
std::string Component::getTooltip() const{
auto name = this->getName();
return this->getParTooltip(name,false);
}
Expand All @@ -625,8 +631,9 @@ namespace Mantid {
if (param){
param->setDescription(descr);
}else{
throw Kernel::Exception::NotFoundError("Component",
"Can not found component named: "+name);
//I see no reason why component's parameter map should be constant.
//But as I do not understand why it is constant, let's HACK!
(const_cast<ParameterMap *>(m_map))->addString(this,name,"",&descr);
}
} else
throw Kernel::Exception::NotImplementedError(
Expand Down
29 changes: 29 additions & 0 deletions Code/Mantid/Framework/Geometry/test/ComponentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,35 @@ class ComponentTest : public CxxTest::TestSuite
TS_ASSERT(ancs[0]->isParametrized());

}
void testDescription()
{
Component parent("Parent",V3D(1,1,1));
//name and parent
Component q("Child",V3D(5,6,7),Quat(1,1,1,1),&parent);

TS_ASSERT_THROWS(parent.setDescription("descr"),Mantid::Kernel::Exception::NotImplementedError);

ParameterMap_sptr pmap( new ParameterMap() );
pmap->addString(&q,"ChildMessage","Message from a child");
Component pq(&q,pmap.get());

TS_ASSERT_EQUALS(pq.getName(),"Child");
TS_ASSERT(pq.isParametrized() );
//check the parent
TS_ASSERT(pq.getParent());
TS_ASSERT(pq.getParent()->isParametrized() );

TS_ASSERT_THROWS_NOTHING(pq.setDescription("This is child description. This is long child description."));

TS_ASSERT_EQUALS(parent.getTooltip(),"");
TS_ASSERT_EQUALS(pq.getTooltip(),"This is child description.");
TS_ASSERT_EQUALS(pq.getParTooltip("Child"),"This is child description.");


TS_ASSERT_EQUALS(pq.getDescription(),"This is child description. This is long child description.");

}


void testGetFullName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getStringParameter,Component::getStringParameter,1,2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getIntParameter,Component::getIntParameter,1,2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterType,Component::getParameterType,1,2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParTooltip,Component::getParTooltip,1,2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParDescription,Component::getParDescription,1,2)


}
Expand All @@ -33,7 +35,14 @@ void export_Component()
.def("getRotationParameter", &Component::getRotationParameter, Component_getRotationParameter())
.def("getStringParameter", &Component::getStringParameter, Component_getStringParameter())
.def("getIntParameter", &Component::getIntParameter, Component_getIntParameter())
// HACK -- python should return parameters regardless of type. this is untill rows below do not work
//
.def("getParTooltip", &Component::getParTooltip, Component_getParTooltip())
.def("getParDescription", &Component::getParDescription, Component_getParDescription())
.def("getTooltip", &Component::getTooltip,"Return the tooltip of current parameterized component")
.def("getDescription", &Component::getDescription,"Return the description of current parameterized component")
.def("setDescription", &Component::setDescription, "Set component's description, if the component is parameterized component")

// HACK -- python should return parameters regardless of type. this is until rows below do not work
.def("getParameterType", &Component::getParameterType, Component_getParameterType())
//// this does not work for some obvious or not obvious reasons
//.def("getParameter", &Component::getNumberParameter, Component_getNumberParameter())
Expand Down

0 comments on commit 83602c7

Please sign in to comment.