KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_lib_textbox_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) 2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <symbol_edit_frame.h>
27#include <widgets/font_choice.h>
29#include <base_units.h>
30#include <general.h>
32#include <lib_textbox.h>
33#include <confirm.h>
35#include <string_utils.h>
36#include <scintilla_tricks.h>
39#include <gr_text.h>
40
42 LIB_TEXTBOX* aTextBox ) :
44 m_frame( aParent ),
45 m_currentText( aTextBox ),
46 m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
47 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
48 m_scintillaTricks( nullptr ),
49 m_helpWindow( nullptr )
50{
51 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
52 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
53
54 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
55 m_borderColorSwatch->SetSwatchBackground( schematicBackground );
56
57 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
58 m_borderStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
59
61
62 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
63 m_fillColorSwatch->SetSwatchBackground( schematicBackground );
64
65 m_textCtrl->SetEOLMode( wxSTC_EOL_LF );
66
67 m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
68 [this]()
69 {
70 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
71 } );
72
73 m_textEntrySizer->AddGrowableRow( 0 );
74
75 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
76 m_textColorSwatch->SetSwatchBackground( schematicBackground );
77
79
81
83 m_bold->SetBitmap( KiBitmap( BITMAPS::text_bold ) );
85 m_italic->SetBitmap( KiBitmap( BITMAPS::text_italic ) );
86
88
90 m_hAlignLeft->SetBitmap( KiBitmap( BITMAPS::text_align_left ) );
92 m_hAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_align_center ) );
94 m_hAlignRight->SetBitmap( KiBitmap( BITMAPS::text_align_right ) );
96
98 m_vAlignTop->SetBitmap( KiBitmap( BITMAPS::text_valign_top ) );
100 m_vAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_valign_center ) );
102 m_vAlignBottom->SetBitmap( KiBitmap( BITMAPS::text_valign_bottom ) );
103
105
107 m_horizontal->SetBitmap( KiBitmap( BITMAPS::text_horizontal ) );
109 m_vertical->SetBitmap( KiBitmap( BITMAPS::text_vertical ) );
110
112
114 Layout();
115
124
125 // Now all widgets have the size fixed, call FinishDialogSettings
127}
128
129
131{
132 delete m_scintillaTricks;
133
134 if( m_helpWindow )
135 m_helpWindow->Destroy();
136}
137
138
140{
141 if( !wxDialog::TransferDataToWindow() )
142 return false;
143
145
146 m_textCtrl->SetValue( m_currentText->GetText() );
147 m_textCtrl->EmptyUndoBuffer();
148
152
155
156 switch( m_currentText->GetHorizJustify() )
157 {
161 }
162
163 switch( m_currentText->GetVertJustify() )
164 {
165 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
168 }
169
171 m_vertical->Check();
172 else
174
175 if( m_currentText->GetWidth() >= 0 )
176 {
177 m_borderCheckbox->SetValue( true );
179 }
180 else
181 {
182 m_borderCheckbox->SetValue( false );
183
184 m_borderWidth.Enable( false );
185 m_borderColorLabel->Enable( false );
186 m_borderColorSwatch->Enable( false );
187 m_borderStyleLabel->Enable( false );
188 m_borderStyleCombo->Enable( false );
189 }
190
192
193 int style = static_cast<int>( m_currentText->GetStroke().GetPlotStyle() );
194
195 if( style == -1 )
196 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
197 else if( style < (int) lineTypeNames.size() )
198 m_borderStyleCombo->SetSelection( style );
199 else
200 wxFAIL_MSG( "Line type not found in the type lookup map" );
201
202 m_filledCtrl->SetValue( m_currentText->IsFilled() );
204
207
209 m_CommonUnit->SetValue(
210 symbol && symbol->GetUnitCount() > 1 && m_currentText->GetUnit() == 0 );
211 m_CommonUnit->Enable( symbol && symbol->GetUnitCount() > 1 );
212 m_CommonConvert->SetValue( m_currentText->GetConvert() == 0 );
213
214 return true;
215}
216
217
219{
221 {
222 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
223 btn->Check( false );
224 }
225}
226
227
229{
231 {
232 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
233 btn->Check( false );
234 }
235}
236
237
239{
240 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
241 {
242 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
243 btn->Check( false );
244 }
245}
246
247
249{
250 if( !wxDialog::TransferDataFromWindow() )
251 return false;
252
253 wxString text = m_textCtrl->GetValue();
254
255#ifdef __WXMAC__
256 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
257 text.Replace( wxS( "\r" ), wxS( "\n" ) );
258#elif defined( __WINDOWS__ )
259 // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
260 // drawing routines so strip the \r char.
261 text.Replace( wxS( "\r" ), wxS( "" ) );
262#endif
263
265
268
270 {
272 m_italic->IsChecked() ) );
273 }
274
275 if( m_bold->IsChecked() != m_currentText->IsBold() )
276 {
277 if( m_bold->IsChecked() )
278 {
279 m_currentText->SetBold( true );
281 }
282 else
283 {
284 m_currentText->SetBold( false );
285 m_currentText->SetTextThickness( 0 ); // Use default pen width
286 }
287 }
288
291
292 if( m_hAlignRight->IsChecked() )
294 else if( m_hAlignCenter->IsChecked() )
296 else
298
301 else if( m_vAlignCenter->IsChecked() )
303 else
305
306 if( m_vertical->IsChecked() )
308 else
310
312
313 if( m_borderCheckbox->GetValue() )
314 stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
315 else
316 stroke.SetWidth( -1 );
317
318 auto it = lineTypeNames.begin();
319 std::advance( it, m_borderStyleCombo->GetSelection() );
320
321 if( it == lineTypeNames.end() )
322 stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
323 else
324 stroke.SetPlotStyle( it->first );
325
327
328 m_currentText->SetStroke( stroke );
329
330 m_currentText->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR
331 : FILL_T::NO_FILL );
333
335
336 if( !m_CommonUnit->GetValue() )
338 else
340
341 if( !m_CommonConvert->GetValue() )
343 else
345
346 // Record settings used for next time:
348 tools->SetLastTextAngle( m_currentText->GetTextAngle() );
349 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
350 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
351
353
354 return true;
355}
356
357
359{
361}
362
363
365{
368
369 event.Skip();
370}
371
372
374{
375 bool border = m_borderCheckbox->GetValue();
376
377 if( border && m_borderWidth.GetValue() < 0 )
379
380 m_borderWidth.Enable( border );
381 m_borderColorLabel->Enable( border );
382 m_borderColorSwatch->Enable( border );
383 m_borderStyleLabel->Enable( border );
384 m_borderStyleCombo->Enable( border );
385}
386
387
389{
390 bool fill = m_filledCtrl->GetValue();
391
392 m_fillColorLabel->Enable( fill );
393 m_fillColorSwatch->Enable( fill );
394}
395
396
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
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
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void SetIsRadioButton()
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_LIB_TEXTBOX_PROPERTIES_BASE.
DIALOG_LIB_TEXTBOX_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_TEXTBOX *aTextBox)
void OnFormattingHelp(wxHyperlinkEvent &aEvent) override
void onBorderChecked(wxCommandEvent &event) override
void onVAlignButton(wxCommandEvent &aEvent)
void onFillChecked(wxCommandEvent &event) override
void onHAlignButton(wxCommandEvent &aEvent)
void onTextAngleButton(wxCommandEvent &aEvent)
void onMultiLineTCLostFocus(wxFocusEvent &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...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool IsFilled() const
Definition: eda_shape.h:90
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
int GetWidth() const
Definition: eda_shape.h:109
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
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
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:123
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 SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:260
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:152
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
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:155
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:359
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:175
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:343
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:252
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
bool IsPrivate() const
Definition: lib_item.h:299
int GetUnit() const
Definition: lib_item.h:293
void SetPrivate(bool aPrivate)
Definition: lib_item.h:298
int GetConvert() const
Definition: lib_item.h:296
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:188
void SetConvert(int aConvert)
Definition: lib_item.h:295
void SetUnit(int aUnit)
Definition: lib_item.h:292
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
Define a library symbol object.
Definition: lib_symbol.h:99
int GetUnitCount() const override
For items with units, return the number of units.
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:1804
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
void SetWidth(int aWidth)
Definition: stroke_params.h:99
void SetColor(const KIGFX::COLOR4D &aColor)
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
SYMBOL_EDITOR_DRAWING_TOOLS.
The symbol library editor main window.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
This file is part of the common library.
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:425
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:426
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:380
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588