~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/dxf/ogrdxfblockswriterlayer.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * $Id: ogrdxfwriterlayer.cpp 20670 2010-09-22 00:21:17Z warmerdam $
 
3
 *
 
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
 
8
 *
 
9
 ******************************************************************************
 
10
 * Copyright (c) 2010, Frank Warmerdam <warmerdam@pobox.com>
 
11
 *
 
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:
 
18
 *
 
19
 * The above copyright notice and this permission notice shall be included
 
20
 * in all copies or substantial portions of the Software.
 
21
 *
 
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
 ****************************************************************************/
 
30
 
 
31
#include "ogr_dxf.h"
 
32
#include "cpl_conv.h"
 
33
#include "cpl_string.h"
 
34
#include "ogr_featurestyle.h"
 
35
 
 
36
CPL_CVSID("$Id: ogrdxfwriterlayer.cpp 20670 2010-09-22 00:21:17Z warmerdam $");
 
37
 
 
38
/************************************************************************/
 
39
/*                      OGRDXFBlocksWriterLayer()                       */
 
40
/************************************************************************/
 
41
 
 
42
OGRDXFBlocksWriterLayer::OGRDXFBlocksWriterLayer( OGRDXFWriterDS *poDS )
 
43
 
 
44
{
 
45
    (void) poDS;
 
46
 
 
47
    poFeatureDefn = new OGRFeatureDefn( "blocks" );
 
48
    poFeatureDefn->Reference();
 
49
 
 
50
    OGRFieldDefn  oLayerField( "Layer", OFTString );
 
51
    poFeatureDefn->AddFieldDefn( &oLayerField );
 
52
 
 
53
    OGRFieldDefn  oClassField( "SubClasses", OFTString );
 
54
    poFeatureDefn->AddFieldDefn( &oClassField );
 
55
 
 
56
    OGRFieldDefn  oExtendedField( "ExtendedEntity", OFTString );
 
57
    poFeatureDefn->AddFieldDefn( &oExtendedField );
 
58
 
 
59
    OGRFieldDefn  oLinetypeField( "Linetype", OFTString );
 
60
    poFeatureDefn->AddFieldDefn( &oLinetypeField );
 
61
 
 
62
    OGRFieldDefn  oEntityHandleField( "EntityHandle", OFTString );
 
63
    poFeatureDefn->AddFieldDefn( &oEntityHandleField );
 
64
 
 
65
    OGRFieldDefn  oTextField( "Text", OFTString );
 
66
    poFeatureDefn->AddFieldDefn( &oTextField );
 
67
 
 
68
    OGRFieldDefn  oBlockField( "BlockName", OFTString );
 
69
    poFeatureDefn->AddFieldDefn( &oBlockField );
 
70
}
 
71
 
 
72
/************************************************************************/
 
73
/*                      ~OGRDXFBlocksWriterLayer()                      */
 
74
/************************************************************************/
 
75
 
 
76
OGRDXFBlocksWriterLayer::~OGRDXFBlocksWriterLayer()
 
77
 
 
78
{
 
79
    for( size_t i=0; i < apoBlocks.size(); i++ )
 
80
        delete apoBlocks[i];
 
81
 
 
82
    if( poFeatureDefn )
 
83
        poFeatureDefn->Release();
 
84
}
 
85
 
 
86
/************************************************************************/
 
87
/*                           TestCapability()                           */
 
88
/************************************************************************/
 
89
 
 
90
int OGRDXFBlocksWriterLayer::TestCapability( const char * pszCap )
 
91
 
 
92
{
 
93
    if( EQUAL(pszCap,OLCSequentialWrite) )
 
94
        return TRUE;
 
95
    else 
 
96
        return FALSE;
 
97
}
 
98
 
 
99
/************************************************************************/
 
100
/*                            CreateField()                             */
 
101
/*                                                                      */
 
102
/*      This is really a dummy as our fields are precreated.            */
 
103
/************************************************************************/
 
104
 
 
105
OGRErr OGRDXFBlocksWriterLayer::CreateField( OGRFieldDefn *poField,
 
106
                                             int bApproxOK )
 
107
 
 
108
{
 
109
    if( poFeatureDefn->GetFieldIndex(poField->GetNameRef()) >= 0
 
110
        && bApproxOK )
 
111
        return OGRERR_NONE;
 
112
 
 
113
    CPLError( CE_Failure, CPLE_AppDefined,
 
114
              "DXF layer does not support arbitrary field creation, field '%s' not created.",
 
115
              poField->GetNameRef() );
 
116
 
 
117
    return OGRERR_FAILURE;
 
118
}
 
119
 
 
120
/************************************************************************/
 
121
/*                           CreateFeature()                            */
 
122
/*                                                                      */
 
123
/*      We just stash a copy of the features for later writing to       */
 
124
/*      the blocks section of the header.                               */
 
125
/************************************************************************/
 
126
 
 
127
OGRErr OGRDXFBlocksWriterLayer::CreateFeature( OGRFeature *poFeature )
 
128
 
 
129
{
 
130
    apoBlocks.push_back( poFeature->Clone() );
 
131
 
 
132
    return OGRERR_NONE;
 
133
}
 
134
 
 
135
/************************************************************************/
 
136
/*                             FindBlock()                              */
 
137
/************************************************************************/
 
138
 
 
139
OGRFeature *OGRDXFBlocksWriterLayer::FindBlock( const char *pszBlockName )
 
140
 
 
141
{
 
142
    for( size_t i=0; i < apoBlocks.size(); i++ )
 
143
    {
 
144
        const char *pszThisName = apoBlocks[i]->GetFieldAsString("BlockName");
 
145
 
 
146
        if( pszThisName != NULL && strcmp(pszBlockName,pszThisName) == 0 )
 
147
            return apoBlocks[i];
 
148
    }
 
149
    
 
150
    return NULL;
 
151
}