Commit 3cbf8a72 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Fix back annotate field visibility bug in Eeschema. (fixes lp:1304835)

*  Fix Eeschema back annotation bug where footprint field visibility setting was ignored.
*  Replace two confusing and ambiguous dialogs with a simple single choice dialog.
parent 8d23b26f
Loading
Loading
Loading
Loading
+27 −33
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include <dsnlexer.h>
#include <ptree.h>
#include <boost/property_tree/ptree.hpp>
#include <wx/choicdlg.h>


void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfReferences ) throw( IO_ERROR )
@@ -88,7 +89,7 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
            else
                footprint.Empty();

            DBG( printf( "%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )
            // DBG( printf( "%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )

            // Search the component in the flat list
            for( unsigned ii = 0;  ii < refs.GetCount();  ++ii )
@@ -128,8 +129,8 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef


bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilename,
                                                    bool aForceFieldsVisibleAttribute,
                                                    bool aFieldsVisibleAttributeState )
                                                    bool aForceVisibilityState,
                                                    bool aVisibilityState )
{
    // Build a flat list of components in schematic:
    SCH_REFERENCE_LIST  referencesList;
@@ -138,6 +139,7 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
    sheetList.GetComponents( Prj().SchLibs(), referencesList, false );

    FILE* cmpFile = wxFopen( aFullFilename, wxT( "rt" ) );

    if( cmpFile == NULL )
        return false;

@@ -185,7 +187,7 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
            }
        }

        // A block is read: initialize the footprint field of the correponding component
        // A block is read: initialize the footprint field of the corresponding component
        // if the footprint name is not empty
        if( reference.IsEmpty() )
            continue;
@@ -203,10 +205,9 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam

                fpfield->SetText( footprint );

                if( aForceFieldsVisibleAttribute )
                if( aForceVisibilityState )
                {
                    component->GetField( FOOTPRINT )
                            ->SetVisible( aFieldsVisibleAttributeState );
                    component->GetField( FOOTPRINT )->SetVisible( aVisibilityState );
                }
            }
        }
@@ -220,7 +221,7 @@ bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()
{
    wxString path = wxPathOnly( Prj().GetProjectFullName() );

    wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ),
    wxFileDialog dlg( this, _( "Load Component Footprint Link File" ),
                      path, wxEmptyString,
                      ComponentFileExtensionWildcard,
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );
@@ -233,33 +234,26 @@ bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()

    SetTitle( title );

    int response = wxMessageBox( _( "Do you want to force all the footprint fields visibility?" ),
                                 _( "Field Visibility Change" ),
                                 wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
    wxArrayString choices;
    choices.Add( _( "Keep existing footprint field visibility" ) );
    choices.Add( _( "Show all footprint fields" ) );
    choices.Add( _( "Hide all footprint fields" ) );

    if( response == wxCANCEL )
        return false;
    wxSingleChoiceDialog choiceDlg( this, _( "Select the footprint field visibility setting." ),
                                    _( "Change Visibility" ), choices );

    bool changevisibility = response == wxYES;
    bool visible = false;

    if( changevisibility )
    {
        response = wxMessageBox( _( "Do you want to make all the footprint fields visible?" ),
                                     _( "Field Visibility Option" ),
                                     wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
        if( response == wxCANCEL )
    if( choiceDlg.ShowModal() == wxID_CANCEL )
        return false;

        visible = response == wxYES;
    }
    bool forceVisibility = (choiceDlg.GetSelection() != 0 );
    bool visibilityState = (choiceDlg.GetSelection() == 1 );

    if( !ProcessCmpToFootprintLinkFile( filename, changevisibility, visible ) )
    if( !ProcessCmpToFootprintLinkFile( filename, forceVisibility, visibilityState ) )
    {
        wxString msg = wxString::Format( _(
                "Failed to open component-footprint link file '%s'" ),
                filename.GetData()
                );
        wxString msg = wxString::Format( _( "Failed to open component-footprint link file '%s'" ),
                                         filename.GetData() );

        DisplayError( this, msg );
        return false;
    }
+7 −6
Original line number Diff line number Diff line
@@ -701,15 +701,16 @@ public:
     *  EndCmp
     *
     * @param aFullFilename = the full filename to read
     * @param aForceFieldsVisibleAttribute = true to change the footprint field flag
     *                                      visible or invisible
     *                                      false = keep old state.
     * @param aFieldsVisibleAttributeState = footprint field flag visible new state
     * @param aForceVisibilityState = Set to true to change the footprint field visibility
     *                                state to \a aVisibilityState.  False retains the
     *                                current footprint field visibility state.
     * @param aVisiblityState True to show the footprint field or false to hide the footprint
     *                        field if \a aForceVisibilityState is true.
     * @return bool = true if success.
     */
    bool ProcessCmpToFootprintLinkFile( const wxString& aFullFilename,
                                        bool aForceFieldsVisibleAttribute,
                                        bool aFieldsVisibleAttributeState );
                                        bool            aForceVisibilityState,
                                        bool            aVisibilityState );

    /**
     * Function SaveEEFile