Minor fixes broken by symbol library table changes.

Add missing CMP_TREE_NODE_LIB_ID type that was inadvertently deleted by
the symbol library table implementation that broke the preselected symbol
tree expansion and highlighting.

Changed CMP_TREE_NODE_LIB_ID type from ALIAS to LIBID for more accurate
description.

Use LIB_ID in COMPONENT_SELECTION object instead of strings of the
library and symbol names.
This commit is contained in:
Wayne Stambaugh 2017-11-05 20:59:51 -05:00
parent 168bf5e4b0
commit 44d81e4005
7 changed files with 42 additions and 56 deletions

View File

@ -129,14 +129,14 @@ CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit )
CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias ) CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias )
{ {
wxASSERT( aParent && aAlias );
Type = LIBID;
Parent = aParent; Parent = aParent;
Name = aAlias->GetName(); Name = aAlias->GetName();
Desc = aAlias->GetDescription(); Desc = aAlias->GetDescription();
// Parent node is the library nickname so set the LIB_ID library nickname. // Parent node is the library nickname so set the LIB_ID library nickname.
LibId.SetLibNickname( aParent->Name );
LibId.SetLibItemName( aAlias->GetName(), false );
IsRoot = aAlias->IsRoot(); IsRoot = aAlias->IsRoot();
// Pre-normalized strings for fast case-insensitive matching // Pre-normalized strings for fast case-insensitive matching
@ -152,6 +152,7 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a
if( part ) if( part )
{ {
LibId = part->GetLibId();
footprint = part->GetFootprintField().GetText(); footprint = part->GetFootprintField().GetText();
} }
@ -163,9 +164,9 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a
SearchText += footprint.Lower(); SearchText += footprint.Lower();
} }
if( aAlias->GetPart()->IsMulti() ) if( part->IsMulti() )
{ {
for( int u = 1; u <= aAlias->GetPart()->GetUnitCount(); ++u ) for( int u = 1; u <= part->GetUnitCount(); ++u )
{ {
AddUnit( u ); AddUnit( u );
} }

View File

@ -77,7 +77,7 @@ class LIB_ALIAS;
class CMP_TREE_NODE { class CMP_TREE_NODE {
public: public:
enum TYPE { enum TYPE {
ROOT, LIB, ALIAS, UNIT, INVALID ROOT, LIB, LIBID, UNIT, INVALID
}; };
CMP_TREE_NODE* Parent; ///< Parent node or null CMP_TREE_NODE* Parent; ///< Parent node or null

View File

@ -295,7 +295,7 @@ unsigned int CMP_TREE_MODEL_ADAPTER::GetChildren(
{ {
auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree ); auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
if( node->Type != CMP_TREE_NODE::TYPE::ALIAS || m_show_units ) if( node->Type != CMP_TREE_NODE::TYPE::LIBID || m_show_units )
return IntoArray( *node, aChildren ); return IntoArray( *node, aChildren );
else else
return 0; return 0;
@ -332,7 +332,7 @@ bool CMP_TREE_MODEL_ADAPTER::GetAttr(
auto node = ToNode( aItem ); auto node = ToNode( aItem );
wxASSERT( node ); wxASSERT( node );
if( node->Type != CMP_TREE_NODE::ALIAS ) if( node->Type != CMP_TREE_NODE::LIBID )
{ {
// Currently only aliases are formatted at all // Currently only aliases are formatted at all
return false; return false;
@ -439,7 +439,7 @@ bool CMP_TREE_MODEL_ADAPTER::ShowResults()
return FindAndExpand( m_tree, return FindAndExpand( m_tree,
[]( CMP_TREE_NODE const* n ) []( CMP_TREE_NODE const* n )
{ {
return n->Type == CMP_TREE_NODE::TYPE::ALIAS && n->Score > 1; return n->Type == CMP_TREE_NODE::TYPE::LIBID && n->Score > 1;
} ); } );
} }
@ -452,7 +452,7 @@ bool CMP_TREE_MODEL_ADAPTER::ShowPreselect()
return FindAndExpand( m_tree, return FindAndExpand( m_tree,
[&]( CMP_TREE_NODE const* n ) [&]( CMP_TREE_NODE const* n )
{ {
if( n->Type == CMP_TREE_NODE::ALIAS && ( n->Children.empty() || !m_preselect_unit ) ) if( n->Type == CMP_TREE_NODE::LIBID && ( n->Children.empty() || !m_preselect_unit ) )
return m_preselect_lib_id == n->LibId; return m_preselect_lib_id == n->LibId;
else if( n->Type == CMP_TREE_NODE::UNIT && m_preselect_unit ) else if( n->Type == CMP_TREE_NODE::UNIT && m_preselect_unit )
return m_preselect_lib_id == n->Parent->LibId && m_preselect_unit == n->Unit; return m_preselect_lib_id == n->Parent->LibId && m_preselect_unit == n->Unit;
@ -467,7 +467,7 @@ bool CMP_TREE_MODEL_ADAPTER::ShowSingleLibrary()
return FindAndExpand( m_tree, return FindAndExpand( m_tree,
[]( CMP_TREE_NODE const* n ) []( CMP_TREE_NODE const* n )
{ {
return n->Type == CMP_TREE_NODE::TYPE::ALIAS && return n->Type == CMP_TREE_NODE::TYPE::LIBID &&
n->Parent->Parent->Children.size() == 1; n->Parent->Parent->Children.size() == 1;
} ); } );
} }

View File

@ -291,12 +291,10 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event
auto sel = GetParent()->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 ); auto sel = GetParent()->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 );
if( sel.Name.IsEmpty() || sel.LibNickname.IsEmpty() ) if( !sel.LibId.IsValid() )
return; return;
LIB_ID id( sel.LibNickname, sel.Name ); chipnameTextCtrl->SetValue( sel.LibId.Format() );
chipnameTextCtrl->SetValue( id.Format() );
} }

View File

@ -80,8 +80,15 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowse
COMPONENT_SELECTION sel; COMPONENT_SELECTION sel;
if( viewlibFrame->ShowModal( &sel.Name, this ) ) wxString symbol = sel.LibId.Format();
if( viewlibFrame->ShowModal( &symbol, this ) )
{ {
LIB_ID id;
if( id.Parse( symbol ) == -1 )
sel.LibId = id;
sel.Unit = viewlibFrame->GetUnit(); sel.Unit = viewlibFrame->GetUnit();
sel.Convert = viewlibFrame->GetConvert(); sel.Convert = viewlibFrame->GetConvert();
} }
@ -98,7 +105,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
bool aUseLibBrowser, bool aUseLibBrowser,
int aUnit, int aUnit,
int aConvert, int aConvert,
const wxString& aHighlight, const LIB_ID* aHighlight,
bool aAllowFields ) bool aAllowFields )
{ {
wxString dialogTitle; wxString dialogTitle;
@ -131,26 +138,14 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
for( auto const& i : aHistoryList ) for( auto const& i : aHistoryList )
{ {
LIB_ALIAS* alias = nullptr; LIB_ALIAS* alias = GetLibAlias( i.LibId );
try
{
alias = libs->LoadSymbol( i.LibNickname, i.Name );
}
catch( const IO_ERROR& ioe )
{
wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
"\n\n%s" ), i.Name, i.LibNickname, ioe.What() ) );
continue;
}
if( alias ) if( alias )
history_list.push_back( alias ); history_list.push_back( alias );
} }
adapter->AddAliasList( "-- " + _( "History" ) + " --", history_list ); adapter->AddAliasList( "-- " + _( "History" ) + " --", history_list );
adapter->SetPreselectNode( LIB_ID( aHistoryList[0].LibNickname, aHistoryList[0].Name ), adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
aHistoryList[0].Unit );
} }
std::vector< wxString > libNicknames = libs->GetLogicalLibs(); std::vector< wxString > libNicknames = libs->GetLogicalLibs();
@ -163,8 +158,8 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
} }
} }
if( !aHighlight.IsEmpty() ) if( aHighlight && aHighlight->IsValid() )
adapter->SetPreselectNode( aHighlight, /* aUnit */ 0 ); adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 );
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetComponentsCount() ); dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetComponentsCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, aConvert, aAllowFields ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, aConvert, aAllowFields );
@ -182,20 +177,18 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
sel.Unit = 1; sel.Unit = 1;
sel.Fields = dlg.GetFields(); sel.Fields = dlg.GetFields();
sel.Name = id.GetLibItemName(); sel.LibId = id;
sel.LibNickname = id.GetLibNickname();
if( dlg.IsExternalBrowserSelected() ) // User requested component browser. if( dlg.IsExternalBrowserSelected() ) // User requested component browser.
sel = SelectComponentFromLibBrowser( aFilter, id, sel.Unit, sel.Convert ); sel = SelectComponentFromLibBrowser( aFilter, id, sel.Unit, sel.Convert );
if( !sel.Name.empty() ) if( sel.LibId.IsValid() )
{ {
aHistoryList.erase( aHistoryList.erase(
std::remove_if( std::remove_if(
aHistoryList.begin(), aHistoryList.begin(),
aHistoryList.end(), aHistoryList.end(),
[ &sel ]( COMPONENT_SELECTION const& i ){ return i.Name == sel.Name [ &sel ]( COMPONENT_SELECTION const& i ){ return i.LibId == sel.LibId; } ),
&& i.LibNickname == sel.LibNickname; } ),
aHistoryList.end() ); aHistoryList.end() );
aHistoryList.insert( aHistoryList.begin(), sel ); aHistoryList.insert( aHistoryList.begin(), sel );
@ -217,7 +210,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aD
auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1 ); auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1 );
if( sel.Name.IsEmpty() || sel.LibNickname.IsEmpty() ) if( !sel.LibId.IsValid() )
{ {
m_canvas->SetIgnoreMouseEvents( false ); m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
@ -232,10 +225,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aD
if( aFilter ) if( aFilter )
libsource = aFilter->GetLibSource(); libsource = aFilter->GetLibSource();
LIB_ID libId; LIB_ID libId = sel.LibId;
libId.SetLibItemName( sel.Name, false );
libId.SetLibNickname( sel.LibNickname );
LIB_PART* part = GetLibPart( libId, true ); LIB_PART* part = GetLibPart( libId, true );
@ -263,15 +253,14 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aD
} }
// Set the component value that can differ from component name in lib, for aliases // Set the component value that can differ from component name in lib, for aliases
component->GetField( VALUE )->SetText( sel.Name ); component->GetField( VALUE )->SetText( sel.LibId.GetLibItemName() );
// If there is no field defined in the component, copy one over from the library // If there is no field defined in the component, copy one over from the library
// ( from the .dcm file ) // ( from the .dcm file )
// This way the Datasheet field will not be empty and can be changed from the schematic // This way the Datasheet field will not be empty and can be changed from the schematic
auto libs = Prj().SchLibs();
if( component->GetField( DATASHEET )->GetText().IsEmpty() ) if( component->GetField( DATASHEET )->GetText().IsEmpty() )
{ {
LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetLibId() ); LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true );
if( entry && !!entry->GetDocFileName() ) if( entry && !!entry->GetDocFileName() )
component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); component->GetField( DATASHEET )->SetText( entry->GetDocFileName() );

