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 <grid_tricks.h>
29#include <wx/radiobut.h>
30#include <kiface_base.h>
31#include <confirm.h>
32#include <pcb_edit_frame.h>
33#include <dialog_shim.h>
34#include <pcbnew_settings.h>
35#include <zone_settings_bag.h>
36#include <wx/string.h>
37#include <widgets/unit_binder.h>
39#include <widgets/wx_grid.h>
40#include <pad.h>
42
43
44wxDEFINE_EVENT( EVT_ZONE_NAME_UPDATE, wxCommandEvent );
45wxDEFINE_EVENT( EVT_ZONE_NET_UPDATE, wxCommandEvent );
46
48 ZONE_SETTINGS_BAG& aZonesSettingsBag, bool allowNetSpec ) :
50 m_frame( aFrame ),
51 m_zonesSettingsBag( aZonesSettingsBag ),
62{
63 m_netSelector->SetNetInfo( &m_frame->GetBoard()->GetNetInfo() );
64
65 if( !allowNetSpec )
66 {
67 m_netLabel->Hide();
68 m_netSelector->Hide();
69 }
70
72 [&]() -> LSET
73 {
74 return m_settings->m_Layers;
75 } );
76
79 m_layerSpecificOverrides->SetSelectionMode( wxGrid::wxGridSelectRows );
80
81 wxGridCellAttr* attr = new wxGridCellAttr;
82 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
83 LSET forbiddenLayers = LSET::AllNonCuMask();
84
85 for( PCB_LAYER_ID copper : LSET::AllCuMask() )
86 {
87 if( !m_frame->GetBoard()->IsLayerEnabled( copper ) )
88 forbiddenLayers.set( copper );
89 }
90
91 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, forbiddenLayers ) );
92 m_layerSpecificOverrides->SetColAttr( 0, attr );
93 m_layerSpecificOverrides->SetupColumnAutosizer( 0 );
94
97
98 m_netSelector->Bind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
99}
100
101
103{
104 // we passed ownership of table to grid
105 // delete m_layerPropsTable;
106
107 m_layerSpecificOverrides->PopEventHandler( true );
108
109 m_netSelector->Unbind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
110}
111
112
114{
115 if( m_settings )
117
118 m_zone = aZone;
119 m_settings = m_zonesSettingsBag.GetZoneSettings( aZone );
121
123}
124
125
127{
128 if( !m_settings )
129 return false;
130
131 m_tcZoneName->ChangeValue( m_settings->m_Name );
132
133 if( m_netSelector->IsShown() )
134 m_netSelector->SetSelectedNetcode( std::max( 0, m_settings->m_Netcode ) );
135
136 m_cbLocked->SetValue( m_settings->m_Locked );
137 m_cornerSmoothingChoice->SetSelection( m_settings->GetCornerSmoothingType() );
138 m_cornerRadius.SetValue( m_settings->GetCornerRadius() );
139
140 if( m_isTeardrop ) // outlines are never smoothed: they have already the right shape
141 {
142 m_cornerSmoothingChoice->SetSelection( 0 );
143 m_cornerSmoothingChoice->Enable( false );
144 m_cornerRadius.Show( false );
145 }
146
147 switch( m_settings->m_ZoneBorderDisplayStyle )
148 {
149 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
153 }
154
155 m_outlineHatchPitch.SetValue( m_settings->m_BorderHatchPitch );
156
157 m_clearance.SetValue( m_settings->m_ZoneClearance );
158 m_minWidth.SetValue( m_settings->m_ZoneMinThickness );
159
160 switch( m_settings->GetPadConnection() )
161 {
162 default:
163 case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
164 case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
165 case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
166 case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
167 }
168
169 if( m_isTeardrop )
170 {
171 m_PadInZoneOpt->SetSelection( 0 );
172 m_PadInZoneOpt->Enable( false );
173 m_antipadClearance.Enable( false );
174 m_spokeWidth.Enable( false );
175 }
176
177 // Do not enable/disable antipad clearance and spoke width. They might be needed if
178 // a footprint or pad overrides the zone to specify a thermal connection.
179 m_antipadClearance.SetValue( m_settings->m_ThermalReliefGap );
180 m_spokeWidth.SetValue( m_settings->m_ThermalReliefSpokeWidth );
181
183 m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings->GetMinIslandArea() ) );
184
185 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
186
188
190 m_gridStyleRotation.SetAngleValue( m_settings->m_HatchOrientation );
191 m_gridStyleThickness.SetValue( m_settings->m_HatchThickness );
192 m_gridStyleGap.SetValue( m_settings->m_HatchGap );
193
194 m_spinCtrlSmoothLevel->SetValue( m_settings->m_HatchSmoothingLevel );
195 m_spinCtrlSmoothValue->SetValue( m_settings->m_HatchSmoothingValue );
196
197 m_layerPropsTable->Clear();
198
199 for( PCB_LAYER_ID layer : LSET::AllCuMask().UIOrder() )
200 {
201 if( m_settings->m_LayerProperties.contains( layer ) )
202 {
203 ZONE_LAYER_PROPERTIES& props = m_settings->m_LayerProperties[layer];
204
205 if( props.hatching_offset.has_value() )
206 m_layerPropsTable->AddItem( layer, props );
207 }
208 }
209
210 // Enable/Disable some widgets
211 wxCommandEvent aEvent;
212 onNetSelector( aEvent );
214 OnRemoveIslandsSelection( aEvent );
215 onHatched( aEvent );
216
217 return true;
218}
219
220
222{
223 m_islandThreshold.Show( m_cbRemoveIslands->GetSelection() == 2 );
224
225 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
226 dlg->Layout();
227}
228
229
231{
232 switch( m_cornerSmoothingChoice->GetSelection() )
233 {
235 m_cornerRadiusLabel->SetLabel( _( "Chamfer:" ) );
236 m_cornerRadius.Show( true );
237 break;
238
240 m_cornerRadiusLabel->SetLabel( _( "Fillet:" ) );
241 m_cornerRadius.Show( true );
242 break;
243
244 default:
245 m_cornerRadius.Show( false );
246 break;
247 }
248
249 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
250 dlg->Layout();
251}
252
253
254void PANEL_ZONE_PROPERTIES::OnZoneNameChanged( wxCommandEvent& aEvent )
255{
256 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
257 m_settings->m_Name = m_tcZoneName->GetValue();
258 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Name = m_settings->m_Name;
259
260 if( m_zone )
261 m_zone->SetZoneName( m_settings->m_Name );
262
263 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NAME_UPDATE );
264 wxQueueEvent( m_parent, evt );
265}
266
267
268void PANEL_ZONE_PROPERTIES::onNetSelector( wxCommandEvent& aEvent )
269{
270 if( !m_netSelector->IsShown() )
271 return;
272
274
275 // Zones with no net never have islands removed
276 if( m_netSelector->GetSelectedNetcode() == INVALID_NET_CODE )
277 {
278 if( m_cbRemoveIslands->IsEnabled() )
279 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
280
281 m_cbRemoveIslands->SetSelection( 1 );
282 m_staticText40->Enable( false );
283 m_cbRemoveIslands->Enable( false );
284 }
285 else if( !m_cbRemoveIslands->IsEnabled() )
286 {
287 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
288 m_staticText40->Enable( true );
289 m_cbRemoveIslands->Enable( true );
290 }
291
292 // Propagate all the way out so that the MODEL_ZONES_OVERVIEW can pick it up
293 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
294 m_zonesSettingsBag.GetZoneSettings( m_zone )->m_Netcode = m_settings->m_Netcode;
295
296 if( m_zone )
297 m_zone->SetNetCode( m_settings->m_Netcode, true );
298
299 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NET_UPDATE );
300 wxQueueEvent( m_parent, evt );
301}
302
303
305{
306 if( !CommitPendingChanges() )
307 return false;
308
309 if( !m_settings )
310 return false;
311
312 if( !AcceptOptions() )
313 return false;
314
315 return true;
316}
317
318
320{
321 return m_layerSpecificOverrides->CommitPendingChanges();
322}
323
324
325bool PANEL_ZONE_PROPERTIES::AcceptOptions( bool aUseExportableSetupOnly )
326{
327 if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
328 return false;
329
330 if( !m_minWidth.Validate( pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM ), INT_MAX ) )
331 return false;
332
333 if( !m_cornerRadius.Validate( 0, INT_MAX ) )
334 return false;
335
336 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
337 return false;
338
340
341 if( m_settings->m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
342 {
343 int minThickness = m_minWidth.GetIntValue();
344
345 if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
346 return false;
347
348 if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
349 return false;
350 }
351
352 switch( m_PadInZoneOpt->GetSelection() )
353 {
354 case 3: m_settings->SetPadConnection( ZONE_CONNECTION::NONE ); break;
355 case 2: m_settings->SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
356 case 1: m_settings->SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
357 case 0: m_settings->SetPadConnection( ZONE_CONNECTION::FULL ); break;
358 }
359
360 switch( m_OutlineDisplayCtrl->GetSelection() )
361 {
362 case 0: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
363 case 1: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
364 case 2: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
365 }
366
369 {
370 return false;
371 }
372
373 m_settings->m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
374
375 m_settings->m_ZoneClearance = m_clearance.GetIntValue();
376 m_settings->m_ZoneMinThickness = m_minWidth.GetIntValue();
377
378 m_settings->SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
379
380 if( m_settings->GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE )
381 m_settings->SetCornerRadius( 0 );
382 else
383 m_settings->SetCornerRadius( m_cornerRadius.GetIntValue() );
384
385 m_settings->m_Locked = m_cbLocked->GetValue();
386
387 m_settings->m_ThermalReliefGap = m_antipadClearance.GetValue();
388 m_settings->m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
389
390 if( m_settings->m_ThermalReliefSpokeWidth < m_settings->m_ZoneMinThickness )
391 {
392 DisplayErrorMessage( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
393 return false;
394 }
395
396 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
397 m_settings->SetMinIslandArea( m_islandThreshold.GetValue() );
398
399 // If we use only exportable to others zones parameters, exit here:
400 if( aUseExportableSetupOnly )
401 return true;
402
403 if( m_netSelector->IsShown() )
404 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
405
406 m_settings->m_Name = m_tcZoneName->GetValue();
407
409 m_settings->m_HatchOrientation = m_gridStyleRotation.GetAngleValue();
410 m_settings->m_HatchThickness = m_gridStyleThickness.GetIntValue();
411 m_settings->m_HatchGap = m_gridStyleGap.GetIntValue();
412 m_settings->m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
413 m_settings->m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
414
415 for( auto& [layer, props] : m_settings->m_LayerProperties )
416 props.hatching_offset = std::nullopt;
417
418 for( const auto& [layer, props] : m_layerPropsTable->GetItems() )
419 m_settings->m_LayerProperties[layer] = props;
420
421 return true;
422}
423
424
425void PANEL_ZONE_PROPERTIES::onHatched( wxCommandEvent& event )
426{
427 bool enable = m_cbHatched->GetValue();
428 m_gridStyleThickness.Enable( enable );
429 m_gridStyleGap.Enable( enable );
430 m_gridStyleRotation.Enable( enable );
431 m_staticTextGridSmoothingLevel->Enable( enable );
432 m_spinCtrlSmoothLevel->Enable( enable );
433 m_staticTextGridSmootingVal->Enable( enable );
434 m_spinCtrlSmoothValue->Enable( enable );
435 m_offsetOverridesLabel->Enable( enable );
436 m_layerSpecificOverrides->Enable( enable );
437 m_bpAddCustomLayer->Enable( enable );
438 m_bpDeleteCustomLayer->Enable( enable );
439}
440
441
442void PANEL_ZONE_PROPERTIES::OnAddLayerItem( wxCommandEvent& event )
443{
444 m_layerSpecificOverrides->OnAddRow(
445 [&]() -> std::pair<int, int>
446 {
447 if( !m_layerSpecificOverrides->GetTable()->AppendRows( 1 ) )
448 {
449 m_copperZoneInfoBar->ShowMessageFor( _( "All zone layers already overridden." ), 8000,
450 wxICON_WARNING );
451 }
452
453 return { m_layerSpecificOverrides->GetNumberRows() - 1, -1 };
454 } );
455}
456
457
458void PANEL_ZONE_PROPERTIES::OnDeleteLayerItem( wxCommandEvent& event )
459{
460 m_layerSpecificOverrides->OnDeleteRows(
461 [&]( int row )
462 {
463 m_layerSpecificOverrides->GetTable()->DeleteRows( row, 1 );
464 } );
465}
466
467
469{
470 if( m_netSelector->GetSelectedNetcode() <= INVALID_NET_CODE && !m_copperZoneInfoBar->IsShown() )
471 {
472 m_copperZoneInfoBar->ShowMessage( _( "<no net> will result in an isolated copper island." ), wxICON_WARNING );
473 }
474 else if( m_copperZoneInfoBar->IsShown() )
475 {
476 m_copperZoneInfoBar->Dismiss();
477 }
478}
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:610
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:582
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:74
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