From 9e6446a8dc759e9af704c4e47ddbc94ec32453e8 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 30 Dec 2021 23:02:38 +0000 Subject: [PATCH] Use enums for 3d Viewer settings instead of ints --- 3d-viewer/3d_enums.h | 30 ++++++++-------- .../3d_rendering/opengl/create_scene.cpp | 4 +-- 3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp | 2 +- .../3d_viewer/eda_3d_viewer_settings.cpp | 36 ++++++++++--------- 3d-viewer/3d_viewer/eda_3d_viewer_settings.h | 14 +++++--- 3d-viewer/common_ogl/ogl_attr_list.h | 9 ++--- .../dialogs/panel_3D_display_options.cpp | 7 ++-- 3d-viewer/dialogs/panel_3D_opengl_options.cpp | 7 ++-- 8 files changed, 58 insertions(+), 51 deletions(-) diff --git a/3d-viewer/3d_enums.h b/3d-viewer/3d_enums.h index f142e0675a..3de6935e85 100644 --- a/3d-viewer/3d_enums.h +++ b/3d-viewer/3d_enums.h @@ -41,39 +41,37 @@ enum class ROTATION_DIR Z_CCW }; - /// Camera types enum class CAMERA_TYPE { TRACKBALL }; +// Do not modify the following enum numbers, they are saved in the config file and used in the UI /// Grid types -enum GRID3D_TYPE +enum class GRID3D_TYPE { - NONE, - GRID_1MM, - GRID_2P5MM, - GRID_5MM, - GRID_10MM + NONE = 0, + GRID_1MM = 1, + GRID_2P5MM = 2, + GRID_5MM = 3, + GRID_10MM = 4 }; - /// Render engine mode -enum RENDER_ENGINE +enum class RENDER_ENGINE { - OPENGL, - RAYTRACING, + OPENGL = 0, + RAYTRACING = 1, }; - /// Render 3d model shape materials mode -enum MATERIAL_MODE +enum class MATERIAL_MODE { - NORMAL, ///< Use all material properties from model file - DIFFUSE_ONLY, ///< Use only diffuse material properties - CAD_MODE ///< Use a gray shading based on diffuse material + NORMAL = 0, ///< Use all material properties from model file + DIFFUSE_ONLY = 1, ///< Use only diffuse material properties + CAD_MODE = 2 ///< Use a gray shading based on diffuse material }; #endif // _3D_ENUMS_H_ diff --git a/3d-viewer/3d_rendering/opengl/create_scene.cpp b/3d-viewer/3d_rendering/opengl/create_scene.cpp index 45a04301f1..894e92fdbf 100644 --- a/3d-viewer/3d_rendering/opengl/create_scene.cpp +++ b/3d-viewer/3d_rendering/opengl/create_scene.cpp @@ -920,8 +920,8 @@ void RENDER_3D_OPENGL::load3dModels( REPORTER* aStatusReporter ) // only add it if the return is not NULL if( modelPtr ) { - int materialMode = m_boardAdapter.m_Cfg->m_Render.material_mode; - MODEL_3D* model = new MODEL_3D( *modelPtr, (MATERIAL_MODE) materialMode ); + MATERIAL_MODE materialMode = m_boardAdapter.m_Cfg->m_Render.material_mode; + MODEL_3D* model = new MODEL_3D( *modelPtr, materialMode ); m_3dModelMap[ fp_model.m_Filename ] = model; } diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index 86d1bea672..0d389e57ca 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -346,7 +346,7 @@ void EDA_3D_VIEWER_FRAME::Process_Special_Functions( wxCommandEvent &event ) void EDA_3D_VIEWER_FRAME::OnRenderEngineSelection( wxCommandEvent &event ) { - int old_engine = m_boardAdapter.m_Cfg->m_Render.engine; + RENDER_ENGINE old_engine = m_boardAdapter.m_Cfg->m_Render.engine; if( old_engine == RENDER_ENGINE::OPENGL ) m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::RAYTRACING; diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp index 1bd48b000a..23ecb08ae4 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp @@ -37,25 +37,27 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() m_Render(), m_Camera() { - m_params.emplace_back( new PARAM( "render.engine", &m_Render.engine, - static_cast( RENDER_ENGINE::OPENGL ), - static_cast( RENDER_ENGINE::OPENGL ), - static_cast( RENDER_ENGINE::RAYTRACING ) ) ); + m_params.emplace_back( new PARAM_ENUM( "render.engine", &m_Render.engine, + RENDER_ENGINE::OPENGL, + RENDER_ENGINE::OPENGL, + RENDER_ENGINE::RAYTRACING ) ); - m_params.emplace_back( new PARAM( "render.grid_type", &m_Render.grid_type, - static_cast( GRID3D_TYPE::NONE ), - static_cast( GRID3D_TYPE::NONE ), - static_cast( GRID3D_TYPE::GRID_10MM ) ) ); + m_params.emplace_back( new PARAM_ENUM( "render.grid_type", &m_Render.grid_type, + GRID3D_TYPE::NONE, + GRID3D_TYPE::NONE, + GRID3D_TYPE::GRID_10MM ) ); - m_params.emplace_back( new PARAM( "render.material_mode", &m_Render.material_mode, - static_cast( MATERIAL_MODE::NORMAL ), - static_cast( MATERIAL_MODE::NORMAL ), - static_cast( MATERIAL_MODE::CAD_MODE ) ) ); + m_params.emplace_back( new PARAM_ENUM( "render.material_mode", + &m_Render.material_mode, + MATERIAL_MODE::NORMAL, + MATERIAL_MODE::NORMAL, + MATERIAL_MODE::CAD_MODE ) ); - m_params.emplace_back( new PARAM( "render.opengl_AA_mode", &m_Render.opengl_AA_mode, - static_cast( ANTIALIASING_MODE::AA_8X ), - static_cast( ANTIALIASING_MODE::AA_NONE ), - static_cast( ANTIALIASING_MODE::AA_8X ) ) ); + m_params.emplace_back( new PARAM_ENUM( "render.opengl_AA_mode", + &m_Render.opengl_AA_mode, + ANTIALIASING_MODE::AA_8X, + ANTIALIASING_MODE::AA_NONE, + ANTIALIASING_MODE::AA_8X ) ); m_params.emplace_back( new PARAM( "render.opengl_selection_color", &m_Render.opengl_selection_color, @@ -86,7 +88,7 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() &m_Render.raytrace_backfloor, false ) ); m_params.emplace_back( new PARAM( "render.raytrace_post_processing", &m_Render.raytrace_post_processing, true ) ); - m_params.emplace_back( new PARAM( "render.raytrace_procedural_textures", + m_params.emplace_back( new PARAM( "render.raytrace_procedural_textures", &m_Render.raytrace_procedural_textures, true ) ); m_params.emplace_back( new PARAM( "render.raytrace_reflections", &m_Render.raytrace_reflections, true ) ); diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_settings.h b/3d-viewer/3d_viewer/eda_3d_viewer_settings.h index 455dc2da18..2a1a3fdc7b 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_settings.h +++ b/3d-viewer/3d_viewer/eda_3d_viewer_settings.h @@ -21,19 +21,23 @@ #ifndef EDA_3D_VIEWER_SETTINGS_H_ #define EDA_3D_VIEWER_SETTINGS_H_ +#include <3d_enums.h> +#include +#include #include #include -#include + class EDA_3D_VIEWER_SETTINGS : public APP_SETTINGS_BASE { public: struct RENDER_SETTINGS { - int engine; - int grid_type; - int opengl_AA_mode; - int material_mode; + RENDER_ENGINE engine; + GRID3D_TYPE grid_type; + ANTIALIASING_MODE opengl_AA_mode; + MATERIAL_MODE material_mode; + bool opengl_AA_disableOnMove; bool opengl_thickness_disableOnMove; bool opengl_vias_disableOnMove; diff --git a/3d-viewer/common_ogl/ogl_attr_list.h b/3d-viewer/common_ogl/ogl_attr_list.h index 696235bfe2..8c4a6bcb6c 100644 --- a/3d-viewer/common_ogl/ogl_attr_list.h +++ b/3d-viewer/common_ogl/ogl_attr_list.h @@ -33,10 +33,11 @@ /// Anti-aliasing options enum class ANTIALIASING_MODE { - AA_NONE, - AA_2X, - AA_4X, - AA_8X + // Do not change these numbers, they are stored in the config file + AA_NONE = 0, + AA_2X = 1, + AA_4X = 2, + AA_8X = 3 }; /** diff --git a/3d-viewer/dialogs/panel_3D_display_options.cpp b/3d-viewer/dialogs/panel_3D_display_options.cpp index e85e346333..9307b18f86 100644 --- a/3d-viewer/dialogs/panel_3D_display_options.cpp +++ b/3d-viewer/dialogs/panel_3D_display_options.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include <3d_enums.h> #include #include #include @@ -57,7 +58,7 @@ void PANEL_3D_DISPLAY_OPTIONS::loadViewSettings( EDA_3D_VIEWER_SETTINGS* aCfg ) m_checkBoxClipSilkOnViaAnnulus->SetValue( aCfg->m_Render.clip_silk_on_via_annulus ); m_checkBoxRenderPlatedPadsAsPlated->SetValue( aCfg->m_Render.renderPlatedPadsAsPlated ); - m_materialProperties->SetSelection( aCfg->m_Render.material_mode ); + m_materialProperties->SetSelection( static_cast( aCfg->m_Render.material_mode ) ); // Camera Options m_checkBoxEnableAnimation->SetValue( aCfg->m_Camera.animation_enabled ); @@ -92,7 +93,7 @@ bool PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow() cfg->m_Render.clip_silk_on_via_annulus = m_checkBoxClipSilkOnViaAnnulus->GetValue(); cfg->m_Render.renderPlatedPadsAsPlated = m_checkBoxRenderPlatedPadsAsPlated->GetValue(); - cfg->m_Render.material_mode = m_materialProperties->GetSelection(); + cfg->m_Render.material_mode = static_cast( m_materialProperties->GetSelection() ); // Set Layer visibility cfg->m_Render.show_silkscreen = m_checkBoxSilkscreen->GetValue(); @@ -117,4 +118,4 @@ void PANEL_3D_DISPLAY_OPTIONS::ResetPanel() cfg.Load(); // Loading without a file will init to defaults loadViewSettings( &cfg ); -} \ No newline at end of file +} diff --git a/3d-viewer/dialogs/panel_3D_opengl_options.cpp b/3d-viewer/dialogs/panel_3D_opengl_options.cpp index 7ed82885f3..fd7870bc4b 100644 --- a/3d-viewer/dialogs/panel_3D_opengl_options.cpp +++ b/3d-viewer/dialogs/panel_3D_opengl_options.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include <3d_enums.h> #include #include #include @@ -43,7 +44,7 @@ void PANEL_3D_OPENGL_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg ) m_checkBoxBoundingBoxes->SetValue( aCfg->m_Render.opengl_show_model_bbox ); m_checkBoxHighlightOnRollOver->SetValue( aCfg->m_Render.opengl_highlight_on_rollover ); - m_choiceAntiAliasing->SetSelection( aCfg->m_Render.opengl_AA_mode ); + m_choiceAntiAliasing->SetSelection( static_cast( aCfg->m_Render.opengl_AA_mode ) ); m_selectionColorSwatch->SetSwatchColor( aCfg->m_Render.opengl_selection_color, false ); m_checkBoxDisableAAMove->SetValue( aCfg->m_Render.opengl_AA_disableOnMove ); @@ -71,7 +72,7 @@ bool PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow() cfg->m_Render.opengl_show_model_bbox = m_checkBoxBoundingBoxes->GetValue(); cfg->m_Render.opengl_highlight_on_rollover = m_checkBoxHighlightOnRollOver->GetValue(); - cfg->m_Render.opengl_AA_mode = m_choiceAntiAliasing->GetSelection(); + cfg->m_Render.opengl_AA_mode = static_cast( m_choiceAntiAliasing->GetSelection() ); cfg->m_Render.opengl_selection_color = m_selectionColorSwatch->GetSwatchColor(); cfg->m_Render.opengl_AA_disableOnMove = m_checkBoxDisableAAMove->GetValue(); @@ -89,4 +90,4 @@ void PANEL_3D_OPENGL_OPTIONS::ResetPanel() cfg.Load(); // Loading without a file will init to defaults loadSettings( &cfg ); -} \ No newline at end of file +}