KiCad PCB EDA Suite
title_block.cpp
Go to the documentation of this file.
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 
25 #include <richio.h>
26 #include <common.h>
27 #include <title_block.h>
28 
29 void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
30 {
31  // Don't write the title block information if there is nothing to write.
32  bool isempty = true;
33  for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
34  {
35  if( ! m_tbTexts[idx].IsEmpty() )
36  {
37  isempty = false;
38  break;
39  }
40  }
41 
42  if( !isempty )
43  {
44  aFormatter->Print( aNestLevel, "(title_block\n" );
45 
46  if( !GetTitle().IsEmpty() )
47  aFormatter->Print( aNestLevel+1, "(title %s)\n",
48  aFormatter->Quotew( GetTitle() ).c_str() );
49 
50  if( !GetDate().IsEmpty() )
51  aFormatter->Print( aNestLevel+1, "(date %s)\n",
52  aFormatter->Quotew( GetDate() ).c_str() );
53 
54  if( !GetRevision().IsEmpty() )
55  aFormatter->Print( aNestLevel+1, "(rev %s)\n",
56  aFormatter->Quotew( GetRevision() ).c_str() );
57 
58  if( !GetCompany().IsEmpty() )
59  aFormatter->Print( aNestLevel+1, "(company %s)\n",
60  aFormatter->Quotew( GetCompany() ).c_str() );
61 
62  for( int ii = 0; ii < 9; ii++ )
63  {
64  if( !GetComment(ii).IsEmpty() )
65  aFormatter->Print( aNestLevel+1, "(comment %d %s)\n", ii+1,
66  aFormatter->Quotew( GetComment(ii) ).c_str() );
67  }
68 
69  aFormatter->Print( aNestLevel, ")\n\n" );
70  }
71 }
72 
73 void TITLE_BLOCK::GetContextualTextVars( wxArrayString* aVars )
74 {
75  aVars->push_back( wxT( "ISSUE_DATE" ) );
76  aVars->push_back( wxT( "REVISION" ) );
77  aVars->push_back( wxT( "TITLE" ) );
78  aVars->push_back( wxT( "COMPANY" ) );
79  aVars->push_back( wxT( "COMMENT1" ) );
80  aVars->push_back( wxT( "COMMENT2" ) );
81  aVars->push_back( wxT( "COMMENT3" ) );
82  aVars->push_back( wxT( "COMMENT4" ) );
83  aVars->push_back( wxT( "COMMENT5" ) );
84  aVars->push_back( wxT( "COMMENT6" ) );
85  aVars->push_back( wxT( "COMMENT7" ) );
86  aVars->push_back( wxT( "COMMENT8" ) );
87  aVars->push_back( wxT( "COMMENT9" ) );
88 }
89 
90 
91 bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) const
92 {
93  bool tokenUpdated = false;
94 
95  if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
96  {
97  *aToken = GetDate();
98  tokenUpdated = true;
99  }
100  else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
101  {
102  *aToken = GetRevision();
103  tokenUpdated = true;
104  }
105  else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
106  {
107  *aToken = GetTitle();
108  tokenUpdated = true;
109  }
110  else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
111  {
112  *aToken = GetCompany();
113  tokenUpdated = true;
114  }
115  else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
116  {
117  wxChar c = aToken->Last();
118 
119  switch( c )
120  {
121  case '1':
122  case '2':
123  case '3':
124  case '4':
125  case '5':
126  case '6':
127  case '7':
128  case '8':
129  case '9':
130  *aToken = GetComment( c - '1' );
131  tokenUpdated = true;
132  }
133  }
134 
135  if( tokenUpdated )
136  {
137  *aToken = ExpandTextVars( *aToken, aProject );
138  return true;
139  }
140 
141  return false;
142 }
143 
144 
Container for project specific data.
Definition: project.h:62
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:306
static void GetContextualTextVars(wxArrayString *aVars)
Definition: title_block.cpp:73
wxArrayString m_tbTexts
Definition: title_block.h:132
const wxString & GetRevision() const
Definition: title_block.h:86
const wxString & GetCompany() const
Definition: title_block.h:96
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:29
const wxString & GetDate() const
Definition: title_block.h:76
The common library.
bool TextVarResolver(wxString *aToken, const PROJECT *aProject) const
Definition: title_block.cpp:91
const wxString & GetTitle() const
Definition: title_block.h:63
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476