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/V2D.h"
13#include "MantidKernel/V3D.h"
14
15#include <string>
16#include <typeinfo>
17#include <vector>
18
19namespace Poco {
20namespace XML {
21class Attributes;
22class XMLWriter;
23} // namespace XML
24} // namespace Poco
25
26namespace Mantid {
27namespace Geometry {
28
29//----------------------------------------------------------------------
30// Forward declarations
31//----------------------------------------------------------------------
32template <typename T> class ComponentPool;
33
42class MANTID_GEOMETRY_DLL Component : public virtual IComponent {
43public:
45 virtual std::string typeName() const { return "Component"; }
46
48 Component(const IComponent *base, const ParameterMap *map);
49
51 Component();
53 explicit Component(std::string name, IComponent *parent = nullptr);
55 //(optional)
56 Component(std::string name, const Kernel::V3D &position, IComponent *parent = nullptr);
58 // component
59 Component(std::string name, const Kernel::V3D &position, const Kernel::Quat &rotation, IComponent *parent = nullptr);
60
61 IComponent *clone() const override;
62
64 ComponentID getComponentID() const override;
66 // or pointer to itself if not. Currently is the same as getComponentID bar
67 // const cast;
68 IComponent const *getBaseComponent() const override;
69
71 void setParent(IComponent *) override;
72
74 std::shared_ptr<const IComponent> getParent() const override;
76 std::vector<std::shared_ptr<const IComponent>> getAncestors() const override;
77
78 bool isParentNamed(const std::string &expectedName, int maxDepth = -1) const;
79
81 void setName(const std::string &) override;
82
84 std::string getName() const override;
85
87 std::string getFullName() const override;
88
90 // otherwise absolute
91 void setPos(double, double, double) override;
92 void setPos(const Kernel::V3D &) override;
93
95 void setSideBySideViewPos(const Kernel::V2D &) override;
96
98 // otherwise absolute
99 void setRot(const Kernel::Quat &) override;
100
102 // present.
103 void translate(const Kernel::V3D &) override;
104
106 // present.
107 void translate(double, double, double) override;
108
110 void rotate(const Kernel::Quat &) override;
111
113 void rotate(double, const Kernel::V3D &) override;
114
116 Kernel::V3D getRelativePos() const override;
117
119 // parent chain
120 Kernel::V3D getPos() const override;
121
122 std::optional<Kernel::V2D> getSideBySideViewPos() const override;
123
125 Kernel::Quat getRelativeRot() const override;
126
128 Kernel::Quat getRotation() const override;
129
131 double getDistance(const IComponent &) const override;
132
134 void getBoundingBox(BoundingBox &boundingBox) const override;
135
138 // 06/05/2010 MG: Templated virtual functions cannot be defined so we have to
139 // resort to
140 // one for each type, luckily there won't be too many
142 std::set<std::string> getParameterNames(bool recursive = true) const override;
144 std::map<std::string, ComponentID> getParameterNamesByComponent() const override;
146 bool hasParameter(const std::string &name, bool recursive = true) const override;
147
155 std::vector<double> getNumberParameter(const std::string &pname, bool recursive = true) const override {
156 return getParameter<double>(pname, recursive);
157 }
158
166 std::vector<int> getIntParameter(const std::string &pname, bool recursive = true) const override {
167 return getParameter<int>(pname, recursive);
168 }
169
179 std::string getParameterType(const std::string &pname, bool recursive = true) const override {
180 Parameter_sptr param;
181 if (recursive) {
182 param = m_map->getRecursive(this, pname);
183 } else {
184 param = m_map->get(this, pname);
185 }
186 if (param)
187 return std::string(param->type());
188 else
189 return std::string("");
190 }
193 std::string getDescription() const;
194
196 std::string getParamDescription(const std::string &pname, bool recursive = true) const;
197
199 std::string getParamShortDescription(const std::string &pname, bool recursive = true) const;
201 std::string getShortDescription() const;
203 void setDescription(const std::string &descr);
211 std::vector<bool> getBoolParameter(const std::string &pname, bool recursive = true) const override {
212 return getParameter<bool>(pname, recursive);
213 }
214
222 std::vector<Kernel::V3D> getPositionParameter(const std::string &pname, bool recursive = true) const override {
223 return getParameter<Kernel::V3D>(pname, recursive);
224 }
225
233 std::vector<Kernel::Quat> getRotationParameter(const std::string &pname, bool recursive = true) const override {
234 return getParameter<Kernel::Quat>(pname, recursive);
235 }
236
244 std::vector<std::string> getStringParameter(const std::string &pname, bool recursive = true) const override {
245 return getParameter<std::string>(pname, recursive);
246 }
248
249 std::string getParameterAsString(const std::string &pname, bool recursive = true) const override {
250 std::string retVal;
251 if (m_map) {
252 retVal = m_map->getString(this, pname, recursive);
253 }
254 return retVal;
255 }
256
264 bool getParameterVisible(const std::string &p_name, bool recursive) const override {
265 if (m_map) {
266 Parameter_sptr param;
267 if (recursive) {
268 param = m_map->getRecursive(this, p_name);
269 } else {
270 param = m_map->get(this, p_name);
271 }
272 if (param != Parameter_sptr()) {
273 return param->visible();
274 } else {
275 return false;
276 }
277 } else {
278 // Not parametrized = not visible by default
279 return false;
280 }
281 }
282
284 double getFittingParameter(const std::string &pname, double xvalue) const;
285
286 void printSelf(std::ostream &) const override;
287
289 const IComponent *base() const { return m_base; }
290
292 Kernel::V3D getScaleFactor() const override;
293
295 const IComponent *getBareParent() const override { return m_parent; }
296
297 virtual void readXMLAttributes(const Poco::XML::Attributes &attr);
298 virtual void writeXML(Poco::XML::XMLWriter &writer) const;
299 virtual void appendXML(std::ostream &xmlStream) const;
300
301 bool isParametrized() const override;
302
303 virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override;
304 bool hasComponentInfo() const;
305 size_t index() const;
306
307protected:
317
319 std::string m_name;
325 std::optional<Kernel::V2D> m_sidebysideviewpos;
326
335 template <class TYPE> std::vector<TYPE> getParameter(const std::string &p_name, bool recursive) const {
336 if (m_map) {
337 Parameter_sptr param;
338 if (recursive) {
339 param = m_map->getRecursive(this, p_name);
340 } else {
341 param = m_map->get(this, p_name);
342 }
343 if (param != Parameter_sptr()) {
344 return std::vector<TYPE>(1, param->value<TYPE>());
345 } else {
346 return std::vector<TYPE>(0);
347 }
348 } else {
349 // Not parametrized = return empty vector
350 return std::vector<TYPE>(0);
351 }
352 }
353
354protected:
355 // This method is only required for efficient caching of parameterized
356 // components and
357 // should not form part of the interface. It is an implementation detail.
358 template <typename T> friend class ComponentPool;
361 void swap(const Component *base, const ParameterMap *pmap);
362};
363
364} // namespace Geometry
365} // namespace Mantid
std::string name
Definition Run.cpp:60
double position
Definition GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
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:33
ComponentVisitor : Visitor for IComponents.
Component is a wrapper for a Component which can modify some of its parameters, e....
Definition Component.h:42
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
Definition Component.h:316
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:264
virtual std::string typeName() const
Definition Component.h:45
const IComponent * getBareParent() const override
Returns the bare pointer to the IComponent parent.
Definition Component.h:295
std::vector< double > getNumberParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a double.
Definition Component.h:155
std::optional< Kernel::V2D > m_sidebysideviewpos
Position of component in instrument viewer side by side view.
Definition Component.h:325
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:233
std::string m_name
Name of the component.
Definition Component.h:319
Kernel::V3D m_pos
Position w.
Definition Component.h:321
std::string getParameterAsString(const std::string &pname, bool recursive=true) const override
get a string representation of a parameter
Definition Component.h:249
std::vector< int > getIntParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as an int.
Definition Component.h:166
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:222
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:179
const IComponent * base() const
Returns the address of the base component.
Definition Component.h:289
const IComponent * m_parent
Parent component in the tree.
Definition Component.h:309
Kernel::Quat m_rot
Orientation.
Definition Component.h:323
const Component * m_base
The base component - this is the unmodified component (without the parameters).
Definition Component.h:314
std::vector< std::string > getStringParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a string.
Definition Component.h:244
std::vector< bool > getBoolParameter(const std::string &pname, bool recursive=true) const override
Get a parameter defined as a bool.
Definition Component.h:211
std::vector< TYPE > getParameter(const std::string &p_name, bool recursive) const
Get a parameter from the parameter map.
Definition Component.h:335
base class for Geometric IComponent
Definition IComponent.h:53
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
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition V2D.h:29
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:194
Helper class which provides the Collimation Length for SANS instruments.
Generate a tableworkspace to store the calibration results.