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, 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 <advanced_config.h>
27#include <kiface_base.h>
28#include <confirm.h>
29#include <board.h>
31#include <eda_group.h>
32#include <footprint.h>
33#include <pcb_edit_frame.h>
34#include <pcbnew_settings.h>
35#include <zone_settings.h>
39#include <widgets/unit_binder.h>
40#include <wx/statbox.h>
41#include <wx/statline.h>
42#include <wx/radiobut.h>
43
44#define LAYER_LIST_COLUMN_CHECK 0
45#define LAYER_LIST_COLUMN_ICON 1
46#define LAYER_LIST_COLUMN_NAME 2
47#define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
48
49
51{
52public:
54 CONVERT_SETTINGS* aConvertSettings, BOARD* aBoard );
56
57private:
58 bool TransferDataToWindow() override;
59 bool TransferDataFromWindow() override;
60
61 void OnLayerSelection( wxDataViewEvent& event ) override;
62 void OnSheetNameClicked( wxCommandEvent& event );
63 void OnComponentClassClicked( wxCommandEvent& event );
64 void OnGroupClicked( wxCommandEvent& event );
65
66private:
73
75 wxRadioButton* m_rbCenterline;
76 wxRadioButton* m_rbBoundingHull;
77 wxStaticText* m_gapLabel;
78 wxTextCtrl* m_gapCtrl;
79 wxStaticText* m_gapUnits;
82
83 // The name of a rule area source that is not now found on the board (e.g. after a netlist
84 // update). This is used to re-populate the zone settings if the selection is not changed.
89
92};
93
94
95int InvokeRuleAreaEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aZoneSettings, BOARD* aBoard,
96 CONVERT_SETTINGS* aConvertSettings )
97{
98 DIALOG_RULE_AREA_PROPERTIES dlg( aCaller, aZoneSettings, aConvertSettings, aBoard );
99
100 return dlg.ShowModal();
101}
102
103
105 ZONE_SETTINGS* aSettings,
106 CONVERT_SETTINGS* aConvertSettings,
107 BOARD* aBoard ) :
109 m_board( aBoard ),
111 m_convertSettings( aConvertSettings ),
112 m_rbCenterline( nullptr ),
113 m_rbBoundingHull( nullptr ),
114 m_gapLabel( nullptr ),
115 m_gapCtrl( nullptr ),
116 m_gapUnits( nullptr ),
117 m_gap( nullptr ),
118 m_cbDeleteOriginals( nullptr ),
122{
124 m_parent = aParent;
125
126 m_ptr = aSettings;
127 m_zonesettings = *aSettings;
128
130 m_areaPropertiesNb->AddPage( m_keepoutProperties, _( "Keepouts" ), true );
131
133 m_areaPropertiesNb->AddPage( m_placementProperties, _( "Placement" ) );
134
135 m_placementProperties->m_SheetRb->Connect(
136 wxEVT_CHECKBOX,
137 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
138 this );
139 m_placementProperties->m_ComponentsRb->Connect(
140 wxEVT_CHECKBOX,
141 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
142 this );
143 m_placementProperties->m_GroupRb->Connect(
144 wxEVT_CHECKBOX,
145 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
146 this );
147
148 if( aConvertSettings )
149 {
150 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
151 _( "Conversion Settings" ) );
152 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
153
154 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
155 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
156
157 bConvertSizer->AddSpacer( 2 );
158 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
159 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
160
161 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
162 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
163 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
164 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
165
166 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
167 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
168 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
169 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
170
171 bConvertSizer->AddSpacer( 2 );
172 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
173
174 bConvertSizer->AddSpacer( 6 );
175 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
176 _( "Delete source objects after conversion" ) );
177 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
178
179 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
180
181 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
182 wxLI_HORIZONTAL );
183 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
184
185 SetTitle( _( "Convert to Rule Area" ) );
186 }
187
188 BOARD* board = m_parent->GetBoard();
190
191 m_zonesettings.SetupLayersList( m_layers, m_parent, layers );
192
194
196}
197
198
200{
201 m_placementProperties->m_SheetRb->Disconnect(
202 wxEVT_CHECKBOX,
203 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
204 this );
205 m_placementProperties->m_ComponentsRb->Disconnect(
206 wxEVT_CHECKBOX,
207 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
208 this );
209 m_placementProperties->m_GroupRb->Disconnect(
210 wxEVT_CHECKBOX,
211 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
212 this );
213}
214
215
220
221
226
227
232
233
235{
237 {
238 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
239 m_rbBoundingHull->SetValue( true );
240 else
241 m_rbCenterline->SetValue( true );
242
243 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
244 }
245
246 // Init keepout parameters:
247 m_keepoutProperties->m_cbTracksCtrl->SetValue( m_zonesettings.GetDoNotAllowTracks() );
248 m_keepoutProperties->m_cbViasCtrl->SetValue( m_zonesettings.GetDoNotAllowVias() );
249 m_keepoutProperties->m_cbPadsCtrl->SetValue( m_zonesettings.GetDoNotAllowPads() );
250 m_keepoutProperties->m_cbFootprintsCtrl->SetValue( m_zonesettings.GetDoNotAllowFootprints() );
251 m_keepoutProperties->m_cbCopperPourCtrl->SetValue( m_zonesettings.GetDoNotAllowZoneFills() );
252
253 // Init placement parameters:
254 m_placementProperties->m_DisabledRb->SetValue( true );
255 m_placementProperties->m_SheetRb->SetValue( false );
256 m_placementProperties->m_sheetCombo->Clear();
257
258 m_placementProperties->m_ComponentsRb->SetValue( false );
259 m_placementProperties->m_componentClassCombo->Clear();
260
261 m_placementProperties->m_GroupRb->SetValue( false );
262 m_placementProperties->m_groupCombo->Clear();
263
264 wxString curSourceName = m_zonesettings.GetPlacementAreaSource();
265
266 // Load schematic sheet and component class lists
267 if( m_board )
268 {
269 // Fetch component classes
270 std::set<wxString> classNames;
271
272 for( const wxString& className : m_board->GetComponentClassManager().GetClassNames() )
273 classNames.insert( className );
274
275 for( const wxString& sourceName : classNames )
276 m_placementProperties->m_componentClassCombo->Append( sourceName );
277
278 if( !classNames.empty() )
279 m_placementProperties->m_componentClassCombo->Select( 0 );
280
281 // Fetch sheet names and groups
282 std::set<wxString> sheetNames;
283 std::set<wxString> groupNames;
284
285 for( FOOTPRINT* fp : m_board->Footprints() )
286 {
287 sheetNames.insert( fp->GetSheetname() );
288
289 if( fp->GetParentGroup() && !fp->GetParentGroup()->GetName().IsEmpty() )
290 groupNames.insert( fp->GetParentGroup()->GetName() );
291 }
292
293 for( const wxString& sourceName : sheetNames )
294 m_placementProperties->m_sheetCombo->Append( sourceName );
295
296 for( const wxString& groupName : groupNames )
297 m_placementProperties->m_groupCombo->Append( groupName );
298
299 if( !sheetNames.empty() )
300 m_placementProperties->m_sheetCombo->Select( 0 );
301
302 if( !groupNames.empty() )
303 m_placementProperties->m_groupCombo->Select( 0 );
304 }
305
306 auto setupCurrentSourceSelection = [&]( wxComboBox* cb )
307 {
308 if( curSourceName == wxEmptyString )
309 return;
310
311 if( !cb->SetStringSelection( curSourceName ) )
312 {
314 m_notFoundPlacementSourceName = curSourceName;
315 wxString notFoundDisplayName = _( "Not found on board: " ) + curSourceName;
316 cb->Insert( notFoundDisplayName, 0 );
317 cb->Select( 0 );
318 }
319 };
320
321 if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME )
322 {
323 if( m_zonesettings.GetPlacementAreaEnabled() )
324 m_placementProperties->m_SheetRb->SetValue( true );
325
326 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
329 }
330 else if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
331 {
332 if( m_zonesettings.GetPlacementAreaEnabled() )
333 m_placementProperties->m_ComponentsRb->SetValue( true );
334
335 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
338 }
339 else
340 {
341 if( m_zonesettings.GetPlacementAreaEnabled() )
342 m_placementProperties->m_GroupRb->SetValue( true );
343
344 setupCurrentSourceSelection( m_placementProperties->m_groupCombo );
347 }
348
349 // Handle most-useful notebook page selection
350 m_areaPropertiesNb->SetSelection( 0 );
351
352 if( !m_zonesettings.HasKeepoutParametersSet() && m_zonesettings.GetPlacementAreaEnabled() )
353 m_areaPropertiesNb->SetSelection( 1 );
354
355
356 m_cbLocked->SetValue( m_zonesettings.m_Locked );
357 m_tcName->SetValue( m_zonesettings.m_Name );
358
359 switch( m_zonesettings.m_ZoneBorderDisplayStyle )
360 {
361 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
362 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
365 }
366
367 m_outlineHatchPitch.SetValue( m_zonesettings.m_BorderHatchPitch );
368
370 Layout();
371
372 return true;
373}
374
375
377{
378 if( event.GetColumn() != 0 )
379 return;
380
381 int row = m_layers->ItemToRow( event.GetItem() );
382 wxVariant layerID;
383 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
384 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
385
386 const auto setSelectedLayer = [&]()
387 {
388 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
389 };
390
391 // In footprint editor, we may in "expand inner layer" mode, where we
392 // have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
393 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
394 // in board editor, this row is a normal selection
396 {
397 const FOOTPRINT* fp = static_cast<FOOTPRINT*>( m_parent->GetModel() );
398
400 {
401 if( selected )
403 else
404 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
405 }
406 else
407 {
408 // We have a custom stackup footprint, so select just that one layer
409 setSelectedLayer();
410 }
411 }
412 else
413 {
414 setSelectedLayer();
415 }
416}
417
418
420{
422 {
423 if( m_rbBoundingHull->GetValue() )
424 {
425 m_convertSettings->m_Strategy = BOUNDING_HULL;
426 m_convertSettings->m_Gap = m_gap->GetIntValue();
427 }
428 else
429 {
430 m_convertSettings->m_Strategy = CENTERLINE;
431 }
432
433 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
434 }
435
436 // Set keepout parameters:
437 m_zonesettings.SetIsRuleArea( true );
438 m_zonesettings.SetDoNotAllowTracks( m_keepoutProperties->m_cbTracksCtrl->GetValue() );
439 m_zonesettings.SetDoNotAllowVias( m_keepoutProperties->m_cbViasCtrl->GetValue() );
440 m_zonesettings.SetDoNotAllowZoneFills( m_keepoutProperties->m_cbCopperPourCtrl->GetValue() );
441 m_zonesettings.SetDoNotAllowPads( m_keepoutProperties->m_cbPadsCtrl->GetValue() );
442 m_zonesettings.SetDoNotAllowFootprints( m_keepoutProperties->m_cbFootprintsCtrl->GetValue() );
443
444 // Set placement parameters
445 m_zonesettings.SetPlacementAreaEnabled( false );
446 m_zonesettings.SetPlacementAreaSource( wxEmptyString );
447
448 auto setPlacementSource =
449 [this]( PLACEMENT_SOURCE_T sourceType )
450 {
451 m_zonesettings.SetPlacementAreaSourceType( sourceType );
452
453 wxComboBox* cb;
454
455 if( sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
456 cb = m_placementProperties->m_sheetCombo;
457 else if( sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
458 cb = m_placementProperties->m_componentClassCombo;
459 else
460 cb = m_placementProperties->m_groupCombo;
461
462 int selectedSourceIdx = cb->GetSelection();
463
464 if( selectedSourceIdx != wxNOT_FOUND )
465 {
466 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
467 && m_originalPlacementSourceType == sourceType )
468 {
469 m_zonesettings.SetPlacementAreaSource( m_notFoundPlacementSourceName );
470 }
471 else
472 {
473 m_zonesettings.SetPlacementAreaSource( cb->GetString( selectedSourceIdx ) );
474 }
475 }
476 };
477
478 if( m_placementProperties->m_SheetRb->GetValue() )
479 {
480 m_zonesettings.SetPlacementAreaEnabled( true );
481 setPlacementSource( PLACEMENT_SOURCE_T::SHEETNAME );
482 }
483 else if( m_placementProperties->m_ComponentsRb->GetValue() )
484 {
485 m_zonesettings.SetPlacementAreaEnabled( true );
486 setPlacementSource( PLACEMENT_SOURCE_T::COMPONENT_CLASS );
487 }
488 else if( m_placementProperties->m_GroupRb->GetValue() )
489 {
490 m_zonesettings.SetPlacementAreaEnabled( true );
491 setPlacementSource( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
492 }
493 else
494 {
495 setPlacementSource( m_lastPlacementSourceType );
496 }
497
498 if( m_zonesettings.m_Layers.count() == 0 )
499 {
500 DisplayError( this, _( "No layers selected." ) );
501 return false;
502 }
503
504 switch( m_OutlineDisplayCtrl->GetSelection() )
505 {
506 case 0:
507 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
508 break;
509 case 1:
511 break;
512 case 2:
514 break;
515 }
516
519 {
520 return false;
521 }
522
523 m_zonesettings.m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
524
525 m_zonesettings.m_Locked = m_cbLocked->GetValue();
526 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
527
528 m_zonesettings.m_Name = m_tcName->GetValue();
529
531 return true;
532}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
int GetCopperLayerCount() const
Definition board.cpp:919
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:82
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:408
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:627
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:608
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:577
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:177
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:99
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:43
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:754
@ 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:39
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:40