KiCad PCB EDA Suite
dialog_dimension_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) 2020 Jon Evans <[email protected]>
5 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <widgets/font_choice.h>
23#include <board.h>
24#include <board_commit.h>
25#include <pcb_dimension.h>
26#include <pcb_base_edit_frame.h>
28#include <widgets/unit_binder.h>
29#include <wx/msgdlg.h>
30
32
33
34
36 BOARD_ITEM* aItem ) :
38 m_frame( aParent ),
39 m_cbLayerActual( m_cbLayer ),
40 m_txtValueActual( m_txtValue ),
41 m_textWidth( aParent, m_lblTextWidth, m_txtTextWidth, m_lblTextWidthUnits ),
42 m_textHeight( aParent, m_lblTextHeight, m_txtTextHeight, m_lblTextHeightUnits ),
43 m_textThickness( aParent, m_lblTextThickness, m_txtTextThickness, m_lblTextThicknessUnits ),
44 m_textPosX( aParent, m_lblTextPosX, m_txtTextPosX, m_lblTextPosXUnits ),
45 m_textPosY( aParent, m_lblTextPosY, m_txtTextPosY, m_lblTextPosYUnits ),
46 m_orientation( aParent, m_lblTextOrientation, m_cbTextOrientation, nullptr ),
47 m_lineThickness( aParent, m_lblLineThickness, m_txtLineThickness, m_lblLineThicknessUnits ),
48 m_arrowLength( aParent, m_lblArrowLength, m_txtArrowLength, m_lblArrowLengthUnits ),
49 m_extensionOffset( aParent, m_lblExtensionOffset, m_txtExtensionOffset, m_lblExtensionOffsetUnits )
50{
51 wxASSERT( BaseType( aItem->Type() ) == PCB_DIMENSION_T );
52 m_dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
55
56 switch( m_dimension->Type() )
57 {
60 // Hide the main format controls and keep the leader controls shown
61 m_sizerFormat->GetStaticBox()->Hide();
62 m_sizerCenter->GetStaticBox()->Hide();
63
66
67 // Remove a fewings from text format
70 break;
71
74 m_sizerLeader->GetStaticBox()->Hide();
75 m_sizerFormat->GetStaticBox()->Hide();
76 m_sizerText->GetStaticBox()->Hide();
77
78 m_lblArrowLength->Hide();
79 m_txtArrowLength->Hide();
81
85
87 break;
88
89 default:
90 m_sizerLeader->GetStaticBox()->Hide();
91 m_sizerCenter->GetStaticBox()->Hide();
92 break;
93 }
94
96
101
103
110
112
115
117
118 // Fix the size after hiding/showing some of the properties
119 Layout();
120
121 // Configure display origin transforms
124
125 // Configure the layers list selector. Note that footprints are built outside the current
126 // board and so we may need to show all layers if the text is on an unactivated layer.
129
131 m_cbLayerActual->SetBoardFrame( aParent );
133
136
137 // Set predefined rotations in combo dropdown, according to the locale floating point
138 // separator notation
139 double rot_list[] = { 0.0, 90.0, -90.0, 180.0 };
140
141 for( size_t ii = 0; ii < m_cbTextOrientation->GetCount() && ii < 4; ++ii )
142 m_cbTextOrientation->SetString( ii, wxString::Format( "%.1f", rot_list[ii] ) );
143
144 m_cbOverrideValue->Bind( wxEVT_CHECKBOX,
145 [&]( wxCommandEvent& evt )
146 {
147 m_txtValue->Enable( m_cbOverrideValue->GetValue() );
148
149 if( !m_cbOverrideValue->GetValue() )
150 m_txtValue->SetValue( m_dimension->GetValueText() );
151 } );
152
153 auto updateEventHandler =
154 [&]( wxCommandEvent& evt )
155 {
156 if( !m_cbOverrideValue->GetValue() )
157 m_txtValue->ChangeValue( m_dimension->GetValueText() );
158
160 };
161
162 // No need to use m_txtValueActual here since we don't have previewing for leaders
163 m_txtValue->Bind( wxEVT_TEXT, updateEventHandler );
164 m_txtPrefix->Bind( wxEVT_TEXT, updateEventHandler );
165 m_txtSuffix->Bind( wxEVT_TEXT, updateEventHandler );
166
167 m_cbUnits->Bind( wxEVT_CHOICE, updateEventHandler );
168 m_cbUnitsFormat->Bind( wxEVT_CHOICE, updateEventHandler );
169 m_cbPrecision->Bind( wxEVT_CHOICE, updateEventHandler );
170 m_cbSuppressZeroes->Bind( wxEVT_CHECKBOX, updateEventHandler );
171
172 m_cbTextPositionMode->Bind( wxEVT_CHOICE,
173 [&]( wxCommandEvent& aEvt )
174 {
175 // manual mode
176 bool allowPositioning = ( m_cbTextPositionMode->GetSelection() == 2 );
177
178 m_txtTextPosX->Enable( allowPositioning );
179 m_txtTextPosY->Enable( allowPositioning );
180 } );
181
182 m_cbKeepAligned->Bind( wxEVT_CHECKBOX,
183 [&]( wxCommandEvent& aEvt )
184 {
185 m_cbTextOrientation->Enable( !m_cbKeepAligned->GetValue() );
186 } );
187
189
191}
192
193
195{
196 delete m_previewDimension;
197}
198
199
201{
202 BOARD* board = m_frame->GetBoard();
203
206
207 switch( m_dimension->GetUnitsMode() )
208 {
209 case DIM_UNITS_MODE::INCHES: m_cbUnits->SetSelection( 0 ); break;
210 case DIM_UNITS_MODE::MILS: m_cbUnits->SetSelection( 1 ); break;
211 case DIM_UNITS_MODE::MILLIMETRES: m_cbUnits->SetSelection( 2 ); break;
212 case DIM_UNITS_MODE::AUTOMATIC: m_cbUnits->SetSelection( 3 ); break;
213 }
214
215 m_cbUnitsFormat->SetSelection( static_cast<int>( m_dimension->GetUnitsFormat() ) );
216 m_cbPrecision->SetSelection( static_cast<int>( m_dimension->GetPrecision() ) );
217
220
222 {
223 wxMessageBox( _( "This item was on a non-existing layer.\n"
224 "It has been moved to the first defined layer." ) );
225 m_cbLayerActual->SetSelection( 0 );
226 }
227
229
231
232 m_fontCtrl->SetFontSelection( text.GetFont() );
233
234 m_textWidth.SetValue( text.GetTextSize().x );
235 m_textHeight.SetValue( text.GetTextSize().y );
236 m_textThickness.SetValue( text.GetTextThickness() );
237
238 m_textPosX.SetValue( text.GetTextPos().x );
239 m_textPosY.SetValue( text.GetTextPos().y );
240 m_cbTextPositionMode->SetSelection( static_cast<int>( m_dimension->GetTextPositionMode() ) );
241
243 {
244 m_txtTextPosX->Disable();
245 m_txtTextPosY->Disable();
246 }
247
248 EDA_ANGLE orientation = text.GetTextAngle();
252
253 m_bold->Check( text.IsBold() );
254 m_italic->Check( text.IsItalic() );
255
256 switch ( text.GetHorizJustify() )
257 {
258 case GR_TEXT_H_ALIGN_LEFT: m_alignLeft->Check( true ); break;
259 case GR_TEXT_H_ALIGN_CENTER: m_alignCenter->Check( true ); break;
260 case GR_TEXT_H_ALIGN_RIGHT: m_alignRight->Check( true ); break;
261 }
262
263 m_mirrored->Check( text.IsMirrored() );
264
268
269 // Do this last; it depends on the other settings
271 {
273 m_txtValueActual->SetValue( txt );
274 }
275 else
276 {
278 }
279
281 {
282 PCB_DIM_LEADER* leader = static_cast<PCB_DIM_LEADER*>( m_dimension );
283 m_cbTextFrame->SetSelection( static_cast<int>( leader->GetTextBorder() ) );
284 }
285
286 return DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataToWindow();
287}
288
289
291{
292 if( !DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataFromWindow() )
293 return false;
294
295 BOARD_COMMIT commit( m_frame );
296 commit.Modify( m_dimension );
297
298 // If no other command in progress, prepare undo command
299 // (for a command in progress, will be made later, at the completion of command)
300 bool pushCommit = ( m_dimension->GetEditFlags() == 0 );
301
302 /* set flag in edit to force undo/redo/abort proper operation,
303 * and avoid new calls to SaveCopyInUndoList for the same dimension
304 * this can occurs when a dimension is moved, and then rotated, edited ..
305 */
306 if( !pushCommit )
308
310
311 if( pushCommit )
312 commit.Push( _( "Change dimension properties" ) );
313
314 return true;
315}
316
317
318void DIALOG_DIMENSION_PROPERTIES::onFontSelected( wxCommandEvent & aEvent )
319{
320 if( KIFONT::FONT::IsStroke( aEvent.GetString() ) )
321 {
322 m_textThickness.Show( true );
323
324 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
325 int thickness = m_textThickness.GetValue();
326
327 m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
328 < abs( thickness - GetPenSizeForNormal( textSize ) ) );
329 }
330 else
331 {
332 m_textThickness.Show( false );
333 }
334}
335
336
337void DIALOG_DIMENSION_PROPERTIES::onBoldToggle( wxCommandEvent & aEvent )
338{
339 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
340
341 if( aEvent.IsChecked() )
343 else
345
346 aEvent.Skip();
347}
348
349
350void DIALOG_DIMENSION_PROPERTIES::onAlignButton( wxCommandEvent& aEvent )
351{
353 {
354 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
355 btn->Check( false );
356 }
357}
358
359
360void DIALOG_DIMENSION_PROPERTIES::onThickness( wxCommandEvent& event )
361{
362 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
363 int thickness = m_textThickness.GetValue();
364
365 m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
366 < abs( thickness - GetPenSizeForNormal( textSize ) ) );
367}
368
369
371{
372 BOARD* board = m_frame->GetBoard();
373
374 aTarget->SetOverrideTextEnabled( m_cbOverrideValue->GetValue() );
375
376 if( m_cbOverrideValue->GetValue() )
377 {
378 wxString txt = board->ConvertCrossReferencesToKIIDs( m_txtValueActual->GetValue() );
379 aTarget->SetOverrideText( txt );
380 }
381
382 aTarget->SetPrefix( board->ConvertCrossReferencesToKIIDs( m_txtPrefix->GetValue() ) );
383 aTarget->SetSuffix( board->ConvertCrossReferencesToKIIDs( m_txtSuffix->GetValue() ) );
384 aTarget->SetLayer( static_cast<PCB_LAYER_ID>( m_cbLayerActual->GetLayerSelection() ) );
385
386 switch( m_cbUnits->GetSelection() )
387 {
388 case 0:
390 break;
391
392 case 1:
394 break;
395
396 case 2:
398 break;
399
400 case 3:
402 aTarget->SetUnits( m_frame->GetUserUnits() );
403 break;
404 }
405
406 aTarget->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
407 aTarget->SetPrecision( m_cbPrecision->GetSelection() );
408 aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );
409
410 PCB_TEXT& text = aTarget->Text();
411
412 DIM_TEXT_POSITION tpm = static_cast<DIM_TEXT_POSITION>( m_cbTextPositionMode->GetSelection() );
413 aTarget->SetTextPositionMode( tpm );
414
415 if( tpm == DIM_TEXT_POSITION::MANUAL )
416 {
417 wxPoint pos( m_textPosX.GetValue(), m_textPosY.GetValue() );
418 text.SetPosition( pos );
419 }
420
421 aTarget->SetKeepTextAligned( m_cbKeepAligned->GetValue() );
422
423 text.SetTextAngle( m_orientation.GetAngleValue().Normalize() );
424 text.SetTextWidth( m_textWidth.GetValue() );
425 text.SetTextHeight( m_textHeight.GetValue() );
426 text.SetTextThickness( m_textThickness.GetValue() );
427
430
431 text.SetBold( m_bold->IsChecked() );
432 text.SetItalic( m_italic->IsChecked() );
433
434 if( m_alignLeft->IsChecked() )
435 text.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
436 else if( m_alignCenter->IsChecked() )
437 text.SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
438 else
439 text.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
440
441 text.SetMirrored( m_mirrored->IsChecked() );
442
446
447 if( aTarget->Type() == PCB_DIM_LEADER_T || m_dimension->Type() == PCB_FP_DIM_LEADER_T )
448 {
449 PCB_DIM_LEADER* leader = static_cast<PCB_DIM_LEADER*>( aTarget );
450 leader->SetTextBorder( static_cast<DIM_TEXT_BORDER>( m_cbTextFrame->GetSelection()));
451 }
452
453 aTarget->Update();
454}
455
456
458{
461}
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:105
@ text_align_right
@ text_align_left
@ text_mirrored
@ text_align_center
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).
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:167
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:527
wxString ConvertCrossReferencesToKIIDs(const wxString &aSource) const
Convert cross-references back and forth between ${refDes:field} and ${kiid:field}.
Definition: board.cpp:1048
wxString ConvertKIIDsToCrossReferences(const wxString &aSource) const
Definition: board.cpp:1102
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
Class DIALOG_DIMENSION_PROPERTIES_BASE.
void onFontSelected(wxCommandEvent &aEvent) override
PCB_LAYER_BOX_SELECTOR * m_cbLayerActual
void onBoldToggle(wxCommandEvent &aEvent) override
void updateDimensionFromDialog(PCB_DIMENSION_BASE *aTarget)
DIALOG_DIMENSION_PROPERTIES(PCB_BASE_EDIT_FRAME *aParent, BOARD_ITEM *aItem)
void onAlignButton(wxCommandEvent &aEvent) override
void onThickness(wxCommandEvent &aEvent) override
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...
EDA_ANGLE Normalize()
Definition: eda_angle.h:249
EDA_ANGLE Normalize180()
Definition: eda_angle.h:271
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:147
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
bool HaveFontSelection() const
Definition: font_choice.cpp:88
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:67
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic) const
virtual bool IsStroke() const
Definition: font.h:112
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
Common, abstract interface for edit frames.
BOARD * GetBoard() const
Abstract dimension API.
Definition: pcb_dimension.h:96
void Update()
Update the dimension's cached text and geometry.
wxString GetOverrideText() const
wxString GetSuffix() const
void SetPrecision(int aPrecision)
void SetUnitsFormat(const DIM_UNITS_FORMAT aFormat)
int GetLineThickness() const
void SetUnits(EDA_UNITS aUnits)
void SetPrefix(const wxString &aPrefix)
void SetExtensionOffset(int aOffset)
void SetSuppressZeroes(bool aSuppress)
PCB_TEXT & Text()
DIM_TEXT_POSITION GetTextPositionMode() const
void SetParent(EDA_ITEM *aParent) override
bool GetKeepTextAligned() const
wxString GetPrefix() const
void SetOverrideTextEnabled(bool aOverride)
void SetSuffix(const wxString &aSuffix)
DIM_UNITS_MODE GetUnitsMode() const
void SetTextPositionMode(DIM_TEXT_POSITION aMode)
DIM_UNITS_FORMAT GetUnitsFormat() const
void SetLineThickness(int aWidth)
void SetArrowLength(int aLength)
bool GetSuppressZeroes() const
void SetOverrideText(const wxString &aValue)
wxString GetValueText() const
int GetExtensionOffset() const
int GetPrecision() const
int GetArrowLength() const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
bool GetOverrideTextEnabled() const
void SetUnitsMode(DIM_UNITS_MODE aMode)
void SetKeepTextAligned(bool aKeepAligned)
A leader is a dimension-like object pointing to a specific point.
DIM_TEXT_BORDER GetTextBorder() const
void SetTextBorder(DIM_TEXT_BORDER aFrame)
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void ShowNonActivatedLayers(bool aShow)
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:55
EDA_UNITS GetUserUnits() const
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetPrecision(int aLength)
Normally not needed, but can be used to set the precision when using internal units that are floats (...
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
virtual EDA_ANGLE GetAngleValue()
virtual void SetAngleValue(const EDA_ANGLE &aValue)
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:186
#define _(s)
#define IN_EDIT
Item currently edited.
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:52
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401
DIM_TEXT_POSITION
Where to place the text on a dimension.
Definition: pcb_dimension.h:48
@ MANUAL
Text placement is manually set by the user.
DIM_UNITS_FORMAT
How to display the units in a dimension's text.
Definition: pcb_dimension.h:40
DIM_TEXT_BORDER
Frame to show around dimension text.
Definition: pcb_dimension.h:69
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:253
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:105