Distinguish between user added fields and those found in symbols.

Fixes https://gitlab.com/kicad/code/kicad/issues/11511

Fixes https://gitlab.com/kicad/code/kicad/issues/8999
This commit is contained in:
Jeff Young 2022-09-12 23:38:36 +01:00
parent f8c8a2144b
commit d3d5d0f46e
5 changed files with 1092 additions and 1088 deletions

View File

@ -28,6 +28,8 @@
#include <symbol_library.h>
#include <confirm.h>
#include <eda_doc.h>
//#include "eda_list_dialog.h"
#include <wildcards_and_files_ext.h>
#include <eeschema_settings.h>
#include <general.h>
#include <grid_tricks.h>
@ -43,13 +45,9 @@
#include <widgets/wx_grid.h>
#include <wx/ffile.h>
#include <wx/grid.h>
#include <wx/msgdlg.h>
#include <wx/textdlg.h>
#include <wx/filedlg.h>
#include "dialog_symbol_fields_table.h"
#include "eda_list_dialog.h"
#include <wildcards_and_files_ext.h>
#define DISPLAY_NAME_COLUMN 0
#define SHOW_FIELD_COLUMN 1
@ -180,6 +178,7 @@ protected:
std::vector<wxString> m_fieldNames;
int m_sortColumn;
bool m_sortAscending;
std::vector<wxString> m_userAddedFields;
// However, the grid view can vary in two ways:
// 1) the componentRefs can be grouped into fewer rows
@ -206,10 +205,13 @@ public:
m_symbolsList.SplitReferences();
}
void AddColumn( const wxString& aFieldName )
void AddColumn( const wxString& aFieldName, bool aAddedByUser )
{
m_fieldNames.push_back( aFieldName );
if( aAddedByUser )
m_userAddedFields.push_back( aFieldName );
for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
{
SCH_SYMBOL* symbol = m_symbolsList[ i ].GetSymbol();
@ -673,6 +675,9 @@ public:
// Add a not existing field if it has a value for this symbol
bool createField = !destField && !srcValue.IsEmpty();
if( alg::contains( m_userAddedFields, srcName ) )
createField = true;
if( createField )
{
const VECTOR2I symbolPos = symbol.GetPosition();
@ -987,9 +992,9 @@ bool DIALOG_SYMBOL_FIELDS_TABLE::TransferDataFromWindow()
void DIALOG_SYMBOL_FIELDS_TABLE::AddField( const wxString& aDisplayName,
const wxString& aCanonicalName,
bool defaultShow, bool defaultSortBy )
bool defaultShow, bool defaultSortBy, bool addedByUser )
{
m_dataModel->AddColumn( aCanonicalName );
m_dataModel->AddColumn( aCanonicalName, addedByUser );
wxVector<wxVariant> fieldsCtrlRow;
@ -1086,7 +1091,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event )
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
cfg->m_FieldEditorPanel.fields_show[key] = true;
AddField( fieldName, fieldName, true, false );
AddField( fieldName, fieldName, true, false, true );
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_INSERTED,
m_fieldsCtrl->GetItemCount(), 1 );

View File

@ -45,7 +45,7 @@ public:
private:
void AddField( const wxString& displayName, const wxString& aCanonicalName, bool defaultShow,
bool defaultSortBy );
bool defaultSortBy, bool addedByUser = false );
/**
* Construct the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all
@ -73,14 +73,13 @@ private:
void OnFilterMouseMoved( wxMouseEvent& event ) override;
void OnFieldsCtrlSelectionChanged( wxDataViewEvent& event ) override;
private:
SCH_EDIT_FRAME* m_parent;
int m_showColWidth;
int m_groupByColWidth;
SCH_REFERENCE_LIST m_symbolsList;
FIELDS_EDITOR_GRID_DATA_MODEL* m_dataModel;
static int m_newFieldsOption; // Store the option choice for new fields
// during a session:
};
#endif /* DIALOG_SYMBOL_FIELDS_TABLE_H */

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -32,12 +32,12 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare
bLeftSizer->Add( m_fieldsCtrl, 1, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_addFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Add Field..."), wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_addFieldButton, 0, wxALL|wxEXPAND, 5 );
bLeftSizer->Add( m_addFieldButton, 0, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_removeFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Remove Field..."), wxDefaultPosition, wxDefaultSize, 0 );
m_removeFieldButton->Enable( false );
bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxBOTTOM|wxLEFT, 5 );
m_leftPanel->SetSizer( bLeftSizer );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!