File indexing completed on 2024-04-28 11:31:27

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0004 // SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
0005 //
0006 
0007 #ifndef MARBLE_VIEWPORTPARAMS_H
0008 #define MARBLE_VIEWPORTPARAMS_H
0009 
0010 
0011 /** @file
0012  * This file contains the headers for ViewportParams.
0013  * 
0014  * @author Inge Wallin  <inge@lysator.liu.se>
0015  */
0016 
0017 #include <QSize>
0018 
0019 #include "GeoDataCoordinates.h"
0020 #include "Quaternion.h"
0021 #include "MarbleGlobal.h"
0022 #include "marble_export.h"
0023 
0024 class QPolygonF;
0025 class QPainterPath;
0026 
0027 namespace Marble
0028 {
0029 
0030 class GeoDataLatLonAltBox;
0031 class GeoDataLatLonBox;
0032 class GeoDataLineString;
0033 class AbstractProjection;
0034 class ViewportParamsPrivate;
0035 
0036 /** 
0037  * @short A public class that controls what is visible in the viewport of a Marble map.
0038  *
0039  */
0040 
0041 class MARBLE_EXPORT ViewportParams
0042 {
0043  public:
0044     ViewportParams( );
0045     explicit ViewportParams( Projection projection,
0046                              qreal centerLongitude = 0, qreal centerLatitude = 0,
0047                              int radius = 2000,
0048                              const QSize &size = QSize( 100, 100 ) );
0049     ~ViewportParams();
0050 
0051     // Getters and setters
0052     Projection projection() const;
0053     const AbstractProjection *currentProjection() const;
0054     void setProjection(Projection newProjection);
0055 
0056     int polarity() const;
0057 
0058     const GeoDataLatLonAltBox& viewLatLonAltBox() const;
0059 
0060     GeoDataLatLonAltBox latLonAltBox( const QRect &screenRect ) const;
0061 
0062     // Calculates an educated guess for the average angle in radians covered per pixel.
0063     // Given a certain resolution it doesn't make much sense
0064     // - to display an object that covers an angle that is smaller than that.
0065     // - to display two points as distinct points if they are separated by a 
0066     //   an angular distance that is smaller. Instead only one point should be shown.
0067     // So this method helps to filter out details.
0068     // It's somewhat related to https://en.wikipedia.org/wiki/Angular_resolution
0069 
0070     qreal angularResolution() const;
0071 
0072     // Determines whether a geographical feature is big enough so that it should 
0073     // represent a single point on the screen already.
0074     // See angularResolution()
0075 
0076     bool resolves ( const GeoDataLatLonBox &latLonBox, qreal pixel = 2.0 ) const;
0077 
0078     bool resolves ( const GeoDataLatLonAltBox &latLonAltBox, qreal pixel = 2.0, qreal altitude = 10000.0 ) const;
0079 
0080     // Determines whether two points are located enough apart so that it makes 
0081     // sense to display them as distinct points. If this is not the case
0082     // calculation and drawing of one point can be skipped as only a single
0083     // point will be displayed on the screen.
0084     
0085     bool resolves ( const GeoDataCoordinates &coord1, const GeoDataCoordinates &coord2 ) const;
0086 
0087     int  radius() const;
0088 
0089     /**
0090      * @brief Change the radius of the planet
0091      * @param radius Size of the planet radius in pixel. Non-positive values are ignored.
0092      */
0093     void setRadius(int radius);
0094 
0095     void centerOn( qreal lon, qreal lat );
0096     void setHeading( qreal heading );
0097 
0098     Quaternion planetAxis() const;
0099     const matrix &planetAxisMatrix() const;
0100 
0101     int width()  const;
0102     int height() const;
0103     QSize size() const;
0104 
0105     void setWidth(int newWidth);
0106     void setHeight(int newHeight);
0107     void setSize(const QSize& newSize);
0108 
0109     qreal centerLongitude() const;
0110     qreal centerLatitude() const;
0111 
0112     /**
0113      * @brief Get the screen coordinates corresponding to geographical coordinates in the map.
0114      * @param lon    the lon coordinate of the requested pixel position in radians
0115      * @param lat    the lat coordinate of the requested pixel position in radians
0116      * @param x      the x coordinate of the pixel is returned through this parameter
0117      * @param y      the y coordinate of the pixel is returned through this parameter
0118      * @return @c true  if the geographical coordinates are visible on the screen
0119      *         @c false if the geographical coordinates are not visible on the screen
0120      *
0121      * @see ViewportParams
0122      */
0123     bool screenCoordinates( const qreal lon, const qreal lat,
0124                             qreal &x, qreal &y ) const;
0125 
0126     /**
0127      * @brief Get the screen coordinates corresponding to geographical coordinates in the map.
0128      *
0129      * @param geopoint the point on earth, including altitude, that we want the coordinates for.
0130      * @param x      the x coordinate of the pixel is returned through this parameter
0131      * @param y      the y coordinate of the pixel is returned through this parameter
0132      * @param globeHidesPoint  whether the point gets hidden on the far side of the earth
0133      *
0134      * @return @c true  if the geographical coordinates are visible on the screen
0135      *         @c false if the geographical coordinates are not visible on the screen
0136      *
0137      * @see ViewportParams
0138      */
0139     bool screenCoordinates( const GeoDataCoordinates &geopoint,
0140                             qreal &x, qreal &y,
0141                             bool &globeHidesPoint ) const;
0142 
0143     // Will just call the virtual version with a dummy globeHidesPoint.
0144     bool screenCoordinates( const GeoDataCoordinates &geopoint,
0145                             qreal &x, qreal &y ) const;
0146 
0147     /**
0148      * @brief Get the coordinates of screen points for geographical coordinates in the map.
0149      *
0150      * @param coordinates the point on earth, including altitude, that we want the coordinates for.
0151      * @param x      the x coordinates of the pixels are returned through this parameter
0152      * @param y      the y coordinate of the pixel is returned through this parameter
0153      * @param pointRepeatNum      the amount of times that a single geographical
0154                                   point gets represented on the map
0155      * @param size   the size of the point
0156      * @param globeHidesPoint  whether the point gets hidden on the far side of the earth
0157      *
0158      * @return @c true  if the geographical coordinates are visible on the screen
0159      *         @c false if the geographical coordinates are not visible on the screen
0160      *
0161      * @see ViewportParams
0162      */
0163     bool screenCoordinates( const GeoDataCoordinates &coordinates,
0164                             qreal *x, qreal &y, int &pointRepeatNum,
0165                             const QSizeF& size,
0166                             bool &globeHidesPoint ) const;
0167 
0168 
0169     bool screenCoordinates( const GeoDataLineString &lineString,
0170                             QVector<QPolygonF*> &polygons ) const;
0171 
0172     /**
0173      * @brief Get the earth coordinates corresponding to a pixel in the map.
0174      * @param x      the x coordinate of the pixel
0175      * @param y      the y coordinate of the pixel
0176      * @param lon    the longitude angle is returned through this parameter
0177      * @param lat    the latitude angle is returned through this parameter
0178      * @param unit   the unit of the angles for lon and lat.
0179      * @return @c true  if the pixel (x, y) is within the globe
0180      *         @c false if the pixel (x, y) is outside the globe, i.e. in space.
0181      */
0182     bool geoCoordinates( const int x, const int y,
0183                          qreal &lon, qreal &lat,
0184                          GeoDataCoordinates::Unit unit = GeoDataCoordinates::Degree ) const;
0185 
0186     qreal heading() const;
0187     bool mapCoversViewport() const;
0188 
0189     QPainterPath mapShape() const;
0190 
0191     QRegion mapRegion() const;
0192 
0193     /**
0194       * @return The current point of focus, e.g. the point that is not moved
0195       * when changing the zoom level. If not set, it defaults to the
0196       * center point.
0197       * @see centerCoordinates setFocusPoint resetFocusPoint
0198       */
0199     GeoDataCoordinates focusPoint() const;
0200 
0201     /**
0202       * @brief Change the point of focus, overridding any previously set focus point.
0203       * @param focusPoint New focus point
0204       * @see focusPoint resetFocusPoint
0205       */
0206     void setFocusPoint(const GeoDataCoordinates &focusPoint);
0207 
0208     /**
0209       * @brief Invalidate any focus point set with @ref setFocusPoint.
0210       * @see focusPoint setFocusPoint
0211       */
0212     void resetFocusPoint();
0213 
0214  private:
0215     Q_DISABLE_COPY( ViewportParams )
0216     ViewportParamsPrivate * const d;
0217 };
0218 
0219 }
0220 
0221 #endif