diff --git a/pcbnew/dialogs/panel_fp_editor_defaults.cpp b/pcbnew/dialogs/panel_fp_editor_defaults.cpp index 3f326e8fe8..45f92540fb 100644 --- a/pcbnew/dialogs/panel_fp_editor_defaults.cpp +++ b/pcbnew/dialogs/panel_fp_editor_defaults.cpp @@ -170,12 +170,9 @@ enum PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent, - EDA_BASE_FRAME* aUnitsProvider ) : + UNITS_PROVIDER* aUnitsProvider ) : PANEL_FP_EDITOR_DEFAULTS_BASE( aParent ) { - if( aUnitsProvider ) - m_units = aUnitsProvider->GetUserUnits(); - m_parent = static_cast( aParent->GetParent() ); m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 ); @@ -226,29 +223,29 @@ void PANEL_FP_EDITOR_DEFAULTS::loadFPSettings( FOOTPRINT_EDITOR_SETTINGS* aCfg ) { wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ); -#define SET_MILS_CELL( row, col, val ) \ - m_graphicsGrid->SetCellValue( row, col, EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, m_units, val, true ) ) - -#define DISABLE_CELL( row, col ) \ - m_graphicsGrid->SetReadOnly( row, col ); \ - m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour ); + auto disableCell = + [&]( int row, int col ) + { + m_graphicsGrid->SetReadOnly( row, col ); + m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour ); + }; for( int i = 0; i < ROW_COUNT; ++i ) { - SET_MILS_CELL( i, COL_LINE_THICKNESS, aCfg->m_DesignSettings.m_LineThickness[ i ] ); + m_graphicsGrid->SetUnitValue( i, COL_LINE_THICKNESS, aCfg->m_DesignSettings.m_LineThickness[ i ] ); if( i == ROW_EDGES || i == ROW_COURTYARD ) { - DISABLE_CELL( i, COL_TEXT_WIDTH ); - DISABLE_CELL( i, COL_TEXT_HEIGHT ); - DISABLE_CELL( i, COL_TEXT_THICKNESS ); - DISABLE_CELL( i, COL_TEXT_ITALIC ); + disableCell( i, COL_TEXT_WIDTH ); + disableCell( i, COL_TEXT_HEIGHT ); + disableCell( i, COL_TEXT_THICKNESS ); + disableCell( i, COL_TEXT_ITALIC ); } else { - SET_MILS_CELL( i, COL_TEXT_WIDTH, aCfg->m_DesignSettings.m_TextSize[ i ].x ); - SET_MILS_CELL( i, COL_TEXT_HEIGHT, aCfg->m_DesignSettings.m_TextSize[ i ].y ); - SET_MILS_CELL( i, COL_TEXT_THICKNESS, aCfg->m_DesignSettings.m_TextThickness[ i ] ); + m_graphicsGrid->SetUnitValue( i, COL_TEXT_WIDTH, aCfg->m_DesignSettings.m_TextSize[ i ].x ); + m_graphicsGrid->SetUnitValue( i, COL_TEXT_HEIGHT, aCfg->m_DesignSettings.m_TextSize[ i ].y ); + m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, aCfg->m_DesignSettings.m_TextThickness[ i ] ); m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC, aCfg->m_DesignSettings.m_TextItalic[ i ] ? wxT( "1" ) : wxT( "" ) ); auto attr = new wxGridCellAttr; @@ -322,15 +319,6 @@ bool PANEL_FP_EDITOR_DEFAULTS::Show( bool aShow ) } -int PANEL_FP_EDITOR_DEFAULTS::getGridValue( int aRow, int aCol ) -{ - wxString msg = m_graphicsGrid->GetCellValue( aRow, aCol ); - double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_units, msg ); - - return KiROUND( value ); -} - - bool PANEL_FP_EDITOR_DEFAULTS::validateData() { if( !m_textItemsGrid->CommitPendingChanges() || !m_graphicsGrid->CommitPendingChanges() ) @@ -339,10 +327,10 @@ bool PANEL_FP_EDITOR_DEFAULTS::validateData() // Test text parameters. for( int row : { ROW_SILK, ROW_COPPER, ROW_FAB, ROW_OTHERS } ) { - int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ), - getGridValue( row, COL_TEXT_HEIGHT ) ); + int textSize = std::min( m_graphicsGrid->GetUnitValue( row, COL_TEXT_WIDTH ), + m_graphicsGrid->GetUnitValue( row, COL_TEXT_HEIGHT ) ); - if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 ) + if( m_graphicsGrid->GetUnitValue( row, COL_TEXT_THICKNESS ) > textSize / 4 ) { wxString msg = _( "Text will not be readable with a thickness greater than\n" "1/4 its width or height." ); @@ -360,27 +348,27 @@ bool PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow() if( !validateData() ) return false; - SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - FOOTPRINT_EDITOR_SETTINGS* cfg = mgr.GetAppSettings(); + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + BOARD_DESIGN_SETTINGS& cfg = mgr.GetAppSettings()->m_DesignSettings; for( int i = 0; i < ROW_COUNT; ++i ) { - cfg->m_DesignSettings.m_LineThickness[ i ] = getGridValue( i, COL_LINE_THICKNESS ); + cfg.m_LineThickness[ i ] = m_graphicsGrid->GetUnitValue( i, COL_LINE_THICKNESS ); if( i == ROW_EDGES || i == ROW_COURTYARD ) continue; - cfg->m_DesignSettings.m_TextSize[ i ] = wxSize( getGridValue( i, COL_TEXT_WIDTH ), - getGridValue( i, COL_TEXT_HEIGHT ) ); - cfg->m_DesignSettings.m_TextThickness[ i ] = getGridValue( i, COL_TEXT_THICKNESS ); + cfg.m_TextSize[ i ] = wxSize( m_graphicsGrid->GetUnitValue( i, COL_TEXT_WIDTH ), + m_graphicsGrid->GetUnitValue( i, COL_TEXT_HEIGHT ) ); + cfg.m_TextThickness[ i ] = m_graphicsGrid->GetUnitValue( i, COL_TEXT_THICKNESS ); wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC ); - cfg->m_DesignSettings.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg ); + cfg.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg ); } // Footprint defaults wxGridTableBase* table = m_textItemsGrid->GetTable(); - cfg->m_DesignSettings.m_DefaultFPTextItems.clear(); + cfg.m_DefaultFPTextItems.clear(); for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i ) { @@ -388,7 +376,7 @@ bool PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow() bool visible = table->GetValueAsBool( i, 1 ); int layer = (int) table->GetValueAsLong( i, 2 ); - cfg->m_DesignSettings.m_DefaultFPTextItems.emplace_back( text, visible, layer ); + cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer ); } return true; diff --git a/pcbnew/dialogs/panel_fp_editor_defaults.h b/pcbnew/dialogs/panel_fp_editor_defaults.h index 5c1d501d86..4b6c7e22bf 100644 --- a/pcbnew/dialogs/panel_fp_editor_defaults.h +++ b/pcbnew/dialogs/panel_fp_editor_defaults.h @@ -29,7 +29,7 @@ class FOOTPRINT_EDITOR_SETTINGS; class PANEL_FP_EDITOR_DEFAULTS : public PANEL_FP_EDITOR_DEFAULTS_BASE { public: - PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent, EDA_BASE_FRAME* aUnitsProvider ); + PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent, UNITS_PROVIDER* aUnitsProvider ); ~PANEL_FP_EDITOR_DEFAULTS() override; bool TransferDataToWindow() override; @@ -43,14 +43,11 @@ private: bool Show( bool aShow ) override; - int getGridValue( int aRow, int aCol ); - bool validateData(); void loadFPSettings( FOOTPRINT_EDITOR_SETTINGS* aCfg ); private: - EDA_UNITS m_units = EDA_UNITS::MILLIMETRES; PAGED_DIALOG* m_parent; bool m_firstShow = true; }; diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 7678ddafac..9a05550fc7 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -158,8 +158,8 @@ static struct IFACE : public KIFACE_BASE if( !unitsProvider ) { - // If we can't find an eeschema frame we'll have to make do with the units - // defined in whatever FRAME we _can_ find. + // If we can't find a pcb-type frame we'll have to make do with whatever FRAME + // we _can_ find. for( unsigned i = 0; !unitsProvider && i < KIWAY_PLAYER_COUNT; ++i ) unitsProvider = aKiway->Player( (FRAME_T) i, false ); } @@ -168,6 +168,7 @@ static struct IFACE : public KIFACE_BASE { wxWindow* manager = wxFindWindowByName( KICAD_MANAGER_FRAME_NAME ); unitsProvider = static_cast( manager ); + wxASSERT( unitsProvider ); } if( aClassId == PANEL_FP_EDIT_OPTIONS )