KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 m_extensionOvershoot( aParent, m_lblExtensionOvershoot, m_txtExtensionOvershoot, m_lblExtensionOvershootUnits )
51{
52 wxASSERT( BaseType( aItem->Type() ) == PCB_DIMENSION_T );
53 m_dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
56
57 switch( m_dimension->Type() )
58 {
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
73 m_sizerLeader->GetStaticBox()->Hide();
74 m_sizerFormat->GetStaticBox()->Hide();
75 m_sizerText->GetStaticBox()->Hide();
76
77 m_lblArrowLength->Hide();
78 m_txtArrowLength->Hide();
80
84
86 break;
87
88 default:
89 m_sizerLeader->GetStaticBox()->Hide();
90 m_sizerCenter->GetStaticBox()->Hide();
91 break;
92 }
93
95
97 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
99 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
100
102
104 m_alignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
106 m_alignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
108 m_alignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
109
111
113 m_mirrored->SetBitmap( KiBitmapBundle( BITMAPS::text_mirrored ) );
114
116
117 // Fix the size after hiding/showing some of the properties
118 Layout();
119
120 // Configure display origin transforms
123
124 // Configure the layers list selector. Note that footprints are built outside the current
125 // board and so we may need to show all layers if the text is on an unactivated layer.
128
130 m_cbLayerActual->SetBoardFrame( aParent );
132
133 m_orientation.SetUnits( EDA_UNITS::DEGREES );
135
136 // Set predefined rotations in combo dropdown, according to the locale floating point
137 // separator notation
138 double rot_list[] = { 0.0, 90.0, -90.0, 180.0 };
139
140 for( size_t ii = 0; ii < m_cbTextOrientation->GetCount() && ii < 4; ++ii )
141 m_cbTextOrientation->SetString( ii, wxString::Format( "%.1f", rot_list[ii] ) );
142
143 m_cbOverrideValue->Bind( wxEVT_CHECKBOX,
144 [&]( wxCommandEvent& evt )
145 {
146 m_txtValue->Enable( m_cbOverrideValue->GetValue() );
147
148 if( !m_cbOverrideValue->GetValue() )
149 m_txtValue->SetValue( m_dimension->GetValueText() );
150 } );
151
152 auto updateEventHandler =
153 [&]( wxCommandEvent& evt )
154 {
155 if( !m_cbOverrideValue->GetValue() )
156 m_txtValue->ChangeValue( m_dimension->GetValueText() );
157
159 };
160
161 // No need to use m_txtValueActual here since we don't have previewing for leaders
162 m_txtValue->Bind( wxEVT_TEXT, updateEventHandler );
163 m_txtPrefix->Bind( wxEVT_TEXT, updateEventHandler );
164 m_txtSuffix->Bind( wxEVT_TEXT, updateEventHandler );
165
166 m_cbUnits->Bind( wxEVT_CHOICE, updateEventHandler );
167 m_cbUnitsFormat->Bind( wxEVT_CHOICE, updateEventHandler );
168 m_cbPrecision->Bind( wxEVT_CHOICE, updateEventHandler );
169 m_cbSuppressZeroes->Bind( wxEVT_CHECKBOX, updateEventHandler );
170
171 m_cbTextPositionMode->Bind( wxEVT_CHOICE,
172 [&]( wxCommandEvent& aEvt )
173 {
174 // manual mode
175 bool allowPositioning = ( m_cbTextPositionMode->GetSelection() == 2 );
176
177 m_txtTextPosX->Enable( allowPositioning );
178 m_txtTextPosY->Enable( allowPositioning );
179 } );
180
181 m_cbKeepAligned->Bind( wxEVT_CHECKBOX,
182 [&]( wxCommandEvent& aEvt )
183 {
184 m_cbTextOrientation->Enable( !m_cbKeepAligned->GetValue() );
185 } );
186
188
190}
191
192
194{
195 delete m_previewDimension;
196}
197
198
200{
201 BOARD* board = m_frame->GetBoard();
202
205
206 switch( m_dimension->GetUnitsMode() )
207 {
208 case DIM_UNITS_MODE::INCHES: m_cbUnits->SetSelection( 0 ); break;
209 case DIM_UNITS_MODE::MILS: m_cbUnits->SetSelection( 1 ); break;
210 case DIM_UNITS_MODE::MILLIMETRES: m_cbUnits->SetSelection( 2 ); break;
211 case DIM_UNITS_MODE::AUTOMATIC: m_cbUnits->SetSelection( 3 ); break;
212 }
213
214 m_cbUnitsFormat->SetSelection( static_cast<int>( m_dimension->GetUnitsFormat() ) );
215 m_cbPrecision->SetSelection( static_cast<int>( m_dimension->GetPrecision() ) );
216
219
221 {
222 wxMessageBox( _( "This item was on a non-existing layer.\n"
223 "It has been moved to the first defined layer." ) );
224 m_cbLayerActual->SetSelection( 0 );
225 }
226
228
230
234
237 m_cbTextPositionMode->SetSelection( static_cast<int>( m_dimension->GetTextPositionMode() ) );
238
239 if( m_dimension->GetTextPositionMode() != DIM_TEXT_POSITION::MANUAL )
240 {
241 m_txtTextPosX->Disable();
242 m_txtTextPosY->Disable();
243 }
244
245 EDA_ANGLE orientation = m_dimension->GetTextAngle();
249
252
253 switch ( m_dimension->GetHorizJustify() )
254 {
255 case GR_TEXT_H_ALIGN_LEFT: m_alignLeft->Check( true ); break;
256 case GR_TEXT_H_ALIGN_CENTER: m_alignCenter->Check( true ); break;
257 case GR_TEXT_H_ALIGN_RIGHT: m_alignRight->Check( true ); break;
259 }
260
262
266
267 if( PCB_DIM_ALIGNED* aligned = dynamic_cast<PCB_DIM_ALIGNED*>( m_dimension ) )
268 m_extensionOvershoot.SetValue( aligned->GetExtensionHeight() );
269 else
270 m_extensionOvershoot.Show( false );
271
272 // Do this last; it depends on the other settings
274 {
276 m_txtValueActual->SetValue( txt );
277 }
278 else
279 {
281 }
282
283 if( PCB_DIM_LEADER* leader = static_cast<PCB_DIM_LEADER*>( m_dimension ) )
284 m_cbTextFrame->SetSelection( static_cast<int>( leader->GetTextBorder() ) );
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( _( "Edit 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: aTarget->SetUnitsMode( DIM_UNITS_MODE::INCHES ); break;
389 case 1: aTarget->SetUnitsMode( DIM_UNITS_MODE::MILS ); break;
390 case 2: aTarget->SetUnitsMode( DIM_UNITS_MODE::MILLIMETRES ); break;
391 case 3: aTarget->SetUnitsMode( DIM_UNITS_MODE::AUTOMATIC ); break;
392 }
393
394 aTarget->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
395 aTarget->SetPrecision( static_cast<DIM_PRECISION>( m_cbPrecision->GetSelection() ) );
396 aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );
397
398 DIM_TEXT_POSITION tpm = static_cast<DIM_TEXT_POSITION>( m_cbTextPositionMode->GetSelection() );
399 aTarget->SetTextPositionMode( tpm );
400
401 if( tpm == DIM_TEXT_POSITION::MANUAL )
402 {
404 aTarget->SetTextPos( pos );
405 }
406
407 aTarget->SetKeepTextAligned( m_cbKeepAligned->GetValue() );
408
410 aTarget->SetTextWidth( m_textWidth.GetValue() );
411 aTarget->SetTextHeight( m_textHeight.GetValue() );
413
416
417 // Must come after SetTextWidth/Height()
418 aTarget->SetBold( m_bold->IsChecked() );
419 aTarget->SetItalic( m_italic->IsChecked() );
420
421 if( m_alignLeft->IsChecked() )
423 else if( m_alignCenter->IsChecked() )
425 else
427
428 aTarget->SetMirrored( m_mirrored->IsChecked() );
429
433
434 if( PCB_DIM_ALIGNED* aligned = dynamic_cast<PCB_DIM_ALIGNED*>( aTarget ) )
435 aligned->SetExtensionHeight( m_extensionOvershoot.GetValue() );
436
437 if( PCB_DIM_LEADER* leader = dynamic_cast<PCB_DIM_LEADER*>( aTarget ) )
438 leader->SetTextBorder( static_cast<DIM_TEXT_BORDER>( m_cbTextFrame->GetSelection()));
439
440 aTarget->Update();
441}
442
443
445{
448}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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:41
void SetIsRadioButton()
bool IsChecked() const
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).
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
virtual void Push(const wxString &aMessage=wxEmptyString, 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:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
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:715
wxString ConvertCrossReferencesToKIIDs(const wxString &aSource) const
Convert cross-references back and forth between ${refDes:field} and ${kiid:field}.
Definition: board.cpp:1306
wxString ConvertKIIDsToCrossReferences(const wxString &aSource) const
Definition: board.cpp:1360
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
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:255
EDA_ANGLE Normalize180()
Definition: eda_angle.h:294
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:129
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:231
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:419
KIFONT::FONT * GetFont() const
Definition: eda_text.h:208
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:252
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:161
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:397
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:197
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:408
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsMirrored() const
Definition: eda_text.h:151
bool IsBold() const
Definition: eda_text.h:145
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
int GetTextThickness() const
Definition: eda_text.h:123
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:358
VECTOR2I GetTextSize() const
Definition: eda_text.h:219
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:268
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
virtual bool IsStroke() const
Definition: font.h:138
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
Common, abstract interface for edit frames.
BOARD * GetBoard() const
Abstract dimension API.
void Update()
Update the dimension's cached text and geometry.
wxString GetOverrideText() const
wxString GetSuffix() const
void SetUnitsFormat(const DIM_UNITS_FORMAT aFormat)
int GetLineThickness() const
void SetPrefix(const wxString &aPrefix)
void SetExtensionOffset(int aOffset)
void SetSuppressZeroes(bool aSuppress)
DIM_TEXT_POSITION GetTextPositionMode() const
bool GetKeepTextAligned() const
DIM_PRECISION GetPrecision() 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)
void SetPrecision(DIM_PRECISION aPrecision)
bool GetSuppressZeroes() const
void SetOverrideText(const wxString &aValue)
wxString GetValueText() const
int GetExtensionOffset() const
int GetArrowLength() const
bool GetOverrideTextEnabled() const
void SetUnitsMode(DIM_UNITS_MODE aMode)
void SetKeepTextAligned(bool aKeepAligned)
For better understanding of the points that make a dimension:
A leader is a dimension-like object pointing to a specific point.
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void ShowNonActivatedLayers(bool aShow)
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:78
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_text.cpp:402
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:188
#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:64
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
DIM_TEXT_POSITION
Where to place the text on a dimension.
Definition: pcb_dimension.h:62
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:83
DIM_PRECISION
Definition: pcb_dimension.h:47
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:257
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:100