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 : * Permission is hereby granted, free of charge, to any person obtaining a copy 14 : * of this software and associated documentation files (the "Software"), to 15 : *deal in the Software without restriction, including without limitation the 16 : *rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 17 : *sell copies of the Software, and to permit persons to whom the Software is 18 : * furnished to do so, subject to the following conditions: 19 : * 20 : * The above copyright notice and this permission notice shall be included in 21 : *all copies or substantial portions of the Software. 22 : * 23 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 : *FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 : *IN THE SOFTWARE. 30 : *******************************************************************************/ 31 : #ifndef OGR_CAD_H_INCLUDED 32 : #define OGR_CAD_H_INCLUDED 33 : 34 : // gdal headers 35 : #include "ogrsf_frmts.h" 36 : 37 : // libopencad headers 38 : #include "cadgeometry.h" 39 : #include "opencad_api.h" 40 : 41 : #include <set> 42 : 43 : class OGRCADLayer final : public OGRLayer 44 : { 45 : GDALDataset *m_poDS = nullptr; 46 : OGRFeatureDefn *poFeatureDefn; 47 : OGRSpatialReference *poSpatialRef; 48 : GIntBig nNextFID; 49 : CADLayer &poCADLayer; 50 : int nDWGEncoding; 51 : 52 : public: 53 : OGRCADLayer(GDALDataset *poDS, CADLayer &poCADLayer, 54 : OGRSpatialReference *poSR, int nEncoding); 55 : ~OGRCADLayer(); 56 : 57 : void ResetReading() override; 58 : OGRFeature *GetNextFeature() override; 59 : OGRFeature *GetFeature(GIntBig nFID) override; 60 : GIntBig GetFeatureCount(int /* bForce */) override; 61 : 62 0 : OGRSpatialReference *GetSpatialRef() override 63 : { 64 0 : return poSpatialRef; 65 : } 66 : 67 8 : OGRFeatureDefn *GetLayerDefn() override 68 : { 69 8 : return poFeatureDefn; 70 : } 71 : 72 : std::set<CPLString> asFeaturesAttributes; 73 : int TestCapability(const char *) override; 74 : 75 1 : GDALDataset *GetDataset() override 76 : { 77 1 : return m_poDS; 78 : } 79 : }; 80 : 81 : class GDALCADDataset final : public GDALDataset 82 : { 83 : CPLString osCADFilename; 84 : CADFile *poCADFile; 85 : // vector 86 : OGRCADLayer **papoLayers; 87 : int nLayers; 88 : // raster 89 : double adfGeoTransform[6]; 90 : GDALDataset *poRasterDS; 91 : mutable OGRSpatialReference *poSpatialReference; 92 : 93 : public: 94 : GDALCADDataset(); 95 : virtual ~GDALCADDataset(); 96 : 97 : int Open(GDALOpenInfo *poOpenInfo, CADFileIO *pFileIO, 98 : long nSubRasterLayer = -1, long nSubRasterFID = -1); 99 : 100 5 : int GetLayerCount() override 101 : { 102 5 : return nLayers; 103 : } 104 : 105 : OGRLayer *GetLayer(int) override; 106 : int TestCapability(const char *) override; 107 : virtual char **GetFileList() override; 108 : const OGRSpatialReference *GetSpatialRef() const override; 109 : virtual CPLErr GetGeoTransform(double *) override; 110 : virtual int GetGCPCount() override; 111 : const OGRSpatialReference *GetGCPSpatialRef() const override; 112 : virtual const GDAL_GCP *GetGCPs() override; 113 : virtual int CloseDependentDatasets() override; 114 : 115 : protected: 116 : const char *GetPrjFilePath() const; 117 : void FillTransform(CADImage *pImage, double dfUnits); 118 : int GetCadEncoding() const; 119 : 120 : private: 121 : CPL_DISALLOW_COPY_ASSIGN(GDALCADDataset) 122 : }; 123 : 124 : CPLString CADRecode(const CPLString &sString, int CADEncoding); 125 : 126 : #endif