Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/10139_show_inst_params_o…
Browse files Browse the repository at this point in the history
…n_inst_view'
  • Loading branch information
mantid-roman committed Aug 22, 2014
2 parents 7560909 + 687eefb commit f406f1e
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 8 deletions.
23 changes: 18 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/SetInstrumentParameter.cpp
Expand Up @@ -91,17 +91,20 @@ namespace Algorithms
Strings::strip(paramValue);

auto inst = ws->getInstrument();
//set default to whole instrument
std::vector<IDetector_const_sptr> dets;
boost::shared_ptr<const IComponent> cmpt = inst;
std::vector<IComponent_const_sptr> cmptList;
//set default to whole instrument
cmptList.push_back(inst);

if (!detectorList.empty())
{
dets = inst->getDetectors(detectorList);
}
else if (cmptName.length() > 0)
{
//get the first matching cmpt
cmpt = inst->getComponentByName(cmptName);
//get all matching cmpts
cmptList = inst->getAllComponentsWithName(cmptName);

}

auto& paramMap = ws->instrumentParameters();
Expand All @@ -114,7 +117,17 @@ namespace Algorithms
}
else
{
addParameter(paramMap, cmpt.get(),paramName,paramType,paramValue);
if (cmptList.size() > 0)
{
for (auto it = cmptList.begin(); it != cmptList.end(); ++it)
{
addParameter(paramMap, it->get(),paramName,paramType,paramValue);
}
}
else
{
g_log.warning("Could not find the component requested.");
}
}

}
Expand Down
Expand Up @@ -132,6 +132,8 @@ namespace Mantid
//@{
/// Return the names of the parameters for this component
virtual std::set<std::string> getParameterNames(bool recursive = true) const = 0;
///return the parameter names and the component they are from
virtual std::map<std::string,ComponentID > getParameterNamesByComponent() const = 0;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const = 0;
//Hack until proper python export functions are defined
Expand All @@ -150,7 +152,8 @@ namespace Mantid
virtual std::vector<int> getIntParameter(const std::string& pname, bool recursive = true) const = 0;
/// Get a parameter defined as a boolean
virtual std::vector<bool> getBoolParameter(const std::string& pname, bool recursive = true) const = 0;

///get a string representation of a parameter
virtual std::string getParameterAsString(const std::string& pname, bool recursive = true) const =0;
//@}
/** Prints a text representation of itself
*/
Expand Down
Expand Up @@ -161,6 +161,8 @@ namespace Mantid
// one for each type, luckily there won't be too many
/// Return the parameter names
virtual std::set<std::string> getParameterNames(bool recursive = true) const;
///return the parameter names and the component they are from
virtual std::map<std::string,ComponentID > getParameterNamesByComponent() const;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const;

Expand Down Expand Up @@ -254,6 +256,16 @@ namespace Mantid
}
//@}

std::string getParameterAsString(const std::string& pname, bool recursive = true) const
{
std::string retVal = "";
if (m_map)
{
retVal = m_map->getString(this, pname, recursive);
}
return retVal;
}

void printSelf(std::ostream&) const;

/// Returns the address of the base component
Expand Down
Expand Up @@ -85,6 +85,8 @@ namespace Mantid
// one for each type, luckily there won't be too many
/// Return the parameter names
virtual std::set<std::string> getParameterNames(bool recursive = true) const;
///return the parameter names and the component they are from
virtual std::map<std::string,ComponentID > getParameterNamesByComponent() const;
/// Returns a boolean indicating whether the parameter exists or not
bool hasParameter(const std::string & name, bool recursive = true) const;
// Hack used untill Geomertry can not exprot different types parematers properly
Expand Down Expand Up @@ -135,6 +137,14 @@ namespace Mantid
*/
std::vector<bool> getBoolParameter(const std::string& pname, bool recursive = true) const;

/**
* Get a string representation of a parameter
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns A empty string as this is not a parameterized component
*/
std::string getParameterAsString(const std::string& pname, bool recursive = true) const;

/** returns the detector's group topology if it has been calculated before or invokes the procedure of
calculating such topology if it was not */
det_topology getTopology(Kernel::V3D &center)const;
Expand Down
Expand Up @@ -235,7 +235,7 @@ namespace Geometry
}

/// Return the value of a parameter as a string
std::string getString(const IComponent* comp,const std::string& name) const;
std::string getString(const IComponent* comp,const std::string& name, bool recursive = false) const;
/// Returns a string parameter as vector's first element if exists and an empty vector if it doesn't
std::vector<std::string> getString(const std::string& compName,const std::string& name) const
{
Expand Down
26 changes: 26 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp
Expand Up @@ -493,6 +493,32 @@ namespace Geometry
return names;
}

/**
* Get the names of the parameters for this component and it's parents.
* @returns A map of strings giving the parameter names and the component they are from, warning this contains shared pointers keeping transient objects alive, do not keep longer than needed
*/
std::map<std::string,ComponentID > Component::getParameterNamesByComponent() const
{
auto retVal = std::map<std::string, ComponentID>();
if (!m_map) return retVal;

std::set<std::string> names = m_map->names(this);
for (auto itNames = names.begin(); itNames != names.end(); ++itNames)
{
retVal.insert(std::pair<std::string, ComponentID>(*itNames,this->getComponentID()));
}

//Walk up the tree and find the parameters attached to the parent components
boost::shared_ptr<const IComponent> parent = getParent();
if( parent )
{
auto parentNames = parent->getParameterNamesByComponent();
//this should discard duplicates
retVal.insert(parentNames.begin(), parentNames.end());
}
return retVal;
}

