KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_zone_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) 2023 Ethan Chien <[email protected]>
5 * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27
28#include <widgets/wx_infobar.h>
30#include <grid_tricks.h>
31#include <wx/radiobut.h>
32#include <kiface_base.h>
33#include <confirm.h>
34#include <pcb_edit_frame.h>
35#include <dialog_shim.h>
36#include <pcbnew_settings.h>
37#include <zone_settings_bag.h>
38#include <wx/string.h>
39#include <widgets/unit_binder.h>
41#include <widgets/wx_grid.h>
42#include <pad.h>
44
45
46wxDEFINE_EVENT( EVT_ZONE_NAME_UPDATE, wxCommandEvent );
47wxDEFINE_EVENT( EVT_ZONE_NET_UPDATE, wxCommandEvent );
48
50 ZONE_SETTINGS_BAG& aZonesSettingsBag, bool allowNetSpec ) :
52 m_frame( aFrame ),
53 m_zonesSettingsBag( aZonesSettingsBag ),
64{
65 m_netSelector->SetNetInfo( &m_frame->GetBoard()->GetNetInfo() );
66
67 if( !allowNetSpec )
68 {
69 m_netLabel->Hide();
70 m_netSelector->Hide();
71 }
72
74 [&]() -> LSET
75 {
76 return m_settings->m_Layers;
77 } );
78
81 m_layerSpecificOverrides->SetSelectionMode( wxGrid::wxGridSelectRows );
82
83 wxGridCellAttr* attr = new wxGridCellAttr;
84 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
85 LSET forbiddenLayers = LSET::AllNonCuMask();
86
87 for( PCB_LAYER_ID copper : LSET::AllCuMask() )
88 {
89 if( !m_frame->GetBoard()->IsLayerEnabled( copper ) )
90 forbiddenLayers.set( copper );
91 }
92
93 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, forbiddenLayers ) );
94 m_layerSpecificOverrides->SetColAttr( 0, attr );
95 m_layerSpecificOverrides->SetupColumnAutosizer( 0 );
96
99
100 m_netSelector->Bind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
101}
102
103
105{
106 // we passed ownership of table to grid
107 // delete m_layerPropsTable;
108
109 m_layerSpecificOverrides->PopEventHandler( true );
110
111 m_netSelector->Unbind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
112}
113
114
116{
117 if( m_settings )
119
120 m_zone = aZone;
121 m_settings = m_zonesSettingsBag.GetZoneSettings( aZone );
123
125}
126
127
129{
130 if( !m_settings )
131 return false;
132
133 m_tcZoneName->ChangeValue( m_settings->m_Name );
134
135 if( m_netSelector->IsShown() )
136 m_netSelector->SetSelectedNetcode( std::max( 0, m_settings->m_Netcode ) );
137
138 m_cbLocked->SetValue( m_settings->m_Locked );
139 m_cornerSmoothingChoice->SetSelection( m_settings->GetCornerSmoothingType() );
140 m_cornerRadius.SetValue( m_settings->GetCornerRadius() );
141
142 if( m_isTeardrop ) // outlines are never smoothed: they have already the right shape
143 {
144 m_cornerSmoothingChoice->SetSelection( 0 );
145 m_cornerSmoothingChoice->Enable( false );
146 m_cornerRadius.Show( false );
147 }
148
149 switch( m_settings->m_ZoneBorderDisplayStyle )
150 {
151 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
155 }
156
157 m_outlineHatchPitch.SetValue( m_settings->m_BorderHatchPitch );
158
159 m_clearance.SetValue( m_settings->m_ZoneClearance );
160 m_minWidth.SetValue( m_settings->m_ZoneMinThickness );
161
162 switch( m_settings->GetPadConnection() )
163 {
164 default:
165 case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
166 case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
167 case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
168 case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
169 }
170
171 if( m_isTeardrop )
172 {
173 m_PadInZoneOpt->SetSelection( 0 );
174 m_PadInZoneOpt->Enable( false );
175 m_antipadClearance.Enable( false );
176 m_spokeWidth.Enable( false );
177 }
178
179 // Do not enable/disable antipad clearance and spoke width. They might be needed if
180 // a footprint or pad overrides the zone to specify a thermal connection.
181 m_antipadClearance.SetValue( m_settings->m_ThermalReliefGap );
182 m_spokeWidth.SetValue( m_settings->m_ThermalReliefSpokeWidth );
183
185 m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings->GetMinIslandArea() ) );
186
187 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
188
190
192 m_gridStyleRotation.SetAngleValue( m_settings->m_HatchOrientation );
193 m_gridStyleThickness.SetValue( m_settings->m_HatchThickness );
194 m_gridStyleGap.SetValue( m_settings->m_HatchGap );
195
196 m_spinCtrlSmoothLevel->SetValue( m_settings->m_HatchSmoothingLevel );
197 m_spinCtrlSmoothValue->SetValue( m_settings->m_HatchSmoothingValue );
198
199 m_layerPropsTable->Clear();
200
201 for( PCB_LAYER_ID layer : LSET::AllCuMask().UIOrder() )
202 {
203 if( m_settings->m_LayerProperties.contains( layer ) )
204 {
205 ZONE_LAYER_PROPERTIES& props = m_settings->m_LayerProperties[layer];
206
207 if( props.hatching_offset.has_value() )
208 m_layerPropsTable->AddItem( layer, props );
209 }
210 }
211
212 // Enable/Disable some widgets
213 wxCommandEvent aEvent;
214 onNetSelector( aEvent );
216 OnRemoveIslandsSelection( aEvent );
217 onHatched( aEvent );
218
219 return true;
220}
221
222
224{
225 m_islandThreshold.Show( m_cbRemoveIslands->GetSelection() == 2 );
226
227 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
228 dlg->Layout();
229}
230
231
233{
234 switch( m_cornerSmoothingChoice->GetSelection() )
235 {
237 m_cornerRadiusLabel->SetLabel( _( "Chamfer:" ) );
238 m_cornerRadius.Show( true );
239 break;
240
242 m_cornerRadiusLabel->SetLabel( _( "Fillet:" ) );
243 m_cornerRadius.Show( true );
244 break;
245
246 default:
247 m_cornerRadius.Show( false );
248 break;
249 }
250
251 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
252 dlg->Layout();
253}
254
255
256void PANEL_ZONE_PROPERTIES::OnZoneNameChanged( wxCommandEvent& aEvent )
257{
258 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
259 m_settings->m_Name = m_tcZoneName->GetValue();
260 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Name = m_settings->m_Name;
261
262 if( m_zone )
263 m_zone->SetZoneName( m_settings->m_Name );
264
265 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NAME_UPDATE );
266 wxQueueEvent( m_parent, evt );
267}
268
269
270void PANEL_ZONE_PROPERTIES::onNetSelector( wxCommandEvent& aEvent )
271{
272 if( !m_netSelector->IsShown() )
273 return;
274
276
277 // Zones with no net never have islands removed
278 if( m_netSelector->GetSelectedNetcode() == INVALID_NET_CODE )
279 {
280 if( m_cbRemoveIslands->IsEnabled() )
281 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
282
283 m_cbRemoveIslands->SetSelection( 1 );
284 m_removeIslandsLabel->Enable( false );
285 m_cbRemoveIslands->Enable( false );
286 }
287 else if( !m_cbRemoveIslands->IsEnabled() )
288 {
289 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
290 m_removeIslandsLabel->Enable( true );
291 m_cbRemoveIslands->Enable( true );
292 }
293
294 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
295 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
296 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Netcode = m_settings->m_Netcode;
297
298 if( m_zone )
299 m_zone->SetNetCode( m_settings->m_Netcode, true );
300
301 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NET_UPDATE );
302 wxQueueEvent( m_parent, evt );
303}
304
305
307{
308 if( !CommitPendingChanges() )
309 return false;
310
311 if( !m_settings )
312 return false;
313
314 if( !AcceptOptions() )
315 return false;
316
317 return true;
318}
319
320
322{
323 return m_layerSpecificOverrides->CommitPendingChanges();
324}
325
326
327bool PANEL_ZONE_PROPERTIES::AcceptOptions( bool aUseExportableSetupOnly )
328{
329 if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
330 return false;
331
332 if( !m_minWidth.Validate( pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM ), INT_MAX ) )
333 return false;
334
335 if( !m_cornerRadius.Validate( 0, INT_MAX ) )
336 return false;
337
338 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
339 return false;
340
342
343 if( m_settings->m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
344 {
345 int minThickness = m_minWidth.GetIntValue();
346
347 if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
348 return false;
349
350 if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
351 return false;
352 }
353
354 switch( m_PadInZoneOpt->GetSelection() )
355 {
356 case 3: m_settings->SetPadConnection( ZONE_CONNECTION::NONE ); break;
357 case 2: m_settings->SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
358 case 1: m_settings->SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
359 case 0: m_settings->SetPadConnection( ZONE_CONNECTION::FULL ); break;
360 }
361
362 switch( m_OutlineDisplayCtrl->GetSelection() )
363 {
364 case 0: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
365 case 1: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
366 case 2: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
367 }
368
371 {
372 return false;
373 }
374
375 m_settings->m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
376
377 m_settings->m_ZoneClearance = m_clearance.GetIntValue();
378 m_settings->m_ZoneMinThickness = m_minWidth.GetIntValue();
379
380 m_settings->SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
381
382 if( m_settings->GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE )
383 m_settings->SetCornerRadius( 0 );
384 else
385 m_settings->SetCornerRadius( m_cornerRadius.GetIntValue() );
386
387 m_settings->m_Locked = m_cbLocked->GetValue();
388
389 m_settings->m_ThermalReliefGap = m_antipadClearance.GetValue();
390 m_settings->m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
391
392 if( m_settings->m_ThermalReliefSpokeWidth < m_settings->m_ZoneMinThickness )
393 {
394 DisplayErrorMessage( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
395 return false;
396 }
397
398 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
399 m_settings->SetMinIslandArea( m_islandThreshold.GetValue() );
400
401 // If we use only exportable to others zones parameters, exit here:
402 if( aUseExportableSetupOnly )
403 return true;
404
405 if( m_netSelector->IsShown() )
406 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
407
408 m_settings->m_Name = m_tcZoneName->GetValue();
409
411 m_settings->m_HatchOrientation = m_gridStyleRotation.GetAngleValue();
412 m_settings->m_HatchThickness = m_gridStyleThickness.GetIntValue();
413 m_settings->m_HatchGap = m_gridStyleGap.GetIntValue();
414 m_settings->m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
415 m_settings->m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
416
417 for( auto& [layer, props] : m_settings->m_LayerProperties )
418 props.hatching_offset = std::nullopt;
419
420 for( const auto& [layer, props] : m_layerPropsTable->GetItems() )
421 m_settings->m_LayerProperties[layer] = props;
422
423 return true;
424}
425
426
427void PANEL_ZONE_PROPERTIES::onHatched( wxCommandEvent& event )
428{
429 bool enable = m_cbHatched->GetValue();
430 m_gridStyleThickness.Enable( enable );
431 m_gridStyleGap.Enable( enable );
432 m_gridStyleRotation.Enable( enable );
433 m_staticTextGridSmoothingLevel->Enable( enable );
434 m_spinCtrlSmoothLevel->Enable( enable );
435 m_staticTextGridSmootingVal->Enable( enable );
436 m_spinCtrlSmoothValue->Enable( enable );
437 m_offsetOverridesLabel->Enable( enable );
438 m_layerSpecificOverrides->Enable( enable );
439 m_bpAddCustomLayer->Enable( enable );
440 m_bpDeleteCustomLayer->Enable( enable );
441}
442
443
444void PANEL_ZONE_PROPERTIES::OnAddLayerItem( wxCommandEvent& event )
445{
446 m_layerSpecificOverrides->OnAddRow(
447 [&]() -> std::pair<int, int>
448 {
449 if( !m_layerSpecificOverrides->GetTable()->AppendRows( 1 ) )
450 {
451 m_copperZoneInfoBar->ShowMessageFor( _( "All zone layers already overridden." ), 8000,
452 wxICON_WARNING );
453 }
454
455 return { m_layerSpecificOverrides->GetNumberRows() - 1, -1 };
456 } );
457}
458
459
460void PANEL_ZONE_PROPERTIES::OnDeleteLayerItem( wxCommandEvent& event )
461{
462 m_layerSpecificOverrides->OnDeleteRows(
463 [&]( int row )
464 {
465 m_layerSpecificOverrides->GetTable()->DeleteRows( row, 1 );
466 } );
467}
468
469
471{
472 if( m_netSelector->GetSelectedNetcode() <= INVALID_NET_CODE && !m_copperZoneInfoBar->IsShown() )
473 {
474 m_copperZoneInfoBar->ShowMessage( _( "<no net> will result in an isolated copper island." ), wxICON_WARNING );
475 }
476 else if( m_copperZoneInfoBar->IsShown() )
477 {
478 m_copperZoneInfoBar->Dismiss();
479 }
480}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
BASE_SET & set(size_t pos)
Definition base_set.h:116
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:627
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:599
PANEL_ZONE_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnAddLayerItem(wxCommandEvent &event) override
static constexpr int INVALID_NET_CODE
void OnZoneNameChanged(wxCommandEvent &event) override
void onNetSelector(wxCommandEvent &aEvent)
bool AcceptOptions(bool aUseExportableSetupOnly=false)
PANEL_ZONE_PROPERTIES(wxWindow *aParent, PCB_BASE_FRAME *aFrame, ZONE_SETTINGS_BAG &aZonesSettingsBag, bool allowNetSpec=true)
void onHatched(wxCommandEvent &event) override
void OnRemoveIslandsSelection(wxCommandEvent &event) override
ZONE_SETTINGS_BAG & m_zonesSettingsBag
void OnDeleteLayerItem(wxCommandEvent &event) override
std::shared_ptr< ZONE_SETTINGS > m_settings
void OnCornerSmoothingSelection(wxCommandEvent &event) override
LAYER_PROPERTIES_GRID_TABLE * m_layerPropsTable
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Handle a list of polygons defining a copper zone.
Definition zone.h:73
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.
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
wxDEFINE_EVENT(EVT_ZONE_NAME_UPDATE, wxCommandEvent)
std::optional< VECTOR2I > hatching_offset
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .
Definition trigo.h:196
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
#define ZONE_CLEARANCE_MAX_VALUE_MM
Definition zones.h:37
@ THERMAL
Use thermal relief for pads.
Definition zones.h:50
@ THT_THERMAL
Thermal relief only for THT pads.
Definition zones.h:52
@ NONE
Pads are not covered.
Definition zones.h:49
@ FULL
pads are covered by copper
Definition zones.h:51
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:39
#define ZONE_THICKNESS_MIN_VALUE_MM
Definition zones.h:35
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:40