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 <kiface_i.h>
30 #include <confirm.h>
31 #include <pcb_edit_frame.h>
32 #include <pcbnew_settings.h>
33 #include <widgets/unit_binder.h>
34 #include <zones.h>
35 
37 
38 
40 {
41 private:
44  ZONE_SETTINGS m_settings; // working copy of zone settings
51 
52  bool TransferDataToWindow() override;
53  bool TransferDataFromWindow() override;
54 
55  void OnStyleSelection( wxCommandEvent& event ) override;
56  void OnLayerSelection( wxDataViewEvent& event ) override;
57  void OnUpdateUI( wxUpdateUIEvent& ) override;
58 
59 public:
61 };
62 
63 
65 {
66  DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings );
67 
68  return dlg.ShowModal();
69 }
70 
71 #define MIN_THICKNESS 10*IU_PER_MILS
72 
74  ZONE_SETTINGS* aSettings ) :
76  m_minWidth( aParent, m_MinWidthLabel, m_MinWidthCtrl, m_MinWidthUnits, true ),
77  m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits,
78  false ),
79  m_gridStyleThickness( aParent, m_staticTextStyleThickness,
80  m_tcGridStyleThickness, m_GridStyleThicknessUnits, false),
81  m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits, false ),
82  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
83  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits, true )
84 {
85  m_parent = aParent;
86 
87  m_ptr = aSettings;
88  m_settings = *aSettings;
90 
91  m_sdbSizerButtonsOK->SetDefault();
92 
94 }
95 
96 
98 {
99  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
100  {
102 
104  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
105  else
106  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
107  }
108 
110 }
111 
112 
114 {
117 
120 
122  {
123  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
124  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
125  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
126  }
127 
129 
130  switch( m_settings.m_FillMode )
131  {
132  case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
133  default: m_GridStyleCtrl->SetSelection( 0 ); break;
134  }
135 
137  m_gridStyleRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
138 
139  // Gives a reasonable value to grid style parameters, if currently there are no defined
140  // parameters for grid pattern thickness and gap (if the value is 0)
141  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
142  // or 1mm
143  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
144  // or 1.5 mm
145  int bestvalue = m_settings.m_HatchThickness;
146 
147  if( bestvalue <= 0 ) // No defined value for m_hatchThickness
148  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
149 
151 
152  bestvalue = m_settings.m_HatchGap;
153 
154  if( bestvalue <= 0 ) // No defined value for m_hatchGap
155  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
156 
157  m_gridStyleGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
158 
161 
162  // Enable/Disable some widgets
163  wxCommandEvent event;
164  OnStyleSelection( event );
165 
166  return true;
167 }
168 
169 
171 {
172  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
173  m_tcGridStyleThickness->Enable( enable );
174  m_tcGridStyleGap->Enable( enable );
175  m_tcGridStyleOrientation->Enable( enable );
176  m_spinCtrlSmoothLevel->Enable( enable );
177  m_spinCtrlSmoothValue->Enable( enable );
178 }
179 
180 
182 {
183  if( event.GetColumn() != 0 )
184  return;
185 
186  int row = m_layers->ItemToRow( event.GetItem() );
187  bool val = m_layers->GetToggleValue( row, 0 );
188 
189  wxVariant layerID;
190  m_layers->GetValue( layerID, row, 2 );
191  m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
192 }
193 
194 
196 {
198 
200  ? 0 : m_cornerRadius.GetValue() );
201 
202  if( !m_gridStyleRotation.Validate( -1800, 1800 ) )
203  return false;
204 
206 
207  switch( m_OutlineDisplayCtrl->GetSelection() )
208  {
212  }
213 
214  if( m_GridStyleCtrl->GetSelection() > 0 )
216  else
218 
219 
221  {
222  int minThickness = m_minWidth.GetValue();
223 
224  if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
225  return false;
226 
227  if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
228  return false;
229  }
230 
231 
232  m_settings.m_HatchOrientation = m_gridStyleRotation.GetValue() / 10.0; // value is returned in deci-degree
237 
238  auto cfg = m_parent->GetPcbNewSettings();
239  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
240 
242 
243  // Get the layer selection for this zone
244  int layer = -1;
245  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
246  {
247  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
248  {
249  layer = ii;
250  break;
251  }
252  }
253 
254  if( layer < 0 )
255  {
256  DisplayError( this, _( "No layer selected." ) );
257  return false;
258  }
259 
260  *m_ptr = m_settings;
261  return true;
262 }
263 
264 
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:240
This file is part of the common library.
double m_HatchSmoothingValue
Definition: zone_settings.h:89
void SetCornerSmoothingType(int aType)
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
int GetCornerSmoothingType() const
PCBNEW_SETTINGS * GetPcbNewSettings()
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
unsigned int GetCornerRadius() const
Class DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
void OnStyleSelection(wxCommandEvent &event) override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:81
virtual void SetUnits(EDA_UNITS aUnits)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:79
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Function Validate Validates the control against the given range, informing the user of any errors fou...
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
#define _(s)
Definition: 3d_actions.cpp:33
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)
void OnLayerSelection(wxDataViewEvent &event) override
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
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).
static constexpr int Millimeter2iu(double mm)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:898
double m_HatchOrientation
Definition: zone_settings.h:86
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int m_ZoneMinThickness
Definition: zone_settings.h:83