KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/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 (C) 2024 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
25#include <widgets/font_choice.h>
26#include <confirm.h>
27#include <board_commit.h>
29#include <board.h>
30#include <footprint.h>
31#include <pcb_textbox.h>
32#include <pcb_tablecell.h>
33#include <pcb_table.h>
34#include <project.h>
35#include <pcb_edit_frame.h>
37#include <tool/tool_manager.h>
38#include <tools/pcb_actions.h>
39#include <scintilla_tricks.h>
41
43 std::vector<PCB_TABLECELL*> aCells ) :
45 m_frame( aFrame ),
46 m_table( nullptr ),
47 m_cells( std::move( aCells ) ),
48 m_textHeight( aFrame, m_SizeYLabel, m_SizeYCtrl, m_SizeYUnits ),
49 m_textWidth( aFrame, m_SizeXLabel, m_SizeXCtrl, m_SizeXUnits ),
50 m_textThickness( aFrame, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits ),
51 m_marginLeft( aFrame, nullptr, m_marginLeftCtrl, nullptr ),
52 m_marginTop( aFrame, nullptr, m_marginTopCtrl, m_marginTopUnits ),
53 m_marginRight( aFrame, nullptr, m_marginRightCtrl, nullptr ),
54 m_marginBottom( aFrame, nullptr, m_marginBottomCtrl, nullptr ),
55 m_returnValue( TABLECELL_PROPS_CANCEL )
56{
57 wxASSERT( m_cells.size() > 0 && m_cells[0] );
58
59 m_table = static_cast<PCB_TABLE*>( m_cells[0]->GetParent() );
60
62 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
64 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
66 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
67
69 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
71 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
73 m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
74
76 Layout();
77
81 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_TABLECELL_PROPERTIES::onVAlignButton, this );
84
85 // Now all widgets have the size fixed, call FinishDialogSettings
87}
88
89
91{
92 if( !wxDialog::TransferDataToWindow() )
93 return false;
94
95 bool firstCell = true;
98
99 for( PCB_TABLECELL* cell : m_cells )
100 {
101 if( firstCell )
102 {
103 m_fontCtrl->SetFontSelection( cell->GetFont() );
104 m_textWidth.SetValue( cell->GetTextWidth() );
105 m_textHeight.SetValue( cell->GetTextHeight() );
106 m_textThickness.SetValue( cell->GetTextThickness() );
107
108 m_bold->Set3StateValue( cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
109 m_italic->Set3StateValue( cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
110
111 hAlign = cell->GetHorizJustify();
112 vAlign = cell->GetVertJustify();
113
114 m_marginLeft.SetValue( cell->GetMarginLeft() );
115 m_marginTop.SetValue( cell->GetMarginTop() );
116 m_marginRight.SetValue( cell->GetMarginRight() );
117 m_marginBottom.SetValue( cell->GetMarginBottom() );
118
119 firstCell = false;
120 }
121 else
122 {
123 if( cell->GetFont() != m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) )
124 m_fontCtrl->SetSelection( -1 );
125
126 if( cell->GetTextWidth() != m_textWidth.GetValue() )
128
129 if( cell->GetTextHeight() != m_textHeight.GetValue() )
131
132 if( cell->GetTextThickness() != m_textThickness.GetValue() )
134
135 wxCheckBoxState bold = cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
136
137 if( bold != m_bold->Get3StateValue() )
138 m_bold->Set3StateValue( wxCHK_UNDETERMINED );
139
140 wxCheckBoxState italic = cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
141
142 if( italic != m_italic->Get3StateValue() )
143 m_italic->Set3StateValue( wxCHK_UNDETERMINED );
144
145 if( cell->GetHorizJustify() != hAlign )
147
148 if( cell->GetVertJustify() != vAlign )
150
151 if( cell->GetMarginLeft() != m_marginLeft.GetIntValue() )
153
154 if( cell->GetMarginTop() != m_marginTop.GetIntValue() )
156
157 if( cell->GetMarginRight() != m_marginRight.GetIntValue() )
159
160 if( cell->GetMarginBottom() != m_marginBottom.GetIntValue() )
162 }
163
164 switch( hAlign )
165 {
170 }
171
172 switch( vAlign )
173 {
174 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
178 }
179 }
180
181 return true;
182}
183
184
185void DIALOG_TABLECELL_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
186{
188 {
189 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
190 btn->Check( false );
191 }
192}
193
194
195void DIALOG_TABLECELL_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
196{
198 {
199 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
200 btn->Check( false );
201 }
202}
203
204
206{
207 if( !wxDialog::TransferDataFromWindow() )
208 return false;
209
210 BOARD_COMMIT commit( m_frame );
211 commit.Modify( m_table );
212
213 // If no other command in progress, prepare undo command
214 // (for a command in progress, will be made later, at the completion of command)
215 bool pushCommit = ( m_table->GetEditFlags() == 0 );
216
217 // Set IN_EDIT flag to force undo/redo/abort proper operation and avoid new calls to
218 // SaveCopyInUndoList for the same text if is moved, and then rotated, edited, etc....
219 if( !pushCommit )
221
222 for( PCB_TABLECELL* cell : m_cells )
223 {
224 if( m_bold->Get3StateValue() == wxCHK_CHECKED )
225 cell->SetBold( true );
226 else if( m_bold->Get3StateValue() == wxCHK_UNCHECKED )
227 cell->SetBold( false );
228
229 if( m_italic->Get3StateValue() == wxCHK_CHECKED )
230 cell->SetItalic( true );
231 else if( m_italic->Get3StateValue() == wxCHK_UNCHECKED )
232 cell->SetItalic( false );
233
235 cell->SetFont( m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) );
236
238 cell->SetTextWidth( m_textWidth.GetIntValue() );
239
241 cell->SetTextHeight( m_textHeight.GetIntValue() );
242
244 cell->SetTextThickness( m_textThickness.GetIntValue() );
245
246 if( m_hAlignLeft->IsChecked() )
247 cell->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
248 else if( m_hAlignRight->IsChecked() )
249 cell->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
250 else if( m_hAlignCenter->IsChecked() )
251 cell->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
252
253 if( m_vAlignTop->IsChecked() )
254 cell->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
255 else if( m_vAlignBottom->IsChecked() )
256 cell->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
257 else if( m_vAlignCenter->IsChecked() )
258 cell->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
259
261 cell->SetMarginLeft( m_marginLeft.GetIntValue() );
262
264 cell->SetMarginTop( m_marginTop.GetIntValue() );
265
267 cell->SetMarginRight( m_marginRight.GetIntValue() );
268
270 cell->SetMarginBottom( m_marginBottom.GetIntValue() );
271 }
272
273 if( !commit.Empty() )
274 commit.Push( _( "Edit Table Cell Properties" ), SKIP_CONNECTIVITY );
275
277 return true;
278}
279
280
281void DIALOG_TABLECELL_PROPERTIES::onEditTable( wxCommandEvent& aEvent )
282{
284 {
286 Close();
287 }
288}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
#define SKIP_CONNECTIVITY
Definition: board_commit.h:42
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.
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...
DIALOG_TABLECELL_PROPERTIES(SCH_EDIT_FRAME *aParentFrame, std::vector< SCH_TABLECELL * > aCells)
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:133
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
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
Common, abstract interface for edit frames.
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.
This file is part of the common library.
#define _(s)
#define IN_EDIT
Item currently edited.
STL namespace.
GR_TEXT_H_ALIGN_T
@ 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
@ 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