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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <advanced_config.h>
23#include <kiface_base.h>
24#include <confirm.h>
25#include <board.h>
27#include <eda_group.h>
28#include <footprint.h>
29#include <pcb_edit_frame.h>
30#include <pcbnew_settings.h>
31#include <zone_settings.h>
35#include <widgets/unit_binder.h>
36#include <wx/statbox.h>
37#include <wx/statline.h>
38#include <wx/radiobut.h>
39
40#define LAYER_LIST_COLUMN_CHECK 0
41#define LAYER_LIST_COLUMN_ICON 1
42#define LAYER_LIST_COLUMN_NAME 2
43#define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
44
45
47{
48public:
50 CONVERT_SETTINGS* aConvertSettings, BOARD* aBoard );
52
53private:
54 bool TransferDataToWindow() override;
55 bool TransferDataFromWindow() override;
56
57 void OnLayerSelection( wxDataViewEvent& event ) override;
58 void OnSheetNameClicked( wxCommandEvent& event );
59 void OnComponentClassClicked( wxCommandEvent& event );
60 void OnGroupClicked( wxCommandEvent& event );
61
62private:
69
71 wxRadioButton* m_rbCenterline;
72 wxRadioButton* m_rbBoundingHull;
73 wxStaticText* m_gapLabel;
74 wxTextCtrl* m_gapCtrl;
75 wxStaticText* m_gapUnits;
78
79 // The name of a rule area source that is not now found on the board (e.g. after a netlist
80 // update). This is used to re-populate the zone settings if the selection is not changed.
85
88};
89
90
91int InvokeRuleAreaEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aZoneSettings, BOARD* aBoard,
92 CONVERT_SETTINGS* aConvertSettings )
93{
94 DIALOG_RULE_AREA_PROPERTIES dlg( aCaller, aZoneSettings, aConvertSettings, aBoard );
95
96 return dlg.ShowModal();
97}
98
99
101 ZONE_SETTINGS* aSettings,
102 CONVERT_SETTINGS* aConvertSettings,
103 BOARD* aBoard ) :
105 m_board( aBoard ),
107 m_convertSettings( aConvertSettings ),
108 m_rbCenterline( nullptr ),
109 m_rbBoundingHull( nullptr ),
110 m_gapLabel( nullptr ),
111 m_gapCtrl( nullptr ),
112 m_gapUnits( nullptr ),
113 m_gap( nullptr ),
114 m_cbDeleteOriginals( nullptr ),
118{
120 m_parent = aParent;
121
122 m_ptr = aSettings;
123 m_zonesettings = *aSettings;
124
126 m_areaPropertiesNb->AddPage( m_keepoutProperties, _( "Keepouts" ), true );
127
129 m_areaPropertiesNb->AddPage( m_placementProperties, _( "Placement" ) );
130
131 m_placementProperties->m_SheetRb->Connect(
132 wxEVT_CHECKBOX,
133 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
134 this );
135 m_placementProperties->m_ComponentsRb->Connect(
136 wxEVT_CHECKBOX,
137 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
138 this );
139 m_placementProperties->m_GroupRb->Connect(
140 wxEVT_CHECKBOX,
141 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
142 this );
143
144 if( aConvertSettings )
145 {
146 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
147 _( "Conversion Settings" ) );
148 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
149
150 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
151 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
152
153 bConvertSizer->AddSpacer( 2 );
154 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
155 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
156
157 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
158 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
159 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
160 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
161
162 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
163 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
164 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
165 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
166
167 bConvertSizer->AddSpacer( 2 );
168 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
169
170 bConvertSizer->AddSpacer( 6 );
171 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
172 _( "Delete source objects after conversion" ) );
173 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
174
175 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
176
177 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
178 wxLI_HORIZONTAL );
179 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
180
181 SetTitle( _( "Convert to Rule Area" ) );
182 }
183
184 BOARD* board = m_parent->GetBoard();
186
187 m_zonesettings.SetupLayersList( m_layers, m_parent, layers );
188
190
192}
193
194
196{
197 m_placementProperties->m_SheetRb->Disconnect(
198 wxEVT_CHECKBOX,
199 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
200 this );
201 m_placementProperties->m_ComponentsRb->Disconnect(
202 wxEVT_CHECKBOX,
203 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
204 this );
205 m_placementProperties->m_GroupRb->Disconnect(
206 wxEVT_CHECKBOX,
207 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
208 this );
209}
210
211
216
217
222
223
228
229
231{
233 {
234 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
235 m_rbBoundingHull->SetValue( true );
236 else
237 m_rbCenterline->SetValue( true );
238
239 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
240 }
241
242 // Init keepout parameters:
243 m_keepoutProperties->m_cbTracksCtrl->SetValue( m_zonesettings.GetDoNotAllowTracks() );
244 m_keepoutProperties->m_cbViasCtrl->SetValue( m_zonesettings.GetDoNotAllowVias() );
245 m_keepoutProperties->m_cbPadsCtrl->SetValue( m_zonesettings.GetDoNotAllowPads() );
246 m_keepoutProperties->m_cbFootprintsCtrl->SetValue( m_zonesettings.GetDoNotAllowFootprints() );
247 m_keepoutProperties->m_cbCopperPourCtrl->SetValue( m_zonesettings.GetDoNotAllowZoneFills() );
248
249 // Init placement parameters:
250 m_placementProperties->m_DisabledRb->SetValue( true );
251 m_placementProperties->m_SheetRb->SetValue( false );
252 m_placementProperties->m_sheetCombo->Clear();
253
254 m_placementProperties->m_ComponentsRb->SetValue( false );
255 m_placementProperties->m_componentClassCombo->Clear();
256
257 m_placementProperties->m_GroupRb->SetValue( false );
258 m_placementProperties->m_groupCombo->Clear();
259
260 wxString curSourceName = m_zonesettings.GetPlacementAreaSource();
261
262 // Load schematic sheet and component class lists
263 if( m_board )
264 {
265 // Fetch component classes
266 std::set<wxString> classNames;
267
268 for( const wxString& className : m_board->GetComponentClassManager().GetClassNames() )
269 classNames.insert( className );
270
271 for( const wxString& sourceName : classNames )
272 m_placementProperties->m_componentClassCombo->Append( sourceName );
273
274 if( !classNames.empty() )
275 m_placementProperties->m_componentClassCombo->Select( 0 );
276
277 // Fetch sheet names and groups
278 std::set<wxString> sheetNames;
279 std::set<wxString> groupNames;
280
281 for( FOOTPRINT* fp : m_board->Footprints() )
282 {
283 sheetNames.insert( fp->GetSheetname() );
284
285 if( fp->GetParentGroup() && !fp->GetParentGroup()->GetName().IsEmpty() )
286 groupNames.insert( fp->GetParentGroup()->GetName() );
287 }
288
289 for( const wxString& sourceName : sheetNames )
290 m_placementProperties->m_sheetCombo->Append( sourceName );
291
292 for( const wxString& groupName : groupNames )
293 m_placementProperties->m_groupCombo->Append( groupName );
294
295 if( !sheetNames.empty() )
296 m_placementProperties->m_sheetCombo->Select( 0 );
297
298 if( !groupNames.empty() )
299 m_placementProperties->m_groupCombo->Select( 0 );
300 }
301
302 auto setupCurrentSourceSelection = [&]( wxComboBox* cb )
303 {
304 if( curSourceName == wxEmptyString )
305 return;
306
307 if( !cb->SetStringSelection( curSourceName ) )
308 {
310 m_notFoundPlacementSourceName = curSourceName;
311 wxString notFoundDisplayName = _( "Not found on board: " ) + curSourceName;
312 cb->Insert( notFoundDisplayName, 0 );
313 cb->Select( 0 );
314 }
315 };
316
317 if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME )
318 {
319 if( m_zonesettings.GetPlacementAreaEnabled() )
320 m_placementProperties->m_SheetRb->SetValue( true );
321
322 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
325 }
326 else if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
327 {
328 if( m_zonesettings.GetPlacementAreaEnabled() )
329 m_placementProperties->m_ComponentsRb->SetValue( true );
330
331 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
334 }
335 else
336 {
337 if( m_zonesettings.GetPlacementAreaEnabled() )
338 m_placementProperties->m_GroupRb->SetValue( true );
339
340 setupCurrentSourceSelection( m_placementProperties->m_groupCombo );
343 }
344
345 // Handle most-useful notebook page selection
346 m_areaPropertiesNb->SetSelection( 0 );
347
348 if( !m_zonesettings.HasKeepoutParametersSet() && m_zonesettings.GetPlacementAreaEnabled() )
349 m_areaPropertiesNb->SetSelection( 1 );
350
351
352 m_cbLocked->SetValue( m_zonesettings.m_Locked );
353 m_tcName->SetValue( m_zonesettings.m_Name );
354
355 switch( m_zonesettings.m_ZoneBorderDisplayStyle )
356 {
357 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
358 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
361 }
362
363 m_outlineHatchPitch.SetValue( m_zonesettings.m_BorderHatchPitch );
364
366 Layout();
367
368 return true;
369}
370
371
373{
374 if( event.GetColumn() != 0 )
375 return;
376
377 int row = m_layers->ItemToRow( event.GetItem() );
378 wxVariant layerID;
379 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
380 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
381
382 const auto setSelectedLayer = [&]()
383 {
384 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
385 };
386
387 // In footprint editor, we may in "expand inner layer" mode, where we
388 // have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
389 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
390 // in board editor, this row is a normal selection
392 {
393 const FOOTPRINT* fp = static_cast<FOOTPRINT*>( m_parent->GetModel() );
394
396 {
397 if( selected )
399 else
400 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
401 }
402 else
403 {
404 // We have a custom stackup footprint, so select just that one layer
405 setSelectedLayer();
406 }
407 }
408 else
409 {
410 setSelectedLayer();
411 }
412}
413
414
416{
418 {
419 if( m_rbBoundingHull->GetValue() )
420 {
421 m_convertSettings->m_Strategy = BOUNDING_HULL;
422 m_convertSettings->m_Gap = m_gap->GetIntValue();
423 }
424 else
425 {
426 m_convertSettings->m_Strategy = CENTERLINE;
427 }
428
429 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
430 }
431
432 // Set keepout parameters:
433 m_zonesettings.SetIsRuleArea( true );
434 m_zonesettings.SetDoNotAllowTracks( m_keepoutProperties->m_cbTracksCtrl->GetValue() );
435 m_zonesettings.SetDoNotAllowVias( m_keepoutProperties->m_cbViasCtrl->GetValue() );
436 m_zonesettings.SetDoNotAllowZoneFills( m_keepoutProperties->m_cbCopperPourCtrl->GetValue() );
437 m_zonesettings.SetDoNotAllowPads( m_keepoutProperties->m_cbPadsCtrl->GetValue() );
438 m_zonesettings.SetDoNotAllowFootprints( m_keepoutProperties->m_cbFootprintsCtrl->GetValue() );
439
440 // Set placement parameters
441 m_zonesettings.SetPlacementAreaEnabled( false );
442 m_zonesettings.SetPlacementAreaSource( wxEmptyString );
443
444 auto setPlacementSource =
445 [this]( PLACEMENT_SOURCE_T sourceType )
446 {
447 m_zonesettings.SetPlacementAreaSourceType( sourceType );
448
449 wxComboBox* cb;
450
451 if( sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
452 cb = m_placementProperties->m_sheetCombo;
453 else if( sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
454 cb = m_placementProperties->m_componentClassCombo;
455 else
456 cb = m_placementProperties->m_groupCombo;
457
458 int selectedSourceIdx = cb->GetSelection();
459
460 if( selectedSourceIdx != wxNOT_FOUND )
461 {
462 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
463 && m_originalPlacementSourceType == sourceType )
464 {
465 m_zonesettings.SetPlacementAreaSource( m_notFoundPlacementSourceName );
466 }
467 else
468 {
469 m_zonesettings.SetPlacementAreaSource( cb->GetString( selectedSourceIdx ) );
470 }
471 }
472 };
473
474 if( m_placementProperties->m_SheetRb->GetValue() )
475 {
476 m_zonesettings.SetPlacementAreaEnabled( true );
477 setPlacementSource( PLACEMENT_SOURCE_T::SHEETNAME );
478 }
479 else if( m_placementProperties->m_ComponentsRb->GetValue() )
480 {
481 m_zonesettings.SetPlacementAreaEnabled( true );
482 setPlacementSource( PLACEMENT_SOURCE_T::COMPONENT_CLASS );
483 }
484 else if( m_placementProperties->m_GroupRb->GetValue() )
485 {
486 m_zonesettings.SetPlacementAreaEnabled( true );
487 setPlacementSource( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
488 }
489 else
490 {
491 setPlacementSource( m_lastPlacementSourceType );
492 }
493
494 if( m_zonesettings.m_Layers.count() == 0 )
495 {
496 DisplayError( this, _( "No layers selected." ) );
497 return false;
498 }
499
500 switch( m_OutlineDisplayCtrl->GetSelection() )
501 {
502 case 0:
503 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
504 break;
505 case 1:
507 break;
508 case 2:
510 break;
511 }
512
515 {
516 return false;
517 }
518
519 m_zonesettings.m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
520
521 m_zonesettings.m_Locked = m_cbLocked->GetValue();
522 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
523
524 m_zonesettings.m_Name = m_tcName->GetValue();
525
527 return true;
528}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
int GetCopperLayerCount() const
Definition board.cpp:985
DIALOG_RULE_AREA_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Rule Area Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(708, 471), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxBORDER_SUNKEN)
void OnLayerSelection(wxDataViewEvent &event) override
ZONE_SETTINGS m_zonesettings
the working copy of zone settings
void OnSheetNameClicked(wxCommandEvent &event)
PANEL_RULE_AREA_PROPERTIES_KEEPOUT_BASE * m_keepoutProperties
ZONE_SETTINGS * m_ptr
the pointer to the zone settings of the zone to edit
PANEL_RULE_AREA_PROPERTIES_PLACEMENT_BASE * m_placementProperties
void OnGroupClicked(wxCommandEvent &event)
DIALOG_RULE_AREA_PROPERTIES(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings, BOARD *aBoard)
void OnComponentClassClicked(wxCommandEvent &event)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:79
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...
int ShowModal() override
FRAME_T GetFrameType() const
FOOTPRINT_STACKUP GetStackupMode() const
Definition footprint.h:498
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:573
Class PANEL_RULE_AREA_PROPERTIES_KEEPOUT_BASE.
Class PANEL_RULE_AREA_PROPERTIES_PLACEMENT_BASE.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
ZONE_SETTINGS handles zones parameters.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define LAYER_LIST_ROW_ALL_INNER_LAYERS
#define LAYER_LIST_COLUMN_NAME
#define LAYER_LIST_COLUMN_CHECK
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aZoneSettings, BOARD *aBoard, CONVERT_SETTINGS *aConvertSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
#define _(s)
@ EXPAND_INNER_LAYERS
The 'normal' stackup handling, where there is a single inner layer (In1) and rule areas using it expa...
Definition footprint.h:148
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
@ CENTERLINE
@ BOUNDING_HULL
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
PLACEMENT_SOURCE_T
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:35
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:36