View File

@ -163,15 +163,14 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
// Get the name of the current part to preselect it // Get the name of the current part to preselect it
LIB_PART* current_part = GetCurPart(); LIB_PART* current_part = GetCurPart();
wxString part_name = current_part ? current_part->GetName() : wxString( wxEmptyString ); LIB_ID id = current_part->GetLibId();
SCH_BASE_FRAME::HISTORY_LIST dummyHistoryList; SCH_BASE_FRAME::HISTORY_LIST dummyHistoryList;
SCHLIB_FILTER filter; SCHLIB_FILTER filter;
filter.LoadFrom( lib ); filter.LoadFrom( lib );
auto sel = SelectComponentFromLibrary( &filter, dummyHistoryList, auto sel = SelectComponentFromLibrary( &filter, dummyHistoryList, true, 0, 0, &id, false );
true, 0, 0, part_name, false );
if( sel.Name.empty() ) if( sel.LibId.GetLibItemName().empty() )
return; return;
GetScreen()->ClrModify(); GetScreen()->ClrModify();
@ -182,7 +181,7 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
m_aliasName.Empty(); m_aliasName.Empty();
// Load the new library symbol // Load the new library symbol
LoadComponentFromCurrentLib( sel.Name, sel.Unit, sel.Convert ); LoadComponentFromCurrentLib( sel.LibId.GetLibItemName(), sel.Unit, sel.Convert );
} }

