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>
31 
32 
34  DIALOG_LIB_EDIT_TEXT_BASE( aParent ),
35  m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
36  m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
37  m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
38 {
39  m_parent = aParent;
40  m_graphicText = aText;
41 
42  // Disable options for fieldedit, not existing in graphic text
43  m_visible->Show( false );
45  m_PowerComponentValues->Show( false );
46 
48 
50  m_StyledTextCtrl->Show( false );
51 
52  if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
53  {
54  m_sdbSizerButtonsCancel->SetDefault();
55  m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
56  m_sdbSizerButtonsOK->Enable( false );
57  }
58  else
59  {
60  m_sdbSizerButtonsOK->SetDefault();
61  }
62 
63  // Now all widgets have the size fixed, call FinishDialogSettings
65 }
66 
67 
69 {
70  if( m_graphicText )
71  {
75  m_TextCtrl->SetValue( m_graphicText->GetText() );
76 
77  m_italic->SetValue( m_graphicText->IsItalic() );
78  m_bold->SetValue( m_graphicText->IsBold() );
79  m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
80  m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
81  m_orientChoice->SetSelection( m_graphicText->GetTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
82 
83  switch ( m_graphicText->GetHorizJustify() )
84  {
85  case GR_TEXT_HJUSTIFY_LEFT: m_hAlignChoice->SetSelection( 0 ); break;
86  case GR_TEXT_HJUSTIFY_CENTER: m_hAlignChoice->SetSelection( 1 ); break;
87  case GR_TEXT_HJUSTIFY_RIGHT: m_hAlignChoice->SetSelection( 2 ); break;
88  }
89 
90  switch ( m_graphicText->GetVertJustify() )
91  {
92  case GR_TEXT_VJUSTIFY_TOP: m_vAlignChoice->SetSelection( 0 ); break;
93  case GR_TEXT_VJUSTIFY_CENTER: m_vAlignChoice->SetSelection( 1 ); break;
94  case GR_TEXT_VJUSTIFY_BOTTOM: m_vAlignChoice->SetSelection( 2 ); break;
95  }
96  }
97  else
98  {
101 
102  m_textSize.SetValue( Mils2iu( cfg->m_Defaults.text_size ) );
103 
104  m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
105  m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
106  m_orientChoice->SetSelection( tools->GetLastTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
107  }
108 
109  return true;
110 }
111 
112 
114 {
115  if( m_graphicText )
116  {
117  if( m_TextCtrl->GetValue().IsEmpty() )
118  m_graphicText->SetText( wxT( "[null]" ) );
119  else
120  m_graphicText->SetText( m_TextCtrl->GetValue() );
121 
124 
126  : TEXT_ANGLE_HORIZ );
127 
128  if( !m_CommonUnit->GetValue() )
130  else
131  m_graphicText->SetUnit( 0 );
132 
133  if( !m_CommonConvert->GetValue() )
135  else
137 
138  m_graphicText->SetItalic( m_italic->GetValue() );
139  m_graphicText->SetBold( m_bold->GetValue() );
140 
141  switch( m_hAlignChoice->GetSelection() )
142  {
146  }
147 
148  switch( m_vAlignChoice->GetSelection() )
149  {
153  }
154 
155  // Record settings used for next time:
157  tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
158  tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
159  tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
160  }
161 
163 
164  return true;
165 }
#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:183
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
Define a symbol library graphical text item.
Definition: lib_text.h:39
SYMBOL_EDITOR_SETTINGS * GetSettings() const
wxPoint GetPosition() const override
Definition: lib_text.h:93
bool TransferDataToWindow() override
void SetItalic(bool isItalic)
Definition: eda_text.h:179
double GetTextAngle() const
Definition: eda_text.h:174
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:237
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:97
bool IsItalic() const
Definition: eda_text.h:180
int GetUnit() const
Definition: lib_item.h:259
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
bool IsSymbolAlias() const
Restore the empty editor screen, without any symbol 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:202
#define _(s)
int GetConvert() const
Definition: lib_item.h:262
Class DIALOG_LIB_EDIT_TEXT_BASE.
void SetConvert(int aConvert)
Definition: lib_item.h:261
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:258
int GetTextWidth() const
Definition: eda_text.h:241
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
wxFont GetInfoFont()
Definition: ui_common.cpp:97
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
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:212
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:167
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:133
SYMBOL_EDITOR_DRAWING_TOOLS.
The symbol library editor main window.