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 <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 ),
107 m_outlineHatchPitch( aParent, m_stBorderHatchPitchText, m_outlineHatchPitchCtrl, m_outlineHatchUnits ),
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 ),
116 m_notFoundPlacementSource( false ),
117 m_originalPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME ),
118 m_lastPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
119{
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
132 wxEVT_CHECKBOX,
133 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
134 this );
136 wxEVT_CHECKBOX,
137 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
138 this );
139
140 if( aConvertSettings )
141 {
142 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY,
143 _( "Conversion Settings" ) );
144 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
145
146 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
147 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
148
149 bConvertSizer->AddSpacer( 2 );
150 m_rbBoundingHull = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
151 bConvertSizer->Add( m_rbBoundingHull, 0, wxLEFT|wxRIGHT, 5 );
152
153 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
154 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
155 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
156 m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
157
158 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
159 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
160 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
161 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
162
163 bConvertSizer->AddSpacer( 2 );
164 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
165
166 bConvertSizer->AddSpacer( 6 );
167 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY,
168 _( "Delete source objects after conversion" ) );
169 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
170
171 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
172
173 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
174 wxLI_HORIZONTAL );
175 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
176
177 SetTitle( _( "Convert to Rule Area" ) );
178 }
179
181
182 BOARD* board = m_parent->GetBoard();
184
186
188
190}
191
192
194{
195 m_placementProperties->m_SheetRb->Disconnect(
196 wxEVT_CHECKBOX,
197 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnSheetNameClicked ), nullptr,
198 this );
200 wxEVT_CHECKBOX,
201 wxCommandEventHandler( DIALOG_RULE_AREA_PROPERTIES::OnComponentClassClicked ), nullptr,
202 this );
203}
204
205
207{
208 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
209}
210
211
213{
214 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
215}
216
217
219{
221 {
223 m_rbBoundingHull->SetValue( true );
224 else
225 m_rbCenterline->SetValue( true );
226
228 }
229
230 // Init keepout parameters:
236
237 // Init placement parameters:
238 m_placementProperties->m_DisabedlRb->SetValue( true );
239 m_placementProperties->m_SheetRb->SetValue( false );
241
242 m_placementProperties->m_ComponentsRb->SetValue( false );
244
245 wxString curSourceName = m_zonesettings.GetRuleAreaPlacementSource();
246
247 // Load schematic sheet and component class lists
248 if( m_board )
249 {
250 // Fetch component classes
251 std::set<wxString> classNames;
252
253 for( const auto& [k, v] : m_board->GetComponentClassManager().GetClasses() )
254 classNames.insert( k );
255
256 for( const wxString& sourceName : classNames )
257 m_placementProperties->m_componentClassCombo->Append( sourceName );
258
259 if( !classNames.empty() )
261
262 // Fetch sheet names
263 std::set<wxString> sheetNames;
264
265 for( FOOTPRINT* fp : m_board->Footprints() )
266 sheetNames.insert( fp->GetSheetname() );
267
268 for( const wxString& sourceName : sheetNames )
269 m_placementProperties->m_sheetCombo->Append( sourceName );
270
271 if( !sheetNames.empty() )
273 }
274
275 auto setupCurrentSourceSelection = [&]( wxComboBox* cb )
276 {
277 if( curSourceName == wxEmptyString )
278 return;
279
280 if( !cb->SetStringSelection( curSourceName ) )
281 {
283 m_notFoundPlacementSourceName = curSourceName;
284 wxString notFoundDisplayName = _( "Not found on board: " ) + curSourceName;
285 cb->Insert( notFoundDisplayName, 0 );
286 cb->Select( 0 );
287 }
288 };
289
291 == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
292 {
294 m_placementProperties->m_SheetRb->SetValue( true );
295
296 setupCurrentSourceSelection( m_placementProperties->m_sheetCombo );
297 m_originalPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
298 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
299 }
300 else
301 {
303 m_placementProperties->m_ComponentsRb->SetValue( true );
304
305 setupCurrentSourceSelection( m_placementProperties->m_componentClassCombo );
306 m_originalPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
307 m_lastPlacementSourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
308 }
309
310 // Handle most-useful notebook page selection
311 m_areaPropertiesNb->SetSelection( 0 );
312
314 {
315 m_areaPropertiesNb->SetSelection( 1 );
316 }
317
318
320 m_tcName->SetValue( m_zonesettings.m_Name );
321
323 {
324 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: // Not used for standard zones. Here use NO_HATCH
325 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
326 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
327 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
328 }
329
331
333 Layout();
334
335 return true;
336}
337
338
340{
341 if( event.GetColumn() != 0 )
342 return;
343
344 int row = m_layers->ItemToRow( event.GetItem() );
345 wxVariant layerID;
346 m_layers->GetValue( layerID, row, LAYER_LIST_COLUMN_NAME );
347 bool selected = m_layers->GetToggleValue( row, LAYER_LIST_COLUMN_CHECK );
348
349 // In footprint editor, we have only 3 possible layer selection: C_Cu, inner layers, B_Cu.
350 // So row LAYER_LIST_ROW_ALL_INNER_LAYERS selection is fp editor specific.
351 // in board editor, this row is a normal selection
353 {
354 if( selected )
356 else
357 m_zonesettings.m_Layers &= ~LSET::InternalCuMask();
358 }
359 else
360 {
361 m_zonesettings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), selected );
362 }
363}
364
365
367{
369 {
370 if( m_rbBoundingHull->GetValue() )
371 {
374 }
375 else
376 {
378 }
379
381 }
382
383 // Set keepout parameters:
390
391 // Set placement parameters
394
395 auto setPlacementSource = [this]( RULE_AREA_PLACEMENT_SOURCE_TYPE sourceType )
396 {
398
399 wxComboBox* cb;
400
401 if( sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
403 else
405
406 int selectedSourceIdx = cb->GetSelection();
407
408 if( selectedSourceIdx != wxNOT_FOUND )
409 {
410 if( selectedSourceIdx == 0 && m_notFoundPlacementSource
411 && m_originalPlacementSourceType == sourceType )
412 {
414 }
415 else
416 {
417 m_zonesettings.SetRuleAreaPlacementSource( cb->GetString( selectedSourceIdx ) );
418 }
419 }
420 };
421
422 if( m_placementProperties->m_SheetRb->GetValue() )
423 {
425 setPlacementSource( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
426 }
427 else if( m_placementProperties->m_ComponentsRb->GetValue() )
428 {
430 setPlacementSource( RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS );
431 }
432 else
433 {
434 setPlacementSource( m_lastPlacementSourceType );
435 }
436
437 if( m_zonesettings.m_Layers.count() == 0 )
438 {
439 DisplayError( this, _( "No layers selected." ) );
440 return false;
441 }
442
443 switch( m_OutlineDisplayCtrl->GetSelection() )
444 {
445 case 0:
446 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
447 break;
448 case 1:
449 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
450 break;
451 case 2:
452 m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
453 break;
454 }
455
458 {
459 return false;
460 }
461
463
464 m_zonesettings.m_Locked = m_cbLocked->GetValue();
465 m_zonesettings.m_ZonePriority = 0; // for a keepout, this param is not used.
466
467 m_zonesettings.m_Name = m_tcName->GetValue();
468
470 return true;
471}
472
473
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
BASE_SET & set(size_t pos)
Definition: base_set.h:116
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:295
int GetCopperLayerCount() const
Definition: board.cpp:780
const FOOTPRINTS & Footprints() const
Definition: board.h:336
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition: board.h:1288
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:37
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:573
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:551
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:562
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:699
@ 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