Line data Source code
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 : * Permission is hereby granted, free of charge, to any person obtaining a copy 14 : * of this software and associated documentation files (the "Software"), to deal 15 : * in the Software without restriction, including without limitation the rights 16 : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 : * 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 all 21 : * 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 FROM, 28 : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 : * SOFTWARE. 30 : *******************************************************************************/ 31 : #include "cadfile.h" 32 : #include "opencad_api.h" 33 : 34 : #include <iostream> 35 : 36 8 : CADFile::CADFile( CADFileIO * poFileIO ) : 37 : pFileIO( poFileIO ), 38 8 : bReadingUnsupportedGeometries( false ) 39 : { 40 8 : } 41 : 42 8 : CADFile::~CADFile() 43 : { 44 8 : if( nullptr != pFileIO ) 45 : { 46 8 : pFileIO->Close(); 47 8 : delete pFileIO; 48 : } 49 8 : } 50 : 51 16 : const CADHeader& CADFile::getHeader() const 52 : { 53 16 : return oHeader; 54 : } 55 : 56 0 : const CADClasses& CADFile::getClasses() const 57 : { 58 0 : return oClasses; 59 : } 60 : 61 0 : const CADTables& CADFile::getTables() const 62 : { 63 0 : return oTables; 64 : } 65 : 66 8 : int CADFile::ParseFile( enum OpenOptions eOptions, bool bReadUnsupportedGeometries ) 67 : { 68 8 : if( nullptr == pFileIO ) 69 0 : return CADErrorCodes::FILE_OPEN_FAILED; 70 : 71 8 : if( !pFileIO->IsOpened() ) 72 : { 73 0 : if( !pFileIO->Open( CADFileIO::in | CADFileIO::binary ) ) 74 0 : return CADErrorCodes::FILE_OPEN_FAILED; 75 : } 76 : 77 : // Set flag which will tell CADLayer to skip/not skip unsupported geoms 78 8 : bReadingUnsupportedGeometries = bReadUnsupportedGeometries; 79 : 80 : int nResultCode; 81 8 : nResultCode = ReadSectionLocators(); 82 8 : if( nResultCode != CADErrorCodes::SUCCESS ) 83 0 : return nResultCode; 84 8 : nResultCode = ReadHeader( eOptions ); 85 8 : if( nResultCode != CADErrorCodes::SUCCESS ) 86 0 : return nResultCode; 87 8 : nResultCode = ReadClasses( eOptions ); 88 8 : if( nResultCode != CADErrorCodes::SUCCESS ) 89 0 : return nResultCode; 90 8 : nResultCode = CreateFileMap(); 91 8 : if( nResultCode != CADErrorCodes::SUCCESS ) 92 0 : return nResultCode; 93 8 : nResultCode = ReadTables( eOptions ); 94 8 : if( nResultCode != CADErrorCodes::SUCCESS ) 95 0 : return nResultCode; 96 : 97 8 : return CADErrorCodes::SUCCESS; 98 : } 99 : 100 8 : int CADFile::ReadTables( CADFile::OpenOptions /*eOptions*/ ) 101 : { 102 : // TODO: read other tables in ALL option mode 103 : 104 8 : int nResult = oTables.ReadTable( this, CADTables::LayersTable ); 105 8 : return nResult; 106 : } 107 : 108 26 : size_t CADFile::GetLayersCount() const 109 : { 110 26 : return oTables.GetLayerCount(); 111 : } 112 : 113 27 : CADLayer& CADFile::GetLayer( size_t index ) 114 : { 115 27 : return oTables.GetLayer( index ); 116 : } 117 : 118 18 : bool CADFile::isReadingUnsupportedGeometries() 119 : { 120 18 : return bReadingUnsupportedGeometries; 121 : }