diff --git a/src/3rdparty/o5mreader/o5mreader.cpp b/src/3rdparty/o5mreader/o5mreader.cpp index e7b2753f7..fdd0caa4e 100644 --- a/src/3rdparty/o5mreader/o5mreader.cpp +++ b/src/3rdparty/o5mreader/o5mreader.cpp @@ -1,533 +1,533 @@ // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #include "o5mreader.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define STR_PAIR_TABLE_SIZE 15000 #define STR_PAIR_STRING_SIZE 256 O5mreaderRet o5mreader_readUInt(O5mreader *pReader, uint64_t *ret) { uint8_t b; uint8_t i = 0; *ret = 0LL; do { if ( fread(&b,1,1,pReader->f) == 0 ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE, NULL ); return O5MREADER_RET_ERR; } *ret |= (long long)(b & 0x7f) << (i++ * 7); } while ( b & 0x80 ); o5mreader_setNoError(pReader); return O5MREADER_RET_OK; } O5mreaderRet o5mreader_readInt(O5mreader *pReader, uint64_t *ret) { if ( o5mreader_readUInt(pReader, ret) == O5MREADER_RET_ERR ) return O5MREADER_RET_ERR; *ret = *ret & 1 ? -(int64_t)(*ret >> 1) - 1 : (int64_t)(*ret >> 1); return O5MREADER_RET_OK; } O5mreaderRet o5mreader_readStrPair(O5mreader *pReader, char **tagpair, int single) { static char buffer[1024]; char* pBuf; static uint64_t pointer = 0; int length; uint64_t key; int i; if ( o5mreader_readUInt(pReader,&key) == O5MREADER_RET_ERR ) { return O5MREADER_RET_ERR; } if ( key ) { *tagpair = pReader->strPairTable[(pointer+15000-key)%15000]; return key; } else { pBuf = buffer; for ( i=0; i<(single?1:2); i++ ) { do { if ( fread(pBuf,1,1,pReader->f) == 0 ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE, NULL ); return O5MREADER_RET_ERR; } } while ( *(pBuf++) ); } length = strlen(buffer) + (single ? 1 : strlen(buffer+strlen(buffer) +1) + 2); if ( length <= 252 ) { *tagpair = pReader->strPairTable[(pointer+15000)%15000]; memcpy(pReader->strPairTable[((pointer++)+15000)%15000],buffer,length); } else { *tagpair = buffer; } } return O5MREADER_RET_OK; } O5mreaderRet o5mreader_reset(O5mreader *pReader) { pReader->nodeId = pReader->wayId = pReader->wayNodeId = pReader->relId = pReader->nodeRefId = pReader->wayRefId = pReader->relRefId = 0; pReader->lon = pReader->lat = 0; pReader->offset = 0; pReader->canIterateTags = pReader->canIterateNds = pReader->canIterateRefs = 0; return O5MREADER_RET_OK; } O5mreaderRet o5mreader_open(O5mreader **ppReader,FILE* f) { uint8_t byte; int i; *ppReader = (O5mreader*)malloc(sizeof(O5mreader)); if ( !(*ppReader) ) { return O5MREADER_RET_ERR; } (*ppReader)->errMsg = NULL; (*ppReader)->f = f; (*ppReader)->strPairTable = NULL; if ( fread(&byte,1,1,(*ppReader)->f) == 0 ) { o5mreader_setError(*ppReader, O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE, NULL ); return O5MREADER_RET_ERR; } if ( byte != O5MREADER_DS_RESET ) { o5mreader_setError(*ppReader, O5MREADER_ERR_CODE_FILE_HAS_WRONG_START, NULL ); return O5MREADER_RET_ERR; } o5mreader_reset(*ppReader); (*ppReader)->strPairTable = (char**) malloc(STR_PAIR_TABLE_SIZE*sizeof(char*)); if ( (*ppReader)->strPairTable == 0 ) { o5mreader_setError(*ppReader, O5MREADER_ERR_CODE_MEMORY_ERROR, NULL ); return O5MREADER_RET_ERR; } for ( i = 0; i < STR_PAIR_TABLE_SIZE; ++i ) { (*ppReader)->strPairTable[i] = (char*) malloc(sizeof(char)*STR_PAIR_STRING_SIZE); if ( (*ppReader)->strPairTable[i] == 0 ) { o5mreader_setError(*ppReader, O5MREADER_ERR_CODE_MEMORY_ERROR, NULL ); return O5MREADER_RET_ERR; } } o5mreader_setNoError(*ppReader); return O5MREADER_RET_OK; } void o5mreader_close(O5mreader *pReader) { int i; if ( pReader ) { if ( pReader->strPairTable ) { for ( i = 0; i < STR_PAIR_TABLE_SIZE; ++i ) if ( pReader->strPairTable[i] ) free(pReader->strPairTable[i]); free(pReader->strPairTable); } o5mreader_setNoError(pReader); free(pReader); } } const char* o5mreader_strerror(int errCode) { switch ( errCode ) { case O5MREADER_ERR_CODE_FILE_HAS_WRONG_START: return "'0xFF' isn't first byte of file."; case O5MREADER_ERR_CODE_MEMORY_ERROR: return "Memory error."; case O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE: return "Unexpected end of file."; case O5MREADER_ERR_CODE_CAN_NOT_ITERATE_TAGS_HERE: return "Tags iteration is not allowed here."; case O5MREADER_ERR_CODE_CAN_NOT_ITERATE_NDS_HERE: return "Nodes iteration is not allowed here."; case O5MREADER_ERR_CODE_CAN_NOT_ITERATE_REFS_HERE: return "References iteration is not allowed here."; default: return "Unknown error code"; } } void o5mreader_setError(O5mreader *pReader,int code, const char* message) { pReader->errCode = code; if ( pReader->errMsg ) { free(pReader->errMsg); } if ( message ) { pReader->errMsg = (char*) malloc(strlen(message)+1); strcpy(pReader->errMsg,message); } } void o5mreader_setNoError(O5mreader *pReader) { pReader->errCode = O5MREADER_ERR_CODE_OK; if ( pReader->errMsg ) { free(pReader->errMsg); } pReader->errMsg = NULL; } O5mreaderIterateRet o5mreader_iterateDataSet(O5mreader *pReader, O5mreaderDataset* ds) { for (;;) { if ( pReader->offset ) { if ( o5mreader_skipTags(pReader) == O5MREADER_ITERATE_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; fseek( pReader->f, (pReader->current - ftell(pReader->f)) + pReader->offset, SEEK_CUR ); pReader->offset = 0; } if ( fread(&(ds->type),1,1,pReader->f) == 0 ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE, NULL ); return O5MREADER_ITERATE_RET_ERR; } if ( O5MREADER_DS_END == ds->type ) return O5MREADER_ITERATE_RET_DONE; if ( O5MREADER_DS_RESET == ds->type ) { o5mreader_reset(pReader); } else if ( 0xf0 == ds->type ) {} else { if ( o5mreader_readUInt(pReader,&pReader->offset) == O5MREADER_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } pReader->current = ftell(pReader->f); switch ( ds->type ) { case O5MREADER_DS_NODE: return o5mreader_readNode(pReader, ds); case O5MREADER_DS_WAY: return o5mreader_readWay(pReader, ds); case O5MREADER_DS_REL: return o5mreader_readRel(pReader, ds); /* case O5MREADER_DS_BBOX: case O5MREADER_DS_TSTAMP: case O5MREADER_DS_HEADER: case O5MREADER_DS_SYNC: case O5MREADER_DS_JUMP: default: break; */ } } } } int o5mreader_thereAreNoMoreData(O5mreader *pReader) { return (int)((pReader->current - ftell(pReader->f)) + pReader->offset) <= 0; } O5mreaderIterateRet o5mreader_readVersion(O5mreader *pReader, O5mreaderDataset* ds) { uint64_t tmp; if ( o5mreader_readUInt(pReader,&tmp) == O5MREADER_ITERATE_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } ds->version = tmp; if ( tmp ) { if ( o5mreader_readUInt(pReader,&tmp) == O5MREADER_ITERATE_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } if ( o5mreader_readInt(pReader,&tmp) == O5MREADER_ITERATE_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } if ( o5mreader_thereAreNoMoreData(pReader) ) return O5MREADER_ITERATE_RET_DONE; if ( o5mreader_readStrPair(pReader,&pReader->tagPair,0) == O5MREADER_ITERATE_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } } if ( o5mreader_thereAreNoMoreData(pReader) ) return O5MREADER_ITERATE_RET_DONE; return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_iterateTags(O5mreader *pReader, char** pKey, char** pVal) { if ( pReader->canIterateRefs ) { if ( o5mreader_skipRefs(pReader) == O5MREADER_ITERATE_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; } if ( pReader->canIterateNds ) { if ( o5mreader_skipNds(pReader) == O5MREADER_ITERATE_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; } if ( !pReader->canIterateTags ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_CAN_NOT_ITERATE_TAGS_HERE, NULL ); return O5MREADER_ITERATE_RET_ERR; } if ( o5mreader_thereAreNoMoreData(pReader) ) { pReader->canIterateTags = 0; return O5MREADER_ITERATE_RET_DONE; } if ( o5mreader_readStrPair(pReader,&pReader->tagPair,0) == O5MREADER_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } if ( pKey ) *pKey = pReader->tagPair; if ( pVal ) *pVal = pReader->tagPair + strlen(pReader->tagPair) + 1; return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_skipTags(O5mreader *pReader) { int ret = O5MREADER_ITERATE_RET_DONE; if ( pReader->canIterateTags ) { while ( O5MREADER_ITERATE_RET_NEXT == (ret = o5mreader_iterateTags(pReader, NULL, NULL)) ); } return ret; } O5mreaderIterateRet o5mreader_readNode(O5mreader *pReader, O5mreaderDataset* ds) { int64_t nodeId; int64_t lon,lat; if ( o5mreader_readInt(pReader,(uint64_t *)&nodeId) == O5MREADER_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; pReader->canIterateRefs = 0; pReader->canIterateNds = 0; pReader->canIterateTags = 1; pReader->nodeId += nodeId; ds->id = pReader->nodeId; if ( o5mreader_readVersion(pReader, ds) == O5MREADER_ITERATE_RET_DONE ) { ds->isEmpty = 1; return O5MREADER_ITERATE_RET_NEXT; } else ds->isEmpty = 0; if ( o5mreader_thereAreNoMoreData(pReader) ) { return O5MREADER_ITERATE_RET_NEXT; } if ( o5mreader_readInt(pReader,(uint64_t *)&lon) == O5MREADER_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; pReader->lon += (int32_t)lon; if ( o5mreader_readInt(pReader,(uint64_t *)&lat) == O5MREADER_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } pReader->lat += (int32_t)lat; ds->lon = pReader->lon; ds->lat = pReader->lat; return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_iterateNds(O5mreader *pReader, uint64_t *nodeId) { int64_t wayNodeId; if ( !pReader->canIterateNds ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_CAN_NOT_ITERATE_NDS_HERE, NULL ); return O5MREADER_ITERATE_RET_ERR; } if ( ftell(pReader->f) >= long(pReader->offsetNd) ) { pReader->canIterateNds = 0; pReader->canIterateTags = 1; pReader->canIterateRefs = 0; return O5MREADER_ITERATE_RET_DONE; } if ( o5mreader_readInt(pReader,(uint64_t *)&wayNodeId) == O5MREADER_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; pReader->wayNodeId += wayNodeId; if ( nodeId ) *nodeId = pReader->wayNodeId; return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_skipNds(O5mreader *pReader) { uint8_t ret; while ( pReader->canIterateNds && O5MREADER_ITERATE_RET_NEXT == (ret = o5mreader_iterateNds(pReader, NULL)) ); return ret; } O5mreaderIterateRet o5mreader_readWay(O5mreader *pReader, O5mreaderDataset* ds) { int64_t wayId; if ( o5mreader_readInt(pReader,(uint64_t *)&wayId) == O5MREADER_RET_ERR) return O5MREADER_ITERATE_RET_ERR; pReader->wayId += wayId; ds->id = pReader->wayId; if ( o5mreader_readVersion(pReader, ds) == O5MREADER_ITERATE_RET_DONE ) { ds->isEmpty = 1; return O5MREADER_ITERATE_RET_NEXT; } else ds->isEmpty = 0; if ( o5mreader_readUInt(pReader,&pReader->offsetNd) == O5MREADER_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } pReader->offsetNd += ftell(pReader->f); pReader->canIterateRefs = 0; pReader->canIterateNds = 1; pReader->canIterateTags = 0; return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_iterateRefs(O5mreader *pReader, uint64_t *refId, uint8_t *type, char** pRole) { int64_t relRefId; if ( !pReader->canIterateRefs ) { o5mreader_setError(pReader, O5MREADER_ERR_CODE_CAN_NOT_ITERATE_REFS_HERE, NULL ); return O5MREADER_ITERATE_RET_ERR; } if ( ftell(pReader->f) >= long(pReader->offsetRf) ) { pReader->canIterateNds = 0; pReader->canIterateTags = 1; pReader->canIterateRefs = 0; return O5MREADER_ITERATE_RET_DONE; } if ( o5mreader_readInt(pReader, (uint64_t *)&relRefId) == O5MREADER_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; //fread(_,1,1,pReader->f); if ( o5mreader_readStrPair(pReader, &pReader->tagPair,1) == O5MREADER_RET_ERR ) { return O5MREADER_ITERATE_RET_ERR; } switch( pReader->tagPair[0] ) { case '0': if ( type ) *type = O5MREADER_DS_NODE; pReader->nodeRefId += relRefId; if ( refId ) *refId = pReader->nodeRefId; break; case '1': if ( type ) *type = O5MREADER_DS_WAY; pReader->wayRefId += relRefId; if ( refId ) *refId = pReader->wayRefId; break; case '2': if ( type ) *type = O5MREADER_DS_REL; pReader->relRefId += relRefId; if ( refId ) *refId = pReader->relRefId; break; } if ( pRole ) { *pRole = pReader->tagPair + 1; } return O5MREADER_ITERATE_RET_NEXT; } O5mreaderIterateRet o5mreader_skipRefs(O5mreader *pReader) { uint8_t ret; while ( pReader->canIterateRefs && O5MREADER_ITERATE_RET_NEXT == (ret = o5mreader_iterateRefs(pReader, NULL, NULL, NULL)) ); return ret; } O5mreaderIterateRet o5mreader_readRel(O5mreader *pReader, O5mreaderDataset* ds) { int64_t relId; if ( o5mreader_readInt(pReader,(uint64_t *)&relId) == O5MREADER_RET_ERR ) return O5MREADER_ITERATE_RET_ERR; pReader->relId += relId; ds->id = pReader->relId; if ( o5mreader_readVersion(pReader,ds) == O5MREADER_ITERATE_RET_DONE ) { ds->isEmpty = 1; return O5MREADER_ITERATE_RET_NEXT; } else ds->isEmpty = 0; o5mreader_readUInt(pReader,&pReader->offsetRf); pReader->offsetRf += ftell(pReader->f); pReader->canIterateRefs = 1; pReader->canIterateNds = 0; pReader->canIterateTags = 0; return O5MREADER_ITERATE_RET_NEXT; } diff --git a/src/3rdparty/o5mreader/o5mreader.h b/src/3rdparty/o5mreader/o5mreader.h index 11b9a68cf..0f672fca6 100644 --- a/src/3rdparty/o5mreader/o5mreader.h +++ b/src/3rdparty/o5mreader/o5mreader.h @@ -1,122 +1,122 @@ // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #ifndef O5MREADER_H #define O5MREADER_H -#include -#include +#include +#include #define O5MREADER_RET_OK 1 #define O5MREADER_RET_ERR 0 #define O5MREADER_ITERATE_RET_DONE 0 #define O5MREADER_ITERATE_RET_ERR -1 #define O5MREADER_ITERATE_RET_NEXT 1 #define O5MREADER_DS_END 0xfe #define O5MREADER_DS_NODE 0x10 #define O5MREADER_DS_WAY 0x11 #define O5MREADER_DS_REL 0x12 #define O5MREADER_DS_BBOX 0xdb #define O5MREADER_DS_TSTAMP 0xdc #define O5MREADER_DS_HEADER 0xe0 #define O5MREADER_DS_SYNC 0xee #define O5MREADER_DS_JUMP 0xef #define O5MREADER_DS_RESET 0xff #define O5MREADER_ERR_CODE_OK 0 #define O5MREADER_ERR_CODE_FILE_HAS_WRONG_START 1 #define O5MREADER_ERR_CODE_UNEXPECTED_END_OF_FILE 2 #define O5MREADER_ERR_CODE_MEMORY_ERROR 3 #define O5MREADER_ERR_CODE_CAN_NOT_ITERATE_TAGS_HERE 4 #define O5MREADER_ERR_CODE_CAN_NOT_ITERATE_NDS_HERE 5 #define O5MREADER_ERR_CODE_CAN_NOT_ITERATE_REFS_HERE 6 typedef int O5mreaderRet; typedef int O5mreaderIterateRet; typedef struct { int errCode; char* errMsg; FILE *f; uint64_t offset; uint64_t offsetNd; uint64_t offsetRf; uint64_t current; char* tagPair; int64_t nodeId; int64_t wayId; int64_t wayNodeId; int64_t relId; int64_t nodeRefId; int64_t wayRefId; int64_t relRefId; int32_t lon; int32_t lat; uint8_t canIterateTags; uint8_t canIterateNds; uint8_t canIterateRefs; char** strPairTable; } O5mreader; typedef struct { uint8_t type; uint64_t id; uint32_t version; uint8_t isEmpty; int32_t lon; int32_t lat; } O5mreaderDataset; #if defined (__cplusplus) extern "C" { #endif void o5mreader_setError(O5mreader *pReader,int code, const char* message); void o5mreader_setNoError(O5mreader *pReader); O5mreaderIterateRet o5mreader_skipTags(O5mreader *pReader); O5mreaderIterateRet o5mreader_readNode(O5mreader *pReader, O5mreaderDataset* ds); O5mreaderIterateRet o5mreader_readWay(O5mreader *pReader, O5mreaderDataset* ds); O5mreaderIterateRet o5mreader_readRel(O5mreader *pReader, O5mreaderDataset* ds); O5mreaderIterateRet o5mreader_skipRefs(O5mreader *pReader); O5mreaderIterateRet o5mreader_skipNds(O5mreader *pReader); O5mreaderRet o5mreader_readInt(O5mreader *pReader, uint64_t *ret); O5mreaderRet o5mreader_open(O5mreader **ppReader,FILE* f); void o5mreader_close(O5mreader *pReader); const char* o5mreader_strerror(int errCode); O5mreaderIterateRet o5mreader_iterateDataSet(O5mreader *pReader, O5mreaderDataset* ds); O5mreaderIterateRet o5mreader_iterateTags(O5mreader *pReader, char** pKey, char** pVal); O5mreaderIterateRet o5mreader_iterateNds(O5mreader *pReader, uint64_t *nodeId); O5mreaderIterateRet o5mreader_iterateRefs(O5mreader *pReader, uint64_t *refId, uint8_t *type, char** pRole); #if defined (__cplusplus) } #endif #endif // O5MREADER_H diff --git a/src/3rdparty/sgp4/sgp4ext.h b/src/3rdparty/sgp4/sgp4ext.h index ee564f1c7..b0c2916e7 100644 --- a/src/3rdparty/sgp4/sgp4ext.h +++ b/src/3rdparty/sgp4/sgp4ext.h @@ -1,92 +1,92 @@ #ifndef _sgp4ext_ #define _sgp4ext_ /* ---------------------------------------------------------------- * * sgp4ext.h * * this file contains extra routines needed for the main test program for sgp4. * these routines are derived from the astro libraries. * * companion code for * fundamentals of astrodynamics and applications * 2007 * by david vallado * * (w) 719-573-2600, email dvallado@agi.com * * current : * 20 apr 07 david vallado * misc documentation updates * changes : * 14 aug 06 david vallado * original baseline * ---------------------------------------------------------------- */ -#include -#include +#include +#include #include "sgp4unit.h" // ------------------------- function declarations ------------------------- double sgn ( double x ); double mag ( double x[3] ); void cross ( double vec1[3], double vec2[3], double outvec[3] ); double dot ( double x[3], double y[3] ); double angle ( double vec1[3], double vec2[3] ); void newtonnu ( double ecc, double nu, double& e0, double& m ); void rv2coe ( double r[3], double v[3], double mu, double& p, double& a, double& ecc, double& incl, double& omega, double& argp, double& nu, double& m, double& arglat, double& truelon, double& lonper ); void jday ( int year, int mon, int day, int hr, int minute, double sec, double& jd ); void days2mdhms ( int year, double days, int& mon, int& day, int& hr, int& minute, double& sec ); void invjday ( double jd, int& year, int& mon, int& day, int& hr, int& minute, double& sec ); #endif diff --git a/src/3rdparty/sgp4/sgp4io.h b/src/3rdparty/sgp4/sgp4io.h index a99e1e2ea..0b3e742c6 100644 --- a/src/3rdparty/sgp4/sgp4io.h +++ b/src/3rdparty/sgp4/sgp4io.h @@ -1,46 +1,46 @@ #ifndef _sgp4io_ #define _sgp4io_ /* ---------------------------------------------------------------- * * sgp4io.h; * * this file contains a function to read two line element sets. while * not formerly part of the sgp4 mathematical theory, it is * required for practical implementation. * * companion code for * fundamentals of astrodynamics and applications * 2007 * by david vallado * * (w) 719-573-2600, email dvallado@agi.com * * current : * 3 sep 07 david vallado * add operationmode for afspc (a) or improved (i) * changes : * 20 apr 07 david vallado * misc updates for manual operation * 14 aug 06 david vallado * original baseline * ---------------------------------------------------------------- */ -#include -#include +#include +#include #include "sgp4ext.h" // for several misc routines #include "sgp4unit.h" // for sgp4init and getgravconst // ------------------------- function declarations ------------------------- void twoline2rv ( char longstr1[130], char longstr2[130], char typerun, char typeinput, char opsmode, gravconsttype whichconst, double& startmfe, double& stopmfe, double& deltamin, elsetrec& satrec ); #endif diff --git a/src/3rdparty/sgp4/sgp4unit.h b/src/3rdparty/sgp4/sgp4unit.h index f16ba19fd..38ef245ed 100644 --- a/src/3rdparty/sgp4/sgp4unit.h +++ b/src/3rdparty/sgp4/sgp4unit.h @@ -1,128 +1,128 @@ #ifndef _sgp4unit_ #define _sgp4unit_ /* ---------------------------------------------------------------- * * sgp4unit.h * * this file contains the sgp4 procedures for analytical propagation * of a satellite. the code was originally released in the 1980 and 1986 * spacetrack papers. a detailed discussion of the theory and history * may be found in the 2006 aiaa paper by vallado, crawford, hujsak, * and kelso. * * companion code for * fundamentals of astrodynamics and applications * 2007 * by david vallado * * (w) 719-573-2600, email dvallado@agi.com * * current : * 3 Nov 08 david vallado * put returns in for error codes * changes : * 29 sep 08 david vallado * fix atime for faster operation in dspace * add operationmode for afspc (a) or improved (i) * performance mode * 20 apr 07 david vallado * misc fixes for constants * 11 aug 06 david vallado * chg lyddane choice back to strn3, constants, misc doc * 15 dec 05 david vallado * misc fixes * 26 jul 05 david vallado * fixes for paper * note that each fix is preceded by a * comment with "sgp4fix" and an explanation of * what was changed * 10 aug 04 david vallado * 2nd printing baseline working * 14 may 01 david vallado * 2nd edition baseline * 80 norad * original baseline * ---------------------------------------------------------------- */ -#include -#include +#include +#include #define SGP4Version "SGP4 Version 2008-11-03" #ifndef M_PI #define M_PI 3.14159265358979323846 #endif // -------------------------- structure declarations ---------------------------- typedef enum { wgs72old, wgs72, wgs84 } gravconsttype; typedef struct elsetrec { long int satnum; int epochyr, epochtynumrev; int error; char operationmode; char init, method; /* Near Earth */ int isimp; double aycof , con41 , cc1 , cc4 , cc5 , d2 , d3 , d4 , delmo , eta , argpdot, omgcof , sinmao , t , t2cof, t3cof , t4cof , t5cof , x1mth2 , x7thm1 , mdot , nodedot, xlcof , xmcof , nodecf; /* Deep Space */ int irez; double d2201 , d2211 , d3210 , d3222 , d4410 , d4422 , d5220 , d5232 , d5421 , d5433 , dedt , del1 , del2 , del3 , didt , dmdt , dnodt , domdt , e3 , ee2 , peo , pgho , pho , pinco , plo , se2 , se3 , sgh2 , sgh3 , sgh4 , sh2 , sh3 , si2 , si3 , sl2 , sl3 , sl4 , gsto , xfact , xgh2 , xgh3 , xgh4 , xh2 , xh3 , xi2 , xi3 , xl2 , xl3 , xl4 , xlamo , zmol , zmos , atime , xli , xni; double a , altp , alta , epochdays, jdsatepoch , nddot , ndot , bstar , rcse , inclo , nodeo , ecco , argpo , mo , no; } elsetrec; // --------------------------- function declarations ---------------------------- bool sgp4init ( gravconsttype whichconst, char opsmode, const int satn, const double epoch, const double xbstar, const double xecco, const double xargpo, const double xinclo, const double xmo, const double xno, const double xnodeo, elsetrec& satrec ); bool sgp4 ( gravconsttype whichconst, elsetrec& satrec, double tsince, double r[3], double v[3] ); double gstime ( double jdut1 ); void getgravconst ( gravconsttype whichconst, double& tumin, double& mu, double& radiusearthkm, double& xke, double& j2, double& j3, double& j4, double& j3oj2 ); #endif diff --git a/src/lib/marble/AutoNavigation.cpp b/src/lib/marble/AutoNavigation.cpp index 594854405..a2c109b55 100644 --- a/src/lib/marble/AutoNavigation.cpp +++ b/src/lib/marble/AutoNavigation.cpp @@ -1,390 +1,390 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2010 Siddharth Srivastava // Copyright 2011 Bernhard Beschow // #include "AutoNavigation.h" #include "GeoDataCoordinates.h" #include "PositionTracking.h" #include "MarbleDebug.h" #include "MarbleModel.h" #include "MarbleMath.h" #include "ViewportParams.h" #include "MarbleGlobal.h" #include "RoutingManager.h" #include "RoutingModel.h" #include "Route.h" #include #include #include #include -#include +#include namespace Marble { class Q_DECL_HIDDEN AutoNavigation::Private { public: AutoNavigation *const m_parent; const MarbleModel *const m_model; const ViewportParams *const m_viewport; const PositionTracking *const m_tracking; AutoNavigation::CenterMode m_recenterMode; bool m_adjustZoom; QTimer m_lastWidgetInteraction; bool m_selfInteraction; /** Constructor */ Private( MarbleModel *model, const ViewportParams *viewport, AutoNavigation *parent ); /** * @brief To center on when reaching custom defined border * @param position current gps location * @param speed optional speed argument */ void moveOnBorderToCenter( const GeoDataCoordinates &position, qreal speed ); /** * For calculating intersection point of projected LineString from * current gps location with the map border * @param position current gps location */ GeoDataCoordinates findIntersection( qreal currentX, qreal currentY ) const; /** * @brief Adjust the zoom value of the map * @param currentPosition current location of the gps device */ void adjustZoom( const GeoDataCoordinates ¤tPosition, qreal speed ); /** * Center the widget on the given position unless recentering is currently inhibited */ void centerOn( const GeoDataCoordinates &position ); }; AutoNavigation::Private::Private( MarbleModel *model, const ViewportParams *viewport, AutoNavigation *parent ) : m_parent( parent ), m_model( model ), m_viewport( viewport ), m_tracking( model->positionTracking() ), m_recenterMode( AutoNavigation::DontRecenter ), m_adjustZoom( 0 ), m_selfInteraction( false ) { m_lastWidgetInteraction.setInterval( 10 * 1000 ); m_lastWidgetInteraction.setSingleShot( true ); } void AutoNavigation::Private::moveOnBorderToCenter( const GeoDataCoordinates &position, qreal ) { qreal x = 0.0; qreal y = 0.0; //recenter if initially the gps location is not visible on the screen if(!( m_viewport->screenCoordinates( position, x, y ) ) ) { centerOn( position ); } qreal centerLon = m_viewport->centerLongitude(); qreal centerLat = m_viewport->centerLatitude(); qreal centerX = 0.0; qreal centerY = 0.0; m_viewport->screenCoordinates( centerLon, centerLat, centerX, centerY ); const qreal borderRatio = 0.25; //defining the default border distance from map center int shiftX = qRound( centerX * borderRatio ); int shiftY = qRound( centerY * borderRatio ); QRect recenterBorderBound; recenterBorderBound.setCoords( centerX-shiftX, centerY-shiftY, centerX+shiftX, centerY+shiftY ); if( !recenterBorderBound.contains( x,y ) ) { centerOn( position ); } } GeoDataCoordinates AutoNavigation::Private::findIntersection( qreal currentX, qreal currentY ) const { qreal direction = m_tracking->direction(); if ( direction >= 360 ) { direction = fmod( direction,360.0 ); } const qreal width = m_viewport->width(); const qreal height = m_viewport->height(); QPointF intercept; QPointF destinationHorizontal; QPointF destinationVertical; QPointF destination; bool crossHorizontal = false; bool crossVertical = false; //calculation of intersection point if( 0 < direction && direction < 90 ) { const qreal angle = direction; //Intersection with line x = width intercept.setX( width - currentX ); intercept.setY( intercept.x() / tan( angle ) ); destinationVertical.setX( width ); destinationVertical.setY( currentY-intercept.y() ); //Intersection with line y = 0 intercept.setY( currentY ); intercept.setX( intercept.y() * tan( angle ) ); destinationHorizontal.setX( currentX + intercept.x() ); destinationHorizontal.setY( 0 ); if ( destinationVertical.y() < 0 ) { crossHorizontal = true; } else if( destinationHorizontal.x() > width ) { crossVertical = true; } } else if( 270 < direction && direction < 360 ) { const qreal angle = direction - 270; //Intersection with line y = 0 intercept.setY( currentY ); intercept.setX( intercept.y() / tan( angle ) ); destinationHorizontal.setX( currentX - intercept.x() ); destinationHorizontal.setY( 0 ); //Intersection with line x = 0 intercept.setX( currentX ); intercept.setY( intercept.x() * tan( angle ) ); destinationVertical.setY( currentY - intercept.y() ); destinationVertical.setX( 0 ); if( destinationHorizontal.x() > width ) { crossVertical = true; } else if( destinationVertical.y() < 0 ) { crossHorizontal = true; } } else if( 180 < direction && direction < 270 ) { const qreal angle = direction - 180; //Intersection with line x = 0 intercept.setX( currentX ); intercept.setY( intercept.x() / tan( angle ) ); destinationVertical.setY( currentY + intercept.y() ); destinationVertical.setX( 0 ); //Intersection with line y = height intercept.setY( currentY ); intercept.setX( intercept.y() * tan( angle ) ); destinationHorizontal.setX( currentX - intercept.x() ); destinationHorizontal.setY( height ); if ( destinationVertical.y() > height ) { crossHorizontal = true; } else if ( destinationHorizontal.x() < 0 ) { crossVertical = true; } } else if( 90 < direction && direction < 180 ) { const qreal angle = direction - 90; //Intersection with line y = height intercept.setY( height - currentY ); intercept.setX( intercept.y() / tan( angle ) ); destinationHorizontal.setX( currentX + intercept.x() ); destinationHorizontal.setY( height ); //Intersection with line x = width intercept.setX( width - currentX ); intercept.setY( intercept.x() * tan( angle ) ); destinationVertical.setX( width ); destinationVertical.setY( currentY + intercept.y() ); if ( destinationHorizontal.x() > width ) { crossVertical = true; } else if( destinationVertical.y() > height ) { crossHorizontal = true; } } else if( direction == 0 ) { destinationHorizontal.setX( currentX ); destinationHorizontal.setY( 0 ); crossHorizontal = true; } else if( direction == 90 ) { destinationVertical.setX( width ); destinationVertical.setY( currentY ); crossVertical = true; } else if( direction == 190 ) { destinationHorizontal.setX( currentX ); destinationHorizontal.setY( height ); crossHorizontal = true; } else if( direction == 270 ) { destinationVertical.setX( 0 ); destinationVertical.setY( currentY ); crossVertical = true; } if ( crossHorizontal == true && crossVertical == false ) { destination.setX( destinationHorizontal.x() ); destination.setY( destinationHorizontal.y() ); } else if ( crossVertical == true && crossHorizontal == false ) { destination.setX( destinationVertical.x() ); destination.setY( destinationVertical.y() ); } qreal destinationLon = 0.0; qreal destinationLat = 0.0; m_viewport->geoCoordinates( destination.x(), destination.y(), destinationLon, destinationLat, GeoDataCoordinates::Radian ); GeoDataCoordinates destinationCoord( destinationLon, destinationLat, GeoDataCoordinates::Radian ); return destinationCoord; } void AutoNavigation::Private::adjustZoom( const GeoDataCoordinates ¤tPosition, qreal speed ) { qreal currentX = 0; qreal currentY = 0; if( !m_viewport->screenCoordinates(currentPosition, currentX, currentY ) ) { return; } const GeoDataCoordinates destination = findIntersection( currentX, currentY ); qreal greatCircleDistance = distanceSphere( currentPosition, destination ); qreal radius = m_model->planetRadius(); qreal distance = greatCircleDistance * radius; if( speed != 0 ) { // time (in seconds) remaining to reach the border of the map qreal remainingTime = distance / speed; // tolerance time limits (in seconds) before auto zooming qreal thresholdLow = 15; qreal thresholdHigh = 120; m_selfInteraction = true; if ( remainingTime < thresholdLow ) { emit m_parent->zoomOut( Instant ); } else if ( remainingTime > thresholdHigh ) { emit m_parent->zoomIn( Instant ); } m_selfInteraction = false; } } void AutoNavigation::Private::centerOn( const GeoDataCoordinates &position ) { m_selfInteraction = true; RoutingManager const * routingManager = m_model->routingManager(); RoutingModel const * routingModel = routingManager->routingModel(); if (!routingManager->guidanceModeEnabled() || routingModel->deviatedFromRoute()){ emit m_parent->centerOn( position, false ); } else { GeoDataCoordinates positionOnRoute = routingModel->route().positionOnRoute(); emit m_parent->centerOn( positionOnRoute, false ); } m_selfInteraction = false; } AutoNavigation::AutoNavigation( MarbleModel *model, const ViewportParams *viewport, QObject *parent ) : QObject( parent ), d( new AutoNavigation::Private( model, viewport, this ) ) { connect( d->m_tracking, SIGNAL(gpsLocation(GeoDataCoordinates,qreal)), this, SLOT(adjust(GeoDataCoordinates,qreal)) ); } AutoNavigation::~AutoNavigation() { delete d; } void AutoNavigation::adjust( const GeoDataCoordinates &position, qreal speed ) { if ( d->m_lastWidgetInteraction.isActive() ) { return; } switch( d->m_recenterMode ) { case DontRecenter: /* nothing to do */ break; case AlwaysRecenter: d->centerOn( position ); break; case RecenterOnBorder: d->moveOnBorderToCenter( position, speed ); break; } if ( d->m_adjustZoom ) { switch( d->m_recenterMode ) { case DontRecenter: /* nothing to do */ break; case AlwaysRecenter: case RecenterOnBorder: // fallthrough d->adjustZoom( position, speed ); break; } } } void AutoNavigation::setAutoZoom( bool autoZoom ) { d->m_adjustZoom = autoZoom; emit autoZoomToggled( autoZoom ); } void AutoNavigation::setRecenter( CenterMode recenterMode ) { d->m_recenterMode = recenterMode; emit recenterModeChanged( recenterMode ); } void AutoNavigation::inhibitAutoAdjustments() { if ( !d->m_selfInteraction ) { d->m_lastWidgetInteraction.start(); } } AutoNavigation::CenterMode AutoNavigation::recenterMode() const { return d->m_recenterMode; } bool AutoNavigation::autoZoom() const { return d->m_adjustZoom; } } // namespace Marble #include "moc_AutoNavigation.cpp" diff --git a/src/lib/marble/MarbleDirs.cpp b/src/lib/marble/MarbleDirs.cpp index 15bef155f..3b160b44a 100644 --- a/src/lib/marble/MarbleDirs.cpp +++ b/src/lib/marble/MarbleDirs.cpp @@ -1,351 +1,351 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2004-2007 Torsten Rahn // Copyright 2007 Inge Wallin // #include "MarbleDirs.h" #include "MarbleDebug.h" #include #include #include #include #include -#include +#include #include #ifdef Q_OS_WIN //for getting appdata path //mingw-w64 Internet Explorer 5.01 #define _WIN32_IE 0x0501 #include #endif #ifdef Q_OS_MACX //for getting app bundle path #include #endif #include using namespace Marble; namespace { QString runTimeMarbleDataPath; QString runTimeMarblePluginPath; } MarbleDirs::MarbleDirs() : d( 0 ) { } QString MarbleDirs::path( const QString& relativePath ) { QString localpath = localPath() + QLatin1Char('/') + relativePath; // local path QString systempath = systemPath() + QLatin1Char('/') + relativePath; // system path QString fullpath = systempath; if ( QFile::exists( localpath ) ) { fullpath = localpath; } return QDir( fullpath ).canonicalPath(); } QString MarbleDirs::pluginPath( const QString& relativePath ) { const QString localpath = pluginLocalPath() + QDir::separator() + relativePath; // local path const QString systempath = pluginSystemPath() + QDir::separator() + relativePath; // system path QString fullpath = systempath; if ( QFile::exists( localpath ) ) { fullpath = localpath; } return QDir( fullpath ).canonicalPath(); } QStringList MarbleDirs::entryList( const QString& relativePath, QDir::Filters filters ) { QStringList filesLocal = QDir(MarbleDirs::localPath() + QLatin1Char('/') + relativePath).entryList(filters); QStringList filesSystem = QDir(MarbleDirs::systemPath() + QLatin1Char('/') + relativePath).entryList(filters); QStringList allFiles( filesLocal ); allFiles << filesSystem; // remove duplicate entries allFiles.sort(); for ( int i = 1; i < allFiles.size(); ++i ) { if ( allFiles.at(i) == allFiles.at( i - 1 ) ) { allFiles.removeAt(i); --i; } } return allFiles; } QStringList MarbleDirs::pluginEntryList( const QString& relativePath, QDir::Filters filters ) { QStringList allFiles = QDir(MarbleDirs::pluginLocalPath() + QLatin1Char('/') + relativePath).entryList(filters); auto const pluginSystemPath = MarbleDirs::pluginSystemPath(); if (!pluginSystemPath.isEmpty()) { allFiles << QDir(pluginSystemPath + QLatin1Char('/') + relativePath).entryList(filters); } // remove duplicate entries allFiles.sort(); for ( int i = 1; i < allFiles.size(); ++i ) { if ( allFiles.at(i) == allFiles.at( i - 1 ) ) { allFiles.removeAt(i); --i; } } return allFiles; } QString MarbleDirs::systemPath() { if (!runTimeMarbleDataPath.isEmpty()) { return runTimeMarbleDataPath; } QString systempath; #ifdef Q_OS_WIN return QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("data"); #endif #ifdef Q_OS_MACX // // On OSX lets try to find any file first in the bundle // before branching out to home and sys dirs // CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle); const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding()); CFRelease(myBundleRef); QString myPath(mypPathPtr); CFRelease(myMacPath); //do some magick so that we can still find data dir if //marble was not built as a bundle if (myPath.contains(QLatin1String(".app"))) { //its a bundle! systempath = myPath + QLatin1String("/Contents/Resources/data"); } if ( QFile::exists( systempath ) ){ return systempath; } #endif // mac bundle #ifdef Q_OS_ANDROID systempath = "assets:/data"; return systempath; #endif #ifdef MARBLE_DATA_PATH //MARBLE_DATA_PATH is a compiler define set by cmake QString compileTimeMarbleDataPath(MARBLE_DATA_PATH); if(QDir(compileTimeMarbleDataPath).exists()) return compileTimeMarbleDataPath; #endif // MARBLE_DATA_PATH return QDir( QCoreApplication::applicationDirPath() // TODO: QTONLY definition was removed during Qt5/KF5 port, check what code should do #if defined(QTONLY) + QLatin1String( "/data" ) #else + QLatin1String( "/../share/apps/marble/data" ) #endif ).canonicalPath(); } QString MarbleDirs::pluginSystemPath() { if (!runTimeMarblePluginPath.isEmpty()) { return runTimeMarblePluginPath; } QString systempath; #ifdef Q_OS_MACX // // On OSX lets try to find any file first in the bundle // before branching out to home and sys dirs // CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle); const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding()); CFRelease(myBundleRef); CFRelease(myMacPath); QString myPath(mypPathPtr); //do some magick so that we can still find data dir if //marble was not built as a bundle if (myPath.contains(QLatin1String(".app"))) { //its a bundle! systempath = myPath + QLatin1String("/Contents/Resources/plugins"); } if ( QFile::exists( systempath ) ){ return systempath; } #endif // mac bundle #ifdef Q_OS_WIN return QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("plugins"); #endif #ifdef Q_OS_ANDROID return "assets:/plugins"; #endif #ifdef MARBLE_PLUGIN_PATH //MARBLE_PLUGIN_PATH is a compiler define set by cmake QString compileTimeMarblePluginPath(MARBLE_PLUGIN_PATH); if(QDir(compileTimeMarblePluginPath).exists()) return compileTimeMarblePluginPath; #endif // MARBLE_PLUGIN_PATH return QDir( QCoreApplication::applicationDirPath() // TODO: QTONLY definition was removed during Qt5/KF5 port, check what code should do #if defined(QTONLY) + QLatin1String( "/plugins" ) #else + QLatin1String( "/../lib/kde4/plugins/marble" ) #endif ).canonicalPath(); } QString MarbleDirs::localPath() { #ifndef Q_OS_WIN QString dataHome = getenv( "XDG_DATA_HOME" ); if( dataHome.isEmpty() ) dataHome = QDir::homePath() + QLatin1String("/.local/share"); return dataHome + QLatin1String("/marble"); // local path #else return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/.marble/data"); #endif } QStringList MarbleDirs::oldLocalPaths() { QStringList possibleOldPaths; #ifndef Q_OS_WIN const QString oldDefault = QDir::homePath() + QLatin1String("/.marble/data"); possibleOldPaths.append( oldDefault ); const QString xdgDefault = QDir::homePath() + QLatin1String("/.local/share/marble"); possibleOldPaths.append( xdgDefault ); QString xdg = getenv( "XDG_DATA_HOME" ); xdg += QLatin1String("/marble/"); possibleOldPaths.append( xdg ); #endif #ifdef Q_OS_WIN HWND hwnd = 0; WCHAR *appdata_path = new WCHAR[MAX_PATH + 1]; SHGetSpecialFolderPathW(hwnd, appdata_path, CSIDL_APPDATA, 0); QString appdata = QString::fromUtf16(reinterpret_cast(appdata_path)); delete[] appdata_path; possibleOldPaths << QString(QDir::fromNativeSeparators(appdata) + QLatin1String("/.marble/data")); // local path #endif QString currentLocalPath = QDir( MarbleDirs::localPath() ).canonicalPath(); QStringList oldPaths; for( const QString& possibleOldPath: possibleOldPaths ) { if( !QDir().exists( possibleOldPath ) ) { continue; } QString canonicalPossibleOldPath = QDir( possibleOldPath ).canonicalPath(); if( canonicalPossibleOldPath == currentLocalPath ) { continue; } oldPaths.append( canonicalPossibleOldPath ); } return oldPaths; } QString MarbleDirs::pluginLocalPath() { #ifndef Q_OS_WIN return QDir::homePath() + QLatin1String("/.marble/plugins"); // local path #else return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/.marble/plugins"); #endif } QString MarbleDirs::marbleDataPath() { return runTimeMarbleDataPath; } QString MarbleDirs::marblePluginPath() { return runTimeMarblePluginPath; } void MarbleDirs::setMarbleDataPath( const QString& adaptedPath ) { if ( !QDir::root().exists( adaptedPath ) ) { qWarning() << QString( "Invalid MarbleDataPath \"%1\". Using \"%2\" instead." ).arg( adaptedPath ).arg( systemPath() ); return; } runTimeMarbleDataPath = adaptedPath; } void MarbleDirs::setMarblePluginPath( const QString& adaptedPath ) { if ( !QDir::root().exists( adaptedPath ) ) { qWarning() << QString( "Invalid MarblePluginPath \"%1\". Using \"%2\" instead." ).arg( adaptedPath ).arg( pluginSystemPath() ); return; } runTimeMarblePluginPath = adaptedPath; } void MarbleDirs::debug() { mDebug() << "=== MarbleDirs: ==="; mDebug() << "Local Path:" << localPath(); mDebug() << "Plugin Local Path:" << pluginLocalPath(); mDebug() << ""; mDebug() << "Marble Data Path (Run Time) :" << runTimeMarbleDataPath; mDebug() << "Marble Data Path (Compile Time):" << QString(MARBLE_DATA_PATH); mDebug() << ""; mDebug() << "Marble Plugin Path (Run Time) :" << runTimeMarblePluginPath; mDebug() << "Marble Plugin Path (Compile Time):" << QString(MARBLE_PLUGIN_PATH); mDebug() << ""; mDebug() << "System Path:" << systemPath(); mDebug() << "Plugin System Path:" << pluginSystemPath(); mDebug() << "==================="; } diff --git a/src/lib/marble/MarbleGlobal.h b/src/lib/marble/MarbleGlobal.h index e33f61278..8c13b3f52 100644 --- a/src/lib/marble/MarbleGlobal.h +++ b/src/lib/marble/MarbleGlobal.h @@ -1,310 +1,310 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2007-2009 Torsten Rahn // Copyright 2007 Inge Wallin // #ifndef MARBLE_GLOBAL_H #define MARBLE_GLOBAL_H -#include +#include #include #include "marble_export.h" #include "MarbleColors.h" // #define QT_STRICT_ITERATORS namespace Marble { enum TessellationFlag { NoTessellation = 0x0, Tessellate = 0x1, RespectLatitudeCircle = 0x2, FollowGround = 0x4, PreventNodeFiltering = 0x8 }; Q_DECLARE_FLAGS(TessellationFlags, TessellationFlag) /** * @brief This enum is used to choose the projection shown in the view. */ enum Projection { Spherical, ///< Spherical projection ("Orthographic") Equirectangular, ///< Flat projection ("plate carree") Mercator, ///< Mercator projection Gnomonic, ///< Gnomonic projection Stereographic, ///< Stereographic projection LambertAzimuthal, ///< Lambert Azimuthal Equal-Area projection AzimuthalEquidistant, ///< Azimuthal Equidistant projection VerticalPerspective ///< Vertical perspective projection // NOTE: MarbleWidget::setProjection(int) relies on VerticalPerspective being the last // value above. Adjust that method if you do changes here }; /** * @brief This enum is used to choose the dimension. */ enum Dimension { Latitude, ///< Latitude Longitude ///< Longitude }; Q_DECLARE_FLAGS(Dimensions, Dimension) /** * @brief This enum is used to choose the unit chosen to measure angles. */ enum AngleUnit { DMSDegree, ///< Degrees in DMS notation DecimalDegree, ///< Degrees in decimal notation UTM ///< UTM }; /** * @brief This enum is used to choose context in which map quality gets used. */ enum ViewContext { Still, ///< still image Animation ///< animated view (e.g. while rotating the globe) }; /** * @brief This enum is used to choose the map quality shown in the view. */ enum MapQuality { OutlineQuality, ///< Only a wire representation is drawn LowQuality, ///< Low resolution (e.g. interlaced) NormalQuality, ///< Normal quality HighQuality, ///< High quality (e.g. antialiasing for lines) PrintQuality ///< Print quality }; /** * @brief This enum is used to specify the proxy that is used. */ enum ProxyType { HttpProxy, ///< Uses an Http proxy Socks5Proxy ///< Uses a Socks5Proxy }; /** * @brief This enum is used to choose the localization of the labels. */ enum LabelPositionFlag { NoLabel = 0x0, LineStart = 0x1, LineCenter = 0x2, LineEnd = 0x4, IgnoreXMargin = 0x8, IgnoreYMargin = 0x10, FollowLine = 0x20 }; Q_DECLARE_FLAGS(LabelPositionFlags, LabelPositionFlag) /** * @brief This enum is used to choose the localization of the labels. */ enum LabelLocalization { CustomAndNative, ///< Custom and native labels Custom, ///< Shows the name in the user's language Native ///< Display the name in the official language and /// glyphs of the labeled place. }; /** * @brief This enum is used to choose how the globe behaves while dragging. */ enum DragLocation { KeepAxisVertically, ///< Keep planet axis vertically FollowMousePointer ///< Follow mouse pointer exactly }; /** * @brief This enum is used to choose how the globe behaves while dragging. */ enum OnStartup { ShowHomeLocation, ///< Show home location on startup LastLocationVisited ///< Show last location visited on quit }; enum AltitudeMode { ClampToGround, ///< Altitude always sticks to ground level RelativeToGround, ///< Altitude is always given relative to ground level Absolute, ///< Altitude is given relative to the sealevel RelativeToSeaFloor, ///< Altitude is given relative to the sea floor ClampToSeaFloor ///< Altitude always sticks to sea floor }; enum Pole { AnyPole, ///< Any pole NorthPole, ///< Only North Pole SouthPole ///< Only South Pole }; /** * @brief This enum is used to describe the type of download */ enum DownloadUsage { DownloadBulk, ///< Bulk download, for example "File/Download region" DownloadBrowse ///< Browsing mode, normal operation of Marble, like a web browser }; /** * @brief Describes possible flight mode (interpolation between source * and target camera positions) */ enum FlyToMode { Automatic, ///< A sane value is chosen automatically depending on animation settings and the action Instant, ///< Change camera position immediately (no interpolation) Linear, ///< Linear interpolation of lon, lat and distance to ground Jump ///< Linear interpolation of lon and lat, distance increases towards the middle point, then decreases }; /** * @brief Search mode: Global (worldwide) versus area (local, regional) search */ enum SearchMode { GlobalSearch, ///< Search a whole planet AreaSearch ///< Search a certain region of a planet (e.g. visible region) }; /** * @brief */ enum RenderStatus { Complete, ///< All data is there and up to date WaitingForUpdate, ///< Rendering is based on complete, but outdated data, data update was requested WaitingForData, ///< Rendering is based on no or partial data, more data was requested (e.g. pending network queries) Incomplete ///< Data is missing and some error occurred when trying to retrieve it (e.g. network failure) }; const int defaultLevelZeroColumns = 2; const int defaultLevelZeroRows = 1; // Conversion Metric / Imperial System: km vs. miles const qreal MI2KM = 1.609344; const qreal KM2MI = 1.0 / MI2KM; // Conversion Nautical / Imperial System: nm vs. km const qreal NM2KM = 1.852; const qreal KM2NM = 1.0 / NM2KM; const qreal NM2FT = 6080; // nm feet // Conversion Metric / Imperial System: meter vs. feet const qreal M2FT = 3.2808; const qreal FT2M = 1.0 / M2FT; // Conversion Metric / Imperial System: meter vs inch const qreal M2IN = 39.3701; const qreal IN2M = 1.0 / M2IN; // Conversion Metric / Imperial System: meter vs yard const qreal M2YD = 1.09361; const qreal YD2M = 1.0 / M2YD; // Conversion meter vs millimeter const qreal M2MM = 1000.0; const qreal MM2M = 1.0 / M2MM; // Conversion meter vs centimeter const qreal M2CM = 100.0; const qreal CM2M = 1.0 / M2CM; // Conversion degree vs. radians const qreal DEG2RAD = M_PI / 180.0; const qreal RAD2DEG = 180.0 / M_PI; // Conversion meter vs kilometer const qreal KM2METER = 1000.0; const qreal METER2KM = 1.0 / KM2METER; //Conversion hour vs minute const qreal HOUR2MIN = 60.0; const qreal MIN2HOUR = 1.0 / HOUR2MIN; //Conversion (time) minute vs second const qreal MIN2SEC = 60.0; const qreal SEC2MIN = 1.0 / MIN2SEC; //Conversion hour vs second const qreal HOUR2SEC = 3600.0; const qreal SEC2HOUR = 1.0 / HOUR2SEC; // Version definitions to use with an external application (as digiKam) // String for about dialog and http user agent // FIXME: check if blanks are allowed in user agent version numbers const QString MARBLE_VERSION_STRING = QString::fromLatin1( "0.26.20 (0.27 development version)" ); // API Version id: // form : 0xMMmmpp // MM = major revision. // mm = minor revision. // pp = patch revision. #define MARBLE_VERSION 0x001a14 static const char NOT_AVAILABLE[] = QT_TRANSLATE_NOOP("Marble", "not available"); const int tileDigits = 6; // Average earth radius in m // Deprecated: Please use model()->planetRadius() instead. const qreal EARTH_RADIUS = 6378137.0; // Maximum level of base tiles const int maxBaseTileLevel = 4; // Default size (width and height) of tiles const unsigned int c_defaultTileSize = 675; class MarbleGlobalPrivate; class MarbleLocale; class MARBLE_EXPORT MarbleGlobal { public: static MarbleGlobal * getInstance(); ~MarbleGlobal(); MarbleLocale * locale() const; enum Profile { Default = 0x0, SmallScreen = 0x1, HighResolution = 0x2 }; Q_DECLARE_FLAGS( Profiles, Profile ) Profiles profiles() const; void setProfiles( Profiles profiles ); /** @deprecated Profiles are detected automatically now. This only returns profiles() anymore */ MARBLE_DEPRECATED static Profiles detectProfiles(); private: MarbleGlobal(); Q_DISABLE_COPY( MarbleGlobal ) MarbleGlobalPrivate * const d; }; } Q_DECLARE_OPERATORS_FOR_FLAGS( Marble::TessellationFlags ) Q_DECLARE_OPERATORS_FOR_FLAGS( Marble::LabelPositionFlags ) Q_DECLARE_OPERATORS_FOR_FLAGS( Marble::MarbleGlobal::Profiles ) #endif diff --git a/src/lib/marble/MarbleMath.h b/src/lib/marble/MarbleMath.h index 0643defff..240c07268 100644 --- a/src/lib/marble/MarbleMath.h +++ b/src/lib/marble/MarbleMath.h @@ -1,129 +1,129 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2007 Torsten Rahn // Copyright 2007 Inge Wallin // #ifndef MARBLE_MARBLEMATH_H #define MARBLE_MARBLEMATH_H #include #include "GeoDataCoordinates.h" -#include +#include namespace { const qreal a1 = 1.0/6.0; const qreal a2 = 1.0/24.0; const qreal a3 = 61.0/5040; const qreal a4 = 277.0/72576.0; const qreal a5 = 50521.0/39916800.0; const qreal a6 = 41581.0/95800320.0; const qreal a7 = 199360981.0/1307674368000.0; const qreal a8 = 228135437.0/4184557977600.0; const qreal a9 = 2404879675441.0/121645100408832000.0; const qreal a10 = 14814847529501.0/2043637686868377600.0; const qreal a11 = 69348874393137901.0/25852016738884976640000.0; const qreal a12 = 238685140977801337.0/238634000666630553600000.0; const qreal a13 = 4087072509293123892361.0/10888869450418352160768000000.0; const qreal a14 = 454540704683713199807.0/3209350995912777478963200000.0; const qreal a15 = 441543893249023104553682821.0/8222838654177922817725562880000000.0; const qreal a16 = 2088463430347521052196056349.0/102156677868375135241390522368000000.0; } namespace Marble { /** * @brief This method calculates the shortest distance between two points on a sphere. * @brief See: http://en.wikipedia.org/wiki/Great-circle_distance * @param lon1 longitude of first point in radians * @param lat1 latitude of first point in radians * @param lon2 longitude of second point in radians * @param lat2 latitude of second point in radians */ inline qreal distanceSphere( qreal lon1, qreal lat1, qreal lon2, qreal lat2 ) { qreal h1 = sin( 0.5 * ( lat2 - lat1 ) ); qreal h2 = sin( 0.5 * ( lon2 - lon1 ) ); qreal d = h1 * h1 + cos( lat1 ) * cos( lat2 ) * h2 * h2; return 2.0 * atan2( sqrt( d ), sqrt( 1.0 - d ) ); } /** * @brief This method calculates the shortest distance between two points on a sphere. * @brief See: http://en.wikipedia.org/wiki/Great-circle_distance */ inline qreal distanceSphere( const GeoDataCoordinates& coords1, const GeoDataCoordinates& coords2 ) { qreal lon1, lat1; coords1.geoCoordinates( lon1, lat1 ); qreal lon2, lat2; coords2.geoCoordinates( lon2, lat2 ); // FIXME: Take the altitude into account! return distanceSphere( lon1, lat1, lon2, lat2 ); } /** * @brief This method roughly calculates the shortest distance between two points on a sphere. * @brief It's probably faster than distanceSphere(...) but for 7 significant digits only has * @brief an accuracy of about 1 arcmin. * @brief See: http://en.wikipedia.org/wiki/Great-circle_distance */ inline qreal distanceSphereApprox( qreal lon1, qreal lat1, qreal lon2, qreal lat2 ) { return acos( sin( lat1 ) * sin( lat2 ) + cos( lat1 ) * cos( lat2 ) * cos( lon1 - lon2 ) ); } /** * @brief This method is a fast Mac Laurin power series approximation of the * @brief inverse Gudermannian. The inverse Gudermannian gives the vertical * @brief position y in the Mercator projection in terms of the latitude. * @brief See: http://en.wikipedia.org/wiki/Mercator_projection */ inline qreal gdInv( qreal x ) { const qreal x2 = x * x; return x + x * x2 * ( a1 + x2 * ( a2 + x2 * ( a3 + x2 * ( a4 + x2 * ( a5 + x2 * ( a6 + x2 * ( a7 + x2 * ( a8 + x2 * ( a9 + x2 * ( a10 + x2 * ( a11 + x2 * ( a12 + x2 * ( a13 + x2 * ( a14 + x2 * ( a15 + x2 * ( a16 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); } } /** * @brief This method is a fast Mac Laurin power series approximation of the * Gudermannian. The Gudermannian gives the latitude * in the Mercator projection in terms of the vertical position y. * See: http://en.wikipedia.org/wiki/Mercator_projection */ inline qreal gd( qreal x ) { /* const qreal x2 = x * x; return x - x * x2 * ( a1 - x2 * ( a2 - x2 * ( a3 - x2 * ( a4 - x2 * ( a5 - x2 * ( a6 - x2 * ( a7 - x2 * ( a8 - x2 * ( a9 - x2 * ( a10 - x2 * ( a11 - x2 * ( a12 - x2 * ( a13 - x2 * ( a14 - x2 * ( a15 - x2 * ( a16 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); */ return atan ( sinh ( x ) ); } #endif diff --git a/src/lib/marble/ServerLayout.cpp b/src/lib/marble/ServerLayout.cpp index fd5818510..37670e73b 100644 --- a/src/lib/marble/ServerLayout.cpp +++ b/src/lib/marble/ServerLayout.cpp @@ -1,237 +1,237 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2010,2011 Bernhard Beschow // // Own #include "ServerLayout.h" #include "GeoSceneTileDataset.h" #include "GeoDataLatLonBox.h" #include "MarbleGlobal.h" #include "TileId.h" #include -#include +#include namespace Marble { ServerLayout::ServerLayout( GeoSceneTileDataset *textureLayer ) : m_textureLayer( textureLayer ) { } ServerLayout::~ServerLayout() { } MarbleServerLayout::MarbleServerLayout( GeoSceneTileDataset *textureLayer ) : ServerLayout( textureLayer ) { } QUrl MarbleServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const { const QString path = QString( "%1/%2/%3/%3_%4.%5" ) .arg( prototypeUrl.path() ) .arg( id.zoomLevel() ) .arg(id.y(), tileDigits, 10, QLatin1Char('0')) .arg(id.x(), tileDigits, 10, QLatin1Char('0')) .arg( m_textureLayer->fileFormat().toLower() ); QUrl url = prototypeUrl; url.setPath( path ); return url; } QString MarbleServerLayout::name() const { return "Marble"; } QString ServerLayout::sourceDir() const { return m_textureLayer ? m_textureLayer->sourceDir() : QString(); } OsmServerLayout::OsmServerLayout( GeoSceneTileDataset *textureLayer ) : ServerLayout( textureLayer ) { } QUrl OsmServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const { const QString suffix = m_textureLayer->fileFormat().toLower(); const QString path = QString( "%1/%2/%3.%4" ).arg( id.zoomLevel() ) .arg( id.x() ) .arg( id.y() ) .arg( suffix ); QUrl url = prototypeUrl; url.setPath( url.path() + path ); return url; } QString OsmServerLayout::name() const { return "OpenStreetMap"; } CustomServerLayout::CustomServerLayout( GeoSceneTileDataset *texture ) : ServerLayout( texture ) { } QUrl CustomServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const { const GeoDataLatLonBox bbox = m_textureLayer->tileProjection()->geoCoordinates(id); QString urlStr = prototypeUrl.toString( QUrl::DecodeReserved ); urlStr.replace( "{zoomLevel}", QString::number( id.zoomLevel() ) ); urlStr.replace( "{x}", QString::number( id.x() ) ); urlStr.replace( "{y}", QString::number( id.y() ) ); urlStr.replace( "{west}", QString::number( bbox.west( GeoDataCoordinates::Degree ), 'f', 12 ) ); urlStr.replace( "{south}", QString::number( bbox.south( GeoDataCoordinates::Degree ), 'f', 12 ) ); urlStr.replace( "{east}", QString::number( bbox.east( GeoDataCoordinates::Degree ), 'f', 12 ) ); urlStr.replace( "{north}", QString::number( bbox.north( GeoDataCoordinates::Degree ), 'f', 12 ) ); return QUrl( urlStr ); } QString CustomServerLayout::name() const { return "Custom"; } WmsServerLayout::WmsServerLayout( GeoSceneTileDataset *texture ) : ServerLayout( texture ) { } QUrl WmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &tileId ) const { const GeoDataLatLonBox box = m_textureLayer->tileProjection()->geoCoordinates(tileId); QUrlQuery url(prototypeUrl.query()); url.addQueryItem( "service", "WMS" ); url.addQueryItem( "request", "GetMap" ); url.addQueryItem( "version", "1.1.1" ); if ( !url.hasQueryItem( "styles" ) ) url.addQueryItem( "styles", "" ); if ( !url.hasQueryItem( "format" ) ) { if (m_textureLayer->fileFormat().toLower() == QLatin1String("jpg")) url.addQueryItem( "format", "image/jpeg" ); else url.addQueryItem("format", QLatin1String("image/") + m_textureLayer->fileFormat().toLower()); } if ( !url.hasQueryItem( "srs" ) ) { url.addQueryItem( "srs", epsgCode() ); } if ( !url.hasQueryItem( "layers" ) ) url.addQueryItem( "layers", m_textureLayer->name() ); url.addQueryItem( "width", QString::number( m_textureLayer->tileSize().width() ) ); url.addQueryItem( "height", QString::number( m_textureLayer->tileSize().height() ) ); url.addQueryItem( "bbox", QString( "%1,%2,%3,%4" ).arg( QString::number( box.west( GeoDataCoordinates::Degree ), 'f', 12 ) ) .arg( QString::number( box.south( GeoDataCoordinates::Degree ), 'f', 12 ) ) .arg( QString::number( box.east( GeoDataCoordinates::Degree ), 'f', 12 ) ) .arg( QString::number( box.north( GeoDataCoordinates::Degree ), 'f', 12 ) ) ); QUrl finalUrl = prototypeUrl; finalUrl.setQuery(url); return finalUrl; } QString WmsServerLayout::name() const { return "WebMapService"; } QString WmsServerLayout::epsgCode() const { switch (m_textureLayer->tileProjectionType()) { case GeoSceneAbstractTileProjection::Equirectangular: return "EPSG:4326"; case GeoSceneAbstractTileProjection::Mercator: return "EPSG:3785"; } Q_ASSERT( false ); // not reached return QString(); } QuadTreeServerLayout::QuadTreeServerLayout( GeoSceneTileDataset *textureLayer ) : ServerLayout( textureLayer ) { } QUrl QuadTreeServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &id ) const { QString urlStr = prototypeUrl.toString( QUrl::DecodeReserved ); urlStr.replace( "{quadIndex}", encodeQuadTree( id ) ); return QUrl( urlStr ); } QString QuadTreeServerLayout::name() const { return "QuadTree"; } QString QuadTreeServerLayout::encodeQuadTree( const Marble::TileId &id ) { QString tileNum; for ( int i = id.zoomLevel(); i >= 0; i-- ) { const int tileX = (id.x() >> i) % 2; const int tileY = (id.y() >> i) % 2; const int num = ( 2 * tileY ) + tileX; tileNum += QString::number( num ); } return tileNum; } TmsServerLayout::TmsServerLayout(GeoSceneTileDataset *textureLayer ) : ServerLayout( textureLayer ) { } QUrl TmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const { const QString suffix = m_textureLayer->fileFormat().toLower(); // y coordinate in TMS start at the bottom of the map (South) and go upwards, // opposed to OSM which start at the top. // // http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification int y_frombottom = ( 1< // Copyright 2013 Sanjiban Bairagya // #include "GeoDataModel.h" #include "GeoDataGeometry_p.h" #include "GeoDataTypes.h" #include "GeoDataLink.h" #include "GeoDataLocation.h" #include "GeoDataOrientation.h" #include "GeoDataResourceMap.h" #include "GeoDataScale.h" -#include "stdio.h" +#include namespace Marble { class GeoDataModelPrivate : public GeoDataGeometryPrivate { public: GeoDataModelPrivate(); GeoDataGeometryPrivate *copy() const override { return new GeoDataModelPrivate( *this ); } GeoDataCoordinates m_coordinates; GeoDataScale m_scale; GeoDataOrientation m_orientation; GeoDataLocation m_location; GeoDataLink m_link; GeoDataResourceMap m_map; QString m_targetHref; QString m_sourceHref; }; GeoDataModelPrivate::GeoDataModelPrivate() : m_coordinates(), m_scale(), m_orientation(), m_location(), m_link(), m_map(), m_targetHref(), m_sourceHref() { } GeoDataModel::GeoDataModel() : GeoDataGeometry( new GeoDataModelPrivate ) { setAltitudeMode( ClampToGround ); } GeoDataModel::GeoDataModel( const GeoDataModel &other ) : GeoDataGeometry( other ) { // nothing to do } GeoDataModel &GeoDataModel::operator=( const GeoDataModel &other ) { GeoDataGeometry::operator=( other ); return *this; } const char *GeoDataModel::nodeType() const { return GeoDataTypes::GeoDataModelType; } EnumGeometryId GeoDataModel::geometryId() const { return GeoDataModelId; } GeoDataGeometry *GeoDataModel::copy() const { return new GeoDataModel(*this); } bool GeoDataModel::operator==( const GeoDataModel &other ) const { Q_D(const GeoDataModel); const GeoDataModelPrivate *other_d = other.d_func(); return equals(other) && d->m_coordinates == other_d->m_coordinates && d->m_scale == other_d->m_scale && d->m_orientation == other_d->m_orientation && d->m_location == other_d->m_location && d->m_link == other_d->m_link && d->m_map == other_d->m_map && d->m_targetHref == other_d->m_targetHref && d->m_sourceHref == other_d->m_sourceHref; } bool GeoDataModel::operator!=( const GeoDataModel &other ) const { return !this->operator==( other ); } GeoDataModel::~GeoDataModel() { } const GeoDataCoordinates &GeoDataModel::coordinates() const { Q_D(const GeoDataModel); return d->m_coordinates; } GeoDataCoordinates &GeoDataModel::coordinates() { detach(); Q_D(GeoDataModel); return d->m_coordinates; } const GeoDataLocation &GeoDataModel::location() const { Q_D(const GeoDataModel); return d->m_location; } GeoDataLocation &GeoDataModel::location() { detach(); Q_D(GeoDataModel); return d->m_location; } void GeoDataModel::setCoordinates(const GeoDataCoordinates &coordinates) { detach(); Q_D(GeoDataModel); d->m_coordinates = coordinates; } void GeoDataModel::setLocation(const GeoDataLocation &location) { detach(); Q_D(GeoDataModel); d->m_location = location; } const GeoDataLink &GeoDataModel::link() const { Q_D(const GeoDataModel); return d->m_link; } GeoDataLink &GeoDataModel::link() { detach(); Q_D(GeoDataModel); return d->m_link; } void GeoDataModel::setLink( const GeoDataLink &link ) { detach(); Q_D(GeoDataModel); d->m_link = link; } const GeoDataScale &GeoDataModel::scale() const { Q_D(const GeoDataModel); return d->m_scale; } GeoDataScale &GeoDataModel::scale() { detach(); Q_D(GeoDataModel); return d->m_scale; } void GeoDataModel::setScale(const GeoDataScale &scale) { detach(); Q_D(GeoDataModel); d->m_scale = scale; } const GeoDataOrientation &GeoDataModel::orientation() const { Q_D(const GeoDataModel); return d->m_orientation; } GeoDataOrientation &GeoDataModel::orientation() { detach(); Q_D(GeoDataModel); return d->m_orientation; } void GeoDataModel::setOrientation(const GeoDataOrientation &orientation) { detach(); Q_D(GeoDataModel); d->m_orientation = orientation; } const GeoDataResourceMap &GeoDataModel::resourceMap() const { Q_D(const GeoDataModel); return d->m_map; } GeoDataResourceMap &GeoDataModel::resourceMap() { detach(); Q_D(GeoDataModel); return d->m_map; } void GeoDataModel::setResourceMap(const GeoDataResourceMap &map) { detach(); Q_D(GeoDataModel); d->m_map = map; } QString GeoDataModel::targetHref() const { Q_D(const GeoDataModel); return d->m_map.targetHref(); } void GeoDataModel::setTargetHref(const QString &targetHref) { detach(); Q_D(GeoDataModel); d->m_map.setTargetHref( targetHref ); } QString GeoDataModel::sourceHref() const { Q_D(const GeoDataModel); return d->m_map.sourceHref(); } void GeoDataModel::setSourceHref(const QString &sourceHref) { detach(); Q_D(GeoDataModel); d->m_map.setSourceHref( sourceHref ); } } diff --git a/src/plugins/positionprovider/flightgear/FlightGearPositionProviderPlugin.cpp b/src/plugins/positionprovider/flightgear/FlightGearPositionProviderPlugin.cpp index b27a8f1d5..624b4448f 100644 --- a/src/plugins/positionprovider/flightgear/FlightGearPositionProviderPlugin.cpp +++ b/src/plugins/positionprovider/flightgear/FlightGearPositionProviderPlugin.cpp @@ -1,231 +1,231 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2012 Ralf Habacker // #include "FlightGearPositionProviderPlugin.h" #include "MarbleDebug.h" -#include +#include #include #include using namespace Marble; /* TRANSLATOR Marble::FlightGearPositionProviderPlugin */ using namespace std; FlightGearPositionProviderPlugin::FlightGearPositionProviderPlugin() : m_socket(0), m_speed( 0.0 ), m_track( 0.0 ) { } FlightGearPositionProviderPlugin::~FlightGearPositionProviderPlugin() { delete m_socket; } QString FlightGearPositionProviderPlugin::name() const { return tr( "FlightGear position provider Plugin" ); } QString FlightGearPositionProviderPlugin::nameId() const { return QStringLiteral("flightgear"); } QString FlightGearPositionProviderPlugin::guiString() const { return tr( "FlightGear" ); } QString FlightGearPositionProviderPlugin::version() const { return QStringLiteral("1.0"); } QString FlightGearPositionProviderPlugin::description() const { return tr( "Reports the position of running flightgear application." ); } QString FlightGearPositionProviderPlugin::copyrightYears() const { return QStringLiteral("2012"); } QVector FlightGearPositionProviderPlugin::pluginAuthors() const { return QVector() << PluginAuthor(QStringLiteral("Ralf Habacker"), QStringLiteral("ralf.habacker@freenet.de")); } QIcon FlightGearPositionProviderPlugin::icon() const { return QIcon(); } void FlightGearPositionProviderPlugin::initialize() { m_status = PositionProviderStatusAcquiring; emit statusChanged( m_status ); m_socket = new QUdpSocket(this); m_socket->bind(QHostAddress::LocalHost, 5500); connect(m_socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); } /** fixed case where wrong date format is used '2404112' instead of '240412' */ bool fixBadGPRMC(QByteArray &line) { if (!line.startsWith("$GPRMC")) return false; QStringList parts = QString(line).split(QLatin1Char(',')); if (parts[9].size() == 7) { parts[9].remove(4,1); line = parts.join(QLatin1Char(',')).toLatin1(); // update crc int crc = 0; for(int i=1; i < line.size()-3; i++) { crc ^= (int) line[i]; } parts[11] = parts[11][0] + parts[11][1] + QString::number(crc, 16).toUpper(); line = parts.join(QLatin1Char(',')).toLatin1(); return true; } return false; } void FlightGearPositionProviderPlugin::readPendingDatagrams() { while (m_socket->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(m_socket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; m_socket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); typedef QList::Iterator Iterator; QList split = datagram.split('\n'); for (Iterator i = split.begin(); i != split.end(); i++) { fixBadGPRMC(*i); i->append( "\n" ); parseNmeaSentence( *i ); } } } void FlightGearPositionProviderPlugin::parseNmeaSentence( const QString &sentence ) { PositionProviderStatus oldStatus = m_status; GeoDataCoordinates oldPosition = m_position; if ( sentence.startsWith( QLatin1String( "$GPRMC" ) ) ) { QStringList const values = sentence.split(QLatin1Char(',')); if ( values.size() > 9 ) { if (values[2] == QLatin1String("A")) { m_speed = values[7].toDouble() * 0.514444; // knots => m/s m_track = values[8].toDouble(); QString const date = values[9] + QLatin1Char(' ') + values[1]; m_timestamp = QDateTime::fromString( date, "ddMMyy HHmmss" ); if (m_timestamp.date().year() <= 1930 && m_timestamp.date().year() >= 1900 ) { m_timestamp = m_timestamp.addYears( 100 ); // Qt range is 1900-1999 for two-digits } } // Flightgear submits geoposition twice in one datagram, once // in GPRMC and once in GPGGA. Parsing one is sufficient } } else if ( sentence.startsWith( QLatin1String( "$GPGGA" ) ) ) { QStringList const values = sentence.split(QLatin1Char(',')); if ( values.size() > 10 ) { if ( values[6] == 0 ) { m_status = PositionProviderStatusAcquiring; // no fix } else { double const lat = parsePosition(values[2], values[3] == QLatin1String("S")); double const lon = parsePosition(values[4], values[5] == QLatin1String("W")); double const unitFactor = values[10] == QLatin1String("F") ? FT2M : 1.0; double const alt = unitFactor * values[9].toDouble(); m_position.set( lon, lat, alt, GeoDataCoordinates::Degree ); m_accuracy.level = GeoDataAccuracy::Detailed; m_status = PositionProviderStatusAvailable; } } } else { return; } if ( m_status != oldStatus ) { emit statusChanged( m_status ); } if ( m_position != oldPosition && m_status == PositionProviderStatusAvailable ) { emit positionChanged( m_position, m_accuracy ); } } double FlightGearPositionProviderPlugin::parsePosition( const QString &value, bool isNegative ) { double pos = value.toDouble(); pos = int( pos / 100.0 ) + ( pos - 100.0 * int( pos / 100.0 ) ) / 60.0; return isNegative ? -qAbs( pos ) : pos; } bool FlightGearPositionProviderPlugin::isInitialized() const { return m_socket; } PositionProviderPlugin* FlightGearPositionProviderPlugin::newInstance() const { return new FlightGearPositionProviderPlugin; } PositionProviderStatus FlightGearPositionProviderPlugin::status() const { return m_status; } GeoDataCoordinates FlightGearPositionProviderPlugin::position() const { return m_position; } GeoDataAccuracy FlightGearPositionProviderPlugin::accuracy() const { return m_accuracy; } qreal FlightGearPositionProviderPlugin::speed() const { return m_speed; } qreal FlightGearPositionProviderPlugin::direction() const { return m_track; } QDateTime FlightGearPositionProviderPlugin::timestamp() const { return m_timestamp; } QString FlightGearPositionProviderPlugin::error() const { return QString(); } #include "moc_FlightGearPositionProviderPlugin.cpp" diff --git a/src/plugins/positionprovider/gpsd/GpsdConnection.cpp b/src/plugins/positionprovider/gpsd/GpsdConnection.cpp index 7dcc9013e..ca9d84173 100644 --- a/src/plugins/positionprovider/gpsd/GpsdConnection.cpp +++ b/src/plugins/positionprovider/gpsd/GpsdConnection.cpp @@ -1,144 +1,144 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2009 Eckhart Wörner // Copyright 2011 Bastian Holst // #include "GpsdConnection.h" #include "MarbleDebug.h" #include -#include +#include #include using namespace Marble; /* TRANSLATOR Marble::GpsdConnection */ const int gpsUpdateInterval = 1000; // ms const int gpsWaitTimeout = 200; // ms GpsdConnection::GpsdConnection( QObject* parent ) : QObject( parent ), #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 ) m_gpsd( "localhost", DEFAULT_GPSD_PORT ), #endif m_timer( 0 ) { m_oldLocale = setlocale( LC_NUMERIC, NULL ); setlocale( LC_NUMERIC, "C" ); connect( &m_timer, SIGNAL(timeout()), this, SLOT(update()) ); } GpsdConnection::~GpsdConnection() { setlocale( LC_NUMERIC, m_oldLocale ); } void GpsdConnection::initialize() { m_timer.stop(); bool success = false; #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 ) success = true; #else gps_data_t* data = m_gpsd.open(); success = ( data != 0 ); #endif #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 3 ) && defined( WATCH_ENABLE ) if ( success ) { success = (m_gpsd.stream( WATCH_ENABLE ) != NULL); } #endif if ( success ) { m_status = PositionProviderStatusAcquiring; emit statusChanged( m_status ); m_timer.start( gpsUpdateInterval ); } else { // There is also gps_errstr() for libgps version >= 2.90, // but it doesn't return a sensible error description switch ( errno ) { case NL_NOSERVICE: m_error = tr("Internal gpsd error (cannot get service entry)"); break; case NL_NOHOST: m_error = tr("Internal gpsd error (cannot get host entry)"); break; case NL_NOPROTO: m_error = tr("Internal gpsd error (cannot get protocol entry)"); break; case NL_NOSOCK: m_error = tr("Internal gpsd error (unable to create socket)"); break; case NL_NOSOCKOPT: m_error = tr("Internal gpsd error (unable to set socket option)"); break; case NL_NOCONNECT: m_error = tr("No GPS device found by gpsd."); break; default: m_error = tr("Unknown error when opening gpsd connection"); break; } m_status = PositionProviderStatusError; emit statusChanged( m_status ); mDebug() << "Connection to gpsd failed, no position info available: " << m_error; } } void GpsdConnection::update() { #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 4 ) && defined( PACKET_SET ) gps_data_t *data = 0; QTime watchdog; watchdog.start(); #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 ) while ( m_gpsd.waiting( 0 ) && watchdog.elapsed() < gpsWaitTimeout ) { gps_data_t *currentData = m_gpsd.read(); #else while ( m_gpsd.waiting() && watchdog.elapsed() < gpsWaitTimeout ) { gps_data_t *currentData = m_gpsd.poll(); #endif if( currentData && currentData->set & PACKET_SET ) { data = currentData; } } if ( data ) { emit gpsdInfo( *data ); } #else #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION == 3 ) && defined( PACKET_SET ) gps_data_t *data = m_gpsd.poll(); #else gps_data_t* data = m_gpsd.query( "o" ); #endif if ( data ) { emit gpsdInfo( *data ); } else if ( m_status != PositionProviderStatusAcquiring ) { mDebug() << "Lost connection to gpsd, trying to re-open."; initialize(); } #endif } QString GpsdConnection::error() const { return m_error; } #include "moc_GpsdConnection.cpp" diff --git a/src/plugins/render/satellites/SatellitesModel.cpp b/src/plugins/render/satellites/SatellitesModel.cpp index bc87ee623..d5c6bdf72 100644 --- a/src/plugins/render/satellites/SatellitesModel.cpp +++ b/src/plugins/render/satellites/SatellitesModel.cpp @@ -1,272 +1,272 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2011 Guillaume Martres // #include "SatellitesModel.h" #include "MarbleDebug.h" #include "MarbleDirs.h" #include "SatellitesMSCItem.h" #include "SatellitesTLEItem.h" #include "MarbleClock.h" #include "GeoDataPlacemark.h" #include "GeoDataStyle.h" #include "GeoDataIconStyle.h" #include "GeoDataLabelStyle.h" #include "GeoDataLineStyle.h" #include #include -#include +#include namespace Marble { SatellitesModel::SatellitesModel( GeoDataTreeModel *treeModel, const MarbleClock *clock ) : TrackerPluginModel( treeModel ), m_clock( clock ), m_currentColorIndex( 0 ) { setupColors(); connect(m_clock, SIGNAL(timeChanged()), this, SLOT(update())); } void SatellitesModel::setupColors() { m_colorList.push_back( Oxygen::brickRed4 ); m_colorList.push_back( Oxygen::raspberryPink4 ); m_colorList.push_back( Oxygen::burgundyPurple4 ); m_colorList.push_back( Oxygen::grapeViolet4 ); m_colorList.push_back( Oxygen::skyBlue4 ); m_colorList.push_back( Oxygen::seaBlue4 ); m_colorList.push_back( Oxygen::emeraldGreen4 ); m_colorList.push_back( Oxygen::forestGreen4 ); m_colorList.push_back( Oxygen::sunYellow4 ); m_colorList.push_back( Oxygen::hotOrange4 ); m_colorList.push_back( Oxygen::aluminumGray4 ); m_colorList.push_back( Oxygen::woodBrown4 ); } QColor SatellitesModel::nextColor() { if (m_colorList.isEmpty()) { return Oxygen::brickRed4; } if (m_currentColorIndex < m_colorList.size()) { m_currentColorIndex++; return m_colorList[m_currentColorIndex-1]; } else { m_currentColorIndex = 1; return m_colorList[0]; } return Oxygen::brickRed4; } void SatellitesModel::loadSettings( const QHash &settings ) { QStringList idList = settings[QStringLiteral("idList")].toStringList(); m_enabledIds = idList; updateVisibility(); } void SatellitesModel::setPlanet( const QString &planetId ) { if( m_lcPlanet != planetId ) { mDebug() << "Planet changed from" << m_lcPlanet << "to" << planetId; m_lcPlanet = planetId; updateVisibility(); } } void SatellitesModel::updateVisibility() { beginUpdateItems(); for( TrackerPluginItem *obj: items() ) { SatellitesMSCItem *oItem = dynamic_cast(obj); if( oItem != NULL ) { bool enabled = ( ( oItem->relatedBody().toLower() == m_lcPlanet ) && ( m_enabledIds.contains( oItem->id() ) ) ); oItem->setEnabled( enabled ); if( enabled ) { oItem->update(); } } SatellitesTLEItem *eItem = dynamic_cast(obj); if( eItem != NULL ) { // TLE satellites are always earth satellites bool enabled = (m_lcPlanet == QLatin1String("earth")); eItem->setEnabled( enabled ); if( enabled ) { eItem->update(); } } } endUpdateItems(); } void SatellitesModel::parseFile( const QString &id, const QByteArray &data ) { // catalog files are comma serparated while tle files // are not allowed to contain commas, so we use this // to distinguish between those two if( data.contains( ',' ) ) { parseCatalog( id, data ); } else { parseTLE( id, data ); } emit fileParsed( id ); } void SatellitesModel::parseCatalog( const QString &id, const QByteArray &data ) { // For details see: // http://techbase.kde.org/Projects/Marble/SatelliteCatalogFormat mDebug() << "Reading satellite catalog from:" << id; QTextStream ts(data); int index = 1; beginUpdateItems(); QString line = ts.readLine(); for( ; !line.isNull(); line = ts.readLine() ) { if (line.trimmed().startsWith(QLatin1Char('#'))) { continue; } QStringList elms = line.split(", "); // check for '<' instead of '==' in order to allow fields to be added // to catalogs later without breaking the code if( elms.size() < 14 ) { mDebug() << "Skipping line:" << elms << "(" << line << ")"; continue; } QString name( elms[0] ); QString category( elms[1] ); QString body( elms[2] ); QByteArray body8Bit = body.toLocal8Bit(); char *cbody = const_cast( body8Bit.constData() ); mDebug() << "Loading" << category << name; PlanetarySats *planSat = new PlanetarySats(); planSat->setPlanet( cbody ); planSat->setStateVector( elms[7].toFloat() - 2400000.5, elms[8].toFloat(), elms[9].toFloat(), elms[10].toFloat(), elms[11].toFloat(), elms[12].toFloat(), elms[13].toFloat() ); planSat->stateToKepler(); QDateTime missionStart, missionEnd; if( elms[3].toUInt() > 0 ) { missionStart = QDateTime::fromTime_t( elms[3].toUInt() ); } if( elms[4].toUInt() > 0 ) { missionEnd = QDateTime::fromTime_t( elms[4].toUInt() ); } SatellitesMSCItem *item = new SatellitesMSCItem( name, category, body, id, missionStart, missionEnd, index++, planSat, m_clock ); GeoDataStyle::Ptr style(new GeoDataStyle( *item->placemark()->style() )); style->lineStyle().setPenStyle( Qt::SolidLine ); style->lineStyle().setColor( nextColor() ); style->labelStyle().setGlow( true ); // use special icon for moons if (category == QLatin1String("Moons")) { style->iconStyle().setIconPath(QStringLiteral(":/icons/moon.png")); } else { style->iconStyle().setIconPath(MarbleDirs::path(QStringLiteral("bitmaps/satellite.png"))); } item->placemark()->setStyle( style ); item->placemark()->setVisible( ( body.toLower() == m_lcPlanet ) ); addItem( item ); } endUpdateItems(); } void SatellitesModel::parseTLE( const QString &id, const QByteArray &data ) { mDebug() << "Reading satellite TLE data from:" << id; QList tleLines = data.split( '\n' ); // File format: One line of description, two lines of TLE, last line is empty if ( tleLines.size() % 3 != 1 ) { mDebug() << "Malformated satellite data file"; } beginUpdateItems(); //FIXME: terrible hack because twoline2rv uses sscanf setlocale( LC_NUMERIC, "C" ); double startmfe, stopmfe, deltamin; elsetrec satrec; int i = 0; while ( i < tleLines.size() - 1 ) { QString satelliteName = QString( tleLines.at( i++ ) ).trimmed(); char line1[130]; char line2[130]; if( tleLines.at( i ).size() >= 79 || tleLines.at( i+1 ).size() >= 79 ) { mDebug() << "Invalid TLE data!"; return; } qstrcpy( line1, tleLines.at( i++ ).constData() ); qstrcpy( line2, tleLines.at( i++ ).constData() ); twoline2rv( line1, line2, 'c', 'd', 'i', wgs84, startmfe, stopmfe, deltamin, satrec ); if ( satrec.error != 0 ) { mDebug() << "Error: " << satrec.error; return; } SatellitesTLEItem *item = new SatellitesTLEItem( satelliteName, satrec, m_clock ); GeoDataStyle::Ptr style(new GeoDataStyle( *item->placemark()->style() )); style->lineStyle().setPenStyle( Qt::SolidLine ); style->lineStyle().setColor( nextColor() ); style->labelStyle().setGlow( true ); style->iconStyle().setIconPath(MarbleDirs::path(QStringLiteral("bitmaps/satellite.png"))); item->placemark()->setStyle( style ); addItem( item ); } //Reset to environment setlocale( LC_NUMERIC, "" ); endUpdateItems(); } } // namespace Marble #include "moc_SatellitesModel.cpp"