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.

156 lines
4.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  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 <richio.h>
  25. #include <common.h>
  26. #include <title_block.h>
  27. void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  28. {
  29. // Don't write the title block information if there is nothing to write.
  30. bool isempty = true;
  31. for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
  32. {
  33. if( ! m_tbTexts[idx].IsEmpty() )
  34. {
  35. isempty = false;
  36. break;
  37. }
  38. }
  39. if( !isempty )
  40. {
  41. aFormatter->Print( aNestLevel, "(title_block\n" );
  42. if( !GetTitle().IsEmpty() )
  43. aFormatter->Print( aNestLevel+1, "(title %s)\n",
  44. aFormatter->Quotew( GetTitle() ).c_str() );
  45. if( !GetDate().IsEmpty() )
  46. aFormatter->Print( aNestLevel+1, "(date %s)\n",
  47. aFormatter->Quotew( GetDate() ).c_str() );
  48. if( !GetRevision().IsEmpty() )
  49. aFormatter->Print( aNestLevel+1, "(rev %s)\n",
  50. aFormatter->Quotew( GetRevision() ).c_str() );
  51. if( !GetCompany().IsEmpty() )
  52. aFormatter->Print( aNestLevel+1, "(company %s)\n",
  53. aFormatter->Quotew( GetCompany() ).c_str() );
  54. for( int ii = 0; ii < 9; ii++ )
  55. {
  56. if( !GetComment(ii).IsEmpty() )
  57. aFormatter->Print( aNestLevel+1, "(comment %d %s)\n", ii+1,
  58. aFormatter->Quotew( GetComment(ii) ).c_str() );
  59. }
  60. aFormatter->Print( aNestLevel, ")\n\n" );
  61. }
  62. }
  63. void TITLE_BLOCK::GetContextualTextVars( wxArrayString* aVars )
  64. {
  65. aVars->push_back( wxT( "ISSUE_DATE" ) );
  66. aVars->push_back( wxT( "REVISION" ) );
  67. aVars->push_back( wxT( "TITLE" ) );
  68. aVars->push_back( wxT( "COMPANY" ) );
  69. aVars->push_back( wxT( "COMMENT1" ) );
  70. aVars->push_back( wxT( "COMMENT2" ) );
  71. aVars->push_back( wxT( "COMMENT3" ) );
  72. aVars->push_back( wxT( "COMMENT4" ) );
  73. aVars->push_back( wxT( "COMMENT5" ) );
  74. aVars->push_back( wxT( "COMMENT6" ) );
  75. aVars->push_back( wxT( "COMMENT7" ) );
  76. aVars->push_back( wxT( "COMMENT8" ) );
  77. aVars->push_back( wxT( "COMMENT9" ) );
  78. }
  79. bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) const
  80. {
  81. bool tokenUpdated = false;
  82. if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
  83. {
  84. *aToken = GetDate();
  85. tokenUpdated = true;
  86. }
  87. else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
  88. {
  89. // We can choose different formats. Should probably be kept in sync with ISSUE_DATE
  90. // formatting in DIALOG_PAGES_SETTINGS.
  91. //
  92. // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
  93. // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
  94. // *aToken = wxDateTime::Now().Format( wxT("%Y-%b-%d") );
  95. *aToken = wxDateTime::Now().FormatISODate();
  96. tokenUpdated = true;
  97. }
  98. else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
  99. {
  100. *aToken = GetRevision();
  101. tokenUpdated = true;
  102. }
  103. else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
  104. {
  105. *aToken = GetTitle();
  106. tokenUpdated = true;
  107. }
  108. else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
  109. {
  110. *aToken = GetCompany();
  111. tokenUpdated = true;
  112. }
  113. else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
  114. {
  115. wxChar c = aToken->Last();
  116. switch( c )
  117. {
  118. case '1':
  119. case '2':
  120. case '3':
  121. case '4':
  122. case '5':
  123. case '6':
  124. case '7':
  125. case '8':
  126. case '9':
  127. *aToken = GetComment( c - '1' );
  128. tokenUpdated = true;
  129. }
  130. }
  131. if( tokenUpdated )
  132. {
  133. *aToken = ExpandTextVars( *aToken, aProject );
  134. return true;
  135. }
  136. return false;
  137. }