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 m_fpEditorInstance = static_cast<PG_FPID_EDITOR*>( wxPropertyGrid::RegisterEditorClass( fpEditor ) );
294 }
295
296 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_URL_EDITOR::BuildEditorName( m_frame ) );
297
298 if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
299 {
300 m_urlEditorInstance = static_cast<PG_URL_EDITOR*>( it->second );
301 m_urlEditorInstance->UpdateFrame( m_frame );
302 }
303 else
304 {
305 PG_URL_EDITOR* urlEditor = new PG_URL_EDITOR( m_frame );
306 m_urlEditorInstance = static_cast<PG_URL_EDITOR*>( wxPropertyGrid::RegisterEditorClass( urlEditor ) );
307 }
308}
309
310
312{
313 m_unitEditorInstance->UpdateFrame( nullptr );
314 m_fpEditorInstance->UpdateFrame( nullptr );
315 m_urlEditorInstance->UpdateFrame( nullptr );
316}
317
318
320{
321 PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
322 const SELECTION& selection = selectionTool->GetSelection();
323
324 if( selection.Empty() && m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
325 {
326 if( BOARD* board = m_frame->GetBoard() )
327 {
328 if( FOOTPRINT* footprint = board->GetFirstFootprint() )
329 {
330 aFallbackSelection.Clear();
331 aFallbackSelection.Add( footprint );
332 return aFallbackSelection;
333 }
334 }
335 }
336
337 return selection;
338}
339
340
342{
343 SELECTION fallbackSelection;
344 const SELECTION& selection = getSelection( fallbackSelection );
345
346 return selection.Empty() ? nullptr : selection.Front();
347}
348
349
351{
352 SELECTION fallbackSelection;
353 const SELECTION& selection = getSelection( fallbackSelection );
354
355 // TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD?
356 updateLists( static_cast<PCB_EDIT_FRAME*>( m_frame )->GetBoard() );
357
358 // Will actually just be updatePropertyValues() if selection hasn't changed
359 rebuildProperties( selection );
360}
361
362
364{
365 SELECTION fallbackSelection;
366 const SELECTION& selection = getSelection( fallbackSelection );
367
368 rebuildProperties( selection );
369}
370
371
373{
374 m_currentFieldNames.clear();
375
376 for( EDA_ITEM* item : aSelection )
377 {
378 if( item->Type() != PCB_FOOTPRINT_T )
379 continue;
380
381 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
382
383 for( PCB_FIELD* field : footprint->GetFields() )
384 m_currentFieldNames.insert( field->GetCanonicalName() );
385 }
386
387 const wxString groupFields = _HKI( "Fields" );
388
389 for( const wxString& name : m_currentFieldNames )
390 {
391 if( !m_propMgr.GetProperty( TYPE_HASH( FOOTPRINT ), name ) )
392 {
393 m_propMgr.AddProperty( new PCB_FOOTPRINT_FIELD_PROPERTY( name ), groupFields )
394 .SetAvailableFunc( [name]( INSPECTABLE* )
395 {
397 } );
398 }
399 }
400
402}
403
404
405wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
406{
407 if( aProperty->TypeHash() == TYPE_HASH( PCB_LAYER_ID ) )
408 {
409 wxASSERT( aProperty->HasChoices() );
410
411 const wxPGChoices& canonicalLayers = aProperty->Choices();
412 wxArrayString boardLayerNames;
413 wxArrayInt boardLayerIDs;
414
415 for( int ii = 0; ii < (int) aProperty->Choices().GetCount(); ++ii )
416 {
417 int layer = canonicalLayers.GetValue( ii );
418
419 boardLayerNames.push_back( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) );
420 boardLayerIDs.push_back( canonicalLayers.GetValue( ii ) );
421 }
422
423 auto ret = new PGPROPERTY_COLORENUM( new wxPGChoices( boardLayerNames, boardLayerIDs ) );
424
425 ret->SetColorFunc(
426 [&]( int aValue ) -> wxColour
427 {
428 return m_frame->GetColorSettings()->GetColor( ToLAYER_ID( aValue ) ).ToColour();
429 } );
430
431 ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
432 ret->SetName( aProperty->Name() );
433 ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
434 ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
435
436 return ret;
437 }
438
439 wxPGProperty* prop = PGPropertyFactory( aProperty, m_frame );
440
441 if( aProperty->Name() == GetCanonicalFieldName( FIELD_T::FOOTPRINT ) )
442 prop->SetEditor( PG_FPID_EDITOR::BuildEditorName( m_frame ) );
443 else if( aProperty->Name() == GetCanonicalFieldName( FIELD_T::DATASHEET ) )
444 prop->SetEditor( PG_URL_EDITOR::BuildEditorName( m_frame ) );
445
446 return prop;
447}
448
449
450PROPERTY_BASE* PCB_PROPERTIES_PANEL::getPropertyFromEvent( const wxPropertyGridEvent& aEvent ) const
451{
452 EDA_ITEM* item = const_cast<PCB_PROPERTIES_PANEL*>( this )->getFrontItem();
453
454 if( !item || !item->IsBOARD_ITEM() )
455 return nullptr;
456
457 BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( item );
458
459 wxCHECK_MSG( firstItem, nullptr,
460 wxT( "getPropertyFromEvent for a property with nothing selected!") );
461
462 PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ), aEvent.GetPropertyName() );
463 wxCHECK_MSG( property, nullptr,
464 wxT( "getPropertyFromEvent for a property not found on the selected item!" ) );
465
466 return property;
467}
468
469
470void PCB_PROPERTIES_PANEL::valueChanging( wxPropertyGridEvent& aEvent )
471{
473 return;
474
475 EDA_ITEM* item = getFrontItem();
476
477 PROPERTY_BASE* property = getPropertyFromEvent( aEvent );
478 wxCHECK( property, /* void */ );
479 wxCHECK( item, /* void */ );
480
481 wxVariant newValue = aEvent.GetPropertyValue();
482
483 if( VALIDATOR_RESULT validationFailure = property->Validate( newValue.GetAny(), item ) )
484 {
485 wxString errorMsg = wxString::Format( wxS( "%s: %s" ), wxGetTranslation( property->Name() ),
486 validationFailure->get()->Format( m_frame ) );
487 m_frame->ShowInfoBarError( errorMsg );
488 aEvent.Veto();
489 return;
490 }
491
492 aEvent.Skip();
493}
494
495
496void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
497{
499 return;
500
501 SELECTION fallbackSelection;
502 const SELECTION& selection = getSelection( fallbackSelection );
503
504 wxCHECK( getPropertyFromEvent( aEvent ), /* void */ );
505
506 wxVariant newValue = aEvent.GetPropertyValue();
507 BOARD_COMMIT changes( m_frame );
508
509 PROPERTY_COMMIT_HANDLER handler( &changes );
510
511 for( EDA_ITEM* edaItem : selection )
512 {
513 if( !edaItem->IsBOARD_ITEM() )
514 continue;
515
516 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( edaItem );
517 PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *item ), aEvent.GetPropertyName() );
518 wxCHECK( property, /* void */ );
519
520 if( item->Type() == PCB_TABLECELL_T )
521 changes.Modify( item->GetParent(), nullptr, RECURSE_MODE::NO_RECURSE );
522 else if( item->Type() == PCB_GENERATOR_T )
523 changes.Modify( item, nullptr, RECURSE_MODE::RECURSE );
524 else
525 changes.Modify( item, nullptr, RECURSE_MODE::NO_RECURSE );
526
527 // In the PCB Editor, we generally restrict pad movement to the footprint (like dragging)
528 if( item->Type() == PCB_PAD_T && m_frame
529 && m_frame->IsType( FRAME_PCB_EDITOR )
530 && !m_frame->GetPcbNewSettings()->m_AllowFreePads
531 && ( aEvent.GetPropertyName() == _HKI( "Position X" )
532 || aEvent.GetPropertyName() == _HKI( "Position Y" ) ) )
533 {
534 PAD* pad = static_cast<PAD*>( item );
535 FOOTPRINT* fp = pad->GetParentFootprint();
536
537 if( fp )
538 {
539 VECTOR2I oldPos = pad->GetPosition();
540 VECTOR2I newPos = oldPos;
541
542 if( aEvent.GetPropertyName() == _HKI( "Position X" ) )
543 newPos.x = (int) newValue.GetLong();
544 else
545 newPos.y = (int) newValue.GetLong();
546
547 VECTOR2I delta = newPos - oldPos;
548
549 if( delta.x != 0 || delta.y != 0 )
550 {
551 changes.Modify( fp );
552 fp->Move( delta );
553 }
554 }
555
556 continue;
557 }
558
559 // Handle variant-aware boolean properties for footprints
560 if( item->Type() == PCB_FOOTPRINT_T )
561 {
562 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
563 wxString variantName;
564
565 if( footprint->GetBoard() )
566 variantName = footprint->GetBoard()->GetCurrentVariant();
567
568 if( !variantName.IsEmpty() )
569 {
570 wxString propName = aEvent.GetPropertyName();
571
572 if( propName == _HKI( "Do not Populate" )
573 || propName == _HKI( "Exclude From Bill of Materials" )
574 || propName == _HKI( "Exclude From Position Files" ) )
575 {
576 FOOTPRINT_VARIANT* variant = footprint->GetVariant( variantName );
577
578 if( !variant )
579 variant = footprint->AddVariant( variantName );
580
581 if( variant )
582 {
583 bool boolValue = newValue.GetBool();
584
585 if( propName == _HKI( "Do not Populate" ) )
586 variant->SetDNP( boolValue );
587 else if( propName == _HKI( "Exclude From Bill of Materials" ) )
588 variant->SetExcludedFromBOM( boolValue );
589 else if( propName == _HKI( "Exclude From Position Files" ) )
590 variant->SetExcludedFromPosFiles( boolValue );
591
592 continue;
593 }
594 }
595 }
596 }
597
598 item->Set( property, newValue );
599 }
600
601 changes.Push( _( "Edit Properties" ) );
602
603 m_frame->Refresh();
604
605 // Perform grid updates as necessary based on value change
606 AfterCommit();
607
608 // PointEditor may need to update if locked/unlocked
609 if( aEvent.GetPropertyName() == _HKI( "Locked" ) )
610 m_frame->GetToolManager()->ProcessEvent( EVENTS::SelectedEvent );
611
612 aEvent.Skip();
613}
614
615
617{
618 wxPGChoices layersAll;
619 wxPGChoices layersCu;
620 wxPGChoices nets;
621 wxPGChoices fonts;
622
623 // Regenerate all layers
624 for( PCB_LAYER_ID layer : aBoard->GetEnabledLayers().UIOrder() )
625 layersAll.Add( LSET::Name( layer ), layer );
626
627 for( PCB_LAYER_ID layer : LSET( aBoard->GetEnabledLayers() & LSET::AllCuMask() ).UIOrder() )
628 layersCu.Add( LSET::Name( layer ), layer );
629
630 m_propMgr.GetProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) )->SetChoices( layersAll );
631 m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) )->SetChoices( layersAll );
632
633 // Copper only properties
634 m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) )->SetChoices( layersCu );
635 m_propMgr.GetProperty( TYPE_HASH( PAD ), _HKI( "Bottom Backdrill Must-Cut" ) )->SetChoices( layersCu );
636 m_propMgr.GetProperty( TYPE_HASH( PAD ), _HKI( "Top Backdrill Must-Cut" ) )->SetChoices( layersCu );
637 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Top" ) )->SetChoices( layersCu );
638 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Bottom" ) )->SetChoices( layersCu );
639 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Bottom Backdrill Must-Cut" ) )->SetChoices( layersCu );
640 m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Top Backdrill Must-Cut" ) )->SetChoices( layersCu );
641 m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Layer" ) )->SetChoices( layersCu );
642
643 // Regenerate nets
644
645 std::vector<std::pair<wxString, int>> netNames;
646 netNames.reserve( aBoard->GetNetInfo().NetsByNetcode().size() );
647
648 for( const auto& [ netCode, netInfo ] : aBoard->GetNetInfo().NetsByNetcode() )
649 netNames.emplace_back( UnescapeString( netInfo->GetNetname() ), netCode );
650
651 std::sort( netNames.begin(), netNames.end(),
652 []( const auto& a, const auto& b )
653 {
654 return a.first.CmpNoCase( b.first ) < 0;
655 } );
656
657 for( const auto& [ netName, netCode ] : netNames )
658 nets.Add( netName, netCode );
659
660 auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) );
661 netProperty->SetChoices( nets );
662
663 auto tuningNet = m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Net" ) );
664 tuningNet->SetChoices( nets );
665}
666
667
668bool PCB_PROPERTIES_PANEL::getItemValue( EDA_ITEM* aItem, PROPERTY_BASE* aProperty, wxVariant& aValue )
669{
670 // For FOOTPRINT variant-aware boolean properties, return variant-specific values
671 if( aItem->Type() == PCB_FOOTPRINT_T )
672 {
673 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
674 wxString variantName;
675
676 if( footprint->GetBoard() )
677 variantName = footprint->GetBoard()->GetCurrentVariant();
678
679 if( !variantName.IsEmpty() )
680 {
681 wxString propName = aProperty->Name();
682
683 if( propName == _HKI( "Do not Populate" ) )
684 {
685 aValue = wxVariant( footprint->GetDNPForVariant( variantName ) );
686 return true;
687 }
688 else if( propName == _HKI( "Exclude From Bill of Materials" ) )
689 {
690 aValue = wxVariant( footprint->GetExcludedFromBOMForVariant( variantName ) );
691 return true;
692 }
693 else if( propName == _HKI( "Exclude From Position Files" ) )
694 {
695 aValue = wxVariant( footprint->GetExcludedFromPosFilesForVariant( variantName ) );
696 return true;
697 }
698 }
699 }
700
701 return PROPERTIES_PANEL::getItemValue( aItem, aProperty, aValue );
702}
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:967
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:279
static const TOOL_EVENT SelectedEvent
Definition actions.h:345
Variant information for a footprint.
Definition footprint.h:144
void SetExcludedFromPosFiles(bool aExclude)
Definition footprint.h:164
void SetDNP(bool aDNP)
Definition footprint.h:158
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:186
void SetExcludedFromBOM(bool aExclude)
Definition footprint.h:161
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:726
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:582
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:737
#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