/**
* Returns a boolean indicating if the component has the named parameter
* @param name :: The name of the parameter
Expand Down
23 changes: 23 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp
Expand Up @@ -343,6 +343,29 @@ namespace Mantid
return std::set<std::string>();
}

/**
* Get the names of the parameters for this component and it's parents.
* @returns A map of strings giving the parameter names and the component they are from, warning this contains shared pointers keeping transient objects alive, do not keep longer than needed
*/
std::map<std::string,ComponentID > DetectorGroup::getParameterNamesByComponent() const
{
return std::map<std::string,ComponentID >();
}

/**
* Get a string representation of a parameter
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns A empty string as this is not a parameterized component
*/
std::string DetectorGroup::getParameterAsString(const std::string& pname, bool recursive) const
{
(void) pname; //Avoid compiler warning
(void) recursive; //Avoid compiler warning
return "";
}


/**
* Get the bounding box for this group of detectors. It is simply the sum of the bounding boxes of its constituents.
* @param boundingBox :: [Out] The resulting bounding box is stored here.
Expand Down
11 changes: 10 additions & 1 deletion Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
Expand Up @@ -831,11 +831,20 @@ namespace Mantid
* Return the value of a parameter as a string
* @param comp :: Component to which parameter is related
* @param name :: Parameter name
* @param recursive :: Whether to travel up the instrument tree if not found at this level
* @return string representation of the parameter
*/
std::string ParameterMap::getString(const IComponent* comp, const std::string& name) const
std::string ParameterMap::getString(const IComponent* comp, const std::string& name, bool recursive) const
{
Parameter_sptr param = get(comp,name);
if( recursive )
{
param = getRecursive(comp,name);
}
else
{
param = get(comp,name);
}
if (!param) return "";
return param->asString();
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
#include "PeakMarker2D.h"

#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DynamicFactory.h"
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/ITableWorkspace.h"
Expand Down Expand Up @@ -366,6 +367,8 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid)
xUnits = QString::fromStdString(instrActor->getWorkspace()->getAxis(0)->unit()->caption());
}
text += "X units: " + xUnits + '\n';
// display info about peak overlays
text += getParameterInfo(det);
}
else
{
Expand All @@ -376,6 +379,8 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid)
// display info about peak overlays
text += getNonDetectorInfo();



if ( !text.isEmpty() )
{
m_selectionInfoDisplay->setText(text);
Expand All @@ -386,6 +391,55 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid)
}
}

/**
* Form a string for output from the components instrument parameters
*/
QString InstrumentWindowPickTab::getParameterInfo(Mantid::Geometry::IComponent_const_sptr comp)
{
QString text = "";
std::map<Mantid::Geometry::ComponentID, std::vector<std::string> > mapCmptToNameVector;

auto paramNames = comp->getParameterNamesByComponent();
for (auto itParamName = paramNames.begin(); itParamName != paramNames.end(); ++itParamName)
{
//build the data structure I need Map comp id -> vector of names
std::string paramName = itParamName->first;
Mantid::Geometry::ComponentID paramCompId = itParamName->second;
//attempt to insert this will fail silently if the key already exists
if ( mapCmptToNameVector.find(paramCompId) == mapCmptToNameVector.end() )
{
mapCmptToNameVector.insert(std::pair<Mantid::Geometry::ComponentID, std::vector<std::string> >(paramCompId,std::vector<std::string>()));
}
//get the vector out and add the name
mapCmptToNameVector[paramCompId].push_back(paramName);
}

//walk out from the selected component
Mantid::Geometry::IComponent_const_sptr paramComp = comp;
while (paramComp)
{
auto& compParamNames = mapCmptToNameVector[paramComp->getComponentID()];
if (compParamNames.size() > 0)
{
text += QString::fromStdString("\nParameters from: " + paramComp->getName() + "\n");
std::sort(compParamNames.begin(), compParamNames.end(),Mantid::Kernel::CaseInsensitiveStringComparator());
for (auto itParamName = compParamNames.begin(); itParamName != compParamNames.end(); ++itParamName)
{
std::string paramName = *itParamName;
//no need to search recursively as we are asking from the matching component
std::string paramValue = paramComp->getParameterAsString(paramName,false);
if (paramValue != "")
{
text += QString::fromStdString(paramName + ": " + paramValue + "\n");
}
}
}
paramComp = paramComp->getParent();
}

return text;
}

/**
* Display the miniplot's context menu.
*/
Expand Down
Expand Up @@ -100,6 +100,7 @@ private slots:
std::vector<double>* err = NULL);
QString getTubeXUnitsName(TubeXUnits unit) const;
QString getNonDetectorInfo();
QString getParameterInfo(Mantid::Geometry::IComponent_const_sptr comp);
QColor getShapeBorderColor() const;
static double getOutOfPlaneAngle(const Mantid::Kernel::V3D& pos, const Mantid::Kernel::V3D& origin, const Mantid::Kernel::V3D& normal);

Expand Down

0 comments on commit f406f1e

Please sign in to comment.