* new from/to_proxy for the AxisAdpater class
[diffractometer.git] / src / DiffractometerDeviceExtra.cpp
blob8a2093aa55ec8c66ae6a7c3e15a50c3cc0d1a251
1 #include "DiffractometerDevice.h"
2 #include "DynamicAttrAxis.h"
3 #include "macros.h"
5 namespace DiffractometerDevice_ns
7 void DiffractometerDevice::compute_angles(double h, double k ,double l)
9 DEBUG_STREAM << "DiffractometerDevice::compute_angles(): entering... !" << endl;
10 DEBUG_STREAM << " h : " << h
11 << " k : " << k
12 << " l : " << l << std::endl;
14 if (!_hklAdapter->simulated) {
15 this->set_state(Tango::MOVING);
16 this->set_status("DiffractometerDevice moving");
19 std::string status;
20 bool res = _hklAdapter->internal_compute_angles(h, k, l, status);
21 if(!res)
22 TANGO_EXCEPTION_THROW("Can not compute the hkl",
23 status.c_str());
26 void DiffractometerDevice::refresh_crystal_parameters()
28 DEBUG_STREAM << "DiffractometerDevice::refresh_crystal_parameters(): entering... !" << endl;
30 // Refresh Values
31 if(_hklAdapter)
32 _hklAdapter->get_sample_lattices(attr_A_read, attr_B_read, attr_C_read,
33 attr_Alpha_read, attr_Beta_read, attr_Gamma_read,
34 attr_AStar_read, attr_BStar_read, attr_CStar_read,
35 attr_AlphaStar_read, attr_BetaStar_read, attr_GammaStar_read);
38 HklGeometryType DiffractometerDevice::get_type_from_property(std::string const & name)
40 HklGeometryType type;
42 if (!strcasecmp(name.c_str(), "2CV"))
43 type = HKL_GEOMETRY_TWOC_VERTICAL;
44 else if (!strcasecmp(name.c_str(), "E4CV"))
45 type = HKL_GEOMETRY_EULERIAN4C_VERTICAL;
46 else if (!strcasecmp(name.c_str(), "K4CV"))
47 type = HKL_GEOMETRY_KAPPA4C_VERTICAL;
48 else if (!strcasecmp(name.c_str(), "K6C"))
49 type = HKL_GEOMETRY_KAPPA6C;
50 else if (!strcasecmp(name.c_str(), "E6C"))
51 type = HKL_GEOMETRY_EULERIAN6C;
52 else
53 type = HKL_GEOMETRY_EULERIAN4C_VERTICAL;
55 return type;
58 void DiffractometerDevice::create_dynamic_attributes(void)
60 if(_hklAdapter){
61 size_t i;
62 size_t n;
63 const std::vector<AxisAdapter> & axes = _hklAdapter->get_axes();
64 n = axes.size();
65 _dynamic_axes_names_char = (char **)malloc(n * sizeof(char *));
66 for(i=0; i<n; ++i){
67 std::string name;
68 AxisAttrib *att;
70 // compute the axis name
71 name = "axis";
72 name += axes[i].get_name();
73 name[4] = toupper(name[4]);
75 // create the AxisAttribut
76 att = new AxisAttrib(name.c_str(), _hklAdapter, i);
77 this->add_attribute(att);
78 _dynamic_attributes.push_back(att);
79 _dynamic_axes_names.push_back(name);
80 _dynamic_axes_names_char[i] = const_cast<char *>(_dynamic_axes_names[i].c_str());
85 void DiffractometerDevice::remove_dynamic_attributes(void)
87 for(unsigned int i=0;i<_dynamic_attributes.size(); ++i)
88 this->remove_attribute(_dynamic_attributes[i], true);
89 _dynamic_attributes.clear();
90 _dynamic_axes_names.clear();
91 if(_dynamic_axes_names_char){
92 free(_dynamic_axes_names_char);
93 _dynamic_axes_names_char = NULL;
97 void DiffractometerDevice::write_attributes_3(const Tango::AttributeValueList& values) throw (CORBA::SystemException, Tango::DevFailed, Tango::MultiDevFailed)
99 DEBUG_STREAM << "DiffractometerDevice::write_attributes_3: entering... !" << std::endl;
100 // TODO check if it's really H,K and L
101 // If we received 2 or 3 values , assume they are h,k,l
103 std::string error = "DiffractometerDevice::write_attributes_3:";
104 for (unsigned int i = 0; i < values.length(); i++) {
105 error += " ";
106 error += values[i].name;
108 DEBUG_STREAM << error << std::endl;
110 if (values.length() == 3 || values.length() == 2) {
111 double h = attr_H_write;
112 double k = attr_K_write;
113 double l = attr_L_write;
116 // set flag value to avoid direct write on hardware of each single attribute
117 _write_attributes_hkl_together = true;
119 // Initialise defaut h,k,l setpoint values
120 attr_H_write = *attr_H_read;
121 attr_K_write = *attr_K_read;
122 attr_L_write = *attr_L_read;
123 // do standard treatement to set the hkl coordinates from the user.
124 Device_3Impl::write_attributes_3(values);
125 // do the final hkl, write with values which have been stored in xCoordinate_temp members
126 this->compute_angles(attr_H_write, attr_K_write, attr_L_write);
128 // reset flag
129 _write_attributes_hkl_together = false;
131 catch (Tango::DevFailed &)
133 // restore write part
134 attr_H_write = h;
135 attr_K_write = k;
136 attr_L_write = l;
137 // reset flag
138 _write_attributes_hkl_together = false;
140 } else {
141 //standard case i.e only 1 attribute
142 Device_3Impl::write_attributes_3(values);
145 } // namespace_ns