| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: OpenGIS Simple Features Reference Implementation |
| 4 |
* Purpose: OGR Driver for DGNv8 |
| 5 |
* Author: Even Rouault <even.rouault at spatialys.com> |
| 6 |
* |
| 7 |
****************************************************************************** |
| 8 |
* Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com> |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: MIT |
| 11 |
****************************************************************************/ |
| 12 |
|
| 13 |
#include "gdal_frmts.h" |
| 14 |
#include "gdalplugindriverproxy.h" |
| 15 |
|
| 16 |
#include "ogrsf_frmts.h" |
| 17 |
|
| 18 |
#include "ogrdgnv8drivercore.h" |
| 19 |
|
| 20 |
/************************************************************************/ |
| 21 |
/* OGRDGNV8DriverIdentify() */ |
| 22 |
/************************************************************************/ |
| 23 |
|
| 24 |
int OGRDGNV8DriverIdentify(GDALOpenInfo *poOpenInfo) |
| 25 |
|
| 26 |
{ |
| 27 |
VSIStatBuf sStat; |
| 28 |
if (poOpenInfo->fpL != nullptr && poOpenInfo->nHeaderBytes >= 512) |
| 29 |
{ |
| 30 |
// Is it a DGN v7 cell library? |
| 31 |
if (poOpenInfo->pabyHeader[0] == 0x08 && |
| 32 |
poOpenInfo->pabyHeader[1] == 0x05 && |
| 33 |
poOpenInfo->pabyHeader[2] == 0x17 && |
| 34 |
poOpenInfo->pabyHeader[3] == 0x00) |
| 35 |
{ |
| 36 |
return GDALGetDriverByName("DGN") == nullptr && |
| 37 |
VSIStat(poOpenInfo->pszFilename, &sStat) == 0; |
| 38 |
} |
| 39 |
|
| 40 |
// Is it a DGN v7 regular 2D or 3D file? |
| 41 |
if ((poOpenInfo->pabyHeader[0] == 0x08 || |
| 42 |
poOpenInfo->pabyHeader[0] == 0xC8) && |
| 43 |
poOpenInfo->pabyHeader[1] == 0x09 && |
| 44 |
poOpenInfo->pabyHeader[2] == 0xFE && |
| 45 |
poOpenInfo->pabyHeader[3] == 0x02) |
| 46 |
{ |
| 47 |
return GDALGetDriverByName("DGN") == nullptr && |
| 48 |
VSIStat(poOpenInfo->pszFilename, &sStat) == 0; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return poOpenInfo->fpL != nullptr && poOpenInfo->nHeaderBytes >= 512 && |
| 53 |
poOpenInfo->IsExtensionEqualToCI("DGN") && |
| 54 |
memcmp(poOpenInfo->pabyHeader, "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1", |
| 55 |
8) == 0 && |
| 56 |
VSIStat(poOpenInfo->pszFilename, &sStat) == 0; |
| 57 |
} |
| 58 |
|
| 59 |
/************************************************************************/ |
| 60 |
/* OGRDGNV8DriverSetCommonMetadata() */ |
| 61 |
/************************************************************************/ |
| 62 |
|
| 63 |
void OGRDGNV8DriverSetCommonMetadata(GDALDriver *poDriver) |
| 64 |
{ |
| 65 |
poDriver->SetDescription(DRIVER_NAME); |
| 66 |
poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); |
| 67 |
poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Microstation DGNv8"); |
| 68 |
poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "dgn"); |
| 69 |
poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/dgnv8.html"); |
| 70 |
poDriver->SetMetadataItem(GDAL_DCAP_FEATURE_STYLES, "YES"); |
| 71 |
poDriver->SetMetadataItem(GDAL_DCAP_FEATURE_STYLES_READ, "YES"); |
| 72 |
poDriver->SetMetadataItem(GDAL_DCAP_FEATURE_STYLES_WRITE, "YES"); |
| 73 |
poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); |
| 74 |
poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); |
| 75 |
poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); |
| 76 |
|
| 77 |
poDriver->SetMetadataItem( |
| 78 |
GDAL_DMD_CREATIONOPTIONLIST, |
| 79 |
"<CreationOptionList>" |
| 80 |
" <Option name='SEED' type='string' " |
| 81 |
"description='Filename of seed file to use'/>" |
| 82 |
" <Option name='COPY_SEED_FILE_COLOR_TABLE' type='boolean' " |
| 83 |
"description='whether the color table should be copied from the " |
| 84 |
"seed file.' default='NO'/>" |
| 85 |
" <Option name='COPY_SEED_FILE_MODEL' type='boolean' " |
| 86 |
"description='whether the existing models (without their graphic " |
| 87 |
"contents) should be copied from the seed file.' default='YES'/>" |
| 88 |
" <Option name='COPY_SEED_FILE_MODEL_CONTROL_ELEMENTS' type='boolean' " |
| 89 |
"description='whether the existing control elements of models should " |
| 90 |
"be " |
| 91 |
"copied from the seed file.' default='YES'/>" |
| 92 |
" <Option name='APPLICATION' type='string' " |
| 93 |
"description='Set Application field in header'/>" |
| 94 |
" <Option name='TITLE' type='string' " |
| 95 |
"description='Set Title field in header'/>" |
| 96 |
" <Option name='SUBJECT' type='string' " |
| 97 |
"description='Set Subject field in header'/>" |
| 98 |
" <Option name='AUTHOR' type='string' " |
| 99 |
"description='Set Author field in header'/>" |
| 100 |
" <Option name='KEYWORDS' type='string' " |
| 101 |
"description='Set Keywords field in header'/>" |
| 102 |
" <Option name='TEMPLATE' type='string' " |
| 103 |
"description='Set Template field in header'/>" |
| 104 |
" <Option name='COMMENTS' type='string' " |
| 105 |
"description='Set Comments field in header'/>" |
| 106 |
" <Option name='LAST_SAVED_BY' type='string' " |
| 107 |
"description='Set LastSavedBy field in header'/>" |
| 108 |
" <Option name='REVISION_NUMBER' type='string' " |
| 109 |
"description='Set RevisionNumber field in header'/>" |
| 110 |
" <Option name='CATEGORY' type='string' " |
| 111 |
"description='Set Category field in header'/>" |
| 112 |
" <Option name='MANAGER' type='string' " |
| 113 |
"description='Set Manager field in header'/>" |
| 114 |
" <Option name='COMPANY' type='string' " |
| 115 |
"description='Set Company field in header'/>" |
| 116 |
"</CreationOptionList>"); |
| 117 |
|
| 118 |
poDriver->SetMetadataItem( |
| 119 |
GDAL_DS_LAYER_CREATIONOPTIONLIST, |
| 120 |
"<LayerCreationOptionList>" |
| 121 |
" <Option name='DESCRIPTION' type='string' " |
| 122 |
"description='Description of the layer/model'/>" |
| 123 |
" <Option name='DIM' type='int' " |
| 124 |
"description='Dimension (2 or 3) of the layer/model'/>" |
| 125 |
"</LayerCreationOptionList>"); |
| 126 |
|
| 127 |
poDriver->pfnIdentify = OGRDGNV8DriverIdentify; |
| 128 |
poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); |
| 129 |
poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); |
| 130 |
} |
| 131 |
|
| 132 |
/************************************************************************/ |
| 133 |
/* DeclareDeferredOGRDGNV8Plugin() */ |
| 134 |
/************************************************************************/ |
| 135 |
|
| 136 |
#ifdef PLUGIN_FILENAME |
| 137 |
void DeclareDeferredOGRDGNV8Plugin() |
| 138 |
{ |
| 139 |
if (GDALGetDriverByName(DRIVER_NAME) != nullptr) |
| 140 |
{ |
| 141 |
return; |
| 142 |
} |
| 143 |
auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); |
| 144 |
#ifdef PLUGIN_INSTALLATION_MESSAGE |
| 145 |
poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, |
| 146 |
PLUGIN_INSTALLATION_MESSAGE); |
| 147 |
#endif |
| 148 |
OGRDGNV8DriverSetCommonMetadata(poDriver); |
| 149 |
GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); |
| 150 |
} |
| 151 |
#endif |