You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
7.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectSystemAnchor.h"
  2. position3D::position3D(){
  3. x = y = z = lat = lon = rot_z = rot_y = rot_z = speed = 0.f;
  4. utmZone = 0;
  5. };
  6. position3D::~position3D(){
  7. };
  8. void position3D::setPositionWGS84( C3D_FLOAT Lat, C3D_FLOAT Lon, C3D_FLOAT Alt ){
  9. coordConverter CC;
  10. lat = Lat;
  11. lon = Lon;
  12. z = Alt;
  13. #ifdef FLOAT_64
  14. double A, B;
  15. CC.LatLonToUTMXY( lat, lon, utmZone, A, B );
  16. x = A;
  17. y = B;
  18. #else
  19. CC.LatLonToUTMXY( lat, lon, utmZone, x, y );
  20. #endif
  21. };
  22. void position3D::setPositionXYZ( C3D_FLOAT X, C3D_FLOAT Y, C3D_FLOAT Z, int zone ){
  23. coordConverter CC;
  24. if( zone != 0 ) utmZone = zone;
  25. x = X;
  26. y = Y;
  27. z = Z;
  28. #ifdef FLOAT_64
  29. double A, B;
  30. CC.UTMXYToLatLon(x, y, utmZone, false, A, B);
  31. lat = A;
  32. lon = B;
  33. #else
  34. CC.UTMXYToLatLon(x, y, utmZone, false, lat, lon);
  35. #endif
  36. };
  37. void position3D::setOrientationRad( C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ ){
  38. rot_x = RotX;
  39. rot_y = RotY;
  40. rot_z = RotZ;
  41. };
  42. void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT RotZ){
  43. rot_x = deg2rad(RotX);
  44. rot_y = deg2rad(RotY);
  45. rot_z = deg2rad(RotZ);
  46. };
  47. void position3D::setSpeed( C3D_FLOAT Speed ){
  48. speed = Speed;
  49. };
  50. systemAnchor* systemAnchor::_instance = 0;
  51. /**
  52. * Returns the single instance of the object.
  53. */
  54. systemAnchor* systemAnchor::getInstance() {
  55. // check if the instance has been created yet
  56. if (0 == _instance) {
  57. // if not, then create it
  58. _instance = new systemAnchor;
  59. }
  60. // return the single instance
  61. return _instance;
  62. };
  63. systemAnchor::systemAnchor(){
  64. config_setting_t *pSetting;
  65. m_pSettings = NULL;
  66. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  67. if( pSetting != NULL ){
  68. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  69. };
  70. // Read Config
  71. if( m_pSettings != NULL ){
  72. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT );
  73. if (pSetting == NULL){
  74. lat = 0.f;
  75. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  76. config_setting_set_float( pSetting, lat );
  77. basicSettingsProvider::getInstance()->compromise();
  78. } else {
  79. lat = (float)config_setting_get_float(pSetting);
  80. };
  81. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON );
  82. if (pSetting == NULL){
  83. lon = 0.f;
  84. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  85. config_setting_set_float( pSetting, lon );
  86. basicSettingsProvider::getInstance()->compromise();
  87. } else {
  88. lon = config_setting_get_float(pSetting);
  89. };
  90. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT );
  91. if (pSetting == NULL){
  92. z = 0.f;
  93. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  94. config_setting_set_float( pSetting, z );
  95. basicSettingsProvider::getInstance()->compromise();
  96. } else {
  97. z = config_setting_get_float(pSetting);
  98. };
  99. /* No need to set Anchore Orientation
  100. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL );
  101. if (pSetting == NULL){
  102. rot_y = 0.f;
  103. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT );
  104. config_setting_set_float(pSetting, rot_y);
  105. basicSettingsProvider::getInstance()->compromise();
  106. } else {
  107. rot_y = config_setting_get_float(pSetting);
  108. };
  109. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH );
  110. if (pSetting == NULL){
  111. rot_x = 0.f;
  112. pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT );
  113. config_setting_set_float(pSetting, rot_x);
  114. basicSettingsProvider::getInstance()->compromise();
  115. } else {
  116. rot_x = config_setting_get_float(pSetting);
  117. };
  118. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW );
  119. if (pSetting == NULL){
  120. rot_z = 0.f;
  121. pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT );
  122. config_setting_set_float(pSetting, rot_z);
  123. basicSettingsProvider::getInstance()->compromise();
  124. } else {
  125. rot_z = config_setting_get_float(pSetting);
  126. };
  127. */
  128. coordConverter CC;
  129. #ifdef FLOAT_64
  130. double A, B;
  131. utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B );
  132. x = A;
  133. y = B;
  134. #else
  135. utmZone = CC.LatLonToUTMXY(lat, lon, 0, x, y);
  136. #endif
  137. basicSettingsProvider::getInstance()->validate();
  138. };
  139. };
  140. systemAnchor::~systemAnchor(){
  141. config_setting_t *pSetting;
  142. C3D_FLOAT tVal;
  143. m_pSettings = NULL;
  144. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  145. if( pSetting != NULL ){
  146. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  147. };
  148. // Read Config
  149. if( m_pSettings != NULL ){
  150. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  151. if (pSetting == NULL){
  152. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  153. config_setting_set_float(pSetting, lat );
  154. basicSettingsProvider::getInstance()->compromise();
  155. } else {
  156. tVal = config_setting_get_float(pSetting);
  157. if( lat != tVal ){
  158. config_setting_set_float(pSetting, lat );
  159. basicSettingsProvider::getInstance()->compromise();
  160. };
  161. };
  162. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  163. if (pSetting == NULL){
  164. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  165. config_setting_set_float(pSetting, lon );
  166. basicSettingsProvider::getInstance()->compromise();
  167. } else {
  168. tVal = config_setting_get_float(pSetting);
  169. if( lon != tVal ){
  170. config_setting_set_float(pSetting, lon );
  171. basicSettingsProvider::getInstance()->compromise();
  172. };
  173. };
  174. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  175. if (pSetting == NULL){
  176. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  177. config_setting_set_float(pSetting, z );
  178. basicSettingsProvider::getInstance()->compromise();
  179. } else {
  180. tVal = config_setting_get_float(pSetting);
  181. if( z != tVal ){
  182. config_setting_set_float(pSetting, z );
  183. basicSettingsProvider::getInstance()->compromise();
  184. };
  185. };
  186. /*
  187. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
  188. if (pSetting == NULL){
  189. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT );
  190. config_setting_set_float(pSetting, rot_y );
  191. basicSettingsProvider::getInstance()->compromise();
  192. } else {
  193. tVal = config_setting_get_float(pSetting);
  194. if (rot_y != tVal){
  195. config_setting_set_float(pSetting, rot_y);
  196. basicSettingsProvider::getInstance()->compromise();
  197. };
  198. };
  199. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
  200. if (pSetting == NULL){
  201. pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT );
  202. config_setting_set_float(pSetting, rot_x);
  203. basicSettingsProvider::getInstance()->compromise();
  204. } else {
  205. tVal = config_setting_get_float(pSetting);
  206. if (rot_x != tVal){
  207. config_setting_set_float(pSetting, rot_x);
  208. basicSettingsProvider::getInstance()->compromise();
  209. };
  210. };
  211. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
  212. if (pSetting == NULL){
  213. pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT );
  214. config_setting_set_float(pSetting, rot_z);
  215. basicSettingsProvider::getInstance()->compromise();
  216. } else {
  217. tVal = config_setting_get_float(pSetting);
  218. if (rot_z != tVal){
  219. config_setting_set_float(pSetting, rot_z);
  220. basicSettingsProvider::getInstance()->compromise();
  221. };
  222. };
  223. */
  224. basicSettingsProvider::getInstance()->validate();
  225. };
  226. };