KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_drill_chart_options.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <iterator>
23#include <set>
24
25#include <board.h>
28#include <confirm.h>
31#include <pcb_drill_chart.h>
32
33#include <wx/filedlg.h>
34#include <wx/filename.h>
35
36
37namespace
38{
39
46
47} // namespace
48
49
54
55
57{
58 const PCB_DRILL_CHART& chart = static_cast<const PCB_DRILL_CHART&>( aTable );
59 const DRILL_CHART_FILTER& filter = chart.Filter();
60
61 m_filterPlated->SetValue( filter.m_Plated );
62 m_filterNonPlated->SetValue( filter.m_NonPlated );
63 m_filterVias->SetValue( filter.m_Vias );
64 m_filterSlots->SetValue( filter.m_Slots );
65 m_filterBackdrills->SetValue( filter.m_Backdrills );
66 m_filterCastellated->SetValue( filter.m_Castellated );
67
68 m_showTotals->SetValue( chart.GetShowTotals() );
69
70 if( const BOARD* board = chart.GetBoard() )
71 {
72 const DRILL_SYMBOL_PROFILE& profile = board->GetDesignSettings().GetDrillSymbolProfile();
73
74 for( size_t row = 0; row < std::size( g_groupKeyRows ); ++row )
75 m_groupByList->Check( row, profile.IsGroupedBy( g_groupKeyRows[row] ) );
76 }
77}
78
79
81{
82 PCB_DRILL_CHART& chart = static_cast<PCB_DRILL_CHART&>( aTable );
84
85 filter.m_Plated = m_filterPlated->GetValue();
86 filter.m_NonPlated = m_filterNonPlated->GetValue();
87 filter.m_Vias = m_filterVias->GetValue();
88 filter.m_Slots = m_filterSlots->GetValue();
89 filter.m_Backdrills = m_filterBackdrills->GetValue();
90 filter.m_Castellated = m_filterCastellated->GetValue();
91
92 chart.SetShowTotals( m_showTotals->GetValue() );
93
94 DRILL_SYMBOL_PROFILE& profile = aRefresh.Pending<DRILL_PROFILE_PENDING>().m_Profile;
95 const std::set<DRILL_GROUP_KEY> wasGroupedBy = profile.GroupKeys();
96
97 for( size_t row = 0; row < std::size( g_groupKeyRows ); ++row )
98 profile.SetGroupedBy( g_groupKeyRows[row], m_groupByList->IsChecked( row ) );
99
100 if( profile.GroupKeys() != wasGroupedBy && chart.GetBoard() )
101 {
102 // Grouping is board-wide, so every other chart and map has to be rebuilt against it.
103 // Only a cache key, so an OK that later fails costs one needless rebuild and nothing else
105 }
106
107 return true;
108}
109
110
112{
113 wxFileDialog dlg( this, _( "Import Drill Chart Template" ), wxEmptyString, wxEmptyString,
114 _( "Drill chart templates" ) + wxT( " (*.json)|*.json" ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
115
116 if( dlg.ShowModal() != wxID_OK )
117 return;
118
120 wxString error;
121
122 if( !tmpl.LoadFromFile( dlg.GetPath(), &error ) )
123 {
124 DisplayError( this, error );
125 return;
126 }
127
129 format.m_Columns = tmpl.Columns();
130 format.m_Units = tmpl.GetUnits();
131 format.m_Precision = tmpl.GetPrecision();
132
133 m_SetFormat( format );
134 m_showTotals->SetValue( tmpl.GetShowTotals() );
135}
136
137
139{
140 std::optional<GENERATED_TABLE_FORMAT> format = m_GetFormat();
141
142 if( !format )
143 return;
144
145 wxFileDialog dlg( this, _( "Export Drill Chart Template" ), wxEmptyString, wxT( "drill_chart" ),
146 _( "Drill chart templates" ) + wxT( " (*.json)|*.json" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
147
148 if( dlg.ShowModal() != wxID_OK )
149 return;
150
152
153 // The file names the template, so whoever opens the json can tell which one it is
154 tmpl.SetName( wxFileName( dlg.GetPath() ).GetName() );
155 tmpl.SetUnits( format->m_Units );
156 tmpl.SetPrecision( format->m_Precision );
157 tmpl.SetShowTotals( m_showTotals->GetValue() );
158 tmpl.Columns() = format->m_Columns;
159
160 wxString error;
161
162 if( !tmpl.SaveToFile( dlg.GetPath(), &error ) )
163 DisplayError( this, error );
164}
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
void BumpDrillModelGeneration()
Bumped whenever anything a drill chart or map reports on has moved.
Definition board.cpp:179
The column set and formatting a new chart starts from.
bool SaveToFile(const wxString &aPath, wxString *aError) const
Read and write a template as JSON.
void SetName(const wxString &aName)
void SetPrecision(int aPrecision)
GENERATED_TABLE_UNITS GetUnits() const
void SetShowTotals(bool aShow)
std::vector< GENERATED_TABLE_COLUMN > & Columns()
bool LoadFromFile(const wxString &aPath, wxString *aError)
void SetUnits(GENERATED_TABLE_UNITS aUnits)
Grouping rules and symbol assignments, shared by reference so a chart and its map can never disagree ...
bool IsGroupedBy(DRILL_GROUP_KEY aKey) const
void SetGroupedBy(DRILL_GROUP_KEY aKey, bool aOn)
const std::set< DRILL_GROUP_KEY > & GroupKeys() const
std::function< std::optional< GENERATED_TABLE_FORMAT >()> m_GetFormat
The dialog's columns, units and precision as edited so far, or nothing when a grid edit is invalid.
std::function< void(const GENERATED_TABLE_FORMAT &)> m_SetFormat
Hands the dialog a new column set, units and precision, e.g. from an imported template.
One pass of rebuilding tables.
T & Pending()
The pass's T, created from the board on first use.
PANEL_DRILL_CHART_OPTIONS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void onImportTemplate(wxCommandEvent &aEvent) override
void TransferToWindow(const PCB_GENERATED_TABLE &aTable) override
void onExportTemplate(wxCommandEvent &aEvent) override
bool TransferFromWindow(PCB_GENERATED_TABLE &aTable, GENERATED_TABLE_REFRESH &aRefresh) override
Applies to the table. Board state goes into aRefresh so Cancel leaves the board alone.
A drill chart placed on the board, kept in step with the holes.
void SetShowTotals(bool aShow)
bool GetShowTotals() const
DRILL_CHART_FILTER & Filter()
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
DRILL_GROUP_KEY
Which properties split holes into separate chart rows and symbols.
#define _(s)
Which holes a chart reports on.
The board's drill symbol profile as a refresh assigns new symbols into it.
What the shared dialog edits that a template also carries.
std::vector< GENERATED_TABLE_COLUMN > m_Columns
Shown columns only, in table order.