From e2f32ce7b687d87b41faf21b394d68cf0342b0f0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 29 Aug 2020 18:37:56 +0100 Subject: [PATCH] Allow setting a stroke type back to the default. --- eeschema/dialogs/dialog_edit_line_style.cpp | 61 ++++++++++----------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp index 613feb3ed3..f5d3b0b5be 100644 --- a/eeschema/dialogs/dialog_edit_line_style.cpp +++ b/eeschema/dialogs/dialog_edit_line_style.cpp @@ -50,6 +50,10 @@ const std::map lineTypeNames = { }; +#define DEFAULT_STYLE _( "Default" ) +#define INDETERMINATE_STYLE _( "Leave unchanged" ) + + DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( SCH_EDIT_FRAME* aParent, std::deque& strokeItems ) : DIALOG_EDIT_LINE_STYLE_BASE( aParent ), @@ -66,7 +70,7 @@ DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( SCH_EDIT_FRAME* aParent, for( auto& typeEntry : lineTypeNames ) m_typeCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) ); - m_typeCombo->Append( INDETERMINATE_ACTION ); + m_typeCombo->Append( DEFAULT_STYLE ); m_sdbSizerOK->SetDefault(); @@ -112,13 +116,18 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataToWindow() } ) ) { int style = static_cast( first_stroke_item->GetStroke().GetType() ); - wxCHECK_MSG( style < (int)lineTypeNames.size(), false, - "Line type for first line is not found in the type lookup map" ); - m_typeCombo->SetSelection( style ); + + if( style == -1 ) + m_typeCombo->SetStringSelection( DEFAULT_STYLE ); + else if( style < (int) lineTypeNames.size() ) + m_typeCombo->SetSelection( style ); + else + wxFAIL_MSG( "Line type not found in the type lookup map" ); } else { - m_typeCombo->SetStringSelection( INDETERMINATE_ACTION ); + m_typeCombo->Append( INDETERMINATE_STYLE ); + m_typeCombo->SetStringSelection( INDETERMINATE_STYLE ); } return true; @@ -130,9 +139,7 @@ void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event ) m_width.SetValue( 0 ); m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); - // This isn't quite right: they really want to set each stroke to the stroke set by the - // netclass (if any). - m_typeCombo->SetSelection( 0 ); + m_typeCombo->SetStringSelection( DEFAULT_STYLE ); Refresh(); } @@ -148,32 +155,24 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow() m_frame->SaveCopyInUndoList( pickedItems, UNDO_REDO::CHANGED, false ); - for( auto& strokeItem : m_strokeItems ) + for( SCH_ITEM* strokeItem : m_strokeItems ) { - if( !m_width.IsIndeterminate() ) - { - stroke = strokeItem->GetStroke(); - stroke.SetWidth( m_width.GetValue() ); - strokeItem->SetStroke( stroke ); - } - - int selection = m_typeCombo->GetSelection(); - - if( selection < (int)lineTypeNames.size() ) - { - stroke = strokeItem->GetStroke(); - - auto it = lineTypeNames.begin(); - std::advance( it, selection ); - - stroke.SetType( it->first ); - strokeItem->SetStroke( stroke ); - } - stroke = strokeItem->GetStroke(); - stroke.SetColor( m_colorSwatch->GetSwatchColor() ); - strokeItem->SetStroke( stroke ); + if( !m_width.IsIndeterminate() ) + stroke.SetWidth( m_width.GetValue() ); + + auto it = lineTypeNames.begin(); + std::advance( it, m_typeCombo->GetSelection() ); + + if( it == lineTypeNames.end() ) + stroke.SetType( PLOT_DASH_TYPE::DEFAULT ); + else + stroke.SetType( it->first ); + + stroke.SetColor( m_colorSwatch->GetSwatchColor() ); + + strokeItem->SetStroke( stroke ); m_frame->UpdateItem( strokeItem ); }