1 /******************************************************************************
2 *
3 * Project: DWG Translator
4 * Purpose: Implements OGRDWGDriver.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2011, Frank Warmerdam <warmerdam@pobox.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
29 #include "ogr_dwg.h"
30 #include "cpl_conv.h"
31 #include "ogrteigha.h"
32
33 CPL_CVSID("$Id: ogrdwgdriver.cpp 1761acd90777d5bcc49eddbc13c193098f0ed40b 2020-10-01 12:12:00 +0200 Even Rouault $")
34
35 /************************************************************************/
36 /* OGRDWGDriver() */
37 /************************************************************************/
38
OGRDWGDriver()39 OGRDWGDriver::OGRDWGDriver() : poServices(nullptr)
40
41 {
42 }
43
44 /************************************************************************/
45 /* ~OGRDWGDriver() */
46 /************************************************************************/
47
~OGRDWGDriver()48 OGRDWGDriver::~OGRDWGDriver()
49
50 {
51 OGRTEIGHADeinitialize();
52 }
53
54 /************************************************************************/
55 /* GetName() */
56 /************************************************************************/
57
GetName()58 const char *OGRDWGDriver::GetName()
59
60 {
61 return "DWG";
62 }
63
64 /************************************************************************/
65 /* Open() */
66 /************************************************************************/
67
Open(const char * pszFilename,int)68 OGRDataSource *OGRDWGDriver::Open( const char * pszFilename, int /*bUpdate*/ )
69
70 {
71 if( !EQUAL(CPLGetExtension(pszFilename),"dwg") )
72 return nullptr;
73
74 // Check that this is a real file since the driver doesn't support
75 // VSI*L API
76 VSIStatBuf sStat;
77 if( VSIStat(pszFilename, &sStat) != 0 )
78 return nullptr;
79
80 if( !OGRTEIGHAInitialize() )
81 return nullptr;
82
83 OGRDWGDataSource *poDS = new OGRDWGDataSource();
84
85 if( !poDS->Open( OGRDWGGetServices(), pszFilename ) )
86 {
87 delete poDS;
88 poDS = nullptr;
89 }
90
91 return poDS;
92 }
93
94 /************************************************************************/
95 /* TestCapability() */
96 /************************************************************************/
97
TestCapability(const char *)98 int OGRDWGDriver::TestCapability( const char * /*pszCap*/ )
99
100 {
101 return FALSE;
102 }
103
104 /************************************************************************/
105 /* RegisterOGRDWG() */
106 /************************************************************************/
107
RegisterOGRDWG()108 void RegisterOGRDWG()
109
110 {
111 OGRSFDriver* poDriver = new OGRDWGDriver;
112 poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
113 "AutoCAD DWG" );
114 poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "dwg" );
115 poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/dwg.html" );
116 poDriver->SetMetadataItem( GDAL_DCAP_FEATURE_STYLES, "YES" );
117
118 OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( poDriver );
119 }
120