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  // OpenGL options
60  m_params.emplace_back( new PARAM<bool>(
61  "render.opengl_copper_thickness", &m_Render.opengl_copper_thickness, true ) );
62  m_params.emplace_back( new PARAM<bool>(
63  "render.opengl_show_model_bbox", &m_Render.opengl_show_model_bbox, false ) );
64  m_params.emplace_back( new PARAM<bool>(
65  "render.opengl_AA_disableOnMove", &m_Render.opengl_AA_disableOnMove, false ) );
66  m_params.emplace_back( new PARAM<bool>(
67  "render.opengl_thickness_disableOnMove", &m_Render.opengl_thickness_disableOnMove, false ) );
68  m_params.emplace_back( new PARAM<bool>(
69  "render.opengl_vias_disableOnMove", &m_Render.opengl_vias_disableOnMove, false ) );
70  m_params.emplace_back( new PARAM<bool>(
71  "render.opengl_holes_disableOnMove", &m_Render.opengl_holes_disableOnMove, false ) );
72  m_params.emplace_back( new PARAM<bool>(
73  "render.opengl_render_bbox_only_OnMove", &m_Render.opengl_render_bbox_only_OnMove, false ) );
74 
75  // Raytracing options
76  m_params.emplace_back( new PARAM<bool>( "render.raytrace_anti_aliasing",
78  m_params.emplace_back( new PARAM<bool>( "render.raytrace_backfloor",
79  &m_Render.raytrace_backfloor, false ) );
80  m_params.emplace_back( new PARAM<bool>( "render.raytrace_post_processing",
82  m_params.emplace_back( new PARAM<bool>( "render.raytrace_procedural_textures",
84  m_params.emplace_back( new PARAM<bool>( "render.raytrace_reflections",
85  &m_Render.raytrace_reflections, true ) );
86  m_params.emplace_back( new PARAM<bool>( "render.raytrace_refractions",
87  &m_Render.raytrace_refractions, true ) );
88  m_params.emplace_back( new PARAM<bool>( "render.raytrace_shadows",
89  &m_Render.raytrace_shadows, true ) );
90 
91  m_params.emplace_back( new PARAM<bool>( "render.realistic", &m_Render.realistic, true ) );
92  m_params.emplace_back(
93  new PARAM<bool>( "render.show_adhesive", &m_Render.show_adhesive, true ) );
94  m_params.emplace_back( new PARAM<bool>( "render.show_axis", &m_Render.show_axis, true ) );
95  m_params.emplace_back(
96  new PARAM<bool>( "render.show_board_body", &m_Render.show_board_body, true ) );
97  m_params.emplace_back(
98  new PARAM<bool>( "render.show_comments", &m_Render.show_comments, true ) );
99  m_params.emplace_back( new PARAM<bool>( "render.show_eco", &m_Render.show_eco, true ) );
100  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_insert",
101  &m_Render.show_footprints_insert, true ) );
102  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_normal",
103  &m_Render.show_footprints_normal, true ) );
104  m_params.emplace_back( new PARAM<bool>( "render.show_footprints_virtual",
106  m_params.emplace_back(
107  new PARAM<bool>( "render.show_silkscreen", &m_Render.show_silkscreen, true ) );
108  m_params.emplace_back(
109  new PARAM<bool>( "render.show_soldermask", &m_Render.show_soldermask, true ) );
110  m_params.emplace_back(
111  new PARAM<bool>( "render.show_solderpaste", &m_Render.show_solderpaste, true ) );
112  m_params.emplace_back( new PARAM<bool>( "render.show_zones", &m_Render.show_zones, true ) );
113  m_params.emplace_back( new PARAM<bool>( "render.subtract_mask_from_silk",
114  &m_Render.subtract_mask_from_silk, false ) );
115 
116  m_params.emplace_back( new PARAM<bool>( "camera.animation_enabled",
117  &m_Camera.animation_enabled, true ) );
118  m_params.emplace_back( new PARAM<int>( "camera.moving_speed_multiplier",
120  m_params.emplace_back( new PARAM<double>( "camera.rotation_increment",
121  &m_Camera.rotation_increment, 10.0 ) );
122 
123 }
124 
125 
127 {
128  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
129 
130  ret &= fromLegacy<int>( aCfg, "RenderEngine", "render.engine" );
131  ret &= fromLegacy<int>( aCfg, "ShowGrid3D", "render.grid_type" );
132  ret &= fromLegacy<int>( aCfg, "Render_Material", "render.material_mode" );
133  ret &= fromLegacy<bool>(
134  aCfg, "Render_OGL_ShowCopperThickness", "render.opengl_copper_thickness" );
135  ret &= fromLegacy<bool>(
136  aCfg, "Render_OGL_ShowModelBoudingBoxes", "render.opengl_show_model_bbox" );
137  ret &= fromLegacy<bool>( aCfg, "Render_RAY_AntiAliasing", "render.raytrace_anti_aliasing" );
138  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Backfloor", "render.raytrace_backfloor" );
139  ret &= fromLegacy<bool>( aCfg, "Render_RAY_PostProcess", "render.raytrace_post_processing" );
140  ret &= fromLegacy<bool>(
141  aCfg, "Render_RAY_ProceduralTextures", "render.raytrace_procedural_textures" );
142  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Reflections", "render.raytrace_reflections" );
143  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Refractions", "render.raytrace_refractions" );
144  ret &= fromLegacy<bool>( aCfg, "Render_RAY_Shadows", "render.raytrace_shadows" );
145  ret &= fromLegacy<bool>( aCfg, "ShowRealisticMode", "render.realistic" );
146  ret &= fromLegacy<bool>( aCfg, "ShowAdhesiveLayers", "render.show_adhesive" );
147  ret &= fromLegacy<bool>( aCfg, "ShowAxis", "render.show_axis" );
148  ret &= fromLegacy<bool>( aCfg, "ShowBoardBody", "render.show_board_body" );
149  ret &= fromLegacy<bool>( aCfg, "ShowCommentsLayers", "render.show_comments" );
150  ret &= fromLegacy<bool>( aCfg, "ShowEcoLayers", "render.show_eco" );
151  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Insert", "render.show_footprints_insert" );
152  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Normal", "render.show_footprints_normal" );
153  ret &= fromLegacy<bool>( aCfg, "ShowFootprints_Virtual", "render.show_footprints_virtual" );
154  ret &= fromLegacy<bool>( aCfg, "ShowSilkScreenLayers", "render.show_silkscreen" );
155  ret &= fromLegacy<bool>( aCfg, "ShowSolderMasLayers", "render.show_soldermask" );
156  ret &= fromLegacy<bool>( aCfg, "ShowSolderPasteLayers", "render.show_solderpaste" );
157  ret &= fromLegacy<bool>( aCfg, "ShowZones", "render.show_zones" );
158  ret &= fromLegacy<bool>( aCfg, "SubtractMaskFromSilk", "render.subtract_mask_from_silk" );
159 
160  auto migrate_color =
161  [&] ( const std::string& k_r, const std::string& k_g,
162  const std::string &k_b, std::string dest )
163  {
164  COLOR4D color( 1, 1, 1, 1 );
165 
166  if( aCfg->Read( k_r, &color.r ) &&
167  aCfg->Read( k_g, &color.g ) && aCfg->Read( k_b, &color.b ) )
168  {
169  ( *this )[PointerFromString( dest )] = color;
170  }
171  };
172 
173  migrate_color( "BgColor_Red", "BgColor_Green", "BgColor_Blue", "colors.background_bottom" );
174  migrate_color(
175  "BgColor_Red_Top", "BgColor_Green_Top", "BgColor_Blue_Top", "colors.background_top" );
176  migrate_color(
177  "BoardBodyColor_Red", "BoardBodyColor_Green", "BoardBodyColor_Blue", "colors.board" );
178  migrate_color( "CopperColor_Red", "CopperColor_Green", "CopperColor_Blue", "colors.copper" );
179  migrate_color(
180  "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_bottom" );
181  migrate_color( "SilkColor_Red", "SilkColor_Green", "SilkColor_Blue", "colors.silkscreen_top" );
182  migrate_color( "SMaskColor_Red", "SMaskColor_Green", "SMaskColor_Blue", "colors.soldermask" );
183  migrate_color(
184  "SPasteColor_Red", "SPasteColor_Green", "SPasteColor_Blue", "colors.solderpaste" );
185 
186  return ret;
187 }
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:61
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:91
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.
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:99