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 {
229  {
230  KIDIALOG dlg( this, _( "The legacy segment fill mode is not recommended."
231  "Convert zone to polygon fill? "), _( "Legacy Warning" ),
232  wxYES_NO | wxICON_WARNING );
233  dlg.DoNotShowCheckbox();
234 
235  if( dlg.ShowModal() == wxYES )
237  }
238 
239  switch( m_PadInZoneOpt->GetSelection() )
240  {
245  }
246 
247  switch( m_OutlineAppearanceCtrl->GetSelection() )
248  {
252  }
253 
254  if( m_Config )
255  {
257  wxString filter = m_DoNotShowNetNameFilter->GetValue();
258  m_Config->Write( ZONE_NET_FILTER_STRING_KEY, filter );
259  }
260 
262 
263  if( !m_clearance.Validate( true ) )
264  return false;
266 
267  if( !m_minWidth.Validate( true ) )
268  return false;
270 
273 
275 
277 
280 
281  if( m_Config )
282  {
284  (double) m_settings.m_ZoneClearance / IU_PER_MILS );
286  (double) m_settings.m_ZoneMinThickness / IU_PER_MILS );
288  (double) m_settings.m_ThermalReliefGap / IU_PER_MILS );
290  (double) m_settings.m_ThermalReliefCopperBridge / IU_PER_MILS );
291  }
292 
293  // If we use only exportable to others zones parameters, exit here:
294  if( aUseExportableSetupOnly )
295  return true;
296 
297  // Get the layer selection for this zone
298  int layer = -1;
299  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
300  {
301  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
302  {
303  layer = ii;
304  break;
305  }
306  }
307 
308  if( layer < 0 )
309  {
310  DisplayError( this, _( "No layer selected." ) );
311  return false;
312  }
313 
314  NETINFO_ITEM* net = nullptr;
315 
316  // Search net_code for this net, if a net was selected
317  if( m_ListNetNameSelection->GetSelection() > 0 )
318  net = m_Parent->GetBoard()->FindNet( m_ListNetNameSelection->GetStringSelection() );
319 
320  m_settings.m_NetcodeSelection = net ? net->GetNet() : 0;
321 
322  return true;
323 }
324 
325 
326 void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
327 {
328  if( event.GetColumn() != 0 )
329  return;
330 
331  int row = m_layers->ItemToRow( event.GetItem() );
332 
333  if( m_layers->GetToggleValue( row, 0 ) )
334  {
335  wxVariant layerID;
336  m_layers->GetValue( layerID, row, 2 );
337  m_settings.m_CurrentZone_Layer = ToLAYER_ID( layerID.GetInteger() );
338 
339  // Turn all other checkboxes off.
340  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
341  {
342  if( ii != row )
343  m_layers->SetToggleValue( false, ii, 0 );
344  }
345  }
346 }
347 
348 
350 {
351  m_NetFiltering = !m_showAllNetsOpt->GetValue();
354 
356 
357  if( m_Config )
358  {
359  long configValue = m_NetFiltering ? 2 : 0;
360 
362  configValue += 1;
363 
364  m_Config->Write( ZONE_NET_SORT_OPTION_KEY, configValue );
365  wxString Filter = m_DoNotShowNetNameFilter->GetValue();
366  m_Config->Write( ZONE_NET_FILTER_STRING_KEY, Filter );
367  }
368 }
369 
370 
372 {
373  if( !AcceptOptions( true ) )
374  return;
375 
376  // Export settings ( but layer and netcode ) to others copper zones
377  BOARD* pcb = m_Parent->GetBoard();
378 
379  for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
380  {
381  ZONE_CONTAINER* zone = pcb->GetArea( ii );
382 
383  // Cannot export settings from a copper zone
384  // to a zone keepout:
385  if( zone->GetIsKeepout() )
386  continue;
387 
388  m_settings.ExportSetting( *zone, false ); // false = partial export
389  m_settingsExported = true;
390  m_Parent->OnModify();
391  }
392 }
393 
394 
395 void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
396 {
397  m_NetFiltering = true;
398  m_showAllNetsOpt->SetValue( false );
399 
401 }
402 
403 
405 {
406  wxArrayString listNetName;
407 
409 
410  if( m_NetFiltering )
411  {
412  wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue();
413  wxString ShowFilter = m_ShowNetNameFilter->GetValue();
414 
415  for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
416  {
417  if( listNetName[ii].Matches( doNotShowFilter ) )
418  {
419  listNetName.RemoveAt( ii );
420  ii--;
421  }
422  else if( !listNetName[ii].Matches( ShowFilter ) )
423  {
424  listNetName.RemoveAt( ii );
425  ii--;
426  }
427  }
428  }
429 
430  listNetName.Insert( wxT( "<no net>" ), 0 );
431 
432  // Ensure currently selected net for the zone is visible, regardless of filters
433  int selectedNetListNdx = 0;
434  int net_select = m_settings.m_NetcodeSelection;
435 
436  if( net_select > 0 )
437  {
438  NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
439  if( selectedNet )
440  {
441  selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
442 
443  if( wxNOT_FOUND == selectedNetListNdx )
444  {
445  // the currently selected net must *always* be visible.
446  // <no net> is the zero'th index, so pick next lowest
447  listNetName.Insert( selectedNet->GetNetname(), 1 );
448  selectedNetListNdx = 1;
449  }
450  }
451  }
452 
453  m_ListNetNameSelection->Clear();
454  m_ListNetNameSelection->InsertItems( listNetName, 0 );
455  m_ListNetNameSelection->SetSelection( selectedNetListNdx );
456  m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
457 }
458 
void OnRunFiltersButtonClick(wxCommandEvent &event) override
virtual bool Validate(bool setFocusOnError=false)
Function Validate Validates the control, informing the user of any errors found.
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:74
Class 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
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
void DoNotShowCheckbox()
Shows the &#39;do not show again&#39; checkbox
Definition: confirm.h:54
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:80
Class BOARD to handle a board.
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.
virtual int GetValue() const
Function GetValue Returns the current value in Internal Units.
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.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:67
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
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:63
int SortedNetnamesList(wxArrayString &aNames, bool aSortbyPadsCount)
Function SortedNetnamesList.
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:65
#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:1017
void ExportSetupToOtherCopperZones(wxCommandEvent &event) override
int GetNet() const
Function GetNet.
Definition: netinfo.h:227
Thermal relief only for THT pads.
Definition: zones.h:55
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:50
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:61
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:988
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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 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:95
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:235
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:233
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:803
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:71
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:79
void OnClose(wxCloseEvent &event) override
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:66
pads are covered by copper
Definition: zones.h:54
void OnUpdateUI(wxUpdateUIEvent &) override