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
29#include <boost/test/unit_test.hpp>
30
31#include <base_units.h>
32#include <board.h>
33#include <footprint.h>
34#include <kiid.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::ReadBoardFromFileOrStream(
110 KI_TEST::GetPcbnewTestDataDir() + "issue24690/soldermask_shape.kicad_pcb" );
111
112 BOOST_REQUIRE( board );
113
114 // The export can only drop the mask opening if the mask-flagged shape is on
115 // the board to begin with, so confirm the fixture still carries it.
116 BOOST_REQUIRE_EQUAL( board->Footprints().size(), 1u );
117
118 const FOOTPRINT* fp = board->Footprints().front();
119
120 const auto onMask =
121 []( const BOARD_ITEM* aItem )
122 {
123 return aItem->Type() == PCB_SHAPE_T && aItem->IsOnLayer( F_Mask );
124 };
125
126 BOOST_REQUIRE( std::any_of( fp->GraphicalItems().begin(), fp->GraphicalItems().end(),
127 onMask ) );
128
129 const fs::path outDir =
130 fs::temp_directory_path() / ( "kicad_qa_odb_soldermask_24690_" + KIID().AsString().ToStdString() );
131
132 BOOST_REQUIRE( fs::create_directory( outDir ) );
133
134 PCB_IO_ODBPP odbExporter;
135 std::map<std::string, UTF8> props;
136 props["units"] = "mm";
137 props["sigfig"] = "6";
138
139 BOOST_REQUIRE_NO_THROW( odbExporter.SaveBoard( outDir.string(), *board, &props ) );
140
141 BOOST_REQUIRE_MESSAGE( fs::exists( outDir ), "ODB++ export produced no output tree" );
142
143 bool foundMask = false;
144 int surfaceCount = countMaskSurfaceRecords( outDir, foundMask );
145
146 BOOST_REQUIRE_MESSAGE( foundMask, "ODB++ export produced no solder-mask features file" );
147
148 BOOST_CHECK_MESSAGE( surfaceCount > 0, "Mask-flagged shape was dropped from the ODB++ export "
149 "(no surface features on the solder-mask layer)" );
150
151 fs::remove_all( outDir );
152}
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:84
DRAWINGS & GraphicalItems()
Definition footprint.h:407
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264
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::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
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