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 <jon@craftyjon.com>
5  * Copyright (C) 2020 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 
27 #include "eda_3d_viewer_settings.h"
28 
29 using KIGFX::COLOR4D;
30 
32 const int viewer3dSchemaVersion = 1;
33 
34 
36  : APP_SETTINGS_BASE( "3d_viewer", viewer3dSchemaVersion ),
37  m_Render(),
38  m_Camera()
39 {
40  m_params.emplace_back( new PARAM<int>( "render.engine", &m_Render.engine,
41  static_cast<int>( RENDER_ENGINE::OPENGL_LEGACY ),
42  static_cast<int>( RENDER_ENGINE::OPENGL_LEGACY ),
43  static_cast<int>( RENDER_ENGINE::RAYTRACING ) ) );
44 
45  m_params.emplace_back( new PARAM<int>( "render.grid_type", &m_Render.grid_type,
46  static_cast<int>( GRID3D_TYPE::NONE ),
47  static_cast<int>( GRID3D_TYPE::NONE ),
48  static_cast<int>( GRID3D_TYPE::GRID_10MM ) ) );
49 
50  m_params.emplace_back( new PARAM<int>( "render.material_mode", &m_Render.material_mode,
51  static_cast<int>( MATERIAL_MODE::NORMAL ),
52  static_cast<int>( MATERIAL_MODE::NORMAL ),
53  static_cast<int>( MATERIAL_MODE::CAD_MODE ) ) );
54 
55  m_params.emplace_back( new PARAM<int>( "render.opengl_AA_mode", &m_Render.opengl_AA_mode,
56  static_cast<int>( ANTIALIASING_MODE::AA_8X ),
57  static_cast<int>( ANTIALIASING_MODE::AA_NONE ),
58  static_cast<int>( ANTIALIASING_MODE::AA_8X ) ) );
59 
60  m_params.emplace_back( new PARAM<COLOR4D>( "render.opengl_selection_color",
62  COLOR4D( 0.0, 1.0, 0.0, 1.0 ) ) );
63 
64  // OpenGL options
65  m_params.emplace_back( new PARAM<bool>( "render.opengl_copper_thickness",
67  m_params.emplace_back( new PARAM<bool>( "render.opengl_show_model_bbox",
68  &m_Render.opengl_show_model_bbox, false ) );
69  m_params.emplace_back( new PARAM<bool>( "render.opengl_highlight_on_rollover",
71  m_params.emplace_back( new PARAM<bool>( "render.opengl_AA_disableOnMove",
73  m_params.emplace_back( new PARAM<bool>( "render.opengl_thickness_disableOnMove",
75  m_params.emplace_back( new PARAM<bool>( "render.opengl_vias_disableOnMove",
77  m_params.emplace_back( new PARAM<bool>( "render.opengl_holes_disableOnMove",
79  m_params.emplace_back( new PARAM<bool>( "render.opengl_render_bbox_only_OnMove",
81 
82  // Raytracing options
83  m_params.emplace_back( new PARAM<bool>( "render.raytrace_anti_aliasing",
85  m_params.emplace_back( new PARAM<bool>( "render.raytrace_backfloor",
86  &m_Render.raytrace_backfloor, false ) );
87  m_params.emplace_back( new PARAM<bool>( "render.raytrace_post_processing",
89  m_params.emplace_back( new PARAM<bool>( "render.raytrace_procedural_textures",
91  m_params.emplace_back( new PARAM<bool>( "render.raytrace_reflections",
92  &m_Render.raytrace_reflections, true ) );
93  m_params.emplace_back( new PARAM<bool>( "render.raytrace_refractions",
94  &m_Render.raytrace_refractions, true ) );
95  m_params.emplace_back( new PARAM<bool>( "render.raytrace_shadows",
96  &m_Render.raytrace_shadows, true ) );
97 
98  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_shadows",
100  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_reflections",
102  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_refractions",
104 
105  m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_reflections",
107  m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_refractions",
109 
110  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_shadows",
111  &m_Render.raytrace_spread_shadows, 0.05f ) );
112  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_reflections",
114  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_refractions",
116 
117  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorCamera",
119  COLOR4D( 0.2, 0.2, 0.2, 1.0 ) ) );
120 
121  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorTop",
123  COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
124 
125  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorBottom",
127  COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
128 
129  std::vector<COLOR4D> default_colors =
130  {
131  COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
132  COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
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  };
140 
141  m_params.emplace_back( new PARAM_LIST<COLOR4D>( "render.raytrace_lightColor",
143  default_colors ) );
144 
145  const std::vector<int> default_elevation =
146  {
147  67, 67, 67, 67, -67, -67, -67, -67,
148  };
149 
150  m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightElevation",
152  default_elevation ) );
153 
154  const std::vector<int> default_azimuth =
155  {
156  45, 135, 225, 315, 45, 135, 225, 315,
157  };
158 
159  m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightAzimuth",
161  default_azimuth ) );
162 
163  m_params.emplace_back( new PARAM<bool>( "render.realistic",
164  &m_Render.realistic, true ) );
165  m_params.emplace_back( new PARAM<bool>( "render.show_adhesive",
166  &m_Render.show_adhesive, true ) );
167  m_params.emplace_back( new PARAM<bool>( "render.show_axis",
168  &m_Render.show_axis, true ) );
169  m_params.emplace_back( new PARAM<bool>( "render.show_board_body",
170  &m_Render.show_board_body, true ) );
171  m_params.emplace_back( new PARAM<bool>( "render.show_comments",
172  &m_Render.show_comments, true ) );
173  m_params.emplace_back( new PARAM<bool>( "render.show_eco",
174  &m_Render.show_eco, true ) );
175  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_insert",
176  &m_Render.show_footprints_insert, true ) );
177  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_normal",
178  &m_Render.show_footprints_normal, true ) );
179  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_virtual",
181  m_params.emplace_back( new PARAM<bool>( "render.show_silkscreen",
182  &m_Render.show_silkscreen, true ) );
183  m_params.emplace_back( new PARAM<bool>( "render.show_soldermask",
184  &m_Render.show_soldermask, true ) );
185  m_params.emplace_back( new PARAM<bool>( "render.show_solderpaste",
186  &m_Render.show_solderpaste, true ) );
187  m_params.emplace_back( new PARAM<bool>( "render.show_zones",
188  &m_Render.show_zones, true ) );
189  m_params.emplace_back( new PARAM<bool>( "render.subtract_mask_from_silk",
190  &m_Render.subtract_mask_from_silk, false ) );
191  m_params.emplace_back( new PARAM<bool>( "render.clip_silk_on_via_annulus",
193  m_params.emplace_back( new PARAM<bool>( "render.plated_and_bare_copper",
195  m_params.emplace_back( new PARAM<bool>( "camera.animation_enabled",
196  &m_Camera.animation_enabled, true ) );
197  m_params.emplace_back( new PARAM<int>( "camera.moving_speed_multiplier",
199  m_params.emplace_back( new PARAM<double>( "camera.rotation_increment",
200  &m_Camera.rotation_increment, 10.0 ) );
201  m_params.emplace_back( new PARAM<int>( "camera.projection_mode",
202  &m_Camera.projection_mode, 1 ) );
203 
205 }
206 
207 
209 {
215  try
216  {
217  if( m_internals->contains( "colors" ) )
218  m_internals->erase( "colors" );
219  }
220  catch( ... )
221  {
222  }
223 
224  return true;
225 }
226 
227 
229 {
230  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
231 
232  ret &= fromLegacy<int>( aCfg, "RenderEngine", "render.engine" );
233  ret &= fromLegacy<int>( aCfg, "ShowGrid3D", "render.grid_type" );
234  ret &= fromLegacy<int>( aCfg, "Render_Material", "render.material_mode" );
235  ret &= fromLegacy<bool>( aCfg, "Render_OGL_ShowCopperThickness", "render.opengl_copper_thickness" );
236  ret &= fromLegacy<bool>( aCfg, "Render_OGL_ShowModelBoudingBoxes", "render.opengl_show_model_bbox" );
237  ret &= fromLegacy<bool>( aCfg, "Render_RAY_AntiAliasing", "render.raytrace_anti_aliasing" );
238  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Backfloor", "render.raytrace_backfloor" );
239  ret &= fromLegacy<bool>( aCfg, "Render_RAY_PostProcess", "render.raytrace_post_processing" );
240  ret &= fromLegacy<bool>( aCfg, "Render_RAY_ProceduralTextures", "render.raytrace_procedural_textures" );
241  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Reflections", "render.raytrace_reflections" );
242  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Refractions", "render.raytrace_refractions" );
243  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Shadows", "render.raytrace_shadows" );
244  ret &= fromLegacy<bool>( aCfg, "ShowRealisticMode", "render.realistic" );
245  ret &= fromLegacy<bool>( aCfg, "ShowAdhesiveLayers", "render.show_adhesive" );
246  ret &= fromLegacy<bool>( aCfg, "ShowAxis", "render.show_axis" );
247  ret &= fromLegacy<bool>( aCfg, "ShowBoardBody", "render.show_board_body" );
248  ret &= fromLegacy<bool>( aCfg, "ShowCommentsLayers", "render.show_comments" );
249  ret &= fromLegacy<bool>( aCfg, "ShowEcoLayers", "render.show_eco" );
250  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Insert", "render.show_footprints_insert" );
251  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Normal", "render.show_footprints_normal" );
252  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Virtual", "render.show_footprints_virtual" );
253  ret &= fromLegacy<bool>( aCfg, "ShowSilkScreenLayers", "render.show_silkscreen" );
254  ret &= fromLegacy<bool>( aCfg, "ShowSolderMasLayers", "render.show_soldermask" );
255  ret &= fromLegacy<bool>( aCfg, "ShowSolderPasteLayers", "render.show_solderpaste" );
256  ret &= fromLegacy<bool>( aCfg, "ShowZones", "render.show_zones" );
257  ret &= fromLegacy<bool>( aCfg, "SubtractMaskFromSilk", "render.subtract_mask_from_silk" );
258 
259  auto do_color =
260  [&] ( const std::string& key_r, const std::string& key_g, const std::string& key_b,
261  std::string key_dest, double alpha = 1.0 )
262  {
263  COLOR4D color( 1, 1, 1, alpha );
264 
265  if( aCfg->Read( key_r, &color.r )
266  && aCfg->Read( key_g, &color.g )
267  && aCfg->Read( key_b, &color.b ) )
268  {
269  Set( key_dest, color );
270  }
271  };
272 
273  do_color( "BgColor_Red", "BgColor_Green", "BgColor_Blue", "colors.background_bottom" );
274  do_color( "BgColor_Red_Top", "BgColor_Green_Top", "BgColor_Blue_Top", "colors.background_top" );
275  do_color( "BoardBodyColor_Red", "BoardBodyColor_Green", "BoardBodyColor_Blue", "colors.board" );
276  do_color( "CopperColor_Red", "CopperColor_Green", "CopperColor_Blue", "colors.copper" );
277  do_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_bottom" );
278  do_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_top" );
279  do_color( "SMaskColor_Red", "SMaskColor_Green", "SMaskColor_Blue", "colors.soldermask", 0.83 );
280  do_color( "SPasteColor_Red", "SPasteColor_Green", "SPasteColor_Blue", "colors.solderpaste" );
281 
282  return ret;
283 }
Use a gray shading based on diffuse material.
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...
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
const int viewer3dSchemaVersion
! Update the schema version whenever a migration is required
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
int color
Definition: DXF_plotter.cpp:57
Declaration of the cogl_att_list class.
declared enumerations and flags
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
Use all material properties from model file.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
std::vector< KIGFX::COLOR4D > raytrace_lightColor
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103