Eeschema sheet pin properties: use combobox

Prepopulate with hierarchical labels within the sheet.
Update connection type to match hierarchical label.
This commit is contained in:
Michael Kavanagh 2020-05-20 18:31:19 +01:00 committed by Jon Evans
parent 14f5ef4078
commit a6ec225f43
5 changed files with 46 additions and 17 deletions

View File

@ -48,12 +48,12 @@ DIALOG_EDIT_SHEET_PIN::DIALOG_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_
m_choiceConnectionType->Append( sheetPinType );
m_choiceConnectionType->SetSelection( 0 );
SetInitialFocus( m_textName );
SetInitialFocus( m_comboName );
m_sdbSizerOK->SetDefault();
// Set invalid label characters list:
SCH_NETNAME_VALIDATOR validator;
m_textName->SetValidator( validator );
m_comboName->SetValidator( validator );
// Now all widgets have the size fixed, call FinishDialogSettings
FinishDialogSettings();
@ -76,8 +76,15 @@ DIALOG_EDIT_SHEET_PIN::DIALOG_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_
bool DIALOG_EDIT_SHEET_PIN::TransferDataToWindow()
{
m_textName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
m_textName->SelectAll();
SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
{
m_comboName->Append( static_cast<SCH_HIERLABEL*>( item )->GetText() );
}
m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
m_comboName->SelectAll();
// Currently, eeschema uses only the text width as text size
// (only the text width is saved in files), and expects text width = text height
m_textSize.SetValue( m_sheetPin->GetTextWidth() );
@ -92,7 +99,7 @@ bool DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow()
if( !m_sheetPin->IsNew() )
m_frame->SaveCopyInUndoList( (SCH_ITEM*) m_sheetPin->GetParent(), UR_CHANGED );
m_sheetPin->SetText( EscapeString( m_textName->GetValue(), CTX_NETNAME ) );
m_sheetPin->SetText( EscapeString( m_comboName->GetValue(), CTX_NETNAME ) );
// Currently, eeschema uses only the text width as text size,
// and expects text width = text height
m_sheetPin->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
@ -118,3 +125,20 @@ void DIALOG_EDIT_SHEET_PIN::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
{
SCH_TEXT::ShowSyntaxHelp( this );
}
void DIALOG_EDIT_SHEET_PIN::onComboBox( wxCommandEvent& aEvent )
{
SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
{
auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
{
m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
break;
}
}
}

View File

@ -49,6 +49,7 @@ public:
private:
void onOKButton( wxCommandEvent& event ) override;
void OnSyntaxHelp( wxHyperlinkEvent& event ) override;
void onComboBox( wxCommandEvent& event ) override;
};
#endif // DIALOG_EDIT_SHEET_PIN_H

View File

@ -29,10 +29,8 @@ DIALOG_EDIT_SHEET_PIN_BASE::DIALOG_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWind
m_staticText1->Wrap( -1 );
fgSizer2->Add( m_staticText1, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 );
m_textName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_textName->SetMinSize( wxSize( 160,-1 ) );
fgSizer2->Add( m_textName, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT, 5 );
m_comboName = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
fgSizer2->Add( m_comboName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT|wxTOP, 5 );
fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 );
@ -103,6 +101,7 @@ DIALOG_EDIT_SHEET_PIN_BASE::DIALOG_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWind
this->Centre( wxBOTH );
// Connect Events
m_comboName->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onComboBox ), NULL, this );
m_hyperlink1->Connect( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::OnSyntaxHelp ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this );
}
@ -110,6 +109,7 @@ DIALOG_EDIT_SHEET_PIN_BASE::DIALOG_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWind
DIALOG_EDIT_SHEET_PIN_BASE::~DIALOG_EDIT_SHEET_PIN_BASE()
{
// Disconnect Events
m_comboName->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onComboBox ), NULL, this );
m_hyperlink1->Disconnect( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::OnSyntaxHelp ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this );

View File

@ -146,9 +146,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT|wxTOP</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<object class="wxComboBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -162,6 +162,7 @@
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices"></property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
@ -179,12 +180,11 @@
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">160,-1</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_textName</property>
<property name="name">m_comboName</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -192,10 +192,11 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">-1</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
@ -206,6 +207,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnCombobox">onComboBox</event>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -17,10 +17,11 @@
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/combobox.h>
#include <wx/hyperlink.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/textctrl.h>
#include <wx/choice.h>
#include <wx/button.h>
#include <wx/dialog.h>
@ -37,7 +38,7 @@ class DIALOG_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM
protected:
wxStaticText* m_staticText1;
wxTextCtrl* m_textName;
wxComboBox* m_comboName;
wxHyperlinkCtrl* m_hyperlink1;
wxStaticLine* m_staticline3;
wxStaticText* m_textSizeLabel;
@ -51,6 +52,7 @@ class DIALOG_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void onComboBox( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSyntaxHelp( wxHyperlinkEvent& event ) { event.Skip(); }
virtual void onOKButton( wxCommandEvent& event ) { event.Skip(); }