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@gmail.com>
5  * Copyright (C) 2018-2021 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_sheet_pin.h>
28 #include <sch_validators.h>
31 #include <string_utils.h>
32 
33 
34 static wxString sheetPinTypes[] =
35 {
36  _( "Input" ),
37  _( "Output" ),
38  _( "Bidirectional" ),
39  _( "Tri-state" ),
40  _( "Passive" )
41 };
42 
43 
45  SCH_SHEET_PIN* aPin ) :
47  m_frame( parent ),
48  m_sheetPin( aPin ),
49  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
50  m_helpWindow( nullptr )
51 {
52  for( const wxString& sheetPinType : sheetPinTypes )
53  m_choiceConnectionType->Append( sheetPinType );
54 
55  m_choiceConnectionType->SetSelection( 0 );
57  m_sdbSizerOK->SetDefault();
58 
59  // Set invalid label characters list:
60  SCH_NETNAME_VALIDATOR validator( true );
61  m_comboName->SetValidator( validator );
62 
63  // Now all widgets have the size fixed, call FinishDialogSettings
65 
66  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
67  * the flex grid sizer in wxGTK that prevents the last column from being sized
68  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
69  * in ugly #ifdef __WXGTK__ #endif.
70  */
71  Layout();
72  Fit();
73  SetMinSize( GetSize() );
74 
75  // On some windows manager (Unity, XFCE), this dialog is
76  // not always raised, depending on this dialog is run.
77  // Force it to be raised
78  Raise();
79 }
80 
81 
83 {
84  if( m_helpWindow )
85  m_helpWindow->Destroy();
86 }
87 
88 
90 {
91  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
92 
93  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
94  {
95  wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
96 
97  if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
98  m_comboName->Append( txt );
99  }
100 
101  m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
102  m_comboName->SelectAll();
103  // Currently, eeschema uses only the text width as text size
104  // (only the text width is saved in files), and expects text width = text height
106  m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
107 
108  return true;
109 }
110 
111 
113 {
114  if( !m_sheetPin->IsNew() )
115  {
116  SCH_SHEET* parentSheet = m_sheetPin->GetParent();
117  m_frame->SaveCopyInUndoList( m_frame->GetScreen(), parentSheet, UNDO_REDO::CHANGED, false );
118  }
119 
121  // Currently, eeschema uses only the text width as text size,
122  // and expects text width = text height
124 
125  auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
126  m_sheetPin->SetShape( shape );
127 
128  m_frame->UpdateItem( m_sheetPin, false, true );
129  m_frame->GetCanvas()->Refresh();
130  m_frame->OnModify();
131 
132  return true;
133 }
134 
135 
136 void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
137 {
138  event.Skip();
139 }
140 
141 
142 void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
143 {
145 }
146 
147 
148 void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
149 {
150  SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
151 
152  for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
153  {
154  auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
155 
156  if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
157  {
158  m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
159  break;
160  }
161  }
162 }
void OnSyntaxHelp(wxHyperlinkEvent &event) override
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:216
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:163
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Schematic editor (Eeschema) main window.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
bool IsNew() const
Definition: eda_item.h:119
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:114
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 _(s)
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
wxString UnescapeString(const wxString &aSource)
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:54
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:1718
static wxString sheetPinTypes[]
int GetTextWidth() const
Definition: eda_text.h:241
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.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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...
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
void onComboBox(wxCommandEvent &event) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
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:161