KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_properties_panel.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) 2020-2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
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 3
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 along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include <font/fontconfig.h>
26#include <frame_type.h>
27#include <pgm_base.h>
28#include <pcb_base_edit_frame.h>
29#include <tool/tool_manager.h>
30#include <tools/pcb_actions.h>
34#include <board_commit.h>
36#include <board.h>
38#include <pcb_shape.h>
39#include <pcb_text.h>
40#include <pcb_track.h>
41#include <pcb_generator.h>
43#include <pad.h>
44#include <footprint.h>
45#include <pcb_field.h>
46#include <template_fieldnames.h>
48#include <string_utils.h>
50#include <widgets/ui_common.h>
51
52static const wxString MISSING_FIELD_SENTINEL = wxS( "\uE000" );
53
55{
56public:
57 PCB_FOOTPRINT_FIELD_PROPERTY( const wxString& aName ) :
58 PROPERTY_BASE( aName ),
59 m_name( aName )
60 {
61 }
62
63 size_t OwnerHash() const override { return TYPE_HASH( FOOTPRINT ); }
64 size_t BaseHash() const override { return TYPE_HASH( FOOTPRINT ); }
65 size_t TypeHash() const override { return TYPE_HASH( wxString ); }
66
67 bool Writeable( INSPECTABLE* aObject ) const override
68 {
69 return PROPERTY_BASE::Writeable( aObject );
70 }
71
72 void setter( void* obj, wxAny& v ) override
73 {
74 wxString value;
75
76 if( !v.GetAs( &value ) )
77 return;
78
79 FOOTPRINT* footprint = reinterpret_cast<FOOTPRINT*>( obj );
80 PCB_FIELD* field = footprint->GetField( m_name );
81
82 wxString variantName;
83
84 if( footprint->GetBoard() )
85 variantName = footprint->GetBoard()->GetCurrentVariant();
86
87 if( !variantName.IsEmpty() )
88 {
89 // Store the value as a variant override
90 FOOTPRINT_VARIANT* variant = footprint->AddVariant( variantName );
91
92 if( variant )
93 variant->SetFieldValue( m_name, value );
94 }
95 else
96 {
97 // Set the base field value
98 if( !field )
99 {
100 PCB_FIELD* newField = new PCB_FIELD( footprint, FIELD_T::USER, m_name );
101 newField->SetText( value );
102 footprint->Add( newField );
103 }
104 else
105 {
106 field->SetText( value );
107 }
108 }
109 }
110
111 wxAny getter( const void* obj ) const override
112 {
113 const FOOTPRINT* footprint = reinterpret_cast<const FOOTPRINT*>( obj );
114 PCB_FIELD* field = footprint->GetField( m_name );
115
116 if( field )
117 {
118 wxString variantName;
119
120 if( footprint->GetBoard() )
121 variantName = footprint->GetBoard()->GetCurrentVariant();
122
123 wxString text;
124
125 if( !variantName.IsEmpty() )
126 text = footprint->GetFieldValueForVariant( variantName, m_name );
127 else
128 text = field->GetText();
129
130 return wxAny( text );
131 }
132 else
133 {
134 return wxAny( MISSING_FIELD_SENTINEL );
135 }
136 }
137
138private:
139 wxString m_name;
140};
141
143
144
145class PG_NET_SELECTOR_EDITOR : public wxPGEditor
146{
147public:
148 static const wxString EDITOR_NAME;
149
151 {
152 }
153
154 wxString GetName() const override { return EDITOR_NAME; }
155
156 wxPGWindowList CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty,
157 const wxPoint& aPos, const wxSize& aSize ) const override
158 {
159 NET_SELECTOR* editor = new NET_SELECTOR( aGrid->GetPanel(), wxID_ANY, aPos, aSize, 0 );
160
161 if( BOARD* board = m_frame->GetBoard() )
162 editor->SetNetInfo( &board->GetNetInfo() );
163
164 editor->SetIndeterminateString( INDETERMINATE_STATE );
165 UpdateControl( aProperty, editor );
166
167 editor->Bind( FILTERED_ITEM_SELECTED,
168 [=]( wxCommandEvent& aEvt )
169 {
170 auto& choices = const_cast<wxPGChoices&>( aProperty->GetChoices() );
171 wxString netname = editor->GetSelectedNetname();
172
173 if( choices.Index( netname ) == wxNOT_FOUND )
174 choices.Add( netname, editor->GetSelectedNetcode() );
175
176 wxVariant val( editor->GetSelectedNetcode() );
177 aGrid->ChangePropertyValue( aProperty, val );
178 } );
179
180 return editor;
181 }
182
183 void UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const override
184 {
185 if( NET_SELECTOR* editor = dynamic_cast<NET_SELECTOR*>( aCtrl ) )
186 {
187 if( aProperty->IsValueUnspecified() )
188 editor->SetIndeterminate();
189 else
190 editor->SetSelectedNetcode( (int) aProperty->GetValue().GetLong() );
191 }
192 }
193
194 bool GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty,
195 wxWindow* aCtrl ) const override
196 {
197 NET_SELECTOR* editor = dynamic_cast<NET_SELECTOR*>( aCtrl );
198
199 if( !editor )
200 return false;
201
202 aVariant = static_cast<long>( editor->GetSelectedNetcode() );
203 return true;
204 }
205
206 bool OnEvent( wxPropertyGrid* aGrid, wxPGProperty* aProperty, wxWindow* aWindow,
207 wxEvent& aEvent ) const override
208 {
209 return false;
210 }
211
212private:
214};
215
216const wxString PG_NET_SELECTOR_EDITOR::EDITOR_NAME = wxS( "PG_NET_SELECTOR_EDITOR" );
217
218
219
221 PROPERTIES_PANEL( aParent, aFrame ),
222 m_frame( aFrame ),
223 m_propMgr( PROPERTY_MANAGER::Instance() )
224{
225 m_propMgr.Rebuild();
226 bool found = false;
227
228 wxASSERT( wxPGGlobalVars );
229
230 wxString editorKey = PG_UNIT_EDITOR::BuildEditorName( m_frame );
231
232 auto it = wxPGGlobalVars->m_mapEditorClasses.find( editorKey );
233
234 if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
235 {
236 m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( it->second );
237 m_unitEditorInstance->UpdateFrame( m_frame );
238 found = true;
239 }
240
241 if( !found )
242 {
243 PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame );
244 m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
245 }
246
247 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME );
248
249 if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
250 {
251 PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR();
252 m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( wxPropertyGrid::RegisterEditorClass( cbEditor ) );
253 }
254 else
255 {
256 m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( it->second );
257 }
258
259 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_RATIO_EDITOR::EDITOR_NAME );
260
261 if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
262 {
263 PG_RATIO_EDITOR* ratioEditor = new PG_RATIO_EDITOR();
264 m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( wxPropertyGrid::RegisterEditorClass( ratioEditor ) );
265 }
266 else
267 {
268 m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( it->second );
269 }
270
271 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_NET_SELECTOR_EDITOR::EDITOR_NAME );
272
273 if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
274 {
276 m_netSelectorEditorInstance = static_cast<PG_NET_SELECTOR_EDITOR*>( wxPropertyGrid::RegisterEditorClass( netEditor ) );
277 }
278 else
279 {
280 m_netSelectorEditorInstance = static_cast<PG_NET_SELECTOR_EDITOR*>( it->second );
281 }
282
283 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_FPID_EDITOR::BuildEditorName( m_frame ) );
284
285 if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
286 {
287 m_fpEditorInstance = static_cast<PG_FPID_EDITOR*>( it->second );
288 m_fpEditorInstance->UpdateFrame( m_frame );
289 }
290 else
291 {
292 PG_FPID_EDITOR* fpEditor = new PG_FPID_EDITOR( m_frame,
293 []()
294 {
295 return "";
296 });
297 m_fpEditorInstance = static_cast<PG_FPID_EDITOR*>( wxPropertyGrid::RegisterEditorClass( fpEditor ) );
298 }
299
300 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_URL_EDITOR::BuildEditorName( m_frame ) );
301
302 if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
303 {
304 m_urlEditorInstance = static_cast<PG_URL_EDITOR*>( it->second );
305 m_urlEditorInstance->UpdateFrame( m_frame );
306 }
307 else
308 {
309 PG_URL_EDITOR* urlEditor = new PG_URL_EDITOR( m_frame );
310 m_urlEditorInstance = static_cast<PG_URL_EDITOR*>( wxPropertyGrid::RegisterEditorClass( urlEditor ) );
311 }
312}
313
314
316{
317 m_unitEditorInstance->UpdateFrame( nullptr );
318 m_fpEditorInstance->UpdateFrame( nullptr );
319 m_urlEditorInstance->UpdateFrame( nullptr );
320}
321
322
324{
325 PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
326 const SELECTION& selection = selectionTool->GetSelection();
327
328 if( selection.Empty() && m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
329 {
330 if( BOARD* board = m_frame->GetBoard() )
331 {
332 if( FOOTPRINT* footprint = board->GetFirstFootprint() )
333 {
334 aFallbackSelection.Clear();
335 aFallbackSelection.Add( footprint );
336 return aFallbackSelection;
337 }
338 }
339 }
340
341 return selection;
342}
343
344
346{
347 SELECTION fallbackSelection;
348 const SELECTION& selection = getSelection( fallbackSelection );
349
350 return selection.Empty() ? nullptr : selection.Front();
351}
352
353
355{
356 SELECTION fallbackSelection;
357 const SELECTION& selection = getSelection( fallbackSelection );
358
359 // TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD?
360 updateLists( static_cast<PCB_EDIT_FRAME*>( m_frame )->GetBoard() );
361
362 // Will actually just be updatePropertyValues() if selection hasn't changed
363 rebuildProperties( selection );
364}
365
366
368{
369 SELECTION fallbackSelection;
370 const SELECTION& selection = getSelection( fallbackSelection );
371
372 rebuildProperties( selection );
373}
374
375
377{
378 m_currentFieldNames.clear();
379
380 for( EDA_ITEM* item : aSelection )
381 {
382 if( item->Type() != PCB_FOOTPRINT_T )
383 continue;
384
385 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
386
387 for( PCB_FIELD* field : footprint->GetFields() )
388 {
389 wxCHECK2( field, continue );
390
391 m_currentFieldNames.insert( field->GetCanonicalName() );
392 }
393 }
394
395 const wxString groupFields = _HKI( "Fields" );
396
397 for( const wxString& name : m_currentFieldNames )
398 {
399 if( !m_propMgr.GetProperty( TYPE_HASH( FOOTPRINT ), name ) )
400 {
401 m_propMgr.AddProperty( new PCB_FOOTPRINT_FIELD_PROPERTY( name ), groupFields )
402 .SetAvailableFunc( [name]( INSPECTABLE* )
403 {
405 } );
406 }
407 }
408
410}
411
412
413wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
414{
415 if( aProperty->TypeHash() == TYPE_HASH( PCB_LAYER_ID ) )
416 {
417 wxASSERT( aProperty->HasChoices() );
418
419 const wxPGChoices& canonicalLayers = aProperty->Choices();
420 wxArrayString boardLayerNames;
421 wxArrayInt boardLayerIDs;
422
423 for( int ii = 0; ii < (int) aProperty->Choices().GetCount(); ++ii )
424 {
425 int layer = canonicalLayers.GetValue( ii );
426
427 boardLayerNames.push_back( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) );
428 boardLayerIDs.push_back( canonicalLayers.GetValue( ii ) );
429 }
430
431 auto ret = new PGPROPERTY_COLORENUM( new wxPGChoices( boardLayerNames, boardLayerIDs ) );
432
433 ret->SetColorFunc(
434 [&]( int aValue ) -> wxColour
435 {
436 return m_frame->GetColorSettings()->GetColor( ToLAYER_ID( aValue ) ).ToColour();
437 } );
438
439 ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
440 ret->SetName( aProperty->Name() );
441 ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
442 ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
443
444 return ret;
445 }
446
447 wxPGProperty* prop = PGPropertyFactory( aProperty, m_frame );
448
449 if( aProperty->Name() == GetCanonicalFieldName( FIELD_T::FOOTPRINT ) )
450 prop->SetEditor( PG_FPID_EDITOR::BuildEditorName( m_frame ) );
451 else if( aProperty->Name() == GetCanonicalFieldName( FIELD_T::DATASHEET ) )
452 prop->SetEditor( PG_URL_EDITOR::BuildEditorName( m_frame ) );
453
454 return prop;
455}
456
457
458PROPERTY_BASE* PCB_PROPERTIES_PANEL::getPropertyFromEvent( const wxPropertyGridEvent& aEvent ) const
459{
460 EDA_ITEM* item = const_cast<PCB_PROPERTIES_PANEL*>( this )->getFrontItem();
461
462 if( !item || !item->IsBOARD_ITEM() )
463 return nullptr;
464
465 BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( item );
466
467 wxCHECK_MSG( firstItem, nullptr,
468 wxT( "getPropertyFromEvent for a property with nothing selected!") );
469
470 PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ), aEvent.GetPropertyName() );
471 wxCHECK_MSG( property, nullptr,
472 wxT( "getPropertyFromEvent for a property not found on the selected item!" ) );
473
474 return property;
475}
476
477
478void PCB_PROPERTIES_PANEL::valueChanging( wxPropertyGridEvent& aEvent )
479{
481 return;
482
483 EDA_ITEM* item = getFrontItem();
484
485 PROPERTY_BASE* property = getPropertyFromEvent( aEvent );
486 wxCHECK( property, /* void */ );
487 wxCHECK( item, /* void */ );
488
489 wxVariant newValue = aEvent.GetPropertyValue();
490
491 if( VALIDATOR_RESULT validationFailure = property->Validate( newValue.GetAny(), item ) )
492 {
493 wxString errorMsg = wxString::Format( wxS( "%s: %s" ), wxGetTranslation( property->Name() ),
494 validationFailure->get()->Format( m_frame ) );
495 m_frame->ShowInfoBarError( errorMsg );
496 aEvent.Veto();
497 return;
498 }
499
500 aEvent.Skip();
501}
502
503
504void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
505{
507 return;
508
509 SELECTION fallbackSelection;
510 const SELECTION& selection = getSelection( fallbackSelection );
511
512 wxCHECK( getPropertyFromEvent( aEvent ), /* void */ );
513
514 wxVariant newValue = aEvent.GetPropertyValue();
515 BOARD_COMMIT changes( m_frame );
516
517 PROPERTY_COMMIT_HANDLER handler( &changes );
518
519 for( EDA_ITEM* edaItem : selection )
520 {
521 if( !edaItem->IsBOARD_ITEM() )
522 continue;
523
524 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( edaItem );
525 PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *item ), aEvent.GetPropertyName() );
526 wxCHECK( property, /* void */ );
527
528 if( item->Type() == PCB_TABLECELL_T )
529 changes.Modify( item->GetParent(), nullptr, RECURSE_MODE::NO_RECURSE );
530 else if( item->Type() == PCB_GENERATOR_T )
531 changes.Modify( item, nullptr, RECURSE_MODE::RECURSE );
532 else
533 changes.Modify( item, nullptr, RECURSE_MODE::NO_RECURSE );
534
535 // In the PCB Editor, we generally restrict pad movement to the footprint (like dragging)
536 if( item->Type() == PCB_PAD_T && m_frame
537 && m_frame->IsType( FRAME_PCB_EDITOR )
538 && !m_frame->GetPcbNewSettings()->m_AllowFreePads
539 && ( aEvent.GetPropertyName() == _HKI( "Position X" )
540 || aEvent.GetPropertyName() == _HKI( "Position Y" ) ) )
541 {
542 PAD* pad = static_cast<PAD*>( item );
543 FOOTPRINT* fp = pad->GetParentFootprint();
544
545 if( fp )
546 {
547 VECTOR2I oldPos = pad->GetPosition();
548 VECTOR2I newPos = oldPos;
549
550 if( aEvent.GetPropertyName() == _HKI( "Position X" ) )
551 newPos.x = (int) newValue.GetLong();
552 else
553 newPos.y = (int) newValue.GetLong();
554
555 VECTOR2I delta = newPos - oldPos;
556
557 if( delta.x != 0 || delta.y != 0 )
558 {
559 changes.Modify( fp );
560 fp->Move( delta );
561 }
562 }
563
564 continue;
565 }
566
567 // Handle variant-aware boolean properties for footprints
568 if( item->Type() == PCB_FOOTPRINT_T )
569 {
570 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
571 wxString variantName;
572
573 if( footprint->GetBoard() )
574 variantName = footprint->GetBoard()->GetCurrentVariant();
575
576 if( !variantName.IsEmpty() )
577 {
578 wxString propName = aEvent.GetPropertyName();
579
580 if( propName == _HKI( "Do not Populate" )
581 || propName == _HKI( "Exclude From Bill of Materials" )
582 || propName == _HKI( "Exclude From Position Files" ) )
583 {
584 FOOTPRINT_VARIANT* variant = footprint->GetVariant( variantName );
585
586 if( !variant )
587 variant = footprint->AddVariant( variantName );
588
589 if( variant )
590 {
591 bool boolValue = newValue.GetBool();
592
593 if( propName == _HKI( "Do not Populate" ) )
594 variant->SetDNP( boolValue );
595 else if( propName == _HKI( "Exclude From Bill of Materials" ) )
596 variant->SetExcludedFromBOM( boolValue );
597 else if( propName == _HKI( "Exclude From Position Files" ) )
598 variant->SetExcludedFromPosFiles( boolValue );
599
600 continue;
601 }
602 }
603 }
604 }
605
606 item->Set( property, newValue );
607 }
608
609 changes.Push( _( "Edit Properties" ) );
610
611 m_frame->Refresh();
612
613 // Perform grid updates as necessary based on value change
614 AfterCommit();
615
616 // PointEditor may need to update if locked/unlocked
617 if( aEvent.GetPropertyName() == _HKI( "Locked" ) )
618 m_frame->GetToolManager()->ProcessEvent( EVENTS::SelectedEvent );
619
620 aEvent.Skip();
621}
622
623
625{
626 wxPGChoices layersAll;
627 wxPGChoices layersCu;
628 wxPGChoices nets;
629 wxPGChoices fonts;
630
631 // Regenerate all layers
632 for( PCB_LAYER_ID layer : aBoard->GetEnabledLayers().UIOrder() )
633 layersAll.Add( LSET::Name( layer ), layer );
634
635 for( PCB_LAYER_ID layer : LSET( aBoard->GetEnabledLayers() & LSET::AllCuMask() ).UIOrder() )
636 layersCu.Add( LSET::Name( layer ), layer );
637
638 m_propMgr.GetProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) )->SetChoices( layersAll );
639 m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) )->SetChoices( layersAll );
640
641 // Copper only properties
642 m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) )->SetChoices( layersCu );
643 m_propMgr.GetProperty( TYPE_HASH( PAD ), _HKI( "Bottom Backdrill Must-Cut" ) )->SetChoices( layersCu );
644 m_propMgr.GetProperty( TYPE_HASH( PAD ), _HKI( "Top Backdrill Must-Cut" ) )->SetChoices( layersCu );
645 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Top" ) )->SetChoices( layersCu );
646 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Bottom" ) )->SetChoices( layersCu );
647 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Bottom Backdrill Must-Cut" ) )->SetChoices( layersCu );
648 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Top Backdrill Must-Cut" ) )->SetChoices( layersCu );
649 m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Layer" ) )->SetChoices( layersCu );
650
651 // Regenerate nets
652
653 std::vector<std::pair<wxString, int>> netNames;
654 netNames.reserve( aBoard->GetNetInfo().NetsByNetcode().size() );
655
656 for( const auto& [ netCode, netInfo ] : aBoard->GetNetInfo().NetsByNetcode() )
657 netNames.emplace_back( UnescapeString( netInfo->GetNetname() ), netCode );
658
659 std::sort( netNames.begin(), netNames.end(),
660 []( const auto& a, const auto& b )
661 {
662 return a.first.CmpNoCase( b.first ) < 0;
663 } );
664
665 for( const auto& [ netName, netCode ] : netNames )
666 nets.Add( netName, netCode );
667
668 auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) );
669 netProperty->SetChoices( nets );
670
671 auto tuningNet = m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Net" ) );
672 tuningNet->SetChoices( nets );
673}
674
675
676bool PCB_PROPERTIES_PANEL::getItemValue( EDA_ITEM* aItem, PROPERTY_BASE* aProperty, wxVariant& aValue )
677{
678 // For FOOTPRINT variant-aware boolean properties, return variant-specific values
679 if( aItem->Type() == PCB_FOOTPRINT_T )
680 {
681 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
682 wxString variantName;
683
684 if( footprint->GetBoard() )
685 variantName = footprint->GetBoard()->GetCurrentVariant();
686
687 if( !variantName.IsEmpty() )
688 {
689 wxString propName = aProperty->Name();
690
691 if( propName == _HKI( "Do not Populate" ) )
692 {
693 aValue = wxVariant( footprint->GetDNPForVariant( variantName ) );
694 return true;
695 }
696 else if( propName == _HKI( "Exclude From Bill of Materials" ) )
697 {
698 aValue = wxVariant( footprint->GetExcludedFromBOMForVariant( variantName ) );
699 return true;
700 }
701 else if( propName == _HKI( "Exclude From Position Files" ) )
702 {
703 aValue = wxVariant( footprint->GetExcludedFromPosFilesForVariant( variantName ) );
704 return true;
705 }
706 }
707 }
708
709 return PROPERTIES_PANEL::getItemValue( aItem, aProperty, aValue );
710}
const char * name
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:214
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const NETINFO_LIST & GetNetInfo() const
Definition board.h:996
wxString GetCurrentVariant() const
Definition board.h:404
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:965
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:282
static const TOOL_EVENT SelectedEvent
Definition actions.h:345
Variant information for a footprint.
Definition footprint.h:146
void SetExcludedFromPosFiles(bool aExclude)
Definition footprint.h:166
void SetDNP(bool aDNP)
Definition footprint.h:160
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:188
void SetExcludedFromBOM(bool aExclude)
Definition footprint.h:163
const FOOTPRINT_VARIANT * GetVariant(const wxString &aVariantName) const
Get a variant by name.
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
wxString GetFieldValueForVariant(const wxString &aVariantName, const wxString &aFieldName) const
Get a field value for a specific variant.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
bool GetDNPForVariant(const wxString &aVariantName) const
Get the DNP status for a specific variant.
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
bool GetExcludedFromPosFilesForVariant(const wxString &aVariantName) const
Get the exclude-from-position-files status for a specific variant.
FOOTPRINT_VARIANT * AddVariant(const wxString &aVariantName)
Add a new variant with the given name.
bool GetExcludedFromBOMForVariant(const wxString &aVariantName) const
Get the exclude-from-BOM status for a specific variant.
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:37
bool Set(PROPERTY_BASE *aProperty, wxAny &aValue, bool aNotify=true)
Definition inspectable.h:43
bool IsBOARD_ITEM() const
Definition view_item.h:102
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:743
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:599
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:188
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
Definition netinfo.h:241
Definition pad.h:55
Common, abstract interface for edit frames.
The main frame for Pcbnew.
size_t OwnerHash() const override
Return type-id of the Owner class.
size_t TypeHash() const override
Return type-id of the property type.
void setter(void *obj, wxAny &v) override
size_t BaseHash() const override
Return type-id of the Base class.
PCB_FOOTPRINT_FIELD_PROPERTY(const wxString &aName)
bool Writeable(INSPECTABLE *aObject) const override
wxAny getter(const void *obj) const override
PCB_BASE_EDIT_FRAME * m_frame
PG_NET_SELECTOR_EDITOR * m_netSelectorEditorInstance
void valueChanged(wxPropertyGridEvent &aEvent) override
Regenerates caches storing layer and net names.
PG_UNIT_EDITOR * m_unitEditorInstance
PG_RATIO_EDITOR * m_ratioEditorInstance
wxPGProperty * createPGProperty(const PROPERTY_BASE *aProperty) const override
void rebuildProperties(const SELECTION &aSelection) override
Generates the property grid for a given selection of items.
PCB_PROPERTIES_PANEL(wxWindow *aParent, PCB_BASE_EDIT_FRAME *aFrame)
const SELECTION & getSelection(SELECTION &aFallbackSelection)
Get the current selection from the selection tool.
EDA_ITEM * getFrontItem()
Get the front item of the current selection.
static std::set< wxString > m_currentFieldNames
PROPERTY_BASE * getPropertyFromEvent(const wxPropertyGridEvent &aEvent) const
PROPERTY_MANAGER & m_propMgr
PG_URL_EDITOR * m_urlEditorInstance
PG_CHECKBOX_EDITOR * m_checkboxEditorInstance
void updateLists(const BOARD *aBoard)
void valueChanging(wxPropertyGridEvent &aEvent) override
bool getItemValue(EDA_ITEM *aItem, PROPERTY_BASE *aProperty, wxVariant &aValue) override
Utility to fetch a property value and convert to wxVariant Precondition: aItem is known to have prope...
PG_FPID_EDITOR * m_fpEditorInstance
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
static const wxString EDITOR_NAME
Definition pg_editors.h:75
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aWindow, wxEvent &aEvent) const override
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
PCB_BASE_EDIT_FRAME * m_frame
wxString GetName() const override
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
static const wxString EDITOR_NAME
PG_NET_SELECTOR_EDITOR(PCB_BASE_EDIT_FRAME *aFrame)
static const wxString EDITOR_NAME
Definition pg_editors.h:117
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
PROPERTIES_PANEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
virtual bool getItemValue(EDA_ITEM *aItem, PROPERTY_BASE *aProperty, wxVariant &aValue)
Utility to fetch a property value and convert to wxVariant Precondition: aItem is known to have prope...
virtual void rebuildProperties(const SELECTION &aSelection)
Generates the property grid for a given selection of items.
virtual size_t TypeHash() const =0
Return type-id of the property type.
PROPERTY_BASE(const wxString &aName, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
< Used to generate unique IDs. Must come up front so it's initialized before ctor.
Definition property.h:201
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:246
virtual bool Writeable(INSPECTABLE *aObject) const
Definition property.h:282
friend class INSPECTABLE
Definition property.h:459
const wxString & Name() const
Definition property.h:220
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition property.h:226
Provide class metadata.Helper macro to map type hashes to names.
virtual void Add(EDA_ITEM *aItem)
Definition selection.cpp:42
EDA_ITEM * Front() const
Definition selection.h:177
virtual void Clear() override
Remove all the stored items from the group.
Definition selection.h:98
bool Empty() const
Checks if there is anything selected.
Definition selection.h:115
#define _(s)
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
@ FRAME_PCB_EDITOR
Definition frame_type.h:42
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:43
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:754
#define _HKI(x)
Definition page_info.cpp:44
static const wxString MISSING_FIELD_SENTINEL
BOARD * GetBoard()
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.
see class PGM_BASE
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
#define TYPE_HASH(x)
Definition property.h:74
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
static const wxString MISSING_FIELD_SENTINEL
wxString UnescapeString(const wxString &aSource)
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
wxString GetCanonicalFieldName(FIELD_T aFieldType)
int delta
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:91
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:95
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
Functions to provide common constants and other functions to assist in making a consistent UI.
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695