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.

166 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef CLASS_TITLE_BLOCK_H_
  24. #define CLASS_TITLE_BLOCK_H_
  25. #include <wx/string.h>
  26. class OUTPUTFORMATTER;
  27. class IO_ERROR;
  28. /**
  29. * Class TITLE_BLOCK
  30. * holds the information shown in the lower right corner of a plot, printout, or
  31. * editing view.
  32. *
  33. * @author Dick Hollenbeck
  34. */
  35. class TITLE_BLOCK
  36. {
  37. // Texts are stored in wxArraystring.
  38. // textsIdx gives the index of known texts in
  39. // this array
  40. enum textsIdx
  41. {
  42. titleIdx = 0,
  43. dateIdx,
  44. revisionIdx,
  45. companyIdx,
  46. m_commentIdx
  47. };
  48. public:
  49. TITLE_BLOCK() {};
  50. virtual ~TITLE_BLOCK() {}; // a virtual dtor seems needed to build
  51. // python lib without warning
  52. void SetTitle( const wxString& aTitle )
  53. {
  54. setTbText( titleIdx, aTitle );
  55. }
  56. const wxString& GetTitle() const
  57. {
  58. return getTbText( titleIdx );
  59. }
  60. /**
  61. * Function SetDate
  62. * sets the date field, and defaults to the current time and date.
  63. */
  64. void SetDate( const wxString& aDate )
  65. {
  66. setTbText( dateIdx, aDate );
  67. }
  68. const wxString& GetDate() const
  69. {
  70. return getTbText( dateIdx );
  71. }
  72. void SetRevision( const wxString& aRevision )
  73. {
  74. setTbText( revisionIdx, aRevision );
  75. }
  76. const wxString& GetRevision() const
  77. {
  78. return getTbText( revisionIdx );
  79. }
  80. void SetCompany( const wxString& aCompany )
  81. {
  82. setTbText( companyIdx, aCompany );
  83. }
  84. const wxString& GetCompany() const
  85. {
  86. return getTbText( companyIdx );
  87. }
  88. void SetComment( int aIdx, const wxString& aComment )
  89. {
  90. aIdx += m_commentIdx;
  91. return setTbText( aIdx, aComment );
  92. }
  93. const wxString& GetComment( int aIdx ) const
  94. {
  95. aIdx += m_commentIdx;
  96. return getTbText( aIdx );
  97. }
  98. // Only for old code compatibility. Will be removed later
  99. void SetComment1( const wxString& aComment ) { SetComment( 0, aComment ); }
  100. void SetComment2( const wxString& aComment ) { SetComment( 1, aComment ); }
  101. void SetComment3( const wxString& aComment ) { SetComment( 2, aComment ); }
  102. void SetComment4( const wxString& aComment ) { SetComment( 3, aComment ); }
  103. const wxString& GetComment1( ) const { return GetComment( 0 ); }
  104. const wxString& GetComment2( ) const { return GetComment( 1 ); }
  105. const wxString& GetComment3( ) const { return GetComment( 2 ); }
  106. const wxString& GetComment4( ) const { return GetComment( 3 ); }
  107. void Clear()
  108. {
  109. m_tbTexts.Clear();
  110. }
  111. /**
  112. * Function Format
  113. * outputs the object to \a aFormatter in s-expression form.
  114. *
  115. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  116. * @param aNestLevel The indentation next level.
  117. * @param aControlBits The control bit definition for object specific formatting.
  118. * @throw IO_ERROR on write error.
  119. */
  120. virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  121. throw( IO_ERROR );
  122. private:
  123. wxArrayString m_tbTexts;
  124. void setTbText( int aIdx, const wxString& aText )
  125. {
  126. if( (int)m_tbTexts.GetCount() <= aIdx )
  127. m_tbTexts.Add( wxEmptyString, aIdx + 1 - m_tbTexts.GetCount() );
  128. m_tbTexts[aIdx] = aText;
  129. }
  130. const wxString& getTbText( int aIdx ) const
  131. {
  132. static const wxString m_emptytext;
  133. if( (int)m_tbTexts.GetCount() > aIdx )
  134. return m_tbTexts[aIdx];
  135. else
  136. return m_emptytext;
  137. }
  138. };
  139. #endif // CLASS_TITLE_BLOCK_H_