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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • annotate
GroundOverlayFrame.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 2013 Adrian Draghici <draghici.adrian.b@gmail.com>
9 //
10 
11 #include "GroundOverlayFrame.h"
12 
13 #include "GeoDataPlacemark.h"
14 #include "GeoDataTypes.h"
15 #include "GeoPainter.h"
16 #include "ViewportParams.h"
17 #include "SceneGraphicsTypes.h"
18 
19 
20 namespace Marble
21 {
22 
23 GroundOverlayFrame::GroundOverlayFrame( GeoDataPlacemark *placemark, GeoDataGroundOverlay *overlay, TextureLayer *textureLayer )
24  : SceneGraphicsItem( placemark ),
25  m_movedPoint( -1 ),
26  m_overlay( overlay ),
27  m_textureLayer( textureLayer ),
28  m_viewport( 0 )
29 {
30  update();
31 }
32 
33 void GroundOverlayFrame::paint(GeoPainter *painter, const ViewportParams *viewport )
34 {
35  m_viewport = viewport;
36  QList<QRegion> regionList;
37 
38  painter->save();
39  painter->setBrush( Oxygen::aluminumGray4 );
40  if ( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
41  GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( placemark()->geometry() );
42  GeoDataLinearRing &ring = polygon->outerBoundary();
43  for ( int i = 0; i < ring.size(); ++i ) {
44  regionList.append( painter->regionFromEllipse( ring.at(i), 10, 10 ) );
45  }
46  regionList.append( painter->regionFromPolygon( ring, Qt::OddEvenFill ) );
47  }
48  painter->restore();
49  setRegions( regionList );
50 }
51 
52 bool GroundOverlayFrame::mousePressEvent( QMouseEvent *event )
53 {
54  QList<QRegion> regionList = regions();
55 
56  // React to all ellipse as well as to the polygon.
57  for ( int i = 0; i < regionList.size(); ++i ) {
58  if ( regionList.at(i).contains( event->pos() ) ) {
59  m_movedPoint = i;
60 
61  qreal lon, lat;
62  m_viewport->geoCoordinates( event->pos().x(),
63  event->pos().y(),
64  lon, lat,
65  GeoDataCoordinates::Radian );
66  m_movedPointCoordinates.set( lon, lat );
67 
68  return true;
69  }
70  }
71  return false;
72 }
73 
74 bool GroundOverlayFrame::mouseMoveEvent( QMouseEvent *event )
75 {
76  if( !m_viewport || m_movedPoint < 0 ) {
77  return false;
78  }
79 
80  if( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
81  qreal lon, lat;
82  m_viewport->geoCoordinates( event->pos().x(),
83  event->pos().y(),
84  lon, lat,
85  GeoDataCoordinates::Radian );
86 
87  qreal rotatedLon;
88  qreal rotatedLat;
89 
90  rotateAroundCenter( lon, lat, rotatedLon, rotatedLat, m_overlay->latLonBox(), true );
91 
92  if ( m_movedPoint == NorthWest ) {
93  m_overlay->latLonBox().setNorth( rotatedLat );
94  m_overlay->latLonBox().setWest( rotatedLon );
95  }
96  if ( m_movedPoint == SouthWest ) {
97  m_overlay->latLonBox().setSouth( rotatedLat );
98  m_overlay->latLonBox().setWest( rotatedLon );
99  }
100  if ( m_movedPoint == SouthEast ) {
101  m_overlay->latLonBox().setSouth( rotatedLat );
102  m_overlay->latLonBox().setEast( rotatedLon );
103  }
104  if ( m_movedPoint == NorthEast ) {
105  m_overlay->latLonBox().setNorth( rotatedLat );
106  m_overlay->latLonBox().setEast( rotatedLon );
107  }
108  if ( m_movedPoint == Polygon ) {
109 
110  qreal centerLonDiff = lon - m_movedPointCoordinates.longitude();
111  qreal centerLatDiff = lat - m_movedPointCoordinates.latitude();
112 
113  m_overlay->latLonBox().setBoundaries( m_overlay->latLonBox().north() + centerLatDiff,
114  m_overlay->latLonBox().south() + centerLatDiff,
115  m_overlay->latLonBox().east() + centerLonDiff,
116  m_overlay->latLonBox().west() + centerLonDiff );
117 
118  m_movedPointCoordinates.set( lon, lat );
119  }
120 
121  update();
122 
123  return true;
124  }
125  return false;
126 }
127 
128 bool GroundOverlayFrame::mouseReleaseEvent( QMouseEvent *event )
129 {
130  Q_UNUSED( event );
131 
132  m_movedPoint = -1;
133  m_textureLayer->reset();
134 
135  return true;
136 }
137 
138 void GroundOverlayFrame::update()
139 {
140  GeoDataLatLonBox overlayLatLonBox = m_overlay->latLonBox();
141 
142  GeoDataPolygon *poly = dynamic_cast<GeoDataPolygon*>( placemark()->geometry() );
143 
144  poly->outerBoundary().clear();
145 
146  qreal rotatedLon;
147  qreal rotatedLat;
148 
149  rotateAroundCenter( overlayLatLonBox.west(), overlayLatLonBox.north(), rotatedLon, rotatedLat, overlayLatLonBox );
150  poly->outerBoundary().append( GeoDataCoordinates( rotatedLon, rotatedLat ) );
151 
152  rotateAroundCenter( overlayLatLonBox.west(), overlayLatLonBox.south(), rotatedLon, rotatedLat, overlayLatLonBox );
153  poly->outerBoundary().append( GeoDataCoordinates( rotatedLon, rotatedLat ) );
154 
155  rotateAroundCenter( overlayLatLonBox.east(), overlayLatLonBox.south(), rotatedLon, rotatedLat, overlayLatLonBox );
156  poly->outerBoundary().append( GeoDataCoordinates( rotatedLon, rotatedLat ) );
157 
158  rotateAroundCenter( overlayLatLonBox.east(), overlayLatLonBox.north(), rotatedLon, rotatedLat, overlayLatLonBox );
159  poly->outerBoundary().append( GeoDataCoordinates( rotatedLon, rotatedLat ) );
160 }
161 
162 void GroundOverlayFrame::rotateAroundCenter( qreal lon, qreal lat, qreal &rotatedLon, qreal &rotatedLat, GeoDataLatLonBox &box, bool inverse )
163 {
164  const qreal angle = ( inverse ? ( -1 ) : 1 ) * box.rotation();
165  const qreal sinRotation = sin( angle );
166  const qreal cosRotation = cos( angle );
167 
168  const qreal centerLat = box.center().latitude();
169  qreal centerLon = box.center().longitude();
170 
171  if ( box.crossesDateLine() ) {
172  if ( lon < 0 && centerLon > 0 ) {
173  centerLon -= 2 * M_PI;
174  }
175  if ( lon > 0 && centerLon < 0 ) {
176  centerLon += 2 * M_PI;
177  }
178  if ( box.west() > 0 && box.east() > 0 && box.west() > box.east() && lon > 0 && lon < box.west() ) {
179  if ( ! ( lon < box.west() && lon > box.toCircumscribedRectangle().west() ) ) {
180  centerLon -= 2 * M_PI;
181  }
182  }
183  }
184 
185  rotatedLon = ( lon - centerLon ) * cosRotation - ( lat - centerLat ) * sinRotation + centerLon;
186  rotatedLat = ( lon - centerLon ) * sinRotation + ( lat - centerLat ) * cosRotation + centerLat;
187 
188  GeoDataCoordinates::normalizeLonLat( rotatedLon, rotatedLat );
189 }
190 
191 const char *GroundOverlayFrame::graphicType() const
192 {
193  return SceneGraphicTypes::SceneGraphicGroundOverlay;
194 }
195 
196 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
SceneGraphicsTypes.h
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataLatLonBox::setNorth
void setNorth(const qreal north, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:101
angle
double angle(double vec1[3], double vec2[3])
Definition: sgp4ext.cpp:164
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
GroundOverlayFrame.h
Marble::GeoDataTypes::GeoDataPolygonType
const char * GeoDataPolygonType
Definition: GeoDataTypes.cpp:69
Marble::ViewportParams::geoCoordinates
bool geoCoordinates(const int x, const int y, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const
Get the earth coordinates corresponding to a pixel in the map.
Definition: ViewportParams.cpp:391
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::GroundOverlayFrame::GroundOverlayFrame
GroundOverlayFrame(GeoDataPlacemark *placemark, GeoDataGroundOverlay *overlay, TextureLayer *textureLayer)
Definition: GroundOverlayFrame.cpp:23
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
QList::at
const T & at(int i) const
Marble::SceneGraphicsItem::setRegions
void setRegions(const QList< QRegion > &regions)
A setter for the m_regions private member.
Definition: SceneGraphicsItem.cpp:36
QPainter::save
void save()
Marble::GeoDataLatLonBox::setSouth
void setSouth(const qreal south, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:122
QMouseEvent
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::GeoDataLatLonBox::setWest
void setWest(const qreal west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:164
Marble::GeoPainter::regionFromEllipse
QRegion regionFromEllipse(const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false, qreal strokeWidth=3) const
Creates a region for an ellipse at a given position.
Definition: GeoPainter.cpp:356
Marble::GeoDataGroundOverlay::latLonBox
GeoDataLatLonBox & latLonBox() const
Definition: GeoDataGroundOverlay.cpp:97
QPoint::x
int x() const
Marble::GroundOverlayFrame::NorthWest
Definition: GroundOverlayFrame.h:27
QList::size
int size() const
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry()
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:152
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
QList::append
void append(const T &value)
Marble::Oxygen::aluminumGray4
QColor const aluminumGray4
Definition: MarbleColors.h:92
Marble::TextureLayer::reset
void reset()
Definition: TextureLayer.cpp:420
Marble::SceneGraphicsItem
This is the base class for all scene graphics included within the annotate plugin.
Definition: SceneGraphicsItem.h:34
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::TextureLayer
Definition: TextureLayer.h:38
QPainter::setBrush
void setBrush(const QBrush &brush)
Marble::GroundOverlayFrame::SouthWest
Definition: GroundOverlayFrame.h:28
QList< QRegion >
Marble::GeoDataLatLonBox::rotation
qreal rotation(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the rotation of the bounding box.
Definition: GeoDataLatLonBox.cpp:190
Marble::GeoDataCoordinates::normalizeLonLat
static void normalizeLonLat(qreal &lon, qreal &lat, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize both longitude and latitude at the same time This method normalizes both latitude and longi...
Definition: GeoDataCoordinates.cpp:845
GeoPainter.h
Marble::GeoDataCoordinates::set
void set(qreal lon, qreal lat, qreal alt=0, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
(re)set the coordinates in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:657
GeoDataPlacemark.h
Marble::GeoDataLineString::append
void append(const GeoDataCoordinates &position)
Appends a given geodesic position as a new node to the LineString.
Definition: GeoDataLineString.cpp:225
Marble::GeoDataPolygon::outerBoundary
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
Definition: GeoDataPolygon.cpp:123
Marble::GeoDataLineString::at
GeoDataCoordinates & at(int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
Definition: GeoDataLineString.cpp:143
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::GeoDataLatLonBox::center
virtual GeoDataCoordinates center() const
returns the center of this box
Definition: GeoDataLatLonBox.cpp:276
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::GeoDataLatLonBox::crossesDateLine
bool crossesDateLine() const
Detect whether the bounding box crosses the IDL.
Definition: GeoDataLatLonBox.cpp:266
Marble::GeoDataLatLonBox::toCircumscribedRectangle
GeoDataLatLonBox toCircumscribedRectangle() const
Definition: GeoDataLatLonBox.cpp:506
QPainter::restore
void restore()
Marble::SceneGraphicTypes::SceneGraphicGroundOverlay
const char * SceneGraphicGroundOverlay
Definition: SceneGraphicsTypes.cpp:21
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::SceneGraphicsItem::regions
QList< QRegion > regions() const
Returns the list of regions which form the scene graphic element.
Definition: SceneGraphicsItem.cpp:31
Marble::GeoPainter::regionFromPolygon
QRegion regionFromPolygon(const GeoDataLinearRing &linearRing, Qt::FillRule fillRule, qreal strokeWidth=3) const
Creates a region for a given linear ring (a "polygon without holes").
Definition: GeoPainter.cpp:585
Marble::GroundOverlayFrame::NorthEast
Definition: GroundOverlayFrame.h:30
Marble::GroundOverlayFrame::Polygon
Definition: GroundOverlayFrame.h:31
Marble::GroundOverlayFrame::update
void update()
Definition: GroundOverlayFrame.cpp:138
Marble::GroundOverlayFrame::graphicType
virtual const char * graphicType() const
Provides information for downcasting a SceneGraphicsItem.
Definition: GroundOverlayFrame.cpp:191
Marble::GeoDataLineString::clear
void clear()
Destroys all nodes in a LineString.
Definition: GeoDataLineString.cpp:298
Marble::GroundOverlayFrame::SouthEast
Definition: GroundOverlayFrame.h:29
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
Marble::GeoDataLatLonBox::setBoundaries
void setBoundaries(qreal north, qreal south, qreal east, qreal west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:217
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::GeoDataGroundOverlay
Definition: GeoDataGroundOverlay.h:24
Marble::SceneGraphicsItem::placemark
const GeoDataPlacemark * placemark() const
SceneGraphicItem class, when called from one of its derived classes' constructors, takes as a parameter a pointer to the placemark of the graphic element.
Definition: SceneGraphicsItem.cpp:41
QMouseEvent::pos
const QPoint & pos() const
GeoDataTypes.h
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::GeoDataLatLonBox
A class that defines a 2D bounding box for geographic data.
Definition: GeoDataLatLonBox.h:51
Marble::GeoDataLatLonBox::setEast
void setEast(const qreal east, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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
  • 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