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
21#include <bitmaps.h>
24#include <widgets/font_choice.h>
26#include <sch_edit_frame.h>
27#include <sch_sheet.h>
28#include <sch_sheet_pin.h>
29#include <sch_validators.h>
30#include <sch_commit.h>
31#include <confirm.h>
34#include <string_utils.h>
35#include <gr_text.h>
36
37
40 m_frame( parent ),
41 m_sheetPin( aPin ),
43 m_helpWindow( nullptr )
44{
45 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
46 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
47
48 m_separator1->SetIsSeparator();
49
50 m_bold->SetIsCheckButton();
52 m_italic->SetIsCheckButton();
54
55 m_separator2->SetIsSeparator();
56
57 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
58 m_textColorSwatch->SetSwatchBackground( schematicBackground );
59
62
63 // Set invalid label characters list:
65 m_comboName->SetValidator( validator );
66
67 // Now all widgets have the size fixed, call FinishDialogSettings
69
70 // On some windows manager (Unity, XFCE), this dialog is not always raised, depending on how it is run.
71 Raise();
72}
73
74
80
81
83{
84 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
85
86 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
87 {
88 wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
89
90 if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
91 m_comboName->Append( txt );
92 }
93
94 m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
95 m_comboName->SelectAll();
96 m_fontCtrl->SetFontSelection( m_sheetPin->GetFont() );
97
98 m_bold->Check( m_sheetPin->IsBold() );
99 m_italic->Check( m_sheetPin->IsItalic() );
100
101 // Currently, eeschema uses only the text width as text size
102 // (only the text width is saved in files), and expects text width = text height
103 m_textSize.SetValue( m_sheetPin->GetTextWidth() );
104
105 m_textColorSwatch->SetSwatchColor( m_sheetPin->GetTextColor(), false );
106
107 switch( m_sheetPin->GetShape() )
108 {
109 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
110 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
111 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
112 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
113 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
114 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
115 }
116
117 return true;
118}
119
120
122{
123 wxString name = EscapeString( m_comboName->GetValue(), CTX_NETNAME );
124 wxString visibleName = name;
125
126 visibleName.Trim( false ).Trim( true );
127
128 if( visibleName.IsEmpty() )
129 {
130 DisplayError( this, _( "Sheet pin name can not be empty." ) );
131 return false;
132 }
133
134 SCH_COMMIT commit( m_frame );
135
136 if( !m_sheetPin->IsNew() )
137 commit.Modify( m_sheetPin->GetParent(), m_frame->GetScreen() );
138
139 m_sheetPin->SetText( name );
140
141 if( m_fontCtrl->HaveFontSelection() )
142 {
143 m_sheetPin->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
144 }
145
146 // Currently, eeschema uses only the text width as text size,
147 // and expects text width = text height
148 m_sheetPin->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
149
150 // Must come after SetTextSize()
151 m_sheetPin->SetBold( m_bold->IsChecked() );
152 m_sheetPin->SetItalic( m_italic->IsChecked() );
153
154 m_sheetPin->SetTextColor( m_textColorSwatch->GetSwatchColor() );
155
156 if( m_input->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
157 else if( m_output->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
158 else if( m_bidirectional->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
159 else if( m_triState->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
160 else if( m_passive->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
161
162 if( !commit.Empty() )
163 commit.Push( _( "Edit Sheet Pin Properties" ) );
164
165 return true;
166}
167
168
169void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
170{
171 event.Skip();
172}
173
174
175void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
176{
178}
179
180
181void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
182{
183 SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
184
185 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
186 {
187 SCH_HIERLABEL* hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
188
189 if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
190 {
191 switch( hierLabelItem->GetShape() )
192 {
193 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
194 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
195 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
196 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
197 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
198 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
199 }
200
201 break;
202 }
203 }
204}
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:400
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:145
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
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Push(const wxString &aMessage=wxEmptyString, 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:170
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:178
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
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:516
@ 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:708