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
297 lines
9.4 KiB
#include "objectSystemAnchor.h"
|
|
|
|
systemAnchor* systemAnchor::_instance = 0;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
systemAnchor* systemAnchor::getInstance() {
|
|
// check if the instance has been created yet
|
|
if (0 == _instance) {
|
|
// if not, then create it
|
|
_instance = new systemAnchor;
|
|
}
|
|
// return the single instance
|
|
return _instance;
|
|
};
|
|
|
|
systemAnchor::systemAnchor(): m_SCC(){
|
|
config_setting_t *pSetting;
|
|
m_pSettings = NULL;
|
|
m_bSouthHemisphere = 0;
|
|
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
|
|
if( pSetting != NULL ){
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
|
|
};
|
|
// Read Config
|
|
if( m_pSettings != NULL ){
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT );
|
|
if (pSetting == NULL){
|
|
lat = 0.f;
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float( pSetting, lat );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
lat = (float)config_setting_get_float(pSetting);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON );
|
|
if (pSetting == NULL){
|
|
lon = 0.f;
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float( pSetting, lon );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
lon = config_setting_get_float(pSetting);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT );
|
|
if (pSetting == NULL){
|
|
z = 0.f;
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float( pSetting, z );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
z = config_setting_get_float(pSetting);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
|
|
if (pSetting == NULL){
|
|
m_bSouthHemisphere = false;
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
|
|
config_setting_set_bool(pSetting, m_bSouthHemisphere);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
m_bSouthHemisphere = config_setting_get_bool(pSetting);
|
|
};
|
|
#ifdef FLOAT_64
|
|
double A, B;
|
|
utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B );
|
|
x = A;
|
|
y = B;
|
|
#else
|
|
utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y);
|
|
#endif
|
|
basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
};
|
|
|
|
systemAnchor::~systemAnchor(){
|
|
config_setting_t *pSetting;
|
|
C3D_FLOAT tVal;
|
|
bool tBool;
|
|
|
|
m_pSettings = NULL;
|
|
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
|
|
if( pSetting != NULL ){
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
|
|
};
|
|
// Read Config
|
|
if( m_pSettings != NULL ){
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float(pSetting, lat );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
tVal = config_setting_get_float(pSetting);
|
|
if( lat != tVal ){
|
|
config_setting_set_float(pSetting, lat );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float(pSetting, lon );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
tVal = config_setting_get_float(pSetting);
|
|
if( lon != tVal ){
|
|
config_setting_set_float(pSetting, lon );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
|
|
config_setting_set_float(pSetting, z );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
tVal = config_setting_get_float(pSetting);
|
|
if( z != tVal ){
|
|
config_setting_set_float(pSetting, z );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
|
|
config_setting_set_bool(pSetting, m_bSouthHemisphere );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
} else {
|
|
tBool = config_setting_get_bool(pSetting);
|
|
if (m_bSouthHemisphere != tBool){
|
|
config_setting_set_bool(pSetting, m_bSouthHemisphere );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
|
|
};
|
|
|
|
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
tDec.z = POS.alt;
|
|
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y);
|
|
A[0] = tDec.x - SP->getX();
|
|
A[1] = tDec.y - SP->getY();
|
|
A[2] = tDec.z - SP->getZ();
|
|
pTF->get_vector_local(A, B);
|
|
tDec.x = B[0];
|
|
tDec.y = B[1];
|
|
tDec.z = B[2];
|
|
decart2spherical(tDec, LOC);
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
tDec.z = POS.alt;
|
|
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y);
|
|
A[0] = tDec.x - SP->getX();
|
|
A[1] = tDec.y - SP->getY();
|
|
A[2] = tDec.z - SP->getZ();
|
|
pTF->get_vector_local(A, B);
|
|
tDec.x = B[0];
|
|
tDec.y = B[1];
|
|
tDec.z = B[2];
|
|
decart2spherical(tDec, LOC);
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_DEGREES& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
// POS - is Relative to System Anchore!!
|
|
A[0] = getX() + POS.x - SP->getX();
|
|
A[1] = getY() + POS.y - SP->getY();
|
|
A[2] = getZ() + POS.z - SP->getZ();
|
|
pTF->get_vector_local(A, B);
|
|
tDec.x = B[0];
|
|
tDec.y = B[1];
|
|
tDec.z = B[2];
|
|
decart2spherical(tDec, LOC);
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_RADIANS& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
// POS - is Relative to System Anchore!!
|
|
A[0] = getX() + POS.x - SP->getX();
|
|
A[1] = getY() + POS.y - SP->getY();
|
|
A[2] = getZ() + POS.z - SP->getZ();
|
|
pTF->get_vector_local(A, B);
|
|
tDec.x = B[0];
|
|
tDec.y = B[1];
|
|
tDec.z = B[2];
|
|
decart2spherical(tDec, LOC);
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_WGS84_LOC POS, C3D_DECART& LOC) {
|
|
C3D_DECART tDec;
|
|
tDec.z = POS.alt;
|
|
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, this->getUTMZone(), tDec.x, tDec.y);
|
|
LOC.x = tDec.x - getX();
|
|
LOC.y = tDec.y - getX();
|
|
LOC.z = tDec.z - getZ();
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_DECART& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
spherical2decart(POS, tDec);
|
|
A[0] = tDec.x;
|
|
A[1] = tDec.y;
|
|
A[2] = tDec.z;
|
|
pTF->get_vector_world(A, B);
|
|
LOC.x = SP->getX() + B[0] - getX();
|
|
LOC.y = SP->getY() + B[1] - getY();
|
|
LOC.z = SP->getZ() + B[2] - getZ();
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_DECART& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
spherical2decart(POS, tDec);
|
|
A[0] = tDec.x;
|
|
A[1] = tDec.y;
|
|
A[2] = tDec.z;
|
|
pTF->get_vector_world(A, B);
|
|
LOC.x = SP->getX() + B[0] - getX();
|
|
LOC.y = SP->getY() + B[1] - getY();
|
|
LOC.z = SP->getZ() + B[2] - getZ();
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
spherical2decart(POS, tDec);
|
|
A[0] = tDec.x;
|
|
A[1] = tDec.y;
|
|
A[2] = tDec.z;
|
|
pTF->get_vector_world(A, B);
|
|
tDec.x = B[0] + SP->getX();
|
|
tDec.y = B[1] + SP->getY();
|
|
tDec.z = B[2] + SP->getZ();
|
|
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
|
|
LOC.alt = tDec.z;
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC& LOC) {
|
|
if (SP == NULL) return false;
|
|
transform_3* pTF = SP->getTransform();
|
|
C3D_DECART tDec;
|
|
vector_3 A, B;
|
|
spherical2decart(POS, tDec);
|
|
A[0] = tDec.x;
|
|
A[1] = tDec.y;
|
|
A[2] = tDec.z;
|
|
pTF->get_vector_world(A, B);
|
|
tDec.x = B[0] + SP->getX();
|
|
tDec.y = B[1] + SP->getY();
|
|
tDec.z = B[2] + SP->getZ();
|
|
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
|
|
LOC.alt = tDec.z;
|
|
return true;
|
|
};
|
|
|
|
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_DECART POS, C3D_WGS84_LOC& LOC) {
|
|
C3D_DECART tDec;
|
|
tDec.x = POS.x + getX();
|
|
tDec.y = POS.y + getY();
|
|
tDec.z = POS.z + getZ();
|
|
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
|
|
LOC.alt = tDec.z;
|
|
return true;
|
|
};
|