Newer
Older
Gigg, Martyn Anthony
committed
#ifndef MANTID_GEOMETRY_ICOMPONENT_H_
#define MANTID_GEOMETRY_ICOMPONENT_H_
Gigg, Martyn Anthony
committed
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Objects/BoundingBox.h"
Gigg, Martyn Anthony
committed
#include "MantidKernel/V3D.h"
Federico Montesino Pouzols
committed
#include <map>
Gigg, Martyn Anthony
committed
#include <vector>
Gigg, Martyn Anthony
committed
#include <set>
Federico Montesino Pouzols
committed
#ifndef Q_MOC_RUN
Roman Tolchenov
committed
Federico Montesino Pouzols
committed
namespace Kernel {
class Quat;
}
namespace Geometry {
class IComponent;
class ParameterMap;
/// Define a type for a unique component identifier.
using ComponentID = IComponent *;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** @class IComponent
@brief base class for Geometric IComponent
@version A
@author Laurent C Chapon, ISIS RAL
@date 01/11/2007
This is the base class for geometric components.
Geometric IComponent can be placed in a hierarchical
structure and are defined with respect to a
parent IComponent. The IComponent position and orientation
are relatives, i.e. defined with respect to the parent
IComponent. The orientation is stored as a Kernel::Quaternion.
Each IComponent has a defined bounding box which at the moment
is cuboid.
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_GEOMETRY_DLL IComponent {
public:
/// Returns a string representation of the IComponent type
virtual std::string type() const { return "LogicalComponent"; }
//! Return a clone to the current object
virtual IComponent *clone() const = 0;
/// Destructor
virtual ~IComponent() = default;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Returns the ComponentID - a unique identifier of the component.
virtual ComponentID getComponentID() const = 0;
//! Returns const pointer to base component if this component is parametrized
// or pointer to itself if not. Currently is the same as getComponentID bar
// const cast;
virtual IComponent const *getBaseComponent() const = 0;
//! Assign a parent IComponent. Previous parent link is lost
virtual void setParent(IComponent *) = 0;
//! Return a pointer to the current parent.
virtual boost::shared_ptr<const IComponent> getParent() const = 0;
/** Returns the bare pointer to the IComponent parent */
virtual const IComponent *getBareParent() const = 0;
//! Return an array of all ancestors, the nearest first
virtual std::vector<boost::shared_ptr<const IComponent>>
getAncestors() const = 0;
//! Set the IComponent name
virtual void setName(const std::string &) = 0;
//! Get the IComponent name
virtual std::string getName() const = 0;
//! Get the IComponent full path name
virtual std::string getFullName() const = 0;
//! Set the IComponent position, x, y, z respective to parent (if present)
// otherwise absolute
virtual void setPos(double, double, double) = 0;
/** Set the position of the component
* The position is with respect to the parent component
*/
virtual void setPos(const Kernel::V3D &) = 0;
//! Set the orientation Kernel::Quaternion relative to parent (if present)
// otherwise absolute
virtual void setRot(const Kernel::Quat &) = 0;
//! Copy the Rotation from another IComponent
// virtual void copyRot(const IComponent&) = 0;
//! Translate the IComponent (vector form). This is relative to parent if
// present.
virtual void translate(const Kernel::V3D &) = 0;
//! Translate the IComponent (x,y,z form). This is relative to parent if
// present.
virtual void translate(double, double, double) = 0;
//! Rotate the IComponent. This is relative to parent.
virtual void rotate(const Kernel::Quat &) = 0;
//! Rotate the IComponent by an angle in degrees with respect to an axis.
virtual void rotate(double, const Kernel::V3D &) = 0;
//! Get the position relative to the parent IComponent (absolute if no parent)
virtual Kernel::V3D getRelativePos() const = 0;
//! Get the position of the IComponent. Tree structure is traverse through the
// parent chain
virtual Kernel::V3D getPos() const = 0;
//! Get the relative Orientation
virtual Kernel::Quat getRelativeRot() const = 0;
//! Get the absolute orientation of the IComponent
virtual Kernel::Quat getRotation() const = 0;
//! Get the distance to another IComponent
virtual double getDistance(const IComponent &) const = 0;
/// Get the bounding box for this component and store it in the given argument
virtual void getBoundingBox(BoundingBox &boundingBox) const = 0;
/** Gets the scaling factor of the object for the Object Component.
* @return a vector with 1 in all 3 directions.
Gigg, Martyn Anthony
committed
*/
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
virtual Kernel::V3D getScaleFactor() const {
return Kernel::V3D(1.0, 1.0, 1.0);
}
/** @name ParameterMap access */
//@{
/// 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
virtual std::string getParameterType(const std::string &pname,
bool recursive = true) const = 0;
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to
// resort to
// one for each type, luckily there won't be too many
/// Get a parameter defined as a double
virtual std::vector<double>
getNumberParameter(const std::string &pname, bool recursive = true) const = 0;
/// Get a parameter defined as a Kernel::V3D
virtual std::vector<Kernel::V3D>
getPositionParameter(const std::string &pname,
bool recursive = true) const = 0;
/// Get a parameter defined as a Kernel::Quaternion
virtual std::vector<Kernel::Quat>
getRotationParameter(const std::string &pname,
bool recursive = true) const = 0;
/// Get a parameter defined as a string
virtual std::vector<std::string>
getStringParameter(const std::string &pname, bool recursive = true) const = 0;
/// Get a parameter defined as an integer
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
*/
virtual void printSelf(std::ostream &) const = 0;
//! Returns true if the Component is parametrized (has a parameter map)
virtual bool isParametrized() const = 0;
virtual size_t registerContents(class ComponentVisitor &component) const = 0;
};
/// Typedef of a shared pointer to a IComponent
using IComponent_sptr = boost::shared_ptr<IComponent>;
/// Typdef of a shared pointer to a const IComponent
using IComponent_const_sptr = boost::shared_ptr<const IComponent>;
} // Namespace Geometry
/// An object for constructing a shared_ptr that won't ever delete its pointee
class NoDeleting {
public:
/// Does nothing
void operator()(void *) {}
/// Does nothing
void operator()(const void *) {}
};
} // Namespace Mantid
Gigg, Martyn Anthony
committed
#endif // MANTID_GEOMETRY_ICOMPONENT_H_