source: ntrip/trunk/BNC/bnctabledlg.cpp@ 1420

Last change on this file since 1420 was 1420, checked in by weber, 15 years ago

* empty log message *

File size: 14.4 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncTableDlg
30 *
31 * Purpose: Displays the source table, allows mountpoints selection
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Dec-2005
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bnctabledlg.h"
44#include "bncgetthread.h"
45#include "bncnetqueryv2.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
52
53 setMinimumSize(600,400);
54 setWindowTitle(tr("Add Streams"));
55
56 QVBoxLayout* mainLayout = new QVBoxLayout(this);
57
58 QSettings settings;
59 _casterHostLineEdit = new QComboBox();
60 _casterHostLineEdit->setDuplicatesEnabled(false);
61 _casterHostLineEdit->setEditable(true);
62 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
63 _casterHostLineEdit->setMaximumWidth(20*ww);
64 QStringList casterHostList = settings.value("casterHostList").toStringList();
65 _casterHostLineEdit->addItem(settings.value("casterHost").toString());
66 for (int ii = 0; ii < casterHostList.count(); ii++) {
67 QString item = casterHostList[ii];
68 if (_casterHostLineEdit->findText(item, Qt::MatchFixedString) < 0) {
69 _casterHostLineEdit->addItem(item);
70 }
71 }
72 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
73 _casterPortLineEdit->setMaximumWidth(9*ww);
74 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
75 _casterUserLineEdit->setMaximumWidth(9*ww);
76 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
77 _casterPasswordLineEdit->setMaximumWidth(9*ww);
78 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
79
80 _ntripVersionComboBox = new QComboBox();
81 _ntripVersionComboBox->addItems(QString("1,2,R").split(","));
82 int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
83 if (kk != -1) {
84 _ntripVersionComboBox->setCurrentIndex(kk);
85 }
86
87 // WhatsThis
88 // ---------
89 _casterUserLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected streams. Accounts are usually provided per NTRIP broadcaster through a registration process. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>."));
90 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster hostname or IP number and port number. <u>http://www.rtcm-ntrip.org/home</u> provides information about known NTRIP broadcaster installations. Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>."));
91 _casterHostLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster hostname or IP number and port number. <u>http://www.rtcm-ntrip.org/home</u> provides information about known NTRIP broadcaster installations. Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>."));
92 _casterPasswordLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected streams. Accounts are usually provided per NTRIP broadcaster through a registration procedure. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>."));
93
94 QGridLayout* editLayout = new QGridLayout;
95 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
96 editLayout->addWidget(_casterHostLineEdit, 0, 1);
97 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
98 editLayout->addWidget(_casterPortLineEdit, 0, 3);
99 editLayout->addWidget(new QLabel(tr("NTRIP Version")), 0, 4);
100 editLayout->addWidget(_ntripVersionComboBox, 0, 5);
101 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
102 editLayout->addWidget(_casterUserLineEdit, 1, 1);
103 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
104 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
105
106 mainLayout->addLayout(editLayout);
107
108 _ntripVersionComboBox->setWhatsThis(tr("<p>Select the NTRIP transport protocol version you want to use. Implemented options are:<br>&nbsp; 1:&nbsp; NTRIP version 1, TCP/IP<br>&nbsp; 2:&nbsp; NTRIP version 2, TCP/IP<br>&nbsp; R:&nbsp; NTRIP Version 2, RTSP/RTP<br>Select option '1' if you are not sure whether the NTRIP broadcaster supports NTRIP version 2.</p>"));
109
110 _table = new QTableWidget(this);
111 _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the sourcetable from the NTRIP broadcaster. Select the desired streams line by line, using +Shift and +Ctrl when necessary. Hit 'OK' to return to the main window.</p><p>Pay attention to data field 'format'. Keep in mind that BNC can only decode and convert streams that come in RTCM Version 2.x, RTCM Version 3.x, or RTIGS format. See data field 'format-details' for available message types and their repetition rates in brackets.</p><p>The content of data field 'nmea' tells you whether a stream comes from a virtual reference station (VRS).</p>"));
112 connect(_table, SIGNAL(itemSelectionChanged()),
113 this, SLOT(slotSelectionChanged()));
114 mainLayout->addWidget(_table);
115
116 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
117 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
118
119 _buttonGet = new QPushButton(tr("Get table"), this);
120 _buttonGet->setDefault(true);
121 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
122
123 _buttonCancel = new QPushButton(tr("Cancel"), this);
124 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
125
126 _buttonOK = new QPushButton(tr("OK"), this);
127 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
128
129 QHBoxLayout* buttonLayout = new QHBoxLayout;
130 buttonLayout->addWidget(_buttonWhatsThis);
131 buttonLayout->addStretch(1);
132 buttonLayout->addWidget(_buttonGet);
133 buttonLayout->addWidget(_buttonCancel);
134 buttonLayout->addWidget(_buttonOK);
135
136 mainLayout->addLayout(buttonLayout);
137}
138
139// Destructor
140////////////////////////////////////////////////////////////////////////////
141bncTableDlg::~bncTableDlg() {
142 if (_table) {
143 for (int ir = 0; ir < _table->rowCount(); ir++) {
144 for (int ic = 0; ic < _table->columnCount(); ic++) {
145 delete _table->item(ir,ic);
146 }
147 }
148 }
149}
150
151// Read Table the caster (static)
152////////////////////////////////////////////////////////////////////////////
153t_irc bncTableDlg::getFullTable(const QString& casterHost,
154 int casterPort, QStringList& allLines,
155 bool alwaysRead) {
156
157 static QMutex mutex;
158 static QMap<QString, QStringList> allTables;
159
160 QMutexLocker locker(&mutex);
161
162 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
163 allLines = allTables.find(casterHost).value();
164 return success;
165 }
166
167 allLines.clear();
168
169 QUrl url;
170 url.setHost(casterHost);
171 url.setPort(casterPort);
172 url.setScheme("http");
173 url.setPath("/");
174
175 bncNetQueryV2 query;
176 QByteArray outData;
177 query.waitForRequestResult(url, outData);
178 if (query.status() == bncNetQuery::finished) {
179 QTextStream in(outData);
180 QString line = in.readLine();
181 while ( !line.isNull() ) {
182 allLines.append(line);
183 line = in.readLine();
184 }
185 allTables.insert(casterHost, allLines);
186 return success;
187 }
188 else {
189 return failure;
190 }
191}
192
193// Read Table from Caster
194////////////////////////////////////////////////////////////////////////////
195void bncTableDlg::slotGetTable() {
196
197 _buttonGet->setEnabled(false);
198
199 _allLines.clear();
200
201 if ( getFullTable(_casterHostLineEdit->currentText(),
202 _casterPortLineEdit->text().toInt(),
203 _allLines) != success ) {
204 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
205 _buttonGet->setEnabled(true);
206 return;
207 }
208
209 QStringList lines;
210 QStringListIterator it(_allLines);
211 while (it.hasNext()) {
212 QString line = it.next();
213 if (line.indexOf("STR") == 0) {
214 lines.push_back(line);
215 }
216 }
217
218 static const QStringList labels = QString("mountpoint,identifier,format,"
219 "format-details,carrier,system,network,country,latitude,longitude,"
220 "nmea,solution,generator,compress.,authentic.,fee,bitrate,"
221 "misc").split(",");
222
223 if (lines.size() > 0) {
224 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
225 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
226
227 QStringList hlp = lines[0].split(";");
228 _table->setColumnCount(hlp.size()-1);
229 _table->setRowCount(lines.size());
230
231 QListIterator<QString> it(lines);
232 int nRow = -1;
233 while (it.hasNext()) {
234 QStringList columns = it.next().split(";");
235 ++nRow;
236 for (int ic = 0; ic < columns.size()-1; ic++) {
237
238 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
239
240 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
241 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
242 _table->setItem(nRow, ic, it);
243 }
244 }
245 _table->sortItems(0);
246 _table->setHorizontalHeaderLabels(labels);
247 _table->setSortingEnabled(true);
248
249 int ww = QFontMetrics(this->font()).width('w');
250 _table->horizontalHeader()->resizeSection(0,10*ww);
251 _table->horizontalHeader()->resizeSection(2,8*ww);
252 _table->horizontalHeader()->resizeSection(3,15*ww);
253 _table->horizontalHeader()->resizeSection(4,8*ww);
254 _table->horizontalHeader()->resizeSection(5,8*ww);
255 _table->horizontalHeader()->resizeSection(6,8*ww);
256 _table->horizontalHeader()->resizeSection(7,8*ww);
257 _table->horizontalHeader()->resizeSection(8,8*ww);
258 _table->horizontalHeader()->resizeSection(9,8*ww);
259 _table->horizontalHeader()->resizeSection(10,8*ww);
260 _table->horizontalHeader()->resizeSection(11,8*ww);
261 _table->horizontalHeader()->resizeSection(12,15*ww);
262 _table->horizontalHeader()->resizeSection(13,8*ww);
263 _table->horizontalHeader()->resizeSection(14,8*ww);
264 _table->horizontalHeader()->resizeSection(15,8*ww);
265 _table->horizontalHeader()->resizeSection(16,8*ww);
266 _table->horizontalHeader()->resizeSection(17,15*ww);
267 }
268}
269
270// Accept slot
271////////////////////////////////////////////////////////////////////////////
272void bncTableDlg::accept() {
273
274 QSettings settings;
275 settings.setValue("casterHost", _casterHostLineEdit->currentText());
276 QStringList casterHostList;
277 for (int ii = 0; ii < _casterHostLineEdit->count(); ii++) {
278 casterHostList.push_back(_casterHostLineEdit->itemText(ii));
279 }
280 settings.setValue("casterHostList", casterHostList);
281 settings.setValue("casterPort", _casterPortLineEdit->text());
282 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
283 settings.setValue("casterUser", _casterUserLineEdit->text());
284 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
285
286 QStringList* mountPoints = new QStringList;
287
288 if (_table) {
289 for (int ir = 0; ir < _table->rowCount(); ir++) {
290 QTableWidgetItem* item = _table->item(ir,0);
291 QString format = _table->item(ir,2)->text();
292 QString latitude = _table->item(ir,8)->text();
293 QString longitude = _table->item(ir,9)->text();
294 QString nmea = _table->item(ir,10)->text();
295 QString ntripVersion = _ntripVersionComboBox->currentText();
296 format.replace(" ", "_");
297 if (_table->isItemSelected(item)) {
298 QUrl url;
299 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
300 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
301 url.setHost(_casterHostLineEdit->currentText());
302 url.setPort(_casterPortLineEdit->text().toInt());
303 url.setPath(item->text());
304
305 mountPoints->push_back(url.toString() + " " + format + " " + latitude
306 + " " + longitude + " " + nmea + " " + ntripVersion);
307 }
308 }
309 }
310 emit newMountPoints(mountPoints);
311
312 QDialog::accept();
313}
314
315// User changed the selection of mountPoints
316////////////////////////////////////////////////////////////////////////////
317void bncTableDlg::slotSelectionChanged() {
318 if (_table->selectedItems().isEmpty()) {
319 }
320}
321
322// Create RINEX skeleton header
323////////////////////////////////////////////////////////////////////////////
324void bncTableDlg::slotSkl() {
325
326 int nRows = _table->rowCount();
327 for (int iRow = 0; iRow < nRows; iRow++) {
328 if (_table->isItemSelected(_table->item(iRow,1))) {
329 QString staID = _table->item(iRow,0)->text();
330 QString net = _table->item(iRow,6)->text();
331
332 QString ftpDir;
333 QStringListIterator it(_allLines);
334 while (it.hasNext()) {
335 QString line = it.next();
336 if (line.indexOf("NET") == 0) {
337 QStringList tags = line.split(';');
338 if (tags.at(1) == net) {
339 ftpDir = tags.at(6);
340 break;
341 }
342 }
343 }
344
345 if (!ftpDir.isEmpty()) {
346 QUrl url(ftpDir);
347 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
348 "\nnot yet implemented");
349 }
350 }
351 }
352}
353
354// Whats This Help
355void bncTableDlg::slotWhatsThis() {
356QWhatsThis::enterWhatsThisMode();
357}
358
359
Note: See TracBrowser for help on using the repository browser.