itom  4.1.0
motorAxisController.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef MOTORAXISCONTROLLER_H
29 #define MOTORAXISCONTROLLER_H
30 
31 
32 #include "commonWidgets.h"
33 #include <qwidget.h>
34 #include <qstring.h>
35 #include <qpoint.h>
36 #include <qpointer.h>
37 #include <qcolor.h>
38 #include <qstringlist.h>
39 #include "common/retVal.h"
40 #include "common/interval.h"
41 
42 class ItomSharedSemaphore; //forward declaration
43 
44 class MotorAxisControllerPrivate; //forward declaration
45 
46 namespace ito {
47  class AddInActuator; //forward declaration
48 };
49 
50 class ITOMWIDGETS_EXPORT MotorAxisController : public QWidget
51 {
52  Q_OBJECT
53 
54  Q_PROPERTY(QPointer<ito::AddInActuator> actuator READ actuator WRITE setActuator)
55  Q_PROPERTY(int numAxis READ numAxis WRITE setNumAxis)
56  Q_PROPERTY(AxisUnit defaultAxisUnit READ defaultAxisUnit WRITE setDefaultAxisUnit)
57  Q_PROPERTY(AxisType defaultAxisType READ defaultAxisType WRITE setDefaultAxisType)
58  Q_PROPERTY(bool refreshAvailable READ refreshAvailable WRITE setRefreshAvailable)
59  Q_PROPERTY(bool cancelAvailable READ cancelAvailable WRITE setCancelAvailable)
60  Q_PROPERTY(bool startAllAvailable READ startAllAvailable WRITE setStartAllAvailable)
61  Q_PROPERTY(double defaultRelativeStepSize READ defaultRelativeStepSize WRITE setDefaultRelativeStepSize)
62  Q_PROPERTY(QStringList axisNames READ axisNames WRITE setAxisNames)
63  Q_PROPERTY(int defaultDecimals READ defaultDecimals WRITE setDefaultDecimals)
64  Q_PROPERTY(MovementType movementType READ movementType WRITE setMovementType)
65  Q_PROPERTY(bool movementTypeVisible READ movementTypeVisible WRITE setMovementTypeVisible)
66  Q_PROPERTY(QString arbitraryUnit READ arbitraryUnit WRITE setArbitraryUnit)
67  Q_PROPERTY(QColor backgroundColorMoving READ backgroundColorMoving WRITE setBackgroundColorMoving)
68  Q_PROPERTY(QColor backgroundColorInterrupted READ backgroundColorInterrupted WRITE setBackgroundColorInterrupted)
69  Q_PROPERTY(QColor backgroundColorTimeout READ backgroundColorTimeout WRITE setBackgroundColorTimeout)
70 
71  Q_CLASSINFO("prop://actuator", "Actuator instance that is monitored and controlled by this widget (or None in order to remove a previous actuator).")
72  Q_CLASSINFO("prop://numAxis", "Number of axes that are monitored.")
73  Q_CLASSINFO("prop://defaultAxisUnit", "Default unit for all axes. A different unit can be set for distinct axes using the slot 'setAxisUnit'.")
74  Q_CLASSINFO("prop://defaultAxisType", "Default type for all axes. A different type can be set for any axis using the slot 'setAxisType'.")
75  Q_CLASSINFO("prop://refreshAvailable", "Hide or show a button to manually refresh the positions of all covered axes.")
76  Q_CLASSINFO("prop://cancelAvailable", "Hide or show a button to cancel a running movement of any axis (should only be used, if the specific actuator is able to handle interrupts).")
77  Q_CLASSINFO("prop://startAllAvailable", "Hide or show a button to start a simultaneous movement of all covered axes to their current target positions.")
78  Q_CLASSINFO("prop://defaultRelativeStepSize", "Default relative step size for all axes (in mm or degree, depending on their types).")
79  Q_CLASSINFO("prop://axisNames", "Names of all axes as string list.")
80  Q_CLASSINFO("prop://defaultDecimals", "Default number of decimals of all axes. The number of decimals can also be set individually for each axis using the slot 'setAxisDecimals'.")
81  Q_CLASSINFO("prop://movementType", "Style of the widget depending if it should be optimized for an absolute movement, relative movement, both or no movement.")
82  Q_CLASSINFO("prop://movementTypeVisible", "Hide or show a combobox above the axes values that can be used to select an appropriate movement type.")
83  Q_CLASSINFO("prop://arbitraryUnit", "Unit name that is used for axes, whose unit is set to UnitAU (Arbitrary unit).")
84  Q_CLASSINFO("prop://backgroundColorMoving", "Background color for spinboxes of axes that are currently moving.")
85  Q_CLASSINFO("prop://backgroundColorInterrupted", "Background color for spinboxes of axes that were interrupted.")
86  Q_CLASSINFO("prop://backgroundColorTimeout", "Background color for spinboxes of axes that run into a timeout.")
87 
88 public:
89  enum AxisUnit {
90  UnitNm = 0,
91  UnitMum,
92  UnitMm,
93  UnitCm,
94  UnitM,
95  UnitDeg,
96  UnitAU /*Arbitrary unit*/
97  };
98 
99  enum AxisType {
100  TypeRotational = 0,
101  TypeLinear = 1
102  };
103 
104  enum MovementType {
105  MovementAbsolute = 0,
106  MovementRelative = 1,
107  MovementBoth = 2,
108  MovementNo = 3
109  };
110 
111  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
112  //values are always accessible.
113  Q_ENUM(AxisUnit);
114  Q_ENUM(AxisType);
115  Q_ENUM(MovementType);
116 
117  MotorAxisController(QWidget *parent = NULL);
119 
120  void setActuator(const QPointer<ito::AddInActuator> &actuator);
121  QPointer<ito::AddInActuator> actuator() const;
122 
123  int numAxis() const;
124  AxisUnit axisUnit(int axisIndex) const;
125  AxisUnit defaultAxisUnit() const;
126  AxisType axisType(int axisIndex) const;
127  AxisType defaultAxisType() const;
128  bool refreshAvailable() const;
129  bool cancelAvailable() const;
130  bool startAllAvailable() const;
131  double defaultRelativeStepSize() const;
132  QStringList axisNames() const;
133  QString axisName(int axisIndex) const;
134  int defaultDecimals() const;
135  int axisDecimals(int axisIndex) const;
136  MovementType movementType() const;
137  bool movementTypeVisible() const;
138  bool axisEnabled(int axisIndex) const;
139  QString arbitraryUnit() const;
140 
141  QColor backgroundColorMoving() const;
142  void setBackgroundColorMoving(const QColor &color);
143 
144  QColor backgroundColorInterrupted() const;
145  void setBackgroundColorInterrupted(const QColor &color);
146 
147  QColor backgroundColorTimeout() const;
148  void setBackgroundColorTimeout(const QColor &color);
149 
150 private:
151  void retValToMessageBox(const ito::RetVal &retval, const QString &methodName) const;
152  QString suffixFromAxisUnit(const AxisUnit &unit) const;
153  double baseUnitToUnit(const double &value, const AxisUnit &unit) const;
154  double unitToBaseUnit(const double &value, const AxisUnit &unit) const;
155  ito::RetVal observeInvocation(ItomSharedSemaphore *waitCond) const;
156  void moveRelOrAbs(int axis, double value, bool relNotAbs);
157 
159 
160 public slots:
161  virtual void actuatorStatusChanged(QVector<int> status, QVector<double> actPosition);
162  virtual void targetChanged(QVector<double> targetPositions);
163 
164  ito::RetVal setAxisUnit(int axisIndex, AxisUnit unit);
165  ito::RetVal setAxisEnabled(int axisIndex, bool enabled);
166  ito::RetVal setAxisDecimals(int axisIndex, int decimals);
167  ito::RetVal setAxisType(int axisIndex, AxisType type);
168  ito::RetVal setAxisName(int axisIndex, const QString &name);
169 
170  void setDefaultAxisUnit(AxisUnit unit);
171  void setMovementTypeVisible(bool visible);
172  void setMovementType(MovementType type);
173  void setDefaultDecimals(int decimals);
174  void setAxisNames(const QStringList &names);
175  void setDefaultRelativeStepSize(double defaultRelativeStepSize); /*in mm or degree*/
176  void setCancelAvailable(bool available);
177  void setStartAllAvailable(bool available);
178  void setRefreshAvailable(bool available);
179  void setDefaultAxisType(AxisType type);
180  void setNumAxis(int numAxis);
181  void setArbitraryUnit(const QString &unit);
182 
183  ito::AutoInterval stepSizeInterval(int axisIndex) const;
184  ito::AutoInterval targetInterval(int axisIndex) const;
185 
186  ito::RetVal setStepSizeInterval(int axisIndex, const ito::AutoInterval &interval);
187  ito::RetVal setTargetInterval(int axisIndex, const ito::AutoInterval &interval);
188 
189 
190 private slots:
191  void on_btnCancel_clicked();
192  void on_btnStart_clicked();
193  void on_btnRefresh_clicked();
194  void on_comboType_currentIndexChanged(int index);
195  void stepUpClicked(int index);
196  void stepDownClicked(int index);
197  void runSingleClicked(int index);
198  void customContextMenuRequested(const QPoint &pos);
199 };
200 
201 #endif
Class for managing status values (like errors or warning)
Definition: retVal.h:54
Definition: apiFunctionsGraph.cpp:39
Definition: motorAxisController.h:50
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
class for a interval type containing a min-max-range and an auto-flag.
Definition: interval.h:49
Definition: motorAxisController.cpp:47