~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to GPS/qgps.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Robin Gingras                                   *
3
 
 *   neozenkai@cox.net                                                     *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
20
 
 
21
 
#include <Qt>
22
 
#include <QStatusBar>
23
 
#include <QSettings>
24
 
#include <QDateTime>
25
 
 
26
 
#include "qgps.h"
27
 
#include "qgpsdevice.h"
28
 
#include "qgpssatellitetracker.h"
29
 
#include "SatelliteStrengthView.h"
30
 
 
31
 
#include <iostream>
32
 
 
33
 
//#include "Preferences/MerkaartorPreferences.h"
34
 
 
35
 
QGPS::QGPS(QWidget *parent)
36
 
    : MDockAncestor(parent), gpsDevice(0)
37
 
{
38
 
        setupUi(getWidget());
39
 
        setObjectName("GPSMainWindow");
40
 
 
41
 
    int w = fontMetrics().width("360N 60'60\" W");
42
 
    txtLatitude->setFixedWidth(w);
43
 
    txtLongitude->setFixedWidth(w);
44
 
    txtAltitude->setFixedWidth(w);
45
 
    txtSpeed->setFixedWidth(w);
46
 
        txtNumSats->setFixedWidth(w);
47
 
        txtFixType->setFixedWidth(w);
48
 
        resetGpsStatus();
49
 
 
50
 
        retranslateUi();
51
 
 
52
 
    //loadSettings();
53
 
 
54
 
//    gpsDevice = new QGPSDevice(serialPort);
55
 
 
56
 
    //connect(actStartGps, SIGNAL(activated()), gpsDevice, SLOT(startDevice()));
57
 
    //connect(actStopGps, SIGNAL(activated()), gpsDevice, SLOT(stopDevice()));
58
 
 
59
 
    // The Qt documentation says that using signals and slots between
60
 
    // threaded classes is not recommended! TODO: find a better way!
61
 
}
62
 
 
63
 
void QGPS::setGpsDevice(QGPSDevice * aDevice)
64
 
{
65
 
        if (gpsDevice)
66
 
                disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
67
 
        gpsDevice = aDevice;
68
 
}
69
 
 
70
 
void QGPS::startGps()
71
 
{
72
 
        if (gpsDevice) {
73
 
                if (isVisible())
74
 
                        connect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
75
 
                gpsDevice->startDevice();
76
 
        }
77
 
}
78
 
 
79
 
void QGPS::stopGps()
80
 
{
81
 
        if (gpsDevice) {
82
 
            gpsDevice->stopDevice();
83
 
                disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
84
 
        }
85
 
}
86
 
 
87
 
void QGPS::resetGpsStatus()
88
 
{
89
 
    txtLatitude->setText("");
90
 
    txtLongitude->setText("");
91
 
    txtAltitude->setText("");
92
 
    txtSpeed->setText("");
93
 
        txtNumSats->setText("");
94
 
        txtFixType->setText(tr("Invalid"));
95
 
        
96
 
        lblFixStatus->setText(tr("No Position Fix"));
97
 
        lblFixTime->setText(tr("No UTC Time"));
98
 
 
99
 
        satTracker->setSatellites(std::vector<Satellite>());
100
 
}
101
 
 
102
 
void QGPS::updateGpsStatus()
103
 
