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

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

Scaling site distribution map from caster sourcetable contents

File size: 5.9 KB
RevLine 
[2753]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{
[3288]12 _LaOff = 25; // shift longitude
[2753]13 _mapScen = new QGraphicsScene();
[2796]14 _mapView = new BncMapView();
[2753]15 _mapView->setScene(_mapScen);
[3288]16 _mapView->resetScale();
[2753]17 slotReadMap();
18 slotCreateMap();
[2796]19 _mapScen->setSceneRect(QRect(0,-90,360,180));
[2753]20
[2796]21 setWindowTitle(tr("Source-Table Map [*]"));
[2753]22
23 /* close button */
24 QPushButton* buttClose = new QPushButton("Close");
25 connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
[2796]26
27 /* rescale button */
[3288]28// QPushButton* buttClean = new QPushButton("Clean");
29// connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
[2753]30
[2796]31 /* zoom button */
32 QPushButton* buttZoomIn = new QPushButton("Zoom +");
33 connect(buttZoomIn, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
34
35 /* zoom button */
36 QPushButton* buttZoomOut = new QPushButton("Zoom -");
37 connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
38
[3288]39 /* reset button */
40 QPushButton* buttReset = new QPushButton("World");
41 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
42
[2796]43 /* fit button */
[3288]44 QPushButton* buttFit = new QPushButton("Fit Map");
[2796]45 connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
46
[3288]47 /* font reset button */
48 QPushButton* buttFont = new QPushButton("Fit Font");
49 connect(buttFont, SIGNAL(clicked()), this, SLOT(slotFitFont()));
50
[2753]51 /* layout */
[2796]52 QVBoxLayout* MapLayout = new QVBoxLayout;
53 QHBoxLayout* ButLayout = new QHBoxLayout;
54
55 ButLayout->addWidget(buttZoomIn);
56 ButLayout->addWidget(buttZoomOut);
[3288]57// ButLayout->addWidget(buttClean);
[2796]58 ButLayout->addWidget(buttReset);
59 ButLayout->addWidget(buttFit);
[3288]60 ButLayout->addWidget(buttFont);
[2796]61 ButLayout->addWidget(buttClose);
62
63 MapLayout->addWidget(_mapView);
64 MapLayout->addLayout(ButLayout);
65
66 setLayout(MapLayout);
67
[2753]68 this->show();
69}
70
71
72// ------------
73bncMap::~bncMap(){
74 delete _mapView;
75}
76
77
78// ------------
79void bncMap::slotReadMap()
80{
[2754]81 QFile world(":worldmap.dat");
[2753]82 float fi, la;
83
[2754]84 world.open(QIODevice::ReadOnly | QIODevice::Text);
[2753]85
[2754]86 QTextStream in(&world);
87 in.setRealNumberNotation(QTextStream::FixedNotation);
[2753]88
[2754]89 while( ! in.atEnd() ){
[2753]90
[2754]91 in >> la >> fi;
[2796]92
93 // la = 0-360
94 while( la < 0 ){ la += 360; }
95 while( la >= 360 ){ la -= 360; }
96
97 // fi opposite
[2754]98 _worldMap << QPointF( la, -fi );
[2796]99
[2753]100 }
101 world.close();
102}
103
104
105// ------------
106void bncMap::slotCreateMap()
107{
[2796]108 // _mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
[2753]109
110 int begIdx = 0;
111 int endIdx = 0;
112 for( int i=0; i < _worldMap.size(); i++ ){
113 if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
114 if( i > 0 ){
[2796]115 endIdx = i-1;
[2753]116 while( begIdx < endIdx ){
117
[2796]118 int l1 = 0;
119 int l2 = 0;
[2753]120
121 float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
122 float fi1 = _worldMap.at(begIdx+0).y();
123 float la2 = _worldMap.at(begIdx+1).x() + _LaOff;
124 float fi2 = _worldMap.at(begIdx+1).y();
125 begIdx++;
[2796]126
127 while( la1 < 0 ){ la1 += 360; l1++; }
128 while( la1 >= 360 ){ la1 -= 360; l1--; }
129 while( la2 < 0 ){ la2 += 360; l2++; }
130 while( la2 >= 360 ){ la2 -= 360; l2--; }
[2753]131
[2796]132 if( l1 != 0 and l2 == 0 ){ continue; } // break this line
133 if( l2 != 0 and l1 == 0 ){ continue; } // break this line
[2753]134
[2796]135 _mapScen->addLine(la1, fi1, la2, fi2, QPen(QBrush(Qt::gray),0.3));
[2753]136 }
137 }
138 if( i+1 < _worldMap.size() ) begIdx = i+1;
139 }
140 }
141}
142
143
144// ------------
[2796]145void bncMap::slotCleanMap()
[2753]146{
147 QMutexLocker locker(&_mutexMap);
148 _mapScen->clear();
149 slotCreateMap();
[2796]150 slotResetMap();
[3288]151 slotFitFont();
[2753]152}
153
154
155// ------------
[2796]156void bncMap::slotResetMap()
157{
[3288]158 _mapView->resetScale();
[2796]159}
160
161
162// ------------
[3288]163void bncMap::slotFitMap()
[2796]164{
[3288]165 QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10);
166
167 _mapView->resetScale();
168 _mapView->updateSceneRect(reg);
169 _mapView->centerOn(reg.center());
170 _mapView->fitInView(reg,Qt::KeepAspectRatio);
171
172 slotFitFont();
[2796]173}
174
175
176// ------------
[3288]177void bncMap::slotFitFont()
[2796]178{
[3288]179 _mapScen->clear();
180 slotCreateMap();
181
182 float fontsize = _mapView->scale_rate();
183 float pointsize = _mapView->scale_rate();
184
185 QMapIterator<QString, QList<QVariant> > it(_allNames);
186 while( it.hasNext() ){
187
188 it.next();
189 QString name = it.key();
190 QList<QVariant> tmp = it.value();
191
192 double la = tmp.at(0).toPointF().x();
193 double fi = tmp.at(0).toPointF().y();
194 QPen pen = tmp.at(1).value<QPen>();
195 double basPT = tmp.at(2).toDouble();
196 double basFT = tmp.at(3).toDouble();
197
198 float tmpPT = pointsize * basPT;
199 float tmpFT = fontsize * basFT;
200
201 QFont font(QFont("Arial", 2, 1));
202 font.setPointSizeF( tmpFT );
203
204 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
205 nameItem->setFont( font );
206
207 if( floor(fontsize) < 1 ){
208 nameItem->setPos( la - 4.0 - floor(fontsize), fi - 5.0 - floor(fontsize) );
209 }else{
210 nameItem->setPos( la - 1.0 - floor(fontsize), fi - 4.0 - floor(fontsize) );
211 }
212
213 if( tmpPT < 0.25 ) tmpPT = 0.25;
214 pen.setWidthF(tmpPT);
215
216 _mapScen->addItem( nameItem );
217 _mapScen->addEllipse( la, fi, tmpPT, tmpPT, pen );
218 }
219 _mapView->zoom( 1.0 );
[2796]220}
221
222
223// ------------
[3288]224void bncMap::slotZoomIn()
[2796]225{
[3288]226 _mapView->zoom( 1.2 );
[2796]227}
228
229
230// ------------
[3288]231void bncMap::slotZoomOut()
232{
233 _mapView->zoom( 1/1.2 );
234}
235
236
237// ------------
238void bncMap::slotNewPoint(QPointF point, QString name, QPen pen, double size)
[2753]239{
[2796]240 float la = point.x() + _LaOff;
241 float fi = - point.y();
[2753]242
243 while( la < 0 ){ la += 360; }
244 while( la >= 360 ){ la -= 360; }
[2796]245
[3288]246 QPointF tmppoint(la,fi);
247 _allPoints << tmppoint;
[2753]248
249 if( ! name.isEmpty() ){
250
[3288]251 QList<QVariant> tmp;
252 tmp << tmppoint // QPoint
253 << pen // QPen
254 << size << 4.5; // base pointsize, fontsize
255 _allNames.insert( name, tmp );
[2753]256 }
[2805]257}
Note: See TracBrowser for help on using the repository browser.