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 doPopupSelection( wxCommandEvent& aEvent ) override;
55
56 virtual void showFieldsTablePopupMenu( wxMenu& aMenu, wxGridEvent& aEvent );
57 virtual void doFieldsTablePopupSelection( wxCommandEvent& aEvent );
58
59private:
62};
63
64
66{
67public:
68 DIALOG_FIELDS_TABLE( wxWindow* aParent, FIELDS_TABLE_SETTINGS& aPanelSettings,
69 FIELDS_TABLE_BOM_SETTINGS& aBomSettings, JOB_EXPORT_BOM* aJob );
70 ~DIALOG_FIELDS_TABLE() override;
71
72 void ShowEditTab();
73 void ShowExportTab();
74 void ShowHideColumn( int aCol, bool aShow );
75
81 static wxString GetDefaultBomFileName( const wxString& aInputFileName );
82
83 std::vector<BOM_PRESET> GetUserBomPresets() const;
84 void SetUserBomPresets( std::vector<BOM_PRESET>& aPresetList );
85 void ApplyBomPreset( const wxString& aPresetName );
86 void ApplyBomPreset( const BOM_PRESET& aPreset );
87
91 std::vector<BOM_FMT_PRESET> GetUserBomFmtPresets() const;
92 void SetUserBomFmtPresets( std::vector<BOM_FMT_PRESET>& aPresetList );
93 void ApplyBomFmtPreset( const wxString& aPresetName );
94 void ApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset );
95
96
97protected:
98 wxSize GetDefaultDialogSize() const;
99
102 void OnTableRangeSelectionChanged( wxGridRangeSelectEvent& aEvent );
103
105 std::set<int> GetSelectedGridRows() const;
106
108 std::set<KIID_PATH> SaveGridSelection();
109
111 void RestoreGridSelection( const std::set<KIID_PATH>& aItemKeys );
112
113 void AddField( const wxString& aFieldName, const wxString& aLabelValue, bool aShow, bool aGroupBy,
114 bool aAddedByUser = false );
115
116 void SetReadOnly( bool aReadOnly );
117
118 static void loadJobBomPreset( const JOB_EXPORT_BOM& aJob, BOM_PRESET& aPreset );
119 static void loadJobBomFmtPreset( const JOB_EXPORT_BOM& aJob, BOM_FMT_PRESET& aPreset );
120 void saveJobSettings( JOB_EXPORT_BOM& aJob );
121
122 bool savePresets( bool aSaveCurrentSettings );
123
124
125 void RestorePanelLayout();
126 void SavePanelLayout();
127 void SaveColumnWidths();
128
129 void SetupColumnProperties( int aCol );
131
132 virtual wxGridCellEditor* createReferenceEditor();
133 virtual wxGridCellEditor* createFootprintEditor();
134 virtual wxGridCellEditor* createDatasheetEditor() = 0;
135 virtual void onBomSettingsChanged();
136
137 // Set bitmap and tooltip according to left panel visibility
138 void setSideBarButtonLook( bool aIsLeftPanelCollapsed );
139
140 void OnTableCellClick( wxGridEvent& event ) override;
141 void OnTableValueChanged( wxGridEvent& event ) override;
142 void OnTableColSize( wxGridSizeEvent& event ) override;
143 virtual void OnTableSelectionChanged( const std::set<int>& aRows ) = 0;
144 void OnSizeViewControlsGrid( wxSizeEvent& event ) override;
145 void OnViewControlsCellChanged( wxGridEvent& aEvent ) override;
146
147 void OnAddField( wxCommandEvent& aEvent ) override;
148 void OnRemoveField( wxCommandEvent& aEvent ) override;
149 void OnRenameField( wxCommandEvent& aEvent ) override;
150
151 void OnFilterMouseMoved( wxMouseEvent& event ) override;
152 void OnFilterText( wxCommandEvent& aEvent ) override;
153 void OnFilterScope( wxCommandEvent& aEvent ) override;
154 void OnGroupSymbolsToggled( wxCommandEvent& aEvent ) override;
155 void OnRegroupSymbols( wxCommandEvent& aEvent ) override;
156 void OnColSort( wxGridEvent& aEvent );
157 void OnColMove( wxGridEvent& aEvent );
158 void OnGridMouseMove( wxMouseEvent& aEvent );
159 void OnGridMouseWheel( wxMouseEvent& aEvent );
160
161 void OnPageChanged( wxNotebookEvent& aEvent ) override;
162 void OnPreviewRefresh( wxCommandEvent& aEvent ) override;
163 void OnOutputFileBrowseClicked( wxCommandEvent& aEvent ) override;
164 void OnExport( wxCommandEvent& aEvent ) override;
165 void OnSidebarToggle( wxCommandEvent& event ) override;
166
167 void PreviewRefresh();
168
169 wxString getSelectedVariant() const;
170
173 int presetDashDashDashIndex( int aPresetCount ) const;
174 int presetSavePresetIndex( int aPresetCount ) const;
175 int presetDeletePresetIndex( int aPresetCount ) const;
176 void updateBomPresetSelection( const wxString& aName );
177 void onBomPresetChanged( wxCommandEvent& aEvent );
179 virtual std::vector<BOM_PRESET> getBuiltInBomPresets() const;
180 void doApplyBomPreset( const BOM_PRESET& aPreset );
181 BOM_PRESET getDataModelBomPreset();
182
185 void updateBomFmtPresetSelection( const wxString& aName );
186 void onBomFmtPresetChanged( wxCommandEvent& aEvent );
188 void doApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset );
189
191 virtual wxString resolveVariant() const = 0;
192 virtual bool resolveTextVar( wxString* aToken ) const = 0;
193
194protected:
198
201
202 // Index in the fields list control for each MANDATORY_FIELD type
203 std::map<FIELD_T, int> m_mandatoryFieldListIndexes;
204
205 std::map<wxString, BOM_PRESET> m_bomPresets;
206 BOM_PRESET* m_currentBomPreset = nullptr;
207 BOM_PRESET* m_lastSelectedBomPreset = nullptr;
208 wxArrayString m_bomPresetMRU;
209
210 std::map<wxString, BOM_FMT_PRESET> m_bomFmtPresets;
213 wxArrayString m_bomFmtPresetMRU;
214
215};
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 OnTableCellClick(wxGridEvent &event) override
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)
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 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
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...