KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_outset_items.cpp
Go to the documentation of this file.
1
2/*
3 * This program source code file is part of KiCad, a free EDA CAD application.
4 *
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26
27#include <board.h>
30
34static const std::vector<int> s_outsetPresetValue{
35 // Outsetting a 0.1mm line to touch a 0.1mm line
36 pcbIUScale.mmToIU( 0.1 ),
37 // 0.12mm line to touch a 0.1mm line
38 pcbIUScale.mmToIU( 0.11 ),
39 // IPC dense courtyard
40 pcbIUScale.mmToIU( 0.15 ),
41 // IPC normal courtyard
42 pcbIUScale.mmToIU( 0.25 ),
43 // Keep 0.12mm silkscreen line 0.2mm from copper
44 pcbIUScale.mmToIU( 0.26 ),
45 // IPC connector courtyard
46 pcbIUScale.mmToIU( 0.5 ),
47 // Common router bits
48 pcbIUScale.mmToIU( 1.0 ),
49 pcbIUScale.mmToIU( 2.0 ),
50};
51
52// Ther user can also get the current board design settings widths
53// with the "Layer Default" button.
54static const std::vector<int> s_presetLineWidths{
55 // Courtyard
56 pcbIUScale.mmToIU( 0.05 ),
57 pcbIUScale.mmToIU( 0.1 ),
58 // Silkscreen
59 pcbIUScale.mmToIU( 0.12 ),
60 pcbIUScale.mmToIU( 0.15 ),
61 pcbIUScale.mmToIU( 0.2 ),
62};
63
64static const std::vector<int> s_presetGridRounding{
65 // 0.01 is a common IPC grid round-off value
66 pcbIUScale.mmToIU( 0.01 ),
67};
68
70
71static std::vector<int> s_outsetRecentValues;
72static std::vector<int> s_lineWidthRecentValues;
73static std::vector<int> s_gridRoundingRecentValues;
74
77 DIALOG_OUTSET_ITEMS_BASE( &aParent ), m_parent( aParent ), m_params( aParams ),
78 m_outset( &aParent, m_outsetLabel, m_outsetEntry, m_outsetUnit ),
79 m_lineWidth( &aParent, m_lineWidthLabel, m_lineWidthEntry, m_lineWidthUnit ),
80 m_roundingGrid( &aParent, m_gridRoundingLabel, m_gridRoundingEntry, m_gridRoundingUnit )
81{
86
87 const auto fillOptionList = [&]( UNIT_BINDER& aCombo, const std::vector<int>& aPresets,
88 const std::vector<int>& aRecentPresets )
89 {
90 std::vector<long long int> optionList;
91 optionList.reserve( aPresets.size() + aRecentPresets.size() );
92
93 for( const int val : aPresets )
94 optionList.push_back( val );
95
96 for( const int val : aRecentPresets )
97 optionList.push_back( val );
98
99 // Sort the vector and remove duplicates
100 std::sort( optionList.begin(), optionList.end() );
101 optionList.erase( std::unique( optionList.begin(), optionList.end() ), optionList.end() );
102
103 aCombo.SetOptionsList( optionList );
104 };
105
109
112}
113
115{
116}
117
118void DIALOG_OUTSET_ITEMS::OnLayerDefaultClick( wxCommandEvent& event )
119{
121
123 const int defaultWidth = settings.GetLineThickness( selLayer );
124
125 m_lineWidth.SetValue( defaultWidth );
126}
127
128void DIALOG_OUTSET_ITEMS::OnCopyLayersChecked( wxCommandEvent& event )
129{
130 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
131}
132
133void DIALOG_OUTSET_ITEMS::OnRoundToGridChecked( wxCommandEvent& event )
134{
135 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
136}
137
139{
144
145 m_roundToGrid->SetValue( m_params.gridRounding.has_value() );
146
148
151
152 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
153 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
154
156
157 return true;
158}
159
161{
166
169
170 if( m_roundToGrid->IsChecked() )
172 else
173 m_params.gridRounding = std::nullopt;
174
176
178
179 // Keep the recent values list up to date
180 const auto saveRecentValue = []( std::vector<int>& aRecentValues, int aValue )
181 {
182 const auto it = std::find( aRecentValues.begin(), aRecentValues.end(), aValue );
183 // Already have it
184 if( it != aRecentValues.end() )
185 return;
186
187 aRecentValues.push_back( aValue );
188 };
189
190 saveRecentValue( s_outsetRecentValues, m_params.outsetDistance );
191 saveRecentValue( s_lineWidthRecentValues, m_params.lineWidth );
193 saveRecentValue( s_gridRoundingRecentValues, m_params.gridRounding.value() );
194
195 return true;
196}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
Container for design settings for a BOARD object.
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
Class DIALOG_OUTSET_ITEMS_BASE.
PCB_LAYER_BOX_SELECTOR * m_LayerSelectionCtrl
void OnLayerDefaultClick(wxCommandEvent &event) override
void OnCopyLayersChecked(wxCommandEvent &event) override
PCB_BASE_FRAME & m_parent
OUTSET_ROUTINE::PARAMETERS & m_params
bool TransferDataFromWindow() override
void OnRoundToGridChecked(wxCommandEvent &event) override
DIALOG_OUTSET_ITEMS(PCB_BASE_FRAME &aParent, OUTSET_ROUTINE::PARAMETERS &aParams)
bool TransferDataToWindow() override
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...
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void ShowNonActivatedLayers(bool aShow)
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetOptionsList(std::span< const long long int > aOptions)
Set the list of options for a combobox control.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
static const std::vector< int > s_presetGridRounding
static std::vector< int > s_lineWidthRecentValues
static std::vector< int > s_gridRoundingRecentValues
static int s_gridRoundValuePersist
static const std::vector< int > s_presetLineWidths
static const std::vector< int > s_outsetPresetValue
Some handy preset values for common outset distances.
static std::vector< int > s_outsetRecentValues
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
constexpr int mmToIU(double mm) const
Definition: base_units.h:88