• 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
  • plugins
  • render
  • graticule
GraticulePlugin.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
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 2009 Torsten Rahn <tackat@kde.org>
9 //
10 
11 #include "GraticulePlugin.h"
12 #include "ui_GraticuleConfigWidget.h"
13 
14 #include "MarbleDebug.h"
15 #include "MarbleDirs.h"
16 #include "GeoPainter.h"
17 #include "GeoDataLineString.h"
18 #include "Planet.h"
19 #include "MarbleModel.h"
20 #include "PluginAboutDialog.h"
21 
22 #include "ViewportParams.h"
23 #include "GeoDataLatLonAltBox.h"
24 
25 // Qt
26 #include <QPushButton>
27 #include <QLabel>
28 #include <QRect>
29 #include <QColor>
30 #include <QPixmap>
31 #include <QSvgRenderer>
32 #include <QBrush>
33 #include <QColorDialog>
34 #include <QDebug>
35 
36 
37 
38 namespace Marble
39 {
40 
41 GraticulePlugin::GraticulePlugin()
42  : RenderPlugin( 0 ),
43  ui_configWidget( 0 ),
44  m_configDialog( 0 )
45 {
46 }
47 
48 GraticulePlugin::GraticulePlugin( const MarbleModel *marbleModel )
49  : RenderPlugin( marbleModel ),
50  m_equatorCirclePen( Qt::yellow ),
51  m_tropicsCirclePen( Qt::yellow ),
52  m_gridCirclePen( Qt::white ),
53  m_showPrimaryLabels( true ),
54  m_showSecondaryLabels( true ),
55  m_isInitialized( false ),
56  ui_configWidget( 0 ),
57  m_configDialog( 0 )
58 {
59 }
60 
61 QStringList GraticulePlugin::backendTypes() const
62 {
63  return QStringList( "graticule" );
64 }
65 
66 QString GraticulePlugin::renderPolicy() const
67 {
68  return QString( "ALWAYS" );
69 }
70 
71 QStringList GraticulePlugin::renderPosition() const
72 {
73  return QStringList( "SURFACE" );
74 }
75 
76 QString GraticulePlugin::name() const
77 {
78  return tr( "Coordinate Grid" );
79 }
80 
81 QString GraticulePlugin::guiString() const
82 {
83  return tr( "Coordinate &Grid" );
84 }
85 
86 QString GraticulePlugin::nameId() const
87 {
88  return QString( "coordinate-grid" );
89 }
90 
91 QString GraticulePlugin::version() const
92 {
93  return "1.0";
94 }
95 
96 QString GraticulePlugin::description() const
97 {
98  return tr( "A plugin that shows a coordinate grid." );
99 }
100 
101 QString GraticulePlugin::copyrightYears() const
102 {
103  return "2009";
104 }
105 
106 QList<PluginAuthor> GraticulePlugin::pluginAuthors() const
107 {
108  return QList<PluginAuthor>()
109  << PluginAuthor( "Torsten Rahn", "tackat@kde.org" );
110 }
111 
112 QIcon GraticulePlugin::icon () const
113 {
114  return QIcon(":/icons/coordinate.png");
115 }
116 
117 void GraticulePlugin::initialize ()
118 {
119  // Initialize range maps that map the zoom to the number of coordinate grid lines.
120 
121  initLineMaps( GeoDataCoordinates::defaultNotation() );
122 
123  m_isInitialized = true;
124 }
125 
126 bool GraticulePlugin::isInitialized () const
127 {
128  return m_isInitialized;
129 }
130 
131 QDialog *GraticulePlugin::configDialog()
132 {
133  if ( !m_configDialog ) {
134  m_configDialog = new QDialog();
135  ui_configWidget = new Ui::GraticuleConfigWidget;
136  ui_configWidget->setupUi( m_configDialog );
137 
138  connect( ui_configWidget->gridPushButton, SIGNAL(clicked()), this,
139  SLOT(gridGetColor()) );
140  connect( ui_configWidget->tropicsPushButton, SIGNAL(clicked()), this,
141  SLOT(tropicsGetColor()) );
142  connect( ui_configWidget->equatorPushButton, SIGNAL(clicked()), this,
143  SLOT(equatorGetColor()) );
144 
145 
146  connect( ui_configWidget->m_buttonBox, SIGNAL(accepted()), this,
147  SLOT(writeSettings()) );
148  connect( ui_configWidget->m_buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()),
149  SLOT(restoreDefaultSettings()) );
150  QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
151  connect( applyButton, SIGNAL(clicked()),
152  this, SLOT(writeSettings()) );
153  }
154 
155  readSettings();
156 
157  return m_configDialog;
158 }
159 
160 
161 QHash<QString,QVariant> GraticulePlugin::settings() const
162 {
163  QHash<QString, QVariant> settings = RenderPlugin::settings();
164 
165  settings.insert( "gridColor", m_gridCirclePen.color().name() );
166  settings.insert( "tropicsColor", m_tropicsCirclePen.color().name() );
167  settings.insert( "equatorColor", m_equatorCirclePen.color().name() );
168  settings.insert( "primarylabels", m_showPrimaryLabels );
169  settings.insert( "secondaryLabels", m_showSecondaryLabels );
170 
171  return settings;
172 }
173 
174 void GraticulePlugin::setSettings( const QHash<QString,QVariant> &settings )
175 {
176  RenderPlugin::setSettings( settings );
177 
178  const QColor gridColor = settings.value( "gridColor", QColor( Qt::white ) ).value<QColor>();
179  const QColor tropicsColor = settings.value( "tropicsColor", QColor( Qt::yellow ) ).value<QColor>();
180  const QColor equatorColor = settings.value( "equatorColor", QColor( Qt::yellow ) ).value<QColor>();
181  bool primaryLabels = settings.value( "primaryLabels", true ).toBool();
182  bool secondaryLabels = settings.value( "secondaryLabels", true ).toBool();
183 
184  m_gridCirclePen.setColor( gridColor );
185  m_tropicsCirclePen.setColor( tropicsColor );
186  m_equatorCirclePen.setColor( equatorColor );
187 
188  m_showPrimaryLabels = primaryLabels;
189  m_showSecondaryLabels = secondaryLabels;
190 
191  readSettings();
192 }
193 
194 
195 void GraticulePlugin::readSettings()
196 {
197  if ( !m_configDialog )
198  return;
199 
200  QPalette gridPalette;
201  gridPalette.setColor( QPalette::Button, m_gridCirclePen.color() );
202  ui_configWidget->gridPushButton->setPalette( gridPalette );
203 
204  QPalette tropicsPalette;
205  tropicsPalette.setColor( QPalette::Button, m_tropicsCirclePen.color() );
206  ui_configWidget->tropicsPushButton->setPalette( tropicsPalette );
207 
208 
209  QPalette equatorPalette;
210  equatorPalette.setColor( QPalette::Button, m_equatorCirclePen.color() );
211  ui_configWidget->equatorPushButton->setPalette( equatorPalette );
212  ui_configWidget->primaryCheckBox->setChecked( m_showPrimaryLabels );
213  ui_configWidget->secondaryCheckBox->setChecked( m_showSecondaryLabels );
214 }
215 
216 void GraticulePlugin::gridGetColor()
217 {
218  const QColor c = QColorDialog::getColor( m_gridCirclePen.color(), 0, tr("Please choose the color for the coordinate grid.") );
219 
220  if ( c.isValid() ) {
221  QPalette palette = ui_configWidget->gridPushButton->palette();
222  palette.setColor( QPalette::Button, c );
223  ui_configWidget->gridPushButton->setPalette( palette );
224  }
225 }
226 
227 void GraticulePlugin::tropicsGetColor()
228 {
229  const QColor c = QColorDialog::getColor( m_tropicsCirclePen.color(), 0, tr("Please choose the color for the tropic circles.") );
230 
231  if ( c.isValid() ) {
232  QPalette palette = ui_configWidget->tropicsPushButton->palette();
233  palette.setColor( QPalette::Button, c );
234  ui_configWidget->tropicsPushButton->setPalette( palette );
235  }
236 }
237 
238 void GraticulePlugin::equatorGetColor()
239 {
240  const QColor c = QColorDialog::getColor( m_equatorCirclePen.color(), 0, tr("Please choose the color for the equator.") );
241 
242  if ( c.isValid() ) {
243  QPalette palette = ui_configWidget->equatorPushButton->palette();
244  palette.setColor( QPalette::Button, c );
245  ui_configWidget->equatorPushButton->setPalette( palette );
246  }
247 }
248 
249 void GraticulePlugin::writeSettings()
250 {
251  m_equatorCirclePen.setColor( ui_configWidget->equatorPushButton->palette().color( QPalette::Button ) );
252  m_tropicsCirclePen.setColor( ui_configWidget->tropicsPushButton->palette().color( QPalette::Button ) );
253  m_gridCirclePen.setColor( ui_configWidget->gridPushButton->palette().color( QPalette::Button) );
254  m_showPrimaryLabels = ui_configWidget->primaryCheckBox->isChecked();
255  m_showSecondaryLabels = ui_configWidget->secondaryCheckBox->isChecked();
256 
257  emit settingsChanged( nameId() );
258 }
259 
260 bool GraticulePlugin::render( GeoPainter *painter, ViewportParams *viewport,
261  const QString& renderPos,
262  GeoSceneLayer * layer )
263 {
264  Q_UNUSED( layer )
265  Q_UNUSED( renderPos )
266 
267  if ( m_currentNotation != GeoDataCoordinates::defaultNotation() ) {
268  initLineMaps( GeoDataCoordinates::defaultNotation() );
269  }
270 
271  // Setting the label font for the coordinate lines.
272 #ifdef Q_OS_MACX
273  int defaultFontSize = 10;
274 #else
275  int defaultFontSize = 8;
276 #endif
277 
278  QFont gridFont("Sans Serif");
279  gridFont.setPointSize( defaultFontSize );
280  gridFont.setBold( true );
281 
282  painter->save();
283 
284  painter->setFont( gridFont );
285 
286  renderGrid( painter, viewport, m_equatorCirclePen, m_tropicsCirclePen, m_gridCirclePen );
287 
288  painter->restore();
289 
290  return true;
291 }
292 
293 qreal GraticulePlugin::zValue() const
294 {
295  return 1.0;
296 }
297 
298 void GraticulePlugin::renderGrid( GeoPainter *painter, ViewportParams *viewport,
299  const QPen& equatorCirclePen,
300  const QPen& tropicsCirclePen,
301  const QPen& gridCirclePen )
302 {
303  GeoDataLatLonAltBox viewLatLonAltBox = viewport->viewLatLonAltBox();
304 
305  painter->setPen( gridCirclePen );
306  // painter->setPen( QPen( QBrush( Qt::white ), 0.75 ) );
307 
308  // Render UTM grid zones
309  if ( m_currentNotation == GeoDataCoordinates::UTM ) {
310  renderLatitudeLine( painter, 84.0, viewLatLonAltBox );
311 
312  renderLongitudeLines( painter, viewLatLonAltBox,
313  6.0, 18.0, 154.0, LineStart | IgnoreXMargin );
314  renderLongitudeLines( painter, viewLatLonAltBox,
315  6.0, 34.0, 10.0, LineStart | IgnoreXMargin );
316 
317  // Paint longtudes with exceptions
318  renderLongitudeLines( painter, viewLatLonAltBox,
319  6.0, 6.0, 162.0 );
320  renderLongitudeLines( painter, viewLatLonAltBox,
321  6.0, 26.0, 146.0 );
322 
323  renderLatitudeLines( painter, viewLatLonAltBox, 8.0 /*,
324  LineStart | IgnoreYMargin */ );
325 
326  return;
327  }
328 
329  // Render the normal grid
330 
331  // calculate the angular distance between coordinate lines of the normal grid
332  qreal normalDegreeStep = 360.0 / m_normalLineMap.lowerBound(viewport->radius()).value();
333 
334  LabelPositionFlags labelXPosition(NoLabel), labelYPosition(NoLabel);
335  if ( m_showSecondaryLabels ) {
336  labelXPosition = LineStart | IgnoreXMargin;
337  labelYPosition = LineStart | IgnoreYMargin;
338  }
339  renderLongitudeLines( painter, viewLatLonAltBox,
340  normalDegreeStep, normalDegreeStep, normalDegreeStep,
341  labelXPosition );
342  renderLatitudeLines( painter, viewLatLonAltBox, normalDegreeStep,
343  labelYPosition );
344 
345  // Render some non-cut off longitude lines ..
346  renderLongitudeLine( painter, +90.0, viewLatLonAltBox );
347  renderLongitudeLine( painter, -90.0, viewLatLonAltBox );
348 
349  // Render the bold grid
350 
351  if ( painter->mapQuality() == HighQuality
352  || painter->mapQuality() == PrintQuality ) {
353 
354  QPen boldPen = gridCirclePen;
355  boldPen.setWidthF( 1.5 );
356  painter->setPen( boldPen );
357 
358  // calculate the angular distance between coordinate lines of the bold grid
359  qreal boldDegreeStep = 360.0 / m_boldLineMap.lowerBound(viewport->radius()).value();
360 
361  renderLongitudeLines( painter, viewLatLonAltBox,
362  boldDegreeStep, normalDegreeStep, normalDegreeStep,
363  NoLabel
364  );
365  renderLatitudeLines( painter, viewLatLonAltBox, boldDegreeStep,
366  NoLabel );
367  }
368 
369  painter->setPen( equatorCirclePen );
370 
371  LabelPositionFlags mainPosition(NoLabel);
372  if ( m_showPrimaryLabels ) {
373  mainPosition = LineCenter;
374  }
375  // Render the equator
376  renderLatitudeLine( painter, 0.0, viewLatLonAltBox, tr( "Equator" ), mainPosition );
377 
378  // Render the Prime Meridian and Antimeridian
379  GeoDataCoordinates::Notation notation = GeoDataCoordinates::defaultNotation();
380  if (marbleModel()->planet()->id() != "sky" && notation != GeoDataCoordinates::Astro) {
381  renderLongitudeLine( painter, 0.0, viewLatLonAltBox, 0.0, 0.0, tr( "Prime Meridian" ), mainPosition );
382  renderLongitudeLine( painter, 180.0, viewLatLonAltBox, 0.0, 0.0, tr( "Antimeridian" ), mainPosition );
383  }
384 
385  QPen tropicsPen = tropicsCirclePen;
386  if ( painter->mapQuality() != OutlineQuality
387  && painter->mapQuality() != LowQuality ) {
388  tropicsPen.setStyle( Qt::DotLine );
389  }
390  painter->setPen( tropicsPen );
391 
392  // Determine the planet's axial tilt
393  qreal axialTilt = RAD2DEG * marbleModel()->planet()->epsilon();
394 
395  if ( axialTilt > 0 ) {
396  // Render the tropics
397  renderLatitudeLine( painter, +axialTilt, viewLatLonAltBox, tr( "Tropic of Cancer" ), mainPosition );
398  renderLatitudeLine( painter, -axialTilt, viewLatLonAltBox, tr( "Tropic of Capricorn" ), mainPosition );
399 
400  // Render the arctics
401  renderLatitudeLine( painter, +90.0 - axialTilt, viewLatLonAltBox, tr( "Arctic Circle" ), mainPosition );
402  renderLatitudeLine( painter, -90.0 + axialTilt, viewLatLonAltBox, tr( "Antarctic Circle" ), mainPosition );
403  }
404 }
405 
406 void GraticulePlugin::renderLatitudeLine( GeoPainter *painter, qreal latitude,
407  const GeoDataLatLonAltBox& viewLatLonAltBox,
408  const QString& lineLabel,
409  LabelPositionFlags labelPositionFlags )
410 {
411  qreal fromSouthLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
412  qreal toNorthLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
413 
414  // Coordinate line is not displayed inside the viewport
415  if ( latitude < fromSouthLat || toNorthLat < latitude ) {
416  // mDebug() << "Lat: Out of View";
417  return;
418  }
419 
420  GeoDataLineString line( Tessellate | RespectLatitudeCircle ) ;
421 
422  qreal fromWestLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
423  qreal toEastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
424 
425  if ( fromWestLon < toEastLon ) {
426  qreal step = ( toEastLon - fromWestLon ) * 0.25;
427 
428  for ( int i = 0; i < 5; ++i ) {
429  line << GeoDataCoordinates( fromWestLon + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
430  }
431  }
432  else {
433  qreal step = ( +180.0 - toEastLon ) * 0.25;
434 
435  for ( int i = 0; i < 5; ++i ) {
436  line << GeoDataCoordinates( toEastLon + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
437  }
438 
439  step = ( +180 + fromWestLon ) * 0.25;
440 
441  for ( int i = 0; i < 5; ++i ) {
442  line << GeoDataCoordinates( -180 + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
443  }
444  }
445 
446  painter->drawPolyline( line, lineLabel, labelPositionFlags );
447 }
448 
449 void GraticulePlugin::renderLongitudeLine( GeoPainter *painter, qreal longitude,
450  const GeoDataLatLonAltBox& viewLatLonAltBox,
451  qreal northPolarGap, qreal southPolarGap,
452  const QString& lineLabel,
453  LabelPositionFlags labelPositionFlags )
454 {
455  const qreal fromWestLon = viewLatLonAltBox.west();
456  const qreal toEastLon = viewLatLonAltBox.east();
457 
458  // Coordinate line is not displayed inside the viewport
459  if ( ( !viewLatLonAltBox.crossesDateLine()
460  && ( longitude * DEG2RAD < fromWestLon || toEastLon < longitude * DEG2RAD ) ) ||
461  ( viewLatLonAltBox.crossesDateLine() &&
462  longitude * DEG2RAD < toEastLon && fromWestLon < longitude * DEG2RAD &&
463  fromWestLon != -M_PI && toEastLon != +M_PI )
464  ) {
465  // mDebug() << "Lon: Out of View:" << viewLatLonAltBox.toString() << " Crossing: "<< viewLatLonAltBox.crossesDateLine() << "Longitude: " << longitude;
466  return;
467  }
468 
469  qreal fromSouthLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
470  qreal toNorthLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
471 
472  qreal southLat = ( fromSouthLat < -90.0 + southPolarGap ) ? -90.0 + southPolarGap : fromSouthLat;
473  qreal northLat = ( toNorthLat > +90.0 - northPolarGap ) ? +90.0 - northPolarGap : toNorthLat;
474 
475  GeoDataCoordinates n1( longitude, southLat, 0.0, GeoDataCoordinates::Degree );
476  GeoDataCoordinates n3( longitude, northLat, 0.0, GeoDataCoordinates::Degree );
477 
478  GeoDataLineString line( Tessellate );
479 
480  if ( northLat > 0 && southLat < 0 )
481  {
482  GeoDataCoordinates n2( longitude, 0.0, 0.0, GeoDataCoordinates::Degree );
483  line << n1 << n2 << n3;
484  }
485  else {
486  line << n1 << n3;
487  }
488 
489  painter->drawPolyline( line, lineLabel, labelPositionFlags );
490 }
491 
492 void GraticulePlugin::renderLatitudeLines( GeoPainter *painter,
493  const GeoDataLatLonAltBox& viewLatLonAltBox,
494  qreal step,
495  LabelPositionFlags labelPositionFlags
496  )
497 {
498  if ( step <= 0 ) {
499  return;
500  }
501 
502  // Latitude
503  qreal southLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
504  qreal northLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
505 
506  qreal southLineLat = step * static_cast<int>( southLat / step );
507  qreal northLineLat = step * ( static_cast<int>( northLat / step ) + 1 );
508 
509  if ( m_currentNotation == GeoDataCoordinates::UTM ) {
510  if ( northLineLat > 84.0 )
511  northLineLat = 76.0;
512 
513  if ( southLineLat < -80.0 )
514  southLineLat = -80.0;
515  }
516 
517  qreal itStep = southLineLat;
518 
519  GeoDataCoordinates::Notation notation = GeoDataCoordinates::defaultNotation();
520 
521  while ( itStep < northLineLat ) {
522  // Create a matching label
523  QString label = GeoDataCoordinates::latToString( itStep, notation,
524  GeoDataCoordinates::Degree, -1, 'g' );
525 
526  // No additional labels for the equator
527  if ( labelPositionFlags.testFlag( LineCenter ) && itStep == 0.0 ) {
528  label.clear();
529  }
530 
531  // Paint all latitude coordinate lines except for the equator
532  if ( itStep != 0.0 ) {
533  renderLatitudeLine( painter, itStep, viewLatLonAltBox, label, labelPositionFlags );
534  }
535 
536  itStep += step;
537  }
538 }
539 
540 
541 void GraticulePlugin::renderUtmExceptions( GeoPainter *painter,
542  const GeoDataLatLonAltBox& viewLatLonAltBox,
543  qreal itStep, qreal northPolarGap, qreal southPolarGap,
544  const QString & label,
545  LabelPositionFlags labelPositionFlags )
546 {
547  // This code renders the so called "exceptions" in the UTM coordinate grid
548  // See: http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system#Exceptions
549  if ( northPolarGap == 6.0 && southPolarGap == 162.0) {
550  if ( label == "31" ) {
551  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
552  southPolarGap, label, labelPositionFlags );
553  } else if ( label == "33" ) {
554  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
555  southPolarGap, label, labelPositionFlags );
556  } else if ( label == "35" ) {
557  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
558  southPolarGap, label, labelPositionFlags );
559  } else if ( label == "37" ) {
560  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
561  southPolarGap, label, labelPositionFlags );
562  } else if ( label == "32" || label == "34" || label == "36" ) {
563  // paint nothing
564  } else {
565  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
566  southPolarGap, label, labelPositionFlags );
567  }
568  }
569  else if ( northPolarGap == 26.0 && southPolarGap == 146.0 ) {
570  if ( label == "31" ) {
571  renderLongitudeLine( painter, itStep-3.0, viewLatLonAltBox, northPolarGap,
572  southPolarGap, label, labelPositionFlags );
573  } else {
574  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
575  southPolarGap, label, labelPositionFlags );
576  }
577  }
578  else {
579  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
580  southPolarGap, label, labelPositionFlags );
581  }
582 }
583 
584 void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
585  const GeoDataLatLonAltBox& viewLatLonAltBox,
586  qreal step, qreal northPolarGap, qreal southPolarGap,
587  LabelPositionFlags labelPositionFlags )
588 {
589  if ( step <= 0 ) {
590  return;
591  }
592 
593  GeoDataCoordinates::Notation notation = marbleModel()->planet()->id() == "sky" ? GeoDataCoordinates::Astro :
594  GeoDataCoordinates::defaultNotation();
595 
596  // Longitude
597  qreal westLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
598  qreal eastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
599 
600  qreal westLineLon = step * static_cast<int>( westLon / step );
601  qreal eastLineLon = step * ( static_cast<int>( eastLon / step ) + 1 );
602 
603  if ( !viewLatLonAltBox.crossesDateLine() ||
604  ( westLon == -180.0 && eastLon == +180.0 ) ) {
605  qreal itStep = westLineLon;
606 
607  while ( itStep < eastLineLon ) {
608  // Create a matching label
609  QString label = GeoDataCoordinates::lonToString( itStep,
610  notation, GeoDataCoordinates::Degree,
611  -1, 'g' );
612 
613  // No additional labels for the prime meridian and the antimeridian
614 
615  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
616  {
617  label.clear();
618  }
619 
620  // Paint all longitude coordinate lines except for the meridians
621  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
622  // handle exceptions for UTM grid
623  if (notation == GeoDataCoordinates::UTM ) {
624  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
625  southPolarGap, label, labelPositionFlags );
626  } else {
627  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
628  southPolarGap, label, labelPositionFlags );
629  }
630  }
631  itStep += step;
632  }
633  }
634  else {
635  qreal itStep = eastLineLon;
636 
637  while ( itStep < 180.0 ) {
638 
639  // Create a matching label
640  QString label = GeoDataCoordinates::lonToString( itStep,
641  notation, GeoDataCoordinates::Degree,
642  -1, 'g' );
643 
644  // No additional labels for the prime meridian and the antimeridian
645 
646  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
647  {
648  label.clear();
649  }
650 
651  // Paint all longitude coordinate lines except for the meridians
652  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
653  if (notation == GeoDataCoordinates::UTM ) {
654  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
655  southPolarGap, label, labelPositionFlags );
656  } else {
657  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
658  southPolarGap, label, labelPositionFlags );
659  }
660  }
661  itStep += step;
662  }
663 
664  itStep = -180.0;
665  while ( itStep < westLineLon ) {
666 
667  // Create a matching label
668  QString label = GeoDataCoordinates::lonToString( itStep,
669  notation, GeoDataCoordinates::Degree,
670  -1, 'g' );
671 
672  // No additional labels for the prime meridian and the antimeridian
673  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
674  {
675  label.clear();
676  }
677 
678  // Paint all longitude coordinate lines except for the meridians
679  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
680  if (notation == GeoDataCoordinates::UTM ) {
681  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
682  southPolarGap, label, labelPositionFlags );
683  } else {
684  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
685  southPolarGap, label, labelPositionFlags );
686  }
687  }
688  itStep += step;
689  }
690  }
691 }
692 
693 void GraticulePlugin::initLineMaps( GeoDataCoordinates::Notation notation)
694 {
695  /* Define Upper Bound keys and associated values:
696  The key number is the globe radius in pixel.
697  The value number is the amount of grid lines for the full range.
698 
699  Example: up to a 100 pixel radius the globe is covered
700  with 4 longitude lines (4 half-circles).
701  */
702 
703  if (marbleModel()->planet()->id() == "sky" || notation == GeoDataCoordinates::Astro) {
704  m_normalLineMap[100] = 4; // 6h
705  m_normalLineMap[1000] = 12; // 2h
706  m_normalLineMap[2000] = 24; // 1h
707  m_normalLineMap[4000] = 48; // 30 min
708  m_normalLineMap[8000] = 96; // 15 min
709  m_normalLineMap[16000] = 288; // 5 min
710  m_normalLineMap[100000] = 24 * 60; // 1 min
711  m_normalLineMap[200000] = 24 * 60 * 2; // 30 sec
712  m_normalLineMap[400000] = 24 * 60 * 4; // 15 sec
713  m_normalLineMap[1200000] = 24 * 60 * 12; // 5 sec
714  m_normalLineMap[6000000] = 24 * 60 * 60; // 1 sec
715  m_normalLineMap[12000000] = 24 * 60 * 60 * 2; // 0.5 sec
716  m_normalLineMap[24000000] = 24 * 60 * 60 * 4; // 0.25 sec
717 
718  m_boldLineMap[1000] = 0; // 0h
719  m_boldLineMap[2000] = 4; // 6h
720  m_boldLineMap[16000] = 24; // 30 deg
721  return;
722  }
723 
724  m_normalLineMap[100] = 4; // 90 deg
725  m_normalLineMap[1000] = 12; // 30 deg
726  m_normalLineMap[4000] = 36; // 10 deg
727  m_normalLineMap[16000] = 72; // 5 deg
728  m_normalLineMap[64000] = 360; // 1 deg
729  m_normalLineMap[128000] = 720; // 0.5 deg
730 
731  m_boldLineMap[1000] = 0; // 0 deg
732  m_boldLineMap[4000] = 12; // 30 deg
733  m_boldLineMap[16000] = 36; // 10 deg
734 
735  switch ( notation )
736  {
737  case GeoDataCoordinates::Decimal :
738 
739  m_normalLineMap[512000] = 360 * 10; // 0.1 deg
740  m_normalLineMap[2048000] = 360 * 20; // 0.05 deg
741  m_normalLineMap[8192000] = 360 * 100; // 0.01 deg
742  m_normalLineMap[16384000] = 360 * 200; // 0.005 deg
743  m_normalLineMap[32768000] = 360 * 1000; // 0.001 deg
744  m_normalLineMap[131072000] = 360 * 2000; // 0.0005 deg
745  m_normalLineMap[524288000] = 360 * 10000; // 0.00001 deg
746 
747  m_boldLineMap[512000] = 360; // 0.1 deg
748  m_boldLineMap[2048000] = 720; // 0.05 deg
749  m_boldLineMap[8192000] = 360 * 10; // 0.01 deg
750  m_boldLineMap[1638400] = 360 * 20; // 0.005 deg
751  m_boldLineMap[32768000] = 360 * 100; // 0.001 deg
752  m_boldLineMap[131072000] = 360 * 200; // 0.0005 deg
753  m_boldLineMap[524288000] = 360 * 1000; // 0.00001 deg
754 
755  break;
756  default:
757  case GeoDataCoordinates::DMS :
758  m_normalLineMap[512000] = 360 * 6; // 10'
759  m_normalLineMap[1024000] = 360 * 12; // 5'
760  m_normalLineMap[4096000] = 360 * 60; // 1'
761  m_normalLineMap[8192000] = 360 * 60 * 2; // 30"
762  m_normalLineMap[16384000] = 360 * 60 * 6; // 10"
763  m_normalLineMap[65535000] = 360 * 60 * 12; // 5"
764  m_normalLineMap[524288000] = 360 * 60 * 60; // 1"
765 
766  m_boldLineMap[512000] = 360; // 10'
767  m_boldLineMap[1024000] = 720; // 5'
768  m_boldLineMap[4096000] = 360 * 6; // 1'
769  m_boldLineMap[8192000] = 360 * 12; // 30"
770  m_boldLineMap[16384000] = 360 * 60; // 10"
771  m_boldLineMap[65535000] = 360 * 60 * 2; // 5"
772  m_boldLineMap[524288000] = 360 * 60 * 6; // 1"
773 
774  break;
775  }
776  m_normalLineMap[999999999] = m_normalLineMap.value(262144000); // last
777  m_boldLineMap[999999999] = m_boldLineMap.value(262144000); // last
778 
779  m_currentNotation = notation;
780 }
781 
782 }
783 
784 Q_EXPORT_PLUGIN2(GraticulePlugin, Marble::GraticulePlugin)
785 
786 #include "GraticulePlugin.moc"
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:201
Marble::GeoDataCoordinates::UTM
Definition: GeoDataCoordinates.h:83
Marble::Planet::id
QString id() const
The internal, nonlocalized name of the planet.
Definition: Planet.cpp:262
Marble::GraticulePlugin::readSettings
void readSettings()
Definition: GraticulePlugin.cpp:195
Marble::GraticulePlugin::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: GraticulePlugin.cpp:112
Marble::GraticulePlugin::equatorGetColor
void equatorGetColor()
Definition: GraticulePlugin.cpp:238
QDialog
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::IgnoreYMargin
Definition: MarbleGlobal.h:114
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::GraticulePlugin::version
QString version() const
Definition: GraticulePlugin.cpp:91
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::ViewportParams::viewLatLonAltBox
const GeoDataLatLonAltBox & viewLatLonAltBox() const
Definition: ViewportParams.cpp:305
Marble::GeoDataCoordinates::Decimal
"Decimal" notation (base-10)
Definition: GeoDataCoordinates.h:80
Marble::IgnoreXMargin
Definition: MarbleGlobal.h:113
Marble::RenderPlugin::restoreDefaultSettings
void restoreDefaultSettings()
Passes an empty set of settings to the plugin.
Definition: RenderPlugin.cpp:214
Marble::PrintQuality
Print quality.
Definition: MarbleGlobal.h:85
Marble::GraticulePlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: GraticulePlugin.cpp:161
Planet.h
Marble::MarbleModel::planet
const Planet * planet() const
Returns the planet object for the current map.
Definition: MarbleModel.cpp:574
MarbleDebug.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::GraticulePlugin::tropicsGetColor
void tropicsGetColor()
Definition: GraticulePlugin.cpp:227
Marble::GraticulePlugin::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: GraticulePlugin.cpp:86
Marble::LowQuality
Low resolution (e.g. interlaced)
Definition: MarbleGlobal.h:82
Marble::GraticulePlugin::gridGetColor
void gridGetColor()
Definition: GraticulePlugin.cpp:216
Marble::GraticulePlugin::zValue
virtual qreal zValue() const
Returns the z value of the layer (default: 0.0).
Definition: GraticulePlugin.cpp:293
Marble::GraticulePlugin::initialize
void initialize()
Definition: GraticulePlugin.cpp:117
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::RenderPlugin::settingsChanged
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
Marble::GraticulePlugin::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: GraticulePlugin.cpp:61
MarbleDirs.h
Marble::GraticulePlugin
A plugin that creates a coordinate grid on top of the map.
Definition: GraticulePlugin.h:54
Marble::GraticulePlugin::description
QString description() const
Returns a user description of the plugin.
Definition: GraticulePlugin.cpp:96
Marble::LineCenter
Definition: MarbleGlobal.h:111
GeoDataLineString.h
Marble::GraticulePlugin::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: GraticulePlugin.cpp:106
Marble::NoLabel
Definition: MarbleGlobal.h:109
Marble::LineStart
Definition: MarbleGlobal.h:110
Marble::GraticulePlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: GraticulePlugin.cpp:174
GeoPainter.h
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:200
Marble::GeoDataCoordinates::latToString
QString latToString() const
return a string representation of latitude of the coordinate convenience function that uses the defau...
Definition: GeoDataCoordinates.cpp:1176
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::GraticulePlugin::name
QString name() const
Returns the user-visible name of the plugin.
Definition: GraticulePlugin.cpp:76
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::GeoDataCoordinates::lonToString
QString lonToString() const
return a string representation of longitude of the coordinate convenience function that uses the defa...
Definition: GeoDataCoordinates.cpp:1075
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::GraticulePlugin::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: GraticulePlugin.cpp:71
Marble::RespectLatitudeCircle
Definition: MarbleGlobal.h:33
Marble::GraticulePlugin::GraticulePlugin
GraticulePlugin()
Definition: GraticulePlugin.cpp:41
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::GraticulePlugin::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: GraticulePlugin.cpp:66
Marble::GeoDataCoordinates::Notation
Notation
enum used to specify the notation / numerical system
Definition: GeoDataCoordinates.h:79
Marble::OutlineQuality
Only a wire representation is drawn.
Definition: MarbleGlobal.h:81
Marble::GraticulePlugin::render
virtual bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: GraticulePlugin.cpp:260
Marble::GraticulePlugin::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: GraticulePlugin.cpp:81
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::GraticulePlugin::copyrightYears
QString copyrightYears() const
Definition: GraticulePlugin.cpp:101
Marble::HighQuality
High quality (e.g. antialiasing for lines)
Definition: MarbleGlobal.h:84
GeoDataLatLonAltBox.h
GraticulePlugin.h
PluginAboutDialog.h
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::Planet::epsilon
qreal epsilon() const
obliquity of the ecliptic plane
Definition: Planet.cpp:235
Marble::GeoPainter::mapQuality
MapQuality mapQuality() const
Returns the map quality.
Definition: GeoPainter.cpp:191
Marble::GraticulePlugin::configDialog
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
Definition: GraticulePlugin.cpp:131
Marble::Tessellate
Definition: MarbleGlobal.h:32
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:81
Marble::RenderPlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: RenderPlugin.cpp:183
Marble::GeoDataCoordinates::DMS
"Sexagesimal DMS" notation (base-60)
Definition: GeoDataCoordinates.h:81
Marble::GeoDataCoordinates::defaultNotation
static GeoDataCoordinates::Notation defaultNotation()
return Notation of string representation
Definition: GeoDataCoordinates.cpp:764
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GraticulePlugin::isInitialized
bool isInitialized() const
Definition: GraticulePlugin.cpp:126
Marble::RenderPlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: RenderPlugin.cpp:193
Marble::GeoDataCoordinates::Astro
< "RA and DEC" notation (used for astronomical sky coordinates)
Definition: GeoDataCoordinates.h:84
Marble::GraticulePlugin::writeSettings
void writeSettings()
Definition: GraticulePlugin.cpp:249
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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