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>
30#include <eda_group.h>
31#include <footprint.h>
32#include <pcb_edit_frame.h>
33#include <pcbnew_settings.h>
34#include <zone_settings.h>
38#include <widgets/unit_binder.h>
39#include <wx/statbox.h>
40#include <wx/statline.h>
41#include <wx/radiobut.h>
42
43#define LAYER_LIST_COLUMN_CHECK 0
44#define LAYER_LIST_COLUMN_ICON 1
45#define LAYER_LIST_COLUMN_NAME 2
46#define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
47
48
50{
51public:
53 CONVERT_SETTINGS* aConvertSettings, BOARD* aBoard );
55
56private:
57 bool TransferDataToWindow() override;
58 bool TransferDataFromWindow() override;
59
60 void OnLayerSelection( wxDataViewEvent& event ) override;
61 void OnSheetNameClicked( wxCommandEvent& event );
62 void OnComponentClassClicked( wxCommandEvent& event );
63 void OnGroupClicked( wxCommandEvent& event );
64
65private:
72
74 wxRadioButton* m_rbCenterline;
75 wxRadioButton* m_rbBoundingHull;
76 wxStaticText* m_gapLabel;
77 wxTextCtrl* m_gapCtrl;
78 wxStaticText* m_gapUnits;
81
82 // The name of a rule area source that is not now found on the board (e.g. after a netlist
83 // update). This is used to re-populate the zone settings if the selection is not changed.
88
91};
92
93
94int InvokeRuleAreaEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aZoneSettings, BOARD* aBoard,
95 CONVERT_SETTINGS* aConvertSettings )
96{
97 DIALOG_RULE_AREA_PROPERTIES dlg( aCaller, aZoneSettings, aConvertSettings, aBoard );
98
99 return dlg.ShowModal();
100}
101
102
104 ZONE_SETTINGS* aSettings,
105 CONVERT_SETTINGS* aConvertSettings,
106 BOARD* aBoard ) :
108 m_board( aBoard ),
109 m_outlineHatchPitch( aParent, m_stBorderHatchPitchText, m_outlineHatchPitchCtrl, m_outlineHatchUnits ),
110 m_convertSettings( aConvertSettings ),
111 m_rbCenterline( nullptr ),
112 m_rbBoundingHull( nullptr ),
113 m_gapLabel( nullptr ),
114 m_gapCtrl( nullptr ),
115 m_gapUnits( nullptr ),
116 m_gap( nullptr ),
117 m_cbDeleteOriginals( nullptr ),
118 m_notFoundPlacementSource( false ),
119 m_originalPlacementSourceType( PLACEMENT_SOURCE_T::SHEETNAME ),
120 m_lastPlacementSourceType( PLACEMENT_SOURCE_T::SHEETNAME )
121{
122 m_parent = aParent;
123
124 m_ptr = aSettings;
125 m_zonesettings = *aSettings;
126
128 m_areaPropertiesNb->AddPage( m_keepoutProperties, _( "Keepouts" ), true );
129
131 m_areaPropertiesNb->AddPage( m_placementProperties, _( "Placement" ) );
132
134 wxEVT_CHECKBOX,
135 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
136 this );
138 wxEVT_CHECKBOX,
139 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
140 this );
142 wxEVT_CHECKBOX,
143 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnGroupClicked ), nullptr,
144 this );
145
146 if( aConvertSettings )
147 {
148 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
149 _( "Conversion Settings" ) );
150 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
151
152 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
153 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
154
155 bConvertSizer->AddSpacer( 2 );
156 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
157 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
158
159 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
160 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
161 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
162 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
163
164 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
165 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
166 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
167 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
168
169 bConvertSizer->AddSpacer( 2 );
170 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
171
172 bConvertSizer->AddSpacer( 6 );
173 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
174 _( "Delete source objects after conversion" ) );
175 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
176
177 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
178
179 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
180 wxLI_HORIZONTAL );
181 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
182
183 SetTitle( _( "Convert to Rule Area" ) );
184 }
185
187
188 BOARD* board = m_parent->GetBoard();
190
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 );
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
217{
218 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::SHEETNAME;
219}
220
221
223{
224 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::COMPONENT_CLASS;
225}
226
227
229{
230 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::GROUP_PLACEMENT;
231}
232
233
235{
237 {
239 m_rbBoundingHull->SetValue( true );
240 else
241 m_rbCenterline->SetValue( true );
242
244 }
245
246 // Init keepout parameters:
252
253 // Init placement parameters:
254 m_placementProperties->m_DisabledRb->SetValue( true );
255 m_placementProperties->m_SheetRb->SetValue( false );
257
258 m_placementProperties->m_ComponentsRb->SetValue( false );
260
261 m_placementProperties->m_GroupRb->SetValue( false );
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() )
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() )
301
302 if( !groupNames.empty() )
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 {
324 m_placementProperties->m_SheetRb->SetValue( true );
325
326 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
327 m_originalPlacementSourceType = PLACEMENT_SOURCE_T::SHEETNAME;
328 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::SHEETNAME;
329 }
330 else if( m_zonesettings.GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
331 {
333 m_placementProperties->m_ComponentsRb->SetValue( true );
334
335 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
336 m_originalPlacementSourceType = PLACEMENT_SOURCE_T::COMPONENT_CLASS;
337 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::COMPONENT_CLASS;
338 }
339 else
340 {
342 m_placementProperties->m_GroupRb->SetValue( true );
343
344 setupCurrentSourceSelection( m_placementProperties->m_groupCombo );
345 m_originalPlacementSourceType = PLACEMENT_SOURCE_T::GROUP_PLACEMENT;
346 m_lastPlacementSourceType = PLACEMENT_SOURCE_T::GROUP_PLACEMENT;
347 }
348
349 // Handle most-useful notebook page selection
350 m_areaPropertiesNb->SetSelection( 0 );
351
353 m_areaPropertiesNb->SetSelection( 1 );
354
355
357 m_tcName->SetValue( m_zonesettings.m_Name );
358
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;
363 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
364 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
365 }
366
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 // In footprint editor, we have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
387 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
388 // in board editor, this row is a normal selection
390 {
391 if( selected )
393 else
394 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
395 }
396 else
397 {
398 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
399 }
400}
401
402
404{
406 {
407 if( m_rbBoundingHull->GetValue() )
408 {
411 }
412 else
413 {
415 }
416
418 }
419
420 // Set keepout parameters:
427
428 // Set placement parameters
430 m_zonesettings.SetPlacementAreaSource( wxEmptyString );
431
432 auto setPlacementSource =
433 [this]( PLACEMENT_SOURCE_T sourceType )
434 {
436
437 wxComboBox* cb;
438
439 if( sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
441 else if( sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
443 else
445
446 int selectedSourceIdx = cb->GetSelection();
447
448 if( selectedSourceIdx != wxNOT_FOUND )
449 {
450 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
451 && m_originalPlacementSourceType == sourceType )
452 {
454 }
455 else
456 {
457 m_zonesettings.SetPlacementAreaSource( cb->GetString( selectedSourceIdx ) );
458 }
459 }
460 };
461
462 if( m_placementProperties->m_SheetRb->GetValue() )
463 {
465 setPlacementSource( PLACEMENT_SOURCE_T::SHEETNAME );
466 }
467 else if( m_placementProperties->m_ComponentsRb->GetValue() )
468 {
470 setPlacementSource( PLACEMENT_SOURCE_T::COMPONENT_CLASS );
471 }
472 else if( m_placementProperties->m_GroupRb->GetValue() )
473 {
475 setPlacementSource( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
476 }
477 else
478 {
479 setPlacementSource( m_lastPlacementSourceType );
480 }
481
482 if( m_zonesettings.m_Layers.count() == 0 )
483 {
484 DisplayError( this, _( "No layers selected." ) );
485 return false;
486 }
487
488 switch( m_OutlineDisplayCtrl->GetSelection() )
489 {
490 case 0:
491 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
492 break;
493 case 1:
494 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
495 break;
496 case 2:
497 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
498 break;
499 }
500
503 {
504 return false;
505 }
506
508
509 m_zonesettings.m_Locked = m_cbLocked->GetValue();
510 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
511
512 m_zonesettings.m_Name = m_tcName->GetValue();
513
515 return true;
516}
517
518
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
BASE_SET & set(size_t pos)
Definition: base_set.h:116
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
int GetCopperLayerCount() const
Definition: board.cpp:781
const FOOTPRINTS & Footprints() const
Definition: board.h:358
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition: board.h:1323
std::unordered_set< wxString > GetClassNames() const
Fetches a read-only map of the fundamental component classes.
Class DIALOG_RULE_AREA_PROPERTIES_BASE.
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:66
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
bool IsType(FRAME_T aType) const
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:613
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:583
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:561
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.
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:88
void SetIsRuleArea(bool aEnable)
bool GetDoNotAllowTracks() const
wxString GetPlacementAreaSource() const
void SetDoNotAllowVias(bool aEnable)
bool GetDoNotAllowFootprints() const
bool GetDoNotAllowPads() const
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
bool GetDoNotAllowZoneFills() const
void SetDoNotAllowTracks(bool aEnable)
bool GetDoNotAllowVias() const
void SetPlacementAreaSource(const wxString &aSource)
void SetPlacementAreaEnabled(bool aEnabled)
unsigned m_ZonePriority
Definition: zone_settings.h:99
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers, bool aFpEditorMode)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
bool GetPlacementAreaEnabled() const
Accessors to parameters used in Rule Area zones:
bool HasKeepoutParametersSet() const
Accessor to determine if any keepout parameters are set.
wxString m_Name
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowPads(bool aEnable)
void SetDoNotAllowZoneFills(bool aEnable)
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
void SetPlacementAreaSourceType(PLACEMENT_SOURCE_T aType)
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:178
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)
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:747
@ CENTERLINE
@ BOUNDING_HULL
CONVERT_STRATEGY m_Strategy
constexpr int mmToIU(double mm) const
Definition: base_units.h:92
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
PLACEMENT_SOURCE_T
Definition: zone_settings.h:75
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition: zones.h:40
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition: zones.h:41