LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/cad/libopencad - cadfile.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 34 46 73.9 %
Date: 2024-11-21 22:18:42 Functions: 8 11 72.7 %

          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             :   * SPDX-License-Identifier: MIT
      14             :  *******************************************************************************/
      15             : #include "cadfile.h"
      16             : #include "opencad_api.h"
      17             : 
      18             : #include <iostream>
      19             : 
      20           8 : CADFile::CADFile( CADFileIO * poFileIO ) :
      21             :     pFileIO( poFileIO ),
      22           8 :     bReadingUnsupportedGeometries( false )
      23             : {
      24           8 : }
      25             : 
      26           8 : CADFile::~CADFile()
      27             : {
      28           8 :     if( nullptr != pFileIO )
      29             :     {
      30           8 :         pFileIO->Close();
      31           8 :         delete pFileIO;
      32             :     }
      33           8 : }
      34             : 
      35          16 : const CADHeader& CADFile::getHeader() const
      36             : {
      37          16 :     return oHeader;
      38             : }
      39             : 
      40           0 : const CADClasses& CADFile::getClasses() const
      41             : {
      42           0 :     return oClasses;
      43             : }
      44             : 
      45           0 : const CADTables& CADFile::getTables() const
      46             : {
      47           0 :     return oTables;
      48             : }
      49             : 
      50           8 : int CADFile::ParseFile( enum OpenOptions eOptions, bool bReadUnsupportedGeometries )
      51             : {
      52           8 :     if( nullptr == pFileIO )
      53           0 :         return CADErrorCodes::FILE_OPEN_FAILED;
      54             : 
      55           8 :     if( !pFileIO->IsOpened() )
      56             :     {
      57           0 :         if( !pFileIO->Open( CADFileIO::in | CADFileIO::binary ) )
      58           0 :             return CADErrorCodes::FILE_OPEN_FAILED;
      59             :     }
      60             : 
      61             :     // Set flag which will tell CADLayer to skip/not skip unsupported geoms
      62           8 :     bReadingUnsupportedGeometries = bReadUnsupportedGeometries;
      63             : 
      64             :     int nResultCode;
      65           8 :     nResultCode = ReadSectionLocators();
      66           8 :     if( nResultCode != CADErrorCodes::SUCCESS )
      67           0 :         return nResultCode;
      68           8 :     nResultCode = ReadHeader( eOptions );
      69           8 :     if( nResultCode != CADErrorCodes::SUCCESS )
      70           0 :         return nResultCode;
      71           8 :     nResultCode = ReadClasses( eOptions );
      72           8 :     if( nResultCode != CADErrorCodes::SUCCESS )
      73           0 :         return nResultCode;
      74           8 :     nResultCode = CreateFileMap();
      75           8 :     if( nResultCode != CADErrorCodes::SUCCESS )
      76           0 :         return nResultCode;
      77           8 :     nResultCode = ReadTables( eOptions );
      78           8 :     if( nResultCode != CADErrorCodes::SUCCESS )
      79           0 :         return nResultCode;
      80             : 
      81           8 :     return CADErrorCodes::SUCCESS;
      82             : }
      83             : 
      84           8 : int CADFile::ReadTables( CADFile::OpenOptions /*eOptions*/ )
      85             : {
      86             :     // TODO: read other tables in ALL option mode
      87             : 
      88           8 :     int nResult = oTables.ReadTable( this, CADTables::LayersTable );
      89           8 :     return nResult;
      90             : }
      91             : 
      92          26 : size_t CADFile::GetLayersCount() const
      93             : {
      94          26 :     return oTables.GetLayerCount();
      95             : }
      96             : 
      97          27 : CADLayer& CADFile::GetLayer( size_t index )
      98             : {
      99          27 :     return oTables.GetLayer( index );
     100             : }
     101             : 
     102          18 : bool CADFile::isReadingUnsupportedGeometries()
     103             : {
     104          18 :     return bReadingUnsupportedGeometries;
     105             : }

Generated by: LCOV version 1.14