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