KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_odb_soldermask_shape_export.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <filesystem>
21#include <fstream>
22#include <memory>
23
24#include <algorithm>
25#include <footprint.h>
26
28#include <qa_utils/file_utils.h>
30#include <boost/test/unit_test.hpp>
31
32#include <base_units.h>
33#include <board.h>
34#include <footprint.h>
35#include <pcb_shape.h>
38#include <core/utf8.h>
39
40namespace fs = std::filesystem;
41
48static int countOdbSurfaceRecords( const fs::path& aFeaturesFile )
49{
50 int surfaceCount = 0;
51 std::ifstream stream( aFeaturesFile );
52 std::string line;
53
54 while( std::getline( stream, line ) )
55 {
56 if( line.rfind( "S ", 0 ) == 0 )
57 surfaceCount++;
58 }
59
60 return surfaceCount;
61}
62
63
76static int countMaskSurfaceRecords( const fs::path& aRoot, bool& aFoundFile )
77{
78 int total = 0;
79 aFoundFile = false;
80
81 for( const fs::directory_entry& entry : fs::recursive_directory_iterator( aRoot ) )
82 {
83 if( !entry.is_regular_file() || entry.path().filename() != "features" )
84 continue;
85
86 const std::string layerDir = entry.path().parent_path().filename().string();
87
88 if( layerDir.find( "mask" ) == std::string::npos )
89 continue;
90
91 aFoundFile = true;
92 total += countOdbSurfaceRecords( entry.path() );
93 }
94
95 return total;
96}
97
98
106BOOST_AUTO_TEST_CASE( OdbSolderMaskShapeExport )
107{
108 SETTINGS_MANAGER settingsManager;
109 std::unique_ptr<BOARD> board = KI_TEST::RequireBoardFromPcbnewQAData( "issue24690/soldermask_shape.kicad_pcb" );
110
111 // The export can only drop the mask opening if the mask-flagged shape is on
112 // the board to begin with, so confirm the fixture still carries it.
113 BOOST_REQUIRE_EQUAL( board->Footprints().size(), 1u );
114
115 const FOOTPRINT* fp = board->Footprints().front();
116
117 const auto onMask =
118 []( const BOARD_ITEM* aItem )
119 {
120 return aItem->Type() == PCB_SHAPE_T && aItem->IsOnLayer( F_Mask );
121 };
122
123 BOOST_REQUIRE( std::any_of( fp->GraphicalItems().begin(), fp->GraphicalItems().end(),
124 onMask ) );
125
126 KI_TEST::SCOPED_TEMP_DIR outDir( wxT( "kicad_qa_odb_soldermask_24690" ) );
127
128 PCB_IO_ODBPP odbExporter;
129 std::map<std::string, UTF8> props;
130 props["units"] = "mm";
131 props["sigfig"] = "6";
132
133 BOOST_REQUIRE_NO_THROW( odbExporter.SaveBoard( outDir.Path().string(), *board, &props ) );
134
135 BOOST_REQUIRE_MESSAGE( fs::exists( outDir.Path() ), "ODB++ export produced no output tree" );
136
137 bool foundMask = false;
138 int surfaceCount = countMaskSurfaceRecords( outDir.Path(), foundMask );
139
140 BOOST_REQUIRE_MESSAGE( foundMask, "ODB++ export produced no solder-mask features file" );
141
142 BOOST_CHECK_MESSAGE( surfaceCount > 0, "Mask-flagged shape was dropped from the ODB++ export "
143 "(no surface features on the solder-mask layer)" );
144}
General utilities for PCB file IO for QA programs.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
DRAWINGS & GraphicalItems()
Definition footprint.h:358
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
Definition file_utils.h:61
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
@ F_Mask
Definition layer_ids.h:93
std::unique_ptr< BOARD > RequireBoardFromPcbnewQAData(const std::filesystem::path &aFilename)
Require a board from the path relative to the pcbnew QA data directory.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(OdbSolderMaskShapeExport)
Regression guard for GitLab #24690: a footprint polygon on a copper layer with the "Solder mask" flag...
static int countOdbSurfaceRecords(const fs::path &aFeaturesFile)
Count surface ("S ") feature records in a single ODB++ "features" file.
static int countMaskSurfaceRecords(const fs::path &aRoot, bool &aFoundFile)
Sum surface ("S ") feature records across every solder-mask "features" file in an ODB++ tree.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80