KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_rule_area_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) 2014 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 <board.h>
29#include <pcb_edit_frame.h>
30#include <pcbnew_settings.h>
31#include <zone_settings.h>
33#include <widgets/unit_binder.h>
34#include <wx/statbox.h>
35#include <wx/statline.h>
36#include <wx/radiobut.h>
37
38#define LAYER_LIST_COLUMN_CHECK 0
39#define LAYER_LIST_COLUMN_ICON 1
40#define LAYER_LIST_COLUMN_NAME 2
41#define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
42
43
45{
46public:
48 CONVERT_SETTINGS* aConvertSettings );
49
50private:
51 bool TransferDataToWindow() override;
52 bool TransferDataFromWindow() override;
53
54 void OnLayerSelection( wxDataViewEvent& event ) override;
55 void OnRuleTypeSelect( wxCommandEvent& event ) override;
56
57private:
63
65 wxRadioButton* m_rbCenterline;
66 wxRadioButton* m_rbBoundingHull;
67 wxStaticText* m_gapLabel;
68 wxTextCtrl* m_gapCtrl;
69 wxStaticText* m_gapUnits;
72};
73
74
76 CONVERT_SETTINGS* aConvertSettings )
77{
78 DIALOG_RULE_AREA_PROPERTIES dlg( aCaller, aZoneSettings, aConvertSettings );
79
80 return dlg.ShowModal();
81}
82
83
85 ZONE_SETTINGS* aSettings,
86 CONVERT_SETTINGS* aConvertSettings ) :
88 m_outlineHatchPitch( aParent, m_stBorderHatchPitchText,
89 m_outlineHatchPitchCtrl, m_outlineHatchUnits ),
90 m_convertSettings( aConvertSettings ),
91 m_rbCenterline( nullptr ),
92 m_rbBoundingHull( nullptr ),
93 m_cbDeleteOriginals( nullptr )
94{
95 m_parent = aParent;
96
97 m_ptr = aSettings;
98 m_zonesettings = *aSettings;
99
100 if( aConvertSettings )
101 {
102 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
103 _( "Conversion Settings" ) );
104 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
105
106 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
107 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
108
109 bConvertSizer->AddSpacer( 2 );
110 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
111 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
112
113 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
114 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
115 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
116 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
117
118 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
119 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
120 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
121 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
122
123 bConvertSizer->AddSpacer( 2 );
124 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
125
126 bConvertSizer->AddSpacer( 6 );
127 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
128 _( "Delete source objects after conversion" ) );
129 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
130
131 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
132
133 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
134 wxLI_HORIZONTAL );
135 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
136
137 SetTitle( _( "Convert to Rule Area" ) );
138 }
139
141
142 BOARD* board = m_parent->GetBoard();
144
146
148
150}
151
152
154{
156 {
158 m_rbBoundingHull->SetValue( true );
159 else
160 m_rbCenterline->SetValue( true );
161
163 }
164
165 if( m_zonesettings.GetRuleAreaType() == RULE_AREA_TYPE::KEEPOUT )
166 {
167 // Init keepout parameters:
173 m_rbRuleType->Select( 0 );
174 m_placementRuleSizer->Show( false );
175 m_keepoutRuleSizer->Show( true );
176 }
177 else
178 {
179 m_placementRuleSizer->Show( true );
180 m_keepoutRuleSizer->Show( false );
181 m_rbRuleType->Select( 1 );
182 }
183
186
187 m_tcName->SetValue( m_zonesettings.m_Name );
188
190 {
191 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
192 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
193 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
194 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
195 }
196
198
200 Layout();
201
202 return true;
203}
204
205
207{
208 if( m_rbRuleType->GetSelection() == 0 )
209 {
210 m_zonesettings.SetRuleAreaType( RULE_AREA_TYPE::KEEPOUT );
211 m_placementRuleSizer->Show( false );
212 m_keepoutRuleSizer->Show( true );
213 Layout();
214 }
215 else
216 {
217 m_zonesettings.SetRuleAreaType( RULE_AREA_TYPE::PLACEMENT );
218 m_placementRuleSizer->Show( true );
219 m_keepoutRuleSizer->Show( false );
220 Layout();
221 }
222}
223
224
226{
227 if( event.GetColumn() != 0 )
228 return;
229
230 int row = m_layers->ItemToRow( event.GetItem() );
231 wxVariant layerID;
232 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
233 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
234
235 // In footprint editor, we have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
236 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
237 // in board editor, this row is a normal selection
239 {
240 if( selected )
242 else
243 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
244 }
245 else
246 {
247 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
248 }
249}
250
251
253{
255 {
256 if( m_rbBoundingHull->GetValue() )
257 {
260 }
261 else
262 {
264 }
265
267 }
268
269 // Init keepout parameters:
270 m_zonesettings.SetRuleAreaType( m_rbRuleType->GetSelection() == 0 ? RULE_AREA_TYPE::KEEPOUT : RULE_AREA_TYPE::PLACEMENT );
278
279 if( m_zonesettings.m_Layers.count() == 0 )
280 {
281 DisplayError( this, _( "No layers selected." ) );
282 return false;
283 }
284
285 switch( m_OutlineDisplayCtrl->GetSelection() )
286 {
287 case 0:
288 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
289 break;
290 case 1:
291 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
292 break;
293 case 2:
294 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
295 break;
296 }
297
300 return false;
301
303
304 m_zonesettings.m_Locked = m_cbLocked->GetValue();
305 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
306
307 m_zonesettings.m_Name = m_tcName->GetValue();
308
310 return true;
311}
312
313
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
BASE_SET & set(size_t pos)
Definition: base_set.h:115
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
int GetCopperLayerCount() const
Definition: board.cpp:736
Class DIALOG_RULE_AREA_PROPERTIES_BASE.
void OnRuleTypeSelect(wxCommandEvent &event) override
void OnLayerSelection(wxDataViewEvent &event) override
ZONE_SETTINGS m_zonesettings
the working copy of zone settings
ZONE_SETTINGS * m_ptr
the pointer to the zone settings of the zone to edit
DIALOG_RULE_AREA_PROPERTIES(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
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
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:687
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:665
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
int GetIntValue()
Definition: unit_binder.h:129
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:78
bool GetDoNotAllowCopperPour() const
void SetIsRuleArea(bool aEnable)
RULE_AREA_TYPE GetRuleAreaType() const
const wxString & GetRuleAreaExpression() const
bool GetDoNotAllowTracks() const
void SetDoNotAllowVias(bool aEnable)
bool GetDoNotAllowFootprints() const
bool GetDoNotAllowPads() const
void SetDoNotAllowTracks(bool aEnable)
bool GetDoNotAllowVias() const
unsigned m_ZonePriority
Definition: zone_settings.h:89
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers, bool aFpEditorMode)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
wxString m_Name
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowPads(bool aEnable)
void SetRuleAreaType(RULE_AREA_TYPE aType)
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
void SetRuleAreaExpression(const wxString &aExpr)
void SetDoNotAllowCopperPour(bool aEnable)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
#define LAYER_LIST_ROW_ALL_INNER_LAYERS
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aZoneSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
#define LAYER_LIST_COLUMN_NAME
#define LAYER_LIST_COLUMN_CHECK
#define _(s)
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
@ CENTERLINE
@ BOUNDING_HULL
CONVERT_STRATEGY m_Strategy
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition: zones.h:40
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition: zones.h:41