KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_plot_job_layers.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
22
23#include <board.h>
25#include <json_common.h>
26#include <pcb_plotter.h>
27
28
29namespace
30{
31
32std::unique_ptr<BOARD> loadBoard( const std::string& aName )
33{
35}
36
37} // namespace
38
39
40BOOST_AUTO_TEST_SUITE( PlotJobLayers )
41
42
43// A fab drawing job saved on a 2-layer board must not plot inner copper on a 4-layer board
44BOOST_AUTO_TEST_CASE( JobDialogKeepsOnlyShownLayers )
45{
46 std::unique_ptr<BOARD> twoLayer = loadBoard( "issue17559.kicad_pcb" );
47 std::unique_ptr<BOARD> fourLayer = loadBoard( "issue22536.kicad_pcb" );
48 BOOST_REQUIRE( twoLayer && fourLayer );
49 BOOST_REQUIRE_EQUAL( twoLayer->GetCopperLayerCount(), 2 );
50 BOOST_REQUIRE_EQUAL( fourLayer->GetCopperLayerCount(), 4 );
51
52 LSET stored = PCB_PLOTTER::DialogLayerSelection( LSET( { F_Fab } ), twoLayer->GetEnabledLayers(), true );
53
54 BOOST_CHECK_EQUAL( ( stored & fourLayer->GetEnabledLayers() ).FmtHex(), LSET( { F_Fab } ).FmtHex() );
55}
56
57
58// A job listing every copper layer, re-saved on a 2-layer board, must still plot all copper of a 4-layer board
59BOOST_AUTO_TEST_CASE( AllCopperLayersSurviveSmallerBoard )
60{
61 std::unique_ptr<BOARD> twoLayer = loadBoard( "issue17559.kicad_pcb" );
62 std::unique_ptr<BOARD> fourLayer = loadBoard( "issue22536.kicad_pcb" );
63 BOOST_REQUIRE( twoLayer && fourLayer );
64
65 // Older plot job dialogs wrote every copper layer and no all_copper_layers key
66 nlohmann::json legacy;
67 {
69 LSET layers = LSET::AllCuMask() | LSET( { F_Mask, B_Mask, Edge_Cuts } );
71 job.ToJson( legacy );
72 legacy.erase( "all_copper_layers" );
73 }
74
75 JOB_EXPORT_PCB_GERBERS gerberJob;
76 gerberJob.FromJson( legacy );
78 twoLayer->GetEnabledLayers(), true )
80
81 nlohmann::json saved;
82 gerberJob.ToJson( saved );
83
85 reloaded.FromJson( saved );
86
87 LSET plotted = LSET( reloaded.ResolvePlotLayers( fourLayer->GetEnabledLayers() ) );
88 LSET fourLayerCopper = fourLayer->GetEnabledLayers() & LSET::AllCuMask();
89
90 BOOST_CHECK_EQUAL( ( plotted & LSET::AllCuMask() ).FmtHex(), fourLayerCopper.FmtHex() );
91}
92
93
General utilities for PCB file IO for QA programs.
std::string FmtHex() const
Return a hex string showing contents of this set.
Definition base_set.h:312
LSEQ ResolvePlotLayers(const LSET &aEnabledLayers) const
Return the layers to plot on a board with aEnabledLayers.
void FromJson(const nlohmann::json &aJson) override
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
LSEQ SeqStackupForPlotting() const
Return the sequence that is typical for a bottom-to-top stack-up.
Definition lset.cpp:400
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static LSET DialogLayerSelection(const LSET &aChecked, const LSET &aEnabledLayers, bool aForJob)
Return the layers a plot dialog stores when aChecked are ticked.
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Mask
Definition layer_ids.h:94
@ F_Mask
Definition layer_ids.h:93
@ F_Fab
Definition layer_ids.h:115
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_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(JobDialogKeepsOnlyShownLayers)