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

Last change on this file since 2805 was 2805, checked in by weber, 13 years ago

Newline at end of file added

File size: 4.5 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 = 25; // shift longitude
14 _mapScen = new QGraphicsScene();
15 _mapView = new BncMapView();
16 _mapView->setScene(_mapScen);
17 _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
18 slotReadMap();
19 slotCreateMap();
20 _mapScen->setSceneRect(QRect(0,-90,360,180));
21
22 setWindowTitle(tr("Source-Table Map [*]"));
23
24 /* close button */
25 QPushButton* buttClose = new QPushButton("Close");
26 connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
27
28 /* rescale button */
29 QPushButton* buttClean = new QPushButton("Clean");
30 connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
31
32 /* reset button */
33 QPushButton* buttReset = new QPushButton("Reset");
34 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
35
36 /* zoom button */
37 QPushButton* buttZoomIn = new QPushButton("Zoom +");
38 connect(buttZoomIn, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
39
40 /* zoom button */
41 QPushButton* buttZoomOut = new QPushButton("Zoom -");
42 connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
43
44 /* fit button */
45 QPushButton* buttFit = new QPushButton("Fit");
46 connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
47
48 /* layout */
49 QVBoxLayout* MapLayout = new QVBoxLayout;
50 QHBoxLayout* ButLayout = new QHBoxLayout;
51
52 ButLayout->addWidget(buttZoomIn);
53 ButLayout->addWidget(buttZoomOut);
54 ButLayout->addWidget(buttClean);
55 ButLayout->addWidget(buttReset);
56 ButLayout->addWidget(buttFit);
57 ButLayout->addWidget(buttClose);
58
59 MapLayout->addWidget(_mapView);
60 MapLayout->addLayout(ButLayout);
61
62 setLayout(MapLayout);
63
64 this->show();
65}
66
67
68// ------------
69bncMap::~bncMap(){
70 delete _mapView;
71}
72
73
74// ------------
75void bncMap::slotReadMap()
76{
77 QFile world(":worldmap.dat");
78 float fi, la;
79
80 world.open(QIODevice::ReadOnly | QIODevice::Text);
81
82 QTextStream in(&world);
83 in.setRealNumberNotation(QTextStream::FixedNotation);
84
85 while( ! in.atEnd() ){
86
87 in >> la >> fi;
88
89 // la = 0-360
90 while( la < 0 ){ la += 360; }
91 while( la >= 360 ){ la -= 360; }
92
93 // fi opposite
94 _worldMap << QPointF( la, -fi );
95
96 }
97 world.close();
98}
99
100
101// ------------
102void bncMap::slotCreateMap()
103{
104 // _mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
105
106 int begIdx = 0;
107 int endIdx = 0;
108 for( int i=0; i < _worldMap.size(); i++ ){
109 if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
110 if( i > 0 ){
111 endIdx = i-1;
112 while( begIdx < endIdx ){
113
114 int l1 = 0;
115 int l2 = 0;
116
117 float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
118 float fi1 = _worldMap.at(begIdx+0).y();
119 float la2 = _worldMap.at(begIdx+1).x() + _LaOff;
120 float fi2 = _worldMap.at(begIdx+1).y();
121 begIdx++;
122
123 while( la1 < 0 ){ la1 += 360; l1++; }
124 while( la1 >= 360 ){ la1 -= 360; l1--; }
125 while( la2 < 0 ){ la2 += 360; l2++; }
126 while( la2 >= 360 ){ la2 -= 360; l2--; }
127
128 if( l1 != 0 and l2 == 0 ){ continue; } // break this line
129 if( l2 != 0 and l1 == 0 ){ continue; } // break this line
130
131 _mapScen->addLine(la1, fi1, la2, fi2, QPen(QBrush(Qt::gray),0.3));
132 }
133 }
134 if( i+1 < _worldMap.size() ) begIdx = i+1;
135 }
136 }
137}
138
139
140// ------------
141void bncMap::slotCleanMap()
142{
143 QMutexLocker locker(&_mutexMap);
144 _mapScen->clear();
145 slotCreateMap();
146 slotResetMap();
147}
148
149
150// ------------
151void bncMap::slotResetMap()
152{
153 _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
154}
155
156
157// ------------
158void bncMap::slotZoomIn()
159{
160 _mapView->scale( 1.2, 1.2 );
161}
162
163
164// ------------
165void bncMap::slotZoomOut()
166{
167 _mapView->scale( 1/1.2, 1/1.2 );
168}
169
170
171// ------------
172void bncMap::slotFitMap()
173{
174 QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10);
175
176 _mapView->updateSceneRect(reg);
177 _mapView->centerOn(reg.center());
178 _mapView->fitInView(reg,Qt::KeepAspectRatio);
179}
180
181
182// ------------
183void bncMap::slotNewPoint(QPointF point, QString name, QPen pen)
184{
185 float la = point.x() + _LaOff;
186 float fi = - point.y();
187
188 while( la < 0 ){ la += 360; }
189 while( la >= 360 ){ la -= 360; }
190
191 _allPoints << QPointF(la, fi);
192 _mapScen->addEllipse( la, fi, 1.5, 1.5, pen );
193
194 if( ! name.isEmpty() ){
195 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
196 nameItem->setPos( QPointF(la-1, fi-2));
197 nameItem->setFont( QFont("Arial", 2, 1) );
198
199 _mapScen->addItem( nameItem );
200 }
201}
Note: See TracBrowser for help on using the repository browser.