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 #include <html_messagebox.h>
30 
31 
32 static wxString sheetPinTypes[] =
33 {
34  _( "Input" ),
35  _( "Output" ),
36  _( "Bidirectional" ),
37  _( "Tri-state" ),
38  _( "Passive" )
39 };
40 
41 
44  m_frame( parent ),
45  m_sheetPin( aPin ),
46  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
47  m_helpWindow( nullptr )
48 {
49  for( const wxString& sheetPinType : sheetPinTypes )
50  m_choiceConnectionType->Append( sheetPinType );
51 
52  m_choiceConnectionType->SetSelection( 0 );
54  m_sdbSizerOK->SetDefault();
55 
56  // Set invalid label characters list:
57  SCH_NETNAME_VALIDATOR validator;
58  m_comboName->SetValidator( validator );
59 
60  // Now all widgets have the size fixed, call FinishDialogSettings
62 
63  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
64  * the flex grid sizer in wxGTK that prevents the last column from being sized
65  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
66  * in ugly #ifdef __WXGTK__ #endif.
67  */
68  Layout();
69  Fit();
70  SetMinSize( GetSize() );
71 
72  // On some windows manager (Unity, XFCE), this dialog is
73  // not always raised, depending on this dialog is run.
74  // Force it to be raised
75  Raise();
76 }
77 
78 
80 {
81  if( m_helpWindow )
82  m_helpWindow->Destroy();
83 }
84 
85 
87 {
88  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
89 
90  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
91  {
92  m_comboName->Append( static_cast<SCH_HIERLABEL*>( item )->GetText() );
93  }
94 
95  m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
96  m_comboName->SelectAll();
97  // Currently, eeschema uses only the text width as text size
98  // (only the text width is saved in files), and expects text width = text height
100  m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
101 
102  return true;
103 }
104 
105 
107 {
108  if( !m_sheetPin->IsNew() )
109  {
110  SCH_SHEET* parentSheet = m_sheetPin->GetParent();
111  m_frame->SaveCopyInUndoList( m_frame->GetScreen(), parentSheet, UNDO_REDO::CHANGED, false );
112  }
113 
115  // Currently, eeschema uses only the text width as text size,
116  // and expects text width = text height
118 
119  auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
120  m_sheetPin->SetShape( shape );
121 
123  m_frame->GetCanvas()->Refresh();
124  m_frame->OnModify();
125 
126  return true;
127 }
128 
129 
130 void DIALOG_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event )
131 {
132  event.Skip();
133 }
134 
135 
136 void DIALOG_EDIT_SHEET_PIN::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
137 {
139 }
140 
141 
142 void DIALOG_EDIT_SHEET_PIN::onComboBox( wxCommandEvent& aEvent )
143 {
144  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
145 
146  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
147  {
148  auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
149 
150  if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
151  {
152  m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
153  break;
154  }
155  }
156 }
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:241
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
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:238
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
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Definitions of control validators for schematic dialogs.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, 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...
HTML_MESSAGE_BOX * m_helpWindow
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1236
int GetTextWidth() const
Definition: eda_text.h:242
#define _(s)
Definition: 3d_actions.cpp:33
void OnSyntaxHelp(wxHyperlinkEvent &event) override
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
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:77
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:158
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:194
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:239