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 <jon@craftyjon.com>
5  * Copyright (C) 2020 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 
21 #include <class_board.h>
22 #include <class_dimension.h>
23 #include <pcb_base_edit_frame.h>
24 #include <pcb_layer_box_selector.h>
25 #include <widgets/unit_binder.h>
26 
28 
29 
30 
32  BOARD_ITEM* aItem ) :
34  m_frame( aParent ),
35  m_cbLayerActual( m_cbLayer ),
36  m_txtValueActual( m_txtValue ),
37  m_textWidth( aParent, m_lblTextWidth, m_txtTextWidth, m_lblTextWidthUnits, true ),
38  m_textHeight( aParent, m_lblTextHeight, m_txtTextHeight, m_lblTextHeightUnits, true ),
39  m_textThickness( aParent, m_lblTextThickness, m_txtTextThickness,
40  m_lblTextHeightUnits, true ),
41  m_textPosX( aParent, m_lblTextPosX, m_txtTextPosX, m_lblTextPosXUnits ),
42  m_textPosY( aParent, m_lblTextPosY, m_txtTextPosY, m_lblTextPosYUnits ),
43  m_orientValidator( 1, &m_orientValue ),
44  m_lineThickness( aParent, m_lblLineThickness, m_txtLineThickness,
45  m_lblLineThicknessUnits, true ),
46  m_arrowLength( aParent, m_lblArrowLength, m_txtArrowLength, m_lblArrowLengthUnits, true ),
47  m_extensionOffset( aParent, m_lblExtensionOffset, m_txtExtensionOffset,
48  m_lblExtensionOffsetUnits )
49 {
50  wxASSERT( BaseType( aItem->Type() ) == PCB_DIMENSION_T );
51  m_dimension = static_cast<DIMENSION*>( aItem );
52  m_previewDimension = static_cast<DIMENSION*>( m_dimension->Clone() );
54 
55  switch( m_dimension->Type() )
56  {
57  case PCB_DIM_LEADER_T:
58  // Hide the main format controls and keep the leader controls shown
59  m_sizerFormat->GetStaticBox()->Hide();
60  m_sizerCenter->GetStaticBox()->Hide();
61 
64 
65  // Remove a fewings from text format
66  m_lblTextPositionMode->Hide();
67  m_cbTextPositionMode->Hide();
68  break;
69 
70  case PCB_DIM_CENTER_T:
71  m_sizerLeader->GetStaticBox()->Hide();
72  m_sizerFormat->GetStaticBox()->Hide();
73  m_sizerText->GetStaticBox()->Hide();
74 
75  m_lblArrowLength->Hide();
76  m_txtArrowLength->Hide();
77  m_lblArrowLengthUnits->Hide();
78 
79  m_lblExtensionOffset->Hide();
80  m_txtExtensionOffset->Hide();
82 
84  break;
85 
86  default:
87  m_sizerLeader->GetStaticBox()->Hide();
88  m_sizerCenter->GetStaticBox()->Hide();
89  break;
90  }
91 
92  // Fix the size after hiding/showing some of the properties
93  Layout();
94 
95  // Configure display origin transforms
98 
99  // Configure the layers list selector. Note that footprints are built outside the current
100  // board and so we may need to show all layers if the text is on an unactivated layer.
103 
105  m_cbLayerActual->SetBoardFrame( aParent );
107 
108  m_orientValue = 0.0;
109  m_orientValidator.SetRange( -360.0, 360.0 );
110  m_cbTextOrientation->SetValidator( m_orientValidator );
112 
113  // Handle decimal separators in combo dropdown
114  for( size_t i = 0; i < m_cbTextOrientation->GetCount(); ++i )
115  {
116  wxString item = m_cbTextOrientation->GetString( i );
117  item.Replace( '.', localeconv()->decimal_point[0] );
118  m_cbTextOrientation->SetString( i, item );
119  }
120 
121  m_sdbSizerOK->SetDefault();
122 
123  m_cbOverrideValue->Bind( wxEVT_CHECKBOX,
124  [&]( wxCommandEvent& evt )
125  {
126  m_txtValue->Enable( m_cbOverrideValue->GetValue() );
127 
128  if( !m_cbOverrideValue->GetValue() )
129  m_txtValue->SetValue( m_dimension->GetValueText() );
130  } );
131 
132  auto updateEventHandler =
133  [&]( wxCommandEvent& evt )
134  {
135  if( !m_cbOverrideValue->GetValue() )
136  m_txtValue->ChangeValue( m_dimension->GetValueText() );
137 
139  };
140 
141  // No need to use m_txtValueActual here since we don't have previewing for leaders
142  m_txtValue->Bind( wxEVT_TEXT, updateEventHandler );
143  m_txtPrefix->Bind( wxEVT_TEXT, updateEventHandler );
144  m_txtSuffix->Bind( wxEVT_TEXT, updateEventHandler );
145 
146  m_cbUnits->Bind( wxEVT_CHOICE, updateEventHandler );
147  m_cbUnitsFormat->Bind( wxEVT_CHOICE, updateEventHandler );
148  m_cbPrecision->Bind( wxEVT_CHOICE, updateEventHandler );
149  m_cbSuppressZeroes->Bind( wxEVT_CHECKBOX, updateEventHandler );
150 
151  m_cbTextPositionMode->Bind( wxEVT_CHOICE,
152  [&]( wxCommandEvent& aEvt )
153  {
154  // manual mode
155  bool allowPositioning = ( m_cbTextPositionMode->GetSelection() == 2 );
156 
157  m_txtTextPosX->Enable( allowPositioning );
158  m_txtTextPosY->Enable( allowPositioning );
159  } );
160 
161  m_cbKeepAligned->Bind( wxEVT_CHECKBOX,
162  [&]( wxCommandEvent& aEvt )
163  {
164  m_cbTextOrientation->Enable( !m_cbKeepAligned->GetValue() );
165  } );
166 
168 }
169 
170 
172 {
173  delete m_previewDimension;
174 }
175 
176 
178 {
179  BOARD* board = m_frame->GetBoard();
180 
183 
184  EDA_UNITS units;
185  m_dimension->GetUnits( units );
186 
187  m_cbUnits->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : units == EDA_UNITS::MILS ? 1 : 0 );
188  m_cbUnitsFormat->SetSelection( static_cast<int>( m_dimension->GetUnitsFormat() ) );
189  m_cbPrecision->SetSelection( static_cast<int>( m_dimension->GetPrecision() ) );
190 
193 
195  {
196  wxMessageBox( _( "This item was on a non-existing or forbidden layer.\n"
197  "It has been moved to the first allowed layer." ) );
198  m_cbLayerActual->SetSelection( 0 );
199  }
200 
202 
203  PCB_TEXT& text = m_dimension->Text();
204 
205  m_textWidth.SetValue( text.GetTextSize().x );
206  m_textHeight.SetValue( text.GetTextSize().y );
208 
209  m_textPosX.SetValue( text.GetTextPos().x );
210  m_textPosY.SetValue( text.GetTextPos().y );
211  m_cbTextPositionMode->SetSelection( static_cast<int>( m_dimension->GetTextPositionMode() ) );
212 
214  {
215  m_txtTextPosX->Disable();
216  m_txtTextPosY->Disable();
217  }
218 
222 
223  m_cbItalic->SetValue( text.IsItalic() );
224  m_cbMirrored->SetValue( text.IsMirrored() );
225  EDA_TEXT_HJUSTIFY_T hJustify = text.GetHorizJustify();
226  m_cbJustification->SetSelection( (int) hJustify + 1 );
227 
231 
232  // Do this last; it depends on the other settings
234  {
235  wxString txt = board->ConvertKIIDsToCrossReferences( m_dimension->GetOverrideText() );
236  m_txtValueActual->SetValue( txt );
237  }
238  else
239  {
240  m_txtValueActual->SetValue( m_dimension->GetValueText() );
241  }
242 
243  m_orientValidator.TransferToWindow();
244 
245  if( m_dimension->Type() == PCB_DIM_LEADER_T )
246  {
247  LEADER* leader = static_cast<LEADER*>( m_dimension );
248  m_cbTextFrame->SetSelection( static_cast<int>( leader->GetTextFrame() ) );
249  }
250 
251  return DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataToWindow();
252 }
253 
254 
256 {
257  if( !DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataFromWindow() )
258  return false;
259 
260  BOARD_COMMIT commit( m_frame );
261  commit.Modify( m_dimension );
262 
263  // If no other command in progress, prepare undo command
264  // (for a command in progress, will be made later, at the completion of command)
265  bool pushCommit = ( m_dimension->GetEditFlags() == 0 );
266 
267  /* set flag in edit to force undo/redo/abort proper operation,
268  * and avoid new calls to SaveCopyInUndoList for the same dimension
269  * this can occurs when a dimension is moved, and then rotated, edited ..
270  */
271  if( !pushCommit )
273 
275 
276  if( pushCommit )
277  commit.Push( _( "Change dimension properties" ) );
278 
279  return true;
280 }
281 
282 
284 {
285  BOARD* board = m_frame->GetBoard();
286 
287  m_orientValidator.TransferFromWindow();
288 
289  aTarget->SetOverrideTextEnabled( m_cbOverrideValue->GetValue() );
290 
291  if( m_cbOverrideValue->GetValue() )
292  {
293  wxString txt = board->ConvertCrossReferencesToKIIDs( m_txtValueActual->GetValue() );
294  aTarget->SetOverrideText( txt );
295  }
296 
297  aTarget->SetPrefix( board->ConvertCrossReferencesToKIIDs( m_txtPrefix->GetValue() ) );
298  aTarget->SetSuffix( board->ConvertCrossReferencesToKIIDs( m_txtSuffix->GetValue() ) );
299  aTarget->SetLayer( static_cast<PCB_LAYER_ID>( m_cbLayerActual->GetLayerSelection() ) );
300 
301  aTarget->SetUnits( m_frame->GetUserUnits() );
302  aTarget->SetUnitsMode( static_cast<DIM_UNITS_MODE>( m_cbUnits->GetSelection() ) );
303  aTarget->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
304  aTarget->SetPrecision( m_cbPrecision->GetSelection() );
305  aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );
306 
307  PCB_TEXT& text = aTarget->Text();
308 
309  DIM_TEXT_POSITION tpm = static_cast<DIM_TEXT_POSITION>( m_cbTextPositionMode->GetSelection() );
310  aTarget->SetTextPositionMode( tpm );
311 
312  if( tpm == DIM_TEXT_POSITION::MANUAL )
313  {
314  wxPoint pos( m_textPosX.GetValue(), m_textPosY.GetValue() );
315  text.SetPosition( pos );
316  }
317 
318  aTarget->SetKeepTextAligned( m_cbKeepAligned->GetValue() );
319 
320  text.SetTextAngle( KiROUND( m_orientValue * 10.0 ) );
324  text.SetItalic( m_cbItalic->GetValue() );
325  text.SetMirrored( m_cbMirrored->GetValue() );
326  int justification = m_cbJustification->GetSelection() - 1;
327  text.SetHorizJustify( static_cast<EDA_TEXT_HJUSTIFY_T>( justification ) );
328 
330  aTarget->SetArrowLength( m_arrowLength.GetValue() );
332 
333  if( aTarget->Type() == PCB_DIM_LEADER_T )
334  {
335  LEADER* leader = static_cast<LEADER*>( aTarget );
336  leader->SetTextFrame( static_cast<DIM_TEXT_FRAME>( m_cbTextFrame->GetSelection() ) );
337  }
338 
339  aTarget->Update();
340 }
341 
342 
344 {
347 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:194
Text placement is manually set by the user.
void SetKeepTextAligned(bool aKeepAligned)
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
Class DIALOG_DIMENSION_PROPERTIES_BASE.
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
void updateDimensionFromDialog(DIMENSION *aTarget)
bool IsMirrored() const
Definition: eda_text.h:195
void SetOverrideText(const wxString &aValue)
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:77
void SetTextFrame(DIM_TEXT_FRAME aFrame)
void SetSuffix(const wxString &aSuffix)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
DIM_TEXT_FRAME GetTextFrame() const
void SetPrefix(const wxString &aPrefix)
DIM_TEXT_POSITION GetTextPositionMode() const
void SetTextAngle(double aAngle) override
Definition: pcb_text.cpp:100
constexpr KICAD_T BaseType(const KICAD_T aType)
Returns the underlying type of the given type.
Definition: typeinfo.h:234
int GetPrecision() const
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
void SetItalic(bool isItalic)
Definition: eda_text.h:185
void Update()
Updates the dimension's cached text and geometry.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
wxFloatingPointValidator< double > m_orientValidator
PCB_LAYER_BOX_SELECTOR * m_cbLayerActual
int GetTextThickness() const
Definition: eda_text.h:165
wxString ConvertKIIDsToCrossReferences(const wxString &aSource)
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: class_board.h:480
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:97
bool IsItalic() const
Definition: eda_text.h:186
void SetUnitsMode(DIM_UNITS_MODE aMode)
DIMENSION class definition.
LAYER_NUM GetLayerSelection() const
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:51
void SetArrowLength(int aLength)
int GetExtensionOffset() const
void SetOverrideTextEnabled(bool aOverride)
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:221
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
A leader is a dimension-like object pointing to a specific point.
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:226
void ShowNonActivatedLayers(bool aShow)
const wxSize & GetTextSize() const
Definition: eda_text.h:245
bool GetKeepTextAligned() const
#define IN_EDIT
Item currently edited.
Definition: eda_item.h:104
int GetArrowLength() const
void SetParent(EDA_ITEM *aParent) override
PCB_TEXT & Text()
int SetLayerSelection(LAYER_NUM layer)
DIM_UNITS_FORMAT GetUnitsFormat() const
bool GetSuppressZeroes() const
wxString GetOverrideText() const
wxString GetPrefix() const
bool SetLayersHotkeys(bool value)
class DIMENSION: abstract dimension meta-type
Definition: typeinfo.h:100
void SetPrecision(int aPrecision)
void SetTextWidth(int aWidth)
Definition: eda_text.h:247
EDA_UNITS
Definition: eda_units.h:38
DIM_TEXT_POSITION
Where to place the text on a dimension.
double GetTextAngleDegrees() const
Definition: eda_text.h:182
wxString GetSuffix() const
Common, abstract interface for edit frames.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
void SetUnitsFormat(const DIM_UNITS_FORMAT aFormat)
void SetExtensionOffset(int aOffset)
int GetLineThickness() const
void SetTextHeight(int aHeight)
Definition: eda_text.h:250
void SetTextPositionMode(DIM_TEXT_POSITION aMode)
DIALOG_DIMENSION_PROPERTIES(PCB_BASE_EDIT_FRAME *aParent, BOARD_ITEM *aItem)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
bool GetOverrideTextEnabled() const
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
wxString GetValueText() const
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Function SetOriginTransform Sets the current origin transform mode.
Definition: unit_binder.h:168
BOARD * GetBoard() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
wxString ConvertCrossReferencesToKIIDs(const wxString &aSource)
Convert cross-references back and forth between ${refDes:field} and ${kiid:field}.
Abstract dimension API.
void SetLineThickness(int aWidth)
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void GetUnits(EDA_UNITS &aUnits) const
void SetUnits(EDA_UNITS aUnits)
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
void SetSuppressZeroes(bool aSuppress)