{
104
 
    QString latCardinal, longCardinal, varCardinal;
105
 
 
106
 
    if(gpsDevice->latCardinal() == QGPSDevice::CardinalNorth)
107
 
        latCardinal = "N";
108
 
    else
109
 
        latCardinal = "S";
110
 
 
111
 
    if(gpsDevice->longCardinal() == QGPSDevice::CardinalEast)
112
 
        longCardinal = "E";
113
 
    else
114
 
        longCardinal = "W";
115
 
 
116
 
    if(gpsDevice->varCardinal() == QGPSDevice::CardinalEast)
117
 
        varCardinal = "E";
118
 
    else
119
 
        varCardinal = "W";
120
 
 
121
 
    txtLatitude->setText(
122
 
        QString("%1 %2\' %3\" %4")
123
 
            .arg(gpsDevice->latDegrees())
124
 
            .arg(gpsDevice->latMinutes())
125
 
            .arg(gpsDevice->latSeconds())
126
 
            .arg(latCardinal));
127
 
 
128
 
    txtLongitude->setText(
129
 
        QString("%1 %2\' %3\" %4")
130
 
            .arg(gpsDevice->longDegrees())
131
 
            .arg(gpsDevice->longMinutes())
132
 
            .arg(gpsDevice->longSeconds())
133
 
            .arg(longCardinal));
134
 
 
135
 
    txtAltitude->setText(
136
 
        QString("%1 %2")
137
 
            .arg(gpsDevice->altitude())
138
 
            .arg(tr("Meters")));
139
 
 
140
 
    txtSpeed->setText(
141
 
        QString("%1 %2")
142
 
            .arg(gpsDevice->speed())
143
 
            .arg(tr("km/h")));
144
 
 
145
 
        txtNumSats->setText(
146
 
        QString("%1").arg(gpsDevice->numSatellites()));
147
 
 
148
 
        switch (gpsDevice->fixType()) {
149
 
                case QGPSDevice::FixUnavailable:
150
 
                        txtFixType->setText(tr("Unavailable"));
151
 
                        break;
152
 
                case QGPSDevice::FixInvalid:
153
 
                        txtFixType->setText(tr("Invalid"));
154
 
                        break;
155
 
                case QGPSDevice::Fix2D:
156
 
                        txtFixType->setText(tr("2D"));
157
 
                        break;
158
 
                case QGPSDevice::Fix3D:
159
 
                        txtFixType->setText(tr("3D"));
160
 
                        break;
161
 
        }
162
 
 
163
 
        switch (gpsDevice->fixStatus()) {
164
 
                case QGPSDevice::StatusActive:
165
 
                        lblFixStatus->setText(tr("Position Fix available"));
166
 
                        break;
167
 
                case QGPSDevice::StatusVoid:
168
 
                        lblFixStatus->setText(tr("No Position Fix"));
169
 
                        break;
170
 
        }
171
 
 
172
 
        if (!gpsDevice->dateTime().isValid())
173
 
                lblFixTime->setText(tr("No UTC Time"));
174
 
        else
175
 
                lblFixTime->setText(gpsDevice->dateTime().toString() + " UTC");
176
 
 
177
 
        std::vector<Satellite> List;
178
 
        for(int i = 1; i < 50; i ++)
179
 
        {
180
 
                int b, x, y;
181
 
                gpsDevice->satInfo(i, b, x, y);
182
 
                if (y || b || x)
183
 
                {
184
 
                        Satellite S;
185
 
                        S.Azimuth = x;
186
 
                        S.Elevation = b;
187
 
                        S.SignalStrength = y;
188
 
                        S.Id = i;
189
 
                        List.push_back(S);
190
 
                }
191
 
        }
192
 
        StrengthView->setSatellites(List);
193
 
        satTracker->setSatellites(List);
194
 
    satTracker->setHeading((int)gpsDevice->heading());
195
 
}
196
 
 
197
 
void QGPS::showEvent ( QShowEvent * anEvent )
198
 
{
199
 
        QWidget::showEvent(anEvent);
200
 
 
201
 
        if (gpsDevice)
202
 
                connect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
203
 
}
204
 
 
205
 
void QGPS::hideEvent ( QHideEvent * anEvent )
206
 
{
207
 
        QWidget::hideEvent(anEvent);
208
 
 
209
 
        if (gpsDevice) 
210
 
                disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
211
 
}
212
 
 
213
 
void QGPS::changeEvent(QEvent * event)
214
 
{
215
 
        if (event->type() == QEvent::LanguageChange)
216
 
                retranslateUi();
217
 
        MDockAncestor::changeEvent(event);
218
 
}
219
 
 
220
 
void QGPS::retranslateUi()
221
 
{
222
 
        setWindowTitle("GPS");
223
 
        lblFixStatus->setText(tr("No Position Fix"));
224
 
        lblFixTime->setText(tr("No UTC Time"));
225
 
 
226
 
}