42#include <wx/textdlg.h>
55wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_FOOTPRINT_FIELDS_TABLE, wxCommandEvent );
87 bool toggleCell(
int aRow,
int aCol,
bool aPreserveSelection =
false )
override
97 int row =
m_grid->GetGridCursorRow();
98 int col =
m_grid->GetGridCursorCol();
100 if( row >= 0 && col >= 0 )
105 aMenu.AppendSeparator();
114 int row =
m_grid->GetGridCursorRow();
115 int col =
m_grid->GetGridCursorCol();
119 wxString datasheetUri =
m_grid->GetCellValue( row, col );
124 if( !
m_grid->CommitPendingChanges(
false ) )
132 m_dlg->ShowHideColumn( col, show );
134 wxString fieldName =
m_dataModel->GetColFieldName( col );
161 aParent->GetBoard()->GetDesignSettings(), aJob ),
171 m_grid->UseNativeColHeader(
true );
179 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
188 wxString variantToSelect;
191 variantToSelect =
m_job->GetSelectedVariant();
193 variantToSelect =
m_parent->GetBoard()->GetCurrentVariant();
195 if( !variantToSelect.IsEmpty() )
199 if( toSelect == wxNOT_FOUND )
212 SetTitle(
m_job->GetSettingsDialogTitle() );
214 SetTitle(
_(
"Footprint Fields Table" ) );
262 m_parent->GetBoard()->AddListener(
this );
263 m_parent->Bind( EDA_EVT_PCB_LAST_SCH_SHEET_CHANGED,
269 m_grid->EnableEditing(
false );
283 m_parent->Unbind( EDA_EVT_PCB_LAST_SCH_SHEET_CHANGED,
298 m_grid->PopEventHandler(
true );
312 if( !wxDialog::TransferDataToWindow() )
350 if( selection.GetSize() == 1 )
355 footprint =
static_cast<FOOTPRINT*
>( item );
362 for(
int row = 0; row <
m_dataModel->GetNumberRows(); ++row )
364 std::vector<FOOTPRINT_REF> references =
m_dataModel->GetRowReferences( row );
369 if( &ref.GetFootprint() == footprint )
383 for(
int col = 0; col <
m_dataModel->GetNumberCols(); col++ )
389 else if( anyCol == -1 &&
m_dataModel->GetShowColumn( col ) )
393 if( valueCol != -1 &&
m_dataModel->GetShowColumn( valueCol ) )
394 m_grid->GoToCell( row, valueCol );
395 else if( refCol != -1 &&
m_dataModel->GetShowColumn( refCol ) )
396 m_grid->GoToCell( row, refCol );
397 else if( anyCol != -1 )
398 m_grid->GoToCell( row, anyCol );
416 if( !
m_grid->CommitPendingChanges() )
419 if( !wxDialog::TransferDataFromWindow() )
429 wxString currentVariant =
m_parent->GetBoard()->GetCurrentVariant();
433 if( !commit.
Empty() )
435 commit.
Push( wxS(
"Footprint Fields Table Edit" ) );
448 auto addMandatoryField =
449 [&](
FIELD_T aFieldId,
bool aShow,
bool aGroupBy )
470 std::set<wxString> userFieldNames;
478 if( !field->IsMandatory() && !field->IsPrivate() )
479 userFieldNames.insert( field->GetName() );
483 for(
const wxString& fieldName : userFieldNames )
489 if( userFieldNames.count( templateField.m_Name ) == 0 )
500 if( aScope == SCOPE::SCOPE_SELECTION )
509 std::unordered_set<KIID_PATH> selectionItems;
513 auto addSelectionItem = [&](
EDA_ITEM* aItem )
518 footprint =
static_cast<FOOTPRINT*
>( aItem );
519 else if( aItem->GetParent() && aItem->GetParent()->Type() ==
PCB_FOOTPRINT_T )
520 footprint =
static_cast<FOOTPRINT*
>( aItem->GetParent() );
526 selectionItems.insert(
path );
535 addSelectionItem( item );
544 switch( aEvent.GetSelection() )
546 case 0:
setScope( SCOPE::SCOPE_ALL );
break;
547 case 1:
setScope( SCOPE::SCOPE_SHEET );
break;
548 case 2:
setScope( SCOPE::SCOPE_SHEET_RECURSIVE );
break;
549 case 3:
setScope( SCOPE::SCOPE_SELECTION );
break;
560 _(
"Show footprints marked 'DNP' in the table. This setting also controls whether or not 'DNP' "
561 "footprints are included on export." ),
566 _(
"Show footprints marked 'Exclude from BOM' in the table. Footprints marked 'Exclude from BOM' "
567 "are never included on export." ),
571 menu.AppendSeparator();
574 _(
"Highlight corresponding item on canvas when it is selected in the table" ),
579 _(
"Select corresponding item on canvas when it is selected in the table" ),
584 int menuId =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
627 if(
m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
632 std::set<BOARD_ITEM*> footprints;
634 for(
int row : aRows )
637 footprints.insert( &ref.GetFootprint() );
640 std::vector<BOARD_ITEM*> focusItems( footprints.begin(), footprints.end() );
644 m_parent->FocusOnItems( focusItems );
668 EndModal( wxID_CANCEL );
710 m_grid->CommitPendingChanges(
true );
729 m_parent->GetBoard()->RemoveListener(
this );
732 wxCommandEvent*
event =
new wxCommandEvent( EDA_EVT_CLOSE_DIALOG_FOOTPRINT_FIELDS_TABLE, wxID_ANY );
734 if( wxWindow* parentWindow = GetParent() )
735 wxQueueEvent( parentWindow, event );
749 bool selectionScope =
m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION;
751 if( addedRefs.empty() && !selectionScope )
759 for(
PCB_FIELD* field : ref.GetFootprint().GetFields() )
761 if( !field->IsMandatory() && !field->IsPrivate() )
762 AddField( field->GetUntranslatedName(), field->GetName(),
true,
false,
false );
796 bool selectionScope =
m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION;
798 if( changedRefs.empty() && !selectionScope )
806 for(
PCB_FIELD* field : ref.GetFootprint().GetFields() )
808 if( !field->IsMandatory() && !field->IsPrivate() )
809 AddField( field->GetUntranslatedName(), field->GetName(),
true,
false,
false );
821 wxUnusedVar( aEvent );
832 if(
m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
847 if(
m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
889 wxString currentVariant;
896 m_grid->CommitPendingChanges(
true );
899 m_parent->SetCurrentVariant( selectedVariant );
916 currentVariant =
m_parent->GetBoard()->GetCurrentVariant();
918 if( currentVariant != selectedVariant )
919 m_parent->SetCurrentVariant( selectedVariant );
926 if( currentVariant != selectedVariant )
928 m_grid->CommitPendingChanges(
true );
934 if( !commit.
Empty() )
936 commit.
Push( wxS(
"Footprint Fields Table Edit" ) );
972 return m_parent->GetBoard()->GetCurrentVariant();
978 return m_parent->GetBoard()->ResolveTextVar( aToken, 0 );
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
STD_BITMAP_BUTTON * m_addVariantButton
STD_BITMAP_BUTTON * m_renameVariantButton
wxTextCtrl * m_outputFileName
wxChoice * m_cbBomFmtPresets
wxButton * m_buttonExport
STD_BITMAP_BUTTON * m_copyVariantButton
STD_BITMAP_BUTTON * m_bMenu
STD_BITMAP_BUTTON * m_deleteVariantButton
STD_BITMAP_BUTTON * m_editVariantDescButton
WX_GRID * m_viewControlsGrid
wxListBox * m_variantListBox
wxChoice * m_cbBomPresets
wxCheckBox * m_groupSymbolsBox
void saveJobSettings(JOB_EXPORT_BOM &aJob)
void SetUserBomFmtPresets(std::vector< BOM_FMT_PRESET > &aPresetList)
wxSize GetDefaultDialogSize() const
void syncBomFmtPresetSelection()
void OnColMove(wxGridEvent &aEvent)
void EnableSelectionEvents()
void DisableSelectionEvents()
void OnColSort(wxGridEvent &aEvent)
void OnGridMouseMove(wxMouseEvent &aEvent)
bool savePresets(bool aSaveCurrentSettings)
wxString getSelectedVariant() const
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
static void loadJobBomFmtPreset(const JOB_EXPORT_BOM &aJob, BOM_FMT_PRESET &aPreset)
FIELDS_TABLE_SETTINGS & m_cfgDialogSettings
static void loadJobBomPreset(const JOB_EXPORT_BOM &aJob, BOM_PRESET &aPreset)
void onBomPresetChanged(wxCommandEvent &aEvent)
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)
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...
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
EDA_ITEM * GetParent() const
static const wxString QUANTITY_VARIABLE
static const wxString ITEM_NUMBER_VARIABLE
FIELDS_TABLE_GRID_TRICKS(DIALOG_FIELDS_TABLE *aDialog, WX_GRID *aGrid, FIELDS_TABLE_DATA_MODEL_BASE *aDataModel)
static constexpr int FIRST_CLIENT_ID
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)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual wxString GetFootprint()
For items with footprint fields.
static TOOL_ACTION syncSelection
Sets selection to specified items, zooms to fit, if enabled.
The main frame for Pcbnew.
A set of BOARD_ITEMs (i.e., without duplicates).
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.
This file is part of the common library.
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ MYID_INCLUDE_EXCLUDED_FROM_BOM
@ MYID_HIGHLIGHT_ON_CROSS_PROBE
@ MYID_SELECT_ON_CROSS_PROBE
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.
#define SHOW_FIELD_COLUMN
@ GRIDTRICKS_FIRST_SHOWHIDE
Class to handle a set of BOARD_ITEMs.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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".
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint