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{
38 // Outsetting a 0.1mm line to touch a 0.1mm line
39 pcbIUScale.mmToIU( 0.1 ),
40 // 0.12mm line to touch a 0.1mm line
41 pcbIUScale.mmToIU( 0.11 ),
42 // IPC dense courtyard
43 pcbIUScale.mmToIU( 0.15 ),
44 // IPC normal courtyard
45 pcbIUScale.mmToIU( 0.25 ),
46 // Keep 0.12mm silkscreen line 0.2mm from copper
47 pcbIUScale.mmToIU( 0.26 ),
48 // IPC connector courtyard
49 pcbIUScale.mmToIU( 0.5 ),
50 // Common router bits
51 pcbIUScale.mmToIU( 1.0 ),
52 pcbIUScale.mmToIU( 2.0 ),
53};
54
55// Ther user can also get the current board design settings widths
56// with the "Layer Default" button.
57static const std::vector<int> s_presetLineWidths
58{
59 // Courtyard
60 pcbIUScale.mmToIU( 0.05 ),
61 pcbIUScale.mmToIU( 0.1 ),
62 // Silkscreen
63 pcbIUScale.mmToIU( 0.12 ),
64 pcbIUScale.mmToIU( 0.15 ),
65 pcbIUScale.mmToIU( 0.2 ),
66};
67
68static const std::vector<int> s_presetGridRounding
69{
70 // 0.01 is a common IPC grid round-off value
71 pcbIUScale.mmToIU( 0.01 ),
72};
73
75
76static std::vector<int> s_outsetRecentValues;
77static std::vector<int> s_lineWidthRecentValues;
78static std::vector<int> s_gridRoundingRecentValues;
79
80
82 DIALOG_OUTSET_ITEMS_BASE( &aParent ),
83 m_parent( aParent ),
84 m_params( aParams ),
88{
89 m_LayerSelectionCtrl->ShowNonActivatedLayers( false );
90 m_LayerSelectionCtrl->SetLayersHotkeys( false );
91 m_LayerSelectionCtrl->SetBoardFrame( &aParent );
92 m_LayerSelectionCtrl->Resync();
93
94 const auto fillOptionList =
95 [&]( UNIT_BINDER& aCombo, const std::vector<int>& aPresets, const std::vector<int>& aRecentPresets )
96 {
97 std::vector<long long int> optionList;
98 optionList.reserve( aPresets.size() + aRecentPresets.size() );
99
100 for( const int val : aPresets )
101 optionList.push_back( val );
102
103 for( const int val : aRecentPresets )
104 optionList.push_back( val );
105
106 // Sort the vector and remove duplicates
107 std::sort( optionList.begin(), optionList.end() );
108 optionList.erase( std::unique( optionList.begin(), optionList.end() ), optionList.end() );
109
110 aCombo.SetOptionsList( optionList );
111 };
112
116
119}
120
121
125
126
127void DIALOG_OUTSET_ITEMS::OnLayerDefaultClick( wxCommandEvent& event )
128{
129 const BOARD_DESIGN_SETTINGS& settings = m_parent.GetBoard()->GetDesignSettings();
130
131 const PCB_LAYER_ID selLayer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
132 const int defaultWidth = settings.GetLineThickness( selLayer );
133
134 m_lineWidth.SetValue( defaultWidth );
135}
136
137
138void DIALOG_OUTSET_ITEMS::OnCopyLayersChecked( wxCommandEvent& event )
139{
140 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
141}
142
143
144void DIALOG_OUTSET_ITEMS::OnRoundToGridChecked( wxCommandEvent& event )
145{
146 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
147}
148
149
151{
152 m_LayerSelectionCtrl->SetLayerSelection( m_params.layer );
153 m_outset.SetValue( m_params.outsetDistance );
154 m_roundCorners->SetValue( m_params.roundCorners );
155 m_lineWidth.SetValue( m_params.lineWidth );
156
157 m_roundToGrid->SetValue( m_params.gridRounding.has_value() );
158
159 m_roundingGrid.SetValue( m_params.gridRounding.value_or( s_gridRoundValuePersist ) );
160
161 m_copyLayers->SetValue( m_params.useSourceLayers );
162 m_copyWidths->SetValue( m_params.useSourceWidths );
163
164 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
165 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
166
167 m_deleteSourceItems->SetValue( m_params.deleteSourceItems );
168
169 return true;
170}
171
172
174{
175 if( m_lineWidth.GetIntValue() <= 0 )
176 {
177 DisplayErrorMessage( this, _( "Line width must be a positive value." ) );
178 return false;
179 }
180
181 m_params.layer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
182 m_params.outsetDistance = m_outset.GetIntValue();
183 m_params.roundCorners = m_roundCorners->GetValue();
184 m_params.lineWidth = m_lineWidth.GetIntValue();
185
186 m_params.useSourceLayers = m_copyLayers->GetValue();
187 m_params.useSourceWidths = m_copyWidths->GetValue();
188
189 if( m_roundToGrid->IsChecked() )
190 m_params.gridRounding = m_roundingGrid.GetValue();
191 else
192 m_params.gridRounding = std::nullopt;
193
195
196 m_params.deleteSourceItems = m_deleteSourceItems->GetValue();
197
198 // Keep the recent values list up to date
199 const auto saveRecentValue =
200 []( std::vector<int>& aRecentValues, int aValue )
201 {
202 const auto it = std::find( aRecentValues.begin(), aRecentValues.end(), aValue );
203
204 // Already have it
205 if( it != aRecentValues.end() )
206 return;
207
208 aRecentValues.push_back( aValue );
209 };
210
211 saveRecentValue( s_outsetRecentValues, m_params.outsetDistance );
212 saveRecentValue( s_lineWidthRecentValues, m_params.lineWidth );
213
214 if( m_params.gridRounding )
215 saveRecentValue( s_gridRoundingRecentValues, m_params.gridRounding.value() );
216
217 return true;
218}
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.
PCB_LAYER_BOX_SELECTOR * m_LayerSelectionCtrl
DIALOG_OUTSET_ITEMS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Outset Items"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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...
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual void SetOptionsList(std::span< const long long int > aOptions)
Set the list of options for a combobox control.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
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:754