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-2017 KiCad Developers, see AUTHORS.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 <plotter.h>
33 #include <worksheet.h>
34 #include <base_screen.h>
35 #include <draw_graphic_text.h>
36 #include <title_block.h>
38 #include "worksheet_dataitem.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: plotter.h:827
void FinishTo(const wxPoint &pos)
Definition: plotter.h:251
bool IsBold() const
Definition: eda_text.h:186
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
static wxString GetDefaultFileExtension()
Definition: plotter.h:764
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
const wxPoint & GetEnd() const
virtual void SetColor(COLOR4D color)=0
static wxString GetDefaultFileExtension()
Definition: plotter.h:906
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.
double GetTextAngle() const
Definition: eda_text.h:177
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:50
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.
Definition: title_block.h:40
static wxString GetDefaultFileExtension()
Definition: plotter.h:1021
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename)
WORKSHEET_DATAITEM * GetParent() const
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.
bool IsItalic() const
Definition: eda_text.h:183
static wxString GetDefaultFileExtension()
Definition: plotter.h:1247
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:102
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
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:54
const wxSize & GetTextSize() const
Definition: eda_text.h:228
const wxPoint & GetStart() const
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units...
description of graphic items and texts to build a title block
double GetIUsPerDecimil() const
The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establ...
Definition: plotter.h:217
Definition: colors.h:60
std::vector< wxPoint > m_Corners
bool IsMultilineAllowed() const
Definition: eda_text.h:201
void MoveTo(const wxPoint &pos)
Definition: plotter.h:241
Base plotter engine class.
Definition: plotter.h:97
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
const wxPoint GetPosition() const
static wxString GetDefaultFileExtension()
Definition: plotter.h:586
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
classes and function to generate graphics to plt or draw titles blocks and frame references ...
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:148
Definition: colors.h:45
Basic classes for most KiCad items.
BASE_SCREEN class implementation.
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
bool GetColorMode() const
Definition: plotter.h:131