KiCad PCB EDA Suite
dialog_lib_edit_text.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) 2001 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2020 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 #include <fctsys.h>
26 #include <lib_edit_frame.h>
27 #include <lib_text.h>
29 #include <dialog_lib_edit_text.h>
31 #include <pgm_base.h>
33 
34 
36  DIALOG_LIB_EDIT_TEXT_BASE( aParent ),
37  m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
38  m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
39  m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
40 {
41  m_parent = aParent;
42  m_graphicText = aText;
43 
44  // Disable options for fieldedit, not existing in graphic text
45  m_visible->Show( false );
47  m_PowerComponentValues->Show( false );
48 
49  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
50  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
51  m_PowerComponentValues->SetFont( infoFont );
52 
54  m_StyledTextCtrl->Show( false );
55 
56  m_sdbSizerButtonsOK->SetDefault();
57 
58  // Now all widgets have the size fixed, call FinishDialogSettings
60 }
61 
62 
64 {
65  if( m_graphicText )
66  {
70  m_TextCtrl->SetValue( m_graphicText->GetText() );
71 
72  m_italic->SetValue( m_graphicText->IsItalic() );
73  m_bold->SetValue( m_graphicText->IsBold() );
74  m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
75  m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
76  m_orientChoice->SetSelection( m_graphicText->GetTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
77 
78  switch ( m_graphicText->GetHorizJustify() )
79  {
80  case GR_TEXT_HJUSTIFY_LEFT: m_hAlignChoice->SetSelection( 0 ); break;
81  case GR_TEXT_HJUSTIFY_CENTER: m_hAlignChoice->SetSelection( 1 ); break;
82  case GR_TEXT_HJUSTIFY_RIGHT: m_hAlignChoice->SetSelection( 2 ); break;
83  }
84 
85  switch ( m_graphicText->GetVertJustify() )
86  {
87  case GR_TEXT_VJUSTIFY_TOP: m_vAlignChoice->SetSelection( 0 ); break;
88  case GR_TEXT_VJUSTIFY_CENTER: m_vAlignChoice->SetSelection( 1 ); break;
89  case GR_TEXT_VJUSTIFY_BOTTOM: m_vAlignChoice->SetSelection( 2 ); break;
90  }
91  }
92  else
93  {
94  LIBEDIT_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
96 
97  m_textSize.SetValue( Mils2iu( cfg->m_Defaults.text_size ) );
98 
99  m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
100  m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
101  m_orientChoice->SetSelection( tools->GetLastTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
102  }
103 
104  return true;
105 }
106 
107 
109 {
110  if( m_graphicText )
111  {
112  if( m_TextCtrl->GetValue().IsEmpty() )
113  m_graphicText->SetText( wxT( "[null]" ) );
114  else
115  m_graphicText->SetText( m_TextCtrl->GetValue() );
116 
119 
121  : TEXT_ANGLE_HORIZ );
122 
123  if( !m_CommonUnit->GetValue() )
125  else
126  m_graphicText->SetUnit( 0 );
127 
128  if( !m_CommonConvert->GetValue() )
130  else
132 
133  m_graphicText->SetItalic( m_italic->GetValue() );
134  m_graphicText->SetBold( m_bold->GetValue() );
135 
136  switch( m_hAlignChoice->GetSelection() )
137  {
141  }
142 
143  switch( m_vAlignChoice->GetSelection() )
144  {
148  }
149 
150  // Record settings used for next time:
153  tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
154  tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
155  }
156 
158 
159  return true;
160 }
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:185
bool IsBold() const
Definition: eda_text.h:183
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
int GetConvert() const
Define a symbol library graphical text item.
Definition: lib_text.h:40
LIB_DRAWING_TOOLS.
wxPoint GetPosition() const override
Definition: lib_text.h:84
bool TransferDataToWindow() override
void SetItalic(bool isItalic)
Definition: eda_text.h:179
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
double GetTextAngle() const
Definition: eda_text.h:174
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:238
bool TransferDataFromWindow() override
#define TEXT_ANGLE_VERT
Definition: common.h:186
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
bool IsItalic() const
Definition: eda_text.h:180
int GetUnit() const
Definition: lib_item.h:295
int GetUnit() const
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetLastTextAngle(double aAngle)
void SetDrawSpecificUnit(bool aSpecific)
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:203
LIB_EDIT_FRAME * m_parent
int GetConvert() const
Definition: lib_item.h:298
Class DIALOG_LIB_EDIT_TEXT_BASE.
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
The symbol library editor main window.
int GetTextWidth() const
Definition: eda_text.h:242
see class PGM_BASE
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:202
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:248
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:167
void SetDrawSpecificConvert(bool aSpecific)
void SetBold(bool aBold)
Definition: eda_text.h:182
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127