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;
258 }
259
261
265
266 if( PCB_DIM_ALIGNED* aligned = dynamic_cast<PCB_DIM_ALIGNED*>( m_dimension ) )
267 m_extensionOvershoot.SetValue( aligned->GetExtensionHeight() );
268 else
269 m_extensionOvershoot.Show( false );
270
271 // Do this last; it depends on the other settings
273 {
275 m_txtValueActual->SetValue( txt );
276 }
277 else
278 {
280 }
281
282 if( PCB_DIM_LEADER* leader = static_cast<PCB_DIM_LEADER*>( m_dimension ) )
283 m_cbTextFrame->SetSelection( static_cast<int>( leader->GetTextBorder() ) );
284
285 return DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataToWindow();
286}
287
288
290{
291 if( !DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataFromWindow() )
292 return false;
293
294 BOARD_COMMIT commit( m_frame );
295 commit.Modify( m_dimension );
296
297 // If no other command in progress, prepare undo command
298 // (for a command in progress, will be made later, at the completion of command)
299 bool pushCommit = ( m_dimension->GetEditFlags() == 0 );
300
301 /* set flag in edit to force undo/redo/abort proper operation,
302 * and avoid new calls to SaveCopyInUndoList for the same dimension
303 * this can occurs when a dimension is moved, and then rotated, edited ..
304 */
305 if( !pushCommit )
307
309
310 if( pushCommit )
311 commit.Push( _( "Change dimension properties" ) );
312
313 return true;
314}
315
316
317void DIALOG_DIMENSION_PROPERTIES::onFontSelected( wxCommandEvent & aEvent )
318{
319 if( KIFONT::FONT::IsStroke( aEvent.GetString() ) )
320 {
321 m_textThickness.Show( true );
322
323 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
324 int thickness = m_textThickness.GetValue();
325
326 m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
327 < abs( thickness - GetPenSizeForNormal( textSize ) ) );
328 }
329 else
330 {
331 m_textThickness.Show( false );
332 }
333}
334
335
336void DIALOG_DIMENSION_PROPERTIES::onBoldToggle( wxCommandEvent & aEvent )
337{
338 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
339
340 if( aEvent.IsChecked() )
342 else
344
345 aEvent.Skip();
346}
347
348
349void DIALOG_DIMENSION_PROPERTIES::onAlignButton( wxCommandEvent& aEvent )
350{
352 {
353 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
354 btn->Check( false );
355 }
356}
357
358
359void DIALOG_DIMENSION_PROPERTIES::onThickness( wxCommandEvent& event )
360{
361 int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
362 int thickness = m_textThickness.GetValue();
363
364 m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
365 < abs( thickness - GetPenSizeForNormal( textSize ) ) );
366}
367
368
370{
371 BOARD* board = m_frame->GetBoard();
372
373 aTarget->SetOverrideTextEnabled( m_cbOverrideValue->GetValue() );
374
375 if( m_cbOverrideValue->GetValue() )
376 {
377 wxString txt = board->ConvertCrossReferencesToKIIDs( m_txtValueActual->GetValue() );
378 aTarget->SetOverrideText( txt );
379 }
380
381 aTarget->SetPrefix( board->ConvertCrossReferencesToKIIDs( m_txtPrefix->GetValue() ) );
382 aTarget->SetSuffix( board->ConvertCrossReferencesToKIIDs( m_txtSuffix->GetValue() ) );
383 aTarget->SetLayer( static_cast<PCB_LAYER_ID>( m_cbLayerActual->GetLayerSelection() ) );
384
385 switch( m_cbUnits->GetSelection() )
386 {
387 case 0: aTarget->SetUnitsMode( DIM_UNITS_MODE::INCHES ); break;
388 case 1: aTarget->SetUnitsMode( DIM_UNITS_MODE::MILS ); break;
389 case 2: aTarget->SetUnitsMode( DIM_UNITS_MODE::MILLIMETRES ); break;
390 case 3: aTarget->SetUnitsMode( DIM_UNITS_MODE::AUTOMATIC ); break;
391 }
392
393 aTarget->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
394 aTarget->SetPrecision( static_cast<DIM_PRECISION>( m_cbPrecision->GetSelection() ) );
395 aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );
396
397 DIM_TEXT_POSITION tpm = static_cast<DIM_TEXT_POSITION>( m_cbTextPositionMode->GetSelection() );
398 aTarget->SetTextPositionMode( tpm );
399
400 if( tpm == DIM_TEXT_POSITION::MANUAL )
401 {
403 aTarget->SetTextPos( pos );
404 }
405
406 aTarget->SetKeepTextAligned( m_cbKeepAligned->GetValue() );
407
409 aTarget->SetTextWidth( m_textWidth.GetValue() );
410 aTarget->SetTextHeight( m_textHeight.GetValue() );
412
415
416 aTarget->SetBold( m_bold->IsChecked() );
417 aTarget->SetItalic( m_italic->IsChecked() );
418
419 if( m_alignLeft->IsChecked() )
421 else if( m_alignCenter->IsChecked() )
423 else
425
426 aTarget->SetMirrored( m_mirrored->IsChecked() );
427
431
432 if( PCB_DIM_ALIGNED* aligned = dynamic_cast<PCB_DIM_ALIGNED*>( aTarget ) )
433 aligned->SetExtensionHeight( m_extensionOvershoot.GetValue() );
434
435 if( PCB_DIM_LEADER* leader = dynamic_cast<PCB_DIM_LEADER*>( aTarget ) )
436 leader->SetTextBorder( static_cast<DIM_TEXT_BORDER>( m_cbTextFrame->GetSelection()));
437
438 aTarget->Update();
439}
440
441
443{
446}
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:225
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:259
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:675
wxString ConvertCrossReferencesToKIIDs(const wxString &aSource) const
Convert cross-references back and forth between ${refDes:field} and ${kiid:field}.
Definition: board.cpp:1270
wxString ConvertKIIDsToCrossReferences(const wxString &aSource) const
Definition: board.cpp:1324
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
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:288
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:230
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:401
KIFONT::FONT * GetFont() const
Definition: eda_text.h:207
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:236
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:379
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:390
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsMirrored() const
Definition: eda_text.h:150
bool IsBold() const
Definition: eda_text.h:144
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:342
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
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
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:189
#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
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:100
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:101
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:98