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, see <https://www.gnu.org/licenses/>.
20 */
21
23
24#include <widgets/wx_infobar.h>
26#include <grid_tricks.h>
27#include <wx/radiobut.h>
28#include <kiface_base.h>
29#include <confirm.h>
30#include <pcb_edit_frame.h>
31#include <dialog_shim.h>
32#include <pcbnew_settings.h>
33#include <zone_settings_bag.h>
34#include <wx/string.h>
35#include <widgets/unit_binder.h>
37#include <widgets/wx_grid.h>
38#include <pad.h>
40
41
42wxDEFINE_EVENT( EVT_ZONE_NAME_UPDATE, wxCommandEvent );
43wxDEFINE_EVENT( EVT_ZONE_NET_UPDATE, wxCommandEvent );
44
46 ZONE_SETTINGS_BAG& aZonesSettingsBag, bool allowNetSpec ) :
48 m_frame( aFrame ),
49 m_zonesSettingsBag( aZonesSettingsBag ),
50 m_zone( nullptr ),
61{
62 m_netSelector->SetNetInfo( &m_frame->GetBoard()->GetNetInfo() );
63
64 if( !allowNetSpec )
65 {
66 m_netLabel->Hide();
67 m_netSelector->Hide();
68 }
69
71 [&]() -> LSET
72 {
73 return m_settings->m_Layers;
74 } );
75
78 m_layerSpecificOverrides->SetSelectionMode( wxGrid::wxGridSelectRows );
79
80 wxGridCellAttr* attr = new wxGridCellAttr;
81 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
82 LSET forbiddenLayers = LSET::AllNonCuMask();
83
84 for( PCB_LAYER_ID copper : LSET::AllCuMask() )
85 {
86 if( !m_frame->GetBoard()->IsLayerEnabled( copper ) )
87 forbiddenLayers.set( copper );
88 }
89
90 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, forbiddenLayers ) );
91 m_layerSpecificOverrides->SetColAttr( 0, attr );
92 m_layerSpecificOverrides->SetupColumnAutosizer( 0 );
93
96
97 m_netSelector->Bind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
98}
99
100
102{
103 // we passed ownership of table to grid
104 // delete m_layerPropsTable;
105
106 m_layerSpecificOverrides->PopEventHandler( true );
107
108 m_netSelector->Unbind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
109}
110
111
113{
114 if( m_settings )
116
117 m_zone = aZone;
118 m_settings = m_zonesSettingsBag.GetZoneSettings( aZone );
119
120 if( !m_settings )
121 {
122 m_isTeardrop = false;
123 m_tcZoneName->ChangeValue( wxEmptyString );
124 Enable( false );
125 return;
126 }
127
128 Enable( true );
130
132}
133
134
136{
137 if( !m_settings )
138 return false;
139
140 m_tcZoneName->ChangeValue( m_settings->m_Name );
141
142 if( m_netSelector->IsShown() )
143 m_netSelector->SetSelectedNetcode( std::max( 0, m_settings->m_Netcode ) );
144
145 m_cbLocked->SetValue( m_settings->m_Locked );
146 m_cornerSmoothingChoice->SetSelection( m_settings->GetCornerSmoothingType() );
147 m_cornerRadius.SetValue( m_settings->GetCornerRadius() );
148
149 if( m_isTeardrop ) // outlines are never smoothed: they have already the right shape
150 {
151 m_cornerSmoothingChoice->SetSelection( 0 );
152 m_cornerSmoothingChoice->Enable( false );
153 m_cornerRadius.Show( false );
154 }
155
156 switch( m_settings->m_ZoneBorderDisplayStyle )
157 {
158 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
162 }
163
164 m_outlineHatchPitch.SetValue( m_settings->m_BorderHatchPitch );
165
166 m_clearance.SetValue( m_settings->m_ZoneClearance );
167 m_minWidth.SetValue( m_settings->m_ZoneMinThickness );
168
169 switch( m_settings->GetPadConnection() )
170 {
171 default:
172 case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
173 case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
174 case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
175 case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
176 }
177
178 if( m_isTeardrop )
179 {
180 m_PadInZoneOpt->SetSelection( 0 );
181 m_PadInZoneOpt->Enable( false );
182 m_antipadClearance.Enable( false );
183 m_spokeWidth.Enable( false );
184 }
185
186 // Do not enable/disable antipad clearance and spoke width. They might be needed if
187 // a footprint or pad overrides the zone to specify a thermal connection.
188 m_antipadClearance.SetValue( m_settings->m_ThermalReliefGap );
189 m_spokeWidth.SetValue( m_settings->m_ThermalReliefSpokeWidth );
190
192 m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings->GetMinIslandArea() ) );
193
194 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
195
197
199 m_gridStyleRotation.SetAngleValue( m_settings->m_HatchOrientation );
200 m_gridStyleThickness.SetValue( m_settings->m_HatchThickness );
201 m_gridStyleGap.SetValue( m_settings->m_HatchGap );
202
203 m_spinCtrlSmoothLevel->SetValue( m_settings->m_HatchSmoothingLevel );
204 m_spinCtrlSmoothValue->SetValue( m_settings->m_HatchSmoothingValue );
205
206 m_layerPropsTable->Clear();
207
208 for( PCB_LAYER_ID layer : LSET::AllCuMask().UIOrder() )
209 {
210 if( m_settings->m_LayerProperties.contains( layer ) )
211 {
212 ZONE_LAYER_PROPERTIES& props = m_settings->m_LayerProperties[layer];
213
214 if( props.hatching_offset.has_value() )
215 m_layerPropsTable->AddItem( layer, props );
216 }
217 }
218
219 // Enable/Disable some widgets
220 wxCommandEvent aEvent;
221 onNetSelector( aEvent );
223 OnRemoveIslandsSelection( aEvent );
224 onHatched( aEvent );
225
226 return true;
227}
228
229
231{
232 m_islandThreshold.Show( m_cbRemoveIslands->GetSelection() == 2 );
233
234 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
235 dlg->Layout();
236}
237
238
240{
241 int selection = m_cornerSmoothingChoice->GetSelection();
242
243 if( selection == ZONE_SETTINGS::SMOOTHING_CHAMFER
244 || selection == ZONE_SETTINGS::SMOOTHING_FILLET )
245 {
246 m_cornerRadius.Show( true );
247 }
248 else
249 {
250 m_cornerRadius.Show( false );
251 }
252
253 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
254 dlg->Layout();
255}
256
257
258void PANEL_ZONE_PROPERTIES::OnZoneNameChanged( wxCommandEvent& aEvent )
259{
260 if( !m_settings )
261 return;
262
263 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
264 m_settings->m_Name = m_tcZoneName->GetValue();
265
266 if( m_zone )
267 {
268 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Name = m_settings->m_Name;
269 m_zone->SetZoneName( m_settings->m_Name );
270 }
271
272 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NAME_UPDATE );
273 wxQueueEvent( m_parent, evt );
274}
275
276
277void PANEL_ZONE_PROPERTIES::onNetSelector( wxCommandEvent& aEvent )
278{
279 // There is nothing to do if there is no zone selected which can happen when there are no zones on the board.
280 if( !m_netSelector || !m_netSelector->IsShown() )
281 return;
282
284
285 // Zones with no net never have islands removed
286 if( m_netSelector->GetSelectedNetcode() == INVALID_NET_CODE )
287 {
288 if( m_cbRemoveIslands && m_cbRemoveIslands->IsEnabled() && m_settings )
289 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
290
291 m_cbRemoveIslands->SetSelection( 1 );
292 m_removeIslandsLabel->Enable( false );
293 m_cbRemoveIslands->Enable( false );
294 }
295 else if( !m_cbRemoveIslands->IsEnabled() )
296 {
298 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
299
300 m_removeIslandsLabel->Enable( true );
301 m_cbRemoveIslands->Enable( true );
302 }
303
304 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
305 if( m_settings )
306 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
307
308 if( m_settings && m_zone )
309 {
310 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Netcode = m_settings->m_Netcode;
311 m_zone->SetNetCode( m_settings->m_Netcode, true );
312 }
313
314 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NET_UPDATE );
315 wxQueueEvent( m_parent, evt );
316}
317
318
320{
321 if( !CommitPendingChanges() )
322 return false;
323
324 if( !m_settings )
325 return false;
326
327 if( !AcceptOptions() )
328 return false;
329
330 return true;
331}
332
333
335{
336 return m_layerSpecificOverrides->CommitPendingChanges();
337}
338
339
340bool PANEL_ZONE_PROPERTIES::AcceptOptions( bool aUseExportableSetupOnly )
341{
342 if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
343 return false;
344
345 if( !m_minWidth.Validate( pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM ), INT_MAX ) )
346 return false;
347
348 if( !m_cornerRadius.Validate( 0, INT_MAX ) )
349 return false;
350
351 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
352 return false;
353
355
356 if( m_settings->m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
357 {
358 int minThickness = m_minWidth.GetIntValue();
359
360 if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
361 return false;
362
363 if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
364 return false;
365 }
366
367 switch( m_PadInZoneOpt->GetSelection() )
368 {
369 case 3: m_settings->SetPadConnection( ZONE_CONNECTION::NONE ); break;
370 case 2: m_settings->SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
371 case 1: m_settings->SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
372 case 0: m_settings->SetPadConnection( ZONE_CONNECTION::FULL ); break;
373 }
374
375 switch( m_OutlineDisplayCtrl->GetSelection() )
376 {
377 case 0: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
378 case 1: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
379 case 2: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
380 }
381
384 {
385 return false;
386 }
387
388 m_settings->m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
389
390 m_settings->m_ZoneClearance = m_clearance.GetIntValue();
391 m_settings->m_ZoneMinThickness = m_minWidth.GetIntValue();
392
393 m_settings->SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
394
395 if( m_settings->GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE )
396 m_settings->SetCornerRadius( 0 );
397 else
398 m_settings->SetCornerRadius( m_cornerRadius.GetIntValue() );
399
400 m_settings->m_Locked = m_cbLocked->GetValue();
401
402 m_settings->m_ThermalReliefGap = m_antipadClearance.GetValue();
403 m_settings->m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
404
405 if( m_settings->m_ThermalReliefSpokeWidth < m_settings->m_ZoneMinThickness )
406 {
407 DisplayErrorMessage( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
408 return false;
409 }
410
411 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
412 m_settings->SetMinIslandArea( m_islandThreshold.GetValue() );
413
414 // If we use only exportable to others zones parameters, exit here:
415 if( aUseExportableSetupOnly )
416 return true;
417
418 if( m_netSelector->IsShown() )
419 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
420
421 m_settings->m_Name = m_tcZoneName->GetValue();
422
423 if( BOARD* board = m_frame->GetBoard() )
424 m_settings->m_Name = board->GetUniqueZoneName( m_settings->m_Name, m_zone );
425
426 // Avoid clobbering theiving zone properties
428 {
429 m_settings->m_FillMode = m_cbHatched->GetValue() ? ZONE_FILL_MODE::HATCH_PATTERN
431 }
432 m_settings->m_HatchOrientation = m_gridStyleRotation.GetAngleValue();
433 m_settings->m_HatchThickness = m_gridStyleThickness.GetIntValue();
434 m_settings->m_HatchGap = m_gridStyleGap.GetIntValue();
435 m_settings->m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
436 m_settings->m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
437
438 for( auto& [layer, props] : m_settings->m_LayerProperties )
439 props.hatching_offset = std::nullopt;
440
441 for( const auto& [layer, props] : m_layerPropsTable->GetItems() )
442 m_settings->m_LayerProperties[layer] = props;
443
444 return true;
445}
446
447
448void PANEL_ZONE_PROPERTIES::onHatched( wxCommandEvent& event )
449{
450 bool enable = m_cbHatched->GetValue();
451 m_gridStyleThickness.Enable( enable );
452 m_gridStyleGap.Enable( enable );
453 m_gridStyleRotation.Enable( enable );
454 m_staticTextGridSmoothingLevel->Enable( enable );
455 m_spinCtrlSmoothLevel->Enable( enable );
456 m_staticTextGridSmootingVal->Enable( enable );
457 m_spinCtrlSmoothValue->Enable( enable );
458 m_offsetOverridesLabel->Enable( enable );
459 m_layerSpecificOverrides->Enable( enable );
460 m_bpAddCustomLayer->Enable( enable );
461 m_bpDeleteCustomLayer->Enable( enable );
462}
463
464
465void PANEL_ZONE_PROPERTIES::OnAddLayerItem( wxCommandEvent& event )
466{
467 m_layerSpecificOverrides->OnAddRow(
468 [&]() -> std::pair<int, int>
469 {
470 if( !m_layerSpecificOverrides->GetTable()->AppendRows( 1 ) )
471 {
472 m_copperZoneInfoBar->ShowMessageFor( _( "All zone layers already overridden." ), 8000,
473 wxICON_WARNING );
474 }
475
476 return { m_layerSpecificOverrides->GetNumberRows() - 1, -1 };
477 } );
478}
479
480
481void PANEL_ZONE_PROPERTIES::OnDeleteLayerItem( wxCommandEvent& event )
482{
483 m_layerSpecificOverrides->OnDeleteRows(
484 [&]( int row )
485 {
486 m_layerSpecificOverrides->GetTable()->DeleteRows( row, 1 );
487 } );
488}
489
490
492{
493 if( m_netSelector->GetSelectedNetcode() <= INVALID_NET_CODE && !m_copperZoneInfoBar->IsShown() )
494 {
495 m_copperZoneInfoBar->ShowMessage( _( "<no net> will result in an isolated copper island." ), wxICON_WARNING );
496 }
497 else if( m_copperZoneInfoBar->IsShown() )
498 {
499 m_copperZoneInfoBar->Dismiss();
500 }
501}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
BASE_SET & set(size_t pos)
Definition base_set.h:116
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:65
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:57
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:623
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
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:70
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.
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
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:192
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
#define ZONE_CLEARANCE_MAX_VALUE_MM
Definition zones.h:33
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ THT_THERMAL
Thermal relief only for THT pads.
Definition zones.h:48
@ NONE
Pads are not covered.
Definition zones.h:45
@ FULL
pads are covered by copper
Definition zones.h:47
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:35
#define ZONE_THICKNESS_MIN_VALUE_MM
Definition zones.h:31
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:36