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 <kiface_i.h>
27 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbnew_settings.h>
30 #include <zones.h>
31 #include <bitmaps.h>
32 #include <widgets/unit_binder.h>
33 #include <zone.h>
34 #include <board.h>
35 #include <trigo.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 
69 
70  bool TransferDataToWindow() override;
71  bool TransferDataFromWindow() override;
72 
78  bool AcceptOptions( bool aUseExportableSetupOnly = false );
79 
80  void OnStyleSelection( wxCommandEvent& event ) override;
81  void OnLayerSelection( wxDataViewEvent& event ) override;
82  void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
83  void ExportSetupToOtherCopperZones( wxCommandEvent& event ) override;
84  void OnRunFiltersButtonClick( wxCommandEvent& event ) override;
85  void OnUpdateUI( wxUpdateUIEvent& ) override;
86  void OnButtonCancelClick( wxCommandEvent& event ) override;
87  void OnClose( wxCloseEvent& event ) override;
88 
90 };
91 
92 
93 // Initialize static member variables
94 wxString DIALOG_COPPER_ZONE::m_netNameShowFilter( wxT( "*" ) );
95 
96 
98 {
99  DIALOG_COPPER_ZONE dlg( aCaller, aSettings );
100 
101  return dlg.ShowQuasiModal();
102 }
103 
104 
106  DIALOG_COPPER_ZONE_BASE( aParent ),
107  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
108  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits ),
109  m_clearance( aParent, m_clearanceLabel, m_clearanceCtrl, m_clearanceUnits ),
110  m_minWidth( aParent, m_minWidthLabel, m_minWidthCtrl, m_minWidthUnits ),
111  m_antipadClearance( aParent, m_antipadLabel, m_antipadCtrl, m_antipadUnits ),
112  m_spokeWidth( aParent, m_spokeWidthLabel, m_spokeWidthCtrl, m_spokeWidthUnits ),
113  m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits ),
114  m_gridStyleThickness( aParent, m_staticTextStyleThickness, m_tcGridStyleThickness, m_GridStyleThicknessUnits ),
115  m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits ),
116  m_islandThreshold( aParent, m_islandThresholdLabel, m_tcIslandThreshold, m_islandThresholdUnits )
117 {
118  m_Parent = aParent;
120 
121  m_ptr = aSettings;
122  m_settings = *aSettings;
124 
125  m_settingsExported = false;
126 
127  m_NetFiltering = false;
128  m_NetSortingByPadCount = true; // false = alphabetic sort, true = pad count sort
129 
130  m_sdbSizerOK->SetDefault();
131 
132  m_cbRemoveIslands->Bind( wxEVT_CHOICE,
133  [&]( wxCommandEvent& )
134  {
135  // Area mode is index 2
136  bool val = m_cbRemoveIslands->GetSelection() == 2;
137 
138  m_tcIslandThreshold->Enable( val );
139  m_islandThresholdLabel->Enable( val );
140  m_islandThresholdUnits->Enable( val );
141  } );
142 
144 }
145 
146 
148 {
150  m_cbLocked->SetValue( m_settings.m_Locked );
154 
156  {
157  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
158  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
159  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
160  }
161 
164 
165  switch( m_settings.GetPadConnection() )
166  {
167  default:
168  case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
169  case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
170  case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
171  case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
172  }
173 
174  // Do not enable/disable antipad clearance and spoke width. They might be needed if
175  // a footprint or pad overrides the zone to specify a thermal connection.
178 
180  m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings.GetMinIslandArea() ) );
181 
182  m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings.GetIslandRemovalMode() ) );
183 
185 
186  m_tcIslandThreshold->Enable( val );
187  m_islandThresholdLabel->Enable( val );
188  m_islandThresholdUnits->Enable( val );
189 
190  wxString netNameDoNotShowFilter = wxT( "Net-*" );
191  m_NetFiltering = false;
192  m_NetSortingByPadCount = true;
193 
195 
196  int opt = cfg->m_Zones.net_sort_mode;
197  m_NetFiltering = opt >= 2;
198  m_NetSortingByPadCount = opt % 2;
199 
200  netNameDoNotShowFilter = cfg->m_Zones.net_filter;
201 
203  m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
204  m_showAllNetsOpt->SetValue( !m_NetFiltering );
206 
207  // Build list of nets:
209 
211 
212  switch( m_settings.m_FillMode )
213  {
214  case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
215  default: m_GridStyleCtrl->SetSelection( 0 ); break;
216  }
217 
219  m_gridStyleRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
220 
221  // Gives a reasonable value to grid style parameters, if currently there are no defined
222  // parameters for grid pattern thickness and gap (if the value is 0)
223  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
224  // or 1mm
225  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
226  // or 1.5 mm
227  int bestvalue = m_settings.m_HatchThickness;
228 
229  if( bestvalue <= 0 ) // No defined value for m_HatchThickness
230  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
231 
233 
234  bestvalue = m_settings.m_HatchGap;
235 
236  if( bestvalue <= 0 ) // No defined value for m_HatchGap
237  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
238 
239  m_gridStyleGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
240 
243 
244  m_tcZoneName->SetValue( m_settings.m_Name );
245 
246  // Enable/Disable some widgets
247  wxCommandEvent event;
248  OnStyleSelection( event );
249 
250  Fit();
251 
252  return true;
253 }
254 
255 
256 void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
257 {
258  if( m_ListNetNameSelection->GetSelection() < 0 )
259  m_ListNetNameSelection->SetSelection( 0 );
260 
261  bool noNetSelected = m_ListNetNameSelection->GetSelection() == 0;
262  bool enableSize = !noNetSelected && ( m_cbRemoveIslands->GetSelection() == 2 );
263 
264  m_bNoNetWarning->Show( noNetSelected );
265 
266  // Zones with no net never have islands removed
267  m_cbRemoveIslands->Enable( !noNetSelected );
268  m_islandThresholdLabel->Enable( enableSize );
269  m_islandThresholdUnits->Enable( enableSize );
270  m_tcIslandThreshold->Enable( enableSize );
271 
272  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
273  {
275 
277  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
278  else
279  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
280  }
281 
283 }
284 
285 
286 void DIALOG_COPPER_ZONE::OnButtonCancelClick( wxCommandEvent& event )
287 {
288  // After an "Export Settings to Other Zones" cancel and close must return
289  // ZONE_EXPORT_VALUES instead of wxID_CANCEL.
290  Close( true );
291 }
292 
293 
295 {
297 
298  if( m_GridStyleCtrl->GetSelection() > 0 )
300  else
302 
303  if( !AcceptOptions() )
304  return false;
305 
306  m_settings.m_HatchOrientation = m_gridStyleRotation.GetValue() / 10.0; // value is returned in deci-degree
311 
312  *m_ptr = m_settings;
313  return true;
314 }
315 
316 
317 void DIALOG_COPPER_ZONE::OnClose( wxCloseEvent& event )
318 {
319  SetReturnCode( m_settingsExported ? ZONE_EXPORT_VALUES : wxID_CANCEL );
320  event.Skip();
321 }
322 
323 
324 bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
325 {
326  if( !m_clearance.Validate( 0, Mils2iu( ZONE_CLEARANCE_MAX_VALUE_MIL ) ) )
327  return false;
328 
329  if( !m_minWidth.Validate( Mils2iu( ZONE_THICKNESS_MIN_VALUE_MIL ), INT_MAX ) )
330  return false;
331 
332  if( !m_cornerRadius.Validate( 0, INT_MAX ) )
333  return false;
334 
335  if( !m_spokeWidth.Validate( 0, INT_MAX ) )
336  return false;
337 
339 
341  {
342  int minThickness = m_minWidth.GetValue();
343 
344  if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
345  return false;
346 
347  if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
348  return false;
349  }
350 
351  switch( m_PadInZoneOpt->GetSelection() )
352  {
357  }
358 
359  switch( m_OutlineDisplayCtrl->GetSelection() )
360  {
364  }
365 
367 
368  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
369  cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
370 
372 
375 
377 
379  ? 0 : m_cornerRadius.GetValue() );
380 
382 
384  m_settings.m_Locked = m_cbLocked->GetValue();
385 
388 
390  {
391  DisplayError( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
392  return false;
393  }
394 
395  cfg->m_Zones.clearance = Iu2Mils( m_settings.m_ZoneClearance );
399 
401  static_cast<ISLAND_REMOVAL_MODE>( m_cbRemoveIslands->GetSelection() ) );
403 
404  // If we use only exportable to others zones parameters, exit here:
405  if( aUseExportableSetupOnly )
406  return true;
407 
408  // Get the layer selection for this zone
409  int layers = 0;
410 
411  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
412  {
413  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
414  layers++;
415  }
416 
417  if( layers == 0 )
418  {
419  DisplayError( this, _( "No layer selected." ) );
420  return false;
421  }
422 
423  NETINFO_ITEM* net = nullptr;
424 
425  // Search net_code for this net, if a net was selected
426  if( m_ListNetNameSelection->GetSelection() > 0 )
427  {
428  wxString netname = m_ListNetNameSelection->GetStringSelection();
429  net = m_Parent->GetBoard()->FindNet( netname );
430  }
431 
432  m_settings.m_NetcodeSelection = net ? net->GetNetCode() : 0;
433 
434  m_settings.m_Name = m_tcZoneName->GetValue();
435 
436  return true;
437 }
438 
439 
440 void DIALOG_COPPER_ZONE::OnStyleSelection( wxCommandEvent& event )
441 {
442  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
443  m_tcGridStyleThickness->Enable( enable );
444  m_tcGridStyleGap->Enable( enable );
445  m_tcGridStyleOrientation->Enable( enable );
446  m_spinCtrlSmoothLevel->Enable( enable );
447  m_spinCtrlSmoothValue->Enable( enable );
448 }
449 
450 
451 void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
452 {
453  if( event.GetColumn() != 0 )
454  return;
455 
456  int row = m_layers->ItemToRow( event.GetItem() );
457 
458  bool checked = m_layers->GetToggleValue( row, 0 );
459 
460  wxVariant layerID;
461  m_layers->GetValue( layerID, row, 2 );
462 
463  m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
464 }
465 
466 
468 {
469  m_NetFiltering = !m_showAllNetsOpt->GetValue();
472 
474 
475  auto cfg = m_Parent->GetPcbNewSettings();
476 
477  int configValue = m_NetFiltering ? 2 : 0;
478 
480  configValue += 1;
481 
482  cfg->m_Zones.net_sort_mode = configValue;
483  cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
484 }
485 
486 
488 {
489  if( !AcceptOptions( true ) )
490  return;
491 
492  // Export settings ( but layer and netcode ) to others copper zones
493  BOARD* pcb = m_Parent->GetBoard();
494 
495  for( ZONE* zone : pcb->Zones() )
496  {
497  // Cannot export settings from a copper zone
498  // to a zone keepout:
499  if( zone->GetIsRuleArea() )
500  continue;
501 
502  m_settings.ExportSetting( *zone, false ); // false = partial export
503  m_settingsExported = true;
504  m_Parent->OnModify();
505  }
506 }
507 
508 
509 void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
510 {
511  m_NetFiltering = true;
512  m_showAllNetsOpt->SetValue( false );
513 
515 }
516 
517 
519 {
520  wxArrayString listNetName;
521 
523 
524  if( m_NetFiltering )
525  {
526  wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue().Lower();
527  wxString ShowFilter = m_ShowNetNameFilter->GetValue().Lower();
528 
529  for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
530  {
531  if( listNetName[ii].Lower().Matches( doNotShowFilter ) )
532  {
533  listNetName.RemoveAt( ii );
534  ii--;
535  }
536  else if( !listNetName[ii].Lower().Matches( ShowFilter ) )
537  {
538  listNetName.RemoveAt( ii );
539  ii--;
540  }
541  }
542  }
543 
544  listNetName.Insert( wxT( "<no net>" ), 0 );
545 
546  // Ensure currently selected net for the zone is visible, regardless of filters
547  int selectedNetListNdx = 0;
548  int net_select = m_settings.m_NetcodeSelection;
549 
550  if( net_select > 0 )
551  {
552  NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
553  if( selectedNet )
554  {
555  selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
556 
557  if( wxNOT_FOUND == selectedNetListNdx )
558  {
559  // the currently selected net must *always* be visible.
560  // <no net> is the zero'th index, so pick next lowest
561  listNetName.Insert( selectedNet->GetNetname(), 1 );
562  selectedNetListNdx = 1;
563  }
564  }
565  }
566 
567  m_ListNetNameSelection->Clear();
568  m_ListNetNameSelection->InsertItems( listNetName, 0 );
569  m_ListNetNameSelection->SetSelection( selectedNetListNdx );
570  m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
571 }
572 
void OnRunFiltersButtonClick(wxCommandEvent &event) override
int m_HatchSmoothingLevel
Definition: zone_settings.h:87
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
void SetMinIslandArea(long long int aArea)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1291
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
ZONES & Zones()
Definition: board.h:311
void OnButtonCancelClick(wxCommandEvent &event) override
static wxString m_netNameShowFilter
This file is part of the common library.
double m_HatchSmoothingValue
Definition: zone_settings.h:89
long long int GetMinIslandArea() const
void SetCornerSmoothingType(int aType)
void OnLayerSelection(wxDataViewEvent &event) override
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
int GetCornerSmoothingType() const
#define ZONE_CLEARANCE_MAX_VALUE_MIL
Definition: zones.h:34
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
Definition: unit_binder.cpp:96
wxString m_Name
Definition: zone_settings.h:95
#define ZONE_EXPORT_VALUES
Definition: zones.h:37
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
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:98
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:376
int m_NetcodeSelection
Definition: zone_settings.h:93
pads are covered by copper
void SetPadConnection(ZONE_CONNECTION aPadConnection)
PCB_BASE_FRAME * m_Parent
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
int ShowQuasiModal()
wxSpinCtrlDouble * m_spinCtrlSmoothValue
bool TransferDataFromWindow() override
int SortedNetnamesList(wxArrayString &aNames, bool aSortbyPadsCount)
Definition: board.cpp:1362
const wxString & GetNetname() const
Definition: netinfo.h:119
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
void ExportSetupToOtherCopperZones(wxCommandEvent &event) override
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
Thermal relief only for THT pads.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Use thermal relief for pads.
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:81
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
Definition: unit_binder.cpp:81
virtual void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen and update the ...
Handle the data for a net.
Definition: netinfo.h:64
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:32
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
long m_ThermalReliefSpokeWidth
UNIT_BINDER m_gridStyleThickness
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetCornerRadius(int aRadius)
PCBNEW_SETTINGS * GetPcbNewSettings() const
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Pads are not covered.
void OnNetSortingOptionSelected(wxCommandEvent &event) override
virtual long long int GetValue()
Return 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).
BOARD * GetBoard() const
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
static constexpr int Millimeter2iu(double mm)
bool TransferDataToWindow() override
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
double m_HatchOrientation
Definition: zone_settings.h:86
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
long m_ThermalReliefGap
void OnClose(wxCloseEvent &event) override
int m_ZoneMinThickness
Definition: zone_settings.h:83
void OnUpdateUI(wxUpdateUIEvent &) override
int GetNetCode() const
Definition: netinfo.h:113