KiCad PCB EDA Suite
eda_3d_viewer_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 (C) 2020 Jon Evans <[email protected]>
5 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <3d_enums.h>
23#include <settings/parameters.h>
25#include <wx/config.h>
26
28
29using KIGFX::COLOR4D;
30
33
34
37 m_Render(),
38 m_Camera()
39{
40 m_params.emplace_back( new PARAM_ENUM<RENDER_ENGINE>( "render.engine", &m_Render.engine,
44
45 m_params.emplace_back( new PARAM_ENUM<GRID3D_TYPE>( "render.grid_type", &m_Render.grid_type,
49
50 m_params.emplace_back( new PARAM_ENUM<MATERIAL_MODE>( "render.material_mode",
55
56 m_params.emplace_back( new PARAM_ENUM<ANTIALIASING_MODE>( "render.opengl_AA_mode",
61
62 m_params.emplace_back( new PARAM<COLOR4D>( "render.opengl_selection_color",
64 COLOR4D( 0.0, 1.0, 0.0, 1.0 ) ) );
65
66 // OpenGL options
67 m_params.emplace_back( new PARAM<bool>( "render.opengl_copper_thickness",
69 m_params.emplace_back( new PARAM<bool>( "render.opengl_show_model_bbox",
71 m_params.emplace_back( new PARAM<bool>( "render.opengl_highlight_on_rollover",
73 m_params.emplace_back( new PARAM<bool>( "render.opengl_AA_disableOnMove",
75 m_params.emplace_back( new PARAM<bool>( "render.opengl_thickness_disableOnMove",
77 m_params.emplace_back( new PARAM<bool>( "render.opengl_vias_disableOnMove",
79 m_params.emplace_back( new PARAM<bool>( "render.opengl_holes_disableOnMove",
81 m_params.emplace_back( new PARAM<bool>( "render.opengl_render_bbox_only_OnMove",
83
84 // Raytracing options
85 m_params.emplace_back( new PARAM<bool>( "render.raytrace_anti_aliasing",
87 m_params.emplace_back( new PARAM<bool>( "render.raytrace_backfloor",
88 &m_Render.raytrace_backfloor, false ) );
89 m_params.emplace_back( new PARAM<bool>( "render.raytrace_post_processing",
91 m_params.emplace_back( new PARAM<bool>( "render.raytrace_procedural_textures",
93 m_params.emplace_back( new PARAM<bool>( "render.raytrace_reflections",
95 m_params.emplace_back( new PARAM<bool>( "render.raytrace_refractions",
97 m_params.emplace_back( new PARAM<bool>( "render.raytrace_shadows",
98 &m_Render.raytrace_shadows, true ) );
99
100 m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_shadows",
102 m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_reflections",
104 m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_refractions",
106
107 m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_reflections",
109 m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_refractions",
111
112 m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_shadows",
114 m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_reflections",
116 m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_refractions",
118
119 m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorCamera",
121 COLOR4D( 0.2, 0.2, 0.2, 1.0 ) ) );
122
123 m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorTop",
125 COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
126
127 m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorBottom",
129 COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
130
131 std::vector<COLOR4D> default_colors =
132 {
133 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
134 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
135 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
136 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
137 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
138 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
139 COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
140 COLOR4D( 0.168, 0.168, 0.168, 1.0 )
141 };
142
143 m_params.emplace_back( new PARAM_LIST<COLOR4D>( "render.raytrace_lightColor",
145 default_colors ) );
146
147 const std::vector<int> default_elevation =
148 {
149 67, 67, 67, 67, -67, -67, -67, -67,
150 };
151
152 m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightElevation",
154 default_elevation ) );
155
156 const std::vector<int> default_azimuth =
157 {
158 45, 135, 225, 315, 45, 135, 225, 315,
159 };
160
161 m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightAzimuth",
163 default_azimuth ) );
164
165 m_params.emplace_back( new PARAM<bool>( "render.realistic",
166 &m_Render.realistic, true ) );
167 m_params.emplace_back( new PARAM<bool>( "render.show_adhesive",
168 &m_Render.show_adhesive, true ) );
169 m_params.emplace_back( new PARAM<bool>( "render.show_axis",
170 &m_Render.show_axis, true ) );
171 m_params.emplace_back( new PARAM<bool>( "render.show_board_body",
172 &m_Render.show_board_body, true ) );
173 m_params.emplace_back( new PARAM<bool>( "render.show_comments",
174 &m_Render.show_comments, true ) );
175 m_params.emplace_back( new PARAM<bool>( "render.show_eco",
176 &m_Render.show_eco, true ) );
177 m_params.emplace_back( new PARAM<bool>( "render.show_footprints_insert",
179 m_params.emplace_back( new PARAM<bool>( "render.show_footprints_normal",
181 m_params.emplace_back( new PARAM<bool>( "render.show_footprints_virtual",
183 m_params.emplace_back( new PARAM<bool>( "render.show_footprints_not_in_posfile",
185 m_params.emplace_back( new PARAM<bool>( "render.show_silkscreen",
186 &m_Render.show_silkscreen, true ) );
187 m_params.emplace_back( new PARAM<bool>( "render.show_soldermask",
188 &m_Render.show_soldermask, true ) );
189 m_params.emplace_back( new PARAM<bool>( "render.show_solderpaste",
190 &m_Render.show_solderpaste, true ) );
191 m_params.emplace_back( new PARAM<bool>( "render.show_zones",
192 &m_Render.show_zones, true ) );
193 m_params.emplace_back( new PARAM<bool>( "render.subtract_mask_from_silk",
195 m_params.emplace_back( new PARAM<bool>( "render.clip_silk_on_via_annulus",
197 m_params.emplace_back( new PARAM<bool>( "render.plated_and_bare_copper",
199 m_params.emplace_back( new PARAM<bool>( "camera.animation_enabled",
200 &m_Camera.animation_enabled, true ) );
201 m_params.emplace_back( new PARAM<int>( "camera.moving_speed_multiplier",
203 m_params.emplace_back( new PARAM<double>( "camera.rotation_increment",
204 &m_Camera.rotation_increment, 10.0 ) );
205 m_params.emplace_back( new PARAM<int>( "camera.projection_mode",
207
209
210 registerMigration( 1, 2,
211 [&]() -> bool
212 {
213 Set( "render.opengl_copper_thickness", false );
214 return true;
215 } );
216}
217
218
220{
226 try
227 {
228 if( m_internals->contains( "colors" ) )
229 m_internals->erase( "colors" );
230 }
231 catch( ... )
232 {
233 }
234
235 return true;
236}
237
238
240{
241 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
242
243 ret &= fromLegacy<int>( aCfg, "RenderEngine", "render.engine" );
244 ret &= fromLegacy<int>( aCfg, "ShowGrid3D", "render.grid_type" );
245 ret &= fromLegacy<int>( aCfg, "Render_Material", "render.material_mode" );
246 ret &= fromLegacy<bool>( aCfg, "Render_OGL_ShowCopperThickness", "render.opengl_copper_thickness" );
247 ret &= fromLegacy<bool>( aCfg, "Render_OGL_ShowModelBoudingBoxes", "render.opengl_show_model_bbox" );
248 ret &= fromLegacy<bool>( aCfg, "Render_RAY_AntiAliasing", "render.raytrace_anti_aliasing" );
249 ret &= fromLegacy<bool>( aCfg, "Render_RAY_Backfloor", "render.raytrace_backfloor" );
250 ret &= fromLegacy<bool>( aCfg, "Render_RAY_PostProcess", "render.raytrace_post_processing" );
251 ret &= fromLegacy<bool>( aCfg, "Render_RAY_ProceduralTextures", "render.raytrace_procedural_textures" );
252 ret &= fromLegacy<bool>( aCfg, "Render_RAY_Reflections", "render.raytrace_reflections" );
253 ret &= fromLegacy<bool>( aCfg, "Render_RAY_Refractions", "render.raytrace_refractions" );
254 ret &= fromLegacy<bool>( aCfg, "Render_RAY_Shadows", "render.raytrace_shadows" );
255 ret &= fromLegacy<bool>( aCfg, "ShowRealisticMode", "render.realistic" );
256 ret &= fromLegacy<bool>( aCfg, "ShowAdhesiveLayers", "render.show_adhesive" );
257 ret &= fromLegacy<bool>( aCfg, "ShowAxis", "render.show_axis" );
258 ret &= fromLegacy<bool>( aCfg, "ShowBoardBody", "render.show_board_body" );
259 ret &= fromLegacy<bool>( aCfg, "ShowCommentsLayers", "render.show_comments" );
260 ret &= fromLegacy<bool>( aCfg, "ShowEcoLayers", "render.show_eco" );
261 ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Insert", "render.show_footprints_insert" );
262 ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Normal", "render.show_footprints_normal" );
263 ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Virtual", "render.show_footprints_virtual" );
264 ret &= fromLegacy<bool>( aCfg, "ShowSilkScreenLayers", "render.show_silkscreen" );
265 ret &= fromLegacy<bool>( aCfg, "ShowSolderMasLayers", "render.show_soldermask" );
266 ret &= fromLegacy<bool>( aCfg, "ShowSolderPasteLayers", "render.show_solderpaste" );
267 ret &= fromLegacy<bool>( aCfg, "ShowZones", "render.show_zones" );
268 ret &= fromLegacy<bool>( aCfg, "SubtractMaskFromSilk", "render.subtract_mask_from_silk" );
269
270 auto do_color =
271 [&] ( const std::string& key_r, const std::string& key_g, const std::string& key_b,
272 std::string key_dest, double alpha = 1.0 )
273 {
274 COLOR4D color( 1, 1, 1, alpha );
275
276 if( aCfg->Read( key_r, &color.r )
277 && aCfg->Read( key_g, &color.g )
278 && aCfg->Read( key_b, &color.b ) )
279 {
280 Set( key_dest, color );
281 }
282 };
283
284 do_color( "BgColor_Red", "BgColor_Green", "BgColor_Blue", "colors.background_bottom" );
285 do_color( "BgColor_Red_Top", "BgColor_Green_Top", "BgColor_Blue_Top", "colors.background_top" );
286 do_color( "BoardBodyColor_Red", "BoardBodyColor_Green", "BoardBodyColor_Blue", "colors.board" );
287 do_color( "CopperColor_Red", "CopperColor_Green", "CopperColor_Blue", "colors.copper" );
288 do_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_bottom" );
289 do_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_top" );
290 do_color( "SMaskColor_Red", "SMaskColor_Green", "SMaskColor_Blue", "colors.soldermask", 0.83 );
291 do_color( "SPasteColor_Red", "SPasteColor_Green", "SPasteColor_Blue", "colors.solderpaste" );
292
293 return ret;
294}
declared enumerations and flags
@ NORMAL
Use all material properties from model file.
@ CAD_MODE
Use a gray shading based on diffuse material.
int color
Definition: DXF_plotter.cpp:57
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Stores an enum as an integer.
Definition: parameters.h:217
const int viewer3dSchemaVersion
! Update the schema version whenever a migration is required
Declaration of the cogl_att_list class.
std::vector< KIGFX::COLOR4D > raytrace_lightColor