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 (C) 2018-2023 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
27#include <widgets/font_choice.h>
29#include <sch_edit_frame.h>
30#include <sch_sheet.h>
31#include <sch_sheet_pin.h>
32#include <sch_validators.h>
33#include <sch_commit.h>
36#include <string_utils.h>
37#include <gr_text.h>
38
39
41 SCH_SHEET_PIN* aPin ) :
43 m_frame( parent ),
44 m_sheetPin( aPin ),
45 m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
46 m_helpWindow( nullptr )
47{
48 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
49 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
50
52
54 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
56 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
57
59
60 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
61 m_textColorSwatch->SetSwatchBackground( schematicBackground );
62
65
66 // Set invalid label characters list:
67 SCH_NETNAME_VALIDATOR validator( true );
68 m_comboName->SetValidator( validator );
69
70 // Now all widgets have the size fixed, call FinishDialogSettings
72
73 /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
74 * the flex grid sizer in wxGTK that prevents the last column from being sized
75 * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
76 * in ugly #ifdef __WXGTK__ #endif.
77 */
78 Layout();
79 Fit();
80 SetMinSize( GetSize() );
81
82 // On some windows manager (Unity, XFCE), this dialog is
83 // not always raised, depending on this dialog is run.
84 // Force it to be raised
85 Raise();
86}
87
88
90{
91 if( m_helpWindow )
92 m_helpWindow->Destroy();
93}
94
95
97{
99
100 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
101 {
102 wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
103
104 if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
105 m_comboName->Append( txt );
106 }
107
108 m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
109 m_comboName->SelectAll();
111
114
115 // Currently, eeschema uses only the text width as text size
116 // (only the text width is saved in files), and expects text width = text height
118
120
121 switch( m_sheetPin->GetShape() )
122 {
123 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
124 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
125 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
126 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
127 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
128 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
129 }
130
131 return true;
132}
133
134
136{
137 SCH_COMMIT commit( m_frame );
138
139 if( !m_sheetPin->IsNew() )
141
143
145 {
147 m_italic->IsChecked() ) );
148 }
149
150 // Currently, eeschema uses only the text width as text size,
151 // and expects text width = text height
153
154 // Must come after SetTextSize()
157
159
160 if( m_input->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
161 else if( m_output->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
162 else if( m_bidirectional->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
163 else if( m_triState->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
164 else if( m_passive->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
165
166 if( !commit.Empty() )
167 commit.Push( _( "Edit Sheet Pin Properties" ) );
168
169 return true;
170}
171
172
173void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
174{
175 event.Skip();
176}
177
178
179void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
180{
182}
183
184
185void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
186{
188
189 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
190 {
191 SCH_HIERLABEL* hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
192
193 if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
194 {
195 switch( hierLabelItem->GetShape() )
196 {
197 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
198 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
199 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
200 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
201 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
202 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
203 }
204
205 break;
206 }
207 }
208}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
bool IsChecked() const
void Check(bool aCheck=true)
Check the control.
void SetIsSeparator()
Render button as a toolbar separator.
void SetIsCheckButton()
Setup the control as a two-state button (checked or unchecked).
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
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
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
bool Empty() const
Returns status of an item.
Definition: commit.h:144
Class DIALOG_SHEET_PIN_PROPERTIES_BASE.
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:102
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...
bool IsNew() const
Definition: eda_item.h:107
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:253
COLOR4D GetTextColor() const
Definition: eda_text.h:254
bool IsItalic() const
Definition: eda_text.h:156
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:506
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
int GetTextWidth() const
Definition: eda_text.h:248
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition: eda_text.cpp:327
bool IsBold() const
Definition: eda_text.h:171
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:269
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:299
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:490
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic, bool aForDrawingSheet=false) const
bool HaveFontSelection() const
Definition: font_choice.cpp:94
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:432
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_label.h:178
LABEL_FLAG_SHAPE GetShape() const
Definition: sch_label.h:177
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:2156
int GetIntValue()
Definition: unit_binder.h:129
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:391
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
Definition: string_utils.h:53
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691