KiCad PCB EDA Suite
common_plot_functions.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
10  *
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <fctsys.h>
31 #include <base_struct.h>
32 #include <plot_common.h>
33 #include <worksheet.h>
34 #include <class_base_screen.h>
35 #include <drawtxt.h>
36 #include <class_title_block.h>
39 #include <wx/filename.h>
40 
41 
42 
44 {
45  switch( aFormat )
46  {
47  case PLOT_FORMAT_DXF:
49 
50  case PLOT_FORMAT_POST:
52 
53  case PLOT_FORMAT_PDF:
55 
56  case PLOT_FORMAT_HPGL:
58 
59  case PLOT_FORMAT_GERBER:
61 
62  case PLOT_FORMAT_SVG:
64 
65  default:
66  wxASSERT( false );
67  return wxEmptyString;
68  }
69 }
70 
71 
72 
73 void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
74  const PAGE_INFO& aPageInfo,
75  int aSheetNumber, int aNumberOfSheets,
76  const wxString &aSheetDesc, const wxString &aFilename )
77 {
78  /* Note: Page sizes values are given in mils
79  */
80  double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
81 
82  COLOR4D plotColor = plotter->GetColorMode() ? COLOR4D( RED ) : COLOR4D::BLACK;
83  plotter->SetColor( plotColor );
84  WS_DRAW_ITEM_LIST drawList;
85 
86  // Print only a short filename, if aFilename is the full filename
87  wxFileName fn( aFilename );
88 
89  // Prepare plot parameters
91  drawList.SetMilsToIUfactor( iusPerMil );
92  drawList.SetSheetNumber( aSheetNumber );
93  drawList.SetSheetCount( aNumberOfSheets );
94  drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
95  drawList.SetSheetName( aSheetDesc );
96 
97 
98  drawList.BuildWorkSheetGraphicList( aPageInfo,
99  aTitleBlock, plotColor, plotColor );
100 
101  // Draw item list
102  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item;
103  item = drawList.GetNext() )
104  {
106 
107  switch( item->GetType() )
108  {
110  {
111  WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
112  plotter->SetCurrentLineWidth( line->GetPenWidth() );
113  plotter->MoveTo( line->GetStart() );
114  plotter->FinishTo( line->GetEnd() );
115  }
116  break;
117 
119  {
120  WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
121  plotter->Rect( rect->GetStart(),
122  rect->GetEnd(),
123  NO_FILL,
124  rect->GetPenWidth() );
125  }
126  break;
127 
129  {
130  WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
131  plotter->Text( text->GetTextPos(), text->GetColor(),
132  text->GetShownText(), text->GetTextAngle(),
133  text->GetTextSize(),
134  text->GetHorizJustify(), text->GetVertJustify(),
135  text->GetPenWidth(),
136  text->IsItalic(), text->IsBold(),
137  text->IsMultilineAllowed() );
138  }
139  break;
140 
142  {
144  plotter->PlotPoly( poly->m_Corners,
145  poly->IsFilled() ? FILLED_SHAPE : NO_FILL,
146  poly->GetPenWidth() );
147  }
148  break;
149 
151  {
153 
155 
156  if( parent->m_ImageBitmap == NULL )
157  break;
158 
159  parent->m_ImageBitmap->PlotImage( plotter, bm->GetPosition(),
160  plotColor, PLOTTER::USE_DEFAULT_LINE_WIDTH );
161  }
162  break;
163  }
164  }
165 }
static wxString GetDefaultFileExtension()
Definition: plot_common.h:803
void FinishTo(const wxPoint &pos)
Definition: plot_common.h:241
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
static wxString GetDefaultFileExtension()
Definition: plot_common.h:740
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
bool IsMultilineAllowed() const
Definition: eda_text.h:188
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plot_common.h:49
virtual void SetColor(COLOR4D color)=0
static wxString GetDefaultFileExtension()
Definition: plot_common.h:882
WS_DRAW_ITEM_BASE * GetNext()
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
description of graphic items and texts to build a title block
WS_DRAW_ITEM_BASE * GetFirst()
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, COLOR4D aDefaultColor, int aDefaultPensize)
Function PlotImage Plot bitmap on plotter.
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...
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Function PlotPoly.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
static wxString GetDefaultFileExtension()
Definition: plot_common.h:994
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename)
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: drawtxt.cpp:229
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:135
static wxString GetDefaultFileExtension()
Definition: plot_common.h:1219
double GetIUsPerDecimil() const
The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establ...
Definition: plot_common.h:207
static const int USE_DEFAULT_LINE_WIDTH
Definition: plot_common.h:95
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...
WORKSHEET_DATAITEM * GetParent() const
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units...
const wxPoint & GetEnd() const
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
COLOR4D GetColor() const
Definition: colors.h:60
std::vector< wxPoint > m_Corners
bool GetColorMode() const
Definition: plot_common.h:121
void MoveTo(const wxPoint &pos)
Definition: plot_common.h:231
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
Base plotter engine class.
Definition: plot_common.h:86
BASE_SCREEN class implementation.
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
const wxPoint & GetPosition()
static wxString GetDefaultFileExtension()
Definition: plot_common.h:563
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
This file is part of the common libary.
classes and function to generate graphics to plt or draw titles blocks and frame references ...
Definition: colors.h:45
const wxSize & GetTextSize() const
Definition: eda_text.h:215
Basic classes for most KiCad items.
const wxPoint & GetStart() const
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39