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

Generated by: LCOV version 1.14