Touch up Footprint Viewer for new Lib Tree.

This commit is contained in:
Jeff Young 2018-08-01 11:00:10 +01:00
parent 98849bde96
commit 9322139baa
9 changed files with 47 additions and 108 deletions

View File

@ -444,13 +444,12 @@ public:
FP_LIB_TABLE* aTable ); FP_LIB_TABLE* aTable );
/** /**
* Function LoadModuleFromLibrary * Function SelectFootprintFromLibTree
* opens a dialog to select a footprint. * opens a dialog to select a footprint.
* *
* @param aLibrary = the library name to use, or empty string to search all libraries
* @param aUseFootprintViewer = true to allow selection by the footprint viewer * @param aUseFootprintViewer = true to allow selection by the footprint viewer
*/ */
MODULE* SelectFootprintFromLibTree( const wxString& aLibrary, bool aUseFootprintViewer = true ); MODULE* SelectFootprintFromLibTree( bool aUseFootprintViewer = true );
/** /**
* Adds the given module to the board. * Adds the given module to the board.

View File

@ -87,16 +87,10 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout ) EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
// Toolbar events // Toolbar events
EVT_TOOL( ID_MODVIEW_SELECT_LIB, EVT_TOOL( ID_MODVIEW_SELECT_PART, FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary ) EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_SELECT_PART, EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint ) EVT_TOOL( ID_MODVIEW_EXPORT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_MODVIEW_NEXT,
FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_PREVIOUS,
FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD,
FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame ) EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame )
// listbox events // listbox events
@ -762,65 +756,29 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle()
} }
void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
{
wxString selection = SelectLibrary( getCurNickname() );
if( !!selection && selection != getCurNickname() )
{
setCurNickname( selection );
UpdateTitle();
ReCreateFootprintList();
int id = m_libList->FindString( getCurNickname() );
if( id >= 0 )
m_libList->SetSelection( id );
}
}
void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
{ {
wxString curr_nickname = getCurNickname(); MODULE* module = SelectFootprintFromLibTree( false );
MODULE* oldmodule = GetBoard()->m_Modules;
MODULE* module = SelectFootprintFromLibTree( curr_nickname, false );
if( module ) if( module )
{ {
// Only one footprint allowed: remove the previous footprint (if exists) const LIB_ID& fpid = module->GetFPID();
if( oldmodule )
setCurNickname( fpid.GetLibNickname() );
setCurFootprintName( fpid.GetLibItemName() );
int index = m_libList->FindString( fpid.GetLibNickname() );
if( index != wxNOT_FOUND )
{ {
GetBoard()->Remove( oldmodule ); m_libList->SetSelection( index, true );
delete oldmodule; m_libList->EnsureVisible( index );
} }
SetCrossHairPosition( wxPoint( 0, 0 ) ); ReCreateFootprintList();
AddModuleToBoard( module );
setCurFootprintName( module->GetFPID().GetLibItemName() ); SelectAndViewFootprint( NEW_PART );
}
wxString nickname = module->GetFPID().GetLibNickname();
if( !getCurNickname() && nickname.size() )
{
// Set the listbox
int index = m_libList->FindString( nickname );
if( index != wxNOT_FOUND )
m_libList->SetSelection( index, true );
setCurNickname( nickname );
}
module->ClearFlags();
SetCurItem( NULL );
Zoom_Automatique( false );
m_canvas->Refresh();
Update3D_Frame();
m_footprintList->SetStringSelection( getCurFootprintName() );
}
} }
@ -846,14 +804,16 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
if( selection != wxNOT_FOUND ) if( selection != wxNOT_FOUND )
{ {
m_footprintList->SetSelection( selection ); m_footprintList->SetSelection( selection );
setCurFootprintName( m_footprintList->GetString( selection ) ); m_footprintList->EnsureVisible( selection );
setCurFootprintName( m_footprintList->GetString( (unsigned) selection ) );
SetCurItem( NULL ); SetCurItem( NULL );
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); GetBoard()->m_Modules.DeleteAll();
MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(),
getCurNickname(), getCurFootprintName() ); getCurFootprintName() );
if( footprint ) if( footprint )
GetBoard()->Add( footprint, ADD_APPEND ); GetBoard()->Add( footprint, ADD_APPEND );

View File

@ -147,8 +147,6 @@ private:
*/ */
virtual void OnActivate( wxActivateEvent& event ) override; virtual void OnActivate( wxActivateEvent& event ) override;
void SelectCurrentLibrary( wxCommandEvent& event );
/** /**
* Function SelectCurrentFootprint * Function SelectCurrentFootprint
* Selects the current footprint name and display it * Selects the current footprint name and display it

View File

@ -100,7 +100,7 @@ public:
desc = desc.substr( 0, (unsigned) idx ); desc = desc.substr( 0, (unsigned) idx );
desc = desc.Trim( true ); desc = desc.Trim( true );
if( desc.Last() == ',' ) if( !desc.IsEmpty() && desc.Last() == ',' )
desc.RemoveLast( 1 ); desc.RemoveLast( 1 );
} }

View File

@ -183,7 +183,7 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
} }
MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bool aAllowBrowser ) MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( bool aAllowBrowser )
{ {
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
wxString moduleName; wxString moduleName;
@ -193,7 +193,7 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bo
static wxString lastComponentName; static wxString lastComponentName;
WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 ); WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
GFootprintList.ReadFootprintFiles( fpTable, aLibrary.length() ? &aLibrary : NULL, &progressReporter ); GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter );
progressReporter.Show( false ); progressReporter.Show( false );
if( GFootprintList.GetErrorCount() ) if( GFootprintList.GetErrorCount() )
@ -202,16 +202,15 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bo
auto adapterPtr( FP_TREE_MODEL_ADAPTER::Create( fpTable ) ); auto adapterPtr( FP_TREE_MODEL_ADAPTER::Create( fpTable ) );
auto adapter = static_cast<FP_TREE_MODEL_ADAPTER*>( adapterPtr.get() ); auto adapter = static_cast<FP_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
if( !s_ModuleHistoryList.empty() ) std::vector<LIB_TREE_ITEM*> historyInfos;
{
std::vector<LIB_TREE_ITEM*> history_list;
for( auto const& item : s_ModuleHistoryList ) for( auto const& item : s_ModuleHistoryList )
history_list.push_back( GFootprintList.GetModuleInfo( item ) ); historyInfos.push_back( GFootprintList.GetModuleInfo( item ) );
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list ); adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, historyInfos );
adapter->SetPreselectNode( history_list[0]->GetLibId(), 0 );
} if( !historyInfos.empty() )
adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 );
adapter->AddLibraries(); adapter->AddLibraries();

View File

@ -368,7 +368,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
if( (curr_item == NULL) || (curr_item->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
MODULE* module = SelectFootprintFromLibTree( wxEmptyString, Prj().PcbFootprintLibs()); MODULE* module = SelectFootprintFromLibTree();
SetCurItem( (BOARD_ITEM*) module ); SetCurItem( (BOARD_ITEM*) module );

View File

@ -384,16 +384,14 @@ enum pcbnew_ids
ID_MODEDIT_EXPORT_PART, ID_MODEDIT_EXPORT_PART,
ID_POPUP_MODEDIT_EDIT_BODY_ITEM, ID_POPUP_MODEDIT_EDIT_BODY_ITEM,
ID_MODVIEW_LIBWINDOW,
ID_MODVIEW_FOOTPRINT_WINDOW,
ID_MODVIEW_LIB_LIST, ID_MODVIEW_LIB_LIST,
ID_MODVIEW_FOOTPRINT_LIST, ID_MODVIEW_FOOTPRINT_LIST,
ID_MODVIEW_SELECT_LIB,
ID_MODVIEW_SELECT_PART, ID_MODVIEW_SELECT_PART,
ID_MODVIEW_PREVIOUS, ID_MODVIEW_PREVIOUS,
ID_MODVIEW_NEXT, ID_MODVIEW_NEXT,
ID_MODVIEW_SHOW_3D_VIEW, ID_MODVIEW_SHOW_3D_VIEW,
ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, ID_MODVIEW_EXPORT_TO_BOARD,
ID_FOOTPRINT_WIZARD_WINDOW, ID_FOOTPRINT_WIZARD_WINDOW,
ID_FOOTPRINT_WIZARD_PAGES, ID_FOOTPRINT_WIZARD_PAGES,
ID_FOOTPRINT_WIZARD_PARAMETERS, ID_FOOTPRINT_WIZARD_PARAMETERS,

View File

@ -45,14 +45,9 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
m_mainToolBar->Clear(); m_mainToolBar->Clear();
else else
m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
| wxAUI_TB_OVERFLOW );
// Set up toolbar // Set up toolbar
m_mainToolBar->AddTool( ID_MODVIEW_SELECT_LIB, wxEmptyString,
KiScaledBitmap( open_library_xpm, this ),
_( "Select library to browse" ) );
m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString, m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString,
KiScaledBitmap( load_module_lib_xpm, this ), KiScaledBitmap( load_module_lib_xpm, this ),
_( "Select footprint to browse" ) ); _( "Select footprint to browse" ) );
@ -75,30 +70,26 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
KiScaledSeparator( m_mainToolBar, this ); KiScaledSeparator( m_mainToolBar, this );
msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hotkeys_Descr, msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_IN, IS_COMMENT );
HK_ZOOM_IN, IS_COMMENT );
m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString, m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString,
KiScaledBitmap( zoom_in_xpm, this ), msg ); KiScaledBitmap( zoom_in_xpm, this ), msg );
msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hotkeys_Descr, msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_OUT, IS_COMMENT );
HK_ZOOM_OUT, IS_COMMENT );
m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString, m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString,
KiScaledBitmap( zoom_out_xpm, this ), msg ); KiScaledBitmap( zoom_out_xpm, this ), msg );
msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_REDRAW );
HK_ZOOM_REDRAW );
m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString, m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString,
KiScaledBitmap( zoom_redraw_xpm, this ), msg ); KiScaledBitmap( zoom_redraw_xpm, this ), msg );
msg = AddHotkeyName( _( "Zoom to fit footprint" ), g_Module_Viewer_Hotkeys_Descr, msg = AddHotkeyName( _( "Zoom to fit" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
HK_ZOOM_AUTO );
m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString, m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString,
KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg ); KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
if( IsModal() ) if( IsModal() )
{ {
KiScaledSeparator( m_mainToolBar, this ); KiScaledSeparator( m_mainToolBar, this );
m_mainToolBar->AddTool( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, wxEmptyString, m_mainToolBar->AddTool( ID_MODVIEW_EXPORT_TO_BOARD, wxEmptyString,
KiScaledBitmap( export_footprint_names_xpm, this ), KiScaledBitmap( export_footprint_names_xpm, this ),
_( "Insert footprint in board" ) ); _( "Insert footprint in board" ) );
} }
@ -116,7 +107,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar()
// Virtual function // Virtual function
void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void ) void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar()
{ {
// wxWidgets handles the Mac Application menu behind the scenes, but that means // wxWidgets handles the Mac Application menu behind the scenes, but that means
// we always have to start from scratch with a new wxMenuBar. // we always have to start from scratch with a new wxMenuBar.
@ -129,11 +120,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void )
// Menu File: // Menu File:
wxMenu* fileMenu = new wxMenu; wxMenu* fileMenu = new wxMenu;
// Active library selection
AddMenuItem( fileMenu, ID_MODVIEW_SELECT_LIB, _("Set Active Library..."),
_( "Select library to be displayed" ), KiBitmap( open_library_xpm ) );
fileMenu->AppendSeparator();
// Close viewer // Close viewer
AddMenuItem( fileMenu, wxID_EXIT, AddMenuItem( fileMenu, wxID_EXIT,
_( "Cl&ose" ), _( "Cl&ose" ),
@ -151,8 +137,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void )
HK_ZOOM_OUT, IS_ACCELERATOR ); HK_ZOOM_OUT, IS_ACCELERATOR );
AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) ); AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
HK_ZOOM_AUTO );
AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ), AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
KiBitmap( zoom_fit_in_page_xpm ) ); KiBitmap( zoom_fit_in_page_xpm ) );

View File

@ -467,7 +467,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
if( !module ) if( !module )
{ {
// Pick the module to be placed // Pick the module to be placed
module = m_frame->SelectFootprintFromLibTree( wxEmptyString ); module = m_frame->SelectFootprintFromLibTree();
if( module == NULL ) if( module == NULL )
continue; continue;