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_textWidth( parent, m_widthLabel, m_widthCtrl, m_widthUnits, true ),
46  m_textHeight( parent, m_heightLabel, m_heightCtrl, m_heightUnits, true )
47 {
48  for( const wxString& sheetPinType : sheetPinTypes )
49  m_choiceConnectionType->Append( sheetPinType );
50 
51  m_choiceConnectionType->SetSelection( 0 );
52  m_textName->SetFocus();
53  m_sdbSizerOK->SetDefault();
54 
55  // Set invalid label characters list:
56  SCH_NETNAME_VALIDATOR validator;
57  m_textName->SetValidator( validator );
58 
59  // Now all widgets have the size fixed, call FinishDialogSettings
61 
62  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
63  * the flex grid sizer in wxGTK that prevents the last column from being sized
64  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
65  * in ugly #ifdef __WXGTK__ #endif.
66  */
67  Layout();
68  Fit();
69  SetMinSize( GetSize() );
70 
71  // On some windows manager (Unity, XFCE), this dialog is
72  // not always raised, depending on this dialog is run.
73  // Force it to be raised
74  Raise();
75 }
76 
77 
79 {
80  m_textName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
81  m_textName->SelectAll();
84  m_choiceConnectionType->SetSelection( m_sheetPin->GetShape() );
85 
86  return true;
87 }
88 
89 
91 {
92  if( !m_sheetPin->IsNew() )
94 
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_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event )
110 {
111  event.Skip();
112 }
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:128
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:158
void onOKButton(wxCommandEvent &event) override
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
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:222
DIALOG_EDIT_SHEET_PIN(SCH_EDIT_FRAME *parent, SCH_SHEET_PIN *aPin)
bool IsNew() const
Definition: base_struct.h:228
int GetTextHeight() const
Definition: eda_text.h:229
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
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_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:75
#define _(s)
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:226
void RefreshItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
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...
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.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:126