OpenIndy-Core  0.2.0.43
function.h
Go to the documentation of this file.
1 #ifndef FUNCTION_H
2 #define FUNCTION_H
3 
4 #include <QMap>
5 #include <QMultiMap>
6 #include <QStringList>
7 #include <QtXml>
8 #include <QObject>
9 #include <QPointer>
10 
11 #include "point.h"
12 #include "line.h"
13 #include "plane.h"
14 #include "sphere.h"
15 #include "circle.h"
16 #include "cone.h"
17 #include "cylinder.h"
18 #include "ellipsoid.h"
19 #include "hyperboloid.h"
20 #include "nurbs.h"
21 #include "paraboloid.h"
22 #include "pointcloud.h"
23 #include "station.h"
24 #include "coordinatesystem.h"
25 #include "trafoparam.h"
26 #include "observation.h"
27 #include "statistic.h"
28 #include "scalarentitydistance.h"
29 #include "scalarentityangle.h"
32 #include "reading.h"
33 #include "slottedhole.h"
34 #include "torus.h"
35 #include "ellipse.h"
36 #include "pluginmetadata.h"
37 #include "featurewrapper.h"
38 #include "types.h"
39 #include "util.h"
40 
41 namespace oi{
42 
43 //############################################
44 //helper classes to define function parameters
45 //############################################
46 
52 public:
53  ElementTypes typeOfElement; //type of the needed input element
54  QString description; //optional description for the needed element to show in the GUI
55  bool infinite; //only one element or as many elements as one wants?
56 };
57 
63 public:
64  InputElement() : isUsed(true), shouldBeUsed(true), id(-1){}
65  InputElement(const int &id) : isUsed(true), shouldBeUsed(true), id(id){}
66 
68  bool operator==(const InputElement &other){
69  if(this->id == other.id){
70  return true;
71  }
72  return false;
73  }
74 
75  int id; //the id of the element
76  ElementTypes typeOfElement; //the type of the element
77 
78  //single parameters of this element that shall not be used in function calculation
79  //e.g. ignore the radius of an input sphere
80  QList<GeometryParameters> ignoredDestinationParams;
81 
82  //single parameters of the feature to be calculated that this element shall not have effect on
83  //e.g. use a point only for a circle's plane, not the radius
84  QList<GeometryParameters> ignoredTargetParams;
85 
86  bool shouldBeUsed; //true if this element should be used in function calculation (user specified)
87  bool isUsed; //true if this element is used in function calculation (plugin specified)
88 
89  //element pointers (only valid for the specified element type)
90  QPointer<Station> station;
91  QPointer<CoordinateSystem> coordSystem;
92  QPointer<TrafoParam> trafoParam;
93 
94  QPointer<Circle> circle;
95  QPointer<Cone> cone;
96  QPointer<Cylinder> cylinder;
97  QPointer<Ellipse> ellipse;
98  QPointer<Ellipsoid> ellipsoid;
99  QPointer<Hyperboloid> hyperboloid;
100  QPointer<Line> line;
101  QPointer<Nurbs> nurbs;
102  QPointer<Paraboloid> paraboloid;
103  QPointer<Plane> plane;
104  QPointer<Point> point;
105  QPointer<PointCloud> pointCloud;
106  QPointer<ScalarEntityAngle> scalarEntityAngle;
107  QPointer<ScalarEntityDistance> scalarEntityDistance;
108  QPointer<ScalarEntityMeasurementSeries> scalarEntityMeasurementSeries;
109  QPointer<ScalarEntityTemperature> scalarEntityTemperature;
110  QPointer<SlottedHole> slottedHole;
111  QPointer<Sphere> sphere;
112  QPointer<Torus> torus;
113 
114  QPointer<Geometry> geometry;
115 
116  QPointer<Observation> observation;
117  QPointer<Reading> polarReading;
118  QPointer<Reading> directionReading;
119  QPointer<Reading> distanceReading;
120  QPointer<Reading> cartesianReading;
121  QPointer<Reading> temperatureReading;
122  QPointer<Reading> levelReading;
123  QPointer<Reading> undefinedReading;
124 };
125 
131 public:
133  isValid = false;
134  }
135 
136  bool isValid;
137  QMap<QString, double> doubleParameter;
138  QMap<QString, int> intParameter;
139  QMap<QString, QString> stringParameter;
140 };
141 
147 public:
148  FixedParameter() : value(0.0){}
149  FixedParameter(const GeometryParameters &param) : value(0.0), parameter(param){}
150 
152  bool operator==(const FixedParameter &other){
153  if(this->parameter == other.parameter){
154  return true;
155  }
156  return false;
157  }
158 
160  double value;
161 };
162 
163 //#####################
164 //function class itself
165 //#####################
166 
170 class OI_CORE_EXPORT Function : public QObject
171 {
172  friend class Feature;
173  Q_OBJECT
174 
175 public:
176  Function(QObject *parent = 0);
177 
178  virtual ~Function();
179 
180  //##############################
181  //function initialization method
182  //##############################
183 
184  virtual void init();
185 
186  //###################################################################
187  //public exec method that calls the appropriate protected exec method
188  //###################################################################
189 
190  bool exec(const QPointer<FeatureWrapper> &feature);
191 
192  //#############################################################
193  //methods to get or set further information to solve a function
194  //#############################################################
195 
196  const QList<NeededElement> &getNeededElements() const;
197  const QList<FeatureTypes> &getApplicableFor() const;
198  const PluginMetaData &getMetaData() const;
199 
200  const QMap<QString, int> &getIntegerParameter() const;
201  const QMap<QString, double> &getDoubleParameter() const;
202  const QMultiMap<QString, QString> &getStringParameter() const;
203 
204  void setScalarInputParams(const ScalarInputParams &params);
205  const ScalarInputParams &getScalarInputParams();
206 
207  const QList<FixedParameter> &getFixedParameters() const;
208  void fixParameter(const FixedParameter &parameter);
209  void unfixParameter(const GeometryParameters &parameter);
210  void unfixAllParameters();
211 
212  //####################
213  //get function results
214  //####################
215 
216  const QStringList &getResultProtocol() const;
217 
218  const Statistic &getStatistic() const;
219 
220  //###############
221  //general getters
222  //###############
223 
224  const int &getId() const;
225 
226  //###################
227  //get or set elements
228  //###################
229 
230  const QMap<int, QList<InputElement> > &getInputElements() const;
231  InputElement getInputElement(const int &id) const;
232  InputElement getInputElement(const int &id, const int &position) const;
233  bool hasInputElement(const int &id) const;
234  void addInputElement(const InputElement &element, const int &position);
235  void removeInputElement(const int &id, const int &position);
236  void removeInputElement(const int &id);
237  void replaceInputElement(const InputElement &element, const int &position);
238 
239  //#################################
240  //mark elements as used or not used
241  //#################################
242 
243  bool getIsUsed(const int &position, const int &id);
244  bool getShouldBeUsed(const int &position, const int &id);
245  void setShouldBeUsed(const int &position, const int &id, const bool &state);
246 
247  //#############
248  //clear results
249  //#############
250 
251  virtual void clear();
252  virtual void clearResults();
253 
254  //#################
255  //save and load XML
256  //#################
257 
258  QDomElement toOpenIndyXML(QDomDocument &xmlDoc) const;
259  bool fromOpenIndyXML(QDomElement &xmlElem);
260 
261 signals:
262 
263  //################################################
264  //signals to inform OpenIndy about function issues
265  //################################################
266 
267  void sendMessage(const QString &msg, const MessageTypes &msgType, const MessageDestinations &msgDest = eConsoleMessage);
268 
269  void inputElementsChanged();
270  void scalarInputParametersChanged();
271 
272 protected:
273 
274  //############
275  //exec methods
276  //############
277 
278  virtual bool exec(Station &station);
279  virtual bool exec(CoordinateSystem &coordinateSystem);
280  virtual bool exec(TrafoParam &trafoParam);
281 
282  virtual bool exec(Circle &circle);
283  virtual bool exec(Cone &cone);
284  virtual bool exec(Cylinder &cylinder);
285  virtual bool exec(Ellipse &ellipse);
286  virtual bool exec(Ellipsoid &ellipsoid);
287  virtual bool exec(Hyperboloid &hyperboloid);
288  virtual bool exec(Line &line);
289  virtual bool exec(Nurbs &nurbs);
290  virtual bool exec(Paraboloid &paraboloid);
291  virtual bool exec(Plane &plane);
292  virtual bool exec(Point &point);
293  virtual bool exec(PointCloud &pointCloud);
294  virtual bool exec(ScalarEntityAngle &angle);
295  virtual bool exec(ScalarEntityDistance &distance);
296  virtual bool exec(ScalarEntityMeasurementSeries &measurementSeries);
297  virtual bool exec(ScalarEntityTemperature &temperature);
298  virtual bool exec(SlottedHole &slottedHole);
299  virtual bool exec(Sphere &sphere);
300  virtual bool exec(Torus &torus);
301 
302  //#################################
303  //mark elements as used or not used
304  //#################################
305 
306  void setIsUsed(const int &position, const int &id, const bool &state);
307 
308  //###########################
309  //input and output parameters
310  //###########################
311 
312  //meta information about the function (to tell OpenIndy what this function does)
313  QList<NeededElement> neededElements;
314  QList<FeatureTypes> applicableFor;
316 
317  //the needed scalar input parameters including default values
318  QMap<QString, int> integerParameters;
319  QMap<QString, double> doubleParameters;
320  QMultiMap<QString, QString> stringParameters;
321 
322  //user defined scalar input parameters
324 
325  //parameters of a geometry that should have a fixed value
326  QList<FixedParameter> fixedParameters;
327 
328  QStringList resultProtocol;
329 
330  //##################
331  //general attributes
332  //##################
333 
334  int id;
335 
337 
338  QMap<int, QList<InputElement> > inputElements;
339 
340 };
341 
342 }
343 
344 Q_DECLARE_METATYPE( oi::Function* )
345 
346 #ifndef STR
347 #define STR(x) #x
348 #endif
349 #ifndef STR2
350 #define STR2(x) STR(x)
351 #endif
352 
353 #ifndef CONCAT
354 #define CONCAT(a, b) a ## b
355 #endif
356 #ifndef CONCAT2
357 #define CONCAT2(a, b) CONCAT(a, b)
358 #endif
359 
360 #define FUNCTION_PREFIX de.openIndy.plugin.function.v
361 #define Function_iid STR2(CONCAT2(FUNCTION_PREFIX, PLUGIN_INTERFACE_VERSION))
362 
363 #endif // FUNCTION_H
Definition: pluginmetadata.h:10
QStringList resultProtocol
Definition: function.h:328
QPointer< SlottedHole > slottedHole
Definition: function.h:110
The Torus class Defines a torus of rotation.
Definition: torus.h:18
The Feature class.
Definition: feature.h:20
QPointer< ScalarEntityTemperature > scalarEntityTemperature
Definition: function.h:109
QPointer< Nurbs > nurbs
Definition: function.h:101
QPointer< Torus > torus
Definition: function.h:112
bool infinite
Definition: function.h:55
QPointer< ScalarEntityDistance > scalarEntityDistance
Definition: function.h:107
void init()
Definition: util.cpp:53
QPointer< Point > point
Definition: function.h:104
The Line class.
Definition: line.h:16
The ScalarEntityAngle class.
Definition: scalarentityangle.h:14
The TrafoParam class.
Definition: trafoparam.h:23
QMap< QString, double > doubleParameter
Definition: function.h:137
The ScalarEntityTemperature class.
Definition: scalarentitytemperature.h:14
PluginMetaData metaData
Definition: function.h:315
QPointer< CoordinateSystem > coordSystem
Definition: function.h:91
QPointer< Paraboloid > paraboloid
Definition: function.h:102
QList< FeatureTypes > applicableFor
Definition: function.h:314
The Cylinder class Defines a right circular cylinder.
Definition: cylinder.h:18
ElementTypes typeOfElement
Definition: function.h:53
Definition: coordinatesystem.h:15
bool isUsed
Definition: function.h:87
The Circle class.
Definition: circle.h:17
FixedParameter()
Definition: function.h:148
The InputElement class Save the input elements that are used to solve a function. ...
Definition: function.h:62
bool operator==(const InputElement &other)
custom comparison operator to compare input elements by their id
Definition: function.h:68
QPointer< ScalarEntityMeasurementSeries > scalarEntityMeasurementSeries
Definition: function.h:108
Definition: types.h:38
bool isValid
Definition: function.h:136
QMap< QString, int > intParameter
Definition: function.h:138
QPointer< Reading > distanceReading
Definition: function.h:119
ElementTypes typeOfElement
Definition: function.h:76
bool shouldBeUsed
Definition: function.h:86
FixedParameter(const GeometryParameters &param)
Definition: function.h:149
GeometryParameters parameter
Definition: function.h:159
MessageDestinations
used to specify where to print a message
Definition: types.h:37
The SlottedHole class Defines an elongated bore with one radius.
Definition: slottedhole.h:19
QList< FixedParameter > fixedParameters
Definition: function.h:326
ElementTypes
all OpenIndy element types
Definition: types.h:48
The Station class.
Definition: station.h:23
InputElement()
Definition: function.h:64
The EllipticParaboloid class Defines an elliptic paraboloid of rotation of the form z = x^2/a^2 + y^2...
Definition: paraboloid.h:17
int id
Definition: function.h:334
QList< NeededElement > neededElements
Definition: function.h:313
QPointer< PointCloud > pointCloud
Definition: function.h:105
QPointer< Cone > cone
Definition: function.h:95
The Statistic class.
Definition: statistic.h:29
QPointer< Sphere > sphere
Definition: function.h:111
MessageTypes
all types of messages
Definition: types.h:29
bool operator==(const FixedParameter &other)
custom comparison operator to compare fixed parameters
Definition: function.h:152
QMap< QString, QString > stringParameter
Definition: function.h:139
QPointer< Reading > undefinedReading
Definition: function.h:123
The Plane class.
Definition: plane.h:16
QList< GeometryParameters > ignoredTargetParams
Definition: function.h:84
The Function class.
Definition: function.h:170
The ScalarInputParams class Save user specified non-element scalar function input parameters...
Definition: function.h:130
QMap< QString, int > integerParameters
Definition: function.h:318
QPointer< Reading > levelReading
Definition: function.h:122
QPointer< Cylinder > cylinder
Definition: function.h:96
QPointer< Ellipse > ellipse
Definition: function.h:97
InputElement(const int &id)
Definition: function.h:65
QString description
Definition: function.h:54
The Cone class Defines a right circular cone.
Definition: cone.h:17
The Nurbs class.
Definition: nurbs.h:14
QPointer< ScalarEntityAngle > scalarEntityAngle
Definition: function.h:106
QPointer< Reading > temperatureReading
Definition: function.h:121
int id
Definition: function.h:75
QPointer< Line > line
Definition: function.h:100
QPointer< Observation > observation
Definition: function.h:116
The NeededElement class Save the needed element types that are necessary to solve a function...
Definition: function.h:51
The Ellipse class.
Definition: ellipse.h:17
The PointCloud class.
Definition: pointcloud.h:35
The CoordinateSystem class.
Definition: coordinatesystem.h:25
QPointer< Reading > cartesianReading
Definition: function.h:120
QPointer< Plane > plane
Definition: function.h:103
ScalarInputParams()
Definition: function.h:132
The ScalarEntityDistance class.
Definition: scalarentitydistance.h:14
The Sphere class.
Definition: sphere.h:17
Statistic statistic
Definition: function.h:336
QPointer< Geometry > geometry
Definition: function.h:114
The FixedParameter class Save a value for each parameter that shall be fixed.
Definition: function.h:146
ScalarInputParams scalarInputParams
Definition: function.h:323
The ScalarEntityMeasurementSeries class.
Definition: scalarentitymeasurementseries.h:14
GeometryParameters
Definition: types.h:159
QMultiMap< QString, QString > stringParameters
Definition: function.h:320
QPointer< Reading > directionReading
Definition: function.h:118
double value
Definition: function.h:160
QPointer< Circle > circle
Definition: function.h:94
QMap< QString, double > doubleParameters
Definition: function.h:319
The Ellipsoid class Defines an ellipsoid of rotation.
Definition: ellipsoid.h:17
#define OI_CORE_EXPORT
Definition: types.h:11
QPointer< Hyperboloid > hyperboloid
Definition: function.h:99
The Point class.
Definition: point.h:15
QList< GeometryParameters > ignoredDestinationParams
Definition: function.h:80
QPointer< Ellipsoid > ellipsoid
Definition: function.h:98
QPointer< TrafoParam > trafoParam
Definition: function.h:92
QPointer< Reading > polarReading
Definition: function.h:117
QPointer< Station > station
Definition: function.h:90
The Hyperboloid class Defines a single shell hyperboloid of rotation of the form 1 = x^2/a^2 + y^2/b^...
Definition: hyperboloid.h:17
QMap< int, QList< InputElement > > inputElements
Definition: function.h:338