Commit 1385e39d authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

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

parent 3d311f83
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -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];

+1 −1
Original line number Diff line number Diff line
@@ -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 ) )
    {
+5 −5
Original line number Diff line number Diff line
@@ -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 )
+8 −12
Original line number Diff line number Diff line
@@ -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_
+62 −17
Original line number Diff line number Diff line
@@ -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,37 +234,78 @@ 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
const wxString FOOTPRINT_EDIT_FRAME::getLibPath()
{
    return Prj().GetModuleLibraryNickname();
}
    try
    {
        const wxString& nickname = GetCurrentLib();

        const FP_LIB_TABLE::ROW* row = Prj().PcbFootprintLibs()->FindRow( nickname );

void FOOTPRINT_EDIT_FRAME::setLibNickName( const wxString& aNickname )
        return row->GetFullURI( true );
    }
    catch( const IO_ERROR& ioe )
    {
    Prj().SetModuleLibraryNickname( aNickname );
        return wxEmptyString;
    }
}


wxString FOOTPRINT_EDIT_FRAME::getLibPath()
const wxString FOOTPRINT_EDIT_FRAME::GetCurrentLib() const
{
    try
    return Prj().GetRString( PROJECT::PCB_LIB_NICKNAME );
};


void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
{
        const wxString& nickname = getLibNickName();
    PCB_IO  pcb_io;
    MODULE* module = GetBoard()->m_Modules;

        const FP_LIB_TABLE::ROW* row = Prj().PcbFootprintLibs()->FindRow( nickname );
    if( module )
    {
        pcb_io.Format( GetBoard()->m_Modules );

        return row->GetFullURI( true );
        wxString pretty = FROM_UTF8( pcb_io.GetStringOutput( true ).c_str() );

        Prj().SetRString( PROJECT::PCB_FOOTPRINT, pretty );
    }
    catch( const IO_ERROR& ioe )
}


void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
{
        return wxEmptyString;
    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()
{
@@ -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 )
    {
Loading