Save the footprint editor's last footprint in the PROJECT RString facility.

This commit is contained in:
Dick Hollenbeck 2014-06-11 00:18:41 -05:00
parent 3d311f831e
commit 1385e39d89
6 changed files with 92 additions and 50 deletions

View File

@ -134,9 +134,6 @@ public:
/// Accessor for Eeschema search stack.
VTBL_ENTRY SEARCH_STACK& SchSearchS() { return m_sch_search; }
VTBL_ENTRY wxString GetModuleLibraryNickname() { return m_module_library_nickname; }
VTBL_ENTRY void SetModuleLibraryNickname( const wxString& aNickName ) { m_module_library_nickname = aNickName; }
/// Retain a number of project specific wxStrings, enumerated here:
enum RSTRING_T
{
@ -144,6 +141,7 @@ public:
SCH_LIB_PATH,
PCB_LIB_NICKNAME,
VIEWER_3D_PATH,
PCB_FOOTPRINT,
RSTRING_COUNT
};
@ -252,8 +250,6 @@ private:
wxFileName m_project_name; ///< <fullpath>/<basename>.pro
wxString m_pro_date_and_time;
wxString m_module_library_nickname; ///< @todo move this into m_rpaths[]
/// @see this::SetRString(), GetRString(), and enum RSTRING_T.
wxString m_rstrings[RSTRING_COUNT];

View File

