Fix LIB_VIEW_FRAME only returning Unit A

Due to library list repopulation on refresh, the unit was being
overwritten with 1. Now, we track whether the unit needs to be
overwritten.

Fixes: lp:1677736
* https://bugs.launchpad.net/kicad/+bug/1677736
This commit is contained in:
Chris Pavlina 2017-07-17 14:57:15 -06:00
parent be109575ce
commit e34f1222fa
3 changed files with 67 additions and 25 deletions

View File

@ -73,11 +73,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowse
viewlibFrame->SetSelectedComponent( aPreselectedAlias->GetName() ); viewlibFrame->SetSelectedComponent( aPreselectedAlias->GetName() );
} }
if( aUnit > 0 ) viewlibFrame->SetUnitAndConvert( aUnit, aConvert );
viewlibFrame->SetUnit( aUnit );
if( aConvert > 0 )
viewlibFrame->SetConvert( aConvert );
viewlibFrame->Refresh(); viewlibFrame->Refresh();

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -173,6 +173,8 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
m_libListWidth = 0; m_libListWidth = 0;
} }
m_selection_changed = false;
// Creates the component window display // Creates the component window display
m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxPoint( 0, 0 ), m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxPoint( 0, 0 ),
wxSize( m_cmpListWidth, -1 ), 0, NULL, wxLB_HSCROLL ); wxSize( m_cmpListWidth, -1 ), 0, NULL, wxLB_HSCROLL );
@ -197,7 +199,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
mesg.MessageToolbarPane(); mesg.MessageToolbarPane();
// Manage main toolbal // Manage main toolbar
m_auimgr.AddPane( m_mainToolBar, m_auimgr.AddPane( m_mainToolBar,
wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) ); wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) );
@ -249,6 +251,14 @@ LIB_VIEW_FRAME::~LIB_VIEW_FRAME()
} }
void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
{
m_unit = aUnit > 0 ? aUnit : 1;
m_convert = aConvert > 0 ? aConvert : 1;
m_selection_changed = false;
}
LIB_ALIAS* LIB_VIEW_FRAME::getSelectedAlias() LIB_ALIAS* LIB_VIEW_FRAME::getSelectedAlias()
{ {
LIB_ALIAS* alias = NULL; LIB_ALIAS* alias = NULL;
@ -402,10 +412,10 @@ double LIB_VIEW_FRAME::BestZoom()
} }
void LIB_VIEW_FRAME::ReCreateListLib() bool LIB_VIEW_FRAME::ReCreateListLib()
{ {
if( !m_libList ) if( !m_libList )
return; return false;
m_libList->Clear(); m_libList->Clear();
@ -438,7 +448,7 @@ void LIB_VIEW_FRAME::ReCreateListLib()
} }
if( libs.IsEmpty() ) if( libs.IsEmpty() )
return; return true;
m_libList->Append( libs ); m_libList->Append( libs );
@ -459,17 +469,19 @@ void LIB_VIEW_FRAME::ReCreateListLib()
m_convert = 1; m_convert = 1;
} }
ReCreateListCmp(); bool cmp_changed = ReCreateListCmp();
ReCreateHToolbar(); ReCreateHToolbar();
DisplayLibInfos(); DisplayLibInfos();
m_canvas->Refresh(); m_canvas->Refresh();
return cmp_changed;
} }
void LIB_VIEW_FRAME::ReCreateListCmp() bool LIB_VIEW_FRAME::ReCreateListCmp()
{ {
if( m_cmpList == NULL ) if( m_cmpList == NULL )
return; return false;
m_cmpList->Clear(); m_cmpList->Clear();
@ -481,7 +493,7 @@ void LIB_VIEW_FRAME::ReCreateListCmp()
m_entryName = wxEmptyString; m_entryName = wxEmptyString;
m_convert = 1; m_convert = 1;
m_unit = 1; m_unit = 1;
return; return true;
} }
wxArrayString nameList; wxArrayString nameList;
@ -494,6 +506,7 @@ void LIB_VIEW_FRAME::ReCreateListCmp()
m_cmpList->Append( nameList ); m_cmpList->Append( nameList );
int index = m_cmpList->FindString( m_entryName ); int index = m_cmpList->FindString( m_entryName );
bool changed = false;
if( index == wxNOT_FOUND ) if( index == wxNOT_FOUND )
{ {
@ -502,13 +515,16 @@ void LIB_VIEW_FRAME::ReCreateListCmp()
m_convert = 1; m_convert = 1;
m_unit = 1; m_unit = 1;
index = 0; index = 0;
changed = true;
m_entryName = wxEmptyString;
} }
m_entryName = wxEmptyString;
m_cmpList->SetSelection( index, true ); m_cmpList->SetSelection( index, true );
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST ); wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
ProcessEvent( evt ); ProcessEvent( evt );
return changed;
} }
@ -519,6 +535,8 @@ void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
if( ii < 0 ) if( ii < 0 )
return; return;
m_selection_changed = true;
SetSelectedLibrary( m_libList->GetString( ii ) ); SetSelectedLibrary( m_libList->GetString( ii ) );
} }
@ -548,6 +566,8 @@ void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
if( ii < 0 ) if( ii < 0 )
return; return;
m_selection_changed = true;
SetSelectedComponent( m_cmpList->GetString( ii ) ); SetSelectedComponent( m_cmpList->GetString( ii ) );
} }
@ -564,8 +584,14 @@ void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
// by another caller than ClickOnCmpList. // by another caller than ClickOnCmpList.
m_cmpList->SetStringSelection( aComponentName, true ); m_cmpList->SetStringSelection( aComponentName, true );
DisplayLibInfos(); DisplayLibInfos();
m_unit = 1;
m_convert = 1; if( m_selection_changed )
{
m_unit = 1;
m_convert = 1;
m_selection_changed = false;
}
Zoom_Automatique( false ); Zoom_Automatique( false );
ReCreateHToolbar(); ReCreateHToolbar();
m_canvas->Refresh(); m_canvas->Refresh();
@ -667,8 +693,10 @@ void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
{ {
EDA_DRAW_FRAME::OnActivate( event ); EDA_DRAW_FRAME::OnActivate( event );
if( m_libList ) bool changed = m_libList ? ReCreateListLib() : false;
ReCreateListLib();
if (changed)
m_selection_changed = true;
DisplayLibInfos(); DisplayLibInfos();
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -70,10 +70,19 @@ public:
* *
* Creates or recreates the list of current loaded libraries. * Creates or recreates the list of current loaded libraries.
* This list is sorted, with the library cache always at end of the list * This list is sorted, with the library cache always at end of the list
*
* @return whether the selection of either library or component was changed (i.e. because the
* selected library no longer exists)
*/ */
void ReCreateListLib(); bool ReCreateListLib();
void ReCreateListCmp(); /**
* Create or recreate the list of components in the currently selected library.
*
* @return whether the selection was changed (i.e. because the selected component no longer
* exists)
*/
bool ReCreateListCmp();
void DisplayLibInfos(); void DisplayLibInfos();
void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override; void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override;
void OnCloseWindow( wxCloseEvent& Event ); void OnCloseWindow( wxCloseEvent& Event );
@ -135,10 +144,13 @@ public:
void SetSelectedComponent( const wxString& aComponentName ); void SetSelectedComponent( const wxString& aComponentName );
// Accessors: // Accessors:
void SetUnit( int aUnit ) { m_unit = aUnit; } /**
* Set unit and convert, and set flag preventing them from automatically resetting to 1
* @param aUnit - unit; if invalid will be set to 1
* @param aConvert - convert; if invalid will be set to 1
*/
void SetUnitAndConvert( int aUnit, int aConvert );
int GetUnit( void ) { return m_unit; } int GetUnit( void ) { return m_unit; }
void SetConvert( int aConvert ) { m_convert = aConvert; }
int GetConvert( void ) { return m_convert; } int GetConvert( void ) { return m_convert; }
bool GetShowElectricalType() { return m_showPinElectricalTypeName; } bool GetShowElectricalType() { return m_showPinElectricalTypeName; }
@ -198,6 +210,12 @@ private:
static int m_unit; static int m_unit;
static int m_convert; static int m_convert;
/**
* Updated to `true` if a list rewrite on GUI activation resulted in the component
* selection changing, or if the user has changed the selection manually.
*/
bool m_selection_changed;
/** /**
* the option to show the pin electrical name in the component editor * the option to show the pin electrical name in the component editor
*/ */