Logo Search packages:      
Sourcecode: qlandkarte version File versions  Download package

CGarminImg.h

/**********************************************************************************************
    Copyright (C) 2006, 2007 Oliver Eichler oliver.eichler@gmx.de

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA

  Garmin and MapSource are registered trademarks or trademarks of Garmin Ltd.
  or one of its subsidiaries.

  This source is based on John Mechalas documentation "Garmin IMG File Format" found
  at sourceforge. The missing bits and error where rectified by the source code of
  Konstantin Galichsky (kg@geopainting.com), http://www.geopainting.com

**********************************************************************************************/
#ifndef CGARMINIMG_H
#define CGARMINIMG_H

#include <QObject>
#include <QString>
#include <QMap>
#include <QRectF>
#include <QDebug>

#include "GarminStrTbl.h"
#include "CGarminPolygon.h"

class IGarminStrTbl;

/// subfile part (TRE, RGN, ...) location information
00041 struct subfile_part_t
{
    subfile_part_t() : offset(0), size(0){}
    /// file offset of subfile part
00045     quint32 offset;
    /// size of the subfile part
00047     quint32 size;
};

class CGarminPoint : public str_info_t
{
    public:
        CGarminPoint() : isLbl6(false), hasSubType(false) {}
        ~CGarminPoint(){}

        quint32 decode(subdiv_desc_t& subdiv, quint8 * pData);

        //quint16 type;
        bool isLbl6;
        bool hasSubType;

        //QString label;
        // double lng;
        // double lat;
        XY point;
};

/// subdivision  information
00069 struct subdiv_desc_t
{
    quint32 n;
    /// section of next level
00073     quint16 next;
    /// end of section group
00075     bool terminate;
    /// offset into the subfile's RGN part
00077     quint32 rgn_start;
    /// end of section in RGN part (last offset = rgn_end - 1)
00079     quint32 rgn_end;

    /// there are points stored in the RGN subsection
00082     bool hasPoints;
    /// there are indexd points stored in the RGN subsection
00084     bool hasIdxPoints;
    /// there are polylines stored in the RGN subsection
00086     bool hasPolylines;
    /// there are polygons stored in the RGN subsection
00088     bool hasPolygons;

    /// the center longitude of the area covered by this subdivision
00091     qint32 iCenterLng;
    /// the center latiude of the area covered by this subdivision
00093     qint32 iCenterLat;

    /// north boundary of area covered by this subsection
00096     double north;
    /// east boundary of area covered by this subsection
00098     double east;
    /// south boundary of area covered by this subsection
00100     double south;
    /// west boundary of area covered by this subsection
00102     double west;

    /// area in meter coordinates covered by this subdivision
00105     QRectF area;

    /// number of left shifts for RGN data
00108     quint32 shift;
    /// map level this subdivision is shown
00110     quint32 level;
    /// pointer to string table (LBL section) object
00112     IGarminStrTbl * strtbl;

    QVector<CGarminPoint>               points;
    QVector<CGarminPoint>               pois;
    QVector<CGarminPolygon>             polylines;
    /// polygons are stored as multimap. See CGarminMap::drawPolygons()
00118     QMultiMap<quint16,CGarminPolygon>   polygons;
};

/// subfile information
00122 struct subfile_desc_t
{
    subfile_desc_t() : north(0.0), east(0.0), south(0.0), west(0.0), isTransparent(false) {}

    struct maplevel_t
    {
        bool inherited;
        quint8 level;
        quint8 bits;
    };

    /// the name of the subfile (not really needed)
00134     QString name;
    /// location information of all parts
00136     QMap<QString,subfile_part_t> parts;

    /// north boundary of area covered by this subfile [rad]
00139     double north;
    /// east boundary of area covered by this subfile [rad]
00141     double east;
    /// south boundary of area covered by this subfile [rad]
00143     double south;
    /// west boundary of area covered by this subfile [rad]
00145     double west;

    /// area in meter coordinates covered by this subfile
00148     QRectF area;
    /// pointer collection to definition areas
00150     QMap<QString,CGarminPolygon> definitionAreas;

    /// list of subdivisions
00153     QVector<subdiv_desc_t> subdivs;
    /// used maplevels
00155     QVector<maplevel_t> maplevels;
    /// bit 1 of POI_flags (TRE header @ 0x3F)
00157     bool isTransparent;
};

enum exce_garmin_e {errOpen,errFormat,errLock};
struct exce_garmin_t
{
    exce_garmin_t(exce_garmin_e err, const QString& msg) : err(err), msg(msg) {}
    exce_garmin_e err;
    QString msg;
};

/// read map data from Garmin *.img file
/**

 */
00172 class CGarminImg : public QObject
{
    Q_OBJECT
        public:
        CGarminImg(QObject * parent);
        virtual ~CGarminImg();
        /// read Garmin *.img file
        void load(const QString& filename, bool peek = false);
        /// get access to map data
00181         const QMap<QString,subfile_desc_t>& getSubFiles(){return subfiles;}

        const QString& getMapDesc(){return mapdesc;}

        bool isTransparent(){return transparent;}

        static const QString polyline_typestr[];

        struct polygon_typestr_entry_t { quint16 order; QString str; };
        static const polygon_typestr_entry_t polygon_typestr[];
    protected:
        void loadSubFile(subfile_desc_t& subfile, quint8 * const pRawData, bool peek);
        void loadSubDiv(subfile_desc_t& subfile, subdiv_desc_t& subdiv, quint8 * const pRawData);

        /// hold all subfile descriptors
        /**
            In a normal *.img file there is only one subfile. However
            gmapsupp.img files can hold several subfiles each with it's
            own subfile parts.
        */
00201         QMap<QString,subfile_desc_t> subfiles;

        /// the img headers map descriptor
00204         QString mapdesc;
        /// relay the transparent flags from the subfiles
00206         bool transparent;
};

#define DEG(x) ((x) < 0x800000 ? (double)(x) * 360.0 / 16777216.0 : (double)((x) - 0x1000000) * 360.0 / 16777216.0)
#define RAD(x) ((x) < 0x800000 ? (double)(x) * TWOPI / 16777216.0 : (double)((x) - 0x1000000) * TWOPI / 16777216.0)
#endif                           //CGARMINIMG_H

Generated by  Doxygen 1.6.0   Back to index