KiCad PCB EDA Suite
dialog_copper_zones.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) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2019 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, 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 
26 #include <fctsys.h>
27 #include <kiface_i.h>
28 #include <confirm.h>
29 #include <pcb_edit_frame.h>
30 #include <pcbnew_settings.h>
31 #include <zones.h>
32 #include <bitmaps.h>
33 #include <widgets/unit_binder.h>
34 #include <class_zone.h>
35 #include <class_board.h>
36 
38 
39 
41 {
42 public:
43  DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings );
44 
45 private:
47 
48  bool m_settingsExported; // settings will be written to all other zones
49 
52 
55  static wxString m_netNameShowFilter; // the filter to show nets (default * "*"). Static
56  // to keep this pattern for an entire Pcbnew session
58 
64 
68 
69  bool TransferDataToWindow() override;
70  bool TransferDataFromWindow() override;
71 
77  bool AcceptOptions( bool aUseExportableSetupOnly = false );
78 
79  void OnStyleSelection( wxCommandEvent& event ) override;
80  void OnLayerSelection( wxDataViewEvent& event ) override;
81  void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
82  void ExportSetupToOtherCopperZones( wxCommandEvent& event ) override;
83  void OnRunFiltersButtonClick( wxCommandEvent& event ) override;
84  void OnUpdateUI( wxUpdateUIEvent& ) override;
85  void OnButtonCancelClick( wxCommandEvent& event ) override;
86  void OnClose( wxCloseEvent& event ) override;
87 
89 };
90 
91 
92 // Initialize static member variables
93 wxString DIALOG_COPPER_ZONE::m_netNameShowFilter( wxT( "*" ) );
94 
95 
97 {
98  DIALOG_COPPER_ZONE dlg( aCaller, aSettings );
99 
100  return dlg.ShowModal();
101 }
102 
103 #define MIN_THICKNESS ZONE_THICKNESS_MIN_VALUE_MIL*IU_PER_MILS
104 
106  DIALOG_COPPER_ZONE_BASE( aParent ),
107  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
108  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits, true ),
109  m_clearance( aParent, m_clearanceLabel, m_clearanceCtrl, m_clearanceUnits, true ),
110  m_minWidth( aParent, m_minWidthLabel, m_minWidthCtrl, m_minWidthUnits, true ),
111  m_antipadClearance( aParent, m_antipadLabel, m_antipadCtrl, m_antipadUnits, true ),
112  m_spokeWidth( aParent, m_spokeWidthLabel, m_spokeWidthCtrl, m_spokeWidthUnits, true ),
113  m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits,
114  false ),
115  m_gridStyleThickness( aParent, m_staticTextStyleThickness,
116  m_tcGridStyleThickness, m_GridStyleThicknessUnits, false ),
117  m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits, false )
118 {
119  m_Parent = aParent;
121 
122  m_ptr = aSettings;
123  m_settings = *aSettings;
125 
126  m_settingsExported = false;
127 
128  m_NetFiltering = false;
129  m_NetSortingByPadCount = true; // false = alphabetic sort, true = pad count sort
130 
131  m_sdbSizerOK->SetDefault();
132 
134 }
135 
136 
138 {
143 
145  {
147  m_OutlineAppearanceCtrl->SetSelection( 0 );
148  break;
150  m_OutlineAppearanceCtrl->SetSelection( 1 );
151  break;
153  m_OutlineAppearanceCtrl->SetSelection( 2 );
154  break;
155  }
156 
159 
160  switch( m_settings.GetPadConnection() )
161  {
162  default:
164  m_PadInZoneOpt->SetSelection( 1 );
165  break;
167  m_PadInZoneOpt->SetSelection( 2 );
168  break;
170  m_PadInZoneOpt->SetSelection( 3 );
171  break;
173  m_PadInZoneOpt->SetSelection( 0 );
174  break;
175  }
176 
177  // Do not enable/disable antipad clearance and spoke width. They might be needed if
178  // a module or pad overrides the zone to specify a thermal connection.
181 
182  wxString netNameDoNotShowFilter = wxT( "Net-*" );
183  m_NetFiltering = false;
184  m_NetSortingByPadCount = true;
185 
186  auto cfg = m_Parent->GetSettings();
187 
188  int opt = cfg->m_Zones.net_sort_mode;
189  m_NetFiltering = opt >= 2;
190  m_NetSortingByPadCount = opt % 2;
191 
192  netNameDoNotShowFilter = cfg->m_Zones.net_filter;
193 
195  m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
196  m_showAllNetsOpt->SetValue( !m_NetFiltering );
198 
199  // Build list of nets:
201 
203 
204  switch( m_settings.m_FillMode )
205  {
207  m_GridStyleCtrl->SetSelection( 1 ); break;
208  default:
209  m_GridStyleCtrl->SetSelection( 0 ); break;
210  }
211 
214 
215  // Gives a reasonable value to grid style parameters, if currently there are no defined
216  // parameters for grid pattern thickness and gap (if the value is 0)
217  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
218  // or 1mm
219  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
220  // or 1.5 mm
221  int bestvalue = m_settings.m_HatchFillTypeThickness;
222 
223  if( bestvalue <= 0 ) // No defined value for m_HatchFillTypeThickness
224  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
225 
227 
228  bestvalue = m_settings.m_HatchFillTypeGap;
229 
230  if( bestvalue <= 0 ) // No defined value for m_HatchFillTypeGap
231  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
232 
233  m_gridStyleGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
234 
237 
238  // Enable/Disable some widgets
239  wxCommandEvent event;
240  OnStyleSelection( event );
241 
242  return true;
243 }
244 
245 
246 void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
247 {
248  if( m_ListNetNameSelection->GetSelection() < 0 )
249  m_ListNetNameSelection->SetSelection( 0 );
250 
251  m_bNoNetWarning->Show( m_ListNetNameSelection->GetSelection() == 0 );
252 
253  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
254  {
256 
258  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
259  else
260  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
261  }
262 
264 }
265 
266 
267 void DIALOG_COPPER_ZONE::OnButtonCancelClick( wxCommandEvent& event )
268 {
269  // After an "Export Settings to Other Zones" cancel and close must return
270  // ZONE_EXPORT_VALUES instead of wxID_CANCEL.
271  Close( true );
272 }
273 
274 
276 {
278 
279  if( m_GridStyleCtrl->GetSelection() > 0 )
281  else
283 
284  if( !AcceptOptions() )
285  return false;
286 
287  m_settings.m_HatchFillTypeOrientation = m_gridStyleRotation.GetValue()/10.0; // value is returned in deci-degree
292 
293  *m_ptr = m_settings;
294  return true;
295 }
296 
297 
298 void DIALOG_COPPER_ZONE::OnClose( wxCloseEvent& event )
299 {
300  EndModal( m_settingsExported ? ZONE_EXPORT_VALUES : wxID_CANCEL );
301 }
302 
303 
304 bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
305 {
306  if( !m_clearance.Validate( 0, Mils2iu( ZONE_CLEARANCE_MAX_VALUE_MIL ) ) )
307  return false;
308 
309  if( !m_minWidth.Validate( Mils2iu( ZONE_THICKNESS_MIN_VALUE_MIL ), INT_MAX ) )
310  return false;
311 
312  if( !m_cornerRadius.Validate( 0, INT_MAX ) )
313  return false;
314 
315  if( !m_spokeWidth.Validate( 0, INT_MAX ) )
316  return false;
317 
319 
321  {
322  int minThickness = m_minWidth.GetValue();
323 
324  if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
325  return false;
326 
327  if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
328  return false;
329  }
330 
331  switch( m_PadInZoneOpt->GetSelection() )
332  {
333  case 3:
335  break;
336  case 2:
338  break;
339  case 1:
341  break;
342  case 0:
344  break;
345  }
346 
347  switch( m_OutlineAppearanceCtrl->GetSelection() )
348  {
349  case 0:
351  break;
352  case 1:
354  break;
355  case 2:
357  break;
358  }
359 
360  auto cfg = m_Parent->GetSettings();
361 
362  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_Zone_HatchingStyle );
363  cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
364 
366 
369 
371 
373  ? 0 : m_cornerRadius.GetValue() );
374 
376 
378 
381 
383  {
384  DisplayError( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
385  return false;
386  }
387 
388  cfg->m_Zones.clearance = Iu2Mils( m_settings.m_ZoneClearance );
389  cfg->m_Zones.min_thickness = Iu2Mils( m_settings.m_ZoneMinThickness );
390  cfg->m_Zones.thermal_relief_gap = Iu2Mils( m_settings.m_ThermalReliefGap );
391  cfg->m_Zones.thermal_relief_copper_width = Iu2Mils( m_settings.m_ThermalReliefCopperBridge );
392 
393  // If we use only exportable to others zones parameters, exit here:
394  if( aUseExportableSetupOnly )
395  return true;
396 
397  // Get the layer selection for this zone
398  int layer = -1;
399  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
400  {
401  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
402  {
403  layer = ii;
404  break;
405  }
406  }
407 
408  if( layer < 0 )
409  {
410  DisplayError( this, _( "No layer selected." ) );
411  return false;
412  }
413 
414  NETINFO_ITEM* net = nullptr;
415 
416  // Search net_code for this net, if a net was selected
417  if( m_ListNetNameSelection->GetSelection() > 0 )
418  {
419  wxString netname = m_ListNetNameSelection->GetStringSelection();
420  net = m_Parent->GetBoard()->FindNet( netname );
421  }
422 
423  m_settings.m_NetcodeSelection = net ? net->GetNet() : 0;
424 
425  return true;
426 }
427 
428 
429 void DIALOG_COPPER_ZONE::OnStyleSelection( wxCommandEvent& event )
430 {
431  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
432  m_tcGridStyleThickness->Enable( enable );
433  m_tcGridStyleGap->Enable( enable );
434  m_tcGridStyleOrientation->Enable( enable );
435  m_spinCtrlSmoothLevel->Enable( enable );
436  m_spinCtrlSmoothValue->Enable( enable );
437 }
438 
439 
440 void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
441 {
442  if( event.GetColumn() != 0 )
443  return;
444 
445  int row = m_layers->ItemToRow( event.GetItem() );
446 
447  if( m_layers->GetToggleValue( row, 0 ) )
448  {
449  wxVariant layerID;
450  m_layers->GetValue( layerID, row, 2 );
451  m_settings.m_CurrentZone_Layer = ToLAYER_ID( layerID.GetInteger() );
452 
453  // Turn all other checkboxes off.
454  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
455  {
456  if( ii != row )
457  m_layers->SetToggleValue( false, ii, 0 );
458  }
459  }
460 }
461 
462 
464 {
465  m_NetFiltering = !m_showAllNetsOpt->GetValue();
468 
470 
471  auto cfg = m_Parent->GetSettings();
472 
473  int configValue = m_NetFiltering ? 2 : 0;
474 
476  configValue += 1;
477 
478  cfg->m_Zones.net_sort_mode = configValue;
479  cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
480 }
481 
482 
484 {
485  if( !AcceptOptions( true ) )
486  return;
487 
488  // Export settings ( but layer and netcode ) to others copper zones
489  BOARD* pcb = m_Parent->GetBoard();
490 
491  for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
492  {
493  ZONE_CONTAINER* zone = pcb->GetArea( ii );
494 
495  // Cannot export settings from a copper zone
496  // to a zone keepout:
497  if( zone->GetIsKeepout() )
498  continue;
499 
500  m_settings.ExportSetting( *zone, false ); // false = partial export
501  m_settingsExported = true;
502  m_Parent->OnModify();
503  }
504 }
505 
506 
507 void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
508 {
509  m_NetFiltering = true;
510  m_showAllNetsOpt->SetValue( false );
511 
513 }
514 
515 
517 {
518  wxArrayString listNetName;
519 
521 
522  if( m_NetFiltering )
523  {
524  wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue();
525  wxString ShowFilter = m_ShowNetNameFilter->GetValue();
526 
527  for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
528  {
529  if( listNetName[ii].Matches( doNotShowFilter ) )
530  {
531  listNetName.RemoveAt( ii );
532  ii--;
533  }
534  else if( !listNetName[ii].Matches( ShowFilter ) )
535  {
536  listNetName.RemoveAt( ii );
537  ii--;
538  }
539  }
540  }
541 
542  listNetName.Insert( wxT( "<no net>" ), 0 );
543 
544  // Ensure currently selected net for the zone is visible, regardless of filters
545  int selectedNetListNdx = 0;
546  int net_select = m_settings.m_NetcodeSelection;
547 
548  if( net_select > 0 )
549  {
550  NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
551  if( selectedNet )
552  {
553  selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
554 
555  if( wxNOT_FOUND == selectedNetListNdx )
556  {
557  // the currently selected net must *always* be visible.
558  // <no net> is the zero'th index, so pick next lowest
559  listNetName.Insert( selectedNet->GetNetname(), 1 );
560  selectedNetListNdx = 1;
561  }
562  }
563  }
564 
565  m_ListNetNameSelection->Clear();
566  m_ListNetNameSelection->InsertItems( listNetName, 0 );
567  m_ListNetNameSelection->SetSelection( selectedNetListNdx );
568  m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
569 }
570 
void OnRunFiltersButtonClick(wxCommandEvent &event) override
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void OnButtonCancelClick(wxCommandEvent &event) override
static wxString m_netNameShowFilter
This file is part of the common library.
void SetCornerSmoothingType(int aType)
void OnLayerSelection(wxDataViewEvent &event) override
long m_ThermalReliefCopperBridge
thickness of the copper bridge in thermal reliefs
Definition: zone_settings.h:94
int m_HatchFillTypeSmoothingLevel
Grid pattern smoothing type, similar to corner smoothing type 0 = no smoothing, 1 = fillet,...
Definition: zone_settings.h:79
double m_HatchFillTypeOrientation
Grid style shape: orientation of grid lines in degrees.
Definition: zone_settings.h:78
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int GetCornerSmoothingType() const
int m_HatchFillTypeGap
Grid style shape: clearance between lines (0 -> solid shape)
Definition: zone_settings.h:77
#define ZONE_CLEARANCE_MAX_VALUE_MIL
Definition: zones.h:34
#define ZONE_EXPORT_VALUES
Definition: zones.h:37
Class DIALOG_COPPER_ZONE_BASE.
ZONE_CONNECTION GetPadConnection() const
void OnStyleSelection(wxCommandEvent &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:115
unsigned int GetCornerRadius() const
bool AcceptOptions(bool aUseExportableSetupOnly=false)
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:345
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:84
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:919
pads are covered by copper
void SetPadConnection(ZONE_CONNECTION aPadConnection)
PCB_BASE_FRAME * m_Parent
const BITMAP_OPAQUE dialog_warning_xpm[1]
wxSpinCtrlDouble * m_spinCtrlSmoothValue
bool TransferDataFromWindow() override
int m_ZonePriority
Priority (0 ... N) of the zone.
Definition: zone_settings.h:72
ZONE_HATCH_STYLE m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:91
int SortedNetnamesList(wxArrayString &aNames, bool aSortbyPadsCount)
Function SortedNetnamesList.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:232
int m_ZoneClearance
Minimal clearance value.
Definition: zone_settings.h:74
void ExportSetupToOtherCopperZones(wxCommandEvent &event) override
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:649
Thermal relief only for THT pads.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:58
Use thermal relief for pads.
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:70
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:32
int GetNet() const
Function GetNet.
Definition: netinfo.h:224
UNIT_BINDER m_gridStyleThickness
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
void SetCornerRadius(int aRadius)
double m_HatchFillTypeSmoothingValue
Grid pattern chamfer distance/fillet value.
Definition: zone_settings.h:81
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Pads are not covered.
void OnNetSortingOptionSelected(wxCommandEvent &event) override
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, bool aShowCopper, bool aFpEditorMode=false)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:884
BOARD * GetBoard() const
int m_HatchFillTypeThickness
Grid style shape: thickness of lines (if 0 -> solid shape)
Definition: zone_settings.h:76
bool TransferDataToWindow() override
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:823
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:88
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
long m_ThermalReliefGap
thickness of the gap in thermal reliefs
Definition: zone_settings.h:93
void OnClose(wxCloseEvent &event) override
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:75
virtual void SetUnits(EDA_UNITS aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:68
PCBNEW_SETTINGS * GetSettings()
void OnUpdateUI(wxUpdateUIEvent &) override