Line data Source code
1 : /******************************************************************************* 2 : * Project: OGR CAD Driver 3 : * Purpose: Implements driver based on libopencad 4 : * Author: Alexandr Borzykh, mush3d at gmail.com 5 : * Author: Dmitry Baryshnikov, polimax@mail.ru 6 : * Language: C++ 7 : ******************************************************************************* 8 : * The MIT License (MIT) 9 : * 10 : * Copyright (c) 2016 Alexandr Borzykh 11 : * Copyright (c) 2016, NextGIS 12 : * 13 : * SPDX-License-Identifier: MIT 14 : *******************************************************************************/ 15 : 16 : #include "ogrsf_frmts.h" 17 : 18 : #include "ogrcaddrivercore.h" 19 : 20 : /************************************************************************/ 21 : /* OGRCADDriverIdentify() */ 22 : /************************************************************************/ 23 : 24 52566 : static int OGRCADDriverIdentify(GDALOpenInfo *poOpenInfo) 25 : 26 : { 27 : #if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) 28 52566 : if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "DWG")) 29 52563 : return FALSE; 30 : #endif 31 27 : return poOpenInfo->nHeaderBytes >= 6 && poOpenInfo->pabyHeader[0] == 'A' && 32 27 : poOpenInfo->pabyHeader[1] == 'C'; 33 : } 34 : 35 : /************************************************************************/ 36 : /* OGRCADDriverSetCommonMetadata() */ 37 : /************************************************************************/ 38 : 39 1301 : void OGRCADDriverSetCommonMetadata(GDALDriver *poDriver) 40 : { 41 1301 : poDriver->SetDescription(DRIVER_NAME); 42 1301 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 43 1301 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 44 1301 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 45 1301 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 46 1301 : poDriver->SetMetadataItem(GDAL_DMD_SUBDATASETS, "YES"); 47 1301 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "AutoCAD Driver"); 48 1301 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "dwg"); 49 1301 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/cad.html"); 50 1301 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 51 1301 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 52 1301 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 53 1301 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 54 1301 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 55 : 56 1301 : poDriver->SetMetadataItem( 57 : GDAL_DMD_OPENOPTIONLIST, 58 : "<OpenOptionList>" 59 : " <Option name='MODE' type='string' description='Open mode. " 60 : "READ_ALL - read all data (slow), READ_FAST - read main data " 61 : "(fast), READ_FASTEST - read less data' default='READ_FAST'/>" 62 : " <Option name='ADD_UNSUPPORTED_GEOMETRIES_DATA' type='string' " 63 : "description='Add unsupported geometries data (color, attributes) " 64 : "to the layer (YES/NO). They will have no geometrical " 65 : "representation.' default='NO'/>" 66 1301 : "</OpenOptionList>"); 67 : 68 1301 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 69 1301 : poDriver->SetMetadataItem(GDAL_DCAP_FEATURE_STYLES, "YES"); 70 1301 : poDriver->SetMetadataItem(GDAL_DCAP_FEATURE_STYLES_READ, "YES"); 71 : 72 1301 : poDriver->pfnIdentify = OGRCADDriverIdentify; 73 1301 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 74 1301 : } 75 : 76 : /************************************************************************/ 77 : /* DeclareDeferredOGRCADPlugin() */ 78 : /************************************************************************/ 79 : 80 : #ifdef PLUGIN_FILENAME 81 1595 : void DeclareDeferredOGRCADPlugin() 82 : { 83 1595 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 84 : { 85 302 : return; 86 : } 87 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 88 : #ifdef PLUGIN_INSTALLATION_MESSAGE 89 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 90 : PLUGIN_INSTALLATION_MESSAGE); 91 : #endif 92 1293 : OGRCADDriverSetCommonMetadata(poDriver); 93 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 94 : } 95 : #endif