KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <richio.h>
22#include <common.h>
23#include <title_block.h>
25#include <core/kicad_algo.h>
26
27
28void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter ) const
29{
30 // Don't write the title block information if there is nothing to write.
31 bool isempty = true;
32 for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
33 {
34 if( ! m_tbTexts[idx].IsEmpty() )
35 {
36 isempty = false;
37 break;
38 }
39 }
40
41 if( !isempty )
42 {
43 aFormatter->Print( "(title_block" );
44
45 if( !GetTitle().IsEmpty() )
46 aFormatter->Print( "(title %s)", aFormatter->Quotew( GetTitle() ).c_str() );
47
48 if( !GetDate().IsEmpty() )
49 aFormatter->Print( "(date %s)", aFormatter->Quotew( GetDate() ).c_str() );
50
51 if( !GetRevision().IsEmpty() )
52 aFormatter->Print( "(rev %s)", aFormatter->Quotew( GetRevision() ).c_str() );
53
54 if( !GetCompany().IsEmpty() )
55 aFormatter->Print( "(company %s)", aFormatter->Quotew( GetCompany() ).c_str() );
56
57 for( int ii = 0; ii < 9; ii++ )
58 {
59 if( !GetComment(ii).IsEmpty() )
60 {
61 aFormatter->Print( "(comment %d %s)",
62 ii+1,
63 aFormatter->Quotew( GetComment(ii) ).c_str() );
64 }
65 }
66
67 aFormatter->Print( ")" );
68 }
69}
70
71
72void TITLE_BLOCK::GetContextualTextVars( wxArrayString* aVars )
73{
74 if( !alg::contains( *aVars, wxT( "ISSUE_DATE" ) ) )
75 {
76 aVars->push_back( wxT( "ISSUE_DATE" ) );
77 aVars->push_back( wxT( "CURRENT_DATE" ) );
78 aVars->push_back( wxT( "CURRENT_TIME_LOCALE" ) );
79 aVars->push_back( wxT( "CURRENT_TIME_HH_MM_SS" ) );
80 aVars->push_back( wxT( "REVISION" ) );
81 aVars->push_back( wxT( "TITLE" ) );
82 aVars->push_back( wxT( "COMPANY" ) );
83 aVars->push_back( wxT( "COMMENT1" ) );
84 aVars->push_back( wxT( "COMMENT2" ) );
85 aVars->push_back( wxT( "COMMENT3" ) );
86 aVars->push_back( wxT( "COMMENT4" ) );
87 aVars->push_back( wxT( "COMMENT5" ) );
88 aVars->push_back( wxT( "COMMENT6" ) );
89 aVars->push_back( wxT( "COMMENT7" ) );
90 aVars->push_back( wxT( "COMMENT8" ) );
91 aVars->push_back( wxT( "COMMENT9" ) );
92 }
93}
94
95
97{
98 // We can choose different formats. Should probably be kept in sync with ISSUE_DATE
99 // formatting in DIALOG_PAGES_SETTINGS.
100 //
101 // return wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
102 // return wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
103 // return wxDateTime::Now().Format( wxT("%Y-%b-%d") );
104 return TEXT_EVAL::ENVIRONMENT::CurrentTime().FormatISODate();
105};
106
107
109{
110 // Returns time in HHhMMmSSs format (e.g., "19h23m42s").
111 // Uses letters as separators to be safe for filenames (':' can't be used as a separator).
112 return TEXT_EVAL::ENVIRONMENT::CurrentTime().Format( wxT( "%Hh%Mm%Ss" ) );
113}
114
115
117{
118 // Returns time formatted according to the current locale (e.g., "7:23:42 PM" or "19:23:42").
119 return TEXT_EVAL::ENVIRONMENT::CurrentTime().FormatTime();
120}
121
122
123bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject, RESOLUTION_CONTEXT aContext ) const
124{
125 bool tokenUpdated = false;
126 wxString originalToken = *aToken;
127
128 if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
129 {
130 *aToken = GetDate();
131 tokenUpdated = true;
132 }
133 else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
134 {
135 *aToken = GetCurrentDate();
136 tokenUpdated = true;
137 }
138 else if( aToken->IsSameAs( wxT( "CURRENT_TIME_HH_MM_SS" ) ) )
139 {
140 *aToken = GetCurrentTimeHHMMSS();
141 tokenUpdated = true;
142 }
143 else if( aToken->IsSameAs( wxT( "CURRENT_TIME_LOCALE" ) ) )
144 {
145 *aToken = GetCurrentTimeLocale();
146 tokenUpdated = true;
147 }
148 else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
149 {
150 *aToken = GetRevision();
151 tokenUpdated = true;
152 }
153 else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
154 {
155 *aToken = GetTitle();
156 tokenUpdated = true;
157 }
158 else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
159 {
160 *aToken = GetCompany();
161 tokenUpdated = true;
162 }
163 else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
164 {
165 wxChar c = aToken->Last();
166
167 switch( c )
168 {
169 case '1':
170 case '2':
171 case '3':
172 case '4':
173 case '5':
174 case '6':
175 case '7':
176 case '8':
177 case '9':
178 *aToken = GetComment( c - '1' );
179 tokenUpdated = true;
180 }
181 }
182
183 if( tokenUpdated )
184 {
185 if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
186 *aToken = GetCurrentDate();
187 else if( aProject )
188 *aToken = ExpandTextVars( *aToken, aProject, aContext );
189
190 // This is the default fallback, so don't claim we resolved it
191 if( *aToken == wxT( "${" ) + originalToken + wxT( "}" ) )
192 return false;
193
194 return true;
195 }
196
197 return false;
198}
199
200
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:505
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:432
Container for project specific data.
Definition project.h:63
static wxDateTime CurrentTime()
const wxString & GetCompany() const
Definition title_block.h:93
static wxString GetCurrentTimeLocale()
bool TextVarResolver(wxString *aToken, const PROJECT *aProject, RESOLUTION_CONTEXT aContext) const
const wxString & GetRevision() const
Definition title_block.h:83
static wxString GetCurrentTimeHHMMSS()
const wxString & GetDate() const
Definition title_block.h:73
const wxString & GetComment(int aIdx) const
wxArrayString m_tbTexts
const wxString & GetTitle() const
Definition title_block.h:60
static wxString GetCurrentDate()
virtual void Format(OUTPUTFORMATTER *aFormatter) const
Output the object to aFormatter in s-expression form.
static void GetContextualTextVars(wxArrayString *aVars)
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
RESOLUTION_CONTEXT
Definition common.h:87
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96