-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThreadTrack2Point.cpp
101 lines (90 loc) · 2.7 KB
/
ThreadTrack2Point.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "ThreadTrack2Point.h"
#ifndef FITC
#include "FitListener.h"
#else
#include "FitParser.h"
#endif
#include "GpxParser.h"
#include "TourData.h"
#include "HelperFunctions.h"
#include <QFileInfo>
#include <QDebug>
ThreadTrack2Point::ThreadTrack2Point(double latitude, double longitude, QMutex *mutex, uint32_t *cnt, QTreeWidgetItem *item)
: m_pItem( item ),
m_pMutex( mutex ),
m_pCnt( cnt ),
m_latitude( latitude ),
m_longitude( longitude )
{
}
void ThreadTrack2Point::run()
{
TourData *pTourData;
#ifndef FITC
FitListener fitListener;
#else
FitParser fitParser;
#endif
GpxParser gpxParser;
if( m_pMutex == nullptr || m_pCnt == nullptr ) return;
if( m_pItem == nullptr )
{
decrementThreadCnt();
return;
}
QString fileName = m_pItem->text( 1 );
if( !QFileInfo( fileName ).exists() ) return;
if( fileName.endsWith( ".fit", Qt::CaseInsensitive ) )
{
//scanFit
#ifndef FITC
fit::Decode decode;
fit::MesgBroadcaster mesgBroadcaster;
//FitListener listener;
std::fstream file;
file.open( fileName.toStdString().data(), std::ios::in | std::ios::binary);
pTourData = &fitListener;
fitListener.reset();
mesgBroadcaster.AddListener((fit::FileIdMesgListener &)fitListener);
mesgBroadcaster.AddListener((fit::MesgListener &)fitListener);
try
{
decode.Read(&file, &mesgBroadcaster, &mesgBroadcaster, &fitListener);
}
catch (const fit::RuntimeException& e)
{
printf("Exception decoding file: %s\n", e.what());
}
file.close();
#else
pTourData = &fitParser;
fitParser.loadFit( fileName );
#endif
}
else
{
//scanGpx
pTourData = &gpxParser;
gpxParser.loadGpx( fileName );
}
HelperFunctions hF;
double minDist = 99999999;
for( int i = 0; i < pTourData->getTourPosLat().size(); i++ )
{
double dist = hF.getDistanceFromLatLonInKm( m_latitude,
m_longitude,
pTourData->getTourPosLat().at(i) * ( 180 / pow(2,31) ),
pTourData->getTourPosLong().at(i) * ( 180 / pow(2,31) ) );
if( dist < minDist ) minDist = dist;
}
//qDebug() << "Minimum distance is" << minDist << "km, Trackpoints:" << pTourData->getTourPosLat().size();
m_pItem->setText( 7, QString( "%1" ).arg( minDist ) );
decrementThreadCnt();
}
void ThreadTrack2Point::decrementThreadCnt()
{
m_pMutex->lock();
*m_pCnt = *m_pCnt - 1;
//qDebug() << "Threads" << *m_pCnt;
m_pMutex->unlock();
}