source: ntrip/trunk/BNC/bncmap.cpp@ 2753

Last change on this file since 2753 was 2753, checked in by mervart, 13 years ago
File size: 3.4 KB
Line 
1// ------------
2// author: jan dousa (jan.dousa@pecny.cz)
3// ------------
4
5#include <iostream>
6#include "bncmap.h"
7
8
9// ------------
10bncMap::bncMap(QWidget* parent) : QDialog(parent)
11{
12 _scale = 2.8; // scale the map
13 _LaOff = 20; // shift longitude
14 _mapView = new QGraphicsView();
15 _mapScen = new QGraphicsScene();
16 _mapView->setScene(_mapScen);
17 slotReadMap();
18 slotCreateMap();
19
20 setWindowTitle(tr("World Map [*]"));
21
22 /* close button */
23 QPushButton* buttClose = new QPushButton("Close");
24 connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
25
26 /* reset button */
27 QPushButton* buttReset = new QPushButton("Reset");
28 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
29
30 /* layout */
31 QGridLayout *layout = new QGridLayout;
32 layout->setRowMinimumHeight( 0, 250);
33 layout->addWidget(_mapView, 0, 0, 3, 1, Qt::AlignLeft);
34 layout->addWidget(buttReset, 1, 1, 1, 1, Qt::AlignBottom);
35 layout->addWidget(buttClose, 2, 1, 1, 1, Qt::AlignBottom);
36 setLayout(layout);
37
38// this->resize(860,400);
39 this->show();
40}
41
42
43// ------------
44bncMap::~bncMap(){
45 delete _mapView;
46}
47
48
49// ------------
50void bncMap::slotReadMap()
51{
52 QString mapFile = "worldmap.dat";
53 QFile world(mapFile);
54 float fi, la;
55
56 if( world.open(QIODevice::ReadOnly) ){
57
58 QTextStream in(&world);
59 in.setRealNumberNotation(QTextStream::FixedNotation);
60
61 while( ! in.atEnd() ){
62
63 in >> la >> fi;
64 _worldMap << QPointF( la, -fi );
65
66 }
67 }else{
68 std::cerr << QString("World map cannot be found : %1\n").arg(mapFile).toAscii().data();
69 }
70 world.close();
71}
72
73
74// ------------
75void bncMap::slotCreateMap()
76{
77// mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
78
79 int begIdx = 0;
80 int endIdx = 0;
81 for( int i=0; i < _worldMap.size(); i++ ){
82 if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
83 if( i > 0 ){
84 endIdx = i-1;
85 while( begIdx < endIdx ){
86
87 int l1 = 0;
88 int l2 = 0;
89
90 float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
91 float fi1 = _worldMap.at(begIdx+0).y();
92 float la2 = _worldMap.at(begIdx+1).x() + _LaOff;
93 float fi2 = _worldMap.at(begIdx+1).y();
94 begIdx++;
95
96 while( la1 < 0 ){ la1 += 360; l1++; }
97 while( la1 >= 360 ){ la1 -= 360; l1--; }
98 while( la2 < 0 ){ la2 += 360; l2++; }
99 while( la2 >= 360 ){ la2 -= 360; l2--; }
100
101 if( l1 != 0 and l2 == 0 ){ continue; } // break this line
102 if( l2 != 0 and l1 == 0 ){ continue; } // break this line
103
104 _mapScen->addLine(la1*_scale, fi1*_scale, la2*_scale, fi2*_scale, QPen(QBrush(Qt::black),1));
105 }
106 }
107 if( i+1 < _worldMap.size() ) begIdx = i+1;
108 }
109 }
110 _mapScen->setSceneRect(0*_scale,-90*_scale,360*_scale,180*_scale);
111}
112
113
114// ------------
115void bncMap::slotResetMap()
116{
117 QMutexLocker locker(&_mutexMap);
118 _mapScen->clear();
119 slotCreateMap();
120}
121
122
123// ------------
124void bncMap::slotNewPoint(QPointF point, QString name, QPen pen)
125{
126 float la = point.x() + _LaOff;
127 float fi = point.y();
128
129 while( la < 0 ){ la += 360; }
130 while( la >= 360 ){ la -= 360; }
131
132 _mapScen->addEllipse( la*_scale, -fi*_scale, 5, 5, pen );
133
134 if( ! name.isEmpty() ){
135 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
136 nameItem->setPos( QPointF(la*_scale, -fi*_scale));
137 nameItem->setFont( QFont("Helvetica", 8) );
138
139 _mapScen->addItem( nameItem );
140 }
141}
Note: See TracBrowser for help on using the repository browser.