KiCad PCB EDA Suite
dialog_sch_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 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>
27 
28 
29 static wxString sheetPinTypes[] =
30 {
31  _( "Input" ),
32  _( "Output" ),
33  _( "Bidirectional" ),
34  _( "Tri-state" ),
35  _( "Passive" )
36 };
37 
38 
41  m_frame( parent ),
42  m_sheetPin( aPin ),
43  m_textWidth( parent, m_widthLabel, m_widthCtrl, m_widthUnits, true ),
44  m_textHeight( parent, m_heightLabel, m_heightCtrl, m_heightUnits, true )
45 {
46  for( const wxString& sheetPinType : sheetPinTypes )
47  m_choiceConnectionType->Append( sheetPinType );
48 
49  m_choiceConnectionType->SetSelection( 0 );
50  m_textName->SetFocus();
51  m_sdbSizerOK->SetDefault();
52 
53  // Set invalid label characters list:
54  wxTextValidator* validator = static_cast<wxTextValidator*>( m_textName->GetValidator() );
55  validator->SetCharExcludes( " /" );
56 
57  // Now all widgets have the size fixed, call FinishDialogSettings
59 
60  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
61  * the flex grid sizer in wxGTK that prevents the last column from being sized
62  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
63  * in ugly #ifdef __WXGTK__ #endif.
64  */
65  Layout();
66  Fit();
67  SetMinSize( GetSize() );
68 
69  // On some windows manager (Unity, XFCE), this dialog is
70  // not always raised, depending on this dialog is run.
71  // Force it to be raised
72  Raise();
73 }
74 
75 
77 {
78  m_textName->SetValue( m_sheetPin->GetText() );
81  m_choiceConnectionType->SetSelection( m_sheetPin->GetShape() );
82 
83  return true;
84 }
85 
86 
88 {
89  if( !m_sheetPin->IsNew() )
90  {
92  m_frame->GetScreen()->SetCurItem( nullptr );
93  }
94 
95  m_sheetPin->SetText( m_textName->GetValue() );
97 
98  auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
99  m_sheetPin->SetShape( shape );
100 
102  m_frame->GetCanvas()->Refresh();
103  m_frame->OnModify();
104 
105  return true;
106 }
107 
108 
109 void DIALOG_SCH_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event )
110 {
111  // Disable wxWidgets message if a pin name has not allowed chars
112  // (It happens only when editing a old sheet pin name that can contains not allowed chars)
113  wxTextValidator* validator = static_cast<wxTextValidator*>( m_textName->GetValidator() );
114  validator->SetCharExcludes( "" );
115 
116  event.Skip();
117 }
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:118
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:120
void onOKButton(wxCommandEvent &event) override
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:159
DIALOG_SCH_EDIT_SHEET_PIN(SCH_EDIT_FRAME *parent, SCH_SHEET_PIN *aPin)
bool IsNew() const
Definition: base_struct.h:219
static wxString sheetPinTypes[]
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
int GetTextWidth() const
Definition: eda_text.h:231
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SCH_EDIT_SHEET_PIN_BASE.
Schematic editor (Eeschema) main window.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
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...
Subclass of DIALOG_SCH_EDIT_SHEET_PIN_BASE, which is generated by wxFormBuilder.
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
SCH_DRAW_PANEL * GetCanvas() const override
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:61
PINSHEETLABEL_SHAPE
Definition: sch_text.h:46
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:204
int GetTextHeight() const
Definition: eda_text.h:234
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154