KiCad PCB EDA Suite
dialog_edit_sheet_pin.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) 2010 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <sch_edit_frame.h>
26 #include <sch_sheet.h>
27 #include <sch_validators.h>
28 #include <dialog_edit_sheet_pin.h>
29 
30 
31 static wxString sheetPinTypes[] =
32 {
33  _( "Input" ),
34  _( "Output" ),
35  _( "Bidirectional" ),
36  _( "Tri-state" ),
37  _( "Passive" )
38 };
39 
40 
43  m_frame( parent ),
44  m_sheetPin( aPin ),
45  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
46 {
47  for( const wxString& sheetPinType : sheetPinTypes )
48  m_choiceConnectionType->Append( sheetPinType );
49 
50  m_choiceConnectionType->SetSelection( 0 );
52  m_sdbSizerOK->SetDefault();
53 
54  // Set invalid label characters list:
55  SCH_NETNAME_VALIDATOR validator;
56  m_comboName->SetValidator( validator );
57 
58  // Now all widgets have the size fixed, call FinishDialogSettings
60 
61  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
62  * the flex grid sizer in wxGTK that prevents the last column from being sized
63  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
64  * in ugly #ifdef __WXGTK__ #endif.
65  */
66  Layout();
67  Fit();
68  SetMinSize( GetSize() );
69 
70  // On some windows manager (Unity, XFCE), this dialog is
71  // not always raised, depending on this dialog is run.
72  // Force it to be raised
73  Raise();
74 }
75 
76 
78 {
79  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
80 
81  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
82  {
83  m_comboName->Append( static_cast<SCH_HIERLABEL*>( item )->GetText() );
84  }
85 
86  m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
87  m_comboName->SelectAll();
88  // Currently, eeschema uses only the text width as text size
89  // (only the text width is saved in files), and expects text width = text height
91  m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
92 
93  return true;
94 }
95 
96 
98 {
99  if( !m_sheetPin->IsNew() )
101 
103  // Currently, eeschema uses only the text width as text size,
104  // and expects text width = text height
106 
107  auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
108  m_sheetPin->SetShape( shape );
109 
111  m_frame->GetCanvas()->Refresh();
112  m_frame->OnModify();
113 
114  return true;
115 }
116 
117 
118 void DIALOG_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event )
119 {
120  event.Skip();
121 }
122 
123 
124 void DIALOG_EDIT_SHEET_PIN::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
125 {
126  SCH_TEXT::ShowSyntaxHelp( this );
127 }
128 
129 
130 void DIALOG_EDIT_SHEET_PIN::onComboBox( wxCommandEvent& aEvent )
131 {
132  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
133 
134  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
135  {
136  auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
137 
138  if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
139  {
140  m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
141  break;
142  }
143  }
144 }
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:239
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:168
void onOKButton(wxCommandEvent &event) override
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Schematic editor (Eeschema) main window.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
static void ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1281
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
DIALOG_EDIT_SHEET_PIN(SCH_EDIT_FRAME *parent, SCH_SHEET_PIN *aPin)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
bool IsNew() const
Definition: base_struct.h:199
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
Definitions of control validators for schematic dialogs.
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int GetTextWidth() const
Definition: eda_text.h:241
void RefreshItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
#define _(s)
Definition: 3d_actions.cpp:33
void OnSyntaxHelp(wxHyperlinkEvent &event) override
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
void onComboBox(wxCommandEvent &event) override
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
Definition: string.cpp:50
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
EE_RTREE & Items()
Definition: sch_screen.h:162
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
static wxString sheetPinTypes[]
Class DIALOG_EDIT_SHEET_PIN_BASE.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:237