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-2021 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 <symbol_edit_frame.h>
26 #include <lib_text.h>
28 #include <dialog_lib_edit_text.h>
30 #include <pgm_base.h>
32 
33 
35  DIALOG_LIB_EDIT_TEXT_BASE( aParent ),
36  m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
37  m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
38  m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
39 {
40  m_parent = aParent;
41  m_graphicText = aText;
42 
43  // Disable options for fieldedit, not existing in graphic text
44  m_visible->Show( false );
46  m_PowerComponentValues->Show( false );
47 
48  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
49  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
50  m_PowerComponentValues->SetFont( infoFont );
51 
53  m_StyledTextCtrl->Show( false );
54 
55  if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
56  {
57  m_sdbSizerButtonsCancel->SetDefault();
58  m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
59  m_sdbSizerButtonsOK->Enable( false );
60  }
61  else
62  {
63  m_sdbSizerButtonsOK->SetDefault();
64  }
65 
66  // Now all widgets have the size fixed, call FinishDialogSettings
68 }
69 
70 
72 {
73  if( m_graphicText )
74  {
78  m_TextCtrl->SetValue( m_graphicText->GetText() );
79 
80  m_italic->SetValue( m_graphicText->IsItalic() );
81  m_bold->SetValue( m_graphicText->IsBold() );
82  m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
83  m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
84  m_orientChoice->SetSelection( m_graphicText->GetTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
85 
86  switch ( m_graphicText->GetHorizJustify() )
87  {
88  case GR_TEXT_HJUSTIFY_LEFT: m_hAlignChoice->SetSelection( 0 ); break;
89  case GR_TEXT_HJUSTIFY_CENTER: m_hAlignChoice->SetSelection( 1 ); break;
90  case GR_TEXT_HJUSTIFY_RIGHT: m_hAlignChoice->SetSelection( 2 ); break;
91  }
92 
93  switch ( m_graphicText->GetVertJustify() )
94  {
95  case GR_TEXT_VJUSTIFY_TOP: m_vAlignChoice->SetSelection( 0 ); break;
96  case GR_TEXT_VJUSTIFY_CENTER: m_vAlignChoice->SetSelection( 1 ); break;
97  case GR_TEXT_VJUSTIFY_BOTTOM: m_vAlignChoice->SetSelection( 2 ); break;
98  }
99  }
100  else
101  {
102  auto* cfg = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
104 
105  m_textSize.SetValue( Mils2iu( cfg->m_Defaults.text_size ) );
106 
107  m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
108  m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
109  m_orientChoice->SetSelection( tools->GetLastTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
110  }
111 
112  return true;
113 }
114 
115 
117 {
118  if( m_graphicText )
119  {
120  if( m_TextCtrl->GetValue().IsEmpty() )
121  m_graphicText->SetText( wxT( "[null]" ) );
122  else
123  m_graphicText->SetText( m_TextCtrl->GetValue() );
124 
127 
129  : TEXT_ANGLE_HORIZ );
130 
131  if( !m_CommonUnit->GetValue() )
133  else
134  m_graphicText->SetUnit( 0 );
135 
136  if( !m_CommonConvert->GetValue() )
138  else
140 
141  m_graphicText->SetItalic( m_italic->GetValue() );
142  m_graphicText->SetBold( m_bold->GetValue() );
143 
144  switch( m_hAlignChoice->GetSelection() )
145  {
149  }
150 
151  switch( m_vAlignChoice->GetSelection() )
152  {
156  }
157 
158  // Record settings used for next time:
160  tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
161  tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
162  tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
163  }
164 
166 
167  return true;
168 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
bool IsBold() const
Definition: eda_text.h:190
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
Define a symbol library graphical text item.
Definition: lib_text.h:39
wxPoint GetPosition() const override
Definition: lib_text.h:93
bool TransferDataToWindow() override
void SetItalic(bool isItalic)
Definition: eda_text.h:186
double GetTextAngle() const
Definition: eda_text.h:181
SYMBOL_EDIT_FRAME * m_parent
DIALOG_LIB_EDIT_TEXT(SYMBOL_EDIT_FRAME *aParent, LIB_TEXT *aText)
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
bool TransferDataFromWindow() override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
bool IsItalic() const
Definition: eda_text.h:187
int GetUnit() const
Definition: lib_item.h:260
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
bool IsSymbolAlias() const
Restore the empty editor screen, without any part or library selected.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
int GetConvert() const
Definition: lib_item.h:263
Class DIALOG_LIB_EDIT_TEXT_BASE.
void SetConvert(int aConvert)
Definition: lib_item.h:262
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetUnit(int aUnit)
Definition: lib_item.h:259
int GetTextWidth() const
Definition: eda_text.h:248
see class PGM_BASE
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:213
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:174
void SetBold(bool aBold)
Definition: eda_text.h:189
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
SYMBOL_EDITOR_DRAWING_TOOLS.
The symbol library editor main window.