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 ) :
50 m_frame( aFrame ),
51 m_zonesSettingsBag( aZonesSettingsBag ),
62{
63 m_netSelector->SetNetInfo( &m_frame->GetBoard()->GetNetInfo() );
64
66 [&]() -> LSET
67 {
68 return m_settings->m_Layers;
69 } );
70
73 m_layerSpecificOverrides->SetSelectionMode( wxGrid::wxGridSelectRows );
74
75 wxGridCellAttr* attr = new wxGridCellAttr;
76 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
77 LSET forbiddenLayers = LSET::AllNonCuMask();
78
79 for( PCB_LAYER_ID copper : LSET::AllCuMask() )
80 {
81 if( !m_frame->GetBoard()->IsLayerEnabled( copper ) )
82 forbiddenLayers.set( copper );
83 }
84
85 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, forbiddenLayers ) );
86 m_layerSpecificOverrides->SetColAttr( 0, attr );
87 m_layerSpecificOverrides->SetupColumnAutosizer( 0 );
88
91
92 m_netSelector->Bind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
93}
94
95
97{
98 // we passed ownership of table to grid
99 // delete m_layerPropsTable;
100
101 m_layerSpecificOverrides->PopEventHandler( true );
102
103 m_netSelector->Unbind( FILTERED_ITEM_SELECTED, &PANEL_ZONE_PROPERTIES::onNetSelector, this );
104}
105
106
108{
109 if( m_settings )
111
112 m_zone = aZone;
113 m_settings = m_zonesSettingsBag.GetZoneSettings( aZone );
115
117}
118
119
121{
122 if( !m_settings )
123 return false;
124
125 m_tcZoneName->SetValue( m_settings->m_Name );
126 m_netSelector->SetSelectedNetcode( std::max( 0, m_settings->m_Netcode ) );
127 m_cbLocked->SetValue( m_settings->m_Locked );
128 m_cornerSmoothingChoice->SetSelection( m_settings->GetCornerSmoothingType() );
129 m_cornerRadius.SetValue( m_settings->GetCornerRadius() );
130
131 if( m_isTeardrop ) // outlines are never smoothed: they have already the right shape
132 {
133 m_cornerSmoothingChoice->SetSelection( 0 );
134 m_cornerSmoothingChoice->Enable( false );
135 m_cornerRadius.Show( false );
136 }
137
138 switch( m_settings->m_ZoneBorderDisplayStyle )
139 {
140 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
144 }
145
146 m_outlineHatchPitch.SetValue( m_settings->m_BorderHatchPitch );
147
148 m_clearance.SetValue( m_settings->m_ZoneClearance );
149 m_minWidth.SetValue( m_settings->m_ZoneMinThickness );
150
151 switch( m_settings->GetPadConnection() )
152 {
153 default:
154 case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
155 case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
156 case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
157 case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
158 }
159
160 if( m_isTeardrop )
161 {
162 m_PadInZoneOpt->SetSelection( 0 );
163 m_PadInZoneOpt->Enable( false );
164 m_antipadClearance.Enable( false );
165 m_spokeWidth.Enable( false );
166 }
167
168 // Do not enable/disable antipad clearance and spoke width. They might be needed if
169 // a footprint or pad overrides the zone to specify a thermal connection.
170 m_antipadClearance.SetValue( m_settings->m_ThermalReliefGap );
171 m_spokeWidth.SetValue( m_settings->m_ThermalReliefSpokeWidth );
172
174 m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings->GetMinIslandArea() ) );
175
176 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
177
179
181 m_gridStyleRotation.SetAngleValue( m_settings->m_HatchOrientation );
182 m_gridStyleThickness.SetValue( m_settings->m_HatchThickness );
183 m_gridStyleGap.SetValue( m_settings->m_HatchGap );
184
185 m_spinCtrlSmoothLevel->SetValue( m_settings->m_HatchSmoothingLevel );
186 m_spinCtrlSmoothValue->SetValue( m_settings->m_HatchSmoothingValue );
187
188 for( const auto& [layer, props] : m_settings->m_LayerProperties )
189 {
190 if( props.hatching_offset.has_value() )
191 m_layerPropsTable->AddItem( layer, props );
192 }
193
194 // Enable/Disable some widgets
195 wxCommandEvent aEvent;
196 onNetSelector( aEvent );
198 OnRemoveIslandsSelection( aEvent );
199 onHatched( aEvent );
200
201 return true;
202}
203
204
206{
207 m_islandThreshold.Show( m_cbRemoveIslands->GetSelection() == 2 );
208
209 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
210 dlg->Layout();
211}
212
213
215{
216 switch( m_cornerSmoothingChoice->GetSelection() )
217 {
219 m_cornerRadiusLabel->SetLabel( _( "Chamfer:" ) );
220 m_cornerRadius.Show( true );
221 break;
222
224 m_cornerRadiusLabel->SetLabel( _( "Fillet:" ) );
225 m_cornerRadius.Show( true );
226 break;
227
228 default:
229 m_cornerRadius.Show( false );
230 break;
231 }
232
233 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
234 dlg->Layout();
235}
236
237
238void PANEL_ZONE_PROPERTIES::OnZoneNameChanged( wxCommandEvent& aEvent )
239{
240 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NAME_UPDATE );
241 evt->SetString( m_tcZoneName->GetValue() );
242 wxQueueEvent( m_parent, evt );
243}
244
245
247{
248 if( !m_layerSpecificOverrides->CommitPendingChanges() )
249 return false;
250
251 if( !m_settings )
252 return false;
253
254 if( !AcceptOptions() )
255 return false;
256
257 return true;
258}
259
260
261bool PANEL_ZONE_PROPERTIES::AcceptOptions( bool aUseExportableSetupOnly )
262{
263 if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
264 return false;
265
266 if( !m_minWidth.Validate( pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM ), INT_MAX ) )
267 return false;
268
269 if( !m_cornerRadius.Validate( 0, INT_MAX ) )
270 return false;
271
272 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
273 return false;
274
276
277 if( m_settings->m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
278 {
279 int minThickness = m_minWidth.GetIntValue();
280
281 if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
282 return false;
283
284 if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
285 return false;
286 }
287
288 switch( m_PadInZoneOpt->GetSelection() )
289 {
290 case 3: m_settings->SetPadConnection( ZONE_CONNECTION::NONE ); break;
291 case 2: m_settings->SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
292 case 1: m_settings->SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
293 case 0: m_settings->SetPadConnection( ZONE_CONNECTION::FULL ); break;
294 }
295
296 switch( m_OutlineDisplayCtrl->GetSelection() )
297 {
298 case 0: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
299 case 1: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
300 case 2: m_settings->m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
301 }
302
305 {
306 return false;
307 }
308
309 m_settings->m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
310
311 m_settings->m_ZoneClearance = m_clearance.GetIntValue();
312 m_settings->m_ZoneMinThickness = m_minWidth.GetIntValue();
313
314 m_settings->SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
315
316 if( m_settings->GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE )
317 m_settings->SetCornerRadius( 0 );
318 else
319 m_settings->SetCornerRadius( m_cornerRadius.GetIntValue() );
320
321 m_settings->m_Locked = m_cbLocked->GetValue();
322
323 m_settings->m_ThermalReliefGap = m_antipadClearance.GetValue();
324 m_settings->m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
325
326 if( m_settings->m_ThermalReliefSpokeWidth < m_settings->m_ZoneMinThickness )
327 {
328 DisplayErrorMessage( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
329 return false;
330 }
331
332 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
333 m_settings->SetMinIslandArea( m_islandThreshold.GetValue() );
334
335 // If we use only exportable to others zones parameters, exit here:
336 if( aUseExportableSetupOnly )
337 return true;
338
339 m_settings->m_Netcode = m_netSelector->GetSelectedNetcode();
340 m_settings->m_Name = m_tcZoneName->GetValue();
341
343 m_settings->m_HatchOrientation = m_gridStyleRotation.GetAngleValue();
344 m_settings->m_HatchThickness = m_gridStyleThickness.GetIntValue();
345 m_settings->m_HatchGap = m_gridStyleGap.GetIntValue();
346 m_settings->m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
347 m_settings->m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
348
349 for( auto& [layer, props] : m_settings->m_LayerProperties )
350 props.hatching_offset = std::nullopt;
351
352 for( const auto& [layer, props] : m_layerPropsTable->GetItems() )
353 m_settings->m_LayerProperties[layer] = props;
354
355 return true;
356}
357
358
359void PANEL_ZONE_PROPERTIES::onNetSelector( wxCommandEvent& aEvent )
360{
362
363 // Zones with no net never have islands removed
364 if( m_netSelector->GetSelectedNetcode() == INVALID_NET_CODE )
365 {
366 if( m_cbRemoveIslands->IsEnabled() )
367 m_settings->SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
368
369 m_cbRemoveIslands->SetSelection( 1 );
370 m_staticText40->Enable( false );
371 m_cbRemoveIslands->Enable( false );
372 }
373 else if( !m_cbRemoveIslands->IsEnabled() )
374 {
375 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings->GetIslandRemovalMode() ) );
376 m_staticText40->Enable( true );
377 m_cbRemoveIslands->Enable( true );
378 }
379
380 wxCommandEvent* evt = new wxCommandEvent( EVT_ZONE_NET_UPDATE );
381 evt->SetId( m_netSelector->GetSelectedNetcode() );
382 wxQueueEvent( m_parent, evt );
383}
384
385
386void PANEL_ZONE_PROPERTIES::onHatched( wxCommandEvent& event )
387{
388 bool enable = m_cbHatched->GetValue();
389 m_gridStyleThickness.Enable( enable );
390 m_gridStyleGap.Enable( enable );
391 m_gridStyleRotation.Enable( enable );
392 m_staticTextGridSmoothingLevel->Enable( enable );
393 m_spinCtrlSmoothLevel->Enable( enable );
394 m_staticTextGridSmootingVal->Enable( enable );
395 m_spinCtrlSmoothValue->Enable( enable );
396 m_offsetOverridesLabel->Enable( enable );
397 m_layerSpecificOverrides->Enable( enable );
398 m_bpAddCustomLayer->Enable( enable );
399 m_bpDeleteCustomLayer->Enable( enable );
400}
401
402
403void PANEL_ZONE_PROPERTIES::OnAddLayerItem( wxCommandEvent& event )
404{
405 m_layerSpecificOverrides->OnAddRow(
406 [&]() -> std::pair<int, int>
407 {
408 m_layerSpecificOverrides->GetTable()->AppendRows( 1 );
409 return { m_layerSpecificOverrides->GetNumberRows() - 1, -1 };
410 } );
411}
412
413
414void PANEL_ZONE_PROPERTIES::OnDeleteLayerItem( wxCommandEvent& event )
415{
416 m_layerSpecificOverrides->OnDeleteRows(
417 [&]( int row )
418 {
419 m_layerSpecificOverrides->GetTable()->DeleteRows( row, 1 );
420 } );
421}
422
423
425{
426 if( m_netSelector->GetSelectedNetcode() <= INVALID_NET_CODE && !m_copperZoneInfoBar->IsShown() )
427 {
428 m_copperZoneInfoBar->ShowMessage( _( "<no net> will result in an isolated copper island." ), wxICON_WARNING );
429 }
430 else if( m_copperZoneInfoBar->IsShown() )
431 {
432 m_copperZoneInfoBar->Dismiss();
433 }
434}
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
PANEL_ZONE_PROPERTIES(wxWindow *aParent, PCB_BASE_FRAME *aFrame, ZONE_SETTINGS_BAG &aZonesSettingsBag)
void OnZoneNameChanged(wxCommandEvent &event) override
void onNetSelector(wxCommandEvent &aEvent)
bool AcceptOptions(bool aUseExportableSetupOnly=false)
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)
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:38
@ 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:40
#define ZONE_THICKNESS_MIN_VALUE_MM
Definition zones.h:36
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:41