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.

153 lines
4.0 KiB

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