KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_project_local_settings.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
27
29
30#include <project.h>
35
36#include <filesystem>
37#include <fstream>
38
39namespace fs = std::filesystem;
40
41
43{
44public:
46 {
47 m_tempDir = fs::temp_directory_path() / "kicad_project_local_settings_test";
48 fs::remove_all( m_tempDir );
49 fs::create_directories( m_tempDir );
50 }
51
53 {
54 fs::remove_all( m_tempDir );
55 }
56
57 void writeAndLoadProject( const std::string& aProjectName, const std::string& aPrlContents,
58 SETTINGS_MANAGER& aSettingsManager )
59 {
60 fs::path projectDir = m_tempDir / aProjectName;
61 fs::create_directories( projectDir );
62
63 fs::path prlPath = projectDir
64 / ( aProjectName + "." + FILEEXT::ProjectLocalSettingsFileExtension );
65
66 {
67 std::ofstream prlFile( prlPath );
68 prlFile << aPrlContents;
69 }
70
71 std::string proContents = R"({ "meta": { "filename": ")" + aProjectName + R"(.kicad_pro", "version": 3 } })";
72
73 fs::path proPath = projectDir / ( aProjectName + ".kicad_pro" );
74
75 {
76 std::ofstream proFile( proPath );
77 proFile << proContents;
78 }
79
80 BOOST_REQUIRE( aSettingsManager.LoadProject( wxString( proPath.string() ) ) );
81 }
82
83 fs::path m_tempDir;
84};
85
86
87BOOST_FIXTURE_TEST_SUITE( ProjectLocalSettings, PROJECT_LOCAL_SETTINGS_FIXTURE )
88
89
90
93BOOST_AUTO_TEST_CASE( V8PrlFootprintTextStaysVisible )
94{
95 // Verbatim v8 export from the issue #24193 reproduction case.
96 std::string prlContent = R"({
97 "board": {
98 "active_layer": 0,
99 "active_layer_preset": "All Layers",
100 "auto_track_width": true,
101 "hidden_netclasses": [],
102 "hidden_nets": [],
103 "high_contrast_mode": 0,
104 "net_color_mode": 1,
105 "opacity": {
106 "images": 0.6,
107 "pads": 1.0,
108 "tracks": 1.0,
109 "vias": 1.0,
110 "zones": 0.6
111 },
112 "selection_filter": {
113 "dimensions": true,
114 "footprints": true,
115 "graphics": true,
116 "keepouts": true,
117 "lockedItems": false,
118 "otherItems": true,
119 "pads": true,
120 "text": true,
121 "tracks": true,
122 "vias": true,
123 "zones": true
124 },
125 "visible_items": [
126 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19,
127 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35,
128 36, 39, 40
129 ],
130 "visible_layers": "fffffff_ffffffff",
131 "zone_display_mode": 0
132 },
133 "meta": {
134 "filename": "v8_project.kicad_prl",
135 "version": 3
136 },
137 "project": {
138 "files": []
139 }
140 })";
141
142 SETTINGS_MANAGER settingsManager;
143 writeAndLoadProject( "v8_project", prlContent, settingsManager );
144
145 PROJECT_LOCAL_SETTINGS& localSettings = settingsManager.Prj().GetLocalSettings();
146
148 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_REFERENCES ) ),
149 "LAYER_FP_REFERENCES should be visible after migrating a V8 PRL" );
150
152 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_VALUES ) ),
153 "LAYER_FP_VALUES should be visible after migrating a V8 PRL" );
154
156 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_TEXT ) ),
157 "LAYER_FP_TEXT should be visible after migrating a V8 PRL" );
158}
159
160
166BOOST_AUTO_TEST_CASE( MinimalVisibleItemsAppliesMigration )
167{
168 // Offsets 5 (FP_TEXT), 17 (FP_VALUES), 18 (FP_REFERENCES) in the v8 enum.
169 std::string prlContent = R"({
170 "board": {
171 "visible_items": [5, 17, 18],
172 "visible_layers": "fffffff_ffffffff"
173 },
174 "meta": {
175 "filename": "minimal_project.kicad_prl",
176 "version": 3
177 },
178 "project": { "files": [] }
179 })";
180
181 SETTINGS_MANAGER settingsManager;
182 writeAndLoadProject( "minimal_project", prlContent, settingsManager );
183
184 PROJECT_LOCAL_SETTINGS& localSettings = settingsManager.Prj().GetLocalSettings();
185
186 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_TEXT ) ) );
187 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_VALUES ) ) );
188 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_REFERENCES ) ) );
189
190 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_TRACKS ) ) );
191 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_ZONES ) ) );
192 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_PADS ) ) );
193}
194
195
void writeAndLoadProject(const std::string &aProjectName, const std::string &aPrlContents, SETTINGS_MANAGER &aSettingsManager)
The project local settings are things that are attached to a particular project, but also might be pa...
GAL_SET m_VisibleItems
The GAL layers (aka items) that are turned on for viewing (.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:206
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
static const std::string ProjectLocalSettingsFileExtension
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition layer_ids.h:291
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
Definition layer_ids.h:362
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_AUTO_TEST_CASE(V8PrlFootprintTextStaysVisible)
https://gitlab.com/kicad/code/kicad/-/issues/24193
Definition of file extensions used in Kicad.