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_originalDir = fs::current_path();
48 m_tempDir = fs::temp_directory_path() / "kicad_project_local_settings_test";
49 fs::remove_all( m_tempDir );
50 fs::create_directories( m_tempDir );
51 }
52
54 {
55 fs::current_path( m_originalDir );
56 fs::remove_all( m_tempDir );
57 }
58
59 void writeAndLoadProject( const std::string& aProjectName, const std::string& aPrlContents,
60 SETTINGS_MANAGER& aSettingsManager )
61 {
62 fs::path projectDir = m_tempDir / aProjectName;
63 fs::create_directories( projectDir );
64
65 fs::path prlPath = projectDir
66 / ( aProjectName + "." + FILEEXT::ProjectLocalSettingsFileExtension );
67
68 {
69 std::ofstream prlFile( prlPath );
70 prlFile << aPrlContents;
71 }
72
73 std::string proContents = R"({ "meta": { "filename": ")" + aProjectName + R"(.kicad_pro", "version": 3 } })";
74
75 fs::path proPath = projectDir / ( aProjectName + ".kicad_pro" );
76
77 {
78 std::ofstream proFile( proPath );
79 proFile << proContents;
80 }
81
82 BOOST_REQUIRE( aSettingsManager.LoadProject( wxString( proPath.string() ) ) );
83 }
84
85 fs::path m_originalDir;
86 fs::path m_tempDir;
87};
88
89
90BOOST_FIXTURE_TEST_SUITE( ProjectLocalSettings, PROJECT_LOCAL_SETTINGS_FIXTURE )
91
92
93
96BOOST_AUTO_TEST_CASE( V8PrlFootprintTextStaysVisible )
97{
98 // Verbatim v8 export from the issue #24193 reproduction case.
99 std::string prlContent = R"({
100 "board": {
101 "active_layer": 0,
102 "active_layer_preset": "All Layers",
103 "auto_track_width": true,
104 "hidden_netclasses": [],
105 "hidden_nets": [],
106 "high_contrast_mode": 0,
107 "net_color_mode": 1,
108 "opacity": {
109 "images": 0.6,
110 "pads": 1.0,
111 "tracks": 1.0,
112 "vias": 1.0,
113 "zones": 0.6
114 },
115 "selection_filter": {
116 "dimensions": true,
117 "footprints": true,
118 "graphics": true,
119 "keepouts": true,
120 "lockedItems": false,
121 "otherItems": true,
122 "pads": true,
123 "text": true,
124 "tracks": true,
125 "vias": true,
126 "zones": true
127 },
128 "visible_items": [
129 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19,
130 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35,
131 36, 39, 40
132 ],
133 "visible_layers": "fffffff_ffffffff",
134 "zone_display_mode": 0
135 },
136 "meta": {
137 "filename": "v8_project.kicad_prl",
138 "version": 3
139 },
140 "project": {
141 "files": []
142 }
143 })";
144
145 SETTINGS_MANAGER settingsManager;
146 writeAndLoadProject( "v8_project", prlContent, settingsManager );
147
148 PROJECT_LOCAL_SETTINGS& localSettings = settingsManager.Prj().GetLocalSettings();
149
150 BOOST_CHECK_MESSAGE(
151 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_REFERENCES ) ),
152 "LAYER_FP_REFERENCES should be visible after migrating a V8 PRL" );
153
154 BOOST_CHECK_MESSAGE(
155 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_VALUES ) ),
156 "LAYER_FP_VALUES should be visible after migrating a V8 PRL" );
157
158 BOOST_CHECK_MESSAGE(
159 localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_TEXT ) ),
160 "LAYER_FP_TEXT should be visible after migrating a V8 PRL" );
161}
162
163
169BOOST_AUTO_TEST_CASE( MinimalVisibleItemsAppliesMigration )
170{
171 // Offsets 5 (FP_TEXT), 17 (FP_VALUES), 18 (FP_REFERENCES) in the v8 enum.
172 std::string prlContent = R"({
173 "board": {
174 "visible_items": [5, 17, 18],
175 "visible_layers": "fffffff_ffffffff"
176 },
177 "meta": {
178 "filename": "minimal_project.kicad_prl",
179 "version": 3
180 },
181 "project": { "files": [] }
182 })";
183
184 SETTINGS_MANAGER settingsManager;
185 writeAndLoadProject( "minimal_project", prlContent, settingsManager );
186
187 PROJECT_LOCAL_SETTINGS& localSettings = settingsManager.Prj().GetLocalSettings();
188
189 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_TEXT ) ) );
190 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_VALUES ) ) );
191 BOOST_CHECK( localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_FP_REFERENCES ) ) );
192
193 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_TRACKS ) ) );
194 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_ZONES ) ) );
195 BOOST_CHECK( !localSettings.m_VisibleItems.test( GAL_LAYER_INDEX( LAYER_PADS ) ) );
196}
197
198
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:207
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:389
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(V8PrlFootprintTextStaysVisible)
https://gitlab.com/kicad/code/kicad/-/issues/24193
Definition of file extensions used in Kicad.