dialog_edit_components_libid: add a tool to remap orphan components.

Orphan components are components that have a link (lib_id) pointing to a non existent symbol in any loaded libraries.
This commit is contained in:
jean-pierre charras 2017-11-23 19:48:49 +01:00
parent d16a5c1d6c
commit cd9d81d720
4 changed files with 167 additions and 4 deletions

View File

@ -34,6 +34,8 @@
#include <class_drawpanel.h>
#include <sch_component.h>
#include <sch_reference_list.h>
#include <pgm_base.h>
#include <symbol_lib_table.h>
#define COL_REFS 0
#define COL_CURR_LIBID 1
@ -85,11 +87,12 @@ class DIALOG_EDIT_COMPONENTS_LIBID : public DIALOG_EDIT_COMPONENTS_LIBID_BASE
public:
DIALOG_EDIT_COMPONENTS_LIBID( SCH_EDIT_FRAME* aParent );
bool IsSchelaticModified() { return m_isModified; }
bool IsSchematicModified() { return m_isModified; }
private:
SCH_EDIT_FRAME* m_parent;
bool m_isModified; // set to true if the schematic is modified
std::vector<int> m_OrphansRowIndexes; // list of rows containing orphan lib_id
std::vector<CMP_CANDIDATE> m_components;
@ -138,6 +141,9 @@ private:
// Undo all changes, and clear the list of new lib_ids
void onUndoChangesButton( wxCommandEvent& event ) override;
// Try to find a candidate for non existing symbols
void onClickOrphansButton( wxCommandEvent& event ) override;
// UI event, to enable/disable buttons
void updateUIChangesButton( wxUpdateUIEvent& event ) override
{
@ -234,7 +240,7 @@ void DIALOG_EDIT_COMPONENTS_LIBID::initDlg()
// (can be 0 if the symbol is not found)
int unit = candidate.m_Component->GetUnitSelection( &sheetpath );
int unitcount = candidate.m_Component->GetUnitCount();
candidate.m_IsOrphan = unitcount == 0;
candidate.m_IsOrphan = ( unitcount == 0 );
if( unitcount > 1 || unit > 1 )
{
@ -255,7 +261,7 @@ void DIALOG_EDIT_COMPONENTS_LIBID::initDlg()
wxString last_str_libid = m_components.front().GetStringLibId();
int row = 0;
wxString refs;
bool mark_cell = false;
bool mark_cell = m_components.front().m_IsOrphan;
CMP_CANDIDATE* cmp = nullptr;
for( unsigned ii = 0; ii < m_components.size(); ii++ )
@ -300,12 +306,17 @@ void DIALOG_EDIT_COMPONENTS_LIBID::initDlg()
// Allows only the selection by row
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
m_buttonOrphanItems->Enable( m_OrphansRowIndexes.size() > 0 );
}
void DIALOG_EDIT_COMPONENTS_LIBID::AddRowToGrid( int aRowId, bool aMarkRow,
const wxString& aReferences, const wxString& aStrLibId )
{
if( aMarkRow ) // a orphan component exists, set m_AsOrphanCmp as true
m_OrphansRowIndexes.push_back( aRowId );
int row = aRowId;
if( m_grid->GetNumberRows() <= row )
@ -401,13 +412,68 @@ void DIALOG_EDIT_COMPONENTS_LIBID::onButtonBrowseLibraries( wxCommandEvent& even
}
void DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton( wxCommandEvent& event )
{
std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
wxArrayString aliasNames;
unsigned fixesCount = 0;
// Try to find a candidate for non existing symbols in any loaded library
for( unsigned ii = 0; ii < m_OrphansRowIndexes.size(); ii++ )
{
wxString orphanLibid = m_grid->GetCellValue( m_OrphansRowIndexes[ii], COL_CURR_LIBID );
LIB_ID curr_libid( orphanLibid );
wxString symbName = curr_libid.GetLibItemName();
// now try to fin a candidate
for( auto &lib : libs )
{
aliasNames.Clear();
try
{
Prj().SchSymbolLibTable()->EnumerateSymbolLib( lib, aliasNames );
}
catch( const IO_ERROR& e ) {} // ignore, it is handled below
if( aliasNames.IsEmpty() )
continue;
// Find a symbol name in symbols inside this library:
int index = aliasNames.Index( symbName );
if( index != wxNOT_FOUND )
{
// a candidate is found!
wxString newLibid = lib + ':' + symbName;
m_grid->SetCellValue( m_OrphansRowIndexes[ii], COL_NEW_LIBID, newLibid );
fixesCount++;
break;
}
}
}
if( fixesCount < m_OrphansRowIndexes.size() ) // Not all orphan components are fixed
{
wxMessageBox( wxString::Format( _( "%u link(s) mapped, %d not found" ),
fixesCount, m_OrphansRowIndexes.size() - fixesCount ) );
}
else
wxMessageBox( wxString::Format( _( "All %u link(s) resolved" ), fixesCount ) );
}
bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
{
#if 0
// Use dialog symbol selector to choose a symbol
SCH_BASE_FRAME::HISTORY_LIST dummy;
SCH_BASE_FRAME::COMPONENT_SELECTION sel =
m_parent->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 );
#else
// Use library viewer to choose a symbol
LIB_ID aPreselectedLibid;
SCH_BASE_FRAME::COMPONENT_SELECTION sel =
m_parent->SelectComponentFromLibBrowser( NULL, aPreselectedLibid, 0, 0 );
@ -510,5 +576,5 @@ bool InvokeDialogEditComponentsLibId( SCH_EDIT_FRAME* aCaller )
DIALOG_EDIT_COMPONENTS_LIBID dlg( aCaller );
dlg.ShowModal();
return dlg.IsSchelaticModified();
return dlg.IsSchematicModified();
}

View File

@ -95,6 +95,11 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
m_buttonBrowseLibs = new wxButton( this, wxID_ANY, _("Browse Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonBrowseLibs, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_buttonOrphanItems = new wxButton( this, wxID_ANY, _("Map Orphans"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonOrphanItems->SetToolTip( _("If some components are orphan (the linked symbol is found nowhere),\ntry to find a candidate having the same name in one of loaded symbol libraries") );
bSizerButtons->Add( m_buttonOrphanItems, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bSizerMain->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 );
@ -115,6 +120,7 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
m_buttonUndo->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );
m_buttonBrowseLibs->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
m_buttonBrowseLibs->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
m_buttonOrphanItems->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onClickOrphansButton ), NULL, this );
}
DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
@ -130,5 +136,6 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
m_buttonUndo->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );
m_buttonBrowseLibs->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
m_buttonBrowseLibs->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
m_buttonOrphanItems->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onClickOrphansButton ), NULL, this );
}

View File

@ -708,6 +708,94 @@
<event name="OnUpdateUI">updateUIBrowseButton</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Map Orphans</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonOrphanItems</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">If some components are orphan (the linked symbol is found nowhere),&#x0A;try to find a candidate having the same name in one of loaded symbol libraries</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onClickOrphansButton</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>

View File

@ -48,6 +48,7 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerCancel;
wxButton* m_buttonUndo;
wxButton* m_buttonBrowseLibs;
wxButton* m_buttonOrphanItems;
// Virtual event handlers, overide them in your derived class
virtual void onCellBrowseLib( wxGridEvent& event ) { event.Skip(); }
@ -57,6 +58,7 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
virtual void updateUIChangesButton( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onButtonBrowseLibraries( wxCommandEvent& event ) { event.Skip(); }
virtual void updateUIBrowseButton( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onClickOrphansButton( wxCommandEvent& event ) { event.Skip(); }
public: