/src/gdal/ogr/ogrsf_frmts/cad/libopencad/cadfile.cpp
Line | Count | Source |
1 | | /******************************************************************************* |
2 | | * Project: libopencad |
3 | | * Purpose: OpenSource CAD formats support library |
4 | | * Author: Alexandr Borzykh, mush3d at gmail.com |
5 | | * Author: Dmitry Baryshnikov, bishop.dev@gmail.com |
6 | | * Language: C++ |
7 | | ******************************************************************************* |
8 | | * The MIT License (MIT) |
9 | | * |
10 | | * Copyright (c) 2016 Alexandr Borzykh |
11 | | * Copyright (c) 2016-2019 NextGIS, <info@nextgis.com> |
12 | | * |
13 | | * SPDX-License-Identifier: MIT |
14 | | *******************************************************************************/ |
15 | | #include "cadfile.h" |
16 | | #include "opencad_api.h" |
17 | | |
18 | | #include <iostream> |
19 | | |
20 | | CADFile::CADFile( CADFileIO * poFileIO ) : |
21 | 7.54k | pFileIO( poFileIO ), |
22 | 7.54k | bReadingUnsupportedGeometries( false ) |
23 | 7.54k | { |
24 | 7.54k | } |
25 | | |
26 | | CADFile::~CADFile() |
27 | 7.54k | { |
28 | 7.54k | if( nullptr != pFileIO ) |
29 | 7.54k | { |
30 | 7.54k | pFileIO->Close(); |
31 | 7.54k | delete pFileIO; |
32 | 7.54k | } |
33 | 7.54k | } |
34 | | |
35 | | const CADHeader& CADFile::getHeader() const |
36 | 4.04k | { |
37 | 4.04k | return oHeader; |
38 | 4.04k | } |
39 | | |
40 | | const CADClasses& CADFile::getClasses() const |
41 | 0 | { |
42 | 0 | return oClasses; |
43 | 0 | } |
44 | | |
45 | | const CADTables& CADFile::getTables() const |
46 | 0 | { |
47 | 0 | return oTables; |
48 | 0 | } |
49 | | |
50 | | int CADFile::ParseFile( enum OpenOptions eOptions, bool bReadUnsupportedGeometries ) |
51 | 7.54k | { |
52 | 7.54k | if( nullptr == pFileIO ) |
53 | 0 | return CADErrorCodes::FILE_OPEN_FAILED; |
54 | | |
55 | 7.54k | if( !pFileIO->IsOpened() ) |
56 | 0 | { |
57 | 0 | if( !pFileIO->Open( CADFileIO::in | CADFileIO::binary ) ) |
58 | 0 | return CADErrorCodes::FILE_OPEN_FAILED; |
59 | 0 | } |
60 | | |
61 | | // Set flag which will tell CADLayer to skip/not skip unsupported geoms |
62 | 7.54k | bReadingUnsupportedGeometries = bReadUnsupportedGeometries; |
63 | | |
64 | 7.54k | int nResultCode; |
65 | 7.54k | nResultCode = ReadSectionLocators(); |
66 | 7.54k | if( nResultCode != CADErrorCodes::SUCCESS ) |
67 | 118 | return nResultCode; |
68 | 7.42k | nResultCode = ReadHeader( eOptions ); |
69 | 7.42k | if( nResultCode != CADErrorCodes::SUCCESS ) |
70 | 77 | return nResultCode; |
71 | 7.35k | nResultCode = ReadClasses( eOptions ); |
72 | 7.35k | if( nResultCode != CADErrorCodes::SUCCESS ) |
73 | 231 | return nResultCode; |
74 | 7.12k | nResultCode = CreateFileMap(); |
75 | 7.12k | if( nResultCode != CADErrorCodes::SUCCESS ) |
76 | 113 | return nResultCode; |
77 | 7.00k | nResultCode = ReadTables( eOptions ); |
78 | 7.00k | if( nResultCode != CADErrorCodes::SUCCESS ) |
79 | 4.98k | return nResultCode; |
80 | | |
81 | 2.02k | return CADErrorCodes::SUCCESS; |
82 | 7.00k | } |
83 | | |
84 | | int CADFile::ReadTables( CADFile::OpenOptions /*eOptions*/ ) |
85 | 7.00k | { |
86 | | // TODO: read other tables in ALL option mode |
87 | | |
88 | 7.00k | int nResult = oTables.ReadTable( this, CADTables::LayersTable ); |
89 | 7.00k | return nResult; |
90 | 7.00k | } |
91 | | |
92 | | size_t CADFile::GetLayersCount() const |
93 | 19.1k | { |
94 | 19.1k | return oTables.GetLayerCount(); |
95 | 19.1k | } |
96 | | |
97 | | CADLayer& CADFile::GetLayer( size_t index ) |
98 | 17.5k | { |
99 | 17.5k | return oTables.GetLayer( index ); |
100 | 17.5k | } |
101 | | |
102 | | bool CADFile::isReadingUnsupportedGeometries() |
103 | 19.4k | { |
104 | 19.4k | return bReadingUnsupportedGeometries; |
105 | 19.4k | } |