KiCad PCB EDA Suite
dialog_non_copper_zones_properties.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
8  * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
9  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <fctsys.h>
30 #include <kiface_i.h>
31 #include <confirm.h>
32 #include <pcb_edit_frame.h>
33 #include <widgets/unit_binder.h>
34 #include <class_zone.h>
35 #include <zones.h>
36 
38 
39 
41 {
42 private:
45  ZONE_SETTINGS m_settings; // working copy of zone settings
52 
53  bool TransferDataToWindow() override;
54  bool TransferDataFromWindow() override;
55 
56  void OnStyleSelection( wxCommandEvent& event ) override;
57  void OnLayerSelection( wxDataViewEvent& event ) override;
58  void OnUpdateUI( wxUpdateUIEvent& ) override;
59 
60 public:
62 };
63 
64 
66 {
67  DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings );
68 
69  return dlg.ShowModal();
70 }
71 
72 #define MIN_THICKNESS 10*IU_PER_MILS
73 
75  ZONE_SETTINGS* aSettings ) :
77  m_minWidth( aParent, m_MinWidthLabel, m_MinWidthCtrl, m_MinWidthUnits, true ),
78  m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits,
79  false ),
80  m_gridStyleThickness( aParent, m_staticTextStyleThickness,
81  m_tcGridStyleThickness, m_GridStyleThicknessUnits, false),
82  m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits, false ),
83  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
84  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits, true )
85 {
86  m_parent = aParent;
87 
88  m_ptr = aSettings;
89  m_settings = *aSettings;
91 
92  m_sdbSizerButtonsOK->SetDefault();
93 
95 }
96 
97 
99 {
100  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
101  {
103 
105  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
106  else
107  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
108  }
109 
111 }
112 
113 
115 {
118 
121 
123  {
124  case ZONE_CONTAINER::NO_HATCH: m_OutlineAppearanceCtrl->SetSelection( 0 ); break;
125  case ZONE_CONTAINER::DIAGONAL_EDGE: m_OutlineAppearanceCtrl->SetSelection( 1 ); break;
126  case ZONE_CONTAINER::DIAGONAL_FULL: m_OutlineAppearanceCtrl->SetSelection( 2 ); break;
127  }
128 
130 
131  switch( m_settings.m_FillMode )
132  {
133  case ZFM_HATCH_PATTERN:
134  m_GridStyleCtrl->SetSelection( 1 ); break;
135  default:
136  m_GridStyleCtrl->SetSelection( 0 ); break;
137  }
138 
141 
142  // Gives a reasonable value to grid style parameters, if currently there are no defined
143  // parameters for grid pattern thickness and gap (if the value is 0)
144  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
145  // or 1mm
146  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
147  // or 1.5 mm
148  int bestvalue = m_settings.m_HatchFillTypeThickness;
149 
150  if( bestvalue <= 0 ) // No defined value for m_HatchFillTypeThickness
151  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
152 
154 
155  bestvalue = m_settings.m_HatchFillTypeGap;
156 
157  if( bestvalue <= 0 ) // No defined value for m_HatchFillTypeGap
158  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
159 
161 
164 
165  // Enable/Disable some widgets
166  wxCommandEvent event;
167  OnStyleSelection( event );
168 
169  return true;
170 }
171 
172 
174 {
175  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
176  m_tcGridStyleThickness->Enable( enable );
177  m_tcGridStyleGap->Enable( enable );
178  m_tcGridStyleOrientation->Enable( enable );
179  m_spinCtrlSmoothLevel->Enable( enable );
180  m_spinCtrlSmoothValue->Enable( enable );
181 }
182 
183 
185 {
186  if( event.GetColumn() != 0 )
187  return;
188 
189  int row = m_layers->ItemToRow( event.GetItem() );
190 
191  if( m_layers->GetToggleValue( row, 0 ) )
192  {
193  wxVariant layerID;
194  m_layers->GetValue( layerID, row, 2 );
195  m_settings.m_CurrentZone_Layer = ToLAYER_ID( layerID.GetInteger() );
196 
197  // Turn all other checkboxes off.
198  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
199  {
200  if( ii != row )
201  m_layers->SetToggleValue( false, ii, 0 );
202  }
203  }
204 }
205 
206 
208 {
210 
212  ? 0 : m_cornerRadius.GetValue() );
213 
214  if( !m_gridStyleRotation.Validate( -1800, 1800 ) )
215  return false;
216 
218 
219  switch( m_OutlineAppearanceCtrl->GetSelection() )
220  {
224  }
225 
226  if( m_GridStyleCtrl->GetSelection() > 0 )
228  else
230 
231 
233  {
234  int minThickness = m_minWidth.GetValue();
235 
236  if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
237  return false;
238 
239  if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
240  return false;
241  }
242 
243 
244  m_settings.m_HatchFillTypeOrientation = m_gridStyleRotation.GetValue()/10.0; // value is returned in deci-degree
249 
250  wxConfigBase* cfg = Kiface().KifaceSettings();
251  wxASSERT( cfg );
252 
254 
256 
257  // Get the layer selection for this zone
258  int layer = -1;
259  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
260  {
261  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
262  {
263  layer = ii;
264  break;
265  }
266  }
267 
268  if( layer < 0 )
269  {
270  DisplayError( this, _( "No layer selected." ) );
271  return false;
272  }
273 
274  *m_ptr = m_settings;
275  return true;
276 }
277 
278 
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:81
This file is part of the common library.
void SetCornerSmoothingType(int aType)
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
int m_HatchFillTypeSmoothingLevel
Grid pattern smoothing type, similar to corner smoothing type.
Definition: zone_settings.h:69
double m_HatchFillTypeOrientation
Grid style shape: orientation of grid lines in degrees.
Definition: zone_settings.h:68
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...
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
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:67
Classes to handle copper zones.
virtual void SetUnits(EDA_UNITS_T aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:65
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:116
unsigned int GetCornerRadius() const
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, bool aShowCopper)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
Class DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE.
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:49
void OnStyleSelection(wxCommandEvent &event) override
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:60
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
#define max(a, b)
Definition: auxiliary.h:86
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:71
void OnLayerSelection(wxDataViewEvent &event) override
#define ZONE_NET_OUTLINES_STYLE_KEY
Definition: zones.h:29
int m_HatchFillTypeThickness
Grid style shape: thickness of lines (if 0 -> solid shape)
Definition: zone_settings.h:66
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:244
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:78
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:65