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 ),
86{
87 m_LayerSelectionCtrl->ShowNonActivatedLayers( false );
88 m_LayerSelectionCtrl->SetLayersHotkeys( false );
89 m_LayerSelectionCtrl->SetBoardFrame( &aParent );
90 m_LayerSelectionCtrl->Resync();
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
123
124
125void DIALOG_OUTSET_ITEMS::OnLayerDefaultClick( wxCommandEvent& event )
126{
127 const BOARD_DESIGN_SETTINGS& settings = m_parent.GetBoard()->GetDesignSettings();
128
129 const PCB_LAYER_ID selLayer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
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{
150 m_LayerSelectionCtrl->SetLayerSelection( m_params.layer );
151 m_outset.SetValue( m_params.outsetDistance );
152 m_roundCorners->SetValue( m_params.roundCorners );
153 m_lineWidth.SetValue( m_params.lineWidth );
154
155 m_roundToGrid->SetValue( m_params.gridRounding.has_value() );
156
157 m_roundingGrid.SetValue( m_params.gridRounding.value_or( s_gridRoundValuePersist ) );
158
159 m_copyLayers->SetValue( m_params.useSourceLayers );
160 m_copyWidths->SetValue( m_params.useSourceWidths );
161
162 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
163 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
164
165 m_deleteSourceItems->SetValue( m_params.deleteSourceItems );
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
185 m_params.layer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
186 m_params.outsetDistance = m_outset.GetIntValue();
187 m_params.roundCorners = m_roundCorners->GetValue();
188 m_params.lineWidth = m_lineWidth.GetIntValue();
189
190 m_params.useSourceLayers = m_copyLayers->GetValue();
191 m_params.useSourceWidths = m_copyWidths->GetValue();
192
193 if( m_roundToGrid->IsChecked() )
194 m_params.gridRounding = m_roundingGrid.GetValue();
195 else
196 m_params.gridRounding = std::nullopt;
197
199
200 m_params.deleteSourceItems = m_deleteSourceItems->GetValue();
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
218 if( m_params.gridRounding )
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.
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: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:737