Mantid
Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidGeometry/DllConfig.h"
11#include "MantidKernel/Quat.h"
12#include "MantidKernel/V3D.h"
13
14#include <string>
15#include <typeinfo>
16#include <vector>
17
18namespace Poco {
19namespace XML {
20class Attributes;
21class XMLWriter;
22} // namespace XML
23} // namespace Poco
24
25namespace Mantid {
26namespace Geometry {
27
28//----------------------------------------------------------------------
29// Forward declarations
30//----------------------------------------------------------------------
31template <typename T> class ComponentPool;
32
41class MANTID_GEOMETRY_DLL Component : public virtual IComponent {
42public:
44 virtual std::string typeName() const { return "Component"; }
45
47 Component(const IComponent *base, const ParameterMap *map);
48
50 Component();
52 explicit Component(std::string name, IComponent *parent = nullptr);
54 //(optional)
55 Component(std::string name, const Kernel::V3D &position, IComponent *parent = nullptr);
57 // component
58 Component(std::string name, const Kernel::V3D &position, const Kernel::Quat &rotation, IComponent *parent = nullptr);
59
60 IComponent *clone() const override;
61
63 ComponentID getComponentID() const override;
65 // or pointer to itself if not. Currently is the same as getComponentID bar
66 // const cast;
67 IComponent const *getBaseComponent() const override;
68
70 void setParent(IComponent *) override;
71
73 std::shared_ptr<const IComponent> getParent() const override;
75 std::vector<std::shared_ptr<const IComponent>> getAncestors() const override;
76
77 bool isParentNamed(const std::string &expectedName, int maxDepth = -1) const;
78
80 void setName(const std::string &) override;
81
83 std::string getName() const override;
84
86 std::string getFullName() const override;
87
89 // otherwise absolute
90 void setPos(double, double, double) override;
91 void setPos(const Kernel::V3D &) override;
92
94 // otherwise absolute
95 void setRot(const Kernel::Quat &) override;
96
98 // present.
99 void translate(const Kernel::V3D &) override;
100
102 // present.
103 void translate(double, double, double) override;
104
106 void rotate(const Kernel::Quat &) override;
107
109 void rotate(double, const Kernel::V3D &) override;
110
112 Kernel::V3D getRelativePos() const override;
113
115 // parent chain
116 Kernel::V3D getPos() const override;
117
119 Kernel::Quat getRelativeRot() const override;
120
122 Kernel::Quat getRotation() const override;
123
125 double getDistance(const IComponent &) const override;
126
128 void getBoundingBox(BoundingBox &boundingBox) const override;
129
132 // 06/05/2010 MG: Templated virtual functions cannot be defined so we have to
133 // resort to
134 // one for each type, luckily there won't be too many
136 std::set<std::string> getParameterNames(bool recursive = true) const override;
138 std::map<std::string, ComponentID> getParameterNamesByComponent() const override;
140 bool hasParameter(const std::string &name, bool recursive = true) const override;
141
149 std::vector<double> getNumberParameter(const std::string &pname, bool recursive = true) const override {
150 return getParameter<double>(pname, recursive);
151 }
152
160 std::vector<int> getIntParameter(const std::string &pname, bool recursive = true) const override {
161 return getParameter<int>(pname, recursive);
162 }
163
173 std::string getParameterType(const std::string &pname, bool recursive = true) const override {
174 Parameter_sptr param;
175 if (recursive) {
176 param = m_map->getRecursive(this, pname);
177 } else {
178 param = m_map->get(this, pname);
179 }
180 if (param)
181 return std::string(param->type());
182 else
183 return std::string("");
184 }
187 std::string getDescription() const;
188
190 std::string getParamDescription(const std::string &pname, bool recursive = true) const;
191
193 std::string getParamShortDescription(const std::string &pname, bool recursive = true) const;
195 std::string getShortDescription() const;
197 void setDescription(const std::string &descr);
205 std::vector<bool> getBoolParameter(const std::string &pname, bool recursive = true) const override {
206 return getParameter<bool>(pname, recursive);
207 }
208
216 std::vector<Kernel::V3D> getPositionParameter(const std::string &pname, bool recursive = true) const override {
217 return getParameter<Kernel::V3D>(pname, recursive);
218 }
219
227 std::vector<Kernel::Quat> getRotationParameter(const std::string &pname, bool recursive = true) const override {
228 return getParameter<Kernel::Quat>(pname, recursive);
229 }
230
238 std::vector<std::string> getStringParameter(const std::string &pname, bool recursive = true) const override {
239 return getParameter<std::string>(pname, recursive);
240 }
242
243 std::string getParameterAsString(const std::string &pname, bool recursive = true) const override {
244 std::string retVal;
245 if (m_map) {
246 retVal = m_map->getString(this, pname, recursive);
247 }
248 return retVal;
249 }
250
258 bool getParameterVisible(const std::string &p_name, bool recursive) const override {
259 if (m_map) {
260 Parameter_sptr param;
261 if (recursive) {
262 param = m_map->getRecursive(this, p_name);
263 } else {
264 param = m_map->get(this, p_name);
265 }
266 if (param != Parameter_sptr()) {
267 return param->visible();
268 } else {
269 return false;
270 }
271 } else {
272 // Not parametrized = not visible by default
273 return false;
274 }
275 }
276
277 void printSelf(std::ostream &) const override;
278
280 const IComponent *base() const { return m_base; }
281
283 Kernel::V3D getScaleFactor() const override;
284
286 const IComponent *getBareParent() const override { return m_parent; }
287
288 virtual void readXMLAttributes(const Poco::XML::Attributes &attr);
289 virtual void writeXML(Poco::XML::XMLWriter &writer) const;
290 virtual void appendXML(std::ostream &xmlStream) const;
291
292 bool isParametrized() const override;
293
294 virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override;
295 bool hasComponentInfo() const;
296 size_t index() const;
297
298protected:
308
310 std::string m_name;
315
324 template <class TYPE> std::vector<TYPE> getParameter(const std::string &p_name, bool recursive) const {
325 if (m_map) {
326 Parameter_sptr param;
327 if (recursive) {
328 param = m_map->getRecursive(this, p_name);
329 } else {
330 param = m_map->get(this, p_name);
331 }
332 if (param != Parameter_sptr()) {
333 return std::vector<TYPE>(1, param->value<TYPE>());
334 } else {
335 return std::vector<TYPE>(0);
336 }
337 } else {
338 // Not parametrized = return empty vector
339 return std::vector<TYPE>(0);
340 }
341 }
342
343protected:
344 // This method is only required for efficient caching of parameterized
345 // components and
346 // should not form part of the interface. It is an implementation detail.
347 template <typename T> friend class ComponentPool;
350 void swap(const Component *base, const ParameterMap *pmap);
351};
352
353} // namespace Geometry
354} // namespace Mantid
double position
Definition: GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
std::string getName(const IMDDimension &self)
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
ComponentVisitor : Visitor for IComponents.
Component is a wrapper for a Component which can modify some of its parameters, e....
Definition: Component.h:41
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
Definition: Component.h:307
bool getParameterVisible(const std::string &p_name, bool recursive) const override
Get a visibility attribute of a parameter from the parameter map.
Definition: Component.h:258
virtual std::string typeName() const
Definition: Component.h:44
const IComponent * getBareParent() const override
Returns the bare pointer to the IComponent parent.
Definition: Component.h:286
std::vector< double > getNumberParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a double.
Definition: Component.h:149
std::vector< Kernel::Quat > getRotationParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a Kernel::Quaternion.
Definition: Component.h:227
std::string m_name
Name of the component.
Definition: Component.h:310
Kernel::V3D m_pos
Position w.
Definition: Component.h:312
std::string getParameterAsString(const std::string &pname, bool recursive=true) const override
get a string representation of a parameter
Definition: Component.h:243
std::vector< int > getIntParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as an int.
Definition: Component.h:160
std::vector< Kernel::V3D > getPositionParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a Kernel::V3D.
Definition: Component.h:216
std::string getParameterType(const std::string &pname, bool recursive=true) const override
Get a parameter's type – this is HACK until Python can export property regardless of the property typ...
Definition: Component.h:173
const IComponent * base() const
Returns the address of the base component.
Definition: Component.h:280
const IComponent * m_parent
Parent component in the tree.
Definition: Component.h:300
Kernel::Quat m_rot
Orientation.
Definition: Component.h:314
const Component * m_base
The base component - this is the unmodified component (without the parameters).
Definition: Component.h:305
std::vector< std::string > getStringParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a string.
Definition: Component.h:238
std::vector< bool > getBoolParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a bool.
Definition: Component.h:205
std::vector< TYPE > getParameter(const std::string &p_name, bool recursive) const
Get a parameter from the parameter map.
Definition: Component.h:324
base class for Geometric IComponent
Definition: IComponent.h:51
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...
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)
Class for quaternions.
Definition: Quat.h:39
Class for 3D vectors.
Definition: V3D.h:34
void swap(MDLeanEvent< nd > &first, MDLeanEvent< nd > &second)
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
Definition: Parameter.h:195
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30
Generate a tableworkspace to store the calibration results.