LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sxf - org_sxf_defs.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 6 6 100.0 %
Date: 2024-04-27 17:22:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  SXF Translator
       5             :  * Purpose:  Include file defining Records Structures for file reading and
       6             :  *           basic constants.
       7             :  * Author:   Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr
       8             :  *           Dmitry Baryshnikov, polimax@mail.ru
       9             :  *           Alexandr Lisovenko, alexander.lisovenko@gmail.com
      10             :  *
      11             :  ******************************************************************************
      12             :  * Copyright (c) 2011, Ben Ahmed Daho Ali
      13             :  * Copyright (c) 2013, NextGIS
      14             :  *
      15             :  * Permission is hereby granted, free of charge, to any person obtaining a
      16             :  * copy of this software and associated documentation files (the "Software"),
      17             :  * to deal in the Software without restriction, including without limitation
      18             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      19             :  * and/or sell copies of the Software, and to permit persons to whom the
      20             :  * Software is furnished to do so, subject to the following conditions:
      21             :  *
      22             :  * The above copyright notice and this permission notice shall be included
      23             :  * in all copies or substantial portions of the Software.
      24             :  *
      25             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      26             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      27             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      28             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      29             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      30             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      31             :  * DEALINGS IN THE SOFTWARE.
      32             :  *
      33             :  ******************************************************************************
      34             :  * Structure of the SXF file :
      35             :  * ----------------------
      36             :  *    - Header
      37             :  *    - Passport
      38             :  *    - Descriptor of data
      39             :  *    - Records
      40             :  *         - Title of the record
      41             :  *         - The certificate of the object (the geometry)
      42             :  *             - sub-objects
      43             :  *             - The graphic description of object
      44             :  *             - The description of the vector of the tying of the 3d- model of
      45             :  *object
      46             :  *         - Semantics of object
      47             :  *
      48             :  * Notes  :
      49             :  * -------
      50             :  * Note 1.  Flag of the state of data (2 bits):
      51             :  * xxxxxx11- given in the state e (size of the exchange of data).
      52             :  *
      53             :  * Note 2.  Flag of the correspondence to projection (1 bit):
      54             :  * xxxxx0xx - do not correspond to the projection (i.e. map it can have turning
      55             :  *                 relative to true position and certain deformation);
      56             :  * xxxxx1xx - correspond to projection.
      57             :  *
      58             :  * Note 3.  Flag of the presence of real coordinates (2 bits):
      59             :  * xxx00xxx - entire certificate of objects is represented in the conditional
      60             :  *                                 system of coordinates (in the samples);
      61             :  * xxx11xxx - entire certificate of objects is represented in the real
      62             :  *coordinates in the locality in accordance with the specifications of sheet
      63             :  *            (projection, the coordinate system, unit of measurement),
      64             :  *            the data about the scale and the discretion of digitization bear
      65             :  *            reference nature.
      66             :  *
      67             :  * Note 4. Flag of the method of coding (2 bits):
      68             :  * x00xxxxx - the classification codes of objects and semantic characteristics
      69             :  *          are represented by the decimal numbers, recorded in the binary
      70             :  *          form (for example: the code of the object "32100000" will be written
      71             :  *          down in the form 0x01E9CEA0, the code of semantics "253" - in the
      72             :  *form 0x00FD).
      73             :  *
      74             :  * Note 5. Table of generalization (1 bit):
      75             :  * 0xxxxxxx - the level of generalization is assigned according to the table of
      76             :  *the general maps (it is described in Table 2.4); 1xxxxxxx - noload condition
      77             :  *the level of generalization is assigned according to the table of the
      78             :  *large-scale maps (it is described in Table 2.5).
      79             :  *
      80             :  * Note 6.  Flag of coding the texts of the Texts objects (1 bytes):
      81             :  * 0- in the coding ASCIIZ (Dos);
      82             :  * 1- in the coding ANSI (Windows);
      83             :  * 2- in the coding KOI-8 (Unix).
      84             :  *
      85             :  * Note 7.  Flag of the accuracy of coordinates (1 bytes):
      86             :  * 0 - are not established;
      87             :  * 1 - the increased accuracy of storage of coordinates (meters, radians or
      88             :  *degrees); 2 - of coordinate are recorded with an accuracy to centimeter
      89             :  *(meters, 2 signs after comma); 3 - coordinates are recorded with an accuracy
      90             :  *to millimeter (meters, 3 sign after comma).
      91             :  *
      92             :  * Note 8. Form of the framework (1 byte):
      93             :  * -1- it is not established;
      94             :  *  0- map is unconfined by the framework;
      95             :  *  1- trapeziform without the salient points;
      96             :  *  2- trapeziform with the salient points;
      97             :  *  3- rectangular;
      98             :  *  4- circular;
      99             :  *  5- arbitrary.
     100             :  *
     101             :  * Note 9. Sign of output to the framework (4 bits):
     102             :  * 0000xxxx - there are no outputs to the framework;
     103             :  * 1000xxxx - northern framework;
     104             :  * 0100xxxx - eastern framework;
     105             :  * 0010xxxx - southern framework;
     106             :  * 0001xxxx - western framework.
     107             :  *
     108             :  * Note 10. Size of the element of certificate (1 bit):
     109             :  * xxxxx0xx - 2 bytes (for the integer value);
     110             :  *            4 bytes (for the floating point);
     111             :  * xxxxx1xx - 4 bytes (for the integer value);
     112             :  *            8 bytes (for the floating point).
     113             :  *
     114             :  * Note 11. Sign of certificate with the text (1 bit):
     115             :  * xxxx0xxx - certificate contains only the coordinates of points;
     116             :  * xxxx1xxx - no-load condition certificate contains the text of signature,
     117             :  *         is allowed only for the objects of the type "signature" or
     118             :  *         "the template of signature".
     119             :  *
     120             :  * Note 12. [Masshtabiruemost] of drawing (sign) (1 bit):
     121             :  * xx0xxxxx - arbitrary symbol of object not scaled;
     122             :  * xx1xxxxx - the arbitrary symbol of object is scaled during the mapping.
     123             :  *
     124             :  * Note 13. Sign of the construction of spline on the certificate (2 bits):
     125             :  * 00xxxxxx - the construction of spline with the visualization is not carried
     126             :  *out; 01xxxxxx - smoothing out spline (cutting angles); 10xxxxxx - enveloping
     127             :  *spline (it penetrates all points of certificate).
     128             :  ****************************************************************************/
     129             : 
     130             : #ifndef SXF_DEFS_H
     131             : #define SXF_DEFS_H
     132             : 
     133             : #define IDSXF 0x00465853 /* SXF  */
     134             : 
     135             : #define IDSXFDATA 0x00544144   /* DAT  */
     136             : #define IDSXFOBJ 0X7FFF7FFF    /* Object */
     137             : #define IDSXFGRAPH 0X7FFF7FFE  /* graphics section */
     138             : #define IDSXFVECT3D 0X7FFF7FFD /* 3D vector section */
     139             : 
     140             : #include <map>
     141             : 
     142             : #include "cpl_port.h"
     143             : 
     144             : enum SXFDataState /* Flag of the state of the data (Note 1) */
     145             : {
     146             :     SXF_DS_UNKNOWN = 0,
     147             :     SXF_DS_EXCHANGE = 8
     148             : };
     149             : 
     150             : enum SXFCodingType /* Flag of the semantics coding type (Note 4) */
     151             : {
     152             :     SXF_SEM_DEC = 0,
     153             :     SXF_SEM_HEX = 1,
     154             :     SXF_SEM_TXT = 2
     155             : };
     156             : 
     157             : enum SXFGeneralizationType /* Flag of the source for generalization data (Note
     158             :                               5) */
     159             : {
     160             :     SXF_GT_SMALL_SCALE = 0,
     161             :     SXF_GT_LARGE_SCALE = 1
     162             : };
     163             : 
     164             : enum SXFTextEncoding /* Flag of text encoding (Note 6) */
     165             : {
     166             :     SXF_ENC_DOS = 0,
     167             :     SXF_ENC_WIN = 1,
     168             :     SXF_ENC_KOI_8 = 2
     169             : 
     170             : #define SXF_ENC_LAST SXF_ENC_KOI_8
     171             : };
     172             : 
     173             : enum SXFCoordinatesAccuracy /* Flag of coordinate storing accuracy (Note 7) */
     174             : {
     175             :     SXF_COORD_ACC_UNDEFINED = 0,
     176             :     SXF_COORD_ACC_HIGH = 1,  // meters, radians or degree
     177             :     SXF_COORD_ACC_CM = 2,    // cantimeters
     178             :     SXF_COORD_ACC_MM = 3,    // millimeters
     179             :     SXF_COORD_ACC_DM = 4     // decimeters
     180             : 
     181             : #define SXF_COORD_ACC_LAST SXF_COORD_ACC_DM
     182             : };
     183             : 
     184             : typedef struct
     185             : {
     186             :     //    SXFDataState   stDataState;         /* Flag of the state of the data
     187             :     //    (Note 1) may be will be needed in future*/
     188             :     bool bProjectionDataCompliance;  /* Flag of the correspondence to the
     189             :                                         projection (Note 2) */
     190             :     bool bRealCoordinatesCompliance; /* Flag of the presence of the real
     191             :                                         coordinates (Note 3) */
     192             :     SXFCodingType stCodingType; /* Flag of the semantics coding type (Note 4) */
     193             :     SXFGeneralizationType
     194             :         stGenType; /* Flag of the source for generalization data (Note 5) */
     195             :     SXFTextEncoding stEnc; /* Flag of text encoding (Note 6) */
     196             :     SXFCoordinatesAccuracy
     197             :         stCoordAcc; /* Flag of coordinate storing accuracy (Note 7) */
     198             :     bool bSort;
     199             : } SXFInformationFlags;
     200             : 
     201             : enum SXFCoordinateMeasUnit
     202             : {
     203             :     SXF_COORD_MU_METRE = 1,
     204             :     SXF_COORD_MU_DECIMETRE,
     205             :     SXF_COORD_MU_CENTIMETRE,
     206             :     SXF_COORD_MU_MILLIMETRE,
     207             :     SXF_COORD_MU_DEGREE,
     208             :     SXF_COORD_MU_RADIAN
     209             : };
     210             : 
     211             : struct SXFMapDescription
     212             : {
     213             :     double stProjCoords[8];  // X(0) & Y(1) South West, X(2) & Y(3) North West,
     214             :                              // X(4) & Y(5) North East, X(6) & Y(7) South East
     215             :     double stGeoCoords[8];
     216             :     double stFrameCoords[8];
     217             :     OGREnvelope Env{};
     218             :     OGRSpatialReference *pSpatRef = nullptr;
     219             :     SXFCoordinateMeasUnit eUnitInPlan = SXF_COORD_MU_METRE;
     220             :     double dfXOr = 0;
     221             :     double dfYOr = 0;
     222             :     double dfFalseNorthing = 0;
     223             :     double dfFalseEasting = 0;
     224             :     GUInt32 nResolution = 0;
     225             :     double dfScale = 0;
     226             :     bool bIsRealCoordinates = false;
     227             :     SXFCoordinatesAccuracy stCoordAcc = SXF_COORD_ACC_UNDEFINED;
     228             : 
     229           6 :     SXFMapDescription()
     230           6 :     {
     231           6 :         memset(stProjCoords, 0, sizeof(stProjCoords));
     232           6 :         memset(stGeoCoords, 0, sizeof(stProjCoords));
     233           6 :         memset(stFrameCoords, 0, sizeof(stFrameCoords));
     234           6 :     }
     235             : };
     236             : 
     237             : enum SXFCoordinateType
     238             : {
     239             :     SXF_CT_RECTANGULAR = 0,
     240             :     SXF_CT_GEODETIC
     241             : };
     242             : 
     243             : /*
     244             :  * List of SXF file format geometry types.
     245             :  */
     246             : enum SXFGeometryType
     247             : {
     248             :     SXF_GT_Unknown = -1,
     249             :     SXF_GT_Line = 0,    /* MultiLineString geometric object                  */
     250             :     SXF_GT_Polygon = 1, /* Polygon geometric object                          */
     251             :     SXF_GT_Point = 2,   /* MultiPoint geometric object                       */
     252             :     SXF_GT_Text = 3,    /* LineString geometric object with associated label */
     253             :     SXF_GT_Vector = 4,  /* Vector geometric object with associated label */
     254             :     SXF_GT_TextTemplate = 5, /* Text template */
     255             :     SXF_GT_VectorAngle = 21, /* Rotated symbol */
     256             :     SXF_GT_VectorScaled = 22 /* Scaled symbol */
     257             : };
     258             : 
     259             : enum SXFValueType
     260             : {
     261             :     SXF_VT_SHORT = 0, /* 2 byte integer */
     262             :     SXF_VT_FLOAT = 1, /* 2 byte float */
     263             :     SXF_VT_INT = 2,   /* 4 byte integer*/
     264             :     SXF_VT_DOUBLE = 3 /* 8 byte float */
     265             : };
     266             : 
     267             : typedef struct
     268             : {
     269             :     SXFGeometryType eGeomType;  // Geometry type (Note 1)
     270             :     SXFValueType eValType;      // size of values (Note 3)
     271             :     int bFormat;  // Has 3D vector (Note 4) /* Format of the certificate (0-
     272             :                   // linear size, 1-vector format ) */
     273             :     GByte bDim;   // Dimensionality of the idea (0- 2D, 1- 3D) (Note 6)
     274             :     bool bHasTextSign;        // Sign of certificate with the text (Note 8)
     275             :     GUInt32 nPointCount;      // Point count
     276             :     GUInt16 nSubObjectCount;  // The sub object count
     277             : 
     278             : } SXFRecordDescription;
     279             : 
     280             : typedef struct
     281             : {
     282             :     GUInt32 nID; /* Identifier of the beginning of record (0x7FFF7FFF) */
     283             :     GUInt32 nFullLength;     /* The overall length of record (with the title) */
     284             :     GUInt32 nGeometryLength; /* Length of certificate (in bytes) */
     285             :     GUInt32 nClassifyCode;   /* Classification code */
     286             :     GUInt16 anGroup[2];      /* 0 - group no, 1 - no in group */
     287             :     GByte nRef[3];           /* Reference data */
     288             :     GByte byPadding;
     289             :     GUInt32 nPointCount;      /* Point count */
     290             :     GUInt16 nSubObjectCount;  /* The sub object count */
     291             :     GUInt16 nPointCountSmall; /* Point count in small geometries */
     292             : } SXFRecordHeader;
     293             : 
     294             : typedef struct
     295             : {
     296             :     GUInt16 nCode;  // type
     297             :     char nType;
     298             :     char nScale;
     299             : } SXFRecordAttributeInfo;
     300             : 
     301             : enum SXFRecordAttributeType
     302             : {
     303             :     SXF_RAT_ASCIIZ_DOS = 0,  // text in DOS encoding
     304             :     SXF_RAT_ONEBYTE = 1,     // number 1 byte
     305             :     SXF_RAT_TWOBYTE = 2,     // number 2 byte
     306             :     SXF_RAT_FOURBYTE = 4,    // number 4 byte
     307             :     SXF_RAT_EIGHTBYTE = 8,   // float point number 8 byte
     308             :     SXF_RAT_ANSI_WIN = 126,  // text in Win encoding
     309             :     SXF_RAT_UNICODE = 127,   // text in unicode
     310             :     SXF_RAT_BIGTEXT = 128    // text more than 255 chars
     311             : };
     312             : 
     313             : /************************************************************************/
     314             : /*                         SXFPassport                                  */
     315             : /************************************************************************/
     316             : 
     317             : struct SXFDate
     318             : {
     319             :     GUInt16 nYear = 0, nMonth = 0, nDay = 0;
     320             : };
     321             : 
     322             : struct SXFPassport
     323             : {
     324             :     GUInt32 version = 0;
     325             :     SXFDate dtCrateDate{};
     326             :     CPLString sMapSheet{};
     327             :     GUInt32 nScale = 0;
     328             :     CPLString sMapSheetName{};
     329             :     SXFInformationFlags informationFlags;
     330             :     SXFMapDescription stMapDescription{};
     331             : };
     332             : 
     333             : typedef struct
     334             : {
     335             :     char szID[4];             // the file ID should be "SXF"
     336             :     GUInt32 nHeaderLength;    // the Header length
     337             :     GByte nFormatVersion[4];  // the format version (e.g. 4)
     338             :     GUInt32 nCheckSum;        // check sum
     339             : } SXFHeader;
     340             : 
     341             : /************************************************************************/
     342             : /*                         RSCInfo                                      */
     343             : /************************************************************************/
     344             : 
     345             : /*
     346             :     RSC File record
     347             : */
     348             : typedef struct
     349             : {
     350             :     GUInt32 nOffset;  // RSC Section offset in bytes from the beginning of the
     351             :                       // RSC file
     352             :     GUInt32 nLength;  // RSC Section record length
     353             :     GUInt32 nRecordCount;  // count of records in the section
     354             : } RSCSection;
     355             : 
     356             : /*
     357             :     RSC File header
     358             : */
     359             : typedef struct
     360             : {
     361             :     char szID[4];
     362             :     GUInt32 nFileLength;
     363             :     GUInt32 nVersion;
     364             :     GUInt32 nEncoding;
     365             :     GUInt32 nFileState;
     366             :     GUInt32 nFileModState;
     367             :     GUInt32 nLang;  // 1 - en, 2 - rus
     368             :     GUInt32 nNextID;
     369             :     GByte date[8];
     370             :     char szMapType[32];
     371             :     char szClassifyName[32];
     372             :     char szClassifyCode[8];
     373             :     GUInt32 nScale;
     374             :     char nScales[4];
     375             :     RSCSection Objects;
     376             :     RSCSection Semantic;
     377             :     RSCSection ClassifySemantic;
     378             :     RSCSection Defaults;
     379             :     RSCSection Semantics;
     380             :     RSCSection Layers;
     381             :     RSCSection Limits;
     382             :     RSCSection Parameters;
     383             :     RSCSection Print;
     384             :     RSCSection Palettes;
     385             :     RSCSection Fonts;
     386             :     RSCSection Libs;
     387             :     RSCSection ImageParams;
     388             :     RSCSection Tables;
     389             :     GByte nFlagKeysAsCodes;
     390             :     GByte nFlagPaletteMods;
     391             :     GByte Reserved[30];
     392             :     GUInt32 nFontEnc;
     393             :     GUInt32 nColorsInPalette;
     394             : } RSCHeader;
     395             : 
     396             : #endif /* SXF_DEFS_H */

Generated by: LCOV version 1.14