* do not remove dynamic devices when stopping the Diffractometer device.
[diffractometer.git] / src / TangoHKLAdapter.h
blob80349f56852001e1fedd6b6f04f7d2300bece09c
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_add_dynamic_attributes(size_t idx);
249 void pseudo_axes_remove_dynamic_attributes(size_t idx);
251 void pseudo_axes_init(size_t idx);
253 void pseudo_axes_create_and_start_devices(void);
255 void pseudo_axes_stop_and_remove_devices(void);
257 /**********************/
258 /* Dynamic attributes */
259 /**********************/
261 void create_axes_dynamic_attributes(void);
263 void add_dynamic_attributes_to_device(void);
265 void delete_dynamic_attributes(void);
267 Matrix<char *> const & get_dynamic_attribute_axes_names(void) const {return _dynamic_attribute_axes_names;}
269 protected :
271 omni_mutex _lock;
272 HklDiffractometer *_diffractometer;
273 std::vector<AxisAdapter> _axes;
274 std::vector<PseudoAxisAdapter *> _pseudoAxisAdapters;
275 std::vector<PseudoAxesAdapter *> _pseudoAxesAdapters;
276 HKLBuffer _hklBuffer;
277 Tango::Group *_proxies;
278 Tango::AttributeProxy *_lambdaAttributeProxy;
279 bool _wrong_nb_of_axis_proxies;
281 void update_lambda(void);
283 void update_angles(void);
285 void update_reflections_angles(void);
287 void update_sample_reflections(void);
289 void update_ub(void);
291 void update_ux_uy_uz(void);
293 void update_mode_names(void);
295 void update_mode_parameters_names(void);
297 void update_axis_adapters(void);
299 void update_HKLBuffer_from_hkl(void);
301 void update_pseudo_axis_adapters_from_hkl(void);
303 void update_pseudo_axes_adapters_from_hkl(void);
305 void update_hkl_from_axis_adapters(void);
307 void update_proxies_from_axis_adapters(void);
309 void update_proxies_from_pseudo_axis_adapters(PseudoAxisAdapter *adapter);
311 void update_state_and_status(void);
313 void load_1(void);
315 /* axis part */
316 void write_axis_i(AxisAdapter & axis, double value);
318 private :
320 Diffractometer *_device;
321 std::string _status;
322 Tango::DevState _state;
323 HklGeometryType _type;
324 Duration duration;
325 double _lambda;
326 Matrix<double> _angles;
327 Matrix<char *> _mode_names;
328 Matrix<char *> _mode_parameters_names;
329 Matrix<char *> _pseudo_axes_proxies;
330 short _angles_idx;
332 // sample part
333 Matrix<double> _reflections_angles;
334 Matrix<double> _sample_reflections;
335 Matrix<double> _ub;
336 double _ux;
337 double _uy;
338 double _uz;
340 // dynamic attributes part
341 std::vector<Tango::Attr *> _dynamic_attribute_axes;
342 Matrix<char *> _dynamic_attribute_axes_names;
346 // given the state compute the new state using the axe state.
347 extern void compose_state(Tango::DevState & state, Tango::DevState const & axe_state);
349 #endif// _TangoHKLAdapter_H