LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/dxf - ogr_dxf.h
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 12
Code covered: 83.3 % Executed lines: 10

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_dxf.h 18752 2010-02-07 22:02:14Z warmerdam $
       3                 :  *
       4                 :  * Project:  DXF Translator
       5                 :  * Purpose:  Definition of classes for OGR .dxf driver.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2009,  Frank Warmerdam
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifndef _OGR_DXF_H_INCLUDED
      31                 : #define _OGR_DXF_H_INCLUDED
      32                 : 
      33                 : #include "ogrsf_frmts.h"
      34                 : #include "cpl_conv.h"
      35                 : #include <vector>
      36                 : #include <map>
      37                 : #include <stack>
      38                 : 
      39                 : class OGRDXFDataSource;
      40                 : 
      41                 : /************************************************************************/
      42                 : /*                          DXFBlockDefinition                          */
      43                 : /*                                                                      */
      44                 : /*      Container for info about a block.                               */
      45                 : /************************************************************************/
      46                 : 
      47                 : class DXFBlockDefinition
      48               2 : {
      49                 : public:
      50               1 :     DXFBlockDefinition() : poGeometry(NULL) {}
      51                 :     ~DXFBlockDefinition();
      52                 : 
      53                 :     OGRGeometry                *poGeometry;
      54                 :     std::vector<OGRFeature *>  apoFeatures;
      55                 : };
      56                 : 
      57                 : /************************************************************************/
      58                 : /*                             OGRDXFLayer                              */
      59                 : /************************************************************************/
      60                 : class OGRDXFDataSource;
      61                 : 
      62                 : class OGRDXFLayer : public OGRLayer
      63                 : {
      64                 :     OGRDXFDataSource   *poDS;
      65                 : 
      66                 :     OGRFeatureDefn     *poFeatureDefn;
      67                 :     int                 iNextFID;
      68                 : 
      69                 :     std::stack<OGRFeature*> apoPendingFeatures;
      70                 :     void                ClearPendingFeatures();
      71                 : 
      72                 :     std::map<CPLString,CPLString> oStyleProperties;
      73                 :     
      74                 :     void                TranslateGenericProperty( OGRFeature *poFeature, 
      75                 :                                                   int nCode, char *pszValue );
      76                 :     void                PrepareLineStyle( OGRFeature *poFeature );
      77                 :     void                ApplyOCSTransformer( OGRGeometry * );
      78                 : 
      79                 :     OGRFeature *        TranslatePOINT();
      80                 :     OGRFeature *        TranslateLINE();
      81                 :     OGRFeature *        TranslatePOLYLINE();
      82                 :     OGRFeature *        TranslateLWPOLYLINE();
      83                 :     OGRFeature *        TranslateCIRCLE();
      84                 :     OGRFeature *        TranslateELLIPSE();
      85                 :     OGRFeature *        TranslateARC();
      86                 :     OGRFeature *        TranslateSPLINE();
      87                 :     OGRFeature *        TranslateINSERT();
      88                 :     OGRFeature *        TranslateMTEXT();
      89                 :     OGRFeature *        TranslateTEXT();
      90                 :     OGRFeature *        TranslateDIMENSION();
      91                 : 
      92                 :     void                FormatDimension( CPLString &osText, double dfValue );
      93                 : 
      94                 :   public:
      95                 :     OGRDXFLayer( OGRDXFDataSource *poDS );
      96                 :     ~OGRDXFLayer();
      97                 : 
      98                 :     void                ResetReading();
      99                 :     OGRFeature *        GetNextFeature();
     100                 : 
     101               2 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
     102                 : 
     103                 :     int                 TestCapability( const char * );
     104                 : 
     105                 :     OGRFeature *        GetNextUnfilteredFeature();
     106                 : };
     107                 : 
     108                 : /************************************************************************/
     109                 : /*                           OGRDXFDataSource                           */
     110                 : /************************************************************************/
     111                 : 
     112                 : class OGRDXFDataSource : public OGRDataSource
     113                 : {
     114                 :     CPLString           osName;
     115                 :     std::vector<OGRDXFLayer*> apoLayers;
     116                 : 
     117                 :     FILE                *fp;
     118                 : 
     119                 :     int                 iEntitiesSectionOffset;
     120                 : 
     121                 :     int                 iSrcBufferOffset;
     122                 :     int                 nSrcBufferBytes;
     123                 :     int                 iSrcBufferFileOffset;
     124                 :     char                achSrcBuffer[1025];
     125                 :     
     126                 :     int                 nLastValueSize;
     127                 : 
     128                 :     std::map<CPLString,DXFBlockDefinition> oBlockMap;
     129                 :     std::map<CPLString,CPLString> oHeaderVariables;
     130                 : 
     131                 :     // indexed by layer name, then by property name.
     132                 :     std::map< CPLString, std::map<CPLString,CPLString> > 
     133                 :                         oLayerTable;
     134                 : 
     135                 :   public:
     136                 :                         OGRDXFDataSource();
     137                 :                         ~OGRDXFDataSource();
     138                 : 
     139                 :     int                 Open( const char * pszFilename );
     140                 :     
     141               6 :     const char          *GetName() { return osName; }
     142                 : 
     143               1 :     int                 GetLayerCount() { return apoLayers.size(); }
     144                 :     OGRLayer            *GetLayer( int );
     145                 : 
     146                 :     int                 TestCapability( const char * );
     147                 : 
     148                 :     // The following is only used by OGRDXFLayer
     149                 : 
     150                 :     // Implemented in ogrdxf_diskio.cpp 
     151                 :     int                 ReadValue( char *pszValueBuffer, 
     152                 :                                    int nValueBufferSize = 81 );
     153                 :     void                UnreadValue();
     154                 :     void                LoadDiskChunk();
     155                 :     void                ResetReadPointer( int iNewOffset );
     156               9 :     void                RestartEntities() 
     157               9 :                         { ResetReadPointer(iEntitiesSectionOffset); }
     158                 : 
     159                 :     // Implemented in ogrdxf_blockmap.cpp
     160                 :     void                ReadBlocksSection();
     161                 :     OGRGeometry        *SimplifyBlockGeometry( OGRGeometryCollection * );
     162                 :     DXFBlockDefinition *LookupBlock( const char *pszName );
     163                 : 
     164                 :     // Layer Table Handling (ogrdxf_tables.cpp)
     165                 :     void                ReadTablesSection();
     166                 :     void                ReadLayerDefinition();
     167                 :     const char         *LookupLayerProperty( const char *pszLayer, 
     168                 :                                              const char *pszProperty );
     169                 : 
     170                 :     // Header variables. 
     171                 :     void                ReadHeaderSection();
     172                 :     const char         *GetVariable(const char *pszName, 
     173                 :                                     const char *pszDefault=NULL );
     174                 : };
     175                 : 
     176                 : /************************************************************************/
     177                 : /*                          OGRDXFWriterLayer                           */
     178                 : /************************************************************************/
     179                 : 
     180                 : class OGRDXFWriterDS;
     181                 : 
     182                 : class OGRDXFWriterLayer : public OGRLayer
     183                 : {
     184                 :     FILE               *fp;
     185                 :     OGRFeatureDefn     *poFeatureDefn;
     186                 :     int                 nNextFID;
     187                 : 
     188                 :     int                 WriteValue( int nCode, const char *pszValue );
     189                 :     int                 WriteValue( int nCode, int nValue );
     190                 :     int                 WriteValue( int nCode, double dfValue );
     191                 : 
     192                 :     OGRErr              WriteCore( OGRFeature* );
     193                 :     OGRErr              WritePOINT( OGRFeature* );
     194                 :     OGRErr              WriteTEXT( OGRFeature* );
     195                 :     OGRErr              WritePOLYLINE( OGRFeature*, OGRGeometry* = NULL );
     196                 : 
     197                 :     int                 ColorStringToDXFColor( const char * );
     198                 : 
     199                 :   public:
     200                 :     OGRDXFWriterLayer( FILE *fp );
     201                 :     ~OGRDXFWriterLayer();
     202                 : 
     203               0 :     void                ResetReading() {}
     204               0 :     OGRFeature         *GetNextFeature() { return NULL; }
     205                 : 
     206               2 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
     207                 : 
     208                 :     int                 TestCapability( const char * );
     209                 :     OGRErr              CreateFeature( OGRFeature *poFeature );
     210                 :     OGRErr              CreateField( OGRFieldDefn *poField,
     211                 :                                      int bApproxOK = TRUE );
     212                 : };
     213                 : 
     214                 : /************************************************************************/
     215                 : /*                           OGRDXFWriterDS                             */
     216                 : /************************************************************************/
     217                 : 
     218                 : class OGRDXFWriterDS : public OGRDataSource
     219                 : {
     220                 :     CPLString           osName;
     221                 :     OGRDXFWriterLayer  *poLayer;
     222                 :     FILE               *fp;
     223                 :     CPLString           osTrailerFile;
     224                 : 
     225                 :   public:
     226                 :                         OGRDXFWriterDS();
     227                 :                         ~OGRDXFWriterDS();
     228                 : 
     229                 :     int                 Open( const char * pszFilename, 
     230                 :                               char **papszOptions );
     231                 :     
     232               1 :     const char          *GetName() { return osName; }
     233                 : 
     234                 :     int                 GetLayerCount();
     235                 :     OGRLayer            *GetLayer( int );
     236                 : 
     237                 :     int                 TestCapability( const char * );
     238                 : 
     239                 :     OGRLayer           *CreateLayer( const char *pszName, 
     240                 :                                      OGRSpatialReference *poSpatialRef = NULL,
     241                 :                                      OGRwkbGeometryType eGType = wkbUnknown,
     242                 :                                      char ** papszOptions = NULL );
     243                 : 
     244                 : };
     245                 : 
     246                 : /************************************************************************/
     247                 : /*                             OGRDXFDriver                             */
     248                 : /************************************************************************/
     249                 : 
     250                 : class OGRDXFDriver : public OGRSFDriver
     251              80 : {
     252                 :   public:
     253                 :                 ~OGRDXFDriver();
     254                 : 
     255                 :     static const unsigned char *GetDXFColorTable();
     256                 : 
     257                 :     const char *GetName();
     258                 :     OGRDataSource *Open( const char *, int );
     259                 :     int         TestCapability( const char * );
     260                 : 
     261                 :     OGRDataSource      *CreateDataSource( const char *pszName,
     262                 :                                           char ** = NULL );
     263                 : };
     264                 : 
     265                 : #endif /* ndef _OGR_DXF_H_INCLUDED */

Generated by: LTP GCOV extension version 1.5