@ -467,7 +467,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
{
wxString nickname = getLibNickName();
wxString nickname = GetCurrentLib();
if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
{

View File

@ -251,11 +251,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_MODEDIT_SELECT_CURRENT_LIB:
{
wxString library = SelectLibrary( getLibNickName() );
wxString library = SelectLibrary( GetCurrentLib() );
if( library.size() )
{
setLibNickName( library );
Prj().SetRString( PROJECT::PCB_LIB_NICKNAME, library );
updateTitle();
}
}
@ -364,9 +364,9 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_MODEDIT_SAVE_LIBMODULE:
if( GetBoard()->m_Modules && getLibNickName().size() )
if( GetBoard()->m_Modules && GetCurrentLib().size() )
{
Save_Module_In_Library( getLibNickName(), GetBoard()->m_Modules, true, true );
Save_Module_In_Library( GetCurrentLib(), GetBoard()->m_Modules, true, true );
GetScreen()->ClrModify();
}
break;
@ -506,7 +506,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SetCrossHairPosition( wxPoint( 0, 0 ) );
LoadModuleFromLibrary( getLibNickName(), Prj().PcbFootprintLibs(), true );
LoadModuleFromLibrary( GetCurrentLib(), Prj().PcbFootprintLibs(), true );
redraw = true;
if( GetBoard()->m_Modules )

View File

@ -245,8 +245,8 @@ public:
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
wxString GetCurrentLib() const { return getLibNickName(); };
/// Return the current library nickname.
const wxString GetCurrentLib() const;
// Footprint edition
void RemoveStruct( EDA_ITEM* Item );
@ -397,7 +397,7 @@ public:
*/
bool DeleteModuleFromCurrentLibrary();
virtual EDA_COLOR_T GetGridColor( void ) const;
virtual EDA_COLOR_T GetGridColor() const;
DECLARE_EVENT_TABLE()
@ -429,15 +429,11 @@ protected:
*/
void updateTitle();
/// The library nickName is a short string, for now the same as the library path
/// but without path and without extension. After library table support it becomes
/// a lookup key.
const wxString getLibNickName() const;
void setLibNickName( const wxString& aNickname );
/// The libPath is not publicly visible, grab it from the FP_LIB_TABLE if we must.
wxString getLibPath();
const wxString getLibPath();
void restoreLastFootprint();
void retainLastFootprint();
};
#endif // MODULE_EDITOR_FRAME_H_

View File

@ -33,6 +33,7 @@
#include <pgm_base.h>
#include <kiway.h>
#include <project.h>
#include <kicad_plugin.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
@ -168,6 +169,9 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
SetBoard( new BOARD() );
// restore the last footprint from the project, if any
restoreLastFootprint();
// Ensure all layers and items are visible:
GetBoard()->SetVisibleAlls();
@ -230,26 +234,16 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
{
// save the footprint in the PROJECT
retainLastFootprint();
}
const wxString FOOTPRINT_EDIT_FRAME::getLibNickName() const
{
return Prj().GetModuleLibraryNickname();
}
void FOOTPRINT_EDIT_FRAME::setLibNickName( const wxString& aNickname )
{
Prj().SetModuleLibraryNickname( aNickname );
}
wxString FOOTPRINT_EDIT_FRAME::getLibPath()
const wxString FOOTPRINT_EDIT_FRAME::getLibPath()
{
try
{
const wxString& nickname = getLibNickName();
const wxString& nickname = GetCurrentLib();
const FP_LIB_TABLE::ROW* row = Prj().PcbFootprintLibs()->FindRow( nickname );
@ -262,6 +256,57 @@ wxString FOOTPRINT_EDIT_FRAME::getLibPath()
}
const wxString FOOTPRINT_EDIT_FRAME::GetCurrentLib() const
{
return Prj().GetRString( PROJECT::PCB_LIB_NICKNAME );
};
void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
{
PCB_IO pcb_io;
MODULE* module = GetBoard()->m_Modules;
if( module )
{
pcb_io.Format( GetBoard()->m_Modules );
wxString pretty = FROM_UTF8( pcb_io.GetStringOutput( true ).c_str() );
Prj().SetRString( PROJECT::PCB_FOOTPRINT, pretty );
}
}
void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
{
wxString pretty = Prj().GetRString( PROJECT::PCB_FOOTPRINT );
if( !!pretty )
{
PCB_IO pcb_io;
MODULE* module = NULL;
try
{
module = (MODULE*) pcb_io.Parse( pretty );
}
catch( const PARSE_ERROR& pe )
{
// unlikely to be a problem, since we produced the pretty string.
wxLogError( wxT( "PARSE_ERROR" ) );
}
catch( const IO_ERROR& ioe )
{
// unlikely to be a problem, since we produced the pretty string.
wxLogError( wxT( "IO_ERROR" ) );
}
if( module )
GetBoard()->Add( module ); // assumes BOARD is empty.
}
}
const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
{
return FOOTPRINT_EDIT_FRAME_NAME;
@ -334,9 +379,9 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_YES:
// code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions,
// at case ID_MODEDIT_SAVE_LIBMODULE
if( GetBoard()->m_Modules && getLibNickName().size() )
if( GetBoard()->m_Modules && GetCurrentLib().size() )
{
if( Save_Module_In_Library( getLibNickName(), GetBoard()->m_Modules, true, true ) )
if( Save_Module_In_Library( GetCurrentLib(), GetBoard()->m_Modules, true, true ) )
{
// save was correct
GetScreen()->ClrModify();
@ -587,7 +632,7 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
{
wxString title = _( "Module Editor " );
wxString nickname = getLibNickName();
wxString nickname = GetCurrentLib();
if( !nickname )
{

View File

@ -30,6 +30,7 @@
*/
#include <fctsys.h>
#include <kiface_i.h>
#include <help_common_strings.h>
#include <dialog_helpers.h>
#include <class_layer_box_selector.h>
@ -218,10 +219,14 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
// Set up toolbar
if( Kiface().IsSingle() )
{
m_mainToolBar->AddTool( ID_NEW_BOARD, wxEmptyString, KiBitmap( new_pcb_xpm ),
_( "New board" ) );
m_mainToolBar->AddTool( ID_LOAD_FILE, wxEmptyString, KiBitmap( open_brd_file_xpm ),
_( "Open existing board" ) );
}
m_mainToolBar->AddTool( ID_SAVE_BOARD, wxEmptyString, KiBitmap( save_xpm ),
_( "Save board" ) );