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, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <board.h>
26#include <wx/msgdlg.h>
27#include <confirm.h>
28
32static const std::vector<int> s_outsetPresetValue
33{
34 // Outsetting a 0.1mm line to touch a 0.1mm line
35 pcbIUScale.mmToIU( 0.1 ),
36 // 0.12mm line to touch a 0.1mm line
37 pcbIUScale.mmToIU( 0.11 ),
38 // IPC dense courtyard
39 pcbIUScale.mmToIU( 0.15 ),
40 // IPC normal courtyard
41 pcbIUScale.mmToIU( 0.25 ),
42 // Keep 0.12mm silkscreen line 0.2mm from copper
43 pcbIUScale.mmToIU( 0.26 ),
44 // IPC connector courtyard
45 pcbIUScale.mmToIU( 0.5 ),
46 // Common router bits
47 pcbIUScale.mmToIU( 1.0 ),
48 pcbIUScale.mmToIU( 2.0 ),
49};
50
51// Ther user can also get the current board design settings widths
52// with the "Layer Default" button.
53static const std::vector<int> s_presetLineWidths
54{
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{
66 // 0.01 is a common IPC grid round-off value
67 pcbIUScale.mmToIU( 0.01 ),
68};
69
71
72static std::vector<int> s_outsetRecentValues;
73static std::vector<int> s_lineWidthRecentValues;
74static std::vector<int> s_gridRoundingRecentValues;
75
76
78 DIALOG_OUTSET_ITEMS_BASE( &aParent ),
79 m_parent( aParent ),
80 m_params( aParams ),
84{
85 m_LayerSelectionCtrl->ShowNonActivatedLayers( false );
86 m_LayerSelectionCtrl->SetLayersHotkeys( false );
87 m_LayerSelectionCtrl->SetBoardFrame( &aParent );
88 m_LayerSelectionCtrl->Resync();
89
90 const auto fillOptionList =
91 [&]( UNIT_BINDER& aCombo, const std::vector<int>& aPresets, const std::vector<int>& aRecentPresets )
92 {
93 std::vector<long long int> optionList;
94 optionList.reserve( aPresets.size() + aRecentPresets.size() );
95
96 for( const int val : aPresets )
97 optionList.push_back( val );
98
99 for( const int val : aRecentPresets )
100 optionList.push_back( val );
101
102 // Sort the vector and remove duplicates
103 std::sort( optionList.begin(), optionList.end() );
104 optionList.erase( std::unique( optionList.begin(), optionList.end() ), optionList.end() );
105
106 aCombo.SetOptionsList( optionList );
107 };
108
112
115}
116
117
121
122
123void DIALOG_OUTSET_ITEMS::OnLayerDefaultClick( wxCommandEvent& event )
124{
125 const BOARD_DESIGN_SETTINGS& settings = m_parent.GetBoard()->GetDesignSettings();
126
127 const PCB_LAYER_ID selLayer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
128 const int defaultWidth = settings.GetLineThickness( selLayer );
129
130 m_lineWidth.SetValue( defaultWidth );
131}
132
133
134void DIALOG_OUTSET_ITEMS::OnCopyLayersChecked( wxCommandEvent& event )
135{
136 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
137}
138
139
140void DIALOG_OUTSET_ITEMS::OnRoundToGridChecked( wxCommandEvent& event )
141{
142 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
143}
144
145
147{
148 m_LayerSelectionCtrl->SetLayerSelection( m_params.layer );
149 m_outset.SetValue( m_params.outsetDistance );
150 m_roundCorners->SetValue( m_params.roundCorners );
151 m_lineWidth.SetValue( m_params.lineWidth );
152
153 m_roundToGrid->SetValue( m_params.gridRounding.has_value() );
154
155 m_roundingGrid.SetValue( m_params.gridRounding.value_or( s_gridRoundValuePersist ) );
156
157 m_copyLayers->SetValue( m_params.useSourceLayers );
158 m_copyWidths->SetValue( m_params.useSourceWidths );
159
160 m_gridRoundingEntry->Enable( m_roundToGrid->IsChecked() );
161 m_LayerSelectionCtrl->Enable( !m_copyLayers->GetValue() );
162
163 m_deleteSourceItems->SetValue( m_params.deleteSourceItems );
164
165 return true;
166}
167
168
170{
171 if( m_lineWidth.GetIntValue() <= 0 )
172 {
173 DisplayErrorMessage( this, _( "Line width must be a positive value." ) );
174 return false;
175 }
176
177 m_params.layer = ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() );
178 m_params.outsetDistance = m_outset.GetIntValue();
179 m_params.roundCorners = m_roundCorners->GetValue();
180 m_params.lineWidth = m_lineWidth.GetIntValue();
181
182 m_params.useSourceLayers = m_copyLayers->GetValue();
183 m_params.useSourceWidths = m_copyWidths->GetValue();
184
185 if( m_roundToGrid->IsChecked() )
186 m_params.gridRounding = m_roundingGrid.GetValue();
187 else
188 m_params.gridRounding = std::nullopt;
189
191
192 m_params.deleteSourceItems = m_deleteSourceItems->GetValue();
193
194 // Keep the recent values list up to date
195 const auto saveRecentValue =
196 []( std::vector<int>& aRecentValues, int aValue )
197 {
198 const auto it = std::find( aRecentValues.begin(), aRecentValues.end(), aValue );
199
200 // Already have it
201 if( it != aRecentValues.end() )
202 return;
203
204 aRecentValues.push_back( aValue );
205 };
206
207 saveRecentValue( s_outsetRecentValues, m_params.outsetDistance );
208 saveRecentValue( s_lineWidthRecentValues, m_params.lineWidth );
209
210 if( m_params.gridRounding )
211 saveRecentValue( s_gridRoundingRecentValues, m_params.gridRounding.value() );
212
213 return true;
214}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
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:217
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:56
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750