KiCad PCB EDA Suite
dialog_pcb_text_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) 2004-2010 Jean-Pierre Charras <jean-pierre.charras@gpisa-lab.inpg.fr>
5  * Copyright (C) 2010-2016 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 /***************************************************************************/
26 /* Dialog editor for text on copper and technical layers (TEXTE_PCB class) */
27 /***************************************************************************/
28 
29 #include <fctsys.h>
30 #include <gr_basic.h>
31 #include <class_drawpanel.h>
32 #include <pcbnew.h>
33 #include <wxPcbStruct.h>
34 #include <drawtxt.h>
35 #include <confirm.h>
36 #include <base_units.h>
37 #include <wx/valnum.h>
38 
39 #include <class_board.h>
40 #include <class_pcb_text.h>
41 
42 #include <vector>
43 #include <wx/wx.h>
46 #include <board_commit.h>
47 
48 
49 class PCB_EDIT_FRAME;
50 class TEXTE_PCB;
51 
52 
54 {
55 public:
56  DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent, TEXTE_PCB* passedTextPCB, wxDC* DC = nullptr );
57 
58 private:
60  wxDC* m_DC;
62 
63  wxFloatingPointValidator<double> m_OrientValidator;
64  double m_OrientValue;
65 
66  bool TransferDataToWindow() override;
67  bool TransferDataFromWindow() override;
68 
69  // Virtual event handler
70  virtual void OnInitDlg( wxInitDialogEvent& event ) override
71  {
72  // Call the default wxDialog handler of a wxInitDialogEvent
74 
75  // Now all widgets have the size fixed, call FinishDialogSettings
77  }
78 };
79 
80 
89  TEXTE_PCB* passedTextPCB, wxDC* DC ) :
91  m_OrientValidator( 1, &m_OrientValue )
92 {
93  m_Parent = parent;
94  m_DC = DC;
95  m_SelectedPCBText = passedTextPCB;
96 
97  m_OrientValue = 0.0;
98  m_OrientValidator.SetRange( -360.0, 360.0 );
99  m_OrientCtrl->SetValidator( m_OrientValidator );
100  m_OrientValidator.SetWindow( m_OrientCtrl );
101 
102  m_StandardSizerOK->SetDefault();
103 
104 }
105 
106 
111 {
113 #ifndef __WXMAC__
114  DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, DC );
115 #else
116  // Avoid "writes" in the dialog, creates errors with WxOverlay and NSView
117  // Raising an Exception - Fixes #891347
118  DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, NULL );
119 #endif
120  dlg.ShowModal();
122  m_canvas->SetIgnoreMouseEvents( false );
123 }
124 
125 
127 {
128  // Put units symbols to text labels where appropriate
134 
135  // Fill fields with current values
137 
143 
144  // Configure the layers list selector
146 
147  // A text has no sense on edge cut layer
152 
154 
156  m_DisplayCtrl->SetSelection( 1 );
157  else
158  m_DisplayCtrl->SetSelection( 0 );
159 
160  if( m_SelectedPCBText->IsItalic() )
161  m_StyleCtrl->SetSelection( 1 );
162  else
163  m_StyleCtrl->SetSelection( 0 );
164 
165  // Set justification
167  m_justifyChoice->SetSelection( (int) hJustify + 1 );
168 
169  // Manually set tab order
170  m_SizeXCtrl->MoveAfterInTabOrder( m_TextContentCtrl );
171  m_SizeYCtrl->MoveAfterInTabOrder( m_SizeXCtrl );
172  m_ThicknessCtrl->MoveAfterInTabOrder( m_SizeYCtrl );
173  m_PositionXCtrl->MoveAfterInTabOrder( m_ThicknessCtrl );
174  m_PositionYCtrl->MoveAfterInTabOrder( m_PositionXCtrl );
175  m_OrientCtrl->MoveAfterInTabOrder( m_PositionYCtrl );
176  m_LayerSelectionCtrl->MoveAfterInTabOrder( m_OrientCtrl );
177  m_StyleCtrl->MoveAfterInTabOrder( m_LayerSelectionCtrl );
178  m_DisplayCtrl->MoveAfterInTabOrder( m_StyleCtrl );
179  m_justifyChoice->MoveAfterInTabOrder( m_DisplayCtrl );
180 
181  // Set focus on most important control
182  m_TextContentCtrl->SetFocus();
183  m_TextContentCtrl->SetSelection( -1, -1 );
184 
185  return DIALOG_PCB_TEXT_PROPERTIES_BASE::TransferDataToWindow();
186 }
187 
188 
190 {
191  if( !DIALOG_PCB_TEXT_PROPERTIES_BASE::TransferDataFromWindow() )
192  return false;
193 
194  BOARD_COMMIT commit( m_Parent );
195  commit.Modify( m_SelectedPCBText );
196 
197  // Test for acceptable layer.
198  // Incorrect layer can happen for old boards,
199  // having texts on edge cut layer for instance
201  {
202  wxMessageBox( _( "No layer selected, Please select the text layer" ) );
203  return false;
204  }
205 
206  wxPoint newPosition;
207  wxSize newSize;
208 
209  // If no other command in progress, prepare undo command
210  // (for a command in progress, will be made later, at the completion of command)
211  bool pushCommit = ( m_SelectedPCBText->GetFlags() == 0 );
212 
213  /* set flag in edit to force undo/redo/abort proper operation,
214  * and avoid new calls to SaveCopyInUndoList for the same text
215  * this can occurs when a text is moved, and then rotated, edited ..
216  */
217  if( m_SelectedPCBText->GetFlags() != 0 )
219 
220 #ifndef USE_WX_OVERLAY
221  // Erase old text on screen if context is available
222  if( m_DC )
223  {
225  }
226 #endif
227 
228  // Set the new text content
229  if( !m_TextContentCtrl->GetValue().IsEmpty() )
230  {
232  }
233 
234  // Set PCB Text position
235  newPosition.x = ValueFromString( g_UserUnit, m_PositionXCtrl->GetValue() );
236  newPosition.y = ValueFromString( g_UserUnit, m_PositionYCtrl->GetValue() );
237  m_SelectedPCBText->SetTextPos( newPosition );
238 
239  // Check constraints and set PCB Text size
240  newSize.x = ValueFromString( g_UserUnit, m_SizeXCtrl->GetValue() );
241  newSize.y = ValueFromString( g_UserUnit, m_SizeYCtrl->GetValue() );
242 
243  if( newSize.x < TEXTS_MIN_SIZE )
244  newSize.x = TEXTS_MIN_SIZE;
245 
246  if( newSize.y < TEXTS_MIN_SIZE )
247  newSize.y = TEXTS_MIN_SIZE;
248 
249  if( newSize.x > TEXTS_MAX_WIDTH )
250  newSize.x = TEXTS_MAX_WIDTH;
251 
252  if( newSize.y > TEXTS_MAX_WIDTH )
253  newSize.y = TEXTS_MAX_WIDTH;
254 
255  m_SelectedPCBText->SetTextSize( newSize );
256 
257  // Set the new thickness
259  m_ThicknessCtrl->GetValue() ) );
260 
261  // Test for acceptable values for thickness and size and clamp if fails
262  int maxthickness = Clamp_Text_PenSize( m_SelectedPCBText->GetThickness(),
264 
265  if( m_SelectedPCBText->GetThickness() > maxthickness )
266  {
267  DisplayError( NULL,
268  _( "The text thickness is too large for the text size. It will be clamped" ) );
269  m_SelectedPCBText->SetThickness( maxthickness );
270  }
271 
272  // Set the layer on which the PCB text is laying
274 
275  // Set whether the PCB text is mirrored (faced down from layer face perspective)
276  m_SelectedPCBText->SetMirrored( m_DisplayCtrl->GetSelection() == 1 );
277 
278  // Set the text angle
280 
281  // Set whether the PCB text is slanted (it is not italics, as italics has additional curves in style)
282  m_SelectedPCBText->SetItalic( m_StyleCtrl->GetSelection() );
283 
284  // Set justification
285  switch( m_justifyChoice->GetSelection() )
286  {
287  case 0:
289  break;
290  case 1:
292  break;
293  case 2:
295  break;
296  default:
297  break;
298  }
299 
300 #ifndef USE_WX_OVERLAY
301  // Finally, display new text if there is a context to do so
302  if( m_DC )
303  {
305  }
306 #else
307  m_Parent->Refresh();
308 #endif
309 
310  if( pushCommit )
311  commit.Push( _( "Change text properties" ) );
312 
313  return true;
314 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:269
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
void SetTextAngle(double aAngle)
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:125
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
TEXTE_PCB class definition.
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
DIALOG_PCB_TEXT_PROPERTIES(PCB_EDIT_FRAME *parent, TEXTE_PCB *passedTextPCB, wxDC *DC=nullptr)
DIALOG_PCB_TEXT_PROPERTIES, derived from DIALOG_PCB_TEXT_PROPERTIES_BASE.
void InstallTextPCBOptionsFrame(TEXTE_PCB *TextPCB, wxDC *DC)
Routine for main window class to launch text properties dialog.
bool IsItalic() const
Definition: eda_text.h:170
#define TEXTS_MAX_WIDTH
Maximum text width in Pcbnew units value (0.5 inches)
Definition: pcbnew.h:64
wxFloatingPointValidator< double > m_OrientValidator
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:337
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Class BOARD to handle a board.
void SetItalic(bool isItalic)
Definition: eda_text.h:169
int GetTextWidth() const
Definition: eda_text.h:218
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
double GetTextAngleDegrees() const
Definition: eda_text.h:166
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:347
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:267
Class DIALOG_PCB_TEXT_PROPERTIES_BASE.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
int SetLayerSelection(LAYER_NUM layer)
bool SetLayersHotkeys(bool value)
#define TEXTS_MIN_SIZE
Minimum text size in Pcbnew units value (5 mils)
Definition: pcbnew.h:62
virtual void OnInitDlg(wxInitDialogEvent &event) override
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
Definition: gr_basic.h:42
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
void PutValueInLocalUnits(wxTextCtrl &aTextCtr, int aValue)
Function PutValueInLocalUnits converts aValue from internal units to user units and append the units ...
Definition: base_units.cpp:265
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit)
Definition: base_units.cpp:509
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
bool IsMirrored() const
Definition: eda_text.h:179
void SetIgnoreMouseEvents(bool aIgnore)
LAYER_NUM GetLayerSelection() const
int GetTextHeight() const
Definition: eda_text.h:221
This file is part of the common libary.
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141