KiCad PCB EDA Suite
dialog_lib_edit_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) 2001 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
10  * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <common.h>
33 #include <class_drawpanel.h>
34 #include <base_units.h>
35 
36 #include <general.h>
37 #include <libeditframe.h>
38 #include <class_libentry.h>
39 #include <lib_text.h>
40 
41 #include <dialog_lib_edit_text.h>
42 
43 
45  DIALOG_LIB_EDIT_TEXT_BASE( aParent )
46 {
47  m_parent = aParent;
48  m_graphicText = aText;
49  initDlg();
50 
51  // Now all widgets have the size fixed, call FinishDialogSettings
53 }
54 
55 
57 {
58  wxString msg;
59 
60  m_TextValue->SetFocus();
61 
62  // Disable options for fieldedition, not existing in graphic text
63  m_Invisible->Show(false);
64 
65  if( m_graphicText )
66  {
68  m_TextSize->SetValue( msg );
69  m_TextValue->SetValue( m_graphicText->GetText() );
70 
71  if( m_graphicText->GetUnit() == 0 )
72  m_CommonUnit->SetValue( true );
73  if( m_graphicText->GetConvert() == 0 )
74  m_CommonConvert->SetValue( true );
76  m_Orient->SetValue( true );
77 
78  int shape = 0;
79  if( m_graphicText->IsItalic() )
80  shape = 1;
81  if( m_graphicText->IsBold() )
82  shape |= 2;
83 
84  m_TextShapeOpt->SetSelection( shape );
85 
86  switch ( m_graphicText->GetHorizJustify() )
87  {
89  m_TextHJustificationOpt->SetSelection( 0 );
90  break;
91 
93  m_TextHJustificationOpt->SetSelection( 1 );
94  break;
95 
97  m_TextHJustificationOpt->SetSelection( 2 );
98  break;
99  }
100 
101  switch ( m_graphicText->GetVertJustify() )
102  {
104  m_TextVJustificationOpt->SetSelection( 0 );
105  break;
106 
108  m_TextVJustificationOpt->SetSelection( 1 );
109  break;
110 
112  m_TextVJustificationOpt->SetSelection( 2 );
113  break;
114  }
115  }
116  else
117  {
119  m_TextSize->SetValue( msg );
120 
122  m_CommonUnit->SetValue( true );
124  m_CommonConvert->SetValue( true );
126  m_Orient->SetValue( true );
127  }
128 
129  msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
130  m_TextSizeText->SetLabel( msg );
131 
132  m_sdbSizerButtonsOK->SetDefault();
133 
134  // Hide the select button as the child dialog classes use this
135  m_TextValueSelectButton->Hide();
136 
137  // Hide the "Power component value text cannot be modified!" warning
138  m_PowerComponentValues->Show( false );
139  Fit();
140 }
141 
142 
143 void DIALOG_LIB_EDIT_TEXT::OnCancelClick( wxCommandEvent& event )
144 {
145  EndModal(wxID_CANCEL);
146 }
147 
148 
149 /* Updates the different parameters for the component being edited */
150 void DIALOG_LIB_EDIT_TEXT::OnOkClick( wxCommandEvent& event )
151 {
152  wxString Line;
153 
154  Line = m_TextValue->GetValue();
156  wxString msg = m_TextSize->GetValue();
158  m_parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
159  m_parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;
160 
161  if( m_graphicText )
162  {
163  if( ! Line.IsEmpty() )
164  m_graphicText->SetText( Line );
165  else
166  m_graphicText->SetText( wxT( "[null]" ) );
167 
170 
173  else
174  m_graphicText->SetUnit( 0 );
175 
178  else
180 
181  m_graphicText->SetItalic( ( m_TextShapeOpt->GetSelection() & 1 ) != 0 );
182  m_graphicText->SetBold( ( m_TextShapeOpt->GetSelection() & 2 ) != 0 );
183 
184  switch( m_TextHJustificationOpt->GetSelection() )
185  {
186  case 0:
188  break;
189 
190  case 1:
192  break;
193 
194  case 2:
196  break;
197  }
198 
199  switch( m_TextVJustificationOpt->GetSelection() )
200  {
201  case 0:
203  break;
204 
205  case 1:
207  break;
208 
209  case 2:
211  break;
212  }
213  }
214 
215  if( m_parent->GetDrawItem() )
217 
218  EndModal(wxID_OK);
219 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
void OnOkClick(wxCommandEvent &aEvent) override
DIALOG_LIB_EDIT_TEXT(LIB_EDIT_FRAME *aParent, LIB_TEXT *aText)
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
static double m_current_text_angle
Current text angle setting.
Definition: libeditframe.h:112
LIB_ITEM * GetDrawItem()
Definition: libeditframe.h:399
bool IsItalic() const
Definition: eda_text.h:170
int GetUnit() const
Implementation of conversion functions that require both schematic and board internal units...
Class LIB_TEXT defines a component library graphical text item.
Definition: lib_text.h:45
wxString ReturnUnitSymbol(EDA_UNITS_T aUnit, const wxString &formatString)
Returns the units symbol.
Definition: base_units.cpp:420
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
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 OnCancelClick(wxCommandEvent &aEvent) override
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
#define TEXT_ANGLE_VERT
Definition: common.h:92
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:754
Class LIB_ITEM definition.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
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
LIB_EDIT_FRAME * m_parent
static int m_textSize
The current text size setting.
Definition: libeditframe.h:109
Class DIALOG_LIB_EDIT_TEXT_BASE.
void SetConvert(int aConvert)
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
void SetUnit(int aUnit)
The component library editor main window.
Definition: libeditframe.h:51
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:488
The common library.
bool m_drawSpecificConvert
Convert of the item currently being drawn.
Definition: libeditframe.h:60
bool m_drawSpecificUnit
Specify which component parts the current draw item applies to.
Definition: libeditframe.h:68
void SetBold(bool aBold)
Definition: eda_text.h:172
Definition of class LIB_EDIT_FRAME.
int GetConvert() const