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 The 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#include <wx/msgdlg.h>
31#include <confirm.h>
32
36static const std::vector<int> s_outsetPresetValue{
37 // Outsetting a 0.1mm line to touch a 0.1mm line
38 pcbIUScale.mmToIU( 0.1 ),
39 // 0.12mm line to touch a 0.1mm line
40 pcbIUScale.mmToIU( 0.11 ),
41 // IPC dense courtyard
42 pcbIUScale.mmToIU( 0.15 ),
43 // IPC normal courtyard
44 pcbIUScale.mmToIU( 0.25 ),
45 // Keep 0.12mm silkscreen line 0.2mm from copper
46 pcbIUScale.mmToIU( 0.26 ),
47 // IPC connector courtyard
48 pcbIUScale.mmToIU( 0.5 ),
49 // Common router bits
50 pcbIUScale.mmToIU( 1.0 ),
51 pcbIUScale.mmToIU( 2.0 ),
52};
53
54// Ther user can also get the current board design settings widths
55// with the "Layer Default" button.
56static const std::vector<int> s_presetLineWidths{
57 // Courtyard
58 pcbIUScale.mmToIU( 0.05 ),
59 pcbIUScale.mmToIU( 0.1 ),
60 // Silkscreen
61 pcbIUScale.mmToIU( 0.12 ),
62 pcbIUScale.mmToIU( 0.15 ),
63 pcbIUScale.mmToIU( 0.2 ),
64};
65
66static const std::vector<int> s_presetGridRounding{
67 // 0.01 is a common IPC grid round-off value
68 pcbIUScale.mmToIU( 0.01 ),
69};
70
72
73static std::vector<int> s_outsetRecentValues;
74static std::vector<int> s_lineWidthRecentValues;
75static std::vector<int> s_gridRoundingRecentValues;
76
77
80 DIALOG_OUTSET_ITEMS_BASE( &aParent ),
81 m_parent( aParent ),
82 m_params( aParams ),
83 m_outset( &aParent, m_outsetLabel, m_outsetEntry, m_outsetUnit ),
84 m_lineWidth( &aParent, m_lineWidthLabel, m_lineWidthEntry, m_lineWidthUnit ),
85 m_roundingGrid( &aParent, m_gridRoundingLabel, m_gridRoundingEntry, m_gridRoundingUnit )
86{
91
92 const auto fillOptionList =
93 [&]( UNIT_BINDER& aCombo, const std::vector<int>& aPresets, const std::vector<int>& aRecentPresets )
94 {
95 std::vector<long long int> optionList;
96 optionList.reserve( aPresets.size() + aRecentPresets.size() );
97
98 for( const int val : aPresets )
99 optionList.push_back( val );
100
101 for( const int val : aRecentPresets )
102 optionList.push_back( val );
103
104 // Sort the vector and remove duplicates
105 std::sort( optionList.begin(), optionList.end() );
106 optionList.erase( std::unique( optionList.begin(), optionList.end() ), optionList.end() );
107
108 aCombo.SetOptionsList( optionList );
109 };
110
114
117}
118
119
121{
122}
123
124
125void DIALOG_OUTSET_ITEMS::OnLayerDefaultClick( wxCommandEvent& event )
126{
128
130 const int defaultWidth = settings.GetLineThickness( selLayer );
131
132 m_lineWidth.SetValue( defaultWidth );
133}
134
135
136void DIALOG_OUTSET_ITEMS::OnCopyLayersChecked( wxCommandEvent& event )
137{
138 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
139}
140
141
142void DIALOG_OUTSET_ITEMS::OnRoundToGridChecked( wxCommandEvent& event )
143{
144 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
145}
146
147
149{
154
155 m_roundToGrid->SetValue( m_params.gridRounding.has_value() );
156
158
161
162 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
163 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
164
166
167 return true;
168}
169
170
172{
173 if( m_outset.GetIntValue() <= 0 )
174 {
175 DisplayErrorMessage( this, _( "Outset must be a positive value." ) );
176 return false;
177 }
178
179 if( m_lineWidth.GetIntValue() <= 0 )
180 {
181 DisplayErrorMessage( this, _( "Line width must be a positive value." ) );
182 return false;
183 }
184
189
192
193 if( m_roundToGrid->IsChecked() )
195 else
196 m_params.gridRounding = std::nullopt;
197
199
201
202 // Keep the recent values list up to date
203 const auto saveRecentValue =
204 []( std::vector<int>& aRecentValues, int aValue )
205 {
206 const auto it = std::find( aRecentValues.begin(), aRecentValues.end(), aValue );
207
208 // Already have it
209 if( it != aRecentValues.end() )
210 return;
211
212 aRecentValues.push_back( aValue );
213 };
214
215 saveRecentValue( s_outsetRecentValues, m_params.outsetDistance );
216 saveRecentValue( s_lineWidthRecentValues, m_params.lineWidth );
217
219 saveRecentValue( s_gridRoundingRecentValues, m_params.gridRounding.value() );
220
221 return true;
222}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
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:1024
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)
int GetIntValue()
Definition: unit_binder.h:134
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.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
This file is part of the common library.
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
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:744
constexpr int mmToIU(double mm) const
Definition: base_units.h:92