• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
VectorComposer.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Project.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
11 //
12 
13 #include "VectorComposer.h"
14 
15 #include <cmath>
16 
17 #include <QColor>
18 
19 #include "MarbleDebug.h"
20 #include "GeoPolygon.h"
21 #include "GeoPainter.h"
22 #include "MarbleGlobal.h"
23 #include "VectorMap.h"
24 #include "ViewportParams.h"
25 #include "MarbleDirs.h"
26 
27 using namespace Marble;
28 
29 QAtomicInt VectorComposer::refCounter( 0 );
30 PntMap *VectorComposer::s_coastLines( 0 );
31 PntMap *VectorComposer::s_islands( 0 );
32 PntMap *VectorComposer::s_lakeislands( 0 );
33 PntMap *VectorComposer::s_lakes( 0 );
34 PntMap *VectorComposer::s_glaciers( 0 );
35 PntMap *VectorComposer::s_rivers( 0 );
36 PntMap *VectorComposer::s_countries( 0 );
37 PntMap *VectorComposer::s_usaStates( 0 );
38 PntMap *VectorComposer::s_dateLine( 0 );
39 bool VectorComposer::s_coastLinesLoaded( false );
40 bool VectorComposer::s_overlaysLoaded( false );
41 
42 VectorComposer::VectorComposer( QObject * parent )
43  : QObject( parent ),
44  m_vectorMap( new VectorMap() ),
45  m_oceanPen( QPen( Qt::NoPen ) ),
46  m_oceanBrush( QBrush( QColor( 153, 179, 204 ) ) ),
47  m_landPen( QPen( Qt::NoPen ) ),
48  m_landBrush( QBrush( QColor( 242, 239, 233 ) ) ),
49  m_textureLandPen( QPen( Qt::NoPen ) ),
50  m_textureLandBrush( QBrush( QColor( 255, 0, 0 ) ) ),
51  m_textureGlacierBrush( QBrush( QColor( 0, 255, 0 ) ) ),
52  m_textureLakeBrush( QBrush( QColor( 0, 0, 0 ) ) ),
53  m_dateLineBrush( QBrush( Qt::NoBrush ) )
54 {
55 #if QT_VERSION < 0x050000
56  if ( refCounter == 0 ) {
57 #else
58  if ( refCounter.load() == 0 ) {
59 #endif
60  s_coastLinesLoaded = false;
61  s_overlaysLoaded = false;
62 
63  s_coastLines = new PntMap();
64  s_islands = new PntMap();
65  s_lakeislands = new PntMap();
66  s_lakes = new PntMap();
67  s_glaciers = new PntMap();
68  s_rivers = new PntMap();
69  s_countries = new PntMap();
70  s_usaStates = new PntMap();
71  s_dateLine = new PntMap();
72  }
73  refCounter.ref();
74 
75  m_textureBorderPen.setStyle( Qt::SolidLine );
76  m_textureBorderPen.setColor( QColor( 0, 255, 0 ) );
77  m_dateLinePen.setStyle( Qt::DashLine );
78  m_dateLinePen.setColor( QColor( 0, 0, 0 ) );
79 
80  connect( s_coastLines, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
81  connect( s_islands, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
82  connect( s_lakeislands, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
83  connect( s_lakes, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
84  connect( s_glaciers, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
85  connect( s_rivers, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
86  connect( s_countries, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
87  connect( s_usaStates, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
88  connect( s_dateLine, SIGNAL(initialized()), SIGNAL(datasetLoaded()) );
89 }
90 
91 VectorComposer::~VectorComposer()
92 {
93  delete m_vectorMap;
94 
95  refCounter.deref();
96 #if QT_VERSION < 0x050000
97  if (refCounter == 0) {
98 #else
99  if (refCounter.load() == 0) {
100 #endif
101  delete s_dateLine;
102  delete s_usaStates; // The states of the USA
103  delete s_countries; // The country borders
104  delete s_rivers;
105  delete s_glaciers;
106  delete s_lakes;
107  delete s_lakeislands;
108  delete s_islands;
109  delete s_coastLines;
110 
111  s_coastLinesLoaded = false;
112  s_overlaysLoaded = false;
113  }
114 }
115 
116 void VectorComposer::loadCoastlines()
117 {
118  if ( s_coastLinesLoaded ) {
119  return;
120  }
121  s_coastLinesLoaded = true;
122 
123  mDebug() << Q_FUNC_INFO;
124 
125  // Coastlines
126  s_coastLines->load( MarbleDirs::path( "mwdbii/PCOAST.PNT" ) );
127  s_islands->load( MarbleDirs::path( "mwdbii/PISLAND.PNT" ) );
128  s_lakeislands->load( MarbleDirs::path( "mwdbii/PLAKEISLAND.PNT" ) );
129  s_lakes->load( MarbleDirs::path( "mwdbii/PLAKE.PNT" ) );
130 
131  // Ice and snow ...
132  s_glaciers->load( MarbleDirs::path( "mwdbii/PGLACIER.PNT" ) );
133 }
134 
135 void VectorComposer::loadOverlays()
136 {
137  if ( s_overlaysLoaded ) {
138  return;
139  }
140  s_overlaysLoaded = true;
141 
142  mDebug() << Q_FUNC_INFO;
143 
144  // The rivers.
145  s_rivers->load( MarbleDirs::path( "mwdbii/RIVER.PNT" ) );
146 
147  // The countries.
148  s_countries->load( MarbleDirs::path( "mwdbii/PDIFFBORDER.PNT" ) );
149 
150  // The States of the USA.
151  s_usaStates->load( MarbleDirs::path( "mwdbii/PUSA48.DIFF.PNT" ) );
152 
153  // The date "line", which in reality is rather crooked.
154  s_dateLine->load( MarbleDirs::path( "mwdbii/DATELINE.PNT" ) );
155 }
156 
157 void VectorComposer::setShowWaterBodies( bool show )
158 {
159  m_showWaterBodies = show;
160 }
161 
162 void VectorComposer::setShowLakes( bool show )
163 {
164  m_showLakes = show;
165 }
166 
167 void VectorComposer::setShowIce( bool show )
168 {
169  m_showIce = show;
170 }
171 
172 void VectorComposer::setShowCoastLines( bool show )
173 {
174  m_showCoastLines = show;
175 }
176 
177 void VectorComposer::setShowRivers( bool show )
178 {
179  m_showRivers = show;
180 }
181 
182 void VectorComposer::setShowBorders( bool show )
183 {
184  m_showBorders = show;
185 }
186 
187 void VectorComposer::drawTextureMap( GeoPainter *painter, const ViewportParams *viewport )
188 {
189  loadCoastlines();
190 
191  // Coastlines
192  m_vectorMap->setzBoundingBoxLimit( 0.4 );
193  m_vectorMap->setzPointLimit( 0 ); // 0.6 results in green pacific
194 
195  // Draw the coast line vectors
196  m_vectorMap->createFromPntMap( s_coastLines, viewport );
197  painter->setPen( m_textureLandPen );
198  painter->setBrush( m_textureLandBrush );
199  m_vectorMap->paintMap( painter );
200 
201  // Islands
202  m_vectorMap->setzBoundingBoxLimit( 0.8 );
203  m_vectorMap->setzPointLimit( 0.9 );
204 
205  m_vectorMap->createFromPntMap( s_islands, viewport );
206  painter->setPen( m_textureLandPen );
207  painter->setBrush( m_textureLandBrush );
208  m_vectorMap->paintMap( painter );
209 
210  if ( m_showWaterBodies && m_showLakes ) {
211  // Lakes
212  m_vectorMap->setzBoundingBoxLimit( 0.95 );
213  m_vectorMap->setzPointLimit( 0.98 );
214 
215  m_vectorMap->createFromPntMap( s_lakes, viewport );
216  painter->setPen( Qt::NoPen );
217  painter->setBrush( m_textureLakeBrush );
218  m_vectorMap->paintMap( painter );
219 
220  m_vectorMap->createFromPntMap( s_lakeislands, viewport );
221  painter->setPen( Qt::NoPen );
222  painter->setBrush( m_textureLandBrush );
223  m_vectorMap->paintMap( painter );
224  }
225 
226  if ( m_showIce ) {
227  // Glaciers
228  m_vectorMap->setzBoundingBoxLimit( 0.8 );
229  m_vectorMap->setzPointLimit( 0.9 );
230  m_vectorMap->createFromPntMap( s_glaciers, viewport );
231  painter->setPen( Qt::NoPen );
232  painter->setBrush( m_textureGlacierBrush );
233 
234  m_vectorMap->paintMap( painter );
235  }
236 
237  // mDebug() << "TextureMap calculated nodes: " << m_vectorMap->nodeCount();
238 }
239 
240 void VectorComposer::paintBaseVectorMap( GeoPainter *painter,
241  const ViewportParams *viewport )
242 {
243  loadCoastlines();
244 
245  const bool antialiased = painter->mapQuality() == HighQuality
246  || painter->mapQuality() == PrintQuality;
247 
248  painter->setRenderHint( QPainter::Antialiasing, antialiased );
249 
250  // Paint the background of it all, i.e. the water.
251  painter->setPen( m_oceanPen );
252  painter->setBrush( m_oceanBrush );
253  painter->drawPath( viewport->mapShape() );
254 
255  // Coastlines
256  m_vectorMap->setzBoundingBoxLimit( 0.4 );
257  m_vectorMap->setzPointLimit( 0 ); // 0.6 results in green pacific
258 
259  if ( m_showCoastLines ) {
260  painter->setPen( m_landPen );
261  painter->setBrush( Qt::NoBrush );
262  }
263  else
264  {
265  painter->setPen( Qt::NoPen );
266  painter->setBrush( m_landBrush );
267  }
268 
269  m_vectorMap->createFromPntMap( s_coastLines, viewport );
270  m_vectorMap->paintMap( painter );
271 
272  // Islands
273  m_vectorMap->setzBoundingBoxLimit( 0.8 );
274  m_vectorMap->setzPointLimit( 0.9 );
275 
276  m_vectorMap->createFromPntMap( s_islands, viewport );
277 
278  if ( m_showCoastLines ) {
279  painter->setPen( m_landPen );
280  painter->setBrush( Qt::NoBrush );
281  }
282  else
283  {
284  painter->setPen( Qt::NoPen );
285  painter->setBrush( m_landBrush );
286  }
287 
288  m_vectorMap->paintMap( painter );
289 
290  if ( ( m_showWaterBodies && m_showLakes ) || m_showCoastLines ) {
291  // Lakes
292  m_vectorMap->setzBoundingBoxLimit( 0.95 );
293  m_vectorMap->setzPointLimit( 0.98 );
294 
295  m_vectorMap->createFromPntMap( s_lakes, viewport );
296  painter->setPen( m_lakePen );
297  painter->setBrush( m_lakeBrush );
298  m_vectorMap->paintMap( painter );
299 
300  m_vectorMap->createFromPntMap( s_lakeislands, viewport );
301  painter->setBrush( m_landBrush );
302  m_vectorMap->paintMap( painter );
303  }
304 }
305 
306 void VectorComposer::paintVectorMap( GeoPainter *painter,
307  const ViewportParams *viewport )
308 {
309  // m_vectorMap->clearNodeCount();
310 
311  const bool antialiased = painter->mapQuality() == HighQuality
312  || painter->mapQuality() == PrintQuality;
313 
314  painter->setRenderHint( QPainter::Antialiasing, antialiased );
315 
316  // Coastlines
317  if ( m_showCoastLines ) {
318 
319  loadCoastlines();
320 
321  m_vectorMap->setzBoundingBoxLimit( 0.4 );
322  m_vectorMap->setzPointLimit( 0 ); // 0.6 results in green pacific
323 
324  m_vectorMap->createFromPntMap( s_coastLines, viewport );
325  painter->setPen( m_landPen );
326  painter->setBrush( Qt::NoBrush );
327  m_vectorMap->paintMap( painter );
328 
329  m_vectorMap->setzBoundingBoxLimit( 0.8 );
330  m_vectorMap->setzPointLimit( 0.9 );
331 
332  m_vectorMap->createFromPntMap( s_islands, viewport );
333  painter->setPen( m_landPen );
334  painter->setBrush( Qt::NoBrush );
335  m_vectorMap->paintMap( painter );
336 
337  // Lakes
338  m_vectorMap->setzBoundingBoxLimit( 0.95 );
339  m_vectorMap->setzPointLimit( 0.98 );
340 
341  m_vectorMap->createFromPntMap( s_lakes, viewport );
342  painter->setPen( m_landPen );
343  painter->setBrush( Qt::NoBrush );
344  m_vectorMap->paintMap( painter );
345 
346  m_vectorMap->createFromPntMap( s_lakeislands, viewport );
347  m_vectorMap->paintMap( painter );
348  }
349 
350  if ( m_showWaterBodies && m_showRivers ) {
351  loadOverlays();
352  // Rivers
353  m_vectorMap->setzBoundingBoxLimit( -1.0 );
354  m_vectorMap->setzPointLimit( -1.0 );
355  m_vectorMap->createFromPntMap( s_rivers, viewport );
356 
357  painter->setPen( m_riverPen );
358  painter->setBrush( m_riverBrush );
359  m_vectorMap->paintMap( painter );
360  }
361 
362  if ( m_showBorders ) {
363  loadOverlays();
364  // Countries
365  m_vectorMap->setzBoundingBoxLimit( -1.0 );
366  m_vectorMap->setzPointLimit( -1.0 );
367  m_vectorMap->createFromPntMap( s_countries, viewport );
368 
369  // Fancy Boundaries Hack:
370  // FIXME: Find a clean solution that allows for all the
371  // tuning necessary for the different quality levels.
372 
373  int radius = viewport->radius();
374  qreal penWidth = (double)(radius) / 400.0;
375  if ( radius < 400.0 ) penWidth = 1.0;
376  if ( radius > 800.0 ) penWidth = 1.75;
377  if ( m_showCoastLines ) penWidth = 1.0;
378 
379  QPen countryPen( m_countryPen);
380  countryPen.setWidthF( penWidth );
381  QColor penColor = m_countryPen.color();
382 
383  QPen borderDashPen( Qt::black );
384  painter->setBrush( m_countryBrush );
385 
386  if ( painter->mapQuality() == HighQuality
387  || painter->mapQuality() == PrintQuality ) {
388 
389  countryPen.setColor( penColor );
390  painter->setPen( countryPen );
391  m_vectorMap->paintMap( painter );
392 
393  // Only paint fancy style if the coast line doesn't get painted as well
394  // (as it looks a bit awkward otherwise)
395 
396  if ( !m_showCoastLines ) {
397  borderDashPen.setDashPattern( QVector<qreal>() << 1 << 5 );
398  borderDashPen.setWidthF( penWidth * 0.5 );
399  painter->setPen( borderDashPen );
400  m_vectorMap->paintMap( painter );
401  }
402  }
403  if ( painter->mapQuality() == OutlineQuality
404  || painter->mapQuality() == LowQuality
405  || painter->mapQuality() == NormalQuality ) {
406 
407  if ( !m_showCoastLines ) {
408  countryPen.setWidthF( 1.0 );
409  countryPen.setColor( penColor.darker(115) );
410  }
411  painter->setPen( countryPen );
412  m_vectorMap->paintMap( painter );
413  }
414 
415  // US-States
416  m_vectorMap->setzBoundingBoxLimit( -1.0 );
417  m_vectorMap->setzPointLimit( -1.0 );
418  m_vectorMap->createFromPntMap( s_usaStates, viewport );
419 
420  QPen statePen( m_statePen);
421  if ( painter->mapQuality() == OutlineQuality
422  || painter->mapQuality() == LowQuality ) {
423  statePen.setStyle( Qt::SolidLine );
424  }
425  painter->setPen( statePen );
426  painter->setBrush( m_stateBrush );
427  m_vectorMap->paintMap( painter );
428 
429  // International Dateline
430  m_vectorMap->setzBoundingBoxLimit( -1.0 );
431  m_vectorMap->setzPointLimit( -1.0 );
432  m_vectorMap->createFromPntMap( s_dateLine, viewport );
433 
434  QPen dateLinePen( m_dateLinePen);
435  if ( painter->mapQuality() == OutlineQuality
436  || painter->mapQuality() == LowQuality ) {
437  dateLinePen.setStyle( Qt::SolidLine );
438  }
439  painter->setPen( dateLinePen );
440  painter->setBrush( m_dateLineBrush );
441  m_vectorMap->paintMap( painter );
442  }
443 
444  // mDebug() << "M_VectorMap calculated nodes: " << m_vectorMap->nodeCount();
445 }
446 
447 #include "VectorComposer.moc"
Marble::PntMap::load
void load(const QString &)
Definition: GeoPolygon.cpp:120
Marble::VectorComposer::setShowLakes
void setShowLakes(bool show)
Definition: VectorComposer.cpp:162
GeoPolygon.h
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:53
Marble::VectorComposer::~VectorComposer
virtual ~VectorComposer()
Definition: VectorComposer.cpp:91
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::VectorMap::setzPointLimit
void setzPointLimit(const qreal zPointLimit)
Definition: VectorMap.h:48
Marble::PrintQuality
Print quality.
Definition: MarbleGlobal.h:85
QObject
Marble::VectorComposer::drawTextureMap
void drawTextureMap(GeoPainter *painter, const ViewportParams *viewport)
Definition: VectorComposer.cpp:187
MarbleDebug.h
Marble::LowQuality
Low resolution (e.g. interlaced)
Definition: MarbleGlobal.h:82
VectorComposer.h
Marble::PntMap
Definition: GeoPolygon.h:95
MarbleDirs.h
Marble::NormalQuality
Normal quality.
Definition: MarbleGlobal.h:83
VectorMap.h
Marble::VectorComposer::setShowBorders
void setShowBorders(bool show)
Definition: VectorComposer.cpp:182
GeoPainter.h
MarbleGlobal.h
Marble::VectorComposer::paintBaseVectorMap
void paintBaseVectorMap(GeoPainter *, const ViewportParams *)
Definition: VectorComposer.cpp:240
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::VectorComposer::setShowWaterBodies
void setShowWaterBodies(bool show)
Definition: VectorComposer.cpp:157
Marble::VectorComposer::VectorComposer
VectorComposer(QObject *parent=0)
Definition: VectorComposer.cpp:42
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::VectorComposer::datasetLoaded
void datasetLoaded()
Marble::ViewportParams::mapShape
QPainterPath mapShape() const
Definition: ViewportParams.cpp:403
Marble::VectorComposer::setShowCoastLines
void setShowCoastLines(bool show)
Definition: VectorComposer.cpp:172
Marble::OutlineQuality
Only a wire representation is drawn.
Definition: MarbleGlobal.h:81
Marble::VectorMap::paintMap
void paintMap(GeoPainter *painter)
Paint the background, i.e.
Definition: VectorMap.cpp:673
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::HighQuality
High quality (e.g. antialiasing for lines)
Definition: MarbleGlobal.h:84
Marble::VectorMap::createFromPntMap
void createFromPntMap(const PntMap *, const ViewportParams *viewport)
Definition: VectorMap.cpp:45
Marble::VectorComposer::setShowIce
void setShowIce(bool show)
Definition: VectorComposer.cpp:167
Marble::VectorMap
Definition: VectorMap.h:34
Marble::VectorComposer::setShowRivers
void setShowRivers(bool show)
Definition: VectorComposer.cpp:177
Marble::VectorComposer::paintVectorMap
void paintVectorMap(GeoPainter *, const ViewportParams *)
Definition: VectorComposer.cpp:306
Marble::GeoPainter::mapQuality
MapQuality mapQuality() const
Returns the map quality.
Definition: GeoPainter.cpp:191
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::VectorMap::setzBoundingBoxLimit
void setzBoundingBoxLimit(const qreal zBoundingBoxLimit)
Definition: VectorMap.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal