LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/dxf - ogrdxfblockslayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 55 42 76.4 %
Date: 2011-12-18 Functions: 9 5 55.6 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrdxflayer.cpp 19643 2010-05-08 21:56:18Z rouault $
       3                 :  *
       4                 :  * Project:  DXF Translator
       5                 :  * Purpose:  Implements OGRDXFBlocksLayer class.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2010, Frank Warmerdam <warmerdam@pobox.com>
      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                 : #include "ogr_dxf.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ogrdxflayer.cpp 19643 2010-05-08 21:56:18Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                         OGRDXFBlocksLayer()                          */
      37                 : /************************************************************************/
      38                 : 
      39               1 : OGRDXFBlocksLayer::OGRDXFBlocksLayer( OGRDXFDataSource *poDS )
      40                 : 
      41                 : {
      42               1 :     this->poDS = poDS;
      43                 : 
      44               1 :     ResetReading();
      45                 : 
      46               1 :     poFeatureDefn = new OGRFeatureDefn( "blocks" );
      47               1 :     poFeatureDefn->Reference();
      48                 : 
      49               1 :     poDS->AddStandardFields( poFeatureDefn );
      50               1 : }
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                         ~OGRDXFBlocksLayer()                         */
      54                 : /************************************************************************/
      55                 : 
      56               1 : OGRDXFBlocksLayer::~OGRDXFBlocksLayer()
      57                 : 
      58                 : {
      59               1 :     if( m_nFeaturesRead > 0 && poFeatureDefn != NULL )
      60                 :     {
      61                 :         CPLDebug( "DXF", "%d features read on layer '%s'.",
      62                 :                   (int) m_nFeaturesRead, 
      63               1 :                   poFeatureDefn->GetName() );
      64                 :     }
      65                 : 
      66               1 :     if( poFeatureDefn )
      67               1 :         poFeatureDefn->Release();
      68               1 : }
      69                 : 
      70                 : /************************************************************************/
      71                 : /*                            ResetReading()                            */
      72                 : /************************************************************************/
      73                 : 
      74               2 : void OGRDXFBlocksLayer::ResetReading()
      75                 : 
      76                 : {
      77               2 :     iNextFID = 0;
      78               2 :     iNextSubFeature = 0;
      79               2 :     oIt = poDS->GetBlockMap().begin();
      80               2 : }
      81                 : 
      82                 : /************************************************************************/
      83                 : /*                      GetNextUnfilteredFeature()                      */
      84                 : /************************************************************************/
      85                 : 
      86               3 : OGRFeature *OGRDXFBlocksLayer::GetNextUnfilteredFeature()
      87                 : 
      88                 : {
      89               3 :     OGRFeature *poFeature = NULL;
      90                 : 
      91                 : /* -------------------------------------------------------------------- */
      92                 : /*      Are we out of features?                                         */
      93                 : /* -------------------------------------------------------------------- */
      94               3 :     if( oIt == poDS->GetBlockMap().end() )
      95               0 :         return NULL;
      96                 : 
      97                 : /* -------------------------------------------------------------------- */
      98                 : /*      Are we done reading the current blocks features?                */
      99                 : /* -------------------------------------------------------------------- */
     100               3 :     DXFBlockDefinition *psBlock = &(oIt->second);
     101               3 :     unsigned int nSubFeatureCount = psBlock->apoFeatures.size();
     102                 : 
     103               3 :     if( psBlock->poGeometry != NULL )
     104               3 :         nSubFeatureCount++;
     105                 : 
     106               3 :     if( iNextSubFeature >= nSubFeatureCount )
     107                 :     {
     108               0 :         oIt++;
     109                 : 
     110               0 :         iNextSubFeature = 0;
     111                 : 
     112               0 :         if( oIt == poDS->GetBlockMap().end() )
     113               0 :             return NULL;
     114                 : 
     115               0 :         psBlock = &(oIt->second);
     116                 :     }
     117                 :         
     118                 : /* -------------------------------------------------------------------- */
     119                 : /*      Is this a geometry based block?                                 */
     120                 : /* -------------------------------------------------------------------- */
     121               3 :     if( psBlock->poGeometry != NULL
     122                 :         && iNextSubFeature == psBlock->apoFeatures.size() )
     123                 :     {
     124               1 :         poFeature = new OGRFeature( poFeatureDefn );
     125               1 :         poFeature->SetGeometry( psBlock->poGeometry );
     126               1 :         iNextSubFeature++;
     127                 :     }
     128                 : 
     129                 : /* -------------------------------------------------------------------- */
     130                 : /*      Otherwise duplicate the next sub-feature.                       */
     131                 : /* -------------------------------------------------------------------- */
     132                 :     else
     133                 :     {
     134               2 :         poFeature = new OGRFeature( poFeatureDefn );
     135               2 :         poFeature->SetFrom( psBlock->apoFeatures[iNextSubFeature] );
     136               2 :         iNextSubFeature++;
     137                 :     }
     138                 : 
     139                 : /* -------------------------------------------------------------------- */
     140                 : /*      Set FID and block name.                                         */
     141                 : /* -------------------------------------------------------------------- */
     142               3 :     poFeature->SetFID( iNextFID++ );
     143                 : 
     144               3 :     poFeature->SetField( "BlockName", oIt->first.c_str() );
     145                 : 
     146               3 :     m_nFeaturesRead++;
     147                 : 
     148               3 :     return poFeature;
     149                 : }
     150                 : 
     151                 : /************************************************************************/
     152                 : /*                           GetNextFeature()                           */
     153                 : /************************************************************************/
     154                 : 
     155               3 : OGRFeature *OGRDXFBlocksLayer::GetNextFeature()
     156                 : 
     157                 : {
     158               0 :     while( TRUE )
     159                 :     {
     160               3 :         OGRFeature *poFeature = GetNextUnfilteredFeature();
     161                 : 
     162               3 :         if( poFeature == NULL )
     163               0 :             return NULL;
     164                 : 
     165               3 :         if( (m_poFilterGeom == NULL
     166                 :              || FilterGeometry( poFeature->GetGeometryRef() ) )
     167                 :             && (m_poAttrQuery == NULL
     168                 :                 || m_poAttrQuery->Evaluate( poFeature ) ) )
     169                 :         {
     170               3 :             return poFeature;
     171                 :         }
     172                 : 
     173               0 :         delete poFeature;
     174                 :     }
     175                 : }
     176                 : 
     177                 : /************************************************************************/
     178                 : /*                           TestCapability()                           */
     179                 : /************************************************************************/
     180                 : 
     181               0 : int OGRDXFBlocksLayer::TestCapability( const char * pszCap )
     182                 : 
     183                 : {
     184               0 :     if( EQUAL(pszCap,OLCStringsAsUTF8) )
     185               0 :         return TRUE;
     186                 :     else
     187               0 :         return FALSE;
     188                 : }
     189                 : 

Generated by: LCOV version 1.7