From ba36fc0009193dfec4d3889320d416d8ffcc79b8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 25 Mar 2020 13:13:03 +0000 Subject: [PATCH] Fix some Coverity issues. --- 3d-viewer/3d_canvas/3d_settings.cpp | 14 +- 3d-viewer/3d_canvas/3d_settings.h | 6 +- 3d-viewer/3d_viewer/3d_viewer_settings.cpp | 4 +- 3d-viewer/3d_viewer/3d_viewer_settings.h | 43 ----- 3d-viewer/3d_viewer/eda_3d_viewer.cpp | 150 +++++++++--------- 3d-viewer/3d_viewer/tools/3d_controller.cpp | 12 +- eeschema/dialogs/dialog_choose_component.cpp | 34 ++-- eeschema/dialogs/dialog_netlist.cpp | 34 ++-- eeschema/eeschema_config.cpp | 135 ++++++++-------- eeschema/tools/backannotate.cpp | 16 +- .../dialogs/panel_pcbnew_action_plugins.cpp | 36 ++--- pcbnew/footprint_wizard_frame.cpp | 17 +- 12 files changed, 246 insertions(+), 255 deletions(-) diff --git a/3d-viewer/3d_canvas/3d_settings.cpp b/3d-viewer/3d_canvas/3d_settings.cpp index ae466ef0a7..78e0a15274 100644 --- a/3d-viewer/3d_canvas/3d_settings.cpp +++ b/3d-viewer/3d_canvas/3d_settings.cpp @@ -51,13 +51,16 @@ EDA_3D_SETTINGS G_null_EDA_3D_SETTINGS; EDA_3D_SETTINGS::EDA_3D_SETTINGS() : - m_currentCamera( m_trackBallCamera ), - m_trackBallCamera( RANGE_SCALE_3D ) + m_board( nullptr ), + m_3d_model_manager( nullptr ), + m_colors( nullptr ), + m_layerZcoordTop(), + m_layerZcoordBottom(), + m_currentCamera( m_trackBallCamera ), + m_trackBallCamera( RANGE_SCALE_3D ) { wxLogTrace( m_logTrace, wxT( "EDA_3D_SETTINGS::EDA_3D_SETTINGS" ) ); - m_board = NULL; - m_3d_model_manager = NULL; m_3D_grid_type = GRID3D_TYPE::NONE; m_drawFlags.resize( FL_LAST, false ); @@ -92,9 +95,6 @@ EDA_3D_SETTINGS::EDA_3D_SETTINGS() : m_calc_seg_min_factor3DU = 0.0f; m_calc_seg_max_factor3DU = 0.0f; - memset( m_layerZcoordTop, 0, sizeof( m_layerZcoordTop ) ); - memset( m_layerZcoordBottom, 0, sizeof( m_layerZcoordBottom ) ); - SetFlag( FL_USE_REALISTIC_MODE, true ); SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, true ); SetFlag( FL_SHOW_BOARD_BODY, true ); diff --git a/3d-viewer/3d_canvas/3d_settings.h b/3d-viewer/3d_canvas/3d_settings.h index a5601f412b..a464360d5a 100644 --- a/3d-viewer/3d_canvas/3d_settings.h +++ b/3d-viewer/3d_canvas/3d_settings.h @@ -25,6 +25,7 @@ #ifndef EDA_3D_SETTINGS_H #define EDA_3D_SETTINGS_H +#include #include #include "../3d_rendering/3d_render_raytracing/accelerators/ccontainer2d.h" #include "../3d_rendering/3d_render_raytracing/accelerators/ccontainer.h" @@ -46,7 +47,6 @@ #include #include - class COLOR_SETTINGS; /// A type that stores a container of 2d objects for each layer id @@ -621,10 +621,10 @@ private: double m_biuTo3Dunits; /// Top (End) Z position of each layer (normalized) - float m_layerZcoordTop[PCB_LAYER_ID_COUNT]; + std::array m_layerZcoordTop; /// Bottom (Start) Z position of each layer (normalized) - float m_layerZcoordBottom[PCB_LAYER_ID_COUNT]; + std::array m_layerZcoordBottom; /// Copper thickness (normalized) float m_copperThickness3DU; diff --git a/3d-viewer/3d_viewer/3d_viewer_settings.cpp b/3d-viewer/3d_viewer/3d_viewer_settings.cpp index 739a163564..f50d9a26da 100644 --- a/3d-viewer/3d_viewer/3d_viewer_settings.cpp +++ b/3d-viewer/3d_viewer/3d_viewer_settings.cpp @@ -19,13 +19,13 @@ */ #include <3d_enums.h> -#include #include -#include #include #include "3d_viewer_settings.h" +using KIGFX::COLOR4D; + ///! Update the schema version whenever a migration is required const int viewer3dSchemaVersion = 0; diff --git a/3d-viewer/3d_viewer/3d_viewer_settings.h b/3d-viewer/3d_viewer/3d_viewer_settings.h index 5f99bf0e16..de87b2eec3 100644 --- a/3d-viewer/3d_viewer/3d_viewer_settings.h +++ b/3d-viewer/3d_viewer/3d_viewer_settings.h @@ -72,47 +72,4 @@ protected: }; -// Individual color param: not necessary once 3D viewer is migrated to color theme system -// TODO(JE) remove once irrelevant -class PARAM_COLOR : public PARAM_BASE -{ -public: - PARAM_COLOR( const std::string& aJsonPath, COLOR4D* aPtr, COLOR4D aDefault, - bool aReadOnly = false ) : - PARAM_BASE( aJsonPath, aReadOnly ), m_ptr( aPtr ), m_default( aDefault ) - {} - - void Load( JSON_SETTINGS* aSettings ) const override - { - if( m_readOnly ) - return; - - COLOR4D val = m_default; - - if( OPT optval = aSettings->Get( m_path ) ) - val = *optval; - - *m_ptr = val; - } - - void Store( JSON_SETTINGS* aSettings) const override - { - aSettings->Set( m_path, *m_ptr ); - } - - COLOR4D GetDefault() const - { - return m_default; - } - - virtual void SetDefault() override - { - *m_ptr = m_default; - } - -private: - COLOR4D* m_ptr; - COLOR4D m_default; -}; - #endif diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index d8770e4147..316e145e0e 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -376,7 +376,7 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg ) { EDA_BASE_FRAME::LoadSettings( aCfg ); - auto cfg = dynamic_cast( aCfg ); + EDA_3D_VIEWER_SETTINGS* cfg = dynamic_cast( aCfg ); wxASSERT( cfg ); wxLogTrace( m_logTrace, "EDA_3D_VIEWER::LoadSettings" ); @@ -400,55 +400,51 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg ) set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_settings.m_SolderMaskColorTop ); set_color( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_settings.m_SolderPasteColor ); - m_settings.SetFlag( FL_USE_REALISTIC_MODE, cfg->m_Render.realistic ); + if( cfg ) + { +#define TRANSER_SETTING( flag, field ) m_settings.SetFlag( flag, cfg->m_Render.field ) - m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, cfg->m_Render.subtract_mask_from_silk ); + TRANSER_SETTING( FL_USE_REALISTIC_MODE, realistic ); + TRANSER_SETTING( FL_SUBTRACT_MASK_FROM_SILK, subtract_mask_from_silk ); - // OpenGL options - m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, cfg->m_Render.opengl_copper_thickness ); + // OpenGL options + TRANSER_SETTING( FL_RENDER_OPENGL_COPPER_THICKNESS, opengl_copper_thickness ); + TRANSER_SETTING( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, opengl_show_model_bbox ); - m_settings.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, cfg->m_Render.opengl_show_model_bbox ); + // Raytracing options + TRANSER_SETTING( FL_RENDER_RAYTRACING_SHADOWS, raytrace_shadows ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_BACKFLOOR, raytrace_backfloor ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_REFRACTIONS, raytrace_refractions ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_REFLECTIONS, raytrace_reflections ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_POST_PROCESSING, raytrace_post_processing ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_ANTI_ALIASING, raytrace_anti_aliasing ); + TRANSER_SETTING( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, raytrace_procedural_textures ); - // Raytracing options - m_settings.SetFlag( FL_RENDER_RAYTRACING_SHADOWS, cfg->m_Render.raytrace_shadows ); + TRANSER_SETTING( FL_AXIS, show_axis ); + TRANSER_SETTING( FL_MODULE_ATTRIBUTES_NORMAL, show_footprints_normal ); + TRANSER_SETTING( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, show_footprints_insert ); + TRANSER_SETTING( FL_MODULE_ATTRIBUTES_VIRTUAL, show_footprints_virtual ); + TRANSER_SETTING( FL_ZONE, show_zones ); + TRANSER_SETTING( FL_ADHESIVE, show_adhesive ); + TRANSER_SETTING( FL_SILKSCREEN, show_silkscreen ); + TRANSER_SETTING( FL_SOLDERMASK, show_soldermask ); + TRANSER_SETTING( FL_SOLDERPASTE, show_solderpaste ); + TRANSER_SETTING( FL_COMMENTS, show_comments ); + TRANSER_SETTING( FL_ECO, show_eco ); + TRANSER_SETTING( FL_SHOW_BOARD_BODY, show_board_body ); - m_settings.SetFlag( FL_RENDER_RAYTRACING_BACKFLOOR, cfg->m_Render.raytrace_backfloor ); + m_settings.GridSet( static_cast( cfg->m_Render.grid_type ) ); - m_settings.SetFlag( FL_RENDER_RAYTRACING_REFRACTIONS, cfg->m_Render.raytrace_refractions ); + RENDER_ENGINE engine = static_cast( cfg->m_Render.engine ); + wxLogTrace( m_logTrace, engine == RENDER_ENGINE::RAYTRACING ? + "EDA_3D_VIEWER::LoadSettings render setting Ray Trace" : + "EDA_3D_VIEWER::LoadSettings render setting OpenGL" ); + m_settings.RenderEngineSet( engine ); - m_settings.SetFlag( FL_RENDER_RAYTRACING_REFLECTIONS, cfg->m_Render.raytrace_reflections ); + m_settings.MaterialModeSet( static_cast( cfg->m_Render.material_mode ) ); - m_settings.SetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING, - cfg->m_Render.raytrace_post_processing ); - - m_settings.SetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING, cfg->m_Render.raytrace_anti_aliasing ); - - m_settings.SetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, - cfg->m_Render.raytrace_procedural_textures ); - - m_settings.SetFlag( FL_AXIS, cfg->m_Render.show_axis ); - - m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, cfg->m_Render.show_footprints_normal ); - m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, cfg->m_Render.show_footprints_insert ); - m_settings.SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, cfg->m_Render.show_footprints_virtual ); - - m_settings.SetFlag( FL_ZONE, cfg->m_Render.show_zones ); - m_settings.SetFlag( FL_ADHESIVE, cfg->m_Render.show_adhesive ); - m_settings.SetFlag( FL_SILKSCREEN, cfg->m_Render.show_silkscreen ); - m_settings.SetFlag( FL_SOLDERMASK, cfg->m_Render.show_soldermask ); - m_settings.SetFlag( FL_SOLDERPASTE, cfg->m_Render.show_solderpaste ); - m_settings.SetFlag( FL_COMMENTS, cfg->m_Render.show_comments ); - m_settings.SetFlag( FL_ECO, cfg->m_Render.show_eco ); - m_settings.SetFlag( FL_SHOW_BOARD_BODY, cfg->m_Render.show_board_body ); - - m_settings.GridSet( static_cast( cfg->m_Render.grid_type ) ); - - RENDER_ENGINE engine = static_cast( cfg->m_Render.engine ); - wxLogTrace( m_logTrace, "EDA_3D_VIEWER::LoadSettings render setting %s", - ( engine == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" : "OpenGL" ); - m_settings.RenderEngineSet( engine ); - - m_settings.MaterialModeSet( static_cast( cfg->m_Render.material_mode ) ); +#undef TRANSFER_SETTING + } } @@ -476,43 +472,49 @@ void EDA_3D_VIEWER::SaveSettings( APP_SETTINGS_BASE *aCfg ) save_color( m_settings.m_SolderMaskColorTop, LAYER_3D_SOLDERMASK ); save_color( m_settings.m_SolderPasteColor, LAYER_3D_SOLDERPASTE ); - wxLogTrace( m_logTrace, "EDA_3D_VIEWER::SaveSettings render setting %s", - ( m_settings.RenderEngineGet() == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" : - "OpenGL" ); + wxLogTrace( m_logTrace, m_settings.RenderEngineGet() == RENDER_ENGINE::RAYTRACING ? + "EDA_3D_VIEWER::SaveSettings render setting Ray Trace" : + "EDA_3D_VIEWER::SaveSettings render setting OpenGL" ); - cfg->m_Render.engine = static_cast( m_settings.RenderEngineGet() ); - cfg->m_Render.grid_type = static_cast( m_settings.GridGet() ); - cfg->m_Render.material_mode = static_cast( m_settings.MaterialModeGet() ); + if( cfg ) + { +#define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_settings.GetFlag( flag ) - cfg->m_Render.opengl_copper_thickness = m_settings.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ); - cfg->m_Render.opengl_show_model_bbox = m_settings.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ); - cfg->m_Render.raytrace_anti_aliasing = m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ); - cfg->m_Render.raytrace_backfloor = m_settings.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR ); - cfg->m_Render.raytrace_post_processing = - m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ); - cfg->m_Render.raytrace_procedural_textures = - m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ); - cfg->m_Render.raytrace_reflections = m_settings.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS ); - cfg->m_Render.raytrace_refractions = m_settings.GetFlag( FL_RENDER_RAYTRACING_REFRACTIONS ); - cfg->m_Render.raytrace_shadows = m_settings.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ); - cfg->m_Render.realistic = m_settings.GetFlag( FL_USE_REALISTIC_MODE ); - cfg->m_Render.show_adhesive = m_settings.GetFlag( FL_ADHESIVE ); - cfg->m_Render.show_axis = m_settings.GetFlag( FL_AXIS ); - cfg->m_Render.show_board_body = m_settings.GetFlag( FL_SHOW_BOARD_BODY ); - cfg->m_Render.show_comments = m_settings.GetFlag( FL_COMMENTS ); - cfg->m_Render.show_eco = m_settings.GetFlag( FL_ECO ); - cfg->m_Render.show_footprints_insert = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ); - cfg->m_Render.show_footprints_normal = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ); - cfg->m_Render.show_footprints_virtual = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL ); - cfg->m_Render.show_silkscreen = m_settings.GetFlag( FL_SILKSCREEN ); - cfg->m_Render.show_soldermask = m_settings.GetFlag( FL_SOLDERMASK ); - cfg->m_Render.show_solderpaste = m_settings.GetFlag( FL_SOLDERPASTE ); - cfg->m_Render.show_zones = m_settings.GetFlag( FL_ZONE ); - cfg->m_Render.subtract_mask_from_silk = m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ); + cfg->m_Render.engine = static_cast( m_settings.RenderEngineGet() ); + cfg->m_Render.grid_type = static_cast( m_settings.GridGet() ); + cfg->m_Render.material_mode = static_cast( m_settings.MaterialModeGet() ); + + TRANSFER_SETTING( opengl_copper_thickness, FL_RENDER_OPENGL_COPPER_THICKNESS ); + TRANSFER_SETTING( opengl_show_model_bbox, FL_RENDER_OPENGL_SHOW_MODEL_BBOX ); + TRANSFER_SETTING( raytrace_anti_aliasing, FL_RENDER_RAYTRACING_ANTI_ALIASING ); + TRANSFER_SETTING( raytrace_backfloor, FL_RENDER_RAYTRACING_BACKFLOOR ); + TRANSFER_SETTING( raytrace_post_processing, FL_RENDER_RAYTRACING_POST_PROCESSING ); + TRANSFER_SETTING( raytrace_procedural_textures, FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ); + TRANSFER_SETTING( raytrace_reflections, FL_RENDER_RAYTRACING_REFLECTIONS ); + TRANSFER_SETTING( raytrace_refractions, FL_RENDER_RAYTRACING_REFRACTIONS ); + TRANSFER_SETTING( raytrace_shadows, FL_RENDER_RAYTRACING_SHADOWS ); + + TRANSFER_SETTING( realistic, FL_USE_REALISTIC_MODE ); + TRANSFER_SETTING( show_adhesive, FL_ADHESIVE ); + TRANSFER_SETTING( show_axis, FL_AXIS ); + TRANSFER_SETTING( show_board_body, FL_SHOW_BOARD_BODY ); + TRANSFER_SETTING( show_comments, FL_COMMENTS ); + TRANSFER_SETTING( show_eco, FL_ECO ); + TRANSFER_SETTING( show_footprints_insert, FL_MODULE_ATTRIBUTES_NORMAL_INSERT ); + TRANSFER_SETTING( show_footprints_normal, FL_MODULE_ATTRIBUTES_NORMAL ); + TRANSFER_SETTING( show_footprints_virtual, FL_MODULE_ATTRIBUTES_VIRTUAL ); + TRANSFER_SETTING( show_silkscreen, FL_SILKSCREEN ); + TRANSFER_SETTING( show_soldermask, FL_SOLDERMASK ); + TRANSFER_SETTING( show_solderpaste, FL_SOLDERPASTE ); + TRANSFER_SETTING( show_zones, FL_ZONE ); + TRANSFER_SETTING( subtract_mask_from_silk, FL_SUBTRACT_MASK_FROM_SILK ); + +#undef TRANSER_SETTING + } } -void EDA_3D_VIEWER::SynchroniseColoursWithBoard( void ) +void EDA_3D_VIEWER::SynchroniseColoursWithBoard() { BOARD* brd = GetBoard(); const FAB_LAYER_COLOR* stdColors = GetColorStandardList(); diff --git a/3d-viewer/3d_viewer/tools/3d_controller.cpp b/3d-viewer/3d_viewer/tools/3d_controller.cpp index 29b5dd67fd..9c6b8a6280 100644 --- a/3d-viewer/3d_viewer/tools/3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/3d_controller.cpp @@ -65,8 +65,16 @@ void EDA_3D_CONTROLLER::Reset( RESET_REASON aReason ) { TOOLS_HOLDER* holder = m_toolMgr->GetToolHolder(); - m_canvas = dynamic_cast( holder->GetToolCanvas() ); - m_settings = dynamic_cast( holder )->GetSettings(); + if( holder ) + { + m_canvas = dynamic_cast( holder->GetToolCanvas() ); + m_settings = dynamic_cast( holder )->GetSettings(); + } + else + { + m_canvas = nullptr; + m_settings = nullptr; + } } diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 14385b7240..d45616b2c5 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -147,22 +147,26 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const Layout(); - auto cfg = dynamic_cast( Kiface().KifaceSettings() ); + EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); + wxASSERT( cfg ); - // We specify the width of the right window (m_symbol_view_panel), because specify - // the width of the left window does not work as expected when SetSashGravity() is called - m_hsplitter->SetSashPosition( cfg->m_SymChooserPanel.sash_pos_h > 0 ? - cfg->m_SymChooserPanel.sash_pos_h : HorizPixelsFromDU( 220 ) ); + if( cfg ) + { + EESCHEMA_SETTINGS::PANEL_SYM_CHOOSER& panelCfg = cfg->m_SymChooserPanel; - if( m_vsplitter ) - m_vsplitter->SetSashPosition( cfg->m_SymChooserPanel.sash_pos_v > 0 ? - cfg->m_SymChooserPanel.sash_pos_v : VertPixelsFromDU( 230 ) ); + // We specify the width of the right window (m_symbol_view_panel), because specify + // the width of the left window does not work as expected when SetSashGravity() is called + m_hsplitter->SetSashPosition( panelCfg.sash_pos_h > 0 ? panelCfg.sash_pos_h : + HorizPixelsFromDU( 220 ) ); - wxSize dlgSize( cfg->m_SymChooserPanel.width > 0 ? - cfg->m_SymChooserPanel.width : HorizPixelsFromDU( 390 ), - cfg->m_SymChooserPanel.height > 0 ? - cfg->m_SymChooserPanel.height : VertPixelsFromDU( 300 ) ); - SetSize( dlgSize ); + if( m_vsplitter ) + m_vsplitter->SetSashPosition( panelCfg.sash_pos_v > 0 ? panelCfg.sash_pos_v : + VertPixelsFromDU( 230 ) ); + + wxSize dlgSize( panelCfg.width > 0 ? panelCfg.width : HorizPixelsFromDU( 390 ), + panelCfg.height > 0 ? panelCfg.height : VertPixelsFromDU( 300 ) ); + SetSize( dlgSize ); + } SetInitialFocus( m_tree ); okButton->SetDefault(); @@ -183,7 +187,7 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const if( m_details ) m_details->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT::OnCharHook ), - NULL, this ); + NULL, this ); } @@ -205,7 +209,7 @@ DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT() if( m_details ) m_details->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_CHOOSE_COMPONENT::OnCharHook ), - NULL, this ); + NULL, this ); // I am not sure the following two lines are necessary, but they will not hurt anyone m_dbl_click_timer->Stop(); diff --git a/eeschema/dialogs/dialog_netlist.cpp b/eeschema/dialogs/dialog_netlist.cpp index 13580f74ad..3a45c01ff4 100644 --- a/eeschema/dialogs/dialog_netlist.cpp +++ b/eeschema/dialogs/dialog_netlist.cpp @@ -555,27 +555,31 @@ void NETLIST_DIALOG::WriteCurrentNetlistSetup() NetlistUpdateOpt(); - auto cfg = dynamic_cast( Kiface().KifaceSettings() ); + EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); + wxASSERT( cfg ); - cfg->m_NetlistPanel.custom_command_titles.clear(); - cfg->m_NetlistPanel.custom_command_paths.clear(); - - // Update existing custom pages - for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ ) + if( cfg ) { - NETLIST_PAGE_DIALOG* currPage = m_PanelNetType[ii + PANELCUSTOMBASE]; + cfg->m_NetlistPanel.custom_command_titles.clear(); + cfg->m_NetlistPanel.custom_command_paths.clear(); - if( currPage == NULL ) - break; + // Update existing custom pages + for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ ) + { + NETLIST_PAGE_DIALOG* currPage = m_PanelNetType[ii + PANELCUSTOMBASE]; - wxString title = currPage->m_TitleStringCtrl->GetValue(); + if( currPage == NULL ) + break; - if( title.IsEmpty() ) - continue; + wxString title = currPage->m_TitleStringCtrl->GetValue(); - cfg->m_NetlistPanel.custom_command_titles.push_back( title.ToStdString() ); - cfg->m_NetlistPanel.custom_command_paths.push_back( - currPage->m_CommandStringCtrl->GetValue().ToStdString() ); + if( title.IsEmpty() ) + continue; + + cfg->m_NetlistPanel.custom_command_titles.emplace_back( title.ToStdString() ); + cfg->m_NetlistPanel.custom_command_paths.emplace_back( + currPage->m_CommandStringCtrl->GetValue().ToStdString() ); + } } } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index c32a00314b..99f1308819 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -497,41 +497,45 @@ void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); - auto cfg = dynamic_cast( aCfg ); + EESCHEMA_SETTINGS* cfg = dynamic_cast( aCfg ); + wxASSERT( cfg ); - m_repeatStep.x = Mils2iu( cfg->m_Drawing.default_repeat_offset_x ); - m_repeatStep.y = Mils2iu( cfg->m_Drawing.default_repeat_offset_y ); - - SetSelectionTextAsBox( cfg->m_Selection.text_as_box ); - SetSelectionDrawChildItems( cfg->m_Selection.draw_selected_children ); - SetSelectionFillShapes( cfg->m_Selection.fill_shapes ); - SetSelectionThickness( Mils2iu( cfg->m_Selection.thickness ) ); - - m_footprintPreview = cfg->m_Appearance.footprint_preview; - m_navigatorStaysOpen = cfg->m_Appearance.navigator_stays_open; - m_showAllPins = cfg->m_Appearance.show_hidden_pins; - m_autoplaceFields = cfg->m_AutoplaceFields.enable; - m_autoplaceAlign = cfg->m_AutoplaceFields.align_to_grid; - m_autoplaceJustify = cfg->m_AutoplaceFields.allow_rejustify; - m_forceHVLines = cfg->m_Drawing.hv_lines_only; - m_dragActionIsMove = cfg->m_Input.drag_is_move; - m_selectPinSelectSymbol = cfg->m_Selection.select_pin_selects_symbol; - m_repeatDeltaLabel = cfg->m_Drawing.repeat_label_increment; - - wxString templateFieldNames = cfg->m_Drawing.field_names; - - if( !templateFieldNames.IsEmpty() ) + if( cfg ) { - TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); + m_repeatStep.x = Mils2iu( cfg->m_Drawing.default_repeat_offset_x ); + m_repeatStep.y = Mils2iu( cfg->m_Drawing.default_repeat_offset_y ); - try + SetSelectionTextAsBox( cfg->m_Selection.text_as_box ); + SetSelectionDrawChildItems( cfg->m_Selection.draw_selected_children ); + SetSelectionFillShapes( cfg->m_Selection.fill_shapes ); + SetSelectionThickness( Mils2iu( cfg->m_Selection.thickness ) ); + + m_footprintPreview = cfg->m_Appearance.footprint_preview; + m_navigatorStaysOpen = cfg->m_Appearance.navigator_stays_open; + m_showAllPins = cfg->m_Appearance.show_hidden_pins; + m_autoplaceFields = cfg->m_AutoplaceFields.enable; + m_autoplaceAlign = cfg->m_AutoplaceFields.align_to_grid; + m_autoplaceJustify = cfg->m_AutoplaceFields.allow_rejustify; + m_forceHVLines = cfg->m_Drawing.hv_lines_only; + m_dragActionIsMove = cfg->m_Input.drag_is_move; + m_selectPinSelectSymbol = cfg->m_Selection.select_pin_selects_symbol; + m_repeatDeltaLabel = cfg->m_Drawing.repeat_label_increment; + + wxString templateFieldNames = cfg->m_Drawing.field_names; + + if( !templateFieldNames.IsEmpty() ) { - m_templateFieldNames.Parse( &lexer, true ); - } - catch( const IO_ERROR& DBG( e ) ) - { - // @todo show error msg - DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) + TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); + + try + { + m_templateFieldNames.Parse( &lexer, true ); + } + catch( const IO_ERROR& DBG( e ) ) + { + // @todo show error msg + DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) + } } } @@ -548,51 +552,54 @@ void SCH_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::SaveSettings( aCfg ); - auto cfg = dynamic_cast( aCfg ); + EESCHEMA_SETTINGS* cfg = dynamic_cast( aCfg ); + wxASSERT( cfg ); // TODO(JE) do most of these need to live as class members here, or can the sites that need // the setting just grab a pointer to the EESCHEMA_SETTINGS and look them up directly? + if( cfg ) + { + cfg->m_Appearance.footprint_preview = m_footprintPreview; + cfg->m_Appearance.navigator_stays_open = m_navigatorStaysOpen; + cfg->m_Appearance.print_sheet_reference = m_printSheetReference; + cfg->m_Appearance.show_hidden_pins = m_showAllPins; + cfg->m_Appearance.show_illegal_symbol_lib_dialog = m_showIllegalSymbolLibDialog; + cfg->m_Appearance.show_page_limits = m_showPageLimits; + cfg->m_Appearance.show_sheet_filename_case_sensitivity_dialog = + m_showSheetFileNameCaseSensitivityDlg; - cfg->m_Appearance.footprint_preview = m_footprintPreview; - cfg->m_Appearance.navigator_stays_open = m_navigatorStaysOpen; - cfg->m_Appearance.print_sheet_reference = m_printSheetReference; - cfg->m_Appearance.show_hidden_pins = m_showAllPins; - cfg->m_Appearance.show_illegal_symbol_lib_dialog = m_showIllegalSymbolLibDialog; - cfg->m_Appearance.show_page_limits = m_showPageLimits; - cfg->m_Appearance.show_sheet_filename_case_sensitivity_dialog = - m_showSheetFileNameCaseSensitivityDlg; + cfg->m_AutoplaceFields.enable = m_autoplaceFields; + cfg->m_AutoplaceFields.allow_rejustify = m_autoplaceJustify; + cfg->m_AutoplaceFields.align_to_grid = m_autoplaceAlign; - cfg->m_AutoplaceFields.enable = m_autoplaceFields; - cfg->m_AutoplaceFields.allow_rejustify = m_autoplaceJustify; - cfg->m_AutoplaceFields.align_to_grid = m_autoplaceAlign; + cfg->m_Drawing.default_repeat_offset_x = Iu2Mils( m_repeatStep.x ); + cfg->m_Drawing.default_repeat_offset_y = Iu2Mils( m_repeatStep.y ); + cfg->m_Drawing.hv_lines_only = GetForceHVLines(); + cfg->m_Drawing.repeat_label_increment = m_repeatDeltaLabel; + cfg->m_Drawing.text_markup_flags = GetTextMarkupFlags(); - cfg->m_Drawing.default_repeat_offset_x = Iu2Mils( m_repeatStep.x ); - cfg->m_Drawing.default_repeat_offset_y = Iu2Mils( m_repeatStep.y ); - cfg->m_Drawing.hv_lines_only = GetForceHVLines(); - cfg->m_Drawing.repeat_label_increment = m_repeatDeltaLabel; - cfg->m_Drawing.text_markup_flags = GetTextMarkupFlags(); + cfg->m_Input.drag_is_move = m_dragActionIsMove; - cfg->m_Input.drag_is_move = m_dragActionIsMove; + cfg->m_Printing.monochrome = m_printMonochrome; - cfg->m_Printing.monochrome = m_printMonochrome; + cfg->m_Selection.thickness = Iu2Mils( GetSelectionThickness() ); + cfg->m_Selection.draw_selected_children = GetSelectionDrawChildItems(); + cfg->m_Selection.fill_shapes = GetSelectionFillShapes(); + cfg->m_Selection.select_pin_selects_symbol = GetSelectPinSelectSymbol(); + cfg->m_Selection.text_as_box = GetSelectionTextAsBox(); - cfg->m_Selection.thickness = Iu2Mils( GetSelectionThickness() ); - cfg->m_Selection.draw_selected_children = GetSelectionDrawChildItems(); - cfg->m_Selection.fill_shapes = GetSelectionFillShapes(); - cfg->m_Selection.select_pin_selects_symbol = GetSelectPinSelectSymbol(); - cfg->m_Selection.text_as_box = GetSelectionTextAsBox(); + cfg->m_System.units = static_cast( m_userUnits ); - cfg->m_System.units = static_cast( m_userUnits ); + // Save template fieldnames + STRING_FORMATTER sf; + m_templateFieldNames.Format( &sf, 0, true ); - // Save template fieldnames - STRING_FORMATTER sf; - m_templateFieldNames.Format( &sf, 0, true ); + wxString record = FROM_UTF8( sf.GetString().c_str() ); + record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines + record.Replace( wxT(" "), wxT(" "), true ); // double space to single - wxString record = FROM_UTF8( sf.GetString().c_str() ); - record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines - record.Replace( wxT(" "), wxT(" "), true ); // double space to single - - cfg->m_Drawing.field_names = record.ToStdString(); + cfg->m_Drawing.field_names = record.ToStdString(); + } } diff --git a/eeschema/tools/backannotate.cpp b/eeschema/tools/backannotate.cpp index a5b22dc7e3..cc7f4f3274 100644 --- a/eeschema/tools/backannotate.cpp +++ b/eeschema/tools/backannotate.cpp @@ -40,9 +40,10 @@ #include -BACK_ANNOTATE::BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, SETTINGS aSettings ) - : m_settings( aSettings ), - m_frame( aFrame ) +BACK_ANNOTATE::BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, SETTINGS aSettings ) : + m_settings( aSettings ), + m_frame( aFrame ), + m_changesCount( 0 ) { } @@ -235,10 +236,11 @@ int BACK_ANNOTATE::checkForUnusedSymbols() m_refs.SortByTimeStamp(); - std::sort( - m_changelist.begin(), m_changelist.end(), []( CHANGELIST_ITEM a, CHANGELIST_ITEM b ) { - return SCH_REFERENCE_LIST::sortByTimeStamp( a.first, b.first ); - } ); + std::sort( m_changelist.begin(), m_changelist.end(), + []( const CHANGELIST_ITEM& a, const CHANGELIST_ITEM& b ) + { + return SCH_REFERENCE_LIST::sortByTimeStamp( a.first, b.first ); + } ); size_t i = 0; for( auto& item : m_changelist ) diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp index 8178cc7353..c3a4700e08 100644 --- a/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp +++ b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp @@ -30,9 +30,10 @@ #include -PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS( PCB_EDIT_FRAME* aFrame, PAGED_DIALOG* aWindow ) : - PANEL_PCBNEW_ACTION_PLUGINS_BASE( aWindow->GetTreebook() ), - m_frame( aFrame ) +PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS( PCB_EDIT_FRAME* aFrame, + PAGED_DIALOG* aWindow ) : + PANEL_PCBNEW_ACTION_PLUGINS_BASE( aWindow->GetTreebook() ), + m_frame( aFrame ) { m_genericIcon = KiBitmap( hammer_xpm ); m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); @@ -138,15 +139,20 @@ void PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick( wxCommandEvent& event ) bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow() { - auto settings = dynamic_cast( Kiface().KifaceSettings() ); + PCBNEW_SETTINGS* settings = dynamic_cast( Kiface().KifaceSettings() ); wxASSERT( settings ); - settings->m_VisibleActionPlugins.clear(); + if( settings ) + { + settings->m_VisibleActionPlugins.clear(); - for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ ) - settings->m_VisibleActionPlugins.emplace_back( std::make_pair( - m_grid->GetCellValue( ii, COLUMN_PATH ), - m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) ); + for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ ) + { + settings->m_VisibleActionPlugins.emplace_back( std::make_pair( + m_grid->GetCellValue( ii, COLUMN_PATH ), + m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) ); + } + } return true; } @@ -155,6 +161,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow() bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() { m_grid->Freeze(); + if( m_grid->GetNumberRows() != 0 ) m_grid->DeleteRows( 0, m_grid->GetNumberRows() ); @@ -173,21 +180,14 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() ); m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER ); - bool showButton = m_frame->GetActionPluginButtonVisible( - ap->GetPluginPath(), ap->GetShowToolbarButton() ); + bool showButton = m_frame->GetActionPluginButtonVisible( ap->GetPluginPath(), + ap->GetShowToolbarButton() ); m_grid->SetCellValue( row, COLUMN_VISIBLE, showButton ? wxT( "1" ) : wxEmptyString ); - // Name m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() ); - - // Category m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() ); - - // Description m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() ); - - // Path m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() ); } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index cfdce07e43..ed2149b842 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -512,9 +512,12 @@ void FOOTPRINT_WIZARD_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) auto cfg = dynamic_cast( aCfg ); wxASSERT( cfg ); - EDA_DRAW_FRAME::LoadSettings( cfg ); + if( cfg ) + { + EDA_DRAW_FRAME::LoadSettings( cfg ); - m_auiPerspective = cfg->m_FootprintViewer.perspective; + m_auiPerspective = cfg->m_FootprintViewer.perspective; + } } @@ -523,9 +526,12 @@ void FOOTPRINT_WIZARD_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) auto cfg = dynamic_cast( aCfg ); wxASSERT( cfg ); - EDA_DRAW_FRAME::SaveSettings( cfg ); + if( cfg ) + { + EDA_DRAW_FRAME::SaveSettings( cfg ); - cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString(); + cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString(); + } } @@ -533,7 +539,8 @@ WINDOW_SETTINGS* FOOTPRINT_WIZARD_FRAME::GetWindowSettings( APP_SETTINGS_BASE* a { auto cfg = dynamic_cast( aCfg ); wxASSERT( cfg ); - return &cfg->m_FootprintWizard; + + return cfg ? &cfg->m_FootprintWizard : nullptr; }