File indexing completed on 2024-05-12 03:50:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
0004 // SPDX-FileCopyrightText: 2008 Inge Wallin <inge@lysator.liu.se>
0005 //
0006 
0007 
0008 #ifndef MARBLE_GEODATAPOLYGON_H
0009 #define MARBLE_GEODATAPOLYGON_H
0010 
0011 #include <QVector>
0012 
0013 #include "MarbleGlobal.h"
0014 
0015 #include "geodata_export.h"
0016 #include "GeoDataGeometry.h"
0017 
0018 namespace Marble
0019 {
0020 
0021 class GeoDataPolygonPrivate;
0022 class GeoDataLinearRing;
0023 class GeoDataCoordinates;
0024 
0025 /*!
0026     \class GeoDataPolygon
0027     \brief A polygon that can have "holes".
0028 
0029     GeoDataPolygon is a tool class that implements the Polygon tag/class
0030     of the Open Geospatial Consortium standard KML 2.2.
0031 
0032     GeoDataPolygon extends GeoDataGeometry to store and edit
0033     Polygons.
0034 
0035     In the QPainter API "pure" Polygons would represent polygons with
0036     "holes" inside. However QPolygon doesn't provide this feature directly.
0037 
0038     Whenever a Polygon is painted GeoDataLineStyle should be used to assign a
0039     color and line width.
0040 
0041     The polygon consists of
0042     \li a single outer boundary and
0043     \li optionally a set of inner boundaries.
0044 
0045     All boundaries are LinearRings.
0046 
0047     The boundaries of a GeoDataPolygon consist of several (geodetic) nodes which
0048     are each connected through line segments. The nodes are stored as
0049     GeoDataCoordinates objects.
0050 
0051 
0052     The API which provides access to the nodes is similar to the API of
0053     QVector.
0054 
0055     GeoDataPolygon allows Polygons to be tessellated in order to make them
0056     follow the terrain and the curvature of the earth. The tessellation options
0057     allow for different ways of visualization:
0058 
0059     \li Not tessellated: A Polygon that connects each two nodes directly and
0060         straight in screen coordinate space.
0061     \li A tessellated line: Each line segment is bent so that the Polygon
0062         follows the curvature of the earth and its terrain. A tessellated
0063         line segment connects two nodes at the shortest possible distance
0064         ("along great circles").
0065     \li A tessellated line that follows latitude circles whenever possible:
0066         In this case Latitude circles are followed as soon as two subsequent
0067         nodes have exactly the same amount of latitude. In all other places the
0068         line segments follow great circles.
0069 
0070     Some convenience methods have been added that allow to calculate the
0071     geodesic bounding box or the length of a Polygon.
0072 
0073     \see GeoDataLinearRing
0074 */
0075 
0076 class GEODATA_EXPORT GeoDataPolygon : public GeoDataGeometry
0077 {
0078  public:
0079 /*!
0080     \brief Creates a new Polygon.
0081 */
0082     explicit GeoDataPolygon( TessellationFlags f = NoTessellation );
0083 
0084 
0085 /*!
0086     \brief Creates a Polygon from an existing geometry object.
0087 */
0088     explicit GeoDataPolygon( const GeoDataGeometry &other );
0089 
0090 /*!
0091     \brief Destroys a Polygon.
0092 */
0093     ~GeoDataPolygon() override;
0094 
0095     const char *nodeType() const override;
0096 
0097     EnumGeometryId geometryId() const override;
0098 
0099     GeoDataGeometry *copy() const override;
0100 
0101 /*!
0102     \brief Returns true/false depending on whether this and other are/are not equal.
0103 */
0104     bool operator==( const GeoDataPolygon &other ) const;
0105     bool operator!=( const GeoDataPolygon &other ) const;
0106 
0107 
0108 /*!
0109     \brief Returns whether a Polygon is a closed polygon.
0110 
0111     \return <code>true</code> for a Polygon.
0112 */    
0113     virtual bool isClosed() const;
0114 
0115 
0116 /*!
0117     \brief Returns whether the Polygon follows the earth's surface.
0118 
0119     \return <code>true</code> if the Polygon's line segments follow the
0120     earth's surface and terrain along great circles.
0121 */    
0122     bool tessellate() const;
0123 
0124 
0125 /*!
0126     \brief Sets the tessellation property for the Polygon.
0127 
0128     If \a tessellate is <code>true</code> then the Polygon's line segments
0129     are bent and follow the earth's surface and terrain along great circles.
0130     If \a tessellate is <code>false</code> then the Polygon's line segments
0131     are rendered as straight lines in screen coordinate space.
0132 */
0133     void setTessellate( bool tessellate );
0134 
0135     
0136 /*!
0137     \brief Returns the tessellation flags for a Polygon.
0138 */
0139     TessellationFlags tessellationFlags() const;
0140 
0141 
0142 /*!
0143     \brief Sets the given tessellation flags for a Polygon.
0144 */
0145     void setTessellationFlags( TessellationFlags f );
0146 
0147 
0148 /*!
0149     \brief Returns the smallest latLonAltBox that contains the Polygon.
0150 
0151     \see GeoDataLatLonAltBox
0152 */
0153     const GeoDataLatLonAltBox& latLonAltBox() const override;
0154 
0155 /*!
0156     \brief Returns the outer boundary that is represented as a LinearRing.
0157 
0158     \see GeoDataLinearRing
0159 */
0160     GeoDataLinearRing &outerBoundary();
0161 
0162 /*!
0163     \brief Returns the outer boundary that is represented as a LinearRing.
0164 
0165     \see GeoDataLinearRing
0166 */
0167     const GeoDataLinearRing &outerBoundary() const;
0168 
0169 /*!
0170     \brief Sets the given LinearRing as an outer boundary of the Polygon.
0171 
0172     \see GeoDataLinearRing
0173 */
0174     void setOuterBoundary( const GeoDataLinearRing& boundary );
0175 
0176 /*!
0177     \brief Returns a set of inner boundaries which are represented as LinearRings.
0178 
0179     \see GeoDataLinearRing
0180 */
0181     QVector<GeoDataLinearRing>& innerBoundaries();
0182 
0183 /*!
0184     \brief Returns a set of inner boundaries which are represented as LinearRings.
0185 
0186     \see GeoDataLinearRing
0187 */
0188     const QVector<GeoDataLinearRing>& innerBoundaries() const;
0189 
0190 /*!
0191     \brief Appends a given LinearRing as an inner boundary of the Polygon.
0192 
0193     \see GeoDataLinearRing
0194 */
0195     void appendInnerBoundary( const GeoDataLinearRing& boundary );
0196 
0197 /*!
0198     \brief Returns whether the given coordinates lie within the polygon.
0199 
0200     \return <code>true</code> if the coordinates lie within the polygon
0201     (and not in its holes), false otherwise.
0202 */
0203     virtual bool contains( const GeoDataCoordinates &coordinates ) const;
0204 
0205     // Serialization
0206 /*!
0207     \brief Serialize the Polygon to a stream.
0208     \param stream the stream.
0209 */
0210     void pack( QDataStream& stream ) const override;
0211 
0212     
0213 /*!
0214     \brief Unserialize the Polygon from a stream.
0215     \param stream the stream.
0216 */
0217     void unpack( QDataStream& stream ) override;
0218 
0219     int renderOrder() const;
0220     void setRenderOrder(int);
0221 
0222  private:
0223     Q_DECLARE_PRIVATE(GeoDataPolygon)
0224 };
0225 
0226 class GEODATA_EXPORT GeoDataOuterBoundary : public GeoDataPolygon
0227 {
0228 };
0229 
0230 class GEODATA_EXPORT GeoDataInnerBoundary : public GeoDataPolygon
0231 {
0232 };
0233 
0234 }
0235 
0236 #endif // GEODATAPOLYGON_H