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.

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