KiCad PCB EDA Suite
dialog_non_copper_zones_properties.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6  * Copyright (C) 1992-2021 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 <kiface_base.h>
27 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbnew_settings.h>
30 #include <widgets/unit_binder.h>
31 #include <zones.h>
32 
34 
35 
37 {
38 private:
41  ZONE_SETTINGS m_settings; // working copy of zone settings
48 
49  bool TransferDataToWindow() override;
50  bool TransferDataFromWindow() override;
51 
52  void OnStyleSelection( wxCommandEvent& event ) override;
53  void OnLayerSelection( wxDataViewEvent& event ) override;
54  void OnUpdateUI( wxUpdateUIEvent& ) override;
55 
56 public:
58 };
59 
60 
62 {
63  DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings );
64 
65  return dlg.ShowQuasiModal();
66 }
67 
68 #define MIN_THICKNESS 10*IU_PER_MILS
69 
71  ZONE_SETTINGS* aSettings ) :
73  m_minWidth( aParent, m_MinWidthLabel, m_MinWidthCtrl, m_MinWidthUnits ),
74  m_hatchRotation( aParent, m_hatchOrientLabel, m_hatchOrientCtrl, m_hatchOrientUnits ),
75  m_hatchWidth( aParent, m_hatchWidthLabel, m_hatchWidthCtrl, m_hatchWidthUnits),
76  m_hatchGap( aParent, m_hatchGapLabel, m_hatchGapCtrl, m_hatchGapUnits ),
77  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
78  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits )
79 {
80  m_parent = aParent;
81 
82  m_ptr = aSettings;
83  m_settings = *aSettings;
85 
86  m_sdbSizerButtonsOK->SetDefault();
87 
89 }
90 
91 
93 {
94  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
95  {
97 
99  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
100  else
101  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
102  }
103 
105 }
106 
107 
109 {
112 
115  m_cbLocked->SetValue( m_settings.m_Locked );
116 
118  {
119  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
120  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
121  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
122  }
123 
125 
126  switch( m_settings.m_FillMode )
127  {
128  case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
129  default: m_GridStyleCtrl->SetSelection( 0 ); break;
130  }
131 
133  m_hatchRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
134 
135  // Gives a reasonable value to grid style parameters, if currently there are no defined
136  // parameters for grid pattern thickness and gap (if the value is 0)
137  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
138  // or 1mm
139  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
140  // or 1.5 mm
141  int bestvalue = m_settings.m_HatchThickness;
142 
143  if( bestvalue <= 0 ) // No defined value for m_hatchWidth
144  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
145 
146  m_hatchWidth.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
147 
148  bestvalue = m_settings.m_HatchGap;
149 
150  if( bestvalue <= 0 ) // No defined value for m_hatchGap
151  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
152 
153  m_hatchGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
154 
157 
158  // Enable/Disable some widgets
159  wxCommandEvent event;
160  OnStyleSelection( event );
161 
162  return true;
163 }
164 
165 
167 {
168  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
169  m_hatchRotation.Enable( enable );
170  m_hatchWidth.Enable( enable );
171  m_hatchGap.Enable( enable );
172  m_smoothLevelLabel->Enable( enable );
173  m_spinCtrlSmoothLevel->Enable( enable );
174  m_smoothValueLabel->Enable( enable );
175  m_spinCtrlSmoothValue->Enable( enable );
176 }
177 
178 
180 {
181  if( event.GetColumn() != 0 )
182  return;
183 
184  int row = m_layers->ItemToRow( event.GetItem() );
185  bool val = m_layers->GetToggleValue( row, 0 );
186 
187  wxVariant layerID;
188  m_layers->GetValue( layerID, row, 2 );
189  m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
190 }
191 
192 
194 {
196 
198  ? 0 : m_cornerRadius.GetValue() );
199 
200  if( !m_hatchRotation.Validate( -1800, 1800 ) )
201  return false;
202 
204 
205  switch( m_OutlineDisplayCtrl->GetSelection() )
206  {
210  }
211 
212  if( m_GridStyleCtrl->GetSelection() > 0 )
214  else
216 
217 
219  {
220  int minThickness = m_minWidth.GetValue();
221 
222  if( !m_hatchWidth.Validate( minThickness, INT_MAX ) )
223  return false;
224 
225  if( !m_hatchGap.Validate( minThickness, INT_MAX ) )
226  return false;
227  }
228 
229 
230  m_settings.m_HatchOrientation = m_hatchRotation.GetValue() / 10.0; // value is returned in deci-degree
235 
236  auto cfg = m_parent->GetPcbNewSettings();
237  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
238 
240  m_settings.m_Locked = m_cbLocked->GetValue();
241 
242  // Get the layer selection for this zone
243  int layer = -1;
244  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
245  {
246  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
247  {
248  layer = ii;
249  break;
250  }
251  }
252 
253  if( layer < 0 )
254  {
255  DisplayError( this, _( "No layer selected." ) );
256  return false;
257  }
258 
259  *m_ptr = m_settings;
260  return true;
261 }
262 
263 
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:279
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
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
unsigned int GetCornerRadius() const
int ShowQuasiModal()
#define _(s)
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)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
Definition: unit_binder.cpp:92
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetCornerRadius(int aRadius)
PCBNEW_SETTINGS * GetPcbNewSettings() const
void OnLayerSelection(wxDataViewEvent &event) override
virtual long long int GetValue()
Return 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:905
double m_HatchOrientation
Definition: zone_settings.h:86
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
int m_ZoneMinThickness
Definition: zone_settings.h:83