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 wxString m_originalName;
70
72 wxRadioButton* m_rbCenterline;
73 wxRadioButton* m_rbBoundingHull;
74 wxStaticText* m_gapLabel;
75 wxTextCtrl* m_gapCtrl;
76 wxStaticText* m_gapUnits;
79
80 // The name of a rule area source that is not now found on the board (e.g. after a netlist
81 // update). This is used to re-populate the zone settings if the selection is not changed.
86
89};
90
91
92int InvokeRuleAreaEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aZoneSettings, BOARD* aBoard,
93 CONVERT_SETTINGS* aConvertSettings )
94{
95 DIALOG_RULE_AREA_PROPERTIES dlg( aCaller, aZoneSettings, aConvertSettings, aBoard );
96
97 return dlg.ShowModal();
98}
99
100
102 ZONE_SETTINGS* aSettings,
103 CONVERT_SETTINGS* aConvertSettings,
104 BOARD* aBoard ) :
106 m_board( aBoard ),
108 m_convertSettings( aConvertSettings ),
109 m_rbCenterline( nullptr ),
110 m_rbBoundingHull( nullptr ),
111 m_gapLabel( nullptr ),
112 m_gapCtrl( nullptr ),
113 m_gapUnits( nullptr ),
114 m_gap( nullptr ),
115 m_cbDeleteOriginals( nullptr ),
119{
121 m_parent = aParent;
122
123 m_ptr = aSettings;
124 m_zonesettings = *aSettings;
125
127 m_areaPropertiesNb->AddPage( m_keepoutProperties, _( "Keepouts" ), true );
128
130 m_areaPropertiesNb->AddPage( m_placementProperties, _( "Placement" ) );
131
132 m_placementProperties->m_SheetRb->Connect(
133 wxEVT_CHECKBOX,
134 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
135 this );
136 m_placementProperties->m_ComponentsRb->Connect(
137 wxEVT_CHECKBOX,
138 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
139 this );
140 m_placementProperties->m_GroupRb->Connect(
141 wxEVT_CHECKBOX,
142 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
143 this );
144
145 if( aConvertSettings )
146 {
147 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
148 _( "Conversion Settings" ) );
149 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
150
151 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
152 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
153
154 bConvertSizer->AddSpacer( 2 );
155 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
156 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
157
158 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
159 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
160 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
161 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
162
163 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
164 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
165 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
166 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
167
168 bConvertSizer->AddSpacer( 2 );
169 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
170
171 bConvertSizer->AddSpacer( 6 );
172 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
173 _( "Delete source objects after conversion" ) );
174 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
175
176 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
177
178 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
179 wxLI_HORIZONTAL );
180 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
181
182 SetTitle( _( "Convert to Rule Area" ) );
183 }
184
185 BOARD* board = m_parent->GetBoard();
187
188 m_zonesettings.SetupLayersList( m_layers, m_parent, layers );
189
191
193}
194
195
197{
198 m_placementProperties->m_SheetRb->Disconnect(
199 wxEVT_CHECKBOX,
200 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
201 this );
202 m_placementProperties->m_ComponentsRb->Disconnect(
203 wxEVT_CHECKBOX,
204 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
205 this );
206 m_placementProperties->m_GroupRb->Disconnect(
207 wxEVT_CHECKBOX,
208 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
209 this );
210}
211
212
217
218
223
224
229
230
232{
234 {
235 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
236 m_rbBoundingHull->SetValue( true );
237 else
238 m_rbCenterline->SetValue( true );
239
240 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
241 }
242
243 // Init keepout parameters:
244 m_keepoutProperties->m_cbTracksCtrl->SetValue( m_zonesettings.GetDoNotAllowTracks() );
245 m_keepoutProperties->m_cbViasCtrl->SetValue( m_zonesettings.GetDoNotAllowVias() );
246 m_keepoutProperties->m_cbPadsCtrl->SetValue( m_zonesettings.GetDoNotAllowPads() );
247 m_keepoutProperties->m_cbFootprintsCtrl->SetValue( m_zonesettings.GetDoNotAllowFootprints() );
248 m_keepoutProperties->m_cbCopperPourCtrl->SetValue( m_zonesettings.GetDoNotAllowZoneFills() );
249
250 // Init placement parameters:
251 m_placementProperties->m_DisabledRb->SetValue( true );
252 m_placementProperties->m_SheetRb->SetValue( false );
253 m_placementProperties->m_sheetCombo->Clear();
254
255 m_placementProperties->m_ComponentsRb->SetValue( false );
256 m_placementProperties->m_componentClassCombo->Clear();
257
258 m_placementProperties->m_GroupRb->SetValue( false );
259 m_placementProperties->m_groupCombo->Clear();
260
261 wxString curSourceName = m_zonesettings.GetPlacementAreaSource();
262
263 // Load schematic sheet and component class lists
264 if( m_board )
265 {
266 // Fetch component classes
267 std::set<wxString> classNames;
268
269 for( const wxString& className : m_board->GetComponentClassManager().GetClassNames() )
270 classNames.insert( className );
271
272 for( const wxString& sourceName : classNames )
273 m_placementProperties->m_componentClassCombo->Append( sourceName );
274
275 if( !classNames.empty() )
276 m_placementProperties->m_componentClassCombo->Select( 0 );
277
278 // Fetch sheet names and groups
279 std::set<wxString> sheetNames;
280 std::set<wxString> groupNames;
281
282 for( FOOTPRINT* fp : m_board->Footprints() )
283 {
284 sheetNames.insert( fp->GetSheetname() );
285
286 if( fp->GetParentGroup() && !fp->GetParentGroup()->GetName().IsEmpty() )
287 groupNames.insert( fp->GetParentGroup()->GetName() );
288 }
289
290 for( const wxString& sourceName : sheetNames )
291 m_placementProperties->m_sheetCombo->Append( sourceName );
292
293 for( const wxString& groupName : groupNames )
294 m_placementProperties->m_groupCombo->Append( groupName );
295
296 if( !sheetNames.empty() )
297 m_placementProperties->m_sheetCombo->Select( 0 );
298
299 if( !groupNames.empty() )
300 m_placementProperties->m_groupCombo->Select( 0 );
301 }
302
303 auto setupCurrentSourceSelection = [&]( wxComboBox* cb )
304 {
305 if( curSourceName == wxEmptyString )
306 return;
307
308 if( !cb->SetStringSelection( curSourceName ) )
309 {
311 m_notFoundPlacementSourceName = curSourceName;
312 wxString notFoundDisplayName = _( "Not found on board: " ) + curSourceName;
313 cb->Insert( notFoundDisplayName, 0 );
314 cb->Select( 0 );
315 }
316 };
317
318 if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME )
319 {
320 if( m_zonesettings.GetPlacementAreaEnabled() )
321 m_placementProperties->m_SheetRb->SetValue( true );
322
323 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
326 }
327 else if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
328 {
329 if( m_zonesettings.GetPlacementAreaEnabled() )
330 m_placementProperties->m_ComponentsRb->SetValue( true );
331
332 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
335 }
336 else
337 {
338 if( m_zonesettings.GetPlacementAreaEnabled() )
339 m_placementProperties->m_GroupRb->SetValue( true );
340
341 setupCurrentSourceSelection( m_placementProperties->m_groupCombo );
344 }
345
346 // Handle most-useful notebook page selection
347 m_areaPropertiesNb->SetSelection( 0 );
348
349 if( !m_zonesettings.HasKeepoutParametersSet() && m_zonesettings.GetPlacementAreaEnabled() )
350 m_areaPropertiesNb->SetSelection( 1 );
351
352
353 m_cbLocked->SetValue( m_zonesettings.m_Locked );
354 m_tcName->SetValue( m_zonesettings.m_Name );
356
357 switch( m_zonesettings.m_ZoneBorderDisplayStyle )
358 {
359 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
360 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
363 }
364
365 m_outlineHatchPitch.SetValue( m_zonesettings.m_BorderHatchPitch );
366
368 Layout();
369
370 return true;
371}
372
373
375{
376 if( event.GetColumn() != 0 )
377 return;
378
379 int row = m_layers->ItemToRow( event.GetItem() );
380 wxVariant layerID;
381 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
382 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
383
384 const auto setSelectedLayer = [&]()
385 {
386 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
387 };
388
389 // In footprint editor, we may in "expand inner layer" mode, where we
390 // have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
391 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
392 // in board editor, this row is a normal selection
394 {
395 const FOOTPRINT* fp = static_cast<FOOTPRINT*>( m_parent->GetModel() );
396
398 {
399 if( selected )
401 else
402 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
403 }
404 else
405 {
406 // We have a custom stackup footprint, so select just that one layer
407 setSelectedLayer();
408 }
409 }
410 else
411 {
412 setSelectedLayer();
413 }
414}
415
416
418{
420 {
421 if( m_rbBoundingHull->GetValue() )
422 {
423 m_convertSettings->m_Strategy = BOUNDING_HULL;
424 m_convertSettings->m_Gap = m_gap->GetIntValue();
425 }
426 else
427 {
428 m_convertSettings->m_Strategy = CENTERLINE;
429 }
430
431 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
432 }
433
434 // Set keepout parameters:
435 m_zonesettings.SetIsRuleArea( true );
436 m_zonesettings.SetDoNotAllowTracks( m_keepoutProperties->m_cbTracksCtrl->GetValue() );
437 m_zonesettings.SetDoNotAllowVias( m_keepoutProperties->m_cbViasCtrl->GetValue() );
438 m_zonesettings.SetDoNotAllowZoneFills( m_keepoutProperties->m_cbCopperPourCtrl->GetValue() );
439 m_zonesettings.SetDoNotAllowPads( m_keepoutProperties->m_cbPadsCtrl->GetValue() );
440 m_zonesettings.SetDoNotAllowFootprints( m_keepoutProperties->m_cbFootprintsCtrl->GetValue() );
441
442 // Set placement parameters
443 m_zonesettings.SetPlacementAreaEnabled( false );
444 m_zonesettings.SetPlacementAreaSource( wxEmptyString );
445
446 auto setPlacementSource =
447 [this]( PLACEMENT_SOURCE_T sourceType )
448 {
449 m_zonesettings.SetPlacementAreaSourceType( sourceType );
450
451 wxComboBox* cb;
452
453 if( sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
454 cb = m_placementProperties->m_sheetCombo;
455 else if( sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
456 cb = m_placementProperties->m_componentClassCombo;
457 else
458 cb = m_placementProperties->m_groupCombo;
459
460 int selectedSourceIdx = cb->GetSelection();
461
462 if( selectedSourceIdx != wxNOT_FOUND )
463 {
464 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
465 && m_originalPlacementSourceType == sourceType )
466 {
467 m_zonesettings.SetPlacementAreaSource( m_notFoundPlacementSourceName );
468 }
469 else
470 {
471 m_zonesettings.SetPlacementAreaSource( cb->GetString( selectedSourceIdx ) );
472 }
473 }
474 };
475
476 if( m_placementProperties->m_SheetRb->GetValue() )
477 {
478 m_zonesettings.SetPlacementAreaEnabled( true );
479 setPlacementSource( PLACEMENT_SOURCE_T::SHEETNAME );
480 }
481 else if( m_placementProperties->m_ComponentsRb->GetValue() )
482 {
483 m_zonesettings.SetPlacementAreaEnabled( true );
484 setPlacementSource( PLACEMENT_SOURCE_T::COMPONENT_CLASS );
485 }
486 else if( m_placementProperties->m_GroupRb->GetValue() )
487 {
488 m_zonesettings.SetPlacementAreaEnabled( true );
489 setPlacementSource( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
490 }
491 else
492 {
493 setPlacementSource( m_lastPlacementSourceType );
494 }
495
496 if( m_zonesettings.m_Layers.count() == 0 )
497 {
498 DisplayError( this, _( "No layers selected." ) );
499 return false;
500 }
501
502 switch( m_OutlineDisplayCtrl->GetSelection() )
503 {
504 case 0:
505 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
506 break;
507 case 1:
509 break;
510 case 2:
512 break;
513 }
514
517 {
518 return false;
519 }
520
521 m_zonesettings.m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
522
523 m_zonesettings.m_Locked = m_cbLocked->GetValue();
524 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
525
526 m_zonesettings.m_Name = m_tcName->GetValue();
527
528 // Only enforce uniqueness when the user actually changed the name (issue 23131)
529 if( m_board && m_zonesettings.m_Name != m_originalName )
530 m_zonesettings.m_Name = m_board->GetUniqueZoneName( m_zonesettings.m_Name );
531
533 return true;
534}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
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
wxString m_originalName
name the dialog opened with, to detect edits
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