KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_non_copper_zones_properties.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <kiface_base.h>
23#include <confirm.h>
24#include <pcb_edit_frame.h>
25#include <pcbnew_settings.h>
26#include <zone_settings.h>
27#include <widgets/unit_binder.h>
28#include <wx/statline.h>
29#include <zones.h>
31
33#include <magic_enum.hpp>
34#include <zone_settings.h>
35
36
64
65
66int InvokeNonCopperZonesEditor( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings, CONVERT_SETTINGS* aConvertSettings )
67{
68 DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings, aConvertSettings );
69
70 return dlg.ShowModal();
71}
72
73#define MIN_THICKNESS 10*pcbIUScale.IU_PER_MILS
74
76 CONVERT_SETTINGS* aConvertSettings ) :
83 m_cornerSmoothingType( ZONE_SETTINGS::CORNER_SMOOTHING::NO_SMOOTHING ),
85{
86 m_parent = aParent;
87
88 m_ptr = aSettings;
89 m_settings = *aSettings;
90
91 if( aConvertSettings )
92 {
93 m_conversionControls = new PANEL_ZONE_CONVERSION( this, aParent, *aConvertSettings );
94 GetSizer()->Insert( 0, m_conversionControls, 0, wxALL|wxEXPAND, 10 );
95
96 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
97 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
98
99 SetTitle( _( "Convert to Non Copper Zone" ) );
100 }
101
103
104 m_settings.SetupLayersList( m_layers, m_parent, LSET::AllNonCuMask() );
105
107
109}
110
111
113{
115 magic_enum::enum_cast<ZONE_SETTINGS::CORNER_SMOOTHING>( m_cornerSmoothingChoice->GetSelection() )
117
118 if( m_cornerSmoothingType != current )
119 {
120 m_cornerSmoothingType = current;
121
123 m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
124 else
125 m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
126 }
127
129}
130
131
133{
135 m_conversionControls->TransferDataToWindow();
136
137 m_cornerSmoothingChoice->SetSelection( static_cast<int>( m_settings.GetCornerSmoothingType() ) );
138 m_cornerRadius.SetValue( m_settings.GetCornerRadius() );
139
140 m_minWidth.SetValue( m_settings.m_ZoneMinThickness );
141 m_cbLocked->SetValue( m_settings.m_Locked );
142
143 switch( m_settings.m_ZoneBorderDisplayStyle )
144 {
145 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
148 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: break; // Not used
149 }
150
151 m_outlineHatchPitch.SetValue( m_settings.m_BorderHatchPitch );
152
154
155 switch( m_settings.m_FillMode )
156 {
157 case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
158 default: m_GridStyleCtrl->SetSelection( 0 ); break;
159 }
160
162 m_hatchRotation.SetAngleValue( m_settings.m_HatchOrientation );
163
164 // Gives a reasonable value to grid style parameters, if currently there are no defined
165 // parameters for grid pattern thickness and gap (if the value is 0)
166 // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
167 // or 1mm
168 // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
169 // or 1.5 mm
170 int bestvalue = m_settings.m_HatchThickness;
171
172 if( bestvalue <= 0 ) // No defined value for m_hatchWidth
173 bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, pcbIUScale.mmToIU( 1.0 ) );
174
175 m_hatchWidth.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
176
177 bestvalue = m_settings.m_HatchGap;
178
179 if( bestvalue <= 0 ) // No defined value for m_hatchGap
180 bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, pcbIUScale.mmToIU( 1.5 ) );
181
182 m_hatchGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
183
184 m_spinCtrlSmoothLevel->SetValue( m_settings.m_HatchSmoothingLevel );
185 m_spinCtrlSmoothValue->SetValue( m_settings.m_HatchSmoothingValue );
186
187 // Enable/Disable some widgets
188 wxCommandEvent event;
189 OnStyleSelection( event );
190
191 return true;
192}
193
194
196{
197 bool enable = m_GridStyleCtrl->GetSelection() >= 1;
198 m_hatchRotation.Enable( enable );
199 m_hatchWidth.Enable( enable );
200 m_hatchGap.Enable( enable );
201 m_smoothLevelLabel->Enable( enable );
202 m_spinCtrlSmoothLevel->Enable( enable );
203 m_smoothValueLabel->Enable( enable );
204 m_spinCtrlSmoothValue->Enable( enable );
205}
206
207
209{
210 if( event.GetColumn() != 0 )
211 return;
212
213 int row = m_layers->ItemToRow( event.GetItem() );
214 bool val = m_layers->GetToggleValue( row, 0 );
215
216 wxVariant layerID;
217 m_layers->GetValue( layerID, row, 2 );
218 m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
219}
220
221
223{
225 m_conversionControls->TransferDataFromWindow();
226
228 magic_enum::enum_cast<ZONE_SETTINGS::CORNER_SMOOTHING>( m_cornerSmoothingChoice->GetSelection() )
230
231 m_settings.SetCornerSmoothingType( smoothing );
232
233 m_settings.SetCornerRadius( m_settings.GetCornerSmoothingType() == ZONE_SETTINGS::CORNER_SMOOTHING::NO_SMOOTHING
234 ? 0 : m_cornerRadius.GetIntValue() );
235
236 m_settings.m_ZoneMinThickness = m_minWidth.GetIntValue();
237
238 switch( m_OutlineDisplayCtrl->GetSelection() )
239 {
240 case 0: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
241 case 1: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
242 case 2: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
243 }
244
247 {
248 return false;
249 }
250
251 m_settings.m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
252
253 if( m_GridStyleCtrl->GetSelection() > 0 )
255 else
257
258
259 if( m_settings.m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
260 {
261 int minThickness = m_minWidth.GetIntValue();
262
263 if( !m_hatchWidth.Validate( minThickness, INT_MAX ) )
264 return false;
265
266 if( !m_hatchGap.Validate( minThickness, INT_MAX ) )
267 return false;
268 }
269
270 m_settings.m_HatchOrientation = m_hatchRotation.GetAngleValue();
271 m_settings.m_HatchThickness = m_hatchWidth.GetIntValue();
272 m_settings.m_HatchGap = m_hatchGap.GetIntValue();
273 m_settings.m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
274 m_settings.m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
275
276 m_settings.m_Locked = m_cbLocked->GetValue();
277
278 // Get the layer selection for this zone
279 int layer = -1;
280
281 for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
282 {
283 if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
284 {
285 layer = ii;
286 break;
287 }
288 }
289
290 if( layer < 0 )
291 {
292 DisplayError( this, _( "No layer selected." ) );
293 return false;
294 }
295
296 *m_ptr = m_settings;
297 return true;
298}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Non Copper Zone Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxBORDER_SUNKEN)
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
ZONE_SETTINGS::CORNER_SMOOTHING m_cornerSmoothingType
void OnStyleSelection(wxCommandEvent &event) override
void OnLayerSelection(wxDataViewEvent &event) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:94
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 ShowModal() override
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Handle zones parameters.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Invoke a modal dialog window for non-copper zone editing.
#define _(s)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:35
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:36