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.

164 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 TITLE_BLOCK_H
  24. #define TITLE_BLOCK_H
  25. #include <wx/string.h>
  26. #include <wx/arrstr.h>
  27. #include <ki_exception.h>
  28. class OUTPUTFORMATTER;
  29. /**
  30. * Class TITLE_BLOCK
  31. * holds the information shown in the lower right corner of a plot, printout, or
  32. * editing view.
  33. *
  34. * @author Dick Hollenbeck
  35. */
  36. class TITLE_BLOCK
  37. {
  38. // Texts are stored in wxArraystring.
  39. // textsIdx gives the index of known texts in
  40. // this array
  41. enum textsIdx
  42. {
  43. titleIdx = 0,
  44. dateIdx,
  45. revisionIdx,
  46. companyIdx,
  47. m_commentIdx
  48. };
  49. public:
  50. TITLE_BLOCK() {};
  51. virtual ~TITLE_BLOCK() {}; // a virtual dtor seems needed to build
  52. // python lib without warning
  53. void SetTitle( const wxString& aTitle )
  54. {
  55. setTbText( titleIdx, aTitle );
  56. }
  57. const wxString& GetTitle() const
  58. {
  59. return getTbText( titleIdx );
  60. }
  61. /**
  62. * Function SetDate
  63. * sets the date field, and defaults to the current time and date.
  64. */
  65. void SetDate( const wxString& aDate )
  66. {
  67. setTbText( dateIdx, aDate );
  68. }
  69. const wxString& GetDate() const
  70. {
  71. return getTbText( dateIdx );
  72. }
  73. void SetRevision( const wxString& aRevision )
  74. {
  75. setTbText( revisionIdx, aRevision );
  76. }
  77. const wxString& GetRevision() const
  78. {
  79. return getTbText( revisionIdx );
  80. }
  81. void SetCompany( const wxString& aCompany )
  82. {
  83. setTbText( companyIdx, aCompany );
  84. }
  85. const wxString& GetCompany() const
  86. {
  87. return getTbText( companyIdx );
  88. }
  89. void SetComment( int aIdx, const wxString& aComment )
  90. {
  91. aIdx += m_commentIdx;
  92. return setTbText( aIdx, aComment );
  93. }
  94. const wxString& GetComment( int aIdx ) const
  95. {
  96. aIdx += m_commentIdx;
  97. return getTbText( aIdx );
  98. }
  99. // Only for old code compatibility. Will be removed later
  100. void SetComment1( const wxString& aComment ) { SetComment( 0, aComment ); }
  101. void SetComment2( const wxString& aComment ) { SetComment( 1, aComment ); }
  102. void SetComment3( const wxString& aComment ) { SetComment( 2, aComment ); }
  103. void SetComment4( const wxString& aComment ) { SetComment( 3, aComment ); }
  104. const wxString& GetComment1( ) const { return GetComment( 0 ); }
  105. const wxString& GetComment2( ) const { return GetComment( 1 ); }
  106. const wxString& GetComment3( ) const { return GetComment( 2 ); }
  107. const wxString& GetComment4( ) const { return GetComment( 3 ); }
  108. void Clear()
  109. {
  110. m_tbTexts.Clear();
  111. }
  112. /**
  113. * Function Format
  114. * outputs the object to \a aFormatter in s-expression form.
  115. *
  116. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  117. * @param aNestLevel The indentation next level.
  118. * @param aControlBits The control bit definition for object specific formatting.
  119. * @throw IO_ERROR on write error.
  120. */
  121. virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
  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 // TITLE_BLOCK_H