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>
30#include <confirm.h>
33#include <string_utils.h>
34#include <gr_text.h>
35
36
39 m_frame( parent ),
40 m_sheetPin( aPin ),
42 m_helpWindow( nullptr )
43{
44 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
45 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
46
47 m_separator1->SetIsSeparator();
48
49 m_bold->SetIsCheckButton();
51 m_italic->SetIsCheckButton();
53
54 m_separator2->SetIsSeparator();
55
56 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
57 m_textColorSwatch->SetSwatchBackground( schematicBackground );
58
61
62 // Set invalid label characters list:
64 m_comboName->SetValidator( validator );
65
66 // Now all widgets have the size fixed, call FinishDialogSettings
68
69 // On some windows manager (Unity, XFCE), this dialog is not always raised, depending on how it is run.
70 Raise();
71}
72
73
79
80
82{
83 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
84
85 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
86 {
87 wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
88
89 if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
90 m_comboName->Append( txt );
91 }
92
93 m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
94 m_comboName->SelectAll();
95 m_fontCtrl->SetFontSelection( m_sheetPin->GetFont() );
96
97 m_bold->Check( m_sheetPin->IsBold() );
98 m_italic->Check( m_sheetPin->IsItalic() );
99
100 // Currently, eeschema uses only the text width as text size
101 // (only the text width is saved in files), and expects text width = text height
102 m_textSize.SetValue( m_sheetPin->GetTextWidth() );
103
104 m_textColorSwatch->SetSwatchColor( m_sheetPin->GetTextColor(), false );
105
106 switch( m_sheetPin->GetShape() )
107 {
108 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
109 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
110 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
111 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
112 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
113 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
114 }
115
116 return true;
117}
118
119
121{
122 wxString name = EscapeString( m_comboName->GetValue(), CTX_NETNAME );
123 wxString visibleName = name;
124
125 visibleName.Trim( false ).Trim( true );
126
127 if( visibleName.IsEmpty() )
128 {
129 DisplayError( this, _( "Sheet pin name can not be empty." ) );
130 return false;
131 }
132
133 SCH_COMMIT commit( m_frame );
134
135 if( !m_sheetPin->IsNew() )
136 commit.Modify( m_sheetPin->GetParent(), m_frame->GetScreen() );
137
138 m_sheetPin->SetText( name );
139
140 if( m_fontCtrl->HaveFontSelection() )
141 {
142 m_sheetPin->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
143 }
144
145 // Currently, eeschema uses only the text width as text size,
146 // and expects text width = text height
147 m_sheetPin->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
148
149 // Must come after SetTextSize()
150 m_sheetPin->SetBold( m_bold->IsChecked() );
151 m_sheetPin->SetItalic( m_italic->IsChecked() );
152
153 m_sheetPin->SetTextColor( m_textColorSwatch->GetSwatchColor() );
154
155 if( m_input->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
156 else if( m_output->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
157 else if( m_bidirectional->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
158 else if( m_triState->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
159 else if( m_passive->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
160
161 if( !commit.Empty() )
162 commit.Push( _( "Edit Sheet Pin Properties" ) );
163
164 return true;
165}
166
167
168void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
169{
170 event.Skip();
171}
172
173
174void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
175{
177}
178
179
180void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
181{
182 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
183
184 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
185 {
186 SCH_HIERLABEL* hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
187
188 if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
189 {
190 switch( hierLabelItem->GetShape() )
191 {
192 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
193 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
194 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
195 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
196 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
197 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
198 }
199
200 break;
201 }
202 }
203}
const char * name
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:399
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:142
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:94
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:118
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
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:165
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:178
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
Define a sheet pin (label) used in sheets to create hierarchical schematics.
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:510
@ 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
JSON_SCHEMA_VALIDATOR validator(schema)
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683