1
/******************************************************************************
2
* $Id: ogrdxfwriterlayer.cpp 20670 2010-09-22 00:21:17Z warmerdam $
4
* Project: DXF Translator
5
* Purpose: Implements OGRDXFBlocksWriterLayer used for capturing block
6
* definitions for writing to a DXF file.
7
* Author: Frank Warmerdam, warmerdam@pobox.com
9
******************************************************************************
10
* Copyright (c) 2010, Frank Warmerdam <warmerdam@pobox.com>
12
* Permission is hereby granted, free of charge, to any person obtaining a
13
* copy of this software and associated documentation files (the "Software"),
14
* to deal in the Software without restriction, including without limitation
15
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
* and/or sell copies of the Software, and to permit persons to whom the
17
* Software is furnished to do so, subject to the following conditions:
19
* The above copyright notice and this permission notice shall be included
20
* in all copies or substantial portions of the Software.
22
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28
* DEALINGS IN THE SOFTWARE.
29
****************************************************************************/
33
#include "cpl_string.h"
34
#include "ogr_featurestyle.h"
36
CPL_CVSID("$Id: ogrdxfwriterlayer.cpp 20670 2010-09-22 00:21:17Z warmerdam $");
38
/************************************************************************/
39
/* OGRDXFBlocksWriterLayer() */
40
/************************************************************************/
42
OGRDXFBlocksWriterLayer::OGRDXFBlocksWriterLayer( OGRDXFWriterDS *poDS )
47
poFeatureDefn = new OGRFeatureDefn( "blocks" );
48
poFeatureDefn->Reference();
50
OGRFieldDefn oLayerField( "Layer", OFTString );
51
poFeatureDefn->AddFieldDefn( &oLayerField );
53
OGRFieldDefn oClassField( "SubClasses", OFTString );
54
poFeatureDefn->AddFieldDefn( &oClassField );
56
OGRFieldDefn oExtendedField( "ExtendedEntity", OFTString );
57
poFeatureDefn->AddFieldDefn( &oExtendedField );
59
OGRFieldDefn oLinetypeField( "Linetype", OFTString );
60
poFeatureDefn->AddFieldDefn( &oLinetypeField );
62
OGRFieldDefn oEntityHandleField( "EntityHandle", OFTString );
63
poFeatureDefn->AddFieldDefn( &oEntityHandleField );
65
OGRFieldDefn oTextField( "Text", OFTString );
66
poFeatureDefn->AddFieldDefn( &oTextField );
68
OGRFieldDefn oBlockField( "BlockName", OFTString );
69
poFeatureDefn->AddFieldDefn( &oBlockField );
72
/************************************************************************/
73
/* ~OGRDXFBlocksWriterLayer() */
74
/************************************************************************/
76
OGRDXFBlocksWriterLayer::~OGRDXFBlocksWriterLayer()
79
for( size_t i=0; i < apoBlocks.size(); i++ )
83
poFeatureDefn->Release();
86
/************************************************************************/
87
/* TestCapability() */
88
/************************************************************************/
90
int OGRDXFBlocksWriterLayer::TestCapability( const char * pszCap )
93
if( EQUAL(pszCap,OLCSequentialWrite) )
99
/************************************************************************/
102
/* This is really a dummy as our fields are precreated. */
103
/************************************************************************/
105
OGRErr OGRDXFBlocksWriterLayer::CreateField( OGRFieldDefn *poField,
109
if( poFeatureDefn->GetFieldIndex(poField->GetNameRef()) >= 0
113
CPLError( CE_Failure, CPLE_AppDefined,
114
"DXF layer does not support arbitrary field creation, field '%s' not created.",
115
poField->GetNameRef() );
117
return OGRERR_FAILURE;
120
/************************************************************************/
121
/* CreateFeature() */
123
/* We just stash a copy of the features for later writing to */
124
/* the blocks section of the header. */
125
/************************************************************************/
127
OGRErr OGRDXFBlocksWriterLayer::CreateFeature( OGRFeature *poFeature )
130
apoBlocks.push_back( poFeature->Clone() );
135
/************************************************************************/
137
/************************************************************************/
139
OGRFeature *OGRDXFBlocksWriterLayer::FindBlock( const char *pszBlockName )
142
for( size_t i=0; i < apoBlocks.size(); i++ )
144
const char *pszThisName = apoBlocks[i]->GetFieldAsString("BlockName");
146
if( pszThisName != NULL && strcmp(pszBlockName,pszThisName) == 0 )