18#include <Poco/SAX/AttributesImpl.h>
19#include <Poco/XML/XMLWriter.h>
34 : m_parent(nullptr), m_base(dynamic_cast<const
Component *>(base)), m_map(map) {
36 throw std::invalid_argument(
"Component::Component() - Cannot construct a "
37 "parameterized component from an invalid base component.");
51 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(
name)), m_pos(), m_rot() {}
60 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(
name)), m_pos(
position), m_rot() {}
69 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(
name)), m_pos(
position), m_rot(
rotation) {}
102 return const_cast<const Component *
>(
this);
134 while (parent && (depth < maxDepth || maxDepth < 0)) {
136 if (parent->
getName() == expectedName)
150 std::vector<std::shared_ptr<const IComponent>> ancs;
152 std::shared_ptr<const IComponent> current = this->
getParent();
154 ancs.emplace_back(current);
155 current = current->getParent();
186 std::vector<std::shared_ptr<const IComponent>> ancestors = this->
getAncestors();
187 if (ancestors.empty()) {
190 std::ostringstream oss;
191 std::vector<std::shared_ptr<const IComponent>>::reverse_iterator rit;
192 for (rit = ancestors.rbegin(); rit < ancestors.rend(); ++rit) {
193 oss << (*rit)->getName() <<
"/";
293 return par->value<
V3D>();
307 auto instrument =
dynamic_cast<const Instrument *
>(root);
352 std::shared_ptr<const IComponent> parParent =
getParent();
355 parentPos = parParent->getPos();
386 return absPos + parentPos;
421 std::shared_ptr<const IComponent> parParent =
getParent();
459 return std::set<std::string>();
461 std::set<std::string> names =
m_map->
names(
this);
465 std::shared_ptr<const IComponent> parent =
getParent();
467 std::set<std::string> parentNames = parent->getParameterNames(
true);
468 names.insert(parentNames.begin(), parentNames.end());
481 auto retVal = std::map<std::string, ComponentID>();
486 for (
const auto &
name : names) {
491 std::shared_ptr<const IComponent> parent =
getParent();
493 auto parentNames = parent->getParameterNamesByComponent();
495 retVal.insert(parentNames.begin(), parentNames.end());
511 bool match_found(
false);
514 }
else if (recursive) {
515 std::shared_ptr<const IComponent> parent =
getParent();
517 match_found = parent->hasParameter(
name,
true);
531 std::shared_ptr<const IComponent> parent =
getParent();
532 os <<
"Name : " <<
getName() <<
'\n';
533 os <<
"Type: " << this->
type() <<
'\n';
535 os <<
"Parent: " << parent->getName() <<
'\n';
537 os <<
"Parent: None\n";
539 os <<
"Position : " <<
getPos() <<
'\n';
565 Poco::XML::AttributesImpl attr;
567 writer.startElement(
"",
"Component",
"", attr);
568 writer.endElement(
"",
"Component",
"");
575 xmlStream <<
"<pos>";
577 xmlStream <<
"</pos>\n";
578 xmlStream <<
"<rot>" <<
m_rot <<
"</rot>\n";
608 return std::string(
"");
617 return param->getDescription();
619 return std::string(
"");
639 return std::string(
"");
648 return param->getShortDescription();
650 return std::string(
"");
667 param->setDescription(descr);
675 "not implemented for "
676 "non-Parametrized Component)");
694 throw std::runtime_error(
"Fitting parameter=" + pname +
695 " could not be extracted from component=" + this->
getName());
699 const auto &fitParam = parameter->value<
FitParameter>();
702 throw std::runtime_error(
"Unable to get lookup table for parameter=" + pname +
703 " from component=" + this->
getName());
706 throw std::runtime_error(
"Parameter map is not available in component=" + this->
getName());
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Kernel::Quat rotation(const size_t componentIndex) const
Kernel::V3D position(const size_t componentIndex) const
Kernel::V3D relativePosition(const size_t componentIndex) const
Kernel::Quat relativeRotation(const size_t componentIndex) const
Kernel::V3D scaleFactor(const size_t componentIndex) const
ComponentVisitor : Visitor for IComponents.
virtual size_t registerGenericComponent(const IComponent &component)=0
Component is a wrapper for a Component which can modify some of its parameters, e....
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
void setSideBySideViewPos(const Kernel::V2D &) override
Set the IComponent position in the side by side instrument view.
virtual void writeXML(Poco::XML::XMLWriter &writer) const
std::map< std::string, ComponentID > getParameterNamesByComponent() const override
return the parameter names and the component they are from
std::string getParamDescription(const std::string &pname, bool recursive=true) const
Get description of a parameter attached to this component
void setRot(const Kernel::Quat &) override
Set the orientation Kernel::Quaternion relative to parent (if present)
std::string getParamShortDescription(const std::string &pname, bool recursive=true) const
Get a component's parameter short description.
std::optional< Kernel::V2D > m_sidebysideviewpos
Position of component in instrument viewer side by side view.
double getFittingParameter(const std::string &pname, double xvalue) const
Get fitting parameter.
virtual void readXMLAttributes(const Poco::XML::Attributes &attr)
Reads the XML attributes from Poco XML parser.
size_t index() const
Helper for legacy access mode. Returns the index of the component.
void setParent(IComponent *) override
Assign a parent IComponent. Previous parent link is lost.
std::string m_name
Name of the component.
Kernel::Quat getRelativeRot() const override
Get the relative Orientation.
void printSelf(std::ostream &) const override
Prints a text representation of itself.
Component()
Create Empty Component at Origin, with no orientation and null parent.
Kernel::V3D m_pos
Position w.
Kernel::V3D getRelativePos() const override
Get the position relative to the parent IComponent (absolute if no parent)
IComponent * clone() const override
Clone method Make a copy of the Component.
void setName(const std::string &) override
Set the IComponent name.
bool hasComponentInfo() const
virtual void appendXML(std::ostream &xmlStream) const
Append to an open XML string.
void rotate(const Kernel::Quat &) override
Rotate the IComponent. This is relative to parent.
void getBoundingBox(BoundingBox &boundingBox) const override
Get the bounding box for this component and store it in the given argument.
const IComponent * base() const
Returns the address of the base component.
std::set< std::string > getParameterNames(bool recursive=true) const override
Return the parameter names.
virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override
Kernel::V3D getScaleFactor() const override
Returns the ScaleFactor.
Kernel::V3D getPos() const override
Get the position of the IComponent. Tree structure is traverse through the.
std::shared_ptr< const IComponent > getParent() const override
Return a pointer to the current parent. as shared pointer.
std::optional< Kernel::V2D > getSideBySideViewPos() const override
Return the position of the component required on the instrument side by side view.
bool isParametrized() const override
Return true if the Component is, in fact, parametrized (that is - it has a valid parameter map)
const IComponent * m_parent
Parent component in the tree.
void swap(const Component *base, const ParameterMap *pmap)
Swap the current references to the un-parameterized component and parameter map for new ones.
Kernel::Quat m_rot
Orientation.
std::string getFullName() const override
Get the full pathname.
IComponent const * getBaseComponent() const override
Returns const pointer to base component if this component is parametrized.
double getDistance(const IComponent &) const override
Get the distance to another IComponent.
std::string getName() const override
Get the IComponent name.
const Component * m_base
The base component - this is the unmodified component (without the parameters).
bool isParentNamed(const std::string &expectedName, int maxDepth=-1) const
Return true if one of the parents of this component is named something.
Kernel::Quat getRotation() const override
Get the absolute orientation of the IComponent.
std::vector< std::shared_ptr< const IComponent > > getAncestors() const override
Return an array of all ancestors.
void setDescription(const std::string &descr)
Set components description.
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)
std::string getDescription() const
Get this component parameter's description – no recursive search within children.
bool hasParameter(const std::string &name, bool recursive=true) const override
Returns a boolean indicating if the component has the named parameter.
void translate(const Kernel::V3D &) override
Translate the IComponent (vector form). This is relative to parent if.
ComponentID getComponentID() const override
Returns the ComponentID - a unique identifier of the component.
std::string getShortDescription() const
Get a components's short description.
Store information about a fitting parameter such as its value if it is constrained or tied.
double getValue(const double &at) const
get paramter value
base class for Geometric IComponent
virtual Kernel::V3D getPos() const =0
Get the position of the IComponent. Tree structure is traverse through the.
virtual std::string type() const
Returns a string representation of the IComponent type.
virtual std::optional< Kernel::V2D > getSideBySideViewPos() const =0
Get the position of the IComponent for display on the side by side instrument view.
virtual Kernel::Quat getRotation() const =0
Get the absolute orientation of the IComponent.
virtual const IComponent * getBareParent() const =0
Returns the bare pointer to the IComponent parent.
virtual std::string getName() const =0
Get the IComponent name.
Void deleter for shared pointers.
static std::shared_ptr< IComponent > create(const std::shared_ptr< const IComponent > &base, const ParameterMap *map)
Create a parameterized component from the given base component and ParameterMap.
bool getCachedRotation(const IComponent *comp, Kernel::Quat &rotation) const
Attempts to retrieve a rotation from the rotation cache.
bool getCachedLocation(const IComponent *comp, Kernel::V3D &location) const
Attempts to retrieve a location from the location cache.
bool contains(const IComponent *comp, const std::string &name, const std::string &type="") const
Does the named parameter exist for the given component and type (std::string version)
std::shared_ptr< Parameter > getRecursive(const IComponent *comp, const std::string &name, const std::string &type="") const
Use get() recursively to see if can find param in all parents of comp and given type (std::string ver...
static const std::string & scale()
std::set< std::string > names(const IComponent *comp) const
Returns a set with all parameter names for component.
size_t componentIndex(const Geometry::ComponentID componentId) const
bool hasComponentInfo(const Instrument *instrument) const
Only for use by ExperimentInfo.
std::shared_ptr< Parameter > get(const IComponent *comp, const std::string &name, const std::string &type="") const
Get a parameter with a given name and type (std::string version)
const Geometry::ComponentInfo & componentInfo() const
Only for use by ExperimentInfo. Returns a reference to the ComponentInfo.
Marks code as not implemented yet.
void rotate(V3D &) const
Rotate a vector.
std::vector< double > getRotation(bool check_normalisation=false, bool throw_on_errors=false) const
returns the rotation matrix defined by this quaternion as an 9-point
Implements a 2-dimensional vector embedded in a 3D space, i.e.
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
std::string toString() const
void write(std::ostream &) const
Write out the point values.
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
IComponent * ComponentID
Define a type for a unique component identifier.
Generate a tableworkspace to store the calibration results.