Coverage Report

Created: 2026-03-30 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.33k
    pFileIO( poFileIO ),
22
7.33k
    bReadingUnsupportedGeometries( false )
23
7.33k
{
24
7.33k
}
25
26
CADFile::~CADFile()
27
7.33k
{
28
7.33k
    if( nullptr != pFileIO )
29
7.33k
    {
30
7.33k
        pFileIO->Close();
31
7.33k
        delete pFileIO;
32
7.33k
    }
33
7.33k
}
34
35
const CADHeader& CADFile::getHeader() const
36
3.87k
{
37
3.87k
    return oHeader;
38
3.87k
}
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.33k
{
52
7.33k
    if( nullptr == pFileIO )
53
0
        return CADErrorCodes::FILE_OPEN_FAILED;
54
55
7.33k
    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.33k
    bReadingUnsupportedGeometries = bReadUnsupportedGeometries;
63
64
7.33k
    int nResultCode;
65
7.33k
    nResultCode = ReadSectionLocators();
66
7.33k
    if( nResultCode != CADErrorCodes::SUCCESS )
67
116
        return nResultCode;
68
7.21k
    nResultCode = ReadHeader( eOptions );
69
7.21k
    if( nResultCode != CADErrorCodes::SUCCESS )
70
63
        return nResultCode;
71
7.15k
    nResultCode = ReadClasses( eOptions );
72
7.15k
    if( nResultCode != CADErrorCodes::SUCCESS )
73
220
        return nResultCode;
74
6.93k
    nResultCode = CreateFileMap();
75
6.93k
    if( nResultCode != CADErrorCodes::SUCCESS )
76
100
        return nResultCode;
77
6.83k
    nResultCode = ReadTables( eOptions );
78
6.83k
    if( nResultCode != CADErrorCodes::SUCCESS )
79
4.89k
        return nResultCode;
80
81
1.93k
    return CADErrorCodes::SUCCESS;
82
6.83k
}
83
84
int CADFile::ReadTables( CADFile::OpenOptions /*eOptions*/ )
85
6.83k
{
86
    // TODO: read other tables in ALL option mode
87
88
6.83k
    int nResult = oTables.ReadTable( this, CADTables::LayersTable );
89
6.83k
    return nResult;
90
6.83k
}
91
92
size_t CADFile::GetLayersCount() const
93
16.4k
{
94
16.4k
    return oTables.GetLayerCount();
95
16.4k
}
96
97
CADLayer& CADFile::GetLayer( size_t index )
98
15.0k
{
99
15.0k
    return oTables.GetLayer( index );
100
15.0k
}
101
102
bool CADFile::isReadingUnsupportedGeometries()
103
19.6k
{
104
19.6k
    return bReadingUnsupportedGeometries;
105
19.6k
}