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 );
128 bool toggleCell(
int aRow,
int aCol,
bool aPreserveSelection =
false )
override
138 int row =
m_grid->GetGridCursorRow();
139 int col =
m_grid->GetGridCursorCol();
142 _(
"Remove the local override and inherit the parent's value" ) );
143 useParentMenu->Enable( row >= 0 && col >= 0 &&
m_grid->IsEditable()
147 _(
"Create a new symbol derived from the selected one" ) );
149 if( row >= 0 && col >= 0 )
151 deriveMenu->Enable(
m_grid->IsEditable() &&
m_dataModel->IsRowSingleSymbol( row ) );
155 wxMenuItem* selectFootprint =
157 selectFootprint->Enable(
m_grid->IsEditable() );
158 aMenu.AppendSeparator();
163 aMenu.AppendSeparator();
168 deriveMenu->Enable(
false );
176 int row =
m_grid->GetGridCursorRow();
177 int col =
m_grid->GetGridCursorCol();
181 if( !
m_grid->IsEditable() || !
m_grid->CommitPendingChanges(
false )
193 if( !
m_grid->IsEditable() )
197 wxString fpid =
m_grid->GetCellValue( row, col );
199 wxString symbolNetlist =
204 m_grid->SetCellValue( row, col, fpid );
206 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_CHANGED,
m_grid, row, col );
207 m_grid->GetEventHandler()->ProcessEvent( evt );
213 wxString datasheetUri =
m_grid->GetCellValue( row, col );
221 if( !
m_grid->IsEditable() )
229 wxArrayString symbolNames;
230 wxArrayString derivedSymbols;
235 [&](
const wxString& aNewName ) ->
bool
237 if( aNewName.IsEmpty() )
239 wxMessageBox(
_(
"Symbol must have a name." ) );
243 return symbolNames.Index(
UnescapeString( aNewName ),
false ) == wxNOT_FOUND;
247 [&](
const wxString& aItem ) ->
int
249 for( wxString& candidate : derivedSymbols )
251 if( candidate.CmpNoCase( aItem ) == 0 )
263 wxString derivedName = dlg.
GetName();
264 m_dataModel->CreateDerivedSymbolImmediate( row, col, derivedName );
273 if( !
m_grid->CommitPendingChanges(
false ) )
281 m_dlg->ShowHideColumn( col, show );
283 wxString fieldName =
m_dataModel->GetColFieldName( col );
309 aParent->libeditconfig()->m_LibFieldEditorBom, nullptr ),
314 const wxString& libName =
m_parent->GetTargetLibId().GetLibNickname();
315 const bool readOnly =
m_parent->GetLibManager().IsLibraryReadOnly( libName );
320 const wxString& targetSymbolName =
m_parent->GetTargetLibId().GetLibItemName();
324 if( symbol->GetName() == targetSymbolName )
326 if( std::shared_ptr<LIB_SYMBOL> root = symbol->GetRootSymbol() )
327 m_dataModel->SetRelatedSymbolRoot( root->GetName() );
333 m_grid->UseNativeColHeader(
true );
341 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
351 m_scope->Append(
_(
"Whole Library" ) );
352 m_scope->Append(
_(
"Related Symbols Only" ) );
356 wxString title = wxString::Format(
_(
"Symbol Fields Table ('%s' Library)" ), libName );
359 title += wxS(
" " ) +
_(
"[Read Only]" );
396 wxString libName =
m_parent->GetTargetLibId().GetLibNickname();
397 wxArrayString symbolNames;
401 if( symbolNames.IsEmpty() )
403 wxMessageBox( wxString::Format(
_(
"No symbols found in library '%s'." ), libName ) );
407 for(
const wxString& symbolName : symbolNames )
425 wxLogWarning( wxString::Format(
_(
"Error loading symbol '%s': %s" ), symbolName, ioe.
What() ) );
431 wxMessageBox(
_(
"No symbols could be loaded from the library." ) );
449 m_grid->PopEventHandler(
true );
461 auto rowAllowsEmptyReference =
464 int row =
m_grid->GetGridCursorRow();
466 if( row < 0 || row >=
m_dataModel->GetNumberRows() )
469 std::vector<LIB_SYMBOL*> symbols =
m_dataModel->GetRowReferences( row );
471 if( symbols.empty() )
477 if( symbol->IsRoot() )
514 if( !wxDialog::TransferDataToWindow() )
546 if( !
m_grid->CommitPendingChanges() )
550 wxString errorMessage;
552 if( !
m_dataModel->ValidateReferences( symbolName, errorMessage ) )
554 DisplayErrorMessage(
this, wxString::Format(
_(
"Invalid reference for symbol '%s'." ), symbolName ),
559 if( !wxDialog::TransferDataFromWindow() )
563 bool updateCanvas =
false;
570 if(
m_parent->GetCurSymbol() == aSymbol )
575 auto createdSymbols =
m_dataModel->GetAndClearCreatedDerivedSymbols();
577 wxLogTrace(
traceLibFieldTable,
"Post-apply handler: found %zu created derived symbols",
578 createdSymbols.size() );
580 for(
const auto& [symbol, libraryName] : createdSymbols )
582 if( !libraryName.IsEmpty() )
585 symbol->GetName(), symbol->m_Uuid.AsString(), libraryName );
586 m_parent->GetLibManager().UpdateSymbol( symbol, libraryName );
590 if( !createdSymbols.empty() )
593 createdSymbols.size() );
595 std::vector<LIB_SYMBOL*> symbolsToPreserve;
597 for(
const auto& [symbol, libraryName] : createdSymbols )
598 symbolsToPreserve.push_back( symbol );
607 return aExistingSymbol->m_Uuid == symbol->m_Uuid;
640 auto addMandatoryField =
641 [&](
FIELD_T aFieldId,
bool aShow,
bool aGroupBy )
662 AddField( wxS(
"${EXCLUDE_FROM_BOM}" ),
_(
"Exclude From BOM" ),
true,
false );
663 AddField( wxS(
"${EXCLUDE_FROM_SIM}" ),
_(
"Exclude From Simulation" ),
true,
false );
664 AddField( wxS(
"${EXCLUDE_FROM_BOARD}" ),
_(
"Exclude From Board" ),
true,
false );
665 AddField( wxS(
"${EXCLUDE_FROM_POS_FILES}" ),
_(
"Exclude From Position Files" ),
true,
false );
671 std::set<wxString> userFieldNames;
675 std::vector<SCH_FIELD*> fields;
676 symbol->GetFields( fields );
680 if( !field->IsMandatory() && !field->IsPrivate() )
681 userFieldNames.insert( field->GetName() );
685 for(
const wxString& fieldName : userFieldNames )
690 Pgm().GetCommonSettings()->m_FieldNameTemplates.GetTemplateFieldNames(
691 TEMPLATES::SCOPE::GLOBAL ) )
693 if( userFieldNames.count( templateField.m_Name ) == 0 )
708 switch( aEvent.GetSelection() )
710 case 0:
setScope( SCOPE::SCOPE_LIBRARY );
break;
711 case 1:
setScope( SCOPE::SCOPE_RELATED_SYMBOLS );
break;
722 _(
"Show symbols marked 'DNP' in the table. This setting also controls whether or not 'DNP' "
723 "symbols are included on export." ),
728 _(
"Show symbols marked 'Exclude from BOM' in the table. Symbols marked 'Exclude from BOM' "
729 "are never included on export." ),
734 int menuId =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
767 m_grid->CommitPendingChanges(
true );
781 EndModal( wxID_CANCEL );
797 m_grid->CommitPendingChanges(
true );
818 std::vector<BOM_PRESET> presets = BOM_PRESET::BuiltInPresets();
820 for( BOM_PRESET& preset : presets )
825 for(
BOM_FIELD& field : preset.fieldsOrdered )
830 field.
label = wxS(
"Symbol Name" );
835 if( preset.name == BOM_PRESET::DefaultEditing().name )
837 preset.groupSymbols =
false;
838 preset.fieldsOrdered = {
848 { wxS(
"${EXCLUDE_FROM_BOM}" ), wxS(
"Exclude From BOM" ),
true,
false },
849 { wxS(
"${EXCLUDE_FROM_SIM}" ), wxS(
"Exclude From Simulation" ),
true,
false },
850 { wxS(
"${EXCLUDE_FROM_BOARD}" ), wxS(
"Exclude From Board" ),
true,
false },
851 { wxS(
"${EXCLUDE_FROM_POS_FILES}" ), wxS(
"Exclude From Position Files" ),
true,
false },
864 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
static const wxString SYMBOL_PARENT
static const wxString SYMBOL_ROOT
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
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.