View File

@ -24,7 +24,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <lib_id.h>
#include <draw_frame.h> #include <draw_frame.h>
#include <class_sch_screen.h> #include <class_sch_screen.h>
class PAGE_INFO; class PAGE_INFO;
@ -153,16 +155,13 @@ public:
struct COMPONENT_SELECTION struct COMPONENT_SELECTION
{ {
wxString LibNickname; LIB_ID LibId;
wxString Name;
int Unit; int Unit;
int Convert; int Convert;
std::vector<std::pair<int, wxString>> Fields; std::vector<std::pair<int, wxString>> Fields;
COMPONENT_SELECTION(): COMPONENT_SELECTION():
LibNickname( "" ),
Name( "" ),
Unit( 1 ), Unit( 1 ),
Convert( 1 ) Convert( 1 )
{} {}
@ -199,7 +198,7 @@ public:
bool aUseLibBrowser, bool aUseLibBrowser,
int aUnit, int aUnit,
int aConvert, int aConvert,
const wxString& aHighlight = wxEmptyString, const LIB_ID* aHighlight = nullptr,
bool aAllowFields = true ); bool aAllowFields = true );
void OnEditSymbolLibTable( wxCommandEvent& aEvent ); void OnEditSymbolLibTable( wxCommandEvent& aEvent );