Browse Source

Touch up Footprint Viewer for new Lib Tree.

pull/13/head
Jeff Young 7 years ago
parent
commit
9322139baa
  1. 5
      include/pcb_base_frame.h
  2. 80
      pcbnew/footprint_viewer_frame.cpp
  3. 2
      pcbnew/footprint_viewer_frame.h
  4. 2
      pcbnew/generate_footprint_info.cpp
  5. 19
      pcbnew/load_select_footprint.cpp
  6. 2
      pcbnew/onleftclick.cpp
  7. 6
      pcbnew/pcbnew_id.h
  8. 31
      pcbnew/tool_footprint_viewer.cpp
  9. 2
      pcbnew/tools/pcb_editor_control.cpp

5
include/pcb_base_frame.h

@ -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.

80
pcbnew/footprint_viewer_frame.cpp

@ -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,
FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary )
EVT_TOOL( ID_MODVIEW_SELECT_PART,
FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
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_SELECT_PART, FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_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* oldmodule = GetBoard()->m_Modules;
MODULE* module = SelectFootprintFromLibTree( curr_nickname, false );
MODULE* module = SelectFootprintFromLibTree( false );
if( module ) if( module )
{ {
// Only one footprint allowed: remove the previous footprint (if exists)
if( oldmodule )
{
GetBoard()->Remove( oldmodule );
delete oldmodule;
}
SetCrossHairPosition( wxPoint( 0, 0 ) );
AddModuleToBoard( module );
const LIB_ID& fpid = module->GetFPID();
setCurFootprintName( module->GetFPID().GetLibItemName() );
setCurNickname( fpid.GetLibNickname() );
setCurFootprintName( fpid.GetLibItemName() );
wxString nickname = module->GetFPID().GetLibNickname();
int index = m_libList->FindString( fpid.GetLibNickname() );
if( !getCurNickname() && nickname.size() )
if( index != wxNOT_FOUND )
{ {
// Set the listbox
int index = m_libList->FindString( nickname );
if( index != wxNOT_FOUND )
m_libList->SetSelection( index, true );
setCurNickname( nickname );
m_libList->SetSelection( index, true );
m_libList->EnsureVisible( index );
} }
module->ClearFlags();
SetCurItem( NULL );
ReCreateFootprintList();
Zoom_Automatique( false );
m_canvas->Refresh();
Update3D_Frame();
m_footprintList->SetStringSelection( getCurFootprintName() );
}
SelectAndViewFootprint( NEW_PART );
}
} }
@ -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(
getCurNickname(), getCurFootprintName() );
MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(),
getCurFootprintName() );
if( footprint ) if( footprint )
GetBoard()->Add( footprint, ADD_APPEND ); GetBoard()->Add( footprint, ADD_APPEND );

2
pcbnew/footprint_viewer_frame.h

@ -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

2
pcbnew/generate_footprint_info.cpp

@ -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 );
} }

19
pcbnew/load_select_footprint.cpp

@ -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*> history_list;
std::vector<LIB_TREE_ITEM*> historyInfos;
for( auto const& item : s_ModuleHistoryList )
history_list.push_back( GFootprintList.GetModuleInfo( item ) );
for( auto const& item : s_ModuleHistoryList )
historyInfos.push_back( GFootprintList.GetModuleInfo( item ) );
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list );
adapter->SetPreselectNode( history_list[0]->GetLibId(), 0 );
}
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, historyInfos );
if( !historyInfos.empty() )
adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 );
adapter->AddLibraries(); adapter->AddLibraries();

2
pcbnew/onleftclick.cpp

@ -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 );

6
pcbnew/pcbnew_id.h

@ -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,

31
pcbnew/tool_footprint_viewer.cpp

@ -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
| wxAUI_TB_OVERFLOW );
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
// 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,
HK_ZOOM_IN, IS_COMMENT );
msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hotkeys_Descr, 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,
HK_ZOOM_OUT, IS_COMMENT );
msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hotkeys_Descr, 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,
HK_ZOOM_REDRAW );
msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, 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,
HK_ZOOM_AUTO );
msg = AddHotkeyName( _( "Zoom to fit" ), g_Module_Viewer_Hotkeys_Descr, 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,
HK_ZOOM_AUTO );
text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, 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 ) );

2
pcbnew/tools/pcb_editor_control.cpp

@ -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;

Loading…
Cancel
Save