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

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
...@@ -45,7 +45,8 @@ ...@@ -45,7 +45,8 @@
bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename, bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
bool aSetFieldAttributeToVisible ) bool aForceFieldsVisibleAttribute,
bool aFieldsVisibleAttributeState )
{ {
// Build a flat list of components in schematic: // Build a flat list of components in schematic:
SCH_REFERENCE_LIST referencesList; SCH_REFERENCE_LIST referencesList;
...@@ -117,71 +118,68 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename, ...@@ -117,71 +118,68 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
// So we *do not* stop the search here // So we *do not* stop the search here
SCH_COMPONENT* component = referencesList[ii].GetComponent(); SCH_COMPONENT* component = referencesList[ii].GetComponent();
SCH_FIELD * fpfield = component->GetField( FOOTPRINT ); 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; fpfield->m_Text = footprint;
if( aSetFieldAttributeToVisible ) if( aForceFieldsVisibleAttribute )
{
if( aFieldsVisibleAttributeState )
component->GetField( FOOTPRINT )->m_Attributs &= ~TEXT_NO_VISIBLE; component->GetField( FOOTPRINT )->m_Attributs &= ~TEXT_NO_VISIBLE;
else else
component->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE; component->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
} }
} }
} }
}
return true; return true;
} }
bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile() bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()
{ {
wxString title, filename; wxString path = wxGetCwd();
wxString msg;
bool visible = false;
wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ), wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ),
wxEmptyString, wxEmptyString, path, wxEmptyString,
ComponentFileExtensionWildcard, ComponentFileExtensionWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST ); wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return false; return false;
filename = dlg.GetPath(); wxString filename = dlg.GetPath();
title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion(); wxString title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
title += wxT( " " ) + filename; title += wxT( " " ) + filename;
SetTitle( title ); SetTitle( title );
int response = wxMessageBox( _( "Do you want to make all the foot print fields visible?" ), int response = wxMessageBox( _( "Do you want to force all the footprint fields visibility?" ),
_( "Field Display Option" ), _( "Field Visibility Change" ),
wxYES_NO | wxICON_QUESTION | wxCANCEL, this ); wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
if( response == wxCANCEL ) if( response == wxCANCEL )
return false; return false;
if( response == wxYES ) bool changevisibility = response == wxYES;
visible = true; 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() ); msg.Printf( _( "Failed to open component-footprint link file <%s>" ), filename.GetData() );
DisplayError( this, msg ); DisplayError( this, msg );
return false; return false;
} }
OnModify();
return true; return true;
} }
...@@ -575,14 +575,13 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -575,14 +575,13 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
// Fixed fields: // Fixed fields:
// may have their own save policy so there is a separate loop for them. // 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 ) for( i = 0; i < MANDATORY_FIELDS; ++i )
{
if( !fields[i].m_Text.IsEmpty() )
{ {
if( !fields[i].Save( aFormatter ) ) if( !fields[i].Save( aFormatter ) )
return false; return false;
} }
}
// User defined fields: // User defined fields:
// may have their own save policy so there is a separate loop for them. // may have their own save policy so there is a separate loop for them.
......
...@@ -846,7 +846,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) ...@@ -846,7 +846,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
INSTALL_UNBUFFERED_DC( dc, m_Parent->GetCanvas() ); INSTALL_UNBUFFERED_DC( dc, m_Parent->GetCanvas() );
m_Cmp->Draw( m_Parent->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode ); 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(); LIB_FIELD& refField = entry->GetReferenceField();
m_Cmp->GetField( REFERENCE )->m_Pos = refField.m_Pos + m_Cmp->m_Pos; m_Cmp->GetField( REFERENCE )->m_Pos = refField.m_Pos + m_Cmp->m_Pos;
m_Cmp->GetField( REFERENCE )->ImportValues( refField ); m_Cmp->GetField( REFERENCE )->ImportValues( refField );
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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() ...@@ -81,11 +81,6 @@ create a new power component with the new value." ), GetChars( entry->GetName()
wxString title; wxString title;
title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) ); 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 ); DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
int response = dlg.ShowModal(); int response = dlg.ShowModal();
......
...@@ -206,12 +206,11 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() ...@@ -206,12 +206,11 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
AddMenuItem( editMenu, wxID_REPLACE, _( "Find and Re&place\tCtrl+Shift+F" ), HELP_REPLACE, AddMenuItem( editMenu, wxID_REPLACE, _( "Find and Re&place\tCtrl+Shift+F" ), HELP_REPLACE,
KiBitmap( find_replace_xpm ) ); KiBitmap( find_replace_xpm ) );
// Backannotate // Import footprint association from the CvPcb cmp file:
editMenu->AppendSeparator(); editMenu->AppendSeparator();
AddMenuItem( editMenu, AddMenuItem( editMenu, ID_BACKANNO_ITEMS,
ID_BACKANNO_ITEMS, _( "Import Footprint Selection" ),
_( "&Backannotate" ), HELP_IMPORT_FOOTPRINTS,
_( "Back annotate the footprint fields" ),
KiBitmap( import_footprint_names_xpm ) ); KiBitmap( import_footprint_names_xpm ) );
// Menu View: // Menu View:
...@@ -502,11 +501,6 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() ...@@ -502,11 +501,6 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
_( "Run Pcbnew" ), _( "Run Pcbnew" ),
KiBitmap( pcbnew_xpm ) ); KiBitmap( pcbnew_xpm ) );
AddMenuItem( toolsMenu, ID_BACKANNO_ITEMS,
_( "Import Footprint Selection" ),
HELP_IMPORT_FOOTPRINTS,
KiBitmap( import_footprint_names_xpm ) );
// Help Menu: // Help Menu:
wxMenu* helpMenu = new wxMenu; wxMenu* helpMenu = new wxMenu;
......
...@@ -1002,10 +1002,10 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents() ...@@ -1002,10 +1002,10 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents()
xcomp->AddChild( node( sValue, comp->GetField( VALUE )->m_Text ) ); xcomp->AddChild( node( sValue, comp->GetField( VALUE )->m_Text ) );
if( !comp->GetField( FOOTPRINT )->m_Text.IsEmpty() ) if( !comp->GetField( FOOTPRINT )->IsVoid() )
xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->m_Text ) ); xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->m_Text ) );
if( !comp->GetField( DATASHEET )->m_Text.IsEmpty() ) if( !comp->GetField( DATASHEET )->IsVoid() )
xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->m_Text ) ); xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->m_Text ) );
// Export all user defined fields within the component, // Export all user defined fields within the component,
...@@ -1020,8 +1020,8 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents() ...@@ -1020,8 +1020,8 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents()
{ {
SCH_FIELD* f = comp->GetField( fldNdx ); SCH_FIELD* f = comp->GetField( fldNdx );
// only output a field if non empty // only output a field if non empty and not just "~"
if( !f->GetText().IsEmpty() ) if( !f->IsVoid() )
{ {
XNODE* xfield; XNODE* xfield;
xfields->AddChild( xfield = node( sField, f->m_Text ) ); xfields->AddChild( xfield = node( sField, f->m_Text ) );
......
...@@ -1042,17 +1042,15 @@ bool SCH_COMPONENT::Save( FILE* f ) const ...@@ -1042,17 +1042,15 @@ bool SCH_COMPONENT::Save( FILE* f ) const
} }
// Fixed fields: // Fixed fields:
// Save fixed fields which are non blank. // Save fixed fields even they are non blank,
// because the visibility, size and orientation are set from libaries
// mainly for footprint names, for those who do not use CvPcb
for( unsigned i = 0; i<MANDATORY_FIELDS; ++i ) for( unsigned i = 0; i<MANDATORY_FIELDS; ++i )
{ {
SCH_FIELD* fld = GetField( i ); SCH_FIELD* fld = GetField( i );
if( !fld->m_Text.IsEmpty() )
{
if( !fld->Save( f ) ) if( !fld->Save( f ) )
return false; return false;
} }
}
// User defined fields: // User defined fields:
// The *policy* about which user defined fields are part of a symbol is now // The *policy* about which user defined fields are part of a symbol is now
...@@ -1497,6 +1495,13 @@ void SCH_COMPONENT::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) ...@@ -1497,6 +1495,13 @@ void SCH_COMPONENT::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Library" ), alias->GetLibraryName(), BROWN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Library" ), alias->GetLibraryName(), BROWN ) );
// Display the current associated footprin, if exists.
if( ! GetField( FOOTPRINT )->IsVoid() )
msg = GetField( FOOTPRINT )->m_Text;
else
msg = _("<Unknown>");
aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), msg, DARKRED ) );
// Display description of the component, and keywords found in lib // Display description of the component, and keywords found in lib
aList.push_back( MSG_PANEL_ITEM( _( "Description" ), alias->GetDescription(), DARKCYAN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Description" ), alias->GetDescription(), DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Key words" ), alias->GetKeyWords(), DARKCYAN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Key words" ), alias->GetKeyWords(), DARKCYAN ) );
......
...@@ -133,7 +133,6 @@ public: ...@@ -133,7 +133,6 @@ public:
return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false; return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false;
} }
void Draw( EDA_DRAW_PANEL* aPanel, void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC, wxDC* aDC,
const wxPoint& aOffset, const wxPoint& aOffset,
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wnadoo.fr * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
* *
......
...@@ -675,11 +675,15 @@ public: ...@@ -675,11 +675,15 @@ public:
* EndCmp * EndCmp
* *
* @param aFullFilename = the full filename to read * @param aFullFilename = the full filename to read
* @param aSetFieldsAttributeToVisible = true to set the footprint field flag to visible * @param aForceFieldsVisibleAttribute = true to change the footprint field flag
* visible or invisible
* false = keep old state.
* @param aFieldsVisibleAttributeState = footprint field flag visible new state
* @return bool = true if success. * @return bool = true if success.
*/ */
bool ProcessCmpToFootprintLinkFile( wxString& aFullFilename, bool ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
bool aSetFieldsAttributeToVisible ); bool aForceFieldsVisibleAttribute,
bool aFieldsVisibleAttributeState );
/** /**
* Function SaveEEFile * Function SaveEEFile
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment