You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
6.1 KiB

  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. #include <fctsys.h>
  25. #include <lib_edit_frame.h>
  26. #include <lib_text.h>
  27. #include <settings/settings_manager.h>
  28. #include <dialog_lib_edit_text.h>
  29. #include <libedit/libedit_settings.h>
  30. #include <pgm_base.h>
  31. #include <tools/lib_drawing_tools.h>
  32. DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText ) :
  33. DIALOG_LIB_EDIT_TEXT_BASE( aParent ),
  34. m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
  35. m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
  36. m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
  37. {
  38. m_parent = aParent;
  39. m_graphicText = aText;
  40. // Disable options for fieldedit, not existing in graphic text
  41. m_visible->Show( false );
  42. m_TextValueSelectButton->Hide();
  43. m_PowerComponentValues->Show( false );
  44. wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  45. infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
  46. m_PowerComponentValues->SetFont( infoFont );
  47. SetInitialFocus( m_TextCtrl );
  48. m_StyledTextCtrl->Show( false );
  49. m_sdbSizerButtonsOK->SetDefault();
  50. // Now all widgets have the size fixed, call FinishDialogSettings
  51. FinishDialogSettings();
  52. }
  53. bool DIALOG_LIB_EDIT_TEXT::TransferDataToWindow()
  54. {
  55. if( m_graphicText )
  56. {
  57. m_posX.SetValue( m_graphicText->GetPosition().x );
  58. m_posY.SetValue( m_graphicText->GetPosition().y );
  59. m_textSize.SetValue( m_graphicText->GetTextWidth() );
  60. m_TextCtrl->SetValue( m_graphicText->GetText() );
  61. m_italic->SetValue( m_graphicText->IsItalic() );
  62. m_bold->SetValue( m_graphicText->IsBold() );
  63. m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
  64. m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
  65. m_orientChoice->SetSelection( m_graphicText->GetTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
  66. switch ( m_graphicText->GetHorizJustify() )
  67. {
  68. case GR_TEXT_HJUSTIFY_LEFT: m_hAlignChoice->SetSelection( 0 ); break;
  69. case GR_TEXT_HJUSTIFY_CENTER: m_hAlignChoice->SetSelection( 1 ); break;
  70. case GR_TEXT_HJUSTIFY_RIGHT: m_hAlignChoice->SetSelection( 2 ); break;
  71. }
  72. switch ( m_graphicText->GetVertJustify() )
  73. {
  74. case GR_TEXT_VJUSTIFY_TOP: m_vAlignChoice->SetSelection( 0 ); break;
  75. case GR_TEXT_VJUSTIFY_CENTER: m_vAlignChoice->SetSelection( 1 ); break;
  76. case GR_TEXT_VJUSTIFY_BOTTOM: m_vAlignChoice->SetSelection( 2 ); break;
  77. }
  78. }
  79. else
  80. {
  81. LIBEDIT_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
  82. LIB_DRAWING_TOOLS* tools = m_parent->GetToolManager()->GetTool<LIB_DRAWING_TOOLS>();
  83. m_textSize.SetValue( Mils2iu( cfg->m_Defaults.text_size ) );
  84. m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
  85. m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
  86. m_orientChoice->SetSelection( tools->GetLastTextAngle() == TEXT_ANGLE_HORIZ ? 0 : 1 );
  87. }
  88. return true;
  89. }
  90. bool DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow()
  91. {
  92. if( m_graphicText )
  93. {
  94. if( m_TextCtrl->GetValue().IsEmpty() )
  95. m_graphicText->SetText( wxT( "[null]" ) );
  96. else
  97. m_graphicText->SetText( m_TextCtrl->GetValue() );
  98. m_graphicText->SetPosition( wxPoint( m_posX.GetValue(), m_posY.GetValue() ) );
  99. m_graphicText->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
  100. m_graphicText->SetTextAngle( m_orientChoice->GetSelection() ? TEXT_ANGLE_VERT
  101. : TEXT_ANGLE_HORIZ );
  102. if( !m_CommonUnit->GetValue() )
  103. m_graphicText->SetUnit( m_parent->GetUnit() );
  104. else
  105. m_graphicText->SetUnit( 0 );
  106. if( !m_CommonConvert->GetValue() )
  107. m_graphicText->SetConvert( m_parent->GetConvert() );
  108. else
  109. m_graphicText->SetConvert( 0 );
  110. m_graphicText->SetItalic( m_italic->GetValue() );
  111. m_graphicText->SetBold( m_bold->GetValue() );
  112. switch( m_hAlignChoice->GetSelection() )
  113. {
  114. case 0: m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
  115. case 1: m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
  116. case 2: m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
  117. }
  118. switch( m_vAlignChoice->GetSelection() )
  119. {
  120. case 0: m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
  121. case 1: m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
  122. case 2: m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
  123. }
  124. // Record settings used for next time:
  125. LIB_DRAWING_TOOLS* tools = m_parent->GetToolManager()->GetTool<LIB_DRAWING_TOOLS>();
  126. tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
  127. tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
  128. tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
  129. }
  130. m_parent->SetMsgPanel( m_graphicText );
  131. return true;
  132. }