Field Name Template (aka Default Fields) fixes.

Move from a "default" fields model to a "seed" fields model.  See
discussion on devlist:
https://lists.launchpad.net/kicad-developers/msg35823.html.
This commit is contained in:
Jeff Young 2018-05-29 22:46:13 +01:00
parent 8c63dac0c3
commit d03e92a3a2
10 changed files with 31 additions and 82 deletions

View File

@ -824,12 +824,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent
// values from the component will be set. // values from the component will be set.
if( !schField ) if( !schField )
{ {
if( !it->m_Visible ) fld.SetVisible( it->m_Visible );
fld.SetVisible( false );
else
fld.SetVisible( true );
fld.SetText( it->m_Value ); // empty? ok too.
} }
else else
{ {

View File

@ -650,12 +650,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers()
if( !libField ) if( !libField )
{ {
fld.SetName( it->m_Name ); fld.SetName( it->m_Name );
fld.SetText( it->m_Value ); // empty? ok too. fld.SetVisible( it->m_Visible );
if( !it->m_Visible )
fld.SetVisible( false );
else
fld.SetVisible( true );
} }
else else
{ {

View File

@ -207,7 +207,6 @@ void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
// Add a new fieldname to the fieldname list // Add a new fieldname to the fieldname list
TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" ); TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
newFieldname.m_Value = wxT( "Value" );
newFieldname.m_Visible = false; newFieldname.m_Visible = false;
templateFields.insert( pos, newFieldname ); templateFields.insert( pos, newFieldname );
TransferDataToFieldGrid(); TransferDataToFieldGrid();
@ -345,18 +344,15 @@ bool DIALOG_EESCHEMA_OPTIONS::TransferDataToFieldGrid()
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row ) for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
{ {
m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name ); m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name );
m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value ); m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
m_fieldGrid->SetCellValue( row, 2,
templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
// Set cell properties // Set cell properties
m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE ); m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE );
// Render the Visible column as a check box // Render the Visible column as a check box
m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() ); m_fieldGrid->SetCellEditor( row, 1, new wxGridCellBoolEditor() );
m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() ); m_fieldGrid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE ); m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE );
} }
m_fieldGrid->AutoSizeRows(); m_fieldGrid->AutoSizeRows();
@ -374,8 +370,7 @@ bool DIALOG_EESCHEMA_OPTIONS::TransferDataFromFieldGrid()
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row ) for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
{ {
templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 ); templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 );
templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 ); templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 1 ) != wxEmptyString );
templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString );
} }
return true; return true;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 19 2018) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -327,24 +327,20 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
m_fieldGrid = new wxGrid( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_fieldGrid = new wxGrid( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid // Grid
m_fieldGrid->CreateGrid( 0, 3 ); m_fieldGrid->CreateGrid( 0, 2 );
m_fieldGrid->EnableEditing( true ); m_fieldGrid->EnableEditing( true );
m_fieldGrid->EnableGridLines( true ); m_fieldGrid->EnableGridLines( true );
m_fieldGrid->EnableDragGridSize( false ); m_fieldGrid->EnableDragGridSize( false );
m_fieldGrid->SetMargins( 0, 0 ); m_fieldGrid->SetMargins( 0, 0 );
// Columns // Columns
m_fieldGrid->SetColSize( 0, 150 ); m_fieldGrid->SetColSize( 0, 300 );
m_fieldGrid->SetColSize( 1, 150 ); m_fieldGrid->SetColSize( 1, 75 );
m_fieldGrid->SetColSize( 2, 75 );
m_fieldGrid->EnableDragColMove( false ); m_fieldGrid->EnableDragColMove( false );
m_fieldGrid->EnableDragColSize( true ); m_fieldGrid->EnableDragColSize( true );
m_fieldGrid->SetColLabelSize( 30 ); m_fieldGrid->SetColLabelSize( 22 );
m_fieldGrid->SetColLabelValue( 0, _("Name") ); m_fieldGrid->SetColLabelValue( 0, _("Name") );
m_fieldGrid->SetColLabelValue( 1, _("Default Value") ); m_fieldGrid->SetColLabelValue( 1, _("Visible") );
m_fieldGrid->SetColLabelValue( 2, _("Visible") );
m_fieldGrid->SetColLabelValue( 3, _("Name") );
m_fieldGrid->SetColLabelValue( 4, wxEmptyString );
m_fieldGrid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_fieldGrid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Rows // Rows
@ -380,7 +376,7 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
m_panel2->SetSizer( bSizer6 ); m_panel2->SetSizer( bSizer6 );
m_panel2->Layout(); m_panel2->Layout();
bSizer6->Fit( m_panel2 ); bSizer6->Fit( m_panel2 );
m_notebook->AddPage( m_panel2, _("Default Fields"), false ); m_notebook->AddPage( m_panel2, _("Field Name Templates"), false );
bOptionsSizer->Add( m_notebook, 1, wxALL|wxEXPAND, 5 ); bOptionsSizer->Add( m_notebook, 1, wxALL|wxEXPAND, 5 );

View File

@ -14,7 +14,6 @@
<property name="file">dialog_eeschema_options_base</property> <property name="file">dialog_eeschema_options_base</property>
<property name="first_id">1000</property> <property name="first_id">1000</property>
<property name="help_provider">none</property> <property name="help_provider">none</property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property> <property name="internationalize">1</property>
<property name="name">dialog_eeschema_options</property> <property name="name">dialog_eeschema_options</property>
<property name="namespace"></property> <property name="namespace"></property>
@ -4786,11 +4785,11 @@
</object> </object>
</object> </object>
</object> </object>
<object class="notebookpage" expanded="0"> <object class="notebookpage" expanded="1">
<property name="bitmap"></property> <property name="bitmap"></property>
<property name="label">Default Fields</property> <property name="label">Field Name Templates</property>
<property name="select">0</property> <property name="select">0</property>
<object class="wxPanel" expanded="0"> <object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
<property name="RightDockable">1</property> <property name="RightDockable">1</property>
@ -4864,16 +4863,16 @@
<event name="OnSetFocus"></event> <event name="OnSetFocus"></event>
<event name="OnSize"></event> <event name="OnSize"></event>
<event name="OnUpdateUI"></event> <event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="0"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">bSizer6</property> <property name="name">bSizer6</property>
<property name="orient">wxHORIZONTAL</property> <property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property> <property name="permission">none</property>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxEXPAND</property> <property name="flag">wxEXPAND</property>
<property name="proportion">1</property> <property name="proportion">1</property>
<object class="wxBoxSizer" expanded="0"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">bSizer11</property> <property name="name">bSizer11</property>
<property name="orient">wxVERTICAL</property> <property name="orient">wxVERTICAL</property>
@ -4905,11 +4904,11 @@
<property name="center_pane">0</property> <property name="center_pane">0</property>
<property name="close_button">1</property> <property name="close_button">1</property>
<property name="col_label_horiz_alignment">wxALIGN_CENTRE</property> <property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="col_label_size">30</property> <property name="col_label_size">22</property>
<property name="col_label_values">&quot;Name&quot; &quot;Default Value&quot; &quot;Visible&quot; &quot;Name&quot; &quot;&quot;</property> <property name="col_label_values">&quot;Name&quot; &quot;Visible&quot;</property>
<property name="col_label_vert_alignment">wxALIGN_CENTRE</property> <property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="cols">3</property> <property name="cols">2</property>
<property name="column_sizes">150,150,75</property> <property name="column_sizes">300,75</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="context_menu">1</property> <property name="context_menu">1</property>
<property name="default_pane">0</property> <property name="default_pane">0</property>

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 19 2018) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!

View File

@ -488,21 +488,6 @@ public:
} }
bool isModifiedDefaultField( std::pair<wxString, wxString> aFieldData )
{
wxString name = aFieldData.first;
wxString value = aFieldData.second;
for( auto defaultField : m_frame->GetTemplateFieldNames() )
{
if( name == defaultField.m_Name && value != defaultField.m_Value )
return true;
}
return false;
}
void ApplyData() void ApplyData()
{ {
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i ) for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
@ -520,7 +505,7 @@ public:
wxString srcValue = srcData.second; wxString srcValue = srcData.second;
SCH_FIELD* destField = comp->FindField( srcName ); SCH_FIELD* destField = comp->FindField( srcName );
if( !destField && ( !srcValue.IsEmpty() || isModifiedDefaultField( srcData ) ) ) if( !destField && !srcValue.IsEmpty() )
destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) ); destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) );
if( destField ) if( destField )

View File

@ -160,15 +160,10 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx ) for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
{ {
SCH_FIELD* f = comp->GetField( fldNdx ); SCH_FIELD* f = comp->GetField( fldNdx );
fields.f[ f->GetName() ] = f->GetText();
}
}
// Add in non-empty default fields which have not been explicitly defined if( f->GetText().size() )
for( auto defaultField : m_frame->GetTemplateFieldNames() ) fields.f[ f->GetName() ] = f->GetText();
{ }
if( defaultField.m_Value.size() && fields.f.count( defaultField.m_Name ) == 0 )
fields.f[ defaultField.m_Name ] = defaultField.m_Value;
} }
// Do not output field values blank in netlist: // Do not output field values blank in netlist:

View File

@ -902,8 +902,7 @@ SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
} }
wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame, wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const
bool aIncludeDefaultFields ) const
{ {
for( unsigned int ii = 0; ii < m_Fields.size(); ii++ ) for( unsigned int ii = 0; ii < m_Fields.size(); ii++ )
{ {
@ -911,13 +910,6 @@ wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME
return m_Fields[ii].GetText(); return m_Fields[ii].GetText();
} }
if( aIncludeDefaultFields )
{
for( auto defaultField : aFrame->GetTemplateFieldNames() )
if( aFieldName == defaultField.m_Name )
return defaultField.m_Value;
}
return wxEmptyString; return wxEmptyString;
} }

View File

@ -331,11 +331,8 @@ public:
* Search for a field named \a aFieldName and returns text associated with this field. * Search for a field named \a aFieldName and returns text associated with this field.
* *
* @param aFieldName is the name of the field * @param aFieldName is the name of the field
* @param aIncludeDefaultFields is used to search the default library symbol fields in the
* search.
*/ */
wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame, wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const;
bool aIncludeDefaultFields = true ) const;
/** /**
* Populates a std::vector with SCH_FIELDs. * Populates a std::vector with SCH_FIELDs.