KiCad PCB EDA Suite
dialog_edit_module_text.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2015 Jean-Pierre Charras
10  * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
11  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
12  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, you may find one here:
26  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
27  * or you may search the http://www.gnu.org website for the version 2 license,
28  * or you may write to the Free Software Foundation, Inc.,
29  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30  */
31 
32 
33 #include <fctsys.h>
34 #include <macros.h>
35 #include <gr_basic.h>
36 #include <common.h>
37 #include <class_drawpanel.h>
38 #include <pcbnew.h>
39 #include <drawtxt.h>
40 #include <confirm.h>
41 #include <wxBasePcbFrame.h>
42 #include <base_units.h>
43 #include <wx/numformatter.h>
44 #include <board_commit.h>
45 
46 #include <class_module.h>
47 #include <class_text_mod.h>
48 #include <class_board.h>
49 
52 
53 
54 extern wxPoint MoveVector; // Move vector for move edge, imported from edtxtmod.cpp
55 
56 
58 {
60  DialogEditModuleText dialog( this, TextMod, DC );
61  dialog.ShowModal();
63 }
64 
65 
67  TEXTE_MODULE* aTextMod, wxDC* aDC ) :
68  DialogEditModuleText_base( aParent ),
69  m_OrientValidator( 1, &m_OrientValue )
70 
71 {
72  m_parent = aParent;
73  m_dc = aDC;
74  m_module = NULL;
75  m_currentText = aTextMod;
76  m_OrientValue = 0;
77 
78  m_OrientValidator.SetRange( -180.0, 180.0 );
79  m_OrientValueCtrl->SetValidator( m_OrientValidator );
81 
82  if( m_currentText )
84 
85  m_sdbSizerOK->SetDefault();
86  SetFocus();
87 
88 }
89 
90 
92 {
93  if( !wxDialog::TransferDataToWindow() )
94  return false;
95 
96  wxString msg;
97 
98  if( m_module )
99  {
100  wxString format = m_ModuleInfoText->GetLabel();
101  msg.Printf( format,
103  GetChars( m_module->GetValue() ),
104  m_module->GetOrientation() / 10.0 );
105  }
106  else
107  {
108  msg.Empty();
109  }
110 
111  m_ModuleInfoText->SetLabel( msg );
112 
113  // Create a list of not allowed layers.
114  // could be slightly dependent of the type of footprint text.
115  LSET forbiddenLayers( LSET::AllCuMask() );
116  forbiddenLayers.set( Edge_Cuts ).set( Margin ).set( F_Paste ).set( B_Paste ).set( F_Mask ).set( B_Mask );
117 
118  switch( m_currentText->GetType() )
119  {
121  m_TextDataTitle->SetLabel( _( "Value:" ) );
122  break;
123 
125  m_TextDataTitle->SetLabel( _( "Text:" ) );
126  break;
127 
129  m_TextDataTitle->SetLabel( _( "Reference:" ) );
130  break;
131  }
132 
133  m_Name->SetValue( m_currentText->GetText() );
134 
135  m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 );
136 
139 
142 
145 
148 
151 
152  double text_orient = m_currentText->GetTextAngle();
153  text_orient = NormalizeAngle180( text_orient );
154 
155  if( !m_currentText->IsVisible() )
156  m_Show->SetSelection( 1 );
157 
158  bool custom_orientation = false;
159  switch( int( text_orient ) )
160  {
161  case 0:
162  m_Orient->SetSelection( 0 );
163  break;
164 
165  case 900:
166  case -2700:
167  m_Orient->SetSelection( 1 );
168  break;
169 
170  case -900:
171  case 2700:
172  m_Orient->SetSelection( 2 );
173  break;
174 
175  case -1800:
176  case 1800:
177  m_Orient->SetSelection( 3 );
178  break;
179 
180  default:
181  m_Orient->SetSelection( 4 );
182  custom_orientation = true;
183  break;
184  }
185 
186  m_OrientValueCtrl->Enable( custom_orientation );
187  m_OrientValue = text_orient / 10.0;
188  m_OrientValidator.TransferToWindow();
189 
190  // Configure the layers list selector
192  // Footprints are built outside the current board, so items cann be
193  // on a not activated layer, therefore show it if happens.
195 
197  m_LayerSelectionCtrl->SetLayerSet( forbiddenLayers );
200 
202  {
203  wxMessageBox( _( "This item has an illegal layer id.\n"
204  "Now, forced on the front silk screen layer. Please, fix it" ) );
206  }
207 
208  return true;
209 }
210 
211 
213 {
214  BOARD_COMMIT commit( m_parent );
215 
216  if( !Validate() || !DialogEditModuleText_base::TransferDataFromWindow() )
217  return false;
218 
219  if( m_module )
220  commit.Modify( m_currentText );
221 
222 #ifndef USE_WX_OVERLAY
223  if( m_dc ) //Erase old text on screen
224  {
226  (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
227  }
228 #endif
229 
230  m_currentText->SetText( m_Name->GetValue() );
231  m_currentText->SetItalic( m_Style->GetSelection() == 1 );
232 
233  wxPoint tmp;
234 
235  tmp.x = ValueFromString( g_UserUnit, m_TxtPosCtrlX->GetValue() );
236  tmp.y = ValueFromString( g_UserUnit, m_TxtPosCtrlY->GetValue() );
237 
238  m_currentText->SetPos0( tmp );
239 
240  wxSize textSize( wxSize( ValueFromString( g_UserUnit, m_TxtSizeCtrlX->GetValue() ),
241  ValueFromString( g_UserUnit, m_TxtSizeCtrlY->GetValue() ) ) );
242 
243  // Test for a reasonable size:
244  if( textSize.x < TEXTS_MIN_SIZE )
245  textSize.x = TEXTS_MIN_SIZE;
246 
247  if( textSize.y < TEXTS_MIN_SIZE )
248  textSize.y = TEXTS_MIN_SIZE;
249 
250  m_currentText->SetTextSize( textSize );
251 
252  int width = ValueFromString( g_UserUnit, m_TxtWidthCtlr->GetValue() );
253 
254  // Test for a reasonable width:
255  if( width <= 1 )
256  width = 1;
257 
258  int maxthickness = Clamp_Text_PenSize(width, m_currentText->GetTextSize() );
259 
260  if( width > maxthickness )
261  {
262  DisplayError( NULL,
263  _( "The text thickness is too large for the text size. It will be clamped" ) );
264  width = maxthickness;
265  }
266 
267  m_currentText->SetThickness( width );
268 
269  m_currentText->SetVisible( m_Show->GetSelection() == 0 );
270 
271  bool custom_orientation = false;
272  switch( m_Orient->GetSelection() )
273  {
274  case 0:
276  break;
277 
278  case 1:
279  m_currentText->SetTextAngle( 900 );
280  break;
281 
282  case 2:
283  m_currentText->SetTextAngle( -900 );
284  break;
285 
286  case 3:
287  m_currentText->SetTextAngle( 1800 );
288  break;
289 
290  default:
291  custom_orientation = true;
293  break;
294  };
295 
296  switch( int( m_currentText->GetTextAngle() ) )
297  {
298  case 0:
299  m_Orient->SetSelection( 0 );
300  break;
301 
302  case 900:
303  case -2700:
304  m_Orient->SetSelection( 1 );
305  break;
306 
307  case -900:
308  case 2700:
309  m_Orient->SetSelection( 2 );
310  break;
311 
312  case -1800:
313  case 1800:
314  m_Orient->SetSelection( 3 );
315  break;
316 
317  default:
318  m_Orient->SetSelection( 4 );
320  custom_orientation = true;
321  break;
322  }
324  m_OrientValueCtrl->Enable( custom_orientation );
325  m_OrientValidator.TransferToWindow();
326 
328 
330  m_currentText->SetLayer( ToLAYER_ID( layer ) );
332 
333 #ifndef USE_WX_OVERLAY
334  if( m_dc ) // Display new text
335  {
337  (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
338  }
339 #else
340  m_parent->Refresh();
341 #endif
342 
343  commit.Push( _( "Modify module text" ) );
344 
345  if( m_module )
347 
348  return true;
349 }
350 
351 
352 void DialogEditModuleText::ModuleOrientEvent( wxCommandEvent& event )
353 {
354  bool custom_orientation = false;
355 
356  switch( m_Orient->GetSelection() )
357  {
358  case 0:
359  m_OrientValue = 0.0;
360  break;
361 
362  case 1:
363  m_OrientValue = 90.0;
364  break;
365 
366  case 2:
367  m_OrientValue = -90.0;
368  break;
369 
370  case 3:
371  m_OrientValue = 180.0;
372  break;
373 
374  default:
375  custom_orientation = true;
376  break;
377  }
378 
379  m_OrientValidator.TransferToWindow();
380  m_OrientValueCtrl->Enable( custom_orientation );
381 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:646
wxPoint MoveVector
Definition: edtxtmod.cpp:54
BOARD_ITEM_CONTAINER * GetParent() const
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
bool IsMoving() const
Definition: base_struct.h:232
PCB_LAYER_BOX_SELECTOR * m_LayerSelectionCtrl
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
bool IsItalic() const
Definition: eda_text.h:170
void ModuleOrientEvent(wxCommandEvent &event) override
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
TEXT_TYPE GetType() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint & GetPos0() const
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Class BOARD to handle a board.
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:439
void SetItalic(bool isItalic)
Definition: eda_text.h:169
int GetTextWidth() const
Definition: eda_text.h:218
void SetVisible(bool aVisible)
Definition: eda_text.h:175
BOARD * GetBoard() const
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:467
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetLastEditTime(time_t aTime)
Definition: class_module.h:302
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
bool TransferDataFromWindow() override
double GetTextAngle() const
Definition: eda_text.h:164
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
This file contains miscellaneous commonly used macros and functions.
bool TransferDataToWindow() override
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:306
Class LSET is a set of PCB_LAYER_IDs.
Footprint text class description.
Classes used in Pcbnew, CvPcb and GerbView.
wxFloatingPointValidator< double > m_OrientValidator
void InstallTextModOptionsFrame(TEXTE_MODULE *TextMod, wxDC *DC)
double GetOrientation() const
Definition: class_module.h:180
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)
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw Draw the text according to the footprint pos and orient.
bool SetLayersHotkeys(bool value)
void SetPos0(const wxPoint &aPos)
#define TEXTS_MIN_SIZE
Minimum text size in Pcbnew units value (5 mils)
Definition: pcbnew.h:62
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
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
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit)
Definition: base_units.cpp:509
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:439
bool IsVisible() const
Definition: eda_text.h:176
void SetIgnoreMouseEvents(bool aIgnore)
void SetDrawCoord()
Set absolute coordinates.
LAYER_NUM GetLayerSelection() const
The common library.
int GetTextHeight() const
Definition: eda_text.h:221
This file is part of the common libary.
DialogEditModuleText(PCB_BASE_FRAME *aParent, TEXTE_MODULE *aTextMod, wxDC *aDC)
void SetTextAngle(double aAngle)
Module description (excepted pads)
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:73
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
Class DialogEditModuleText_base.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
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