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 <advanced_config.h>
27#include <kiface_base.h>
28#include <confirm.h>
29#include <board.h>
30#include <footprint.h>
31#include <pcb_edit_frame.h>
32#include <pcbnew_settings.h>
33#include <zone_settings.h>
37#include <widgets/unit_binder.h>
38#include <wx/statbox.h>
39#include <wx/statline.h>
40#include <wx/radiobut.h>
41
42#define LAYER_LIST_COLUMN_CHECK 0
43#define LAYER_LIST_COLUMN_ICON 1
44#define LAYER_LIST_COLUMN_NAME 2
45#define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
46
47
49{
50public:
52 CONVERT_SETTINGS* aConvertSettings, BOARD* aBoard );
54
55private:
56 bool TransferDataToWindow() override;
57 bool TransferDataFromWindow() override;
58
59 void OnLayerSelection( wxDataViewEvent& event ) override;
60 void OnSheetNameClicked( wxCommandEvent& event );
61 void OnComponentClassClicked( wxCommandEvent& event );
62
63private:
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 ), m_outlineHatchPitch( aParent, m_stBorderHatchPitchText,
107 m_outlineHatchPitchCtrl, m_outlineHatchUnits ),
108 m_convertSettings( aConvertSettings ), m_rbCenterline( nullptr ),
109 m_rbBoundingHull( nullptr ), m_cbDeleteOriginals( nullptr ),
110 m_notFoundPlacementSource( false ),
111 m_originalPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME ),
112 m_lastPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
113{
114 m_parent = aParent;
115
116 m_ptr = aSettings;
117 m_zonesettings = *aSettings;
118
120 m_areaPropertiesNb->AddPage( m_keepoutProperties, _( "Keepouts" ), true );
121
123 m_areaPropertiesNb->AddPage( m_placementProperties, _( "Placement" ) );
124
126 wxEVT_CHECKBOX,
127 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
128 this );
130 wxEVT_CHECKBOX,
131 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
132 this );
133
134 if( aConvertSettings )
135 {
136 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
137 _( "Conversion Settings" ) );
138 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
139
140 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
141 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
142
143 bConvertSizer->AddSpacer( 2 );
144 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
145 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
146
147 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
148 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
149 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
150 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
151
152 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
153 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
154 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
155 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
156
157 bConvertSizer->AddSpacer( 2 );
158 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
159
160 bConvertSizer->AddSpacer( 6 );
161 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
162 _( "Delete source objects after conversion" ) );
163 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
164
165 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
166
167 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
168 wxLI_HORIZONTAL );
169 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
170
171 SetTitle( _( "Convert to Rule Area" ) );
172 }
173
175
176 BOARD* board = m_parent->GetBoard();
178
180
182
184}
185
186
188{
189 m_placementProperties->m_SheetCb->Disconnect(
190 wxEVT_CHECKBOX,
191 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
192 this );
194 wxEVT_CHECKBOX,
195 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
196 this );
197}
198
199
201{
202 m_placementProperties->m_ComponentsCb->SetValue( false );
203 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
204}
205
206
208{
209 m_placementProperties->m_SheetCb->SetValue( false );
210 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
211}
212
213
215{
217 {
219 m_rbBoundingHull->SetValue( true );
220 else
221 m_rbCenterline->SetValue( true );
222
224 }
225
226 // Init keepout parameters:
232
233 // Init placement parameters:
234 m_placementProperties->m_SheetCb->SetValue( false );
236
237 m_placementProperties->m_ComponentsCb->SetValue( false );
239
240 wxString curSourceName = m_zonesettings.GetRuleAreaPlacementSource();
241
242 // Load schematic sheet and component class lists
243 if( m_board )
244 {
245 // Fetch component classes
246 std::set<wxString> classNames;
247
248 for( const auto& [k, v] : m_board->GetComponentClassManager().GetClasses() )
249 classNames.insert( k );
250
251 for( const wxString& sourceName : classNames )
252 m_placementProperties->m_componentClassCombo->Append( sourceName );
253
254 // Fetch sheet names
255 std::set<wxString> sheetNames;
256
257 for( FOOTPRINT* fp : m_board->Footprints() )
258 sheetNames.insert( fp->GetSheetname() );
259
260 for( const wxString& sourceName : sheetNames )
261 m_placementProperties->m_sheetCombo->Append( sourceName );
262 }
263
264 auto setupCurrentSourceSelection = [&]( wxComboBox* cb )
265 {
266 if( curSourceName == wxEmptyString )
267 return;
268
269 if( !cb->SetStringSelection( curSourceName ) )
270 {
272 m_notFoundPlacementSourceName = curSourceName;
273 wxString notFoundDisplayName = _( "Not found on board: " ) + curSourceName;
274 cb->Insert( notFoundDisplayName, 0 );
275 cb->Select( 0 );
276 }
277 };
278
280 == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
281 {
283 m_placementProperties->m_SheetCb->SetValue( true );
284
285 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
286 m_originalPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
287 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
288 }
289 else
290 {
292 m_placementProperties->m_ComponentsCb->SetValue( true );
293
294 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
295 m_originalPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
296 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
297 }
298
299 // Handle most-useful notebook page selection
300 m_areaPropertiesNb->SetSelection( 0 );
301
303 {
304 m_areaPropertiesNb->SetSelection( 1 );
305 }
306
307
309 m_tcName->SetValue( m_zonesettings.m_Name );
310
312 {
313 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
314 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
315 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
316 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
317 }
318
320
322 Layout();
323
324 return true;
325}
326
327
329{
330 if( event.GetColumn() != 0 )
331 return;
332
333 int row = m_layers->ItemToRow( event.GetItem() );
334 wxVariant layerID;
335 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
336 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
337
338 // In footprint editor, we have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
339 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
340 // in board editor, this row is a normal selection
342 {
343 if( selected )
345 else
346 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
347 }
348 else
349 {
350 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
351 }
352}
353
354
356{
358 {
359 if( m_rbBoundingHull->GetValue() )
360 {
363 }
364 else
365 {
367 }
368
370 }
371
372 // Set keepout parameters:
379
380 // Set placement parameters
383
384 auto setPlacementSource = [this]( RULE_AREA_PLACEMENT_SOURCE_TYPE sourceType )
385 {
387
388 wxComboBox* cb;
389
390 if( sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
392 else
394
395 int selectedSourceIdx = cb->GetSelection();
396
397 if( selectedSourceIdx != wxNOT_FOUND )
398 {
399 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
400 && m_originalPlacementSourceType == sourceType )
401 {
403 }
404 else
405 {
406 m_zonesettings.SetRuleAreaPlacementSource( cb->GetString( selectedSourceIdx ) );
407 }
408 }
409 };
410
411 if( m_placementProperties->m_SheetCb->GetValue() )
412 {
414 setPlacementSource( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
415 }
416 else if( m_placementProperties->m_ComponentsCb->GetValue() )
417 {
419 setPlacementSource( RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS );
420 }
421 else
422 {
423 setPlacementSource( m_lastPlacementSourceType );
424 }
425
426 if( m_zonesettings.m_Layers.count() == 0 )
427 {
428 DisplayError( this, _( "No layers selected." ) );
429 return false;
430 }
431
432 switch( m_OutlineDisplayCtrl->GetSelection() )
433 {
434 case 0:
435 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
436 break;
437 case 1:
438 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
439 break;
440 case 2:
441 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
442 break;
443 }
444
447 {
448 return false;
449 }
450
452
453 m_zonesettings.m_Locked = m_cbLocked->GetValue();
454 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
455
456 m_zonesettings.m_Name = m_tcName->GetValue();
457
459 return true;
460}
461
462
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:741
const FOOTPRINTS & Footprints() const
Definition: board.h:331
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition: board.h:1275
const std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > & GetClasses() 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
RULE_AREA_PLACEMENT_SOURCE_TYPE m_lastPlacementSourceType
DIALOG_RULE_AREA_PROPERTIES(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings, BOARD *aBoard)
RULE_AREA_PLACEMENT_SOURCE_TYPE m_originalPlacementSourceType
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: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...
int ShowModal() override
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:697
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:675
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
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:78
bool GetDoNotAllowCopperPour() const
void SetIsRuleArea(bool aEnable)
bool GetDoNotAllowTracks() const
RULE_AREA_PLACEMENT_SOURCE_TYPE GetRuleAreaPlacementSourceType() const
void SetDoNotAllowVias(bool aEnable)
bool GetDoNotAllowFootprints() const
void SetRuleAreaPlacementSourceType(RULE_AREA_PLACEMENT_SOURCE_TYPE aType)
wxString GetRuleAreaPlacementSource() const
bool GetDoNotAllowPads() const
void SetRuleAreaPlacementEnabled(bool aEnabled)
void SetRuleAreaPlacementSource(const wxString &aSource)
void SetDoNotAllowTracks(bool aEnable)
bool GetDoNotAllowVias() const
bool GetRuleAreaPlacementEnabled() 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).
bool HasKeepoutParametersSet() const
Accessor to determine if any keepout parameters are set.
wxString m_Name
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowPads(bool aEnable)
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
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
#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:820
@ CENTERLINE
@ BOUNDING_HULL
@ SHEETNAME
Definition: sch_sheet.h:45
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.
RULE_AREA_PLACEMENT_SOURCE_TYPE
Definition: zone_settings.h:66
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition: zones.h:40
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition: zones.h:41