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
Format(OUTPUTFORMATTER * aFormatter,int aNestLevel,int aControlBits) const29 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
GetContextualTextVars(wxArrayString * aVars)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
TextVarResolver(wxString * aToken,const PROJECT * aProject) const91 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( "CURRENT_DATE" ) ) )
101 {
102 // We can choose different formats. Should probably be kept in sync with ISSUE_DATE
103 // formatting in DIALOG_PAGES_SETTINGS.
104 //
105 // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
106 // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
107 // *aToken = wxDateTime::Now().Format( wxT("%Y-%b-%d") );
108 *aToken = wxDateTime::Now().FormatISODate();
109
110 tokenUpdated = true;
111 }
112 else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
113 {
114 *aToken = GetRevision();
115 tokenUpdated = true;
116 }
117 else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
118 {
119 *aToken = GetTitle();
120 tokenUpdated = true;
121 }
122 else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
123 {
124 *aToken = GetCompany();
125 tokenUpdated = true;
126 }
127 else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
128 {
129 wxChar c = aToken->Last();
130
131 switch( c )
132 {
133 case '1':
134 case '2':
135 case '3':
136 case '4':
137 case '5':
138 case '6':
139 case '7':
140 case '8':
141 case '9':
142 *aToken = GetComment( c - '1' );
143 tokenUpdated = true;
144 }
145 }
146
147 if( tokenUpdated )
148 {
149 *aToken = ExpandTextVars( *aToken, aProject );
150 return true;
151 }
152
153 return false;
154 }
155
156
157