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( __FILE__, __LINE__ );
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 
282  {
283  DisplayError( this,
284  _( "Thermal relief spoke must be greater than the minimum width." ) );
285  return false;
286  }
287 
288  if( m_Config )
289  {
298  }
299 
300  // If we use only exportable to others zones parameters, exit here:
301  if( aUseExportableSetupOnly )
302  return true;
303 
304  // Get the layer selection for this zone
305  int layer = -1;
306  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
307  {
308  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
309  {
310  layer = ii;
311  break;
312  }
313  }
314 
315  if( layer < 0 )
316  {
317  DisplayError( this, _( "No layer selected." ) );
318  return false;
319  }
320 
321  NETINFO_ITEM* net = nullptr;
322 
323  // Search net_code for this net, if a net was selected
324  if( m_ListNetNameSelection->GetSelection() > 0 )
325  net = m_Parent->GetBoard()->FindNet( m_ListNetNameSelection->GetStringSelection() );
326 
327  m_settings.m_NetcodeSelection = net ? net->GetNet() : 0;
328 
329  return true;
330 }
331 
332 
333 void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
334 {
335  if( event.GetColumn() != 0 )
336  return;
337 
338  int row = m_layers->ItemToRow( event.GetItem() );
339 
340  if( m_layers->GetToggleValue( row, 0 ) )
341  {
342  wxVariant layerID;
343  m_layers->GetValue( layerID, row, 2 );
344  m_settings.m_CurrentZone_Layer = ToLAYER_ID( layerID.GetInteger() );
345 
346  // Turn all other checkboxes off.
347  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
348  {
349  if( ii != row )
350  m_layers->SetToggleValue( false, ii, 0 );
351  }
352  }
353 }
354 
355 
357 {
358  m_NetFiltering = !m_showAllNetsOpt->GetValue();
361 
363 
364  if( m_Config )
365  {
366  long configValue = m_NetFiltering ? 2 : 0;
367 
369  configValue += 1;
370 
371  m_Config->Write( ZONE_NET_SORT_OPTION_KEY, configValue );
372  wxString Filter = m_DoNotShowNetNameFilter->GetValue();
373  m_Config->Write( ZONE_NET_FILTER_STRING_KEY, Filter );
374  }
375 }
376 
377 
379 {
380  if( !AcceptOptions( true ) )
381  return;
382 
383  // Export settings ( but layer and netcode ) to others copper zones
384  BOARD* pcb = m_Parent->GetBoard();
385 
386  for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
387  {
388  ZONE_CONTAINER* zone = pcb->GetArea( ii );
389 
390  // Cannot export settings from a copper zone
391  // to a zone keepout:
392  if( zone->GetIsKeepout() )
393  continue;
394 
395  m_settings.ExportSetting( *zone, false ); // false = partial export
396  m_settingsExported = true;
397  m_Parent->OnModify();
398  }
399 }
400 
401 
402 void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
403 {
404  m_NetFiltering = true;
405  m_showAllNetsOpt->SetValue( false );
406 
408 }
409 
410 
412 {
413  wxArrayString listNetName;
414 
416 
417  if( m_NetFiltering )
418  {
419  wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue();
420  wxString ShowFilter = m_ShowNetNameFilter->GetValue();
421 
422  for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
423  {
424  if( listNetName[ii].Matches( doNotShowFilter ) )
425  {
426  listNetName.RemoveAt( ii );
427  ii--;
428  }
429  else if( !listNetName[ii].Matches( ShowFilter ) )
430  {
431  listNetName.RemoveAt( ii );
432  ii--;
433  }
434  }
435  }
436 
437  listNetName.Insert( wxT( "<no net>" ), 0 );
438 
439  // Ensure currently selected net for the zone is visible, regardless of filters
440  int selectedNetListNdx = 0;
441  int net_select = m_settings.m_NetcodeSelection;
442 
443  if( net_select > 0 )
444  {
445  NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
446  if( selectedNet )
447  {
448  selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
449 
450  if( wxNOT_FOUND == selectedNetListNdx )
451  {
452  // the currently selected net must *always* be visible.
453  // <no net> is the zero'th index, so pick next lowest
454  listNetName.Insert( selectedNet->GetNetname(), 1 );
455  selectedNetListNdx = 1;
456  }
457  }
458  }
459 
460  m_ListNetNameSelection->Clear();
461  m_ListNetNameSelection->InsertItems( listNetName, 0 );
462  m_ListNetNameSelection->SetSelection( selectedNetListNdx );
463  m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
464 }
465 
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: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.
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:608
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:65
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: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:1020
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: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:991
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: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:245
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
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