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.

297 lines
9.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectSystemAnchor.h"
  2. systemAnchor* systemAnchor::_instance = 0;
  3. /**
  4. * Returns the single instance of the object.
  5. */
  6. systemAnchor* systemAnchor::getInstance() {
  7. // check if the instance has been created yet
  8. if (0 == _instance) {
  9. // if not, then create it
  10. _instance = new systemAnchor;
  11. }
  12. // return the single instance
  13. return _instance;
  14. };
  15. systemAnchor::systemAnchor(): m_SCC(){
  16. config_setting_t *pSetting;
  17. m_pSettings = NULL;
  18. m_bSouthHemisphere = 0;
  19. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  20. if( pSetting != NULL ){
  21. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  22. };
  23. // Read Config
  24. if( m_pSettings != NULL ){
  25. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT );
  26. if (pSetting == NULL){
  27. lat = 0.f;
  28. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  29. config_setting_set_float( pSetting, lat );
  30. basicSettingsProvider::getInstance()->compromise();
  31. } else {
  32. lat = (float)config_setting_get_float(pSetting);
  33. };
  34. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON );
  35. if (pSetting == NULL){
  36. lon = 0.f;
  37. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  38. config_setting_set_float( pSetting, lon );
  39. basicSettingsProvider::getInstance()->compromise();
  40. } else {
  41. lon = config_setting_get_float(pSetting);
  42. };
  43. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT );
  44. if (pSetting == NULL){
  45. z = 0.f;
  46. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  47. config_setting_set_float( pSetting, z );
  48. basicSettingsProvider::getInstance()->compromise();
  49. } else {
  50. z = config_setting_get_float(pSetting);
  51. };
  52. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
  53. if (pSetting == NULL){
  54. m_bSouthHemisphere = false;
  55. pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
  56. config_setting_set_bool(pSetting, m_bSouthHemisphere);
  57. basicSettingsProvider::getInstance()->compromise();
  58. } else {
  59. m_bSouthHemisphere = config_setting_get_bool(pSetting);
  60. };
  61. #ifdef FLOAT_64
  62. double A, B;
  63. utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B );
  64. x = A;
  65. y = B;
  66. #else
  67. utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y);
  68. #endif
  69. basicSettingsProvider::getInstance()->validate();
  70. };
  71. };
  72. systemAnchor::~systemAnchor(){
  73. config_setting_t *pSetting;
  74. C3D_FLOAT tVal;
  75. bool tBool;
  76. m_pSettings = NULL;
  77. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  78. if( pSetting != NULL ){
  79. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  80. };
  81. // Read Config
  82. if( m_pSettings != NULL ){
  83. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  84. if (pSetting == NULL){
  85. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  86. config_setting_set_float(pSetting, lat );
  87. basicSettingsProvider::getInstance()->compromise();
  88. } else {
  89. tVal = config_setting_get_float(pSetting);
  90. if( lat != tVal ){
  91. config_setting_set_float(pSetting, lat );
  92. basicSettingsProvider::getInstance()->compromise();
  93. };
  94. };
  95. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  96. if (pSetting == NULL){
  97. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  98. config_setting_set_float(pSetting, lon );
  99. basicSettingsProvider::getInstance()->compromise();
  100. } else {
  101. tVal = config_setting_get_float(pSetting);
  102. if( lon != tVal ){
  103. config_setting_set_float(pSetting, lon );
  104. basicSettingsProvider::getInstance()->compromise();
  105. };
  106. };
  107. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  108. if (pSetting == NULL){
  109. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  110. config_setting_set_float(pSetting, z );
  111. basicSettingsProvider::getInstance()->compromise();
  112. } else {
  113. tVal = config_setting_get_float(pSetting);
  114. if( z != tVal ){
  115. config_setting_set_float(pSetting, z );
  116. basicSettingsProvider::getInstance()->compromise();
  117. };
  118. };
  119. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
  120. if (pSetting == NULL){
  121. pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
  122. config_setting_set_bool(pSetting, m_bSouthHemisphere );
  123. basicSettingsProvider::getInstance()->compromise();
  124. } else {
  125. tBool = config_setting_get_bool(pSetting);
  126. if (m_bSouthHemisphere != tBool){
  127. config_setting_set_bool(pSetting, m_bSouthHemisphere );
  128. basicSettingsProvider::getInstance()->compromise();
  129. };
  130. };
  131. basicSettingsProvider::getInstance()->validate();
  132. };
  133. };
  134. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES& LOC) {
  135. if (SP == NULL) return false;
  136. transform_3* pTF = SP->getTransform();
  137. C3D_DECART tDec;
  138. vector_3 A, B;
  139. tDec.z = POS.alt;
  140. m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y);
  141. A[0] = tDec.x - SP->getX();
  142. A[1] = tDec.y - SP->getY();
  143. A[2] = tDec.z - SP->getZ();
  144. pTF->get_vector_local(A, B);
  145. tDec.x = B[0];
  146. tDec.y = B[1];
  147. tDec.z = B[2];
  148. decart2spherical(tDec, LOC);
  149. return true;
  150. };
  151. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS& LOC) {
  152. if (SP == NULL) return false;
  153. transform_3* pTF = SP->getTransform();
  154. C3D_DECART tDec;
  155. vector_3 A, B;
  156. tDec.z = POS.alt;
  157. m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y);
  158. A[0] = tDec.x - SP->getX();
  159. A[1] = tDec.y - SP->getY();
  160. A[2] = tDec.z - SP->getZ();
  161. pTF->get_vector_local(A, B);
  162. tDec.x = B[0];
  163. tDec.y = B[1];
  164. tDec.z = B[2];
  165. decart2spherical(tDec, LOC);
  166. return true;
  167. };
  168. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_DEGREES& LOC) {
  169. if (SP == NULL) return false;
  170. transform_3* pTF = SP->getTransform();
  171. C3D_DECART tDec;
  172. vector_3 A, B;
  173. // POS - is Relative to System Anchore!!
  174. A[0] = getX() + POS.x - SP->getX();
  175. A[1] = getY() + POS.y - SP->getY();
  176. A[2] = getZ() + POS.z - SP->getZ();
  177. pTF->get_vector_local(A, B);
  178. tDec.x = B[0];
  179. tDec.y = B[1];
  180. tDec.z = B[2];
  181. decart2spherical(tDec, LOC);
  182. return true;
  183. };
  184. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_RADIANS& LOC) {
  185. if (SP == NULL) return false;
  186. transform_3* pTF = SP->getTransform();
  187. C3D_DECART tDec;
  188. vector_3 A, B;
  189. // POS - is Relative to System Anchore!!
  190. A[0] = getX() + POS.x - SP->getX();
  191. A[1] = getY() + POS.y - SP->getY();
  192. A[2] = getZ() + POS.z - SP->getZ();
  193. pTF->get_vector_local(A, B);
  194. tDec.x = B[0];
  195. tDec.y = B[1];
  196. tDec.z = B[2];
  197. decart2spherical(tDec, LOC);
  198. return true;
  199. };
  200. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_WGS84_LOC POS, C3D_DECART& LOC) {
  201. C3D_DECART tDec;
  202. tDec.z = POS.alt;
  203. m_SCC.LatLonToUTMXY(POS.lat, POS.lon, this->getUTMZone(), tDec.x, tDec.y);
  204. LOC.x = tDec.x - getX();
  205. LOC.y = tDec.y - getX();
  206. LOC.z = tDec.z - getZ();
  207. return true;
  208. };
  209. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_DECART& LOC) {
  210. if (SP == NULL) return false;
  211. transform_3* pTF = SP->getTransform();
  212. C3D_DECART tDec;
  213. vector_3 A, B;
  214. spherical2decart(POS, tDec);
  215. A[0] = tDec.x;
  216. A[1] = tDec.y;
  217. A[2] = tDec.z;
  218. pTF->get_vector_world(A, B);
  219. LOC.x = SP->getX() + B[0] - getX();
  220. LOC.y = SP->getY() + B[1] - getY();
  221. LOC.z = SP->getZ() + B[2] - getZ();
  222. return true;
  223. };
  224. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_DECART& LOC) {
  225. if (SP == NULL) return false;
  226. transform_3* pTF = SP->getTransform();
  227. C3D_DECART tDec;
  228. vector_3 A, B;
  229. spherical2decart(POS, tDec);
  230. A[0] = tDec.x;
  231. A[1] = tDec.y;
  232. A[2] = tDec.z;
  233. pTF->get_vector_world(A, B);
  234. LOC.x = SP->getX() + B[0] - getX();
  235. LOC.y = SP->getY() + B[1] - getY();
  236. LOC.z = SP->getZ() + B[2] - getZ();
  237. return true;
  238. };
  239. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC& LOC) {
  240. if (SP == NULL) return false;
  241. transform_3* pTF = SP->getTransform();
  242. C3D_DECART tDec;
  243. vector_3 A, B;
  244. spherical2decart(POS, tDec);
  245. A[0] = tDec.x;
  246. A[1] = tDec.y;
  247. A[2] = tDec.z;
  248. pTF->get_vector_world(A, B);
  249. tDec.x = B[0] + SP->getX();
  250. tDec.y = B[1] + SP->getY();
  251. tDec.z = B[2] + SP->getZ();
  252. m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  253. LOC.alt = tDec.z;
  254. return true;
  255. };
  256. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC& LOC) {
  257. if (SP == NULL) return false;
  258. transform_3* pTF = SP->getTransform();
  259. C3D_DECART tDec;
  260. vector_3 A, B;
  261. spherical2decart(POS, tDec);
  262. A[0] = tDec.x;
  263. A[1] = tDec.y;
  264. A[2] = tDec.z;
  265. pTF->get_vector_world(A, B);
  266. tDec.x = B[0] + SP->getX();
  267. tDec.y = B[1] + SP->getY();
  268. tDec.z = B[2] + SP->getZ();
  269. m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  270. LOC.alt = tDec.z;
  271. return true;
  272. };
  273. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_DECART POS, C3D_WGS84_LOC& LOC) {
  274. C3D_DECART tDec;
  275. tDec.x = POS.x + getX();
  276. tDec.y = POS.y + getY();
  277. tDec.z = POS.z + getZ();
  278. m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  279. LOC.alt = tDec.z;
  280. return true;
  281. };