KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <wx/statbox.h>
32#include <wx/statline.h>
33#include <wx/radiobut.h>
34#include <zones.h>
35
37
38
40{
41public:
43 CONVERT_SETTINGS* aConvertSettings );
44
45private:
46 bool TransferDataToWindow() override;
47 bool TransferDataFromWindow() override;
48
49 void OnStyleSelection( wxCommandEvent& event ) override;
50 void OnLayerSelection( wxDataViewEvent& event ) override;
51 void OnUpdateUI( wxUpdateUIEvent& ) override;
52
53private:
56 ZONE_SETTINGS m_settings; // working copy of zone settings
64
66 wxRadioButton* m_rbCenterline;
67 wxRadioButton* m_rbEnvelope;
69};
70
71
73 CONVERT_SETTINGS* aConvertSettings )
74{
75 DIALOG_NON_COPPER_ZONES_EDITOR dlg( aParent, aSettings, aConvertSettings );
76
77 return dlg.ShowQuasiModal();
78}
79
80#define MIN_THICKNESS 10*pcbIUScale.IU_PER_MILS
81
83 ZONE_SETTINGS* aSettings,
84 CONVERT_SETTINGS* aConvertSettings ) :
86 m_outlineHatchPitch( aParent, m_stBorderHatchPitchText,
87 m_outlineHatchPitchCtrl, m_outlineHatchUnits ),
88 m_minWidth( aParent, m_MinWidthLabel, m_MinWidthCtrl, m_MinWidthUnits ),
89 m_hatchRotation( aParent, m_hatchOrientLabel, m_hatchOrientCtrl, m_hatchOrientUnits ),
90 m_hatchWidth( aParent, m_hatchWidthLabel, m_hatchWidthCtrl, m_hatchWidthUnits),
91 m_hatchGap( aParent, m_hatchGapLabel, m_hatchGapCtrl, m_hatchGapUnits ),
92 m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
93 m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits ),
94 m_convertSettings( aConvertSettings ),
95 m_rbCenterline( nullptr ),
96 m_rbEnvelope( nullptr ),
97 m_cbDeleteOriginals( nullptr )
98{
99 m_parent = aParent;
100
101 m_ptr = aSettings;
102 m_settings = *aSettings;
103
104 if( aConvertSettings )
105 {
106 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY, _( "Conversion Settings" ) );
107 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
108
109 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
110 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
111
112 bConvertSizer->AddSpacer( 2 );
113 m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
114 bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
115
116 bConvertSizer->AddSpacer( 6 );
117 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
118 _( "Delete source objects after conversion" ) );
119 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
120
121 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
122
123 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
124 wxLI_HORIZONTAL );
125 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
126
127 SetTitle( _( "Convert to Non Copper Zone" ) );
128 }
129
130 bool fpEditorMode = m_parent->IsType( FRAME_FOOTPRINT_EDITOR );
131
133
135
137
139}
140
141
143{
144 if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
145 {
147
149 m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
150 else
151 m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
152 }
153
155}
156
157
159{
161 {
163 m_rbEnvelope->SetValue( true );
164 else
165 m_rbCenterline->SetValue( true );
166
168 }
169
172
174 m_cbLocked->SetValue( m_settings.m_Locked );
175
177 {
178 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
179 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
180 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
181 }
182
184
186
187 switch( m_settings.m_FillMode )
188 {
189 case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
190 default: m_GridStyleCtrl->SetSelection( 0 ); break;
191 }
192
193 m_hatchRotation.SetUnits( EDA_UNITS::DEGREES );
195
196 // Gives a reasonable value to grid style parameters, if currently there are no defined
197 // parameters for grid pattern thickness and gap (if the value is 0)
198 // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
199 // or 1mm
200 // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
201 // or 1.5 mm
202 int bestvalue = m_settings.m_HatchThickness;
203
204 if( bestvalue <= 0 ) // No defined value for m_hatchWidth
205 bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, pcbIUScale.mmToIU( 1.0 ) );
206
207 m_hatchWidth.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
208
209 bestvalue = m_settings.m_HatchGap;
210
211 if( bestvalue <= 0 ) // No defined value for m_hatchGap
212 bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, pcbIUScale.mmToIU( 1.5 ) );
213
214 m_hatchGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
215
218
219 // Enable/Disable some widgets
220 wxCommandEvent event;
221 OnStyleSelection( event );
222
223 return true;
224}
225
226
228{
229 bool enable = m_GridStyleCtrl->GetSelection() >= 1;
230 m_hatchRotation.Enable( enable );
231 m_hatchWidth.Enable( enable );
232 m_hatchGap.Enable( enable );
233 m_smoothLevelLabel->Enable( enable );
234 m_spinCtrlSmoothLevel->Enable( enable );
235 m_smoothValueLabel->Enable( enable );
236 m_spinCtrlSmoothValue->Enable( enable );
237}
238
239
241{
242 if( event.GetColumn() != 0 )
243 return;
244
245 int row = m_layers->ItemToRow( event.GetItem() );
246 bool val = m_layers->GetToggleValue( row, 0 );
247
248 wxVariant layerID;
249 m_layers->GetValue( layerID, row, 2 );
250 m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), val );
251}
252
253
255{
257 {
258 if( m_rbEnvelope->GetValue() )
260 else
262
264 }
265
267
269 ? 0 : m_cornerRadius.GetValue() );
270
272
273 switch( m_OutlineDisplayCtrl->GetSelection() )
274 {
275 case 0: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
276 case 1: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
277 case 2: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
278 }
279
282 return false;
283
285
286 if( m_GridStyleCtrl->GetSelection() > 0 )
287 m_settings.m_FillMode = ZONE_FILL_MODE::HATCH_PATTERN;
288 else
289 m_settings.m_FillMode = ZONE_FILL_MODE::POLYGONS;
290
291
292 if( m_settings.m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
293 {
294 int minThickness = m_minWidth.GetValue();
295
296 if( !m_hatchWidth.Validate( minThickness, INT_MAX ) )
297 return false;
298
299 if( !m_hatchGap.Validate( minThickness, INT_MAX ) )
300 return false;
301 }
302
303
309
310 m_settings.m_Locked = m_cbLocked->GetValue();
311
312 // Get the layer selection for this zone
313 int layer = -1;
314 for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
315 {
316 if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
317 {
318 layer = ii;
319 break;
320 }
321 }
322
323 if( layer < 0 )
324 {
325 DisplayError( this, _( "No layer selected." ) );
326 return false;
327 }
328
329 *m_ptr = m_settings;
330 return true;
331}
332
333
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
Class DIALOG_NONCOPPER_ZONES_PROPERTIES_BASE.
DIALOG_NON_COPPER_ZONES_EDITOR(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
void OnStyleSelection(wxCommandEvent &event) override
void OnLayerSelection(wxDataViewEvent &event) override
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 SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowQuasiModal()
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool IsType(FRAME_T aType) const
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:794
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
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...
virtual EDA_ANGLE GetAngleValue()
virtual void SetAngleValue(const EDA_ANGLE &aValue)
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.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:70
EDA_ANGLE m_HatchOrientation
Definition: zone_settings.h:88
double m_HatchSmoothingValue
Definition: zone_settings.h:91
int m_ZoneMinThickness
Definition: zone_settings.h:85
void SetCornerRadius(int aRadius)
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers, bool aFpEditorMode)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
int GetCornerSmoothingType() const
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:83
void SetCornerSmoothingType(int aType)
int m_HatchSmoothingLevel
Definition: zone_settings.h:89
unsigned int GetCornerRadius() const
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:283
This file is part of the common library.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
#define _(s)
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:41
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
@ CENTERLINE
@ BOUNDING_HULL
CONVERT_STRATEGY m_Strategy
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition: zones.h:40
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition: zones.h:41