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;
84 
85  bool fpEditorMode = m_parent->IsType( FRAME_FOOTPRINT_EDITOR );
86 
88 
89  m_sdbSizerButtonsOK->SetDefault();
90 
92 }
93 
94 
96 {
97  if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
98  {
100 
102  m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
103  else
104  m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
105  }
106 
108 }
109 
110 
112 {
115 
118  m_cbLocked->SetValue( m_settings.m_Locked );
119 
121  {
122  case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
123  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
124  case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
125  }
126 
128 
129  switch( m_settings.m_FillMode )
130  {
131  case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
132  default: m_GridStyleCtrl->SetSelection( 0 ); break;
133  }
134 
136  m_hatchRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
137 
138  // Gives a reasonable value to grid style parameters, if currently there are no defined
139  // parameters for grid pattern thickness and gap (if the value is 0)
140  // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
141  // or 1mm
142  // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
143  // or 1.5 mm
144  int bestvalue = m_settings.m_HatchThickness;
145 
146  if( bestvalue <= 0 ) // No defined value for m_hatchWidth
147  bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
148 
149  m_hatchWidth.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
150 
151  bestvalue = m_settings.m_HatchGap;
152 
153  if( bestvalue <= 0 ) // No defined value for m_hatchGap
154  bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
155 
156  m_hatchGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
157 
160 
161  // Enable/Disable some widgets
162  wxCommandEvent event;
163  OnStyleSelection( event );
164 
165  return true;
166 }
167 
168 
170 {
171  bool enable = m_GridStyleCtrl->GetSelection() >= 1;
172  m_hatchRotation.Enable( enable );
173  m_hatchWidth.Enable( enable );
174  m_hatchGap.Enable( enable );
175  m_smoothLevelLabel->Enable( enable );
176  m_spinCtrlSmoothLevel->Enable( enable );
177  m_smoothValueLabel->Enable( enable );
178  m_spinCtrlSmoothValue->Enable( enable );
179 }
180 
181 
183 {
184  if( event.GetColumn() != 0 )
185  return;
186 
187  int row = m_layers->ItemToRow( event.GetItem() );
188  bool val = m_layers->GetToggleValue( row, 0 );
189 
190  wxVariant layerID;
191  m_layers->GetValue( layerID, row, 2 );
192  m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
193 }
194 
195 
197 {
199 
201  ? 0 : m_cornerRadius.GetValue() );
202 
203  if( !m_hatchRotation.Validate( -1800, 1800 ) )
204  return false;
205 
207 
208  switch( m_OutlineDisplayCtrl->GetSelection() )
209  {
213  }
214 
215  if( m_GridStyleCtrl->GetSelection() > 0 )
217  else
219 
220 
222  {
223  int minThickness = m_minWidth.GetValue();
224 
225  if( !m_hatchWidth.Validate( minThickness, INT_MAX ) )
226  return false;
227 
228  if( !m_hatchGap.Validate( minThickness, INT_MAX ) )
229  return false;
230  }
231 
232 
233  m_settings.m_HatchOrientation = m_hatchRotation.GetValue() / 10.0; // value is returned in deci-degree
238 
239  auto cfg = m_parent->GetPcbNewSettings();
240  cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
241 
243  m_settings.m_Locked = m_cbLocked->GetValue();
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: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.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:782
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
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers, bool aFpEditorMode)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
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.
bool IsType(FRAME_T aType) const
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.
static constexpr int Millimeter2iu(double mm)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914
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