KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The 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, see <https://www.gnu.org/licenses/>.
19 */
20
23#include <widgets/font_choice.h>
25#include <sch_edit_frame.h>
26#include <sch_sheet.h>
27#include <sch_sheet_pin.h>
28#include <sch_validators.h>
29#include <sch_commit.h>
32#include <string_utils.h>
33#include <gr_text.h>
34
35
38 m_frame( parent ),
39 m_sheetPin( aPin ),
41 m_helpWindow( nullptr )
42{
43 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
44 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
45
46 m_separator1->SetIsSeparator();
47
48 m_bold->SetIsCheckButton();
50 m_italic->SetIsCheckButton();
52
53 m_separator2->SetIsSeparator();
54
55 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
56 m_textColorSwatch->SetSwatchBackground( schematicBackground );
57
60
61 // Set invalid label characters list:
62 SCH_NETNAME_VALIDATOR validator( true );
63 m_comboName->SetValidator( validator );
64
65 // Now all widgets have the size fixed, call FinishDialogSettings
67
68 // On some windows manager (Unity, XFCE), this dialog is not always raised, depending on how it is run.
69 Raise();
70}
71
72
78
79
81{
82 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
83
84 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
85 {
86 wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
87
88 if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
89 m_comboName->Append( txt );
90 }
91
92 m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
93 m_comboName->SelectAll();
94 m_fontCtrl->SetFontSelection( m_sheetPin->GetFont() );
95
96 m_bold->Check( m_sheetPin->IsBold() );
97 m_italic->Check( m_sheetPin->IsItalic() );
98
99 // Currently, eeschema uses only the text width as text size
100 // (only the text width is saved in files), and expects text width = text height
101 m_textSize.SetValue( m_sheetPin->GetTextWidth() );
102
103 m_textColorSwatch->SetSwatchColor( m_sheetPin->GetTextColor(), false );
104
105 switch( m_sheetPin->GetShape() )
106 {
107 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
108 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
109 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
110 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
111 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
112 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
113 }
114
115 return true;
116}
117
118
120{
121 SCH_COMMIT commit( m_frame );
122
123 if( !m_sheetPin->IsNew() )
124 commit.Modify( m_sheetPin->GetParent(), m_frame->GetScreen() );
125
126 m_sheetPin->SetText( EscapeString( m_comboName->GetValue(), CTX_NETNAME ) );
127
128 if( m_fontCtrl->HaveFontSelection() )
129 {
130 m_sheetPin->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
131 }
132
133 // Currently, eeschema uses only the text width as text size,
134 // and expects text width = text height
135 m_sheetPin->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
136
137 // Must come after SetTextSize()
138 m_sheetPin->SetBold( m_bold->IsChecked() );
139 m_sheetPin->SetItalic( m_italic->IsChecked() );
140
141 m_sheetPin->SetTextColor( m_textColorSwatch->GetSwatchColor() );
142
143 if( m_input->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
144 else if( m_output->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
145 else if( m_bidirectional->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
146 else if( m_triState->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
147 else if( m_passive->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
148
149 if( !commit.Empty() )
150 commit.Push( _( "Edit Sheet Pin Properties" ) );
151
152 return true;
153}
154
155
156void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
157{
158 event.Skip();
159}
160
161
162void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
163{
165}
166
167
168void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
169{
170 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
171
172 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
173 {
174 SCH_HIERLABEL* hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
175
176 if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
177 {
178 switch( hierLabelItem->GetShape() )
179 {
180 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
181 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
182 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
183 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
184 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
185 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
186 }
187
188 break;
189 }
190 }
191}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
bool Empty() const
Definition commit.h:134
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
DIALOG_SHEET_PIN_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Sheet Pin Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_SHEET_PIN_PROPERTIES(SCH_EDIT_FRAME *parent, SCH_SHEET_PIN *aPin)
void onComboBox(wxCommandEvent &event) override
void onOKButton(wxCommandEvent &event) override
void OnSyntaxHelp(wxHyperlinkEvent &event) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:79
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:110
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:178
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
Define a sheet pin (label) used in sheets to create hierarchical schematics.
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:486
@ L_BIDI
Definition sch_label.h:100
@ L_TRISTATE
Definition sch_label.h:101
@ L_UNSPECIFIED
Definition sch_label.h:102
@ L_OUTPUT
Definition sch_label.h:99
@ L_INPUT
Definition sch_label.h:98
Definitions of control validators for schematic dialogs.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
@ SCH_HIER_LABEL_T
Definition typeinfo.h:166
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683