KiCad PCB EDA Suite
worksheet.cpp
Go to the documentation of this file.
1 
8 /*
9  * This program source code file is part of KiCad, a free EDA CAD application.
10  *
11  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
12  *
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, you may find one here:
26  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
27  * or you may search the http://www.gnu.org website for the version 2 license,
28  * or you may write to the Free Software Foundation, Inc.,
29  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30  */
31 
32 
33 #include <fctsys.h>
34 #include <pgm_base.h>
35 #include <gr_basic.h>
36 #include <common.h>
37 #include <base_screen.h>
38 #include <draw_frame.h>
39 #include <worksheet.h>
40 #include <title_block.h>
41 #include <build_version.h>
42 
44 
45 
46 static const wxString productName = wxT( "KiCad E.D.A. " );
47 
48 // returns the full text corresponding to the aTextbase,
49 // after replacing format symbols by the corresponding value
50 wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
51 {
52  wxString msg;
53 
54  /* Known formats
55  * %% = replaced by %
56  * %K = Kicad version
57  * %Z = paper format name (A4, USLetter)
58  * %Y = company name
59  * %D = date
60  * %R = revision
61  * %S = sheet number
62  * %N = number of sheets
63  * %L = layer name
64  * %Cx = comment (x = 0 to 9 to identify the comment)
65  * %F = filename
66  * %P = sheet path (sheet full name)
67  * %T = title
68  */
69 
70  for( unsigned ii = 0; ii < aTextbase.Len(); ii++ )
71  {
72  if( aTextbase[ii] != '%' )
73  {
74  msg << aTextbase[ii];
75  continue;
76  }
77 
78  if( ++ii >= aTextbase.Len() )
79  break;
80 
81  wxChar format = aTextbase[ii];
82  switch( format )
83  {
84  case '%':
85  msg += '%';
86  break;
87 
88  case 'D':
89  msg += m_titleBlock->GetDate();
90  break;
91 
92  case 'R':
93  msg += m_titleBlock->GetRevision();
94  break;
95 
96  case 'K':
97  msg += productName + Pgm().App().GetAppName();
98  msg += wxT( " " ) + GetBuildVersion();
99  break;
100 
101  case 'Z':
102  if( m_paperFormat )
103  msg += *m_paperFormat;
104  break;
105 
106  case 'S':
107  msg << m_sheetNumber;
108  break;
109 
110  case 'N':
111  msg << m_sheetCount;
112  break;
113 
114  case 'F':
115  {
116  wxFileName fn( m_fileName );
117  msg += fn.GetFullName();
118  }
119  break;
120 
121  case 'L':
122  if( m_sheetLayer )
123  msg += *m_sheetLayer;
124  break;
125 
126  case 'P':
127  msg += m_sheetFullName;
128  break;
129 
130  case 'Y':
131  msg += m_titleBlock->GetCompany();
132  break;
133 
134  case 'T':
135  msg += m_titleBlock->GetTitle();
136  break;
137 
138  case 'C':
139  format = aTextbase[++ii];
140  switch( format )
141  {
142  case '0':
143  case '1':
144  case '2':
145  case '3':
146  case '4':
147  case '5':
148  case '6':
149  case '7':
150  case '8':
151  case '9':
152  msg += m_titleBlock->GetComment( format - '0');
153  break;
154 
155  default:
156  break;
157  }
158 
159  default:
160  break;
161  }
162  }
163 
164  return msg;
165 }
166 
167 
168 void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
169 
170 {
171  // Don't write the title block information if there is nothing to write.
172  bool isempty = true;
173  for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
174  {
175  if( ! m_tbTexts[idx].IsEmpty() )
176  {
177  isempty = false;
178  break;
179  }
180  }
181 
182  if( !isempty )
183  {
184  aFormatter->Print( aNestLevel, "(title_block\n" );
185 
186  if( !GetTitle().IsEmpty() )
187  aFormatter->Print( aNestLevel+1, "(title %s)\n",
188  aFormatter->Quotew( GetTitle() ).c_str() );
189 
190  if( !GetDate().IsEmpty() )
191  aFormatter->Print( aNestLevel+1, "(date %s)\n",
192  aFormatter->Quotew( GetDate() ).c_str() );
193 
194  if( !GetRevision().IsEmpty() )
195  aFormatter->Print( aNestLevel+1, "(rev %s)\n",
196  aFormatter->Quotew( GetRevision() ).c_str() );
197 
198  if( !GetCompany().IsEmpty() )
199  aFormatter->Print( aNestLevel+1, "(company %s)\n",
200  aFormatter->Quotew( GetCompany() ).c_str() );
201 
202  for( int ii = 0; ii < 4; ii++ )
203  {
204  if( !GetComment(ii).IsEmpty() )
205  aFormatter->Print( aNestLevel+1, "(comment %d %s)\n", ii+1,
206  aFormatter->Quotew( GetComment(ii) ).c_str() );
207  }
208 
209  aFormatter->Print( aNestLevel, ")\n\n" );
210  }
211 }
const wxString * m_paperFormat
const wxString & GetCompany() const
Definition: title_block.h:99
const wxString & GetComment(int aIdx) const
Definition: title_block.h:110
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:188
const TITLE_BLOCK * m_titleBlock
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
const wxString & GetDate() const
Definition: title_block.h:79
const wxString * m_sheetLayer
const wxString & GetTitle() const
Definition: title_block.h:65
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetRevision() const
Definition: title_block.h:89
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:168
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
static const wxString productName
Definition: worksheet.cpp:46
see class PGM_BASE
wxString BuildFullText(const wxString &aTextbase)
Function BuildFullText returns the full text corresponding to the aTextbase, after replacing format s...
Definition: worksheet.cpp:50
The common library.
classes and function to generate graphics to plt or draw titles blocks and frame references ...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
BASE_SCREEN class implementation.