LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/dxf - ogrdxfblockswriterlayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 22 27 81.5 %
Date: 2024-11-21 22:18:42 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  DXF Translator
       4             :  * Purpose:  Implements OGRDXFBlocksWriterLayer used for capturing block
       5             :  *           definitions for writing to a DXF file.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2010, Frank Warmerdam <warmerdam@pobox.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "ogr_dxf.h"
      15             : #include "cpl_conv.h"
      16             : #include "cpl_string.h"
      17             : #include "ogr_featurestyle.h"
      18             : 
      19             : /************************************************************************/
      20             : /*                      OGRDXFBlocksWriterLayer()                       */
      21             : /************************************************************************/
      22             : 
      23           2 : OGRDXFBlocksWriterLayer::OGRDXFBlocksWriterLayer(OGRDXFWriterDS * /* poDS */)
      24           2 :     : poFeatureDefn(new OGRFeatureDefn("blocks"))
      25             : {
      26           2 :     poFeatureDefn->Reference();
      27             : 
      28           2 :     OGRDXFDataSource::AddStandardFields(poFeatureDefn, ODFM_IncludeBlockFields);
      29           2 : }
      30             : 
      31             : /************************************************************************/
      32             : /*                      ~OGRDXFBlocksWriterLayer()                      */
      33             : /************************************************************************/
      34             : 
      35           4 : OGRDXFBlocksWriterLayer::~OGRDXFBlocksWriterLayer()
      36             : 
      37             : {
      38           6 :     for (size_t i = 0; i < apoBlocks.size(); i++)
      39           4 :         delete apoBlocks[i];
      40             : 
      41           2 :     if (poFeatureDefn)
      42           2 :         poFeatureDefn->Release();
      43           4 : }
      44             : 
      45             : /************************************************************************/
      46             : /*                           TestCapability()                           */
      47             : /************************************************************************/
      48             : 
      49           4 : int OGRDXFBlocksWriterLayer::TestCapability(const char *pszCap)
      50             : 
      51             : {
      52           4 :     return EQUAL(pszCap, OLCSequentialWrite);
      53             : }
      54             : 
      55             : /************************************************************************/
      56             : /*                            CreateField()                             */
      57             : /*                                                                      */
      58             : /*      This is really a dummy as our fields are precreated.            */
      59             : /************************************************************************/
      60             : 
      61           0 : OGRErr OGRDXFBlocksWriterLayer::CreateField(const OGRFieldDefn *poField,
      62             :                                             int bApproxOK)
      63             : 
      64             : {
      65           0 :     if (poFeatureDefn->GetFieldIndex(poField->GetNameRef()) >= 0 && bApproxOK)
      66           0 :         return OGRERR_NONE;
      67             : 
      68           0 :     CPLError(CE_Failure, CPLE_AppDefined,
      69             :              "DXF layer does not support arbitrary field creation, field '%s' "
      70             :              "not created.",
      71             :              poField->GetNameRef());
      72             : 
      73           0 :     return OGRERR_FAILURE;
      74             : }
      75             : 
      76             : /************************************************************************/
      77             : /*                           ICreateFeature()                            */
      78             : /*                                                                      */
      79             : /*      We just stash a copy of the features for later writing to       */
      80             : /*      the blocks section of the header.                               */
      81             : /************************************************************************/
      82             : 
      83           4 : OGRErr OGRDXFBlocksWriterLayer::ICreateFeature(OGRFeature *poFeature)
      84             : 
      85             : {
      86           4 :     apoBlocks.push_back(poFeature->Clone());
      87             : 
      88           4 :     return OGRERR_NONE;
      89             : }
      90             : 
      91             : /************************************************************************/
      92             : /*                             FindBlock()                              */
      93             : /************************************************************************/
      94             : 
      95           7 : OGRFeature *OGRDXFBlocksWriterLayer::FindBlock(const char *pszBlockName)
      96             : 
      97             : {
      98          16 :     for (size_t i = 0; i < apoBlocks.size(); i++)
      99             :     {
     100          14 :         const char *pszThisName = apoBlocks[i]->GetFieldAsString("Block");
     101             : 
     102          14 :         if (pszThisName != nullptr && strcmp(pszBlockName, pszThisName) == 0)
     103           5 :             return apoBlocks[i];
     104             :     }
     105             : 
     106           2 :     return nullptr;
     107             : }

Generated by: LCOV version 1.14