diff --git a/include/project.h b/include/project.h index b4415619f4..113aa4e032 100644 --- a/include/project.h +++ b/include/project.h @@ -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; ///< /.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]; diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index cc682e485d..556726d826 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -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 ) ) { diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 784fe1c1e4..ed81bc7989 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -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 ) diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 799ebd5b2c..f20c032c12 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -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 ); @@ -380,7 +380,7 @@ public: * Install a dialog to edit a graphic item of a footprint body. * @param aItem = a pointer to the graphic item to edit */ - void InstallFootprintBodyItemPropertiesDlg(EDGE_MODULE * aItem); + void InstallFootprintBodyItemPropertiesDlg( EDGE_MODULE* aItem ); /** * Function DlgGlobalChange_PadSettings @@ -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_ diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 4bf4f464fa..e4f2da8d48 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -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(); @@ -177,7 +181,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : LoadSettings( config() ); GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER ); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); + GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); // In modedit, set the default paper size to A4: // this should be OK for all footprint to plot/print @@ -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 ) { diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index c115cbcc37..90c2cf6ee8 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -30,6 +30,7 @@ */ #include +#include #include #include #include @@ -218,10 +219,14 @@ void PCB_EDIT_FRAME::ReCreateHToolbar() wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT ); // Set up toolbar - 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" ) ); + 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" ) ); @@ -501,29 +506,29 @@ void PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar() m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString, KiBitmap( mw_add_line_xpm ), _( "Create line of specified length for microwave applications" ), - wxITEM_CHECK ); + wxITEM_CHECK ); m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString, KiBitmap( mw_add_gap_xpm ), _( "Create gap of specified length for microwave applications" ), - wxITEM_CHECK ); + wxITEM_CHECK ); m_microWaveToolBar->AddSeparator(); m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString, KiBitmap( mw_add_stub_xpm ), _( "Create stub of specified length for microwave applications" ), - wxITEM_CHECK ); + wxITEM_CHECK ); m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString, KiBitmap( mw_add_stub_arc_xpm ), _( "Create stub (arc) of specified length for microwave applications" ), - wxITEM_CHECK ); + wxITEM_CHECK ); m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD, wxEmptyString, KiBitmap( mw_add_shape_xpm ), _( "Create a polynomial shape for microwave applications" ), - wxITEM_CHECK ); + wxITEM_CHECK ); m_microWaveToolBar->Realize(); }