Allow setting a stroke type back to the default.

This commit is contained in:
Jeff Young 2020-08-29 18:37:56 +01:00
parent 1bd7290309
commit e2f32ce7b6
1 changed files with 30 additions and 31 deletions

View File

@ -50,6 +50,10 @@ const std::map<PLOT_DASH_TYPE, struct lineTypeStruct> lineTypeNames = {
};
#define DEFAULT_STYLE _( "Default" )
#define INDETERMINATE_STYLE _( "Leave unchanged" )
DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( SCH_EDIT_FRAME* aParent,
std::deque<SCH_ITEM*>& 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<int>( 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 );
}