KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue25010.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 <qa_utils/file_utils.h>
22
23#include <base_units.h>
24#include <board.h>
26#include <footprint.h>
28#include <pad.h>
31
32#include <wx/ffile.h>
33#include <wx/filename.h>
34
35// Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/25010
36//
37// The position file dialog greyed out and force-cleared the DNP and "exclude from BOM" filters
38// whenever the Gerber X3 format was selected, so those footprints always landed in the exported
39// file even though PLACEFILE_GERBER_WRITER honours both flags.
40
41BOOST_AUTO_TEST_SUITE( Issue25010 )
42
43
44static FOOTPRINT* addFootprint( BOARD& aBoard, const wxString& aReference )
45{
46 FOOTPRINT* fp = new FOOTPRINT( &aBoard );
47
48 fp->SetReference( aReference );
49 fp->SetValue( wxS( "10K" ) );
50 fp->SetLayer( F_Cu );
51 fp->SetAttributes( FP_SMD );
52
53 PAD* pad = new PAD( fp );
54 pad->SetNumber( wxS( "1" ) );
55 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
57 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) ) );
58 pad->SetLayerSet( LSET( { F_Cu } ) );
59 fp->Add( pad );
60
61 aBoard.Add( fp, ADD_MODE::INSERT );
62
63 return fp;
64}
65
66
71BOOST_AUTO_TEST_CASE( GerberFormatSupportsPopulationFilters )
72{
74 using FILTER = JOB_EXPORT_PCB_POS::FILTER;
75
76 BOOST_CHECK( JOB_EXPORT_PCB_POS::FormatSupportsFilter( FORMAT::GERBER, FILTER::EXCLUDE_DNP ) );
77 BOOST_CHECK( JOB_EXPORT_PCB_POS::FormatSupportsFilter( FORMAT::GERBER, FILTER::EXCLUDE_BOM ) );
78
79 BOOST_CHECK( !JOB_EXPORT_PCB_POS::FormatSupportsFilter( FORMAT::GERBER, FILTER::SMD_ONLY ) );
80 BOOST_CHECK( !JOB_EXPORT_PCB_POS::FormatSupportsFilter( FORMAT::GERBER, FILTER::EXCLUDE_TH ) );
81
82 for( FORMAT format : { FORMAT::ASCII, FORMAT::CSV } )
83 {
84 for( FILTER filter : { FILTER::SMD_ONLY, FILTER::EXCLUDE_TH, FILTER::EXCLUDE_DNP,
85 FILTER::EXCLUDE_BOM } )
86 {
87 BOOST_CHECK( JOB_EXPORT_PCB_POS::FormatSupportsFilter( format, filter ) );
88 }
89 }
90}
91
92
97BOOST_AUTO_TEST_CASE( GerberPlaceFileHonorsExclusions )
98{
99 BOARD board;
100
101 addFootprint( board, wxS( "R1" ) );
102 addFootprint( board, wxS( "R2" ) )->SetDNP( true );
103 addFootprint( board, wxS( "R3" ) )->SetExcludedFromBOM( true );
104 addFootprint( board, wxS( "R4" ) )->SetExcludedFromPosFiles( true );
105
106 KI_TEST::SCOPED_TEMP_DIR tmpDir( "kicad_qa_issue25010" );
107
108 wxFileName tmpFile( tmpDir.PathStr(), wxS( "pnp.gbr" ) );
109
110 PLACEFILE_GERBER_WRITER writer( &board );
111
112 auto generate =
113 [&]( bool aExcludeDNP, bool aExcludeBOM ) -> wxString
114 {
115 int count = writer.CreatePlaceFile( tmpFile.GetFullPath(), F_Cu, false, aExcludeDNP,
116 aExcludeBOM );
117
118 BOOST_REQUIRE_GE( count, 0 );
119
120 wxFFile file( tmpFile.GetFullPath() );
121 wxString contents;
122
123 BOOST_REQUIRE( file.ReadAll( &contents ) );
124
125 return contents;
126 };
127
128 wxString unfiltered = generate( false, false );
129
130 BOOST_CHECK( unfiltered.Contains( wxS( "R1" ) ) );
131 BOOST_CHECK( unfiltered.Contains( wxS( "R2" ) ) );
132 BOOST_CHECK( unfiltered.Contains( wxS( "R3" ) ) );
133 BOOST_CHECK( !unfiltered.Contains( wxS( "R4" ) ) );
134
135 wxString filtered = generate( true, true );
136
137 BOOST_CHECK( filtered.Contains( wxS( "R1" ) ) );
138 BOOST_CHECK( !filtered.Contains( wxS( "R2" ) ) );
139 BOOST_CHECK( !filtered.Contains( wxS( "R3" ) ) );
140 BOOST_CHECK( !filtered.Contains( wxS( "R4" ) ) );
141}
142
143
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
void SetDNP(bool aDNP=true)
Definition footprint.h:1056
void SetExcludedFromBOM(bool aExclude=true)
Definition footprint.h:1038
void SetAttributes(int aAttributes)
Definition footprint.h:551
void SetExcludedFromPosFiles(bool aExclude=true)
Definition footprint.h:1029
void SetReference(const wxString &aReference)
Definition footprint.h:907
void SetValue(const wxString &aValue)
Definition footprint.h:930
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
FILTER
The footprint selection filters that may be applied while generating position data.
static bool FormatSupportsFilter(FORMAT aFormat, FILTER aFilter)
wxString PathStr() const
Get the path to the temporary directory as a wxString.
Definition file_utils.h:62
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
Definition pad.h:61
Used to create Gerber drill files.
int CreatePlaceFile(const wxString &aFullFilename, PCB_LAYER_ID aLayer, bool aIncludeBrdEdges, bool aExcludeDNP, bool aExcludeBOM)
Create an pnp gerber file.
@ FP_SMD
Definition footprint.h:86
Classes used in place file generation.
@ F_Cu
Definition layer_ids.h:60
@ RECTANGLE
Definition padstack.h:53
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(GerberFormatSupportsPopulationFilters)
The format capability table drives the dialog's checkbox enable state.
static FOOTPRINT * addFootprint(BOARD &aBoard, const wxString &aReference)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683