* no more problem with the state and status #12690
[diffractometer.git] / src / TangoHKLAdapter.h
blobaf633462461f115c72dbe3286feeda4e56804a0f
1 #ifndef __TANGOHKLADAPTER_H__
2 #define __TANGOHKLADAPTER_H__
4 #include <map>
5 #include <vector>
6 #include <string>
7 #include <tango.h>
9 #include <Duration.h>
11 #include <hkl.h>
13 #include "AxisAdapter.h"
14 #include "PseudoAxisAdapter.h"
15 #include "PseudoAxesAdapter.h"
16 #include "Matrix.h"
18 #if ( _MSC_VER && _MSC_VER <= 1200 )
19 // Ce pragma ne devrait pas être dans ce fichier car le warning ne s'affiche
20 // que si l'on compile une version DEBUG de la librairie.
21 // Il faut utiliser l'option de compilation \wd4786 mais elle n'est présente
22 // qu'à partir de VC++7
23 # pragma warning (disable : 4786)
24 #endif
26 #define NO_SOFTWARE_LIMITS -999999
28 namespace Diffractometer_ns {
30 // forward declaration
31 class Diffractometer;
33 struct HklDiffractometer {
34 HklGeometry *geometry_r;
35 HklGeometry *geometry_w;
36 HklGeometry *geometry_r_real;
37 HklGeometry *geometry_w_real;
38 HklDetector detector;
39 HklDetector detector_real;
40 HklSampleList *samples;
41 HklPseudoAxisEngineList *engines_r;
42 HklPseudoAxisEngineList *engines_w;
43 HklPseudoAxisEngineList *engines_r_real;
44 HklPseudoAxisEngineList *engines_w_real;
47 struct HKLBuffer {
48 double h_r; // read part of position value
49 double h_w; // write part of position value
50 double k_r; // read part of position value
51 double k_w; // write part of position value
52 double l_r; // read part of position value
53 double l_w; // write part of position value
54 };
56 /**
58 * Class which associates a Diffractometer with the PseudoAxis
60 class TangoHKLAdapter
62 public :
63 bool simulated;
64 bool ready;
66 TangoHKLAdapter(Diffractometer *_device, HklGeometryType type);
68 virtual ~TangoHKLAdapter(void);
70 Diffractometer *get_device(void) {return _device;}
72 // Diffractometer Part
73 HklDiffractometer* & diffractometer(void) {return _diffractometer;}
75 HKLBuffer const & get_HKLBuffer(void) const {return _hklBuffer;}
77 Tango::DevState const & get_state(void) const {return _state;}
79 std::string const & get_status(void) const {return _status;}
81 bool internal_compute_angles(double h, double k,
82 double l, std::string & status);
84 void goto_reflection(short reflection_number);
86 void set_simulated(bool simulated);
88 void connect_all_proxies(void);
90 void update(void);
92 /**********/
93 /* source */
94 /**********/
96 double & get_lambda(void) {return _lambda;}
98 void set_lambda(double lambda);
100 /************/
101 /* hkl part */
102 /************/
104 Matrix<double> & get_angles(void) {omni_mutex_lock lock(_lock); return _angles;}
106 short & get_angles_idx(void);
108 void set_angles_idx(short idx);
110 void load(void);
112 void save(void);
114 /***************/
115 /* sample part */
116 /***************/
118 char const *get_sample_name(void);
120 void set_current_sample(char const * name);
122 void get_sample_lattices(double * a, double * b, double * c,
123 double * alpha, double * beta, double * gamma,
124 double * a_star, double * b_star, double * c_star,
125 double * alpha_star, double * beta_star, double * gamma_star);
127 Matrix<double> & get_sample_ub(void) {omni_mutex_lock lock(_lock); return _ub;}
129 double & get_sample_Ux(void) {return _ux;}
131 void set_sample_Ux(double ux);
133 double & get_sample_Uy(void) {return _uy;}
135 void set_sample_Uy(double uy);
137 double & get_sample_Uz(void) {return _uz;}
139 void set_sample_Uz(double uz);
141 void add_new_sample(std::string const & name);
143 void copy_sample_as(Tango::DevString copy_name);
145 void del_sample(void);
147 void set_lattice(const Tango::DevVarDoubleArray *argin);
149 void add_reflection(void);
151 void del_reflection(Tango::DevShort argin);
153 // to remove in favour of get_sample_reflections
154 void get_sample_reflection(int idx, Tango::DevVarDoubleArray *argout);
156 // to remove in favour of set_sample_reflections
157 void set_sample_reflection(const Tango::DevVarDoubleArray *argin);
159 Matrix<double> & get_sample_reflections(void) {omni_mutex_lock lock(_lock); return _sample_reflections;}
161 void set_sample_reflections(Matrix<double> const & img);
163 double affine_sample(std::string name);
165 std::vector<std::string> get_samples_names(void);
167 void get_sample_parameter_values(Tango::DevVarDoubleStringArray *argout);
169 void set_sample_parameter_values(Tango::DevVarDoubleStringArray const *argin);
171 void compute_u(const Tango::DevVarLongArray *argin);
173 Matrix<double> & get_reflections_angles(void) {omni_mutex_lock lock(_lock); return _reflections_angles;}
175 /*****************/
176 /* hkl mode part */
177 /*****************/
179 char const *read_mode(void);
181 void write_mode(Tango::DevString argin);
183 Matrix<char *> & get_mode_names(void) {omni_mutex_lock lock(_lock); return _mode_names;}
185 Matrix<char *> & get_mode_parameters_names(void){omni_mutex_lock lock(_lock); return _mode_parameters_names;}
187 void get_mode_parameters_values(Tango::DevVarDoubleStringArray *argout);
189 void set_mode_parameters_values(const Tango::DevVarDoubleStringArray *argin);
191 /*************/
192 /* axes part */
193 /*************/
195 const std::vector<AxisAdapter> & get_axes(void) const {return _axes;}
197 std::vector<AxisAdapter> & get_axes(void) {return _axes;}
199 void read_axis(int idx, double & read, double & write);
201 void write_axis(AxisAdapter & adapter, double value);
203 void stop_all_axis(void);
205 /*******************/
206 /* PseudoAxis Part */
207 /*******************/
209 std::vector<std::string> pseudo_axis_get_names(void);
211 void pseudo_axis_init(PseudoAxisAdapter *buffer, bool init);
213 PseudoAxisAdapter *pseudo_axis_buffer_new(char const *name);
215 void pseudo_axis_write(PseudoAxisAdapter *buffer, double value);
217 Tango::DevString *pseudo_axis_get_mode(PseudoAxisAdapter const *buffer);
219 void pseudo_axis_set_mode(PseudoAxisAdapter *buffer, Tango::DevString const & mode);
221 void pseudo_axis_get_mode_parameters(PseudoAxisAdapter *buffer, Tango::DevVarDoubleStringArray *argout);
223 void pseudo_axis_set_mode_parameters(PseudoAxisAdapter *buffer, const Tango::DevVarDoubleStringArray *argin);
225 /*******************/
226 /* PseudoAxes Part */
227 /*******************/
229 std::vector<PseudoAxesAdapter *> & pseudo_axes(void) {return _pseudoAxesAdapters;}
231 PseudoAxesAdapter *pseudo_axes_adapter_get_by_name(std::string const & name);
233 Matrix<char *> const & get_pseudo_axes_proxies(void) {omni_mutex_lock lock(_lock); return _pseudo_axes_proxies;}
235 void pseudo_axes_write(size_t idx, Matrix<double> const & write);
237 Tango::DevString *pseudo_axes_get_mode(size_t idx);
239 void pseudo_axes_set_mode(size_t idx, const Tango::DevString name);
241 Matrix<char *> & pseudo_axes_get_mode_parameters_names(size_t idx);
243 Matrix<double> const & pseudo_axes_get_mode_parameters(size_t idx);
245 void pseudo_axes_set_mode_parameters(size_t idx, Matrix<double> const & values);
247 void pseudo_axes_init(size_t idx);
249 void pseudo_axes_create_and_start_devices(void);
251 void pseudo_axes_stop_and_remove_devices(void);
253 /**********************/
254 /* Dynamic attributes */
255 /**********************/
257 void create_axes_dynamic_attributes(void);
259 void add_dynamic_attributes_to_device(void);
261 void delete_dynamic_attributes(void);
263 Matrix<char *> const & get_dynamic_attribute_axes_names(void) const {return _dynamic_attribute_axes_names;}
265 protected :
267 omni_mutex _lock;
268 HklDiffractometer *_diffractometer;
269 std::vector<AxisAdapter> _axes;
270 std::vector<PseudoAxisAdapter *> _pseudoAxisAdapters;
271 std::vector<PseudoAxesAdapter *> _pseudoAxesAdapters;
272 HKLBuffer _hklBuffer;
273 Tango::Group *_proxies;
274 Tango::AttributeProxy *_lambdaAttributeProxy;
275 bool _wrong_nb_of_axis_proxies;
277 void update_lambda(void);
279 void update_angles(void);
281 void update_reflections_angles(void);
283 void update_sample_reflections(void);
285 void update_ub(void);
287 void update_ux_uy_uz(void);
289 void update_mode_names(void);
291 void update_mode_parameters_names(void);
293 void update_axis_adapters(void);
295 void update_HKLBuffer_from_hkl(void);
297 void update_pseudo_axis_adapters_from_hkl(void);
299 void update_pseudo_axes_adapters_from_hkl(void);
301 void update_hkl_from_axis_adapters(void);
303 void update_proxies_from_axis_adapters(void);
305 void update_proxies_from_pseudo_axis_adapters(PseudoAxisAdapter *adapter);
307 void update_state_and_status(void);
309 void load_1(void);
311 /* axis part */
312 void write_axis_i(AxisAdapter & axis, double value);
314 private :
316 Diffractometer *_device;
317 std::string _status;
318 Tango::DevState _state;
319 HklGeometryType _type;
320 Duration duration;
321 double _lambda;
322 Matrix<double> _angles;
323 Matrix<char *> _mode_names;
324 Matrix<char *> _mode_parameters_names;
325 Matrix<char *> _pseudo_axes_proxies;
326 short _angles_idx;
328 // sample part
329 Matrix<double> _reflections_angles;
330 Matrix<double> _sample_reflections;
331 Matrix<double> _ub;
332 double _ux;
333 double _uy;
334 double _uz;
336 // dynamic attributes part
337 std::vector<Tango::Attr *> _dynamic_attribute_axes;
338 Matrix<char *> _dynamic_attribute_axes_names;
342 // given the state compute the new state using the axe state.
343 extern void compose_state(Tango::DevState & state, Tango::DevState const & axe_state);
345 #endif// _TangoHKLAdapter_H