mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-13 17:53:11 +02:00
Wrap net_selector widget for properties
Provides consistent interface to modify/filter nets in property panel and dialogs Fixes https://gitlab.com/kicad/code/kicad/-/issues/17643
This commit is contained in:
parent
29c4d9b197
commit
0a767acb3a
@ -247,6 +247,10 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty, EDA_DRAW_FRAME*
|
||||
ret = new PGPROPERTY_RATIO();
|
||||
break;
|
||||
|
||||
case PROPERTY_DISPLAY::PT_NET:
|
||||
ret = new PGPROPERTY_NET( aProperty->Choices() );
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL;
|
||||
KI_FALLTHROUGH;
|
||||
@ -792,3 +796,19 @@ wxValidator* PGPROPERTY_TIME::DoGetValidator() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
PGPROPERTY_NET::PGPROPERTY_NET( const wxPGChoices& aChoices ) :
|
||||
wxEnumProperty( wxPG_LABEL, wxPG_LABEL, const_cast<wxPGChoices&>( aChoices ) )
|
||||
{
|
||||
SetEditor( wxS( "PG_NET_SELECTOR_EDITOR" ) );
|
||||
}
|
||||
|
||||
|
||||
const wxPGEditor* PGPROPERTY_NET::DoGetEditorClass() const
|
||||
{
|
||||
wxCHECK_MSG( m_customEditor, wxPGEditor_Choice,
|
||||
wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_NET!" ) );
|
||||
|
||||
return m_customEditor;
|
||||
}
|
||||
|
@ -366,4 +366,15 @@ protected:
|
||||
EDA_DRAW_FRAME* m_parentFrame;
|
||||
};
|
||||
|
||||
|
||||
class PGPROPERTY_NET : public wxEnumProperty
|
||||
{
|
||||
public:
|
||||
PGPROPERTY_NET( const wxPGChoices& aChoices = wxPGChoices() );
|
||||
|
||||
virtual ~PGPROPERTY_NET() = default;
|
||||
|
||||
const wxPGEditor* DoGetEditorClass() const override;
|
||||
};
|
||||
|
||||
#endif /* PG_PROPERTIES_H */
|
||||
|
@ -66,6 +66,7 @@ enum PROPERTY_DISPLAY
|
||||
PT_DECIDEGREE, ///< Angle expressed in decidegrees
|
||||
PT_RATIO,
|
||||
PT_TIME, ///< Time expressed in ps
|
||||
PT_NET, ///< Net selection property
|
||||
};
|
||||
|
||||
///< Macro to generate unique identifier for a type
|
||||
|
@ -213,7 +213,7 @@ static struct BOARD_CONNECTED_ITEM_DESC
|
||||
|
||||
propMgr.AddProperty( new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, int>( _HKI( "Net" ),
|
||||
&BOARD_CONNECTED_ITEM::SetNetCode,
|
||||
&BOARD_CONNECTED_ITEM::GetNetCode ) )
|
||||
&BOARD_CONNECTED_ITEM::GetNetCode, PT_NET ) )
|
||||
.SetIsHiddenFromRulesEditor()
|
||||
.SetIsHiddenFromLibraryEditors();
|
||||
|
||||
|
@ -2535,7 +2535,7 @@ static struct PCB_TUNING_PATTERN_DESC
|
||||
|
||||
propMgr.AddProperty( new PROPERTY_ENUM<PCB_TUNING_PATTERN, int>( _HKI( "Net" ),
|
||||
&PCB_TUNING_PATTERN::SetNetCode,
|
||||
&PCB_TUNING_PATTERN::GetNetCode ) );
|
||||
&PCB_TUNING_PATTERN::GetNetCode, PT_NET ) );
|
||||
|
||||
const wxString groupTechLayers = _HKI( "Technical Layers" );
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <properties/pg_editors.h>
|
||||
#include <board_commit.h>
|
||||
#include <board_connected_item.h>
|
||||
#include <board.h>
|
||||
#include <properties/pg_properties.h>
|
||||
#include <pcb_shape.h>
|
||||
#include <pcb_text.h>
|
||||
@ -41,6 +42,82 @@
|
||||
#include <pad.h>
|
||||
#include <settings/color_settings.h>
|
||||
#include <string_utils.h>
|
||||
#include <widgets/net_selector.h>
|
||||
#include <widgets/ui_common.h>
|
||||
|
||||
|
||||
class PG_NET_SELECTOR_EDITOR : public wxPGEditor
|
||||
{
|
||||
public:
|
||||
static const wxString EDITOR_NAME;
|
||||
|
||||
PG_NET_SELECTOR_EDITOR( PCB_BASE_EDIT_FRAME* aFrame ) : m_frame( aFrame )
|
||||
{
|
||||
}
|
||||
|
||||
wxString GetName() const override { return EDITOR_NAME; }
|
||||
|
||||
wxPGWindowList CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty,
|
||||
const wxPoint& aPos, const wxSize& aSize ) const override
|
||||
{
|
||||
NET_SELECTOR* editor = new NET_SELECTOR( aGrid->GetPanel(), wxID_ANY, aPos, aSize, 0 );
|
||||
|
||||
if( BOARD* board = m_frame->GetBoard() )
|
||||
editor->SetNetInfo( &board->GetNetInfo() );
|
||||
|
||||
editor->SetIndeterminateString( INDETERMINATE_STATE );
|
||||
UpdateControl( aProperty, editor );
|
||||
|
||||
editor->Bind( FILTERED_ITEM_SELECTED,
|
||||
[=]( wxCommandEvent& aEvt )
|
||||
{
|
||||
auto& choices = const_cast<wxPGChoices&>( aProperty->GetChoices() );
|
||||
wxString netname = editor->GetSelectedNetname();
|
||||
|
||||
if( choices.Index( netname ) == wxNOT_FOUND )
|
||||
choices.Add( netname, editor->GetSelectedNetcode() );
|
||||
|
||||
wxVariant val( editor->GetSelectedNetcode() );
|
||||
aGrid->ChangePropertyValue( aProperty, val );
|
||||
} );
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
void UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const override
|
||||
{
|
||||
if( NET_SELECTOR* editor = dynamic_cast<NET_SELECTOR*>( aCtrl ) )
|
||||
{
|
||||
if( aProperty->IsValueUnspecified() )
|
||||
editor->SetIndeterminate();
|
||||
else
|
||||
editor->SetSelectedNetcode( (int) aProperty->GetValue().GetLong() );
|
||||
}
|
||||
}
|
||||
|
||||
bool GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty,
|
||||
wxWindow* aCtrl ) const override
|
||||
{
|
||||
NET_SELECTOR* editor = dynamic_cast<NET_SELECTOR*>( aCtrl );
|
||||
|
||||
if( !editor )
|
||||
return false;
|
||||
|
||||
aVariant = static_cast<long>( editor->GetSelectedNetcode() );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnEvent( wxPropertyGrid* aGrid, wxPGProperty* aProperty, wxWindow* aWindow,
|
||||
wxEvent& aEvent ) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
PCB_BASE_EDIT_FRAME* m_frame;
|
||||
};
|
||||
|
||||
const wxString PG_NET_SELECTOR_EDITOR::EDITOR_NAME = wxS( "PG_NET_SELECTOR_EDITOR" );
|
||||
|
||||
|
||||
|
||||
@ -94,6 +171,18 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_BASE_EDIT_FRA
|
||||
{
|
||||
m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( it->second );
|
||||
}
|
||||
|
||||
it = wxPGGlobalVars->m_mapEditorClasses.find( PG_NET_SELECTOR_EDITOR::EDITOR_NAME );
|
||||
|
||||
if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
|
||||
{
|
||||
PG_NET_SELECTOR_EDITOR* netEditor = new PG_NET_SELECTOR_EDITOR( m_frame );
|
||||
m_netSelectorEditorInstance = static_cast<PG_NET_SELECTOR_EDITOR*>( wxPropertyGrid::RegisterEditorClass( netEditor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_netSelectorEditorInstance = static_cast<PG_NET_SELECTOR_EDITOR*>( it->second );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -303,5 +392,7 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard )
|
||||
|
||||
auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) );
|
||||
netProperty->SetChoices( nets );
|
||||
m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Net" ) )->SetChoices( nets );
|
||||
|
||||
auto tuningNet = m_propMgr.GetProperty( TYPE_HASH( PCB_TUNING_PATTERN ), _HKI( "Net" ) );
|
||||
tuningNet->SetChoices( nets );
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class PROPERTY_MANAGER;
|
||||
class PG_UNIT_EDITOR;
|
||||
class PG_CHECKBOX_EDITOR;
|
||||
class PG_RATIO_EDITOR;
|
||||
class PG_NET_SELECTOR_EDITOR;
|
||||
|
||||
class PCB_PROPERTIES_PANEL : public PROPERTIES_PANEL
|
||||
{
|
||||
@ -61,6 +62,7 @@ protected:
|
||||
PG_UNIT_EDITOR* m_unitEditorInstance;
|
||||
PG_CHECKBOX_EDITOR* m_checkboxEditorInstance;
|
||||
PG_RATIO_EDITOR* m_ratioEditorInstance;
|
||||
PG_NET_SELECTOR_EDITOR* m_netSelectorEditorInstance;
|
||||
|
||||
wxPGChoices m_nets;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user