KiCad PCB EDA Suite
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>
24 #include <wx/config.h>
25 
26 #include "3d_viewer_settings.h"
27 
28 using KIGFX::COLOR4D;
29 
31 const int viewer3dSchemaVersion = 0;
32 
33 
35  : APP_SETTINGS_BASE( "3d_viewer", viewer3dSchemaVersion ),
36  m_Render(),
37  m_Camera()
38 {
39  m_params.emplace_back( new PARAM<int>( "render.engine", &m_Render.engine,
40  static_cast<int>( RENDER_ENGINE::OPENGL_LEGACY ),
41  static_cast<int>( RENDER_ENGINE::OPENGL_LEGACY ),
42  static_cast<int>( RENDER_ENGINE::RAYTRACING ) ) );
43 
44  m_params.emplace_back( new PARAM<int>( "render.grid_type", &m_Render.grid_type,
45  static_cast<int>( GRID3D_TYPE::NONE ),
46  static_cast<int>( GRID3D_TYPE::NONE ),
47  static_cast<int>( GRID3D_TYPE::GRID_10MM ) ) );
48 
49  m_params.emplace_back( new PARAM<int>( "render.material_mode", &m_Render.material_mode,
50  static_cast<int>( MATERIAL_MODE::NORMAL ),
51  static_cast<int>( MATERIAL_MODE::NORMAL ),
52  static_cast<int>( MATERIAL_MODE::CAD_MODE ) ) );
53 
54  m_params.emplace_back( new PARAM<int>( "render.opengl_AA_mode", &m_Render.opengl_AA_mode,
55  static_cast<int>( ANTIALIASING_MODE::AA_8X ),
56  static_cast<int>( ANTIALIASING_MODE::AA_NONE ),
57  static_cast<int>( ANTIALIASING_MODE::AA_8X ) ) );
58 
59  m_params.emplace_back( new PARAM<COLOR4D>( "render.opengl_selection_color",
61  COLOR4D( 0.0, 1.0, 0.0, 1.0 ) ) );
62 
63  // OpenGL options
64  m_params.emplace_back( new PARAM<bool>(
65  "render.opengl_copper_thickness", &m_Render.opengl_copper_thickness, true ) );
66  m_params.emplace_back( new PARAM<bool>(
67  "render.opengl_show_model_bbox", &m_Render.opengl_show_model_bbox, false ) );
68  m_params.emplace_back( new PARAM<bool>(
69  "render.opengl_AA_disableOnMove", &m_Render.opengl_AA_disableOnMove, false ) );
70  m_params.emplace_back( new PARAM<bool>(
71  "render.opengl_thickness_disableOnMove", &m_Render.opengl_thickness_disableOnMove, false ) );
72  m_params.emplace_back( new PARAM<bool>(
73  "render.opengl_vias_disableOnMove", &m_Render.opengl_vias_disableOnMove, false ) );
74  m_params.emplace_back( new PARAM<bool>(
75  "render.opengl_holes_disableOnMove", &m_Render.opengl_holes_disableOnMove, false ) );
76  m_params.emplace_back( new PARAM<bool>(
77  "render.opengl_render_bbox_only_OnMove", &m_Render.opengl_render_bbox_only_OnMove, false ) );
78 
79  // Raytracing options
80  m_params.emplace_back( new PARAM<bool>( "render.raytrace_anti_aliasing",
82  m_params.emplace_back( new PARAM<bool>( "render.raytrace_backfloor",
83  &m_Render.raytrace_backfloor, false ) );
84  m_params.emplace_back( new PARAM<bool>( "render.raytrace_post_processing",
86  m_params.emplace_back( new PARAM<bool>( "render.raytrace_procedural_textures",
88  m_params.emplace_back( new PARAM<bool>( "render.raytrace_reflections",
89  &m_Render.raytrace_reflections, true ) );
90  m_params.emplace_back( new PARAM<bool>( "render.raytrace_refractions",
91  &m_Render.raytrace_refractions, true ) );
92  m_params.emplace_back( new PARAM<bool>( "render.raytrace_shadows",
93  &m_Render.raytrace_shadows, true ) );
94 
95  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_shadows",
97  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_reflections",
99  m_params.emplace_back( new PARAM<int>( "render.raytrace_nrsamples_refractions",
101 
102  m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_reflections",
104  m_params.emplace_back( new PARAM<int>( "render.raytrace_recursivelevel_refractions",
106 
107  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_shadows",
108  &m_Render.raytrace_spread_shadows, 0.05f ) );
109  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_reflections",
111  m_params.emplace_back( new PARAM<float>( "render.raytrace_spread_refractions",
113 
114  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorCamera",
116  COLOR4D( 0.2, 0.2, 0.2, 1.0 ) ) );
117 
118  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorTop",
120  COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
121 
122  m_params.emplace_back( new PARAM<COLOR4D>( "render.raytrace_lightColorBottom",
124  COLOR4D( 0.247, 0.247, 0.247, 1.0 ) ) );
125 
126  std::vector<COLOR4D> default_colors =
127  {
128  COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
129  COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
130  COLOR4D( 0.168, 0.168, 0.168, 1.0 ),
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  };
137 
138  m_params.emplace_back( new PARAM_LIST<COLOR4D>( "render.raytrace_lightColor",
140  default_colors ) );
141 
142  const std::vector<int> default_elevation =
143  {
144  67, 67, 67, 67, -67, -67, -67, -67,
145  };
146 
147  m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightElevation",
149  default_elevation ) );
150 
151  const std::vector<int> default_azimuth =
152  {
153  45, 135, 225, 315, 45, 135, 225, 315,
154  };
155 
156  m_params.emplace_back( new PARAM_LIST<int>( "render.raytrace_lightAzimuth",
158  default_azimuth ) );
159 
160  m_params.emplace_back( new PARAM<bool>( "render.realistic", &m_Render.realistic, true ) );
161  m_params.emplace_back(
162  new PARAM<bool>( "render.show_adhesive", &m_Render.show_adhesive, true ) );
163  m_params.emplace_back( new PARAM<bool>( "render.show_axis", &m_Render.show_axis, true ) );
164  m_params.emplace_back(
165  new PARAM<bool>( "render.show_board_body", &m_Render.show_board_body, true ) );
166  m_params.emplace_back(
167  new PARAM<bool>( "render.show_comments", &m_Render.show_comments, true ) );
168  m_params.emplace_back( new PARAM<bool>( "render.show_eco", &m_Render.show_eco, true ) );
169  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_insert",
170  &m_Render.show_footprints_insert, true ) );
171  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_normal",
172  &m_Render.show_footprints_normal, true ) );
173  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_virtual",
175  m_params.emplace_back(
176  new PARAM<bool>( "render.show_silkscreen", &m_Render.show_silkscreen, true ) );
177  m_params.emplace_back(
178  new PARAM<bool>( "render.show_soldermask", &m_Render.show_soldermask, true ) );
179  m_params.emplace_back(
180  new PARAM<bool>( "render.show_solderpaste", &m_Render.show_solderpaste, true ) );
181  m_params.emplace_back( new PARAM<bool>( "render.show_zones", &m_Render.show_zones, true ) );
182  m_params.emplace_back( new PARAM<bool>( "render.subtract_mask_from_silk",
183  &m_Render.subtract_mask_from_silk, false ) );
184  m_params.emplace_back( new PARAM<bool>( "render.clip_silk_on_via_annulus",
186  m_params.emplace_back( new PARAM<bool>( "render.plated_and_bare_copper",
188  m_params.emplace_back( new PARAM<bool>( "camera.animation_enabled",
189  &m_Camera.animation_enabled, true ) );
190  m_params.emplace_back( new PARAM<int>( "camera.moving_speed_multiplier",
192  m_params.emplace_back( new PARAM<double>( "camera.rotation_increment",
193  &m_Camera.rotation_increment, 10.0 ) );
194 
195 }
196 
197 
199 {
200  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
201 
202  ret &= fromLegacy<int>( aCfg, "RenderEngine", "render.engine" );
203  ret &= fromLegacy<int>( aCfg, "ShowGrid3D", "render.grid_type" );
204  ret &= fromLegacy<int>( aCfg, "Render_Material", "render.material_mode" );
205  ret &= fromLegacy<bool>(
206  aCfg, "Render_OGL_ShowCopperThickness", "render.opengl_copper_thickness" );
207  ret &= fromLegacy<bool>(
208  aCfg, "Render_OGL_ShowModelBoudingBoxes", "render.opengl_show_model_bbox" );
209  ret &= fromLegacy<bool>( aCfg, "Render_RAY_AntiAliasing", "render.raytrace_anti_aliasing" );
210  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Backfloor", "render.raytrace_backfloor" );
211  ret &= fromLegacy<bool>( aCfg, "Render_RAY_PostProcess", "render.raytrace_post_processing" );
212  ret &= fromLegacy<bool>(
213  aCfg, "Render_RAY_ProceduralTextures", "render.raytrace_procedural_textures" );
214  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Reflections", "render.raytrace_reflections" );
215  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Refractions", "render.raytrace_refractions" );
216  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Shadows", "render.raytrace_shadows" );
217  ret &= fromLegacy<bool>( aCfg, "ShowRealisticMode", "render.realistic" );
218  ret &= fromLegacy<bool>( aCfg, "ShowAdhesiveLayers", "render.show_adhesive" );
219  ret &= fromLegacy<bool>( aCfg, "ShowAxis", "render.show_axis" );
220  ret &= fromLegacy<bool>( aCfg, "ShowBoardBody", "render.show_board_body" );
221  ret &= fromLegacy<bool>( aCfg, "ShowCommentsLayers", "render.show_comments" );
222  ret &= fromLegacy<bool>( aCfg, "ShowEcoLayers", "render.show_eco" );
223  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Insert", "render.show_footprints_insert" );
224  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Normal", "render.show_footprints_normal" );
225  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Virtual", "render.show_footprints_virtual" );
226  ret &= fromLegacy<bool>( aCfg, "ShowSilkScreenLayers", "render.show_silkscreen" );
227  ret &= fromLegacy<bool>( aCfg, "ShowSolderMasLayers", "render.show_soldermask" );
228  ret &= fromLegacy<bool>( aCfg, "ShowSolderPasteLayers", "render.show_solderpaste" );
229  ret &= fromLegacy<bool>( aCfg, "ShowZones", "render.show_zones" );
230  ret &= fromLegacy<bool>( aCfg, "SubtractMaskFromSilk", "render.subtract_mask_from_silk" );
231 
232  auto migrate_color =
233  [&] ( const std::string& k_r, const std::string& k_g,
234  const std::string &k_b, std::string dest, double alpha = 1.0 )
235  {
236  COLOR4D color( 1, 1, 1, alpha );
237 
238  if( aCfg->Read( k_r, &color.r ) &&
239  aCfg->Read( k_g, &color.g ) && aCfg->Read( k_b, &color.b ) )
240  {
241  ( *this )[PointerFromString( dest )] = color;
242  }
243  };
244 
245  migrate_color( "BgColor_Red", "BgColor_Green", "BgColor_Blue", "colors.background_bottom" );
246  migrate_color(
247  "BgColor_Red_Top", "BgColor_Green_Top", "BgColor_Blue_Top", "colors.background_top" );
248  migrate_color(
249  "BoardBodyColor_Red", "BoardBodyColor_Green", "BoardBodyColor_Blue", "colors.board" );
250  migrate_color( "CopperColor_Red", "CopperColor_Green", "CopperColor_Blue", "colors.copper" );
251  migrate_color(
252  "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_bottom" );
253  migrate_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_top" );
254  migrate_color( "SMaskColor_Red", "SMaskColor_Green", "SMaskColor_Blue", "colors.soldermask", 0.83 );
255  migrate_color(
256  "SPasteColor_Red", "SPasteColor_Green", "SPasteColor_Blue", "colors.solderpaste" );
257 
258  return ret;
259 }
Use a gray shading based on diffuse material.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
int color
Definition: DXF_plotter.cpp:60
const int viewer3dSchemaVersion
! Update the schema version whenever a migration is required
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
Use all material properties from model file.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
Declaration of the cogl_att_list class.
std::vector< KIGFX::COLOR4D > raytrace_lightColor
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100