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 <pcbnew_settings.h>
34 #include <widgets/unit_binder.h>
35 #include <class_zone.h>
36 #include <zones.h>
37 
39 
40 
42 {
43 private:
46  ZONE_SETTINGS m_settings; // working copy of zone settings
53 
54  bool TransferDataToWindow() override;
55  bool TransferDataFromWindow() override;
56 
57  void OnStyleSelection( wxCommandEvent& event ) override;
58  void OnLayerSelection( wxDataViewEvent& event ) override;
59  void OnUpdateUI( wxUpdateUIEvent& ) override;
60 
61 public:
63 };
64 
65 
67 {
68  DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings );
69 
70  return dlg.ShowModal();
71 }
72 
73 #define MIN_THICKNESS 10*IU_PER_MILS
74 
76  ZONE_SETTINGS* aSettings ) :
78  m_minWidth( aParent, m_MinWidthLabel, m_MinWidthCtrl, m_MinWidthUnits, true ),
79  m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits,
80  false ),
81  m_gridStyleThickness( aParent, m_staticTextStyleThickness,
82  m_tcGridStyleThickness, m_GridStyleThicknessUnits, false),
83  m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits, false ),
84  m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
85  m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits, true )
86 {
87  m_parent = aParent;
88 
89  m_ptr = aSettings;
90  m_settings = *aSettings;
92 
93  m_sdbSizerButtonsOK->SetDefault();
94 
96 }
97 
98 
100 {
101  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
102  {
104 
106  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
107  else
108  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
109  }
110 
112 }
113 
114 
116 {
119 
122 
124  {
125  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
126  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
127  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
128  }
129 
131 
132  switch( m_settings.m_FillMode )
133  {
134  case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
135  default: m_GridStyleCtrl->SetSelection( 0 ); break;
136  }
137 
139  m_gridStyleRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
140 
141  // Gives a reasonable value to grid style parameters, if currently there are no defined
142  // parameters for grid pattern thickness and gap (if the value is 0)
143  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
144  // or 1mm
145  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
146  // or 1.5 mm
147  int bestvalue = m_settings.m_HatchThickness;
148 
149  if( bestvalue <= 0 ) // No defined value for m_hatchThickness
150  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
151 
153 
154  bestvalue = m_settings.m_HatchGap;
155 
156  if( bestvalue <= 0 ) // No defined value for m_hatchGap
157  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
158 
159  m_gridStyleGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
160 
163 
164  // Enable/Disable some widgets
165  wxCommandEvent event;
166  OnStyleSelection( event );
167 
168  return true;
169 }
170 
171 
173 {
174  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
175  m_tcGridStyleThickness->Enable( enable );
176  m_tcGridStyleGap->Enable( enable );
177  m_tcGridStyleOrientation->Enable( enable );
178  m_spinCtrlSmoothLevel->Enable( enable );
179  m_spinCtrlSmoothValue->Enable( enable );
180 }
181 
182 
184 {
185  if( event.GetColumn() != 0 )
186  return;
187 
188  int row = m_layers->ItemToRow( event.GetItem() );
189  bool val = m_layers->GetToggleValue( row, 0 );
190 
191  wxVariant layerID;
192  m_layers->GetValue( layerID, row, 2 );
193  m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
194 }
195 
196 
198 {
200 
202  ? 0 : m_cornerRadius.GetValue() );
203 
204  if( !m_gridStyleRotation.Validate( -1800, 1800 ) )
205  return false;
206 
208 
209  switch( m_OutlineDisplayCtrl->GetSelection() )
210  {
214  }
215 
216  if( m_GridStyleCtrl->GetSelection() > 0 )
218  else
220 
221 
223  {
224  int minThickness = m_minWidth.GetValue();
225 
226  if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
227  return false;
228 
229  if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
230  return false;
231  }
232 
233 
234  m_settings.m_HatchOrientation = m_gridStyleRotation.GetValue() / 10.0; // value is returned in deci-degree
239 
240  auto cfg = m_parent->GetPcbNewSettings();
241  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
242 
244 
245  // Get the layer selection for this zone
246  int layer = -1;
247  for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
248  {
249  if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
250  {
251  layer = ii;
252  break;
253  }
254  }
255 
256  if( layer < 0 )
257  {
258  DisplayError( this, _( "No layer selected." ) );
259  return false;
260  }
261 
262  *m_ptr = m_settings;
263  return true;
264 }
265 
266 
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:239
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.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:81
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:856
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
virtual void SetUnits(EDA_UNITS aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:81