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-2013 Wayne Stambaugh <stambaughw@verizon.net>
12  * Copyright (C) 1992-2016 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( -90.0, 90.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  NORMALIZE_ANGLE_90( text_orient );
154 
155  if( text_orient != 0.0 )
156  m_Orient->SetSelection( 1 );
157 
158  if( !m_currentText->IsVisible() )
159  m_Show->SetSelection( 1 );
160 
161  bool custom_orientation = false;
162  switch( int( text_orient ) )
163  {
164  case 0:
165  m_Orient->SetSelection( 0 );
166  break;
167 
168  case 900:
169  m_Orient->SetSelection( 1 );
170  break;
171 
172  case -900:
173  m_Orient->SetSelection( 2 );
174  break;
175 
176  default:
177  m_Orient->SetSelection( 3 );
178  custom_orientation = true;
179  break;
180  }
181 
182  m_OrientValueCtrl->Enable( custom_orientation );
183  m_OrientValue = text_orient / 10.0;
184  m_OrientValidator.TransferToWindow();
185 
186  // Configure the layers list selector
188  // Footprints are built outside the current board, so items cann be
189  // on a not activated layer, therefore show it if happens.
191 
193  m_LayerSelectionCtrl->SetLayerSet( forbiddenLayers );
196 
198  {
199  wxMessageBox( _( "This item has an illegal layer id.\n"
200  "Now, forced on the front silk screen layer. Please, fix it" ) );
202  }
203 
204  return true;
205 }
206 
207 
209 {
210  BOARD_COMMIT commit( m_parent );
211 
212  if( !Validate() || !DialogEditModuleText_base::TransferDataFromWindow() )
213  return false;
214 
215  if( m_module )
216  commit.Modify( m_currentText );
217 
218 #ifndef USE_WX_OVERLAY
219  if( m_dc ) //Erase old text on screen
220  {
222  (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
223  }
224 #endif
225 
226  m_currentText->SetText( m_Name->GetValue() );
227  m_currentText->SetItalic( m_Style->GetSelection() == 1 );
228 
229  wxPoint tmp;
230 
231  tmp.x = ValueFromString( g_UserUnit, m_TxtPosCtrlX->GetValue() );
232  tmp.y = ValueFromString( g_UserUnit, m_TxtPosCtrlY->GetValue() );
233 
234  m_currentText->SetPos0( tmp );
235 
236  wxSize textSize( wxSize( ValueFromString( g_UserUnit, m_TxtSizeCtrlX->GetValue() ),
237  ValueFromString( g_UserUnit, m_TxtSizeCtrlY->GetValue() ) ) );
238 
239  // Test for a reasonable size:
240  if( textSize.x < TEXTS_MIN_SIZE )
241  textSize.x = TEXTS_MIN_SIZE;
242 
243  if( textSize.y < TEXTS_MIN_SIZE )
244  textSize.y = TEXTS_MIN_SIZE;
245 
246  m_currentText->SetTextSize( textSize );
247 
248  int width = ValueFromString( g_UserUnit, m_TxtWidthCtlr->GetValue() );
249 
250  // Test for a reasonable width:
251  if( width <= 1 )
252  width = 1;
253 
254  int maxthickness = Clamp_Text_PenSize(width, m_currentText->GetTextSize() );
255 
256  if( width > maxthickness )
257  {
258  DisplayError( NULL,
259  _( "The text thickness is too large for the text size. It will be clamped" ) );
260  width = maxthickness;
261  }
262 
263  m_currentText->SetThickness( width );
264 
265  m_currentText->SetVisible( m_Show->GetSelection() == 0 );
266 
267  bool custom_orientation = false;
268  switch( m_Orient->GetSelection() )
269  {
270  case 0:
272  break;
273 
274  case 1:
275  m_currentText->SetTextAngle( 900 );
276  break;
277 
278  case 2:
279  m_currentText->SetTextAngle( -900 );
280  break;
281 
282  default:
283  custom_orientation = true;
285  break;
286  };
287 
288  switch( int( m_currentText->GetTextAngle() ) )
289  {
290  case 0:
291  m_Orient->SetSelection( 0 );
292  break;
293 
294  case 900:
295  case -2700:
296  m_Orient->SetSelection( 1 );
297  break;
298 
299  case -900:
300  case 2700:
301  m_Orient->SetSelection( 2 );
302  break;
303 
304  default:
305  m_Orient->SetSelection( 3 );
307  custom_orientation = true;
308  break;
309  }
311  m_OrientValueCtrl->Enable( custom_orientation );
312  m_OrientValidator.TransferToWindow();
313 
315 
317  m_currentText->SetLayer( ToLAYER_ID( layer ) );
319 
320 #ifndef USE_WX_OVERLAY
321  if( m_dc ) // Display new text
322  {
324  (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
325  }
326 #else
327  m_parent->Refresh();
328 #endif
329 
330  commit.Push( _( "Modify module text" ) );
331 
332  if( m_module )
334 
335  return true;
336 }
337 
338 
339 void DialogEditModuleText::ModuleOrientEvent( wxCommandEvent& event )
340 {
341  bool custom_orientation = false;
342 
343  switch( m_Orient->GetSelection() )
344  {
345  case 0:
346  m_OrientValue = 0.0;
347  break;
348 
349  case 1:
350  m_OrientValue = 90.0;
351  break;
352 
353  case 2:
354  m_OrientValue = -90.0;
355  break;
356 
357  default:
358  custom_orientation = true;
359  break;
360  }
361 
362  m_OrientValidator.TransferToWindow();
363  m_OrientValueCtrl->Enable( custom_orientation );
364 }
365 
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 LAYER_IDs.
Definition: lset.cpp:638
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:218
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:107
bool IsItalic() const
Definition: eda_text.h:170
void ModuleOrientEvent(wxCommandEvent &event) override
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:299
TEXT_TYPE GetType() const
const wxPoint & GetPos0() const
bool IsBackLayer(LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Class BOARD to handle a board.
void SetItalic(bool isItalic)
Definition: eda_text.h:169
int GetTextWidth() const
Definition: eda_text.h:218
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetVisible(bool aVisible)
Definition: eda_text.h:175
BOARD * GetBoard() const
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:439
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
bool IsLayerEnabled(LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:428
void SetLastEditTime(time_t aTime)
Definition: class_module.h:269
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void NORMALIZE_ANGLE_90(T &Angle)
Definition: trigo.h:277
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
Class LSET is a set of 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:147
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:92
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
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:411
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:69
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