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() )
548 if( !
m_grid->CommitPendingChanges() )
552 wxString errorMessage;
554 if( !
m_dataModel->ValidateReferences( symbolName, errorMessage ) )
556 DisplayErrorMessage(
this, wxString::Format(
_(
"Invalid reference for symbol '%s'." ), symbolName ),
561 if( !wxDialog::TransferDataFromWindow() )
565 bool updateCanvas =
false;
572 if(
m_parent->GetCurSymbol() == aSymbol )
577 auto createdSymbols =
m_dataModel->GetAndClearCreatedDerivedSymbols();
579 wxLogTrace(
traceLibFieldTable,
"Post-apply handler: found %zu created derived symbols",
580 createdSymbols.size() );
582 for(
const auto& [symbol, libraryName] : createdSymbols )
584 if( !libraryName.IsEmpty() )
587 symbol->GetName(), symbol->m_Uuid.AsString(), libraryName );
588 m_parent->GetLibManager().UpdateSymbol( symbol, libraryName );
592 if( !createdSymbols.empty() )
595 createdSymbols.size() );
597 std::vector<LIB_SYMBOL*> symbolsToPreserve;
599 for(
const auto& [symbol, libraryName] : createdSymbols )
600 symbolsToPreserve.push_back( symbol );
609 return aExistingSymbol->m_Uuid == symbol->m_Uuid;
642 auto addMandatoryField =
643 [&](
FIELD_T aFieldId,
bool aShow,
bool aGroupBy )
664 AddField( wxS(
"${EXCLUDE_FROM_BOM}" ),
_(
"Exclude From BOM" ),
true,
false );
665 AddField( wxS(
"${EXCLUDE_FROM_SIM}" ),
_(
"Exclude From Simulation" ),
true,
false );
666 AddField( wxS(
"${EXCLUDE_FROM_BOARD}" ),
_(
"Exclude From Board" ),
true,
false );
667 AddField( wxS(
"${EXCLUDE_FROM_POS_FILES}" ),
_(
"Exclude From Position Files" ),
true,
false );
673 std::set<wxString> userFieldNames;
677 std::vector<SCH_FIELD*> fields;
678 symbol->GetFields( fields );
682 if( !field->IsMandatory() && !field->IsPrivate() )
683 userFieldNames.insert( field->GetName() );
687 for(
const wxString& fieldName : userFieldNames )
692 Pgm().GetCommonSettings()->m_FieldNameTemplates.GetTemplateFieldNames(
693 TEMPLATES::SCOPE::GLOBAL ) )
695 if( userFieldNames.count( templateField.m_Name ) == 0 )
710 switch( aEvent.GetSelection() )
712 case 0:
setScope( SCOPE::SCOPE_LIBRARY );
break;
713 case 1:
setScope( SCOPE::SCOPE_RELATED_SYMBOLS );
break;
724 _(
"Show symbols marked 'DNP' in the table. This setting also controls whether or not 'DNP' "
725 "symbols are included on export." ),
730 _(
"Show symbols marked 'Exclude from BOM' in the table. Symbols marked 'Exclude from BOM' "
731 "are never included on export." ),
736 int menuId =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
769 m_grid->CommitPendingChanges(
true );
783 EndModal( wxID_CANCEL );
799 m_grid->CommitPendingChanges(
true );
820 std::vector<BOM_PRESET> presets = BOM_PRESET::BuiltInPresets();
822 for( BOM_PRESET& preset : presets )
827 for(
BOM_FIELD& field : preset.fieldsOrdered )
832 field.
label = wxS(
"Symbol Name" );
837 if( preset.name == BOM_PRESET::DefaultEditing().name )
839 preset.groupSymbols =
false;
840 preset.fieldsOrdered = {
850 { wxS(
"${EXCLUDE_FROM_BOM}" ), wxS(
"Exclude From BOM" ),
true,
false },
851 { wxS(
"${EXCLUDE_FROM_SIM}" ), wxS(
"Exclude From Simulation" ),
true,
false },
852 { wxS(
"${EXCLUDE_FROM_BOARD}" ), wxS(
"Exclude From Board" ),
true,
false },
853 { wxS(
"${EXCLUDE_FROM_POS_FILES}" ), wxS(
"Exclude From Position Files" ),
true,
false },
866 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)
Store what changed since rememberLoadedPresets(); true if anything did.
void rememberLoadedPresets()
Remember the presets as loaded, which may differ from the stored ones after normalization.
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.