KiCad PCB EDA Suite
dialog_sheet_pin_properties.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>
30 #include <kicad_string.h>
31 
32 
33 static wxString sheetPinTypes[] =
34 {
35  _( "Input" ),
36  _( "Output" ),
37  _( "Bidirectional" ),
38  _( "Tri-state" ),
39  _( "Passive" )
40 };
41 
42 
45  m_frame( parent ),
46  m_sheetPin( aPin ),
47  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
48  m_helpWindow( nullptr )
49 {
50  for( const wxString& sheetPinType : sheetPinTypes )
51  m_choiceConnectionType->Append( sheetPinType );
52 
53  m_choiceConnectionType->SetSelection( 0 );
55  m_sdbSizerOK->SetDefault();
56 
57  // Set invalid label characters list:
58  SCH_NETNAME_VALIDATOR validator( true );
59  m_comboName->SetValidator( validator );
60 
61  // Now all widgets have the size fixed, call FinishDialogSettings
63 
64  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
65  * the flex grid sizer in wxGTK that prevents the last column from being sized
66  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
67  * in ugly #ifdef __WXGTK__ #endif.
68  */
69  Layout();
70  Fit();
71  SetMinSize( GetSize() );
72 
73  // On some windows manager (Unity, XFCE), this dialog is
74  // not always raised, depending on this dialog is run.
75  // Force it to be raised
76  Raise();
77 }
78 
79 
81 {
82  if( m_helpWindow )
83  m_helpWindow->Destroy();
84 }
85 
86 
88 {
89  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
90 
91  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
92  {
93  wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
94 
95  if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
96  m_comboName->Append( txt );
97  }
98 
99  m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
100  m_comboName->SelectAll();
101  // Currently, eeschema uses only the text width as text size
102  // (only the text width is saved in files), and expects text width = text height
104  m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
105 
106  return true;
107 }
108 
109 
111 {
112  if( !m_sheetPin->IsNew() )
113  {
114  SCH_SHEET* parentSheet = m_sheetPin->GetParent();
115  m_frame->SaveCopyInUndoList( m_frame->GetScreen(), parentSheet, UNDO_REDO::CHANGED, false );
116  }
117 
119  // Currently, eeschema uses only the text width as text size,
120  // and expects text width = text height
122 
123  auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
124  m_sheetPin->SetShape( shape );
125 
127  m_frame->GetCanvas()->Refresh();
128  m_frame->OnModify();
129 
130  return true;
131 }
132 
133 
134 void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
135 {
136  event.Skip();
137 }
138 
139 
140 void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
141 {
143 }
144 
145 
146 void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
147 {
148  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
149 
150  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
151  {
152  auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
153 
154  if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
155  {
156  m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
157  break;
158  }
159  }
160 }
void OnSyntaxHelp(wxHyperlinkEvent &event) override
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:219
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:237
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:169
Schematic editor (Eeschema) main window.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:285
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
bool IsNew() const
Definition: eda_item.h:168
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void onOKButton(wxCommandEvent &event) override
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
DIALOG_SHEET_PIN_PROPERTIES(SCH_EDIT_FRAME *parent, SCH_SHEET_PIN *aPin)
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.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:85
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...
Class DIALOG_SHEET_PIN_PROPERTIES_BASE.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1535
static wxString sheetPinTypes[]
int GetTextWidth() const
Definition: eda_text.h:248
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:150
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)
Set new value (in Internal Units) for the text field, taking care of units conversion.
EE_RTREE & Items()
Definition: sch_screen.h:162
virtual long long int GetValue()
Return 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...
void onComboBox(wxCommandEvent &event) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:235