KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
eeschema/dialogs/dialog_tablecell_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 The 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 <gr_text.h>
25#include <sch_edit_frame.h>
28#include <widgets/font_choice.h>
30#include <sch_table.h>
31#include <sch_commit.h>
32#include <tool/tool_manager.h>
34
36 std::vector<SCH_TABLECELL*> aCells ) :
37 DIALOG_TABLECELL_PROPERTIES_BASE( aFrame ), m_frame( aFrame ), m_table( nullptr ),
38 m_cells( std::move( aCells ) ),
39 m_scintillaTricks( nullptr ),
40 m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
41 m_marginLeft( aFrame, nullptr, m_marginLeftCtrl, nullptr ),
42 m_marginTop( aFrame, nullptr, m_marginTopCtrl, m_marginTopUnits ),
43 m_marginRight( aFrame, nullptr, m_marginRightCtrl, nullptr ),
44 m_marginBottom( aFrame, nullptr, m_marginBottomCtrl, nullptr ),
45 m_cellText( m_cellTextCtrl ),
46 m_returnValue( TABLECELL_PROPS_CANCEL )
47{
48 wxASSERT( m_cells.size() > 0 && m_cells[0] );
49
50 m_cellText->SetEOLMode( wxSTC_EOL_LF );
51
52#ifdef _WIN32
53 // Without this setting, on Windows, some esoteric unicode chars create display issue
54 // in a wxStyledTextCtrl.
55 // for SetTechnology() info, see https://www.scintilla.org/ScintillaDoc.html#SCI_SETTECHNOLOGY
56 m_cellText->SetTechnology( wxSTC_TECHNOLOGY_DIRECTWRITE );
57#endif
58
60 m_cellText, wxT( "{}" ), false,
61 // onAcceptFn
62 [this]( wxKeyEvent& aEvent )
63 {
64 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
65 },
66
67 // onCharFn
68 [this]( wxStyledTextEvent& aEvent )
69 {
71 // getTokensFn
72 [this]( const wxString& xRef, wxArrayString* tokens )
73 {
74 getContextualTextVars( xRef, tokens );
75 } );
76 } );
77
79
80 m_table = static_cast<SCH_TABLE*>( m_cells[0]->GetParent() );
81
83 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
84
86 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
88 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
90 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
91
93 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
95 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
97 m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
98
102
104 Layout();
105
106 m_hAlignLeft->Bind( wxEVT_BUTTON, &DIALOG_TABLECELL_PROPERTIES::onHAlignButton, this );
109 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_TABLECELL_PROPERTIES::onVAlignButton, this );
112
113 // Now all widgets have the size fixed, call FinishDialogSettings
115}
116
118{
119 delete m_scintillaTricks;
120}
121
123 wxArrayString* aTokens )
124{
125 SCHEMATIC* schematic = m_table->Schematic();
126
127 if( !aCrossRef.IsEmpty() )
128 {
129 SCH_SYMBOL* refSymbol = nullptr;
130
131 if( schematic )
132 {
134 schematic->Hierarchy().GetSymbols( refs );
135
136 for( int jj = 0; jj < (int) refs.GetCount(); jj++ )
137 {
138 SCH_REFERENCE& ref = refs[jj];
139
140 if( ref.GetSymbol()->GetRef( &ref.GetSheetPath(), true ) == aCrossRef )
141 {
142 refSymbol = ref.GetSymbol();
143 break;
144 }
145 }
146 }
147
148 if( refSymbol )
149 refSymbol->GetContextualTextVars( aTokens );
150 }
151 else
152 {
153 if( schematic && schematic->CurrentSheet().Last() )
154 {
155 schematic->CurrentSheet().Last()->GetContextualTextVars( aTokens );
156 }
157 else
158 {
159 for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
160 aTokens->push_back( entry.first );
161 }
162 }
163}
164
165
167{
168 if( !wxDialog::TransferDataToWindow() )
169 return false;
170
171 bool firstCell = true;
174
175 for( SCH_TABLECELL* cell : m_cells )
176 {
177 wxString text = cell->GetText();
178
179 m_cellText->SetValue( text );
180 m_cellText->EmptyUndoBuffer();
181
182 if( firstCell )
183 {
184 m_fontCtrl->SetFontSelection( cell->GetFont() );
185 m_textSize.SetValue( cell->GetTextWidth() );
186
187 m_bold->Set3StateValue( cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
188 m_italic->Set3StateValue( cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
189
190 hAlign = cell->GetHorizJustify();
191 vAlign = cell->GetVertJustify();
192
193 m_textColorBook->SetSelection( 1 );
194 m_textColorSwatch->SetSwatchColor( cell->GetTextColor(), false );
195 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
196
197 m_fillColorBook->SetSelection( 1 );
198
199 if( cell->IsSolidFill() )
200 m_fillColorSwatch->SetSwatchColor( cell->GetFillColor(), false );
201 else
202 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
203
204 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
205
206 m_marginLeft.SetValue( cell->GetMarginLeft() );
207 m_marginTop.SetValue( cell->GetMarginTop() );
208 m_marginRight.SetValue( cell->GetMarginRight() );
209 m_marginBottom.SetValue( cell->GetMarginBottom() );
210
211 firstCell = false;
212 }
213 else
214 {
215 if( cell->GetFont() != m_fontCtrl->GetFontSelection( cell->IsBold(),
216 cell->IsItalic() ) )
217 m_fontCtrl->SetSelection( -1 );
218
219 if( cell->GetTextWidth() != m_textSize.GetValue() )
221
222 wxCheckBoxState bold = cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
223
224 if( bold != m_bold->Get3StateValue() )
225 m_bold->Set3StateValue( wxCHK_UNDETERMINED );
226
227 wxCheckBoxState italic = cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
228
229 if( italic != m_italic->Get3StateValue() )
230 m_italic->Set3StateValue( wxCHK_UNDETERMINED );
231
232 if( cell->GetHorizJustify() != hAlign )
234
235 if( cell->GetVertJustify() != vAlign )
237
238 if( cell->GetTextColor() != m_textColorSwatch->GetSwatchColor() )
239 {
240 m_textColorBook->SetSelection( 0 );
241 m_textColorPopup->SetSelection( 0 );
242 }
243
244 COLOR4D fillColor = cell->IsSolidFill() ? cell->GetFillColor() : COLOR4D::UNSPECIFIED;
245
246 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
247 {
248 m_fillColorBook->SetSelection( 0 );
249 m_fillColorPopup->SetSelection( 0 );
250 }
251
252 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
253 fillColor = COLOR4D::UNSPECIFIED;
254
255 if( cell->GetMarginLeft() != m_marginLeft.GetIntValue() )
257
258 if( cell->GetMarginTop() != m_marginTop.GetIntValue() )
260
261 if( cell->GetMarginRight() != m_marginRight.GetIntValue() )
263
264 if( cell->GetMarginBottom() != m_marginBottom.GetIntValue() )
266 }
267
268 switch( hAlign )
269 {
274 }
275
276 switch( vAlign )
277 {
278 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
282 }
283 }
284
285 return true;
286}
287
288
290{
292 {
293 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
294 btn->Check( false );
295 }
296}
297
298
300{
302 {
303 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
304 btn->Check( false );
305 }
306}
307
308
310{
311 if( aEvent.GetSelection() == 1 )
312 {
313 m_textColorBook->SetSelection( 1 );
315 }
316}
317
318
320{
321 if( aEvent.GetSelection() == 1 )
322 {
323 m_fillColorBook->SetSelection( 1 );
325 }
326}
327
328
330{
331 if( !wxDialog::TransferDataFromWindow() )
332 return false;
333
334 SCH_COMMIT commit( m_frame );
335
336 /* save table in undo list if not already in edit */
337 if( m_table->GetEditFlags() == 0 )
338 commit.Modify( m_table, m_frame->GetScreen() );
339
340 for( SCH_TABLECELL* cell : m_cells )
341 {
342 wxString text = m_cellTextCtrl->GetValue();
343
344#ifdef __WXMAC__
345 // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
346 text.Replace( "\r", "\n" );
347#elif defined( __WINDOWS__ )
348 // On Windows, a new line is coded as \r\n. We use only \n in KiCad files and in
349 // drawing routines so strip the \r char.
350 text.Replace( "\r", "" );
351#endif
352
353 cell->SetText( text );
354
355 if( m_bold->Get3StateValue() == wxCHK_CHECKED )
356 cell->SetBold( true );
357 else if( m_bold->Get3StateValue() == wxCHK_UNCHECKED )
358 cell->SetBold( false );
359
360 if( m_italic->Get3StateValue() == wxCHK_CHECKED )
361 cell->SetItalic( true );
362 else if( m_italic->Get3StateValue() == wxCHK_UNCHECKED )
363 cell->SetItalic( false );
364
366 cell->SetFont( m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) );
367
369 cell->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
370
371 if( m_hAlignLeft->IsChecked() )
372 cell->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
373 else if( m_hAlignRight->IsChecked() )
374 cell->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
375 else if( m_hAlignCenter->IsChecked() )
376 cell->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
377
378 if( m_vAlignTop->IsChecked() )
379 cell->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
380 else if( m_vAlignBottom->IsChecked() )
381 cell->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
382 else if( m_vAlignCenter->IsChecked() )
383 cell->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
384
385 if( m_textColorBook->GetSelection() == 1 )
386 cell->SetTextColor( m_textColorSwatch->GetSwatchColor() );
387
388 if( m_fillColorBook->GetSelection() == 1 )
389 {
391
392 if( fillColor == COLOR4D::UNSPECIFIED )
393 {
394 cell->SetFillMode( FILL_T::NO_FILL );
395 }
396 else
397 {
398 cell->SetFillMode( FILL_T::FILLED_WITH_COLOR );
399 cell->SetFillColor( fillColor );
400 }
401 }
402
404 cell->SetMarginLeft( m_marginLeft.GetIntValue() );
405
407 cell->SetMarginTop( m_marginTop.GetIntValue() );
408
410 cell->SetMarginRight( m_marginRight.GetIntValue() );
411
413 cell->SetMarginBottom( m_marginBottom.GetIntValue() );
414 }
415
416 if( !commit.Empty() )
417 commit.Push( _( "Edit Table Cell Properties" ) );
418
420 return true;
421}
422
423
424void DIALOG_TABLECELL_PROPERTIES::onEditTable( wxCommandEvent& aEvent )
425{
427 {
429 Close();
430 }
431}
432
434{
437
438 event.Skip();
439}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void SetIsRadioButton()
bool IsChecked() const
void Check(bool aCheck=true)
Check the control.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
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)
Modify a given item in the model.
Definition: commit.h:108
bool Empty() const
Definition: commit.h:150
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:66
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 onTextColorPopup(wxCommandEvent &aEvent) override
void onMultiLineTCLostFocus(wxFocusEvent &event) override
void onFillColorPopup(wxCommandEvent &aEvent) override
DIALOG_TABLECELL_PROPERTIES(SCH_EDIT_FRAME *aParentFrame, std::vector< SCH_TABLECELL * > aCells)
void getContextualTextVars(const wxString &aCrossRef, wxArrayString *aTokens)
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:137
void SetFontSelection(KIFONT::FONT *aFont, bool aSilentMode=false)
Set the selection in wxChoice widget.
Definition: font_choice.cpp:73
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic, bool aForDrawingSheet=false) const
bool HaveFontSelection() const
Definition: font_choice.cpp:95
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:95
Holds all the data relating to one schematic.
Definition: schematic.h:69
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:208
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:148
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
Execute the changes.
Definition: sch_commit.cpp:435
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:156
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
SCH_SYMBOL * GetSymbol() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:177
Schematic symbol object.
Definition: sch_symbol.h:75
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:611
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
void DoTextVarAutocomplete(const std::function< void(const wxString &xRef, wxArrayString *tokens)> &getTokensFn)
int GetIntValue()
Definition: unit_binder.h:129
virtual long long int GetValue()
Return the current value in Internal Units.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:477
STL namespace.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695