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-2022 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>
35#include <string_utils.h>
36#include <gr_text.h>
37
38
40 SCH_SHEET_PIN* aPin ) :
42 m_frame( parent ),
43 m_sheetPin( aPin ),
44 m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
45 m_helpWindow( nullptr )
46{
47 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
48 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
49
51
53 m_bold->SetBitmap( KiBitmap( BITMAPS::text_bold ) );
55 m_italic->SetBitmap( KiBitmap( BITMAPS::text_italic ) );
56
58
59 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
60 m_textColorSwatch->SetSwatchBackground( schematicBackground );
61
64
65 // Set invalid label characters list:
66 SCH_NETNAME_VALIDATOR validator( true );
67 m_comboName->SetValidator( validator );
68
69 // Now all widgets have the size fixed, call FinishDialogSettings
71
72 /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
73 * the flex grid sizer in wxGTK that prevents the last column from being sized
74 * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
75 * in ugly #ifdef __WXGTK__ #endif.
76 */
77 Layout();
78 Fit();
79 SetMinSize( GetSize() );
80
81 // On some windows manager (Unity, XFCE), this dialog is
82 // not always raised, depending on this dialog is run.
83 // Force it to be raised
84 Raise();
85}
86
87
89{
90 if( m_helpWindow )
91 m_helpWindow->Destroy();
92}
93
94
96{
98
99 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
100 {
101 wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
102
103 if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
104 m_comboName->Append( txt );
105 }
106
107 m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
108 m_comboName->SelectAll();
110
113
114 // Currently, eeschema uses only the text width as text size
115 // (only the text width is saved in files), and expects text width = text height
117
119
120 switch( m_sheetPin->GetShape() )
121 {
122 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
123 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
124 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
125 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
126 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
127 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
128 }
129
130 return true;
131}
132
133
135{
136 if( !m_sheetPin->IsNew() )
137 {
138 SCH_SHEET* parentSheet = m_sheetPin->GetParent();
139 m_frame->SaveCopyInUndoList( m_frame->GetScreen(), parentSheet, UNDO_REDO::CHANGED, false );
140 }
141
143
145 {
147 m_italic->IsChecked() ) );
148 }
149
150 if( m_bold->IsChecked() != m_sheetPin->IsBold() )
151 {
152 if( m_bold->IsChecked() )
153 {
154 m_sheetPin->SetBold( true );
156 }
157 else
158 {
159 m_sheetPin->SetBold( false );
160 m_sheetPin->SetTextThickness( 0 ); // Use default pen width
161 }
162 }
163
165
166 // Currently, eeschema uses only the text width as text size,
167 // and expects text width = text height
169
171
172 if( m_input->GetValue() )
173 m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
174 else if( m_output->GetValue() )
175 m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
176 else if( m_bidirectional->GetValue() )
177 m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
178 else if( m_triState->GetValue() )
179 m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
180 else if( m_passive->GetValue() )
181 m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
182
183 m_frame->UpdateItem( m_sheetPin, false, true );
185 m_frame->OnModify();
186
187 return true;
188}
189
190
191void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
192{
193 event.Skip();
194}
195
196
197void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
198{
200}
201
202
203void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
204{
206
207 for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
208 {
209 SCH_HIERLABEL* hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
210
211 if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
212 {
213 switch( hierLabelItem->GetShape() )
214 {
215 case LABEL_FLAG_SHAPE::L_INPUT: m_input->SetValue( true ); break;
216 case LABEL_FLAG_SHAPE::L_OUTPUT: m_output->SetValue( true ); break;
217 case LABEL_FLAG_SHAPE::L_BIDI: m_bidirectional->SetValue( true ); break;
218 case LABEL_FLAG_SHAPE::L_TRISTATE: m_triState->SetValue( true ); break;
219 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: m_passive->SetValue( true ); break;
220 default: wxFAIL_MSG( wxT( "Unknown sheet pin shape" ) ); break;
221 }
222
223 break;
224 }
225 }
226}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:106
bool IsChecked() const
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
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).
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.
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:97
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 void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
bool IsNew() const
Definition: eda_item.h:103
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:207
COLOR4D GetTextColor() const
Definition: eda_text.h:208
bool IsItalic() const
Definition: eda_text.h:133
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
KIFONT::FONT * GetFont() const
Definition: eda_text.h:191
int GetTextWidth() const
Definition: eda_text.h:202
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:197
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:136
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:359
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:175
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:343
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
bool HaveFontSelection() const
Definition: font_choice.cpp:94
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:73
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void SetShape(LABEL_FLAG_SHAPE aShape) override
Definition: sch_label.h:74
LABEL_FLAG_SHAPE GetShape() const override
Definition: sch_label.h:73
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
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.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:1804
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:380
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:54
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:143
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588