Commit e206a1b4 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Eeschema: All fixed fields are now always saved in libraries. Therefore the...

Eeschema: All fixed fields are now always saved in libraries. Therefore the footprint field can be set in lib (size, visibility) and imported in schematic with its predefined attributes, even if the footprint text is not set.
parent 4d465ec8
Loading
Loading
Loading
Loading
+30 −32
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@


bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
                                                    bool aSetFieldAttributeToVisible  )
                                                    bool aForceFieldsVisibleAttribute,
                                                    bool aFieldsVisibleAttributeState )
{
    // Build a flat list of components in schematic:
    SCH_REFERENCE_LIST referencesList;
@@ -117,71 +118,68 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
                // So we *do not* stop the search here
                SCH_COMPONENT* component = referencesList[ii].GetComponent();
                SCH_FIELD * fpfield = component->GetField( FOOTPRINT );
                /* Give a reasonable value to the field position and
                 * orientation, if the text is empty at position 0, because
                 * it is probably not yet initialized
                 */
                if( fpfield->m_Text.IsEmpty() &&
                    ( fpfield->GetPosition() == component->GetPosition() ) )
                {
                    fpfield->m_Orient = component->GetField( VALUE )->m_Orient;
                    fpfield->SetPosition( component->GetField( VALUE )->GetPosition() );
                    fpfield->m_Size   = component->GetField( VALUE )->m_Size;

                    if( fpfield->m_Orient == 0 )
                        fpfield->m_Pos.y += 100;
                    else
                        fpfield->m_Pos.x += 100;
                }

                fpfield->m_Text = footprint;

                if( aSetFieldAttributeToVisible )
                if( aForceFieldsVisibleAttribute )
                {
                    if( aFieldsVisibleAttributeState )
                        component->GetField( FOOTPRINT )->m_Attributs &= ~TEXT_NO_VISIBLE;
                    else
                        component->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
                }
            }
        }
    }
    return true;
}


bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()
{
    wxString title, filename;
    wxString msg;
    bool     visible = false;
    wxString path = wxGetCwd();

    wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ),
                      wxEmptyString, wxEmptyString,
                      path, wxEmptyString,
                      ComponentFileExtensionWildcard,
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );

    if( dlg.ShowModal() == wxID_CANCEL )
        return false;

    filename = dlg.GetPath();
    title  = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
    wxString filename = dlg.GetPath();
    wxString title  = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
    title += wxT( " " ) + filename;
    SetTitle( title );

    int response = wxMessageBox( _( "Do you want to make all the foot print fields visible?" ),
                                 _( "Field Display Option" ),
    int response = wxMessageBox( _( "Do you want to force all the footprint fields visibility?" ),
                                 _( "Field Visibility Change" ),
                                 wxYES_NO | wxICON_QUESTION | wxCANCEL, this );

    if( response == wxCANCEL )
        return false;

    if( response == wxYES )
        visible = true;
    bool changevisibility = response == wxYES;
    bool visible = false;

    if( ! ProcessCmpToFootprintLinkFile( filename, visible ) )
    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 )
            return false;

        visible = response == wxYES;
    }

    if( ! ProcessCmpToFootprintLinkFile( filename, changevisibility, visible ) )
    {
        wxString msg;
        msg.Printf( _( "Failed to open component-footprint link file <%s>" ), filename.GetData() );
        DisplayError( this, msg );
        return false;
    }

    OnModify();
    return true;
}
+4 −5
Original line number Diff line number Diff line
@@ -575,14 +575,13 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )

    // Fixed fields:
    // may have their own save policy so there is a separate loop for them.
    // Empty fields are saved, because the user may have set visibility,
    // size and orientation
    for( i = 0;  i < MANDATORY_FIELDS;  ++i )
    {
        if( !fields[i].m_Text.IsEmpty() )
    {
        if( !fields[i].Save( aFormatter ) )
            return false;
    }
    }

    // User defined fields:
    // may have their own save policy so there is a separate loop for them.
+6 −1
Original line number Diff line number Diff line
@@ -846,7 +846,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
    INSTALL_UNBUFFERED_DC( dc, m_Parent->GetCanvas() );
    m_Cmp->Draw( m_Parent->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );

    // Initialize field values to default values found in library:
    // Initialize fixed field values to default values found in library
    // Note: the field texts are not modified because they are set in schematic,
    // the text from libraries is most of time a dummy text
    // Only VALUE and REFERENCE are re-initialized
    // Perhaps the FOOTPRINT field should also be considered,
    // but for most of components it is not set in library
    LIB_FIELD& refField = entry->GetReferenceField();
    m_Cmp->GetField( REFERENCE )->m_Pos = refField.m_Pos + m_Cmp->m_Pos;
    m_Cmp->GetField( REFERENCE )->ImportValues( refField );
+3 −8
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
@@ -81,11 +81,6 @@ create a new power component with the new value." ), GetChars( entry->GetName()
    wxString title;
    title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );

    if( aField->GetText().IsEmpty() )  // Means the field was not already in use
    {
        aField->m_Pos = component->GetPosition();
        aField->m_Size.x = aField->m_Size.y = m_TextFieldSize;
    }
    DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );

    int response = dlg.ShowModal();
+4 −10
Original line number Diff line number Diff line
@@ -206,12 +206,11 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
    AddMenuItem( editMenu, wxID_REPLACE, _( "Find and Re&place\tCtrl+Shift+F" ), HELP_REPLACE,
                 KiBitmap( find_replace_xpm ) );

    // Backannotate
    // Import footprint association from the CvPcb cmp file:
    editMenu->AppendSeparator();
    AddMenuItem( editMenu,
                 ID_BACKANNO_ITEMS,
                 _( "&Backannotate" ),
                 _( "Back annotate the footprint fields" ),
    AddMenuItem( editMenu, ID_BACKANNO_ITEMS,
                 _( "Import Footprint Selection" ),
                 HELP_IMPORT_FOOTPRINTS,
                 KiBitmap( import_footprint_names_xpm ) );

    // Menu View:
@@ -502,11 +501,6 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
                 _( "Run Pcbnew" ),
                 KiBitmap( pcbnew_xpm ) );

    AddMenuItem( toolsMenu, ID_BACKANNO_ITEMS,
                 _( "Import Footprint Selection" ),
                 HELP_IMPORT_FOOTPRINTS,
                 KiBitmap( import_footprint_names_xpm ) );

    // Help Menu:
    wxMenu* helpMenu = new wxMenu;

Loading