73 wxTextEntry*
const text = GetTextEntry();
88 std::vector<EMBEDDED_FILES*> embedTargets;
89 std::vector<EMBEDDED_FILES*> inheritedFiles;
96 embedTargets.push_back( symbol->GetEmbeddedFiles() );
97 symbol->AppendParentEmbeddedFiles( inheritedFiles );
127 bool toggleCell(
int aRow,
int aCol,
bool aPreserveSelection =
false )
override
137 int row =
m_grid->GetGridCursorRow();
138 int col =
m_grid->GetGridCursorCol();
141 _(
"Create a new symbol derived from the selected one" ) );
143 if( row >= 0 && col >= 0 )
145 deriveMenu->Enable(
m_grid->IsEditable() &&
m_dataModel->IsRowSingleSymbol( row ) );
149 wxMenuItem* selectFootprint =
151 selectFootprint->Enable(
m_grid->IsEditable() );
152 aMenu.AppendSeparator();
157 aMenu.AppendSeparator();
162 deriveMenu->Enable(
false );
170 int row =
m_grid->GetGridCursorRow();
171 int col =
m_grid->GetGridCursorCol();
175 if( !
m_grid->IsEditable() )
179 wxString fpid =
m_grid->GetCellValue( row, col );
181 wxString symbolNetlist =
185 m_grid->SetCellValue( row, col, fpid );
189 wxString datasheetUri =
m_grid->GetCellValue( row, col );
197 if( !
m_grid->IsEditable() )
205 wxArrayString symbolNames;
206 wxArrayString derivedSymbols;
211 [&](
const wxString& aNewName ) ->
bool
213 return symbolNames.Index(
UnescapeString( aNewName ) ) == wxNOT_FOUND;
217 [&](
const wxString& aItem ) ->
int
219 for( wxString& candidate : derivedSymbols )
221 if( candidate.CmpNoCase( aItem ) == 0 )
233 wxString derivedName = dlg.
GetName();
234 m_dataModel->CreateDerivedSymbolImmediate( row, col, derivedName );
243 if( !
m_grid->CommitPendingChanges(
false ) )
251 m_dlg->ShowHideColumn( col, show );
253 wxString fieldName =
m_dataModel->GetColFieldName( col );
279 aParent->libeditconfig()->m_LibFieldEditorBom, nullptr ),
284 const wxString& libName =
m_parent->GetTargetLibId().GetLibNickname();
285 const bool readOnly =
m_parent->GetLibManager().IsLibraryReadOnly( libName );
290 const wxString& targetSymbolName =
m_parent->GetTargetLibId().GetLibItemName();
294 if( symbol->GetName() == targetSymbolName )
296 if( std::shared_ptr<LIB_SYMBOL> root = symbol->GetRootSymbol() )
297 m_dataModel->SetRelatedSymbolRoot( root->GetName() );
303 m_grid->UseNativeColHeader(
true );
311 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
321 m_scope->Append(
_(
"Whole Library" ) );
322 m_scope->Append(
_(
"Related Symbols Only" ) );
326 wxString title = wxString::Format(
_(
"Symbol Fields Table ('%s' Library)" ), libName );
329 title += wxS(
" " ) +
_(
"[Read Only]" );
366 wxString libName =
m_parent->GetTargetLibId().GetLibNickname();
367 wxArrayString symbolNames;
371 if( symbolNames.IsEmpty() )
373 wxMessageBox( wxString::Format(
_(
"No symbols found in library '%s'." ), libName ) );
377 for(
const wxString& symbolName : symbolNames )
381 if( canvasSymbol && canvasSymbol->
GetLibraryName() == libName && canvasSymbol->
GetName() == symbolName )
394 wxLogWarning( wxString::Format(
_(
"Error loading symbol '%s': %s" ), symbolName, ioe.
What() ) );
400 wxMessageBox(
_(
"No symbols could be loaded from the library." ) );
418 m_grid->PopEventHandler(
true );
430 auto rowAllowsEmptyReference =
433 int row =
m_grid->GetGridCursorRow();
435 if( row < 0 || row >=
m_dataModel->GetNumberRows() )
438 std::vector<LIB_SYMBOL*> symbols =
m_dataModel->GetRowReferences( row );
440 if( symbols.empty() )
446 if( symbol->IsRoot() )
483 if( !wxDialog::TransferDataToWindow() )
515 if( !
m_grid->CommitPendingChanges() )
519 wxString errorMessage;
521 if( !
m_dataModel->ValidateReferences( symbolName, errorMessage ) )
523 DisplayErrorMessage(
this, wxString::Format(
_(
"Invalid reference for symbol '%s'." ), symbolName ),
528 if( !wxDialog::TransferDataFromWindow() )
532 bool updateCanvas =
false;
539 if(
m_parent->GetCurSymbol() == aSymbol )
544 auto createdSymbols =
m_dataModel->GetAndClearCreatedDerivedSymbols();
546 wxLogTrace(
traceLibFieldTable,
"Post-apply handler: found %zu created derived symbols",
547 createdSymbols.size() );
549 for(
const auto& [symbol, libraryName] : createdSymbols )
551 if( !libraryName.IsEmpty() )
554 symbol->GetName(), symbol->m_Uuid.AsString(), libraryName );
555 m_parent->GetLibManager().UpdateSymbol( symbol, libraryName );
559 if( !createdSymbols.empty() )
562 createdSymbols.size() );
564 std::vector<LIB_SYMBOL*> symbolsToPreserve;
566 for(
const auto& [symbol, libraryName] : createdSymbols )
567 symbolsToPreserve.push_back( symbol );
576 return aExistingSymbol->m_Uuid == symbol->m_Uuid;
609 auto addMandatoryField =
610 [&](
FIELD_T aFieldId,
bool aShow,
bool aGroupBy )
629 AddField( wxS(
"${EXCLUDE_FROM_BOM}" ),
_(
"Exclude From BOM" ),
true,
false );
630 AddField( wxS(
"${EXCLUDE_FROM_SIM}" ),
_(
"Exclude From Simulation" ),
true,
false );
631 AddField( wxS(
"${EXCLUDE_FROM_BOARD}" ),
_(
"Exclude From Board" ),
true,
false );
632 AddField( wxS(
"${EXCLUDE_FROM_POS_FILES}" ),
_(
"Exclude From Position Files" ),
true,
false );
638 std::set<wxString> userFieldNames;
642 std::vector<SCH_FIELD*> fields;
643 symbol->GetFields( fields );
647 if( !field->IsMandatory() && !field->IsPrivate() )
648 userFieldNames.insert( field->GetName() );
652 for(
const wxString& fieldName : userFieldNames )
657 Pgm().GetCommonSettings()->m_FieldNameTemplates.GetTemplateFieldNames(
658 TEMPLATES::SCOPE::GLOBAL ) )
660 if( userFieldNames.count( templateField.m_Name ) == 0 )
675 switch( aEvent.GetSelection() )
677 case 0:
setScope( SCOPE::SCOPE_LIBRARY );
break;
678 case 1:
setScope( SCOPE::SCOPE_RELATED_SYMBOLS );
break;
689 _(
"Show symbols marked 'DNP' in the table. This setting also controls whether or not 'DNP' "
690 "symbols are included on export." ),
695 _(
"Show symbols marked 'Exclude from BOM' in the table. Symbols marked 'Exclude from BOM' "
696 "are never included on export." ),
701 int menuId =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
734 m_grid->CommitPendingChanges(
true );
748 EndModal( wxID_CANCEL );
764 m_grid->CommitPendingChanges(
true );
785 std::vector<BOM_PRESET> presets = BOM_PRESET::BuiltInPresets();
787 for( BOM_PRESET& preset : presets )
792 for(
BOM_FIELD& field : preset.fieldsOrdered )
797 field.
label = wxS(
"Symbol Name" );
802 if( preset.name == BOM_PRESET::DefaultEditing().name )
804 preset.groupSymbols =
false;
805 preset.fieldsOrdered = {
813 { wxS(
"${EXCLUDE_FROM_BOM}" ), wxS(
"Exclude From BOM" ),
true,
false },
814 { wxS(
"${EXCLUDE_FROM_SIM}" ), wxS(
"Exclude From Simulation" ),
true,
false },
815 { wxS(
"${EXCLUDE_FROM_BOARD}" ), wxS(
"Exclude From Board" ),
true,
false },
816 { wxS(
"${EXCLUDE_FROM_POS_FILES}" ), wxS(
"Exclude From Position Files" ),
true,
false },
829 return wxEmptyString;
wxTextCtrl * m_outputFileName
wxChoice * m_cbBomFmtPresets
wxPanel * m_variantsPanel
STD_BITMAP_BUTTON * m_bMenu
WX_GRID * m_viewControlsGrid
wxChoice * m_cbBomPresets
wxCheckBox * m_groupSymbolsBox
wxSplitterWindow * m_splitter_left
void SetUserBomFmtPresets(std::vector< BOM_FMT_PRESET > &aPresetList)
wxSize GetDefaultDialogSize() const
void syncBomFmtPresetSelection()
void OnColMove(wxGridEvent &aEvent)
void OnColSort(wxGridEvent &aEvent)
void OnGridMouseMove(wxMouseEvent &aEvent)
bool savePresets(bool aSaveCurrentSettings)
void RestorePanelLayout()
void RestoreGridSelection(const std::set< KIID_PATH > &aItemKeys)
Restore a selection previously returned by SaveGridSelection().
std::map< FIELD_T, int > m_mandatoryFieldListIndexes
void onBomFmtPresetChanged(wxCommandEvent &aEvent)
void SetUserBomPresets(std::vector< BOM_PRESET > &aPresetList)
void ApplyBomFmtPreset(const wxString &aPresetName)
DIALOG_FIELDS_TABLE(wxWindow *aParent, FIELDS_TABLE_SETTINGS &aPanelSettings, FIELDS_TABLE_BOM_SETTINGS &aBomSettings, JOB_EXPORT_BOM *aJob)
FIELDS_TABLE_BOM_SETTINGS & m_cfgBomSettings
void onBomPresetChanged(wxCommandEvent &aEvent)
void SetReadOnly(bool aReadOnly)
std::set< KIID_PATH > SaveGridSelection()
Save the grid selection by stable item identity so it can survive a row rebuild.
void ApplyBomPreset(const wxString &aPresetName)
void syncBomPresetSelection()
VIEW_CONTROLS_GRID_DATA_MODEL * m_viewControlsDataModel
void AddField(const wxString &aFieldName, const wxString &aLabelValue, bool aShow, bool aGroupBy, bool aAddedByUser=false)
wxGridCellEditor * createFootprintEditor() override
bool TransferDataToWindow() override
void OnOk(wxCommandEvent &aEvent) override
~DIALOG_LIB_FIELDS_TABLE() override
void OnSaveAndContinue(wxCommandEvent &aEvent) override
LIB_FIELDS_EDITOR_GRID_DATA_MODEL * m_dataModel
std::vector< BOM_PRESET > getBuiltInBomPresets() const override
void OnCancel(wxCommandEvent &aEvent) override
void OnMenu(wxCommandEvent &aEvent) override
void LoadFieldNames()
Construct the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all field names in ...
wxGridCellEditor * createReferenceEditor() override
Lib symbols have different rules for references.
void setScope(LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE aScope)
SYMBOL_EDIT_FRAME * m_parent
std::vector< LIB_SYMBOL * > m_symbolsList
void OnClose(wxCloseEvent &aEvent) override
wxString resolveVariant() const override
wxGridCellEditor * createDatasheetEditor() override
bool TransferDataFromWindow() override
DIALOG_LIB_FIELDS_TABLE(SYMBOL_EDIT_FRAME *aParent, LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE aScope)
bool resolveTextVar(wxString *aToken) const override
void OnScope(wxCommandEvent &aEvent) override
wxString GetName() const override
void ExcludeFromControlUndoRedo(wxWindow *aWindow)
Opt a control out of the dialog's generic Ctrl+Z/Ctrl+Y undo/redo.
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
The base class for create windows for drawing purpose.
FIELDS_TABLE_GRID_TRICKS(DIALOG_FIELDS_TABLE *aDialog, WX_GRID *aGrid, FIELDS_TABLE_DATA_MODEL_BASE *aDataModel)
static constexpr int FIRST_CLIENT_ID
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
FIELD_VALIDATOR(FIELD_T aFieldId, wxString *aValue=nullptr)
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
virtual bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static const wxString SYMBOL_KEYWORDS
static const wxString SYMBOL_NAME
static const wxString SYMBOL_IS_POWER
static const wxString SYMBOL_IS_LOCAL_POWER
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false) override
LIB_FIELDS_EDITOR_GRID_DATA_MODEL * m_dataModel
LIB_FIELDS_EDITOR_GRID_TRICKS(DIALOG_LIB_FIELDS_TABLE *aParent, WX_GRID *aGrid, VIEW_CONTROLS_GRID_DATA_MODEL *aViewFieldsData, LIB_FIELDS_EDITOR_GRID_DATA_MODEL *aDataModel)
VIEW_CONTROLS_GRID_DATA_MODEL * m_viewControlsDataModel
void doFieldsTablePopupSelection(wxCommandEvent &aEvent) override
DIALOG_LIB_FIELDS_TABLE * m_dlg
void showFieldsTablePopupMenu(wxMenu &aMenu, wxGridEvent &aEvent) override
Symbol library management helper that is specific to the symbol library editor frame.
LIB_SYMBOL_REFERENCE_VALIDATOR(std::function< bool()> aAllowEmpty)
wxObject * Clone() const override
std::function< bool()> m_allowEmpty
bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
LIB_SYMBOL_REFERENCE_VALIDATOR(const LIB_SYMBOL_REFERENCE_VALIDATOR &aOther)
Define a library symbol object.
const wxString GetLibraryName() const
wxString GetName() const override
wxString GetLibNickname() const override
Sets the Description field text value.
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
virtual bool TextVarResolver(wxString *aToken) const
The symbol library editor main window.
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
wxString GetGeneratedFieldDisplayName(const wxString &aSource)
Returns any variables unexpanded, e.g.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
DIALOG_LIB_NEW_SYMBOL DIALOG_NEW_SYMBOL
static GRID_CELL_URL_EDITOR_CONTEXT getDatasheetContext(const std::vector< LIB_SYMBOL * > &aSymbols)
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ MYID_INCLUDE_EXCLUDED_FROM_BOM
@ MYID_CREATE_DERIVED_SYMBOL
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
This file is part of the common library.
wxString BuildFootprintChooserSymbolNetlist(const LIB_SYMBOL *aSymbol)
#define SHOW_FIELD_COLUMN
bool SelectFootprintFromChooser(DIALOG_SHIM *aDialog, wxString &aFootprint, const wxString &aSymbolNetlist)
GRID_CELL_URL_EDITOR_CONTEXT MakeGridCellUrlEditorContext(const std::vector< EMBEDDED_FILES * > &aEmbedTargets, const std::vector< EMBEDDED_FILES * > &aAdditionalLookupFiles)
@ GRIDTRICKS_FIRST_SHOWHIDE
const wxChar *const traceLibFieldTable
PGM_BASE & Pgm()
The global program "get" accessor.
wxString UnescapeString(const wxString &aSource)
std::vector< EMBEDDED_FILES * > m_filesStack
Hold a name of a symbol's field, field value, and default visibility.
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
JSON_SCHEMA_VALIDATOR validator(schema)
wxLogTrace helper definitions.
Custom text control validator definitions.