KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_fields_table.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) Mike Williams
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <map>
24#include <set>
25#include <vector>
26
28#include <grid_tricks.h>
29#include <kiid.h>
31
33enum class FIELD_T : int;
34
36class JOB_EXPORT_BOM;
38class wxGridCellEditor;
39
40
42
43
45{
46public:
47 static constexpr int FIRST_CLIENT_ID = GRIDTRICKS_FIRST_CLIENT_ID + 2;
48
50 FIELDS_TABLE_DATA_MODEL_BASE* aDataModel );
51
52protected:
53 void showPopupMenu( wxMenu& aMenu, wxGridEvent& aEvent ) override;
54 void appendPopupMenuItems( wxMenu& aMenu ) override;
55 void doPopupSelection( wxCommandEvent& aEvent ) override;
56
57 virtual void showFieldsTablePopupMenu( wxMenu& aMenu, wxGridEvent& aEvent );
58 virtual void doFieldsTablePopupSelection( wxCommandEvent& aEvent );
59
60private:
61 void copyFromVariant( const wxString& aVariant, const std::vector<wxGridCellCoords>& aCells );
62
65};
66
67
69{
71
72public:
73 DIALOG_FIELDS_TABLE( wxWindow* aParent, FIELDS_TABLE_SETTINGS& aPanelSettings,
74 FIELDS_TABLE_BOM_SETTINGS& aBomSettings, JOB_EXPORT_BOM* aJob );
75 ~DIALOG_FIELDS_TABLE() override;
76
77 void ShowEditTab();
78 void ShowExportTab();
79 void ShowHideColumn( int aCol, bool aShow );
80
86 static wxString GetDefaultBomFileName( const wxString& aInputFileName );
87
88 std::vector<BOM_PRESET> GetUserBomPresets() const;
89 void SetUserBomPresets( std::vector<BOM_PRESET>& aPresetList );
90 void ApplyBomPreset( const wxString& aPresetName );
91 void ApplyBomPreset( const BOM_PRESET& aPreset );
92
96 std::vector<BOM_FMT_PRESET> GetUserBomFmtPresets() const;
97 void SetUserBomFmtPresets( std::vector<BOM_FMT_PRESET>& aPresetList );
98 void ApplyBomFmtPreset( const wxString& aPresetName );
99 void ApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset );
100
101
102protected:
103 wxSize GetDefaultDialogSize() const;
104
107 void OnTableRangeSelectionChanged( wxGridRangeSelectEvent& aEvent );
108
110 std::set<int> GetSelectedGridRows() const;
111
113 std::set<KIID_PATH> SaveGridSelection();
114
116 void RestoreGridSelection( const std::set<KIID_PATH>& aItemKeys );
117
118 void AddField( const wxString& aFieldName, const wxString& aLabelValue, bool aShow, bool aGroupBy,
119 bool aAddedByUser = false );
120
121 void SetReadOnly( bool aReadOnly );
122
123 static void loadJobBomPreset( const JOB_EXPORT_BOM& aJob, BOM_PRESET& aPreset );
124 static void loadJobBomFmtPreset( const JOB_EXPORT_BOM& aJob, BOM_FMT_PRESET& aPreset );
125 void saveJobSettings( JOB_EXPORT_BOM& aJob );
126
127 bool savePresets( bool aSaveCurrentSettings );
128
129
130 void RestorePanelLayout();
131 void SavePanelLayout();
132 void SaveColumnWidths();
133
134 void SetupColumnProperties( int aCol );
137
138 virtual wxGridCellEditor* createReferenceEditor();
139 virtual wxGridCellEditor* createFootprintEditor();
140 virtual wxGridCellEditor* createDatasheetEditor() = 0;
141 virtual void onBomSettingsChanged();
142
143 // Set bitmap and tooltip according to left panel visibility
144 void setSideBarButtonLook( bool aIsLeftPanelCollapsed );
145
146 void OnTableValueChanged( wxGridEvent& event ) override;
147 void OnTableColSize( wxGridSizeEvent& event ) override;
148 void OnTableLabelClick( wxGridEvent& event ) override;
149 virtual void OnTableSelectionChanged( const std::set<int>& aRows ) = 0;
150 void OnSizeViewControlsGrid( wxSizeEvent& event ) override;
151 void OnViewControlsCellChanged( wxGridEvent& aEvent ) override;
152
153 void OnAddField( wxCommandEvent& aEvent ) override;
154 void OnRemoveField( wxCommandEvent& aEvent ) override;
155 void OnRenameField( wxCommandEvent& aEvent ) override;
156
157 void OnFilterMouseMoved( wxMouseEvent& event ) override;
158 void OnFilterText( wxCommandEvent& aEvent ) override;
159 void OnFilterScope( wxCommandEvent& aEvent ) override;
160 void OnGroupSymbolsToggled( wxCommandEvent& aEvent ) override;
161 void OnRegroupSymbols( wxCommandEvent& aEvent ) override;
162 void OnColSort( wxGridEvent& aEvent );
163 void OnColMove( wxGridEvent& aEvent );
164 void OnGridMouseMove( wxMouseEvent& aEvent );
165 void OnGridMouseWheel( wxMouseEvent& aEvent );
166
167 void OnPageChanged( wxNotebookEvent& aEvent ) override;
168 void OnPreviewRefresh( wxCommandEvent& aEvent ) override;
169 void OnOutputFileBrowseClicked( wxCommandEvent& aEvent ) override;
170 void OnExport( wxCommandEvent& aEvent ) override;
171 void OnSidebarToggle( wxCommandEvent& event ) override;
172
173 void PreviewRefresh();
174
175 wxString getSelectedVariant() const;
176
179 int presetDashDashDashIndex( int aPresetCount ) const;
180 int presetSavePresetIndex( int aPresetCount ) const;
181 int presetDeletePresetIndex( int aPresetCount ) const;
182 void updateBomPresetSelection( const wxString& aName );
183 void onBomPresetChanged( wxCommandEvent& aEvent );
185 virtual std::vector<BOM_PRESET> getBuiltInBomPresets() const;
186 void doApplyBomPreset( const BOM_PRESET& aPreset );
187 BOM_PRESET getDataModelBomPreset();
188
191 void updateBomFmtPresetSelection( const wxString& aName );
192 void onBomFmtPresetChanged( wxCommandEvent& aEvent );
194 void doApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset );
195
197 virtual wxString resolveVariant() const = 0;
198 virtual bool resolveTextVar( wxString* aToken ) const = 0;
199
200protected:
204
207 int m_expanderWidth = 0; // wxFormBuilder width, in DIP
208
209 // Index in the fields list control for each MANDATORY_FIELD type
210 std::map<FIELD_T, int> m_mandatoryFieldListIndexes;
211
212 std::map<wxString, BOM_PRESET> m_bomPresets;
213 BOM_PRESET* m_currentBomPreset = nullptr;
214 BOM_PRESET* m_lastSelectedBomPreset = nullptr;
215 wxArrayString m_bomPresetMRU;
216
217 std::map<wxString, BOM_FMT_PRESET> m_bomFmtPresets;
220 wxArrayString m_bomFmtPresetMRU;
221
222};
DIALOG_FIELDS_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Fields Table"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER)
std::map< wxString, BOM_PRESET > m_bomPresets
BOM_PRESET * m_lastSelectedBomPreset
void saveJobSettings(JOB_EXPORT_BOM &aJob)
virtual wxGridCellEditor * createReferenceEditor()
void SetUserBomFmtPresets(std::vector< BOM_FMT_PRESET > &aPresetList)
wxSize GetDefaultDialogSize() const
virtual wxGridCellEditor * createDatasheetEditor()=0
virtual bool resolveTextVar(wxString *aToken) const =0
BOM_FMT_PRESET * m_lastSelectedBomFmtPreset
void OnColMove(wxGridEvent &aEvent)
int presetDashDashDashIndex(int aPresetCount) const
void OnColSort(wxGridEvent &aEvent)
void OnGridMouseMove(wxMouseEvent &aEvent)
bool savePresets(bool aSaveCurrentSettings)
wxArrayString m_bomFmtPresetMRU
void OnSizeViewControlsGrid(wxSizeEvent &event) override
void OnViewControlsCellChanged(wxGridEvent &aEvent) override
BOM_FMT_PRESET * m_currentBomFmtPreset
int presetDeletePresetIndex(int aPresetCount) const
void OnTableRangeSelectionChanged(wxGridRangeSelectEvent &aEvent)
wxString getSelectedVariant() const
void doApplyBomFmtPreset(const BOM_FMT_PRESET &aPreset)
void OnFilterText(wxCommandEvent &aEvent) override
void doApplyBomPreset(const BOM_PRESET &aPreset)
void OnPageChanged(wxNotebookEvent &aEvent) override
void ShowHideColumn(int aCol, bool aShow)
void OnExport(wxCommandEvent &aEvent) override
virtual void OnTableSelectionChanged(const std::set< int > &aRows)=0
void updateBomPresetSelection(const wxString &aName)
void OnFilterScope(wxCommandEvent &aEvent) override
BOM_FMT_PRESET GetCurrentBomFmtSettings()
Returns a formatting configuration corresponding to the values in the UI controls of the dialog.
void RestoreGridSelection(const std::set< KIID_PATH > &aItemKeys)
Restore a selection previously returned by SaveGridSelection().
std::map< FIELD_T, int > m_mandatoryFieldListIndexes
virtual wxGridCellEditor * createFootprintEditor()
void onBomFmtPresetChanged(wxCommandEvent &aEvent)
int presetSavePresetIndex(int aPresetCount) const
void OnRenameField(wxCommandEvent &aEvent) override
void OnGroupSymbolsToggled(wxCommandEvent &aEvent) override
void OnPreviewRefresh(wxCommandEvent &aEvent) override
virtual std::vector< BOM_PRESET > getBuiltInBomPresets() const
void updateBomFmtPresetSelection(const wxString &aName)
void OnTableColSize(wxGridSizeEvent &event) override
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)
void SetupColumnProperties(int aCol)
friend class FIELDS_TABLE_GRID_TRICKS
FIELDS_TABLE_BOM_SETTINGS & m_cfgBomSettings
static void loadJobBomFmtPreset(const JOB_EXPORT_BOM &aJob, BOM_FMT_PRESET &aPreset)
FIELDS_TABLE_SETTINGS & m_cfgDialogSettings
std::map< wxString, BOM_FMT_PRESET > m_bomFmtPresets
static void loadJobBomPreset(const JOB_EXPORT_BOM &aJob, BOM_PRESET &aPreset)
virtual wxString resolveVariant() const =0
std::set< int > GetSelectedGridRows() const
Return the explicitly selected grid rows, or the cursor row if the selection is empty.
void OnGridMouseWheel(wxMouseEvent &aEvent)
void OnSidebarToggle(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &aEvent) override
std::vector< BOM_PRESET > GetUserBomPresets() const
void onBomPresetChanged(wxCommandEvent &aEvent)
virtual void onBomSettingsChanged()
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 OnFilterMouseMoved(wxMouseEvent &event) override
void OnRegroupSymbols(wxCommandEvent &aEvent) override
void OnOutputFileBrowseClicked(wxCommandEvent &aEvent) override
void OnTableValueChanged(wxGridEvent &event) override
virtual FIELDS_TABLE_DATA_MODEL_BASE * getDataModel() const =0
VIEW_CONTROLS_GRID_DATA_MODEL * m_viewControlsDataModel
static wxString GetDefaultBomFileName(const wxString &aInputFileName)
Derive the default BOM output file name from the input file name by swapping the extension to CSV.
std::vector< BOM_FMT_PRESET > GetUserBomFmtPresets() const
void OnTableLabelClick(wxGridEvent &event) override
void setSideBarButtonLook(bool aIsLeftPanelCollapsed)
void AddField(const wxString &aFieldName, const wxString &aLabelValue, bool aShow, bool aGroupBy, bool aAddedByUser=false)
void OnRemoveField(wxCommandEvent &aEvent) override
Contains everything completly generic to fields tables data models, as well as column functionality t...
DIALOG_FIELDS_TABLE * m_dialog
FIELDS_TABLE_GRID_TRICKS(DIALOG_FIELDS_TABLE *aDialog, WX_GRID *aGrid, FIELDS_TABLE_DATA_MODEL_BASE *aDataModel)
virtual void showFieldsTablePopupMenu(wxMenu &aMenu, wxGridEvent &aEvent)
static constexpr int FIRST_CLIENT_ID
void appendPopupMenuItems(wxMenu &aMenu) override
void copyFromVariant(const wxString &aVariant, const std::vector< wxGridCellCoords > &aCells)
FIELDS_TABLE_DATA_MODEL_BASE * m_dataModel
void doPopupSelection(wxCommandEvent &aEvent) override
void showPopupMenu(wxMenu &aMenu, wxGridEvent &aEvent) override
virtual void doFieldsTablePopupSelection(wxCommandEvent &aEvent)
GRID_TRICKS(WX_GRID *aGrid)
@ GRIDTRICKS_FIRST_CLIENT_ID
Definition grid_tricks.h:44
Dialog settings for the lib/symbol/footprint table editors across the various editors.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...