Skip to content

Commit

Permalink
Re #11508 Adding description to some parameters and param factory
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 15, 2015
1 parent 009c897 commit 4d47207
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ void FilterEvents::filterEventsBySplitters(double progressamount) {
Kernel::TimeSplitterType splitters;
generateSplitters(wsindex, splitters);

g_log.debug() << "[FilterEvents D1215]: Output orkspace Index " << wsindex
g_log.debug() << "[FilterEvents D1215]: Output workspace Index " << wsindex
<< ": Name = " << opws->name()
<< "; Number of splitters = " << splitters.size() << ".\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ class MANTID_GEOMETRY_DLL Parameter {
/// Returns the parameter value of type T if the parameter has type
/// ParameterType<T>
template <class T> const T &value();

/// set description:
virtual void setDescription(const std::string &source)
{m_description.assign(source);}
/// get description
virtual const std::string & getDescription()const{return m_description;}
/// get short description (tooltip)
virtual std::string getTooltip()const;
/// Equality operator
bool operator==(const Parameter &rhs) const {
if (this->name() == rhs.name() && this->type() == rhs.type() &&
Expand All @@ -112,16 +118,17 @@ class MANTID_GEOMETRY_DLL Parameter {

friend class ParameterFactory;
/// Constructor
Parameter() : m_type(""), m_name(""), m_str_value("") {}
Parameter() : m_type(""), m_name(""), m_str_value(""),m_description("") {}

private:
/// The type of the property
std::string m_type;
/// The name of the property
std::string m_name;
std::string m_str_value; ///< Parameter value as a string
/// property description
//std::string m_description;
/// parameter's description -- string containing the description
/// of this parameter
std::string m_description;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class MANTID_GEOMETRY_DLL ParameterMap {

/// Method for adding a parameter providing its value as a string
void add(const std::string &type, const IComponent *comp,
const std::string &name, const std::string &value);
const std::string &name, const std::string &value,
const std::string * const pDescription=NULL);

/**
* Method for adding a parameter providing its value of a particular type.
Expand All @@ -132,54 +133,62 @@ class MANTID_GEOMETRY_DLL ParameterMap {
* to
* @param name :: The name of the parameter
* @param value :: The parameter's value
* @param pDescription :: if present, the constant pointer to a constant
* string, containing parameter's description.
*/
template <class T>
void add(const std::string &type, const IComponent *comp,
const std::string &name, const T &value) {
const std::string &name, const T &value,
const std::string * const pDescription=NULL) {
auto param = ParameterFactory::create(type, name);
auto typedParam = boost::dynamic_pointer_cast<ParameterType<T>>(param);
assert(typedParam); // If not true the factory has created the wrong type
typedParam->setValue(value);
this->add(comp, param);

this->add(comp, param,pDescription);
}
/// Method for adding a parameter providing shared pointer to it. The class
/// stores share pointer and increment ref count to it
void add(const IComponent *comp, const boost::shared_ptr<Parameter> &param);
void add(const IComponent *comp, const boost::shared_ptr<Parameter> &param,
const std::string * const pDescription=NULL);

/** @name Helper methods for adding and updating parameter types */
/// Create or adjust "pos" parameter for a component
void addPositionCoordinate(const IComponent *comp, const std::string &name,
const double value);
const double value,const std::string * const pDescription=NULL);
/// Create or adjust "rot" parameter for a component
void addRotationParam(const IComponent *comp, const std::string &name,
const double deg);
const double deg,const std::string * const pDescription=NULL);
/// Adds a double value to the parameter map.
void addDouble(const IComponent *comp, const std::string &name,
const std::string &value);
const std::string &value,const std::string * const pDescription=NULL);
/// Adds a double value to the parameter map.
void addDouble(const IComponent *comp, const std::string &name, double value);
void addDouble(const IComponent *comp, const std::string &name, double value,
const std::string * const pDescription=NULL);
/// Adds an int value to the parameter map.
void addInt(const IComponent *comp, const std::string &name,
const std::string &value);
const std::string &value,const std::string * const pDescription=NULL);
/// Adds an int value to the parameter map.
void addInt(const IComponent *comp, const std::string &name, int value);
void addInt(const IComponent *comp, const std::string &name, int value,
const std::string * const pDescription=NULL);
/// Adds a bool value to the parameter map.
void addBool(const IComponent *comp, const std::string &name,
const std::string &value);
const std::string &value,const std::string * const pDescription=NULL);
/// Adds a bool value to the parameter map.
void addBool(const IComponent *comp, const std::string &name, bool value);
void addBool(const IComponent *comp, const std::string &name, bool value,
const std::string * const pDescription=NULL);
/// Adds a std::string value to the parameter map.
void addString(const IComponent *comp, const std::string &name,
const std::string &value);
const std::string &value,const std::string * const pDescription=NULL);
/// Adds a Kernel::V3D value to the parameter map.
void addV3D(const IComponent *comp, const std::string &name,
const std::string &value);
const std::string &value,const std::string * const pDescription=NULL);
/// @param value :: Parameter value as a Kernel::V3D
void addV3D(const IComponent *comp, const std::string &name,
const Kernel::V3D &value);
const Kernel::V3D &value,const std::string * const pDescription=NULL);
/// Adds a Kernel::Quat value to the parameter map.
void addQuat(const IComponent *comp, const std::string &name,
const Kernel::Quat &value);
const Kernel::Quat &value,const std::string * const pDescription=NULL);
//@}

/// Does the named parameter exist for the given component and type
Expand Down
22 changes: 22 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ namespace Geometry {
// Initialize the static map
ParameterFactory::FactoryMap ParameterFactory::s_map;

/**@return short description of the property (e.g. tooltip).
The short description defined as all in the full description
up to double LF symbol.
(Python agreement on a short description of a function or method)
If no double LF symbol found in the description string, full string
is returned.
*/
std::string Parameter::getTooltip()const{
size_t pos = m_description.find("\n\n");
if (pos == std::string::npos){
return std::string(m_description);
}else{
if (pos>1){
return m_description.substr(0,pos-1);
}else{
return std::string("");
}
}
}


/** Creates an instance of a parameter
* @param className :: The parameter registered type name
* @param name :: The parameter name
Expand Down
20 changes: 15 additions & 5 deletions Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ void ParameterMap::clearParametersByName(const std::string &name,
* @param value :: The parameter's value
*/
void ParameterMap::add(const std::string &type, const IComponent *comp,
const std::string &name, const std::string &value) {
const std::string &name, const std::string &value,
const Kernel::Quat &value,const std::string * const pDescription) {
auto param = ParameterFactory::create(type, name);
param->fromString(value);
this->add(comp, param);
this->add(comp, param,pDescription);
}

/** Method for adding/replacing a parameter providing shared pointer to it.
Expand All @@ -266,10 +267,13 @@ void ParameterMap::add(const std::string &type, const IComponent *comp,
* share pointer and increment ref count to it
*/
void ParameterMap::add(const IComponent *comp,
const boost::shared_ptr<Parameter> &par) {
const boost::shared_ptr<Parameter> &par,
const std::string * const pDescription) {
// can not add null pointer
if (!par)
return;
if (pDescription)
par->setDescription(pDescription)

PARALLEL_CRITICAL(m_mapAccess) {
auto existing_par = positionOf(comp, par->name().c_str(), "");
Expand All @@ -295,7 +299,8 @@ void ParameterMap::add(const IComponent *comp,
*/
void ParameterMap::addPositionCoordinate(const IComponent *comp,
const std::string &name,
const double value) {
const double value,
const std::string * const pDescription) {
Parameter_sptr param = get(comp, pos());
V3D position;
if (param) {
Expand All @@ -317,6 +322,10 @@ void ParameterMap::addPositionCoordinate(const IComponent *comp,
else {
g_log.warning() << "addPositionCoordinate() called with unrecognised "
"coordinate symbol: " << name;
// set description if one is provided
if(pDescription){
param->setDescription(pDescription);
}
return;
}

Expand All @@ -334,7 +343,8 @@ void ParameterMap::addPositionCoordinate(const IComponent *comp,
* @param deg :: Parameter value in degrees
*/
void ParameterMap::addRotationParam(const IComponent *comp,
const std::string &name, const double deg) {
const std::string &name, const double deg,
const std::string * const pDescription) {
Parameter_sptr paramRotX = get(comp, rotx());
Parameter_sptr paramRotY = get(comp, roty());
Parameter_sptr paramRotZ = get(comp, rotz());
Expand Down

0 comments on commit 4d47207

Please sign in to comment.