17#include <Poco/SAX/AttributesImpl.h>
18#include <Poco/XML/XMLWriter.h>
32 : m_parent(nullptr), m_base(dynamic_cast<const
Component *>(base)), m_map(map) {
34 throw std::invalid_argument(
"Component::Component() - Cannot construct a "
35 "parameterized component from an invalid base component.");
49 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(name)), m_pos(), m_rot() {}
58 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(name)), m_pos(
position), m_rot() {}
67 : m_parent(parent), m_base(nullptr), m_map(nullptr), m_name(
std::move(name)), m_pos(
position), m_rot(
rotation) {}
100 return const_cast<const Component *
>(
this);
132 while (parent && (depth < maxDepth || maxDepth < 0)) {
134 if (parent->
getName() == expectedName)
148 std::vector<std::shared_ptr<const IComponent>> ancs;
150 std::shared_ptr<const IComponent> current = this->
getParent();
152 ancs.emplace_back(current);
153 current = current->getParent();
184 std::vector<std::shared_ptr<const IComponent>> ancestors = this->
getAncestors();
185 if (ancestors.empty()) {
188 std::ostringstream oss;
189 std::vector<std::shared_ptr<const IComponent>>::reverse_iterator rit;
190 for (rit = ancestors.rbegin(); rit < ancestors.rend(); ++rit) {
191 oss << (*rit)->getName() <<
"/";
289 return par->value<
V3D>();
303 auto instrument =
dynamic_cast<const Instrument *
>(root);
348 std::shared_ptr<const IComponent> parParent =
getParent();
351 parentPos = parParent->getPos();
400 std::shared_ptr<const IComponent> parParent =
getParent();
438 return std::set<std::string>();
440 std::set<std::string> names =
m_map->
names(
this);
444 std::shared_ptr<const IComponent> parent =
getParent();
446 std::set<std::string> parentNames = parent->getParameterNames(
true);
447 names.insert(parentNames.begin(), parentNames.end());
460 auto retVal = std::map<std::string, ComponentID>();
465 for (
const auto &name : names) {
466 retVal.insert(std::pair<std::string, ComponentID>(name, this->
getComponentID()));
470 std::shared_ptr<const IComponent> parent =
getParent();
472 auto parentNames = parent->getParameterNamesByComponent();
474 retVal.insert(parentNames.begin(), parentNames.end());
490 bool match_found(
false);
493 }
else if (recursive) {
494 std::shared_ptr<const IComponent> parent =
getParent();
496 match_found = parent->hasParameter(name,
true);
510 std::shared_ptr<const IComponent> parent =
getParent();
511 os <<
"Name : " <<
getName() <<
'\n';
512 os <<
"Type: " << this->
type() <<
'\n';
514 os <<
"Parent: " << parent->getName() <<
'\n';
516 os <<
"Parent: None\n";
518 os <<
"Position : " <<
getPos() <<
'\n';
544 Poco::XML::AttributesImpl attr;
546 writer.startElement(
"",
"Component",
"", attr);
547 writer.endElement(
"",
"Component",
"");
554 xmlStream <<
"<pos>";
556 xmlStream <<
"</pos>\n";
557 xmlStream <<
"<rot>" <<
m_rot <<
"</rot>\n";
587 return std::string(
"");
596 return param->getDescription();
598 return std::string(
"");
618 return std::string(
"");
627 return param->getShortDescription();
629 return std::string(
"");
643 std::string name = this->
getName();
646 param->setDescription(descr);
654 "not implemented for "
655 "non-Parametrized Component)");
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.
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.
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.
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.
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 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
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.