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