1 #include "DiffractometerDevice.h"
2 #include "DynamicAttrAxis.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
12 << " l : " << l
<< std::endl
;
14 if (!_hklAdapter
->simulated
) {
15 this->set_state(Tango::MOVING
);
16 this->set_status("DiffractometerDevice moving");
20 bool res
= _hklAdapter
->internal_compute_angles(h
, k
, l
, status
);
22 TANGO_EXCEPTION_THROW("Can not compute the hkl",
26 void DiffractometerDevice::refresh_crystal_parameters()
28 DEBUG_STREAM
<< "DiffractometerDevice::refresh_crystal_parameters(): entering... !" << endl
;
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
)
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
;
53 type
= HKL_GEOMETRY_EULERIAN4C_VERTICAL
;
58 void DiffractometerDevice::create_dynamic_attributes(void)
63 const std::vector
<AxisAdapter
> & axes
= _hklAdapter
->get_axes();
65 _dynamic_axes_names_char
= (char **)malloc(n
* sizeof(char *));
70 // compute the axis name
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
++) {
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
);
129 _write_attributes_hkl_together
= false;
131 catch (Tango::DevFailed
&)
133 // restore write part
138 _write_attributes_hkl_together
= false;
141 //standard case i.e only 1 attribute
142 Device_3Impl::write_attributes_3(values
);