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 )
{
wxASSERT( aParent && aAlias );
Type = LIBID;
Parent = aParent;
Name = aAlias->GetName();
Desc = aAlias->GetDescription();
// 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();
// 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 )
{
LibId = part->GetLibId();
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();
}
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 );
}

View File

@ -77,7 +77,7 @@ class LIB_ALIAS;
class CMP_TREE_NODE {
public:
enum TYPE {
ROOT, LIB, ALIAS, UNIT, INVALID
ROOT, LIB, LIBID, UNIT, INVALID
};
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 );
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 );
else
return 0;
@ -332,7 +332,7 @@ bool CMP_TREE_MODEL_ADAPTER::GetAttr(
auto node = ToNode( aItem );
wxASSERT( node );
if( node->Type != CMP_TREE_NODE::ALIAS )
if( node->Type != CMP_TREE_NODE::LIBID )
{
// Currently only aliases are formatted at all
return false;
@ -439,7 +439,7 @@ bool CMP_TREE_MODEL_ADAPTER::ShowResults()
return FindAndExpand( m_tree,
[]( 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,
[&]( 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;
else if( n->Type == CMP_TREE_NODE::UNIT && m_preselect_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,
[]( 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;
} );
}

View File

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

View File

@ -80,8 +80,15 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowse
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.Convert = viewlibFrame->GetConvert();
}
@ -98,7 +105,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
bool aUseLibBrowser,
int aUnit,
int aConvert,
const wxString& aHighlight,
const LIB_ID* aHighlight,
bool aAllowFields )
{
wxString dialogTitle;
@ -131,26 +138,14 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
for( auto const& i : aHistoryList )
{
LIB_ALIAS* alias = nullptr;
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;
}
LIB_ALIAS* alias = GetLibAlias( i.LibId );
if( alias )
history_list.push_back( alias );
}
adapter->AddAliasList( "-- " + _( "History" ) + " --", history_list );
adapter->SetPreselectNode( LIB_ID( aHistoryList[0].LibNickname, aHistoryList[0].Name ),
aHistoryList[0].Unit );
adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
}
std::vector< wxString > libNicknames = libs->GetLogicalLibs();
@ -163,8 +158,8 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
}
}
if( !aHighlight.IsEmpty() )
adapter->SetPreselectNode( aHighlight, /* aUnit */ 0 );
if( aHighlight && aHighlight->IsValid() )
adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 );
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetComponentsCount() );
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.Fields = dlg.GetFields();
sel.Name = id.GetLibItemName();
sel.LibNickname = id.GetLibNickname();
sel.LibId = id;
if( dlg.IsExternalBrowserSelected() ) // User requested component browser.
sel = SelectComponentFromLibBrowser( aFilter, id, sel.Unit, sel.Convert );
if( !sel.Name.empty() )
if( sel.LibId.IsValid() )
{
aHistoryList.erase(
std::remove_if(
aHistoryList.begin(),
aHistoryList.end(),
[ &sel ]( COMPONENT_SELECTION const& i ){ return i.Name == sel.Name
&& i.LibNickname == sel.LibNickname; } ),
[ &sel ]( COMPONENT_SELECTION const& i ){ return i.LibId == sel.LibId; } ),
aHistoryList.end() );
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 );
if( sel.Name.IsEmpty() || sel.LibNickname.IsEmpty() )
if( !sel.LibId.IsValid() )
{
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
@ -232,10 +225,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aD
if( aFilter )
libsource = aFilter->GetLibSource();
LIB_ID libId;
libId.SetLibItemName( sel.Name, false );
libId.SetLibNickname( sel.LibNickname );
LIB_ID libId = sel.LibId;
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
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
// ( from the .dcm file )
// 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() )
{
LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetLibId() );
LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true );
if( entry && !!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
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;
SCHLIB_FILTER filter;
filter.LoadFrom( lib );
auto sel = SelectComponentFromLibrary( &filter, dummyHistoryList,
true, 0, 0, part_name, false );
auto sel = SelectComponentFromLibrary( &filter, dummyHistoryList, true, 0, 0, &id, false );
if( sel.Name.empty() )
if( sel.LibId.GetLibItemName().empty() )
return;
GetScreen()->ClrModify();
@ -182,7 +181,7 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
m_aliasName.Empty();
// 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
*/
#include <lib_id.h>
#include <draw_frame.h>
#include <class_sch_screen.h>
class PAGE_INFO;
@ -153,16 +155,13 @@ public:
struct COMPONENT_SELECTION
{
wxString LibNickname;
wxString Name;
LIB_ID LibId;
int Unit;
int Convert;
std::vector<std::pair<int, wxString>> Fields;
COMPONENT_SELECTION():
LibNickname( "" ),
Name( "" ),
Unit( 1 ),
Convert( 1 )
{}
@ -199,7 +198,7 @@ public:
bool aUseLibBrowser,
int aUnit,
int aConvert,
const wxString& aHighlight = wxEmptyString,
const LIB_ID* aHighlight = nullptr,
bool aAllowFields = true );
void OnEditSymbolLibTable( wxCommandEvent& aEvent );