KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_plot_controller.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25
26#include <filesystem>
27#include <memory>
28
29#include <board.h>
30#include <footprint.h>
31#include <pad.h>
32#include <pcb_text.h>
33#include <pcbplot.h>
34#include <plotcontroller.h>
35#include <pcb_plot_params.h>
39
40namespace
41{
42
43struct PLOT_CONTROLLER_FIXTURE
44{
45 PLOT_CONTROLLER_FIXTURE()
46 {
47 KI_TEST::LoadBoard( m_settingsManager, "complex_hierarchy", m_board );
48 }
49
50 ~PLOT_CONTROLLER_FIXTURE()
51 {
52 // Clean up temp files
53 for( const wxString& path : m_tempFiles )
54 {
55 if( wxFileExists( path ) )
56 wxRemoveFile( path );
57 }
58 }
59
60 SETTINGS_MANAGER m_settingsManager;
61 std::unique_ptr<BOARD> m_board;
62 std::vector<wxString> m_tempFiles;
63};
64
65} // namespace
66
67
68BOOST_FIXTURE_TEST_SUITE( PlotController, PLOT_CONTROLLER_FIXTURE )
69
70
71
77BOOST_AUTO_TEST_CASE( MultiLayerDxfPlot )
78{
79 BOOST_REQUIRE( m_board );
80 BOOST_REQUIRE( m_board->Footprints().size() > 0 );
81
82 PLOT_CONTROLLER plotController( m_board.get() );
83
84 wxString tempDir = wxFileName::GetTempDir();
85
86 // Plot F.Cu (copper layer - uses PlotLayerOutlines path for DXF)
87 plotController.SetLayer( F_Cu );
88 bool opened = plotController.OpenPlotfile( wxT( "test_fcu" ), PLOT_FORMAT::DXF, wxT( "test" ) );
89 BOOST_REQUIRE( opened );
90
91 m_tempFiles.push_back( plotController.GetPlotFileName() );
92
93 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
94 plotController.ClosePlot();
95
96 // Plot F.Fab (non-copper layer - uses PlotStandardLayer path for DXF)
97 // This is the plot that triggers the crash in issue #23171
98 plotController.SetLayer( F_Fab );
99 opened = plotController.OpenPlotfile( wxT( "test_ffab" ), PLOT_FORMAT::DXF, wxT( "test" ) );
100 BOOST_REQUIRE( opened );
101
102 m_tempFiles.push_back( plotController.GetPlotFileName() );
103
104 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
105 plotController.ClosePlot();
106}
107
108
112BOOST_AUTO_TEST_CASE( MultiLayerSvgPlot )
113{
114 BOOST_REQUIRE( m_board );
115
116 PLOT_CONTROLLER plotController( m_board.get() );
117
118 plotController.SetLayer( F_Cu );
119 bool opened = plotController.OpenPlotfile( wxT( "test_fcu" ), PLOT_FORMAT::SVG, wxT( "test" ) );
120 BOOST_REQUIRE( opened );
121
122 m_tempFiles.push_back( plotController.GetPlotFileName() );
123
124 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
125 plotController.ClosePlot();
126
127 plotController.SetLayer( F_Fab );
128 opened = plotController.OpenPlotfile( wxT( "test_ffab" ), PLOT_FORMAT::SVG, wxT( "test" ) );
129 BOOST_REQUIRE( opened );
130
131 m_tempFiles.push_back( plotController.GetPlotFileName() );
132
133 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
134 plotController.ClosePlot();
135}
136
137
141BOOST_AUTO_TEST_CASE( MultiLayerGerberPlot )
142{
143 BOOST_REQUIRE( m_board );
144
145 PLOT_CONTROLLER plotController( m_board.get() );
146
147 plotController.SetLayer( F_Cu );
148 bool opened = plotController.OpenPlotfile( wxT( "test_fcu" ), PLOT_FORMAT::GERBER, wxT( "test" ) );
149 BOOST_REQUIRE( opened );
150
151 m_tempFiles.push_back( plotController.GetPlotFileName() );
152
153 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
154 plotController.ClosePlot();
155
156 plotController.SetLayer( F_Fab );
157 opened = plotController.OpenPlotfile( wxT( "test_ffab" ), PLOT_FORMAT::GERBER, wxT( "test" ) );
158 BOOST_REQUIRE( opened );
159
160 m_tempFiles.push_back( plotController.GetPlotFileName() );
161
162 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
163 plotController.ClosePlot();
164}
165
166
170BOOST_AUTO_TEST_CASE( MultiLayerPdfPlot )
171{
172 BOOST_REQUIRE( m_board );
173
174 PLOT_CONTROLLER plotController( m_board.get() );
175
176 plotController.SetLayer( F_Cu );
177 bool opened = plotController.OpenPlotfile( wxT( "test_fcu" ), PLOT_FORMAT::PDF, wxT( "test" ) );
178 BOOST_REQUIRE( opened );
179
180 m_tempFiles.push_back( plotController.GetPlotFileName() );
181
182 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
183 plotController.ClosePlot();
184
185 plotController.SetLayer( F_Fab );
186 opened = plotController.OpenPlotfile( wxT( "test_ffab" ), PLOT_FORMAT::PDF, wxT( "test" ) );
187 BOOST_REQUIRE( opened );
188
189 m_tempFiles.push_back( plotController.GetPlotFileName() );
190
191 BOOST_CHECK_NO_THROW( plotController.PlotLayer() );
192 plotController.ClosePlot();
193}
194
195
General utilities for PCB file IO for QA programs.
Batch plotter state object.
bool PlotLayer()
Plot a single layer on the current plotfile m_plotLayer is the layer to plot.
Definition pcbplot.cpp:475
bool OpenPlotfile(const wxString &aSuffix, PLOT_FORMAT aFormat, const wxString &aSheetName=wxEmptyString, const wxString &aSheetPath=wxEmptyString)
Open a new plotfile; works as a factory for plotter objects/.
Definition pcbplot.cpp:420
void SetLayer(int aLayer)
const wxString GetPlotFileName()
void ClosePlot()
Close the current plot, nothing happens if it isn't open.
Definition pcbplot.cpp:406
@ F_Fab
Definition layer_ids.h:119
@ F_Cu
Definition layer_ids.h:64
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_AUTO_TEST_CASE(MultiLayerDxfPlot)
Test that plotting multiple layers sequentially via PLOT_CONTROLLER does not crash.