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) 2017 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2018 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 <zones.h>
31 #include <bitmaps.h>
32 #include <widgets/unit_binder.h>
33 #include <class_zone.h>
34 #include <class_board.h>
35 
37 
38 
40 {
41 public:
42  DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings );
43 
44 private:
46  wxConfigBase* m_Config; // Current config
47 
48  bool m_settingsExported; // settings were written to all other zones
49 
52 
55  static wxString m_netNameShowFilter; // the filter to show nets (default * "*").
56  // static to keep this pattern for an entire Pcbnew session
58 
64 
65  bool TransferDataToWindow() override;
66  bool TransferDataFromWindow() override;
67 
73  bool AcceptOptions( bool aUseExportableSetupOnly = false );
74 
75  void OnLayerSelection( wxDataViewEvent& event ) override;
76  void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
77  void ExportSetupToOtherCopperZones( wxCommandEvent& event ) override;
78  void OnRunFiltersButtonClick( wxCommandEvent& event ) override;
79  void OnUpdateUI( wxUpdateUIEvent& ) override;
80  void OnButtonCancelClick( wxCommandEvent& event ) override;
81  void OnClose( wxCloseEvent& event ) override;
82 
84 };
85 
86 
87 // Initialize static member variables
88 wxString DIALOG_COPPER_ZONE::m_netNameShowFilter( wxT( "*" ) );
89 
90 
92 {
93  DIALOG_COPPER_ZONE dlg( aCaller, aSettings );
94 
95  return dlg.ShowModal();
96 }
97 
98 
100  DIALOG_COPPER_ZONE_BASE( aParent ),
101  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
107 {
108  m_Parent = aParent;
110  m_bitmapNoNetWarning->SetBitmap( KiBitmap( dialog_warning_xpm ) );
111 
112  m_ptr = aSettings;
113  m_settings = *aSettings;
115 
116  m_settingsExported = false;
117 
118  m_NetFiltering = false;
119  m_NetSortingByPadCount = true; // false = alphabetic sort, true = pad count sort
120 
121  m_sdbSizerOK->SetDefault();
122 
124 }
125 
126 
128 {
133 
135  {
136  case ZONE_CONTAINER::NO_HATCH: m_OutlineAppearanceCtrl->SetSelection( 0 ); break;
137  case ZONE_CONTAINER::DIAGONAL_EDGE: m_OutlineAppearanceCtrl->SetSelection( 1 ); break;
138  case ZONE_CONTAINER::DIAGONAL_FULL: m_OutlineAppearanceCtrl->SetSelection( 2 ); break;
139  }
140 
143 
144  switch( m_settings.GetPadConnection() )
145  {
146  default:
147  case PAD_ZONE_CONN_THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
148  case PAD_ZONE_CONN_THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
149  case PAD_ZONE_CONN_NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
150  case PAD_ZONE_CONN_FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
151  }
152 
153  // Do not enable/disable antipad clearance and spoke width. They might be needed if
154  // a module or pad overrides the zone to specify a thermal connection.
157 
158  wxString netNameDoNotShowFilter = wxT( "Net-*" );
159  m_NetFiltering = false;
160  m_NetSortingByPadCount = true;
161 
162  if( m_Config )
163  {
164  int opt = m_Config->Read( ZONE_NET_SORT_OPTION_KEY, 1l );
165  m_NetFiltering = opt >= 2;
166  m_NetSortingByPadCount = opt % 2;
167  m_Config->Read( ZONE_NET_FILTER_STRING_KEY, netNameDoNotShowFilter );
168  }
169 
171  m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
172  m_showAllNetsOpt->SetValue( !m_NetFiltering );
174 
175  // Build list of nets:
177 
178  return true;
179 }
180 
181 
182 void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
183 {
184  if( m_ListNetNameSelection->GetSelection() < 0 )
185  m_ListNetNameSelection->SetSelection( 0 );
186 
187  m_bNoNetWarning->Show( m_ListNetNameSelection->GetSelection() == 0 );
188 
189  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
190  {
192 
194  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
195  else
196  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
197  }
198 }
199 
200 
201 void DIALOG_COPPER_ZONE::OnButtonCancelClick( wxCommandEvent& event )
202 {
203  // After an "Export Settings to Other Zones" cancel and close must return
204  // ZONE_EXPORT_VALUES instead of wxID_CANCEL.
205  Close( true );
206 }
207 
208 
210 {
212 
213  if( !AcceptOptions() )
214  return false;
215 
216  *m_ptr = m_settings;
217  return true;
218 }
219 
220 void DIALOG_COPPER_ZONE::OnClose( wxCloseEvent& event )
221 {
222  EndModal( m_settingsExported ? ZONE_EXPORT_VALUES : wxID_CANCEL );
223 }
224 
225 
226 bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
227 {
228  if( !m_clearance.Validate( 0, Mils2iu( ZONE_CLEARANCE_MAX_VALUE_MIL ) ) )
229  return false;
230  if( !m_minWidth.Validate( Mils2iu( ZONE_THICKNESS_MIN_VALUE_MIL ), INT_MAX ) )
231  return false;
232  if( !m_cornerRadius.Validate( 0, INT_MAX ) )
233  return false;
234  if( !m_spokeWidth.Validate( 0, INT_MAX ) )
235  return false;
236 
238  {
239  KIDIALOG dlg( this, _( "The legacy segment fill mode is not recommended."
240  "Convert zone to polygon fill? "), _( "Legacy Warning" ),
241  wxYES_NO | wxICON_WARNING );
242  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
243 
244  if( dlg.ShowModal() == wxYES )
246  }
247 
248  switch( m_PadInZoneOpt->GetSelection() )
249  {
254  }
255 
256  switch( m_OutlineAppearanceCtrl->GetSelection() )
257  {
261  }
262 
263  if( m_Config )
264  {
266  wxString filter = m_DoNotShowNetNameFilter->GetValue();
267  m_Config->Write( ZONE_NET_FILTER_STRING_KEY, filter );
268  }
269 
271 
273 
275 
278 
280 
282 
285 
287  {
288  DisplayError( this,
289  _( "Thermal relief spoke must be greater than the minimum width." ) );
290  return false;
291  }
292 
293  if( m_Config )
294  {
303  }
304 
305  // If we use only exportable to others zones parameters, exit here:
306  if( aUseExportableSetupOnly )
307  return true;
308 
309  // Get the layer selection for this zone
310  int layer = -1;
311  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
312  {
313  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
314  {
315  layer = ii;
316  break;
317  }
318  }
319 
320  if( layer < 0 )
321  {
322  DisplayError( this, _( "No layer selected." ) );
323  return false;
324  }
325 
326  NETINFO_ITEM* net = nullptr;
327 
328  // Search net_code for this net, if a net was selected
329  if( m_ListNetNameSelection->GetSelection() > 0 )
330  net = m_Parent->GetBoard()->FindNet( m_ListNetNameSelection->GetStringSelection() );
331 
332  m_settings.m_NetcodeSelection = net ? net->GetNet() : 0;
333 
334  return true;
335 }
336 
337 
338 void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
339 {
340  if( event.GetColumn() != 0 )
341  return;
342 
343  int row = m_layers->ItemToRow( event.GetItem() );
344 
345  if( m_layers->GetToggleValue( row, 0 ) )
346  {
347  wxVariant layerID;
348  m_layers->GetValue( layerID, row, 2 );
349  m_settings.m_CurrentZone_Layer = ToLAYER_ID( layerID.GetInteger() );
350 
351  // Turn all other checkboxes off.
352  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
353  {
354  if( ii != row )
355  m_layers->SetToggleValue( false, ii, 0 );
356  }
357  }
358 }
359 
360 
362 {
363  m_NetFiltering = !m_showAllNetsOpt->GetValue();
366 
368 
369  if( m_Config )
370  {
371  long configValue = m_NetFiltering ? 2 : 0;
372 
374  configValue += 1;
375 
376  m_Config->Write( ZONE_NET_SORT_OPTION_KEY, configValue );
377  wxString Filter = m_DoNotShowNetNameFilter->GetValue();
378  m_Config->Write( ZONE_NET_FILTER_STRING_KEY, Filter );
379  }
380 }
381 
382 
384 {
385  if( !AcceptOptions( true ) )
386  return;
387 
388  // Export settings ( but layer and netcode ) to others copper zones
389  BOARD* pcb = m_Parent->GetBoard();
390 
391  for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
392  {
393  ZONE_CONTAINER* zone = pcb->GetArea( ii );
394 
395  // Cannot export settings from a copper zone
396  // to a zone keepout:
397  if( zone->GetIsKeepout() )
398  continue;
399 
400  m_settings.ExportSetting( *zone, false ); // false = partial export
401  m_settingsExported = true;
402  m_Parent->OnModify();
403  }
404 }
405 
406 
407 void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
408 {
409  m_NetFiltering = true;
410  m_showAllNetsOpt->SetValue( false );
411 
413 }
414 
415 
417 {
418  wxArrayString listNetName;
419 
421 
422  if( m_NetFiltering )
423  {
424  wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue();
425  wxString ShowFilter = m_ShowNetNameFilter->GetValue();
426 
427  for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
428  {
429  if( listNetName[ii].Matches( doNotShowFilter ) )
430  {
431  listNetName.RemoveAt( ii );
432  ii--;
433  }
434  else if( !listNetName[ii].Matches( ShowFilter ) )
435  {
436  listNetName.RemoveAt( ii );
437  ii--;
438  }
439  }
440  }
441 
442  listNetName.Insert( wxT( "<no net>" ), 0 );
443 
444  // Ensure currently selected net for the zone is visible, regardless of filters
445  int selectedNetListNdx = 0;
446  int net_select = m_settings.m_NetcodeSelection;
447 
448  if( net_select > 0 )
449  {
450  NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
451  if( selectedNet )
452  {
453  selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
454 
455  if( wxNOT_FOUND == selectedNetListNdx )
456  {
457  // the currently selected net must *always* be visible.
458  // <no net> is the zero'th index, so pick next lowest
459  listNetName.Insert( selectedNet->GetNetname(), 1 );
460  selectedNetListNdx = 1;
461  }
462  }
463  }
464 
465  m_ListNetNameSelection->Clear();
466  m_ListNetNameSelection->InsertItems( listNetName, 0 );
467  m_ListNetNameSelection->SetSelection( selectedNetListNdx );
468  m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
469 }
470 
void OnRunFiltersButtonClick(wxCommandEvent &event) override
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:72
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void DoNotShowCheckbox(wxString file, int line)
Shows the &#39;do not show again&#39; checkbox
Definition: confirm.cpp:60
void OnButtonCancelClick(wxCommandEvent &event) override
static wxString m_netNameShowFilter
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
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:78
Class BOARD to handle a board.
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
#define ZONE_CLEARANCE_MAX_VALUE_MIL
Definition: zones.h:43
BOARD * GetBoard() const
Classes to handle copper zones.
unsigned int GetCornerRadius() const
ZoneConnection GetPadConnection() const
#define ZONE_EXPORT_VALUES
Definition: zones.h:46
Class DIALOG_COPPER_ZONE_BASE.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
bool AcceptOptions(bool aUseExportableSetupOnly=false)
Function AcceptOptions.
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, bool aShowCopper)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
Pads are not covered.
Definition: zones.h:52
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:629
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:65
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
int GetCornerSmoothingType() const
#define ZONE_NET_SORT_OPTION_KEY
Definition: zones.h:30
PCB_BASE_FRAME * m_Parent
bool TransferDataFromWindow() override
int m_ZonePriority
Priority (0 ... N) of the zone.
Definition: zone_settings.h:61
int SortedNetnamesList(wxArrayString &aNames, bool aSortbyPadsCount)
Function SortedNetnamesList.
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:63
#define ZONE_THERMAL_RELIEF_GAP_STRING_KEY
Definition: zones.h:32
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
#define ZONE_NET_FILTER_STRING_KEY
Definition: zones.h:31
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1025
void ExportSetupToOtherCopperZones(wxCommandEvent &event) override
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
Thermal relief only for THT pads.
Definition: zones.h:55
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:48
void ConfigBaseWriteDouble(wxConfigBase *aConfig, const wxString &aKey, double aValue)
Function ConfigBaseWriteDouble This is a helper function to write doubles in config We cannot use wxC...
#define ZONE_MIN_THICKNESS_WIDTH_STRING_KEY
Definition: zones.h:35
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:59
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:41
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY
Definition: zones.h:33
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:996
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
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)
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
#define IU_PER_MILS
Definition: plotter.cpp:134
#define ZONE_CLEARANCE_WIDTH_STRING_KEY
Definition: zones.h:34
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void OnNetSortingOptionSelected(wxCommandEvent &event) override
void SetPadConnection(ZoneConnection aPadConnection)
int ShowModal() override
Definition: confirm.cpp:102
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing...
#define ZONE_NET_OUTLINES_STYLE_KEY
Definition: zones.h:29
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
bool TransferDataToWindow() override
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
Use thermal relief for pads.
Definition: zones.h:53
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:69
class 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:77
void OnClose(wxCloseEvent &event) override
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:64
pads are covered by copper
Definition: zones.h:54
void OnUpdateUI(wxUpdateUIEvent &) override