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 <class_drawpanel.h>
38 #include <class_base_screen.h>
39 #include <drawtxt.h>
40 #include <draw_frame.h>
41 #include <worksheet.h>
42 #include <class_title_block.h>
43 #include <build_version.h>
44 
46 
47 static const wxString productName = wxT( "KiCad E.D.A. " );
48 
49 void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
50  const PAGE_INFO& aPageInfo,
51  const wxString &aFullSheetName,
52  const wxString& aFileName,
53  TITLE_BLOCK& aTitleBlock,
54  int aSheetCount, int aSheetNumber,
55  int aPenWidth, double aScalar,
56  COLOR4D aColor, COLOR4D aAltColor,
57  const wxString& aSheetLayer )
58 {
59  WS_DRAW_ITEM_LIST drawList;
60 
61  drawList.SetPenSize( aPenWidth );
62  drawList.SetMilsToIUfactor( aScalar );
63  drawList.SetSheetNumber( aSheetNumber );
64  drawList.SetSheetCount( aSheetCount );
65  drawList.SetFileName( aFileName );
66  drawList.SetSheetName( aFullSheetName );
67  drawList.SetSheetLayer( aSheetLayer );
68 
69  drawList.BuildWorkSheetGraphicList( aPageInfo,
70  aTitleBlock, aColor, aAltColor );
71 
72  // Draw item list
73  drawList.Draw( aClipBox, aDC );
74 }
75 
76 
77 void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
78  double aScalar, const wxString &aFilename,
79  const wxString &aSheetLayer )
80 {
82  return;
83 
84  const PAGE_INFO& pageInfo = GetPageSettings();
85  wxSize pageSize = pageInfo.GetSizeMils();
86 
87  // if not printing, draw the page limits:
88  if( !aScreen->m_IsPrinting && m_showPageLimits )
89  {
90  GRSetDrawMode( aDC, GR_COPY );
91  GRRect( m_canvas->GetClipBox(), aDC, 0, 0,
92  pageSize.x * aScalar, pageSize.y * aScalar, aLineWidth,
94  }
95 
96  TITLE_BLOCK t_block = GetTitleBlock();
97  COLOR4D color = COLOR4D( RED );
98 
99  wxPoint origin = aDC->GetDeviceOrigin();
100 
101  if( aScreen->m_IsPrinting && origin.y > 0 )
102  {
103  aDC->SetDeviceOrigin( 0, 0 );
104  aDC->SetAxisOrientation( true, false );
105  }
106 
107  DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
108  GetScreenDesc(), aFilename, t_block,
109  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
110  aLineWidth, aScalar, color, color, aSheetLayer );
111 
112  if( aScreen->m_IsPrinting && origin.y > 0 )
113  {
114  aDC->SetDeviceOrigin( origin.x, origin.y );
115  aDC->SetAxisOrientation( true, true );
116  }
117 }
118 
119 
121 {
122  // Virtual function. In basic class, returns
123  // an empty string.
124  return wxEmptyString;
125 }
126 
127 // returns the full text corresponding to the aTextbase,
128 // after replacing format symbols by the corresponding value
129 wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
130 {
131  wxString msg;
132 
133  /* Known formats
134  * %% = replaced by %
135  * %K = Kicad version
136  * %Z = paper format name (A4, USLetter)
137  * %Y = company name
138  * %D = date
139  * %R = revision
140  * %S = sheet number
141  * %N = number of sheets
142  * %L = layer name
143  * %Cx = comment (x = 0 to 9 to identify the comment)
144  * %F = filename
145  * %P = sheet path (sheet full name)
146  * %T = title
147  */
148 
149  for( unsigned ii = 0; ii < aTextbase.Len(); ii++ )
150  {
151  if( aTextbase[ii] != '%' )
152  {
153  msg << aTextbase[ii];
154  continue;
155  }
156 
157  if( ++ii >= aTextbase.Len() )
158  break;
159 
160  wxChar format = aTextbase[ii];
161  switch( format )
162  {
163  case '%':
164  msg += '%';
165  break;
166 
167  case 'D':
168  msg += m_titleBlock->GetDate();
169  break;
170 
171  case 'R':
172  msg += m_titleBlock->GetRevision();
173  break;
174 
175  case 'K':
176  msg += productName + Pgm().App().GetAppName();
177  msg += wxT( " " ) + GetBuildVersion();
178  break;
179 
180  case 'Z':
181  msg += *m_paperFormat;
182  break;
183 
184  case 'S':
185  msg << m_sheetNumber;
186  break;
187 
188  case 'N':
189  msg << m_sheetCount;
190  break;
191 
192  case 'F':
193  {
194  wxFileName fn( m_fileName );
195  msg += fn.GetFullName();
196  }
197  break;
198 
199  case 'L':
200  msg += *m_sheetLayer;
201  break;
202 
203  case 'P':
204  msg += *m_sheetFullName;
205  break;
206 
207  case 'Y':
208  msg += m_titleBlock->GetCompany();
209  break;
210 
211  case 'T':
212  msg += m_titleBlock->GetTitle();
213  break;
214 
215  case 'C':
216  format = aTextbase[++ii];
217  switch( format )
218  {
219  case '0':
220  case '1':
221  case '2':
222  case '3':
223  case '4':
224  case '5':
225  case '6':
226  case '7':
227  case '8':
228  case '9':
229  msg += m_titleBlock->GetComment( format - '0');
230  break;
231 
232  default:
233  break;
234  }
235 
236  default:
237  break;
238  }
239  }
240 
241  return msg;
242 }
243 
244 
245 void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
246 
247 {
248  // Don't write the title block information if there is nothing to write.
249  bool isempty = true;
250  for( unsigned idx = 0; idx < m_tbTexts.GetCount(); idx++ )
251  {
252  if( ! m_tbTexts[idx].IsEmpty() )
253  {
254  isempty = false;
255  break;
256  }
257  }
258 
259  if( !isempty )
260  {
261  aFormatter->Print( aNestLevel, "(title_block\n" );
262 
263  if( !GetTitle().IsEmpty() )
264  aFormatter->Print( aNestLevel+1, "(title %s)\n",
265  aFormatter->Quotew( GetTitle() ).c_str() );
266 
267  if( !GetDate().IsEmpty() )
268  aFormatter->Print( aNestLevel+1, "(date %s)\n",
269  aFormatter->Quotew( GetDate() ).c_str() );
270 
271  if( !GetRevision().IsEmpty() )
272  aFormatter->Print( aNestLevel+1, "(rev %s)\n",
273  aFormatter->Quotew( GetRevision() ).c_str() );
274 
275  if( !GetCompany().IsEmpty() )
276  aFormatter->Print( aNestLevel+1, "(company %s)\n",
277  aFormatter->Quotew( GetCompany() ).c_str() );
278 
279  for( int ii = 0; ii < 4; ii++ )
280  {
281  if( !GetComment(ii).IsEmpty() )
282  aFormatter->Print( aNestLevel+1, "(comment %d %s)\n", ii+1,
283  aFormatter->Quotew( GetComment(ii) ).c_str() );
284  }
285 
286  aFormatter->Print( aNestLevel, ")\n\n" );
287  }
288 }
const wxString * m_paperFormat
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
virtual const TITLE_BLOCK & GetTitleBlock() const =0
const wxString & GetCompany() const
const wxString & GetComment(int aIdx) const
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
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:323
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
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:65
const wxString & GetDate() const
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock, COLOR4D aColor, COLOR4D aAltColor)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
COLOR4D m_drawBgColor
the background color of the draw canvas BLACK for Pcbnew, BLACK or WHITE for eeschema ...
Definition: draw_frame.h:84
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
const wxString * m_sheetLayer
const wxSize & GetSizeMils() const
wxArrayString m_tbTexts
virtual const PAGE_INFO & GetPageSettings() const =0
const wxString & GetTitle() const
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
virtual wxString GetScreenDesc() const
Definition: worksheet.cpp:120
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
const wxString & GetRevision() const
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
bool m_showBorderAndTitleBlock
True shows the drawing border and title block.
Definition: draw_frame.h:113
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units...
EDA_RECT * GetClipBox()
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:245
Definition: colors.h:60
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
const wxString * m_sheetFullName
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
static const wxString productName
Definition: worksheet.cpp:47
void DrawPageLayout(wxDC *aDC, EDA_RECT *aClipBox, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, COLOR4D aAltColor, const wxString &aSheetLayer)
Function DrawPageLayout is a core function to draw the page layout with the frame and the basic inscr...
Definition: worksheet.cpp:49
see class PGM_BASE
BASE_SCREEN class implementation.
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
wxString BuildFullText(const wxString &aTextbase)
Function BuildFullText returns the full text corresponding to the aTextbase, after replacing format s...
Definition: worksheet.cpp:129
Class EDA_RECT handles the component boundary box.
The common library.
bool m_showPageLimits
true to display the page limits
Definition: draw_frame.h:82
Definition: colors.h:49
This file is part of the common libary.
classes and function to generate graphics to plt or draw titles blocks and frame references ...
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Function DrawWorkSheet Draws on screen the page layout with the frame and the basic inscriptions...
Definition: worksheet.cpp:77
void Draw(EDA_RECT *aClipBox, wxDC *aDC)
Draws the item list created by BuildWorkSheetGraphicList.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39