Skip to content

Commit

Permalink
Re #11508 redefined tooltip as all before .
Browse files Browse the repository at this point in the history
and added processing to IDF processing algorithm.
  • Loading branch information
abuts committed Apr 20, 2015
1 parent 0e26e40 commit 837dcc1
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 24 deletions.
19 changes: 11 additions & 8 deletions Code/Mantid/Framework/API/src/ExperimentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,13 +1122,17 @@ void ExperimentInfo::populateWithParameter(
ParameterValue paramValue(paramInfo,
runData); // Defines implicit conversion operator

const std::string * pDescription=NULL;
if(!paramInfo.m_description.empty())
pDescription = &paramInfo.m_description;

// Some names are special. Values should be convertible to double
if (name.compare("x") == 0 || name.compare("y") == 0 ||
name.compare("z") == 0) {
paramMap.addPositionCoordinate(paramInfo.m_component, name, paramValue);
} else if (name.compare("rot") == 0 || name.compare("rotx") == 0 ||
name.compare("roty") == 0 || name.compare("rotz") == 0) {
paramMap.addRotationParam(paramInfo.m_component, name, paramValue);
paramMap.addRotationParam(paramInfo.m_component, name, paramValue,pDescription);
} else if (category.compare("fitting") == 0) {
std::ostringstream str;
str << paramInfo.m_value << " , " << paramInfo.m_fittingFunction << " , "
Expand All @@ -1137,16 +1141,15 @@ void ExperimentInfo::populateWithParameter(
<< " , " << paramInfo.m_tie << " , " << paramInfo.m_formula << " , "
<< paramInfo.m_formulaUnit << " , " << paramInfo.m_resultUnit << " , "
<< (*(paramInfo.m_interpolation));
paramMap.add("fitting", paramInfo.m_component, name, str.str());
paramMap.add("fitting", paramInfo.m_component, name, str.str(),pDescription);
} else if (category.compare("string") == 0) {
paramMap.addString(paramInfo.m_component, name, paramInfo.m_value);
paramMap.addString(paramInfo.m_component, name, paramInfo.m_value,pDescription);
} else if (category.compare("bool") == 0) {
paramMap.addBool(paramInfo.m_component, name, paramValue);
paramMap.addBool(paramInfo.m_component, name, paramValue,pDescription);
} else if (category.compare("int") == 0) {
paramMap.addInt(paramInfo.m_component, name, paramValue);
} else // assume double
{
paramMap.addDouble(paramInfo.m_component, name, paramValue);
paramMap.addInt(paramInfo.m_component, name, paramValue,pDescription);
} else{ // assume double
paramMap.addDouble(paramInfo.m_component, name, paramValue,pDescription);
}
}

Expand Down
10 changes: 8 additions & 2 deletions Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class LoadParameterFileTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ptrDet->getName(), "combined translation6");
Parameter_sptr param = paramMap.get(&(*ptrDet), "fjols");
TS_ASSERT_DELTA( param->value<double>(), 20.0, 0.0001);
auto descr = param->getDescription();
// TS_ASSERT_EQUAL(descr,"test fjols description");

param = paramMap.get(&(*ptrDet), "nedtur");
TS_ASSERT_DELTA( param->value<double>(), 77.0, 0.0001);
param = paramMap.get(&(*ptrDet), "fjols-test-paramfile");
Expand All @@ -76,10 +79,13 @@ class LoadParameterFileTest : public CxxTest::TestSuite
TS_ASSERT_DELTA (dummy[0], 200.0, 0.0001);
dummy = paramMap.getDouble("nickel-holder", "mistake");
TS_ASSERT_EQUALS (dummy.size(), 0);
param = paramMap.getRecursive(i.get(),"mistake");
// TS_ASSERT_EQUALS(param->getTooltip(),"You made a terrible mistake")

dummy = paramMap.getDouble("nickel-holder", "fjols-test-paramfile");
TS_ASSERT_DELTA (dummy[0], 2000.0, 0.0001);

AnalysisDataService::Instance().remove(wsName);
AnalysisDataService::Instance().remove(wsName);

}

Expand Down Expand Up @@ -149,7 +155,7 @@ class LoadParameterFileTest : public CxxTest::TestSuite
dummy = paramMap.getDouble("nickel-holder", "fjols-test-paramfile");
TS_ASSERT_DELTA (dummy[0], 2010.0, 0.0001);

AnalysisDataService::Instance().remove(wsName);
AnalysisDataService::Instance().remove(wsName);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class XMLInstrumentParameterTest : public CxxTest::TestSuite
"double", "",
constraint, penaltyFactor,
fitFunc, extractSingleValueAs,
eq, comp, angleConvert);
eq, comp, angleConvert,"bla bla bla");

TimeSeriesProperty<double>* dummy = NULL;
TS_ASSERT_DELTA( testParamEntry.createParamValue(dummy), 1000.0, 0.0001);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ class MANTID_GEOMETRY_DLL ParameterMap {
}
return retval;
}
/** Get the component description by name */
const std::string getDescription(const std::string &compName,
const std::string &name) const;
/** Get the component tooltip by name */
const std::string getTooltip(const std::string &compName,
const std::string &name) const;

/// Return the value of a parameter as a string
std::string getString(const IComponent *comp, const std::string &name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ InstrumentDefinitionParser::parseXML(Kernel::ProgressBase *prog) {
// Collect some information about types for later use including:
// * populate directory getTypeElement
// * populate directory isTypeAssemply
// * create shapes for all none assemply components and store in
// * create shapes for all none assembly components and store in
// mapTyepNameToShape
// * If 'Outline' attribute set for assemply add attribute object_created=no
// * If 'Outline' attribute set for assembly add attribute object_created=no
// to tell
// create shape for such assemply also later
// create shape for such assembly also later
unsigned long numberTypes = pNL_type->length();
for (unsigned long iType = 0; iType < numberTypes; iType++) {
Element *pTypeElem = static_cast<Element *>(pNL_type->item(iType));
Expand Down Expand Up @@ -2035,6 +2035,7 @@ InstrumentDefinitionParser::setLogfile(const Geometry::IComponent *comp,
size_t numberDescription = pNLDescription ->length();

if (numberDescription >= 1){
// use only first description from a list
Element *pDescription =
static_cast<Element *>(pNLDescription->item(0));
description = pDescription->getAttribute("is");
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Geometry/src/Instrument/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ ParameterFactory::FactoryMap ParameterFactory::s_map;
is returned.
*/
std::string Parameter::getTooltip()const{
size_t pos = m_description.find("\n\n");
size_t pos = m_description.find(".");
if (pos == std::string::npos){
return std::string(m_description);
}else{
if (pos>0){
return m_description.substr(0,pos);
return m_description.substr(0,pos+1);
}else{
return std::string("");
}
Expand Down
46 changes: 46 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,52 @@ bool ParameterMap::operator==(const ParameterMap &rhs) const {
return true;
}

/** Get the component description by name
* @param compName :: The name of the component
* @param name :: The name of the parameter
* @return :: the description for the first parameter found and
* having non-empty description,
* or empty string if no description found.
*/
const std::string ParameterMap::getDescription(const std::string &compName,
const std::string &name) const{
pmap_cit it;
std::string result("");
for (it = m_map.begin(); it != m_map.end(); ++it) {
if (compName.compare(((const IComponent *)(*it).first)->getName()) == 0) {
boost::shared_ptr<Parameter> param =
get((const IComponent *)(*it).first, name);
if (param)
result = param->getDescription();
if(!result.empty())
return result;
}
}
return result;
}
/** Get the component tooltip by name
* @param compName :: The name of the component
* @param name :: The name of the parameter
* @return :: the tooltip (short description) for the first parameter
* found and having non-empty description,
* or empty string if no description found.
*/
const std::string ParameterMap::getTooltip(const std::string &compName,
const std::string &name) const{
pmap_cit it;
std::string result("");
for (it = m_map.begin(); it != m_map.end(); ++it) {
if (compName.compare(((const IComponent *)(*it).first)->getName()) == 0) {
boost::shared_ptr<Parameter> param =
get((const IComponent *)(*it).first, name);
if (param)
result = param->getTooltip();
if(!result.empty())
return result;
}
}
return result;
}
/**
* Output information that helps understanding the mismatch between two
* parameter maps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MantidKernel/Logger.h"
#include <ctime>
#include <fstream>
#include <boost/regex.hpp>

namespace Mantid {
namespace Geometry {
Expand Down Expand Up @@ -40,6 +41,7 @@ using namespace Kernel;
* @param penaltyFactor :: The level of penalty associated with the constraint
* @param fitFunc :: What fit function this applies to
* @param angleConvertConst :: angle conversion constant?????
* @param description :: text description of the parameter
*/
XMLInstrumentParameter::XMLInstrumentParameter(
const std::string &logfileID, const std::string &value,
Expand All @@ -59,7 +61,13 @@ XMLInstrumentParameter::XMLInstrumentParameter(
m_interpolation(interpolation),
m_extractSingleValueAs(extractSingleValueAs), m_eq(eq), m_component(comp),
m_angleConvertConst(angleConvertConst),
m_description(description){}
m_description(""){
if(!description.empty()){ // remove multiple spaces
boost::regex re("\\s+");
std::string desc = boost::regex_replace(description,re," ");
(const_cast<std::string *>(&m_description))->assign(desc);
}
}

/** Returns the parameter value.
* This interprets the XML parameter specification in order to do one of these
Expand Down
13 changes: 10 additions & 3 deletions Code/Mantid/Framework/Geometry/test/ParameterMapTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,16 @@ class ParameterMapTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(parD->getDescription(),descr);
TS_ASSERT_EQUALS(parD->getTooltip(),"Test description");

parD->setDescription("Short description\n\nLongDescription");
TS_ASSERT_EQUALS(parD->getDescription(),"Short description\n\nLongDescription");
TS_ASSERT_EQUALS(parD->getTooltip(),"Short description");
parD->setDescription("Short description. LongDescription.");
TS_ASSERT_EQUALS(parD->getDescription(),"Short description. LongDescription.");
TS_ASSERT_EQUALS(parD->getTooltip(),"Short description.");


descr = pmapA.getDescription("basic","testDouble");
TS_ASSERT_EQUALS(descr,"Short description. LongDescription.");
descr = pmapA.getTooltip("basic","testDouble");
TS_ASSERT_EQUALS(descr,"Short description.");

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,16 @@ class XMLInstrumentParameterTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Filtering by Nth position is not performed correctly", expectedFilteredValue, actualFilteredValue);
}

void test_help_string()
{
std::vector<std::string> constr;
std::string penaltyFactor;
XMLInstrumentParameter testPar("logfileID","value",boost::make_shared<Interpolation>(),"formula",
"sourceFU","resultFU","testPar","aType","noTie",
constr,penaltyFactor,"aFitFunc","FilterBy","eqTo",NULL,0.0,"test string. Long test string.");


TS_ASSERT_EQUALS(testPar.m_description,"test string. Long test string.");
}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<point x="61000" y="110" />
<point x="62000" y="120" />
</lookuptable>
<description is = "this is test description
long long description"/>
</parameter>
</component>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
<!-- <offsets spherical="delta" /> -->
</defaults>

<parameter name="somefunction:toplevel" type="fitting"> <value val="100.0" /> <min val="80"/> <max val="120"/> </parameter>
<parameter name="somefunction:toplevel" type="fitting"> <value val="100.0" /> <min val="80"/> <max val="120"/>
<description is = "Test description for the fitting parameter toplevel\n
long long test description for toplevel fitting parameter"/>
</parameter>

<parameter name="somefunction:percentage" type="fitting"> <value val="250.0" /> <min val="80%"/> <max val="120%"/> <penalty-factor val="9.1" /> </parameter>

<parameter name="somefunction:formula" type="fitting"> <formula eq="100.0+10*centre+centre^2" unit="TOF" result-unit="dSpacing"/> </parameter>


<component-link name="nickel-holder" >
<parameter name="fjols"> <value val="200.0" /> </parameter>
<parameter name="fjols"> <value val="200.0" />
<description is = "test fjols description" />
</parameter>
<parameter name="fjols-string" type="string"> <value val="boevs" /> </parameter>
</component-link>

Expand Down Expand Up @@ -96,7 +102,9 @@
<logfile id="nedtur"/>
<value val="200.0" />
</parameter>
<parameter name="mistake"> </parameter>
<parameter name="mistake">
<description is = "You made a terrible mistake"/>
</parameter>
</component>

<type name="undulator" is="source">
Expand Down

0 comments on commit 837dcc1

Please sign in to comment.