KiCad PCB EDA Suite
TITLE_BLOCK Class Reference

Hold the information shown in the lower right corner of a plot, printout, or editing view. More...

#include <title_block.h>

Public Member Functions

 TITLE_BLOCK ()
 
virtual ~TITLE_BLOCK ()
 
void SetTitle (const wxString &aTitle)
 
const wxString & GetTitle () const
 
void SetDate (const wxString &aDate)
 Set the date field, and defaults to the current time and date. More...
 
const wxString & GetDate () const
 
void SetRevision (const wxString &aRevision)
 
const wxString & GetRevision () const
 
void SetCompany (const wxString &aCompany)
 
const wxString & GetCompany () const
 
void SetComment (int aIdx, const wxString &aComment)
 
const wxString & GetComment (int aIdx) const
 
void Clear ()
 
bool TextVarResolver (wxString *aToken, const PROJECT *aProject) const
 
virtual void Format (OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
 Output the object to aFormatter in s-expression form. More...
 

Static Public Member Functions

static void GetContextualTextVars (wxArrayString *aVars)
 

Private Types

enum  TEXTS_IDX {
  TITLE_IDX = 0 , DATE_IDX , REVISION_IDX , COMPANY_IDX ,
  COMMENT1_IDX
}
 

Private Member Functions

void setTbText (int aIdx, const wxString &aText)
 
const wxString & getTbText (int aIdx) const
 

Private Attributes

wxArrayString m_tbTexts
 

Detailed Description

Hold the information shown in the lower right corner of a plot, printout, or editing view.

Definition at line 40 of file title_block.h.

Member Enumeration Documentation

◆ TEXTS_IDX

enum TITLE_BLOCK::TEXTS_IDX
private
Enumerator
TITLE_IDX 
DATE_IDX 
REVISION_IDX 
COMPANY_IDX 
COMMENT1_IDX 

Definition at line 44 of file title_block.h.

45 {
46 TITLE_IDX = 0,
50 COMMENT1_IDX // idx of the first comment: one can have more than 1 comment
51 };

Constructor & Destructor Documentation

◆ TITLE_BLOCK()

TITLE_BLOCK::TITLE_BLOCK ( )
inline

Definition at line 54 of file title_block.h.

54{};

◆ ~TITLE_BLOCK()

virtual TITLE_BLOCK::~TITLE_BLOCK ( )
inlinevirtual

Definition at line 55 of file title_block.h.

55{}; // a virtual dtor seems needed to build

Member Function Documentation

◆ Clear()

void TITLE_BLOCK::Clear ( )
inline

Definition at line 113 of file title_block.h.

114 {
115 m_tbTexts.Clear();
116 }
wxArrayString m_tbTexts
Definition: title_block.h:132

References m_tbTexts.

Referenced by SCH_SCREEN::Clear().

◆ Format()

void TITLE_BLOCK::Format ( OUTPUTFORMATTER aFormatter,
int  aNestLevel,
int  aControlBits 
) const
virtual

Output the object to aFormatter in s-expression form.

Parameters
aFormatterThe OUTPUTFORMATTER object to write to.
aNestLevelThe indentation next level.
aControlBitsThe control bit definition for object specific formatting.
Exceptions
IO_ERRORon write error.

Definition at line 30 of file title_block.cpp.

31{
32 // Don't write the title block information if there is nothing to write.
33 bool isempty = true;
34 for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
35 {
36 if( ! m_tbTexts[idx].IsEmpty() )
37 {
38 isempty = false;
39 break;
40 }
41 }
42
43 if( !isempty )
44 {
45 aFormatter->Print( aNestLevel, "(title_block\n" );
46
47 if( !GetTitle().IsEmpty() )
48 aFormatter->Print( aNestLevel+1, "(title %s)\n",
49 aFormatter->Quotew( GetTitle() ).c_str() );
50
51 if( !GetDate().IsEmpty() )
52 aFormatter->Print( aNestLevel+1, "(date %s)\n",
53 aFormatter->Quotew( GetDate() ).c_str() );
54
55 if( !GetRevision().IsEmpty() )
56 aFormatter->Print( aNestLevel+1, "(rev %s)\n",
57 aFormatter->Quotew( GetRevision() ).c_str() );
58
59 if( !GetCompany().IsEmpty() )
60 aFormatter->Print( aNestLevel+1, "(company %s)\n",
61 aFormatter->Quotew( GetCompany() ).c_str() );
62
63 for( int ii = 0; ii < 9; ii++ )
64 {
65 if( !GetComment(ii).IsEmpty() )
66 aFormatter->Print( aNestLevel+1, "(comment %d %s)\n", ii+1,
67 aFormatter->Quotew( GetComment(ii) ).c_str() );
68 }
69
70 aFormatter->Print( aNestLevel, ")\n\n" );
71 }
72}
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:501
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:433
const wxString & GetCompany() const
Definition: title_block.h:96
const wxString & GetRevision() const
Definition: title_block.h:86
const wxString & GetDate() const
Definition: title_block.h:76
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
const wxString & GetTitle() const
Definition: title_block.h:63

References GetComment(), GetCompany(), GetDate(), GetRevision(), GetTitle(), m_tbTexts, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by SCH_SEXPR_PLUGIN::Format(), and PCB_PLUGIN::formatGeneral().

◆ GetComment()

const wxString & TITLE_BLOCK::GetComment ( int  aIdx) const
inline

◆ GetCompany()

const wxString & TITLE_BLOCK::GetCompany ( ) const
inline

◆ GetContextualTextVars()

void TITLE_BLOCK::GetContextualTextVars ( wxArrayString *  aVars)
static

Definition at line 74 of file title_block.cpp.

75{
76 if( !alg::contains( *aVars, wxT( "ISSUE_DATE" ) ) )
77 {
78 aVars->push_back( wxT( "ISSUE_DATE" ) );
79 aVars->push_back( wxT( "CURRENT_DATE" ) );
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}
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99

References alg::contains().

Referenced by SCH_SHEET::GetContextualTextVars(), SCHEMATIC::GetContextualTextVars(), and DS_DRAW_ITEM_LIST::GetTextVars().

◆ GetDate()

◆ GetRevision()

◆ getTbText()

const wxString & TITLE_BLOCK::getTbText ( int  aIdx) const
inlineprivate

Definition at line 142 of file title_block.h.

143 {
144 static const wxString m_emptytext;
145
146 if( (int)m_tbTexts.GetCount() > aIdx )
147 return m_tbTexts[aIdx];
148 else
149 return m_emptytext;
150 }

References m_tbTexts.

Referenced by GetComment(), GetCompany(), GetDate(), GetRevision(), and GetTitle().

◆ GetTitle()

◆ SetComment()

◆ SetCompany()

◆ SetDate()

◆ SetRevision()

◆ setTbText()

void TITLE_BLOCK::setTbText ( int  aIdx,
const wxString &  aText 
)
inlineprivate

Definition at line 134 of file title_block.h.

135 {
136 if( (int)m_tbTexts.GetCount() <= aIdx )
137 m_tbTexts.Add( wxEmptyString, aIdx + 1 - m_tbTexts.GetCount() );
138
139 m_tbTexts[aIdx] = aText;
140 }

References m_tbTexts.

Referenced by SetComment(), SetCompany(), SetDate(), SetRevision(), and SetTitle().

◆ SetTitle()

◆ TextVarResolver()

bool TITLE_BLOCK::TextVarResolver ( wxString *  aToken,
const PROJECT aProject 
) const

Definition at line 96 of file title_block.cpp.

97{
98 bool tokenUpdated = false;
99 wxString originalToken = *aToken;
100
101 if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
102 {
103 *aToken = GetDate();
104 tokenUpdated = true;
105 }
106 else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
107 {
108 // We can choose different formats. Should probably be kept in sync with ISSUE_DATE
109 // formatting in DIALOG_PAGES_SETTINGS.
110 //
111 // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) );
112 // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
113 // *aToken = wxDateTime::Now().Format( wxT("%Y-%b-%d") );
114 *aToken = wxDateTime::Now().FormatISODate();
115
116 tokenUpdated = true;
117 }
118 else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
119 {
120 *aToken = GetRevision();
121 tokenUpdated = true;
122 }
123 else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
124 {
125 *aToken = GetTitle();
126 tokenUpdated = true;
127 }
128 else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
129 {
130 *aToken = GetCompany();
131 tokenUpdated = true;
132 }
133 else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
134 {
135 wxChar c = aToken->Last();
136
137 switch( c )
138 {
139 case '1':
140 case '2':
141 case '3':
142 case '4':
143 case '5':
144 case '6':
145 case '7':
146 case '8':
147 case '9':
148 *aToken = GetComment( c - '1' );
149 tokenUpdated = true;
150 }
151 }
152
153 if( tokenUpdated )
154 {
155 if( aProject )
156 *aToken = ExpandTextVars( *aToken, aProject );
157
158 // This is the default fallback, so don't claim we resolved it
159 if( *aToken == wxT( "${" ) + originalToken + wxT( "}" ) )
160 return false;
161
162 return true;
163 }
164
165 return false;
166}
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58

References ExpandTextVars(), GetComment(), GetCompany(), GetDate(), GetRevision(), and GetTitle().

Referenced by BOARD::ResolveTextVar(), and SCH_SHEET::ResolveTextVar().

Member Data Documentation

◆ m_tbTexts

wxArrayString TITLE_BLOCK::m_tbTexts
private

Definition at line 132 of file title_block.h.

Referenced by Clear(), Format(), getTbText(), and setTbText().


The documentation for this class was generated from the following files: