KiCad PCB EDA Suite
common_plot_functions.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <base_struct.h>
27 #include <plotter.h>
28 #include <ws_painter.h>
29 #include <base_screen.h>
30 #include <gr_text.h>
31 #include <title_block.h>
32 #include "ws_draw_item.h"
33 #include "ws_data_item.h"
34 #include <wx/filename.h>
35 
36 
38 {
39  switch( aFormat )
40  {
41  case PLOT_FORMAT::DXF:
43  case PLOT_FORMAT::POST:
45  case PLOT_FORMAT::PDF:
47  case PLOT_FORMAT::HPGL:
51  case PLOT_FORMAT::SVG:
53  default:
54  wxASSERT( false );
55  return wxEmptyString;
56  }
57 }
58 
59 
60 void PlotWorkSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
61  const PAGE_INFO& aPageInfo, int aSheetNumber, int aNumberOfSheets,
62  const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor )
63 {
64  /* Note: Page sizes values are given in mils
65  */
66  double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
67  COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
68  int defaultPenWidth = plotter->RenderSettings()->GetDefaultPenWidth();
69 
70  if( plotColor == COLOR4D::UNSPECIFIED )
71  plotColor = COLOR4D( RED );
72 
73  plotter->SetColor( plotColor );
74  WS_DRAW_ITEM_LIST drawList;
75 
76  // Print only a short filename, if aFilename is the full filename
77  wxFileName fn( aFilename );
78 
79  // Prepare plot parameters
81  drawList.SetMilsToIUfactor( iusPerMil );
82  drawList.SetSheetNumber( aSheetNumber );
83  drawList.SetSheetCount( aNumberOfSheets );
84  drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
85  drawList.SetSheetName( aSheetDesc );
86  drawList.SetProject( aProject );
87 
88  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
89 
90  // Draw item list
91  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
92  {
94 
95  switch( item->Type() )
96  {
97  case WSG_LINE_T:
98  {
99  WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
100  plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
101  plotter->MoveTo( line->GetStart() );
102  plotter->FinishTo( line->GetEnd() );
103  }
104  break;
105 
106  case WSG_RECT_T:
107  {
108  WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
109  int penWidth = std::max( rect->GetPenWidth(), defaultPenWidth );
110  plotter->Rect( rect->GetStart(), rect->GetEnd(), NO_FILL, penWidth );
111  }
112  break;
113 
114  case WSG_TEXT_T:
115  {
116  WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
117  int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
118  plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
119  text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
120  text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
121  text->IsMultilineAllowed() );
122  }
123  break;
124 
125  case WSG_POLY_T:
126  {
128  int penWidth = std::max( poly->GetPenWidth(), defaultPenWidth );
129  std::vector<wxPoint> points;
130 
131  for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
132  {
133  points.clear();
134  SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
135 
136  for( int ii = 0; ii < outline.PointCount(); ii++ )
137  points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
138 
139  plotter->PlotPoly( points, FILLED_SHAPE, penWidth );
140  }
141  }
142  break;
143 
144  case WSG_BITMAP_T:
145  {
146  WS_DRAW_ITEM_BITMAP* drawItem = (WS_DRAW_ITEM_BITMAP*) item;
147  auto* bitmap = (WS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
148 
149  if( bitmap->m_ImageBitmap == NULL )
150  break;
151 
152  bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
154  }
155  break;
156 
157  default:
158  wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
159  break;
160  }
161  }
162 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:208
static wxString GetDefaultFileExtension()
Definition: plotter.h:863
void FinishTo(const wxPoint &pos)
Definition: plotter.h:267
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:67
bool IsBold() const
Definition: eda_text.h:182
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:210
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:426
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:405
int OutlineCount() const
Returns the number of outlines in the set
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
static wxString GetDefaultFileExtension()
Definition: plotter.h:798
PROJECT holds project specific data.
Definition: project.h:61
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Returns the default plot extension for a format.
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:130
virtual void SetColor(COLOR4D color)=0
SHAPE_POLY_SET & GetPolygons()
Definition: ws_draw_item.h:172
static wxString GetDefaultFileExtension()
Definition: plotter.h:941
WS_DRAW_ITEM_BASE * GetNext()
Definition: ws_draw_item.h:477
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:413
double GetTextAngle() const
Definition: eda_text.h:173
WS_DRAW_ITEM_BASE * GetFirst()
Definition: ws_draw_item.h:467
Definition: color4d.h:44
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Function PlotPoly.
int PointCount() const
Function PointCount()
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
static wxString GetDefaultFileExtension()
Definition: plotter.h:1172
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:152
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: gr_text.cpp:222
bool IsItalic() const
Definition: eda_text.h:179
static wxString GetDefaultFileExtension()
Definition: plotter.h:1450
const VECTOR2I & CPoint(int aIndex) const
Function Point()
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:119
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
#define NULL
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
void PlotWorkSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor)
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:451
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
PLOT_FORMAT
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:51
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
const wxSize & GetTextSize() const
Definition: eda_text.h:238
const wxPoint & GetStart() const
Definition: ws_draw_item.h:128
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:433
double GetIUsPerDecimil() const
The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establ...
Definition: plotter.h:220
Definition: color4d.h:59
bool IsMultilineAllowed() const
Definition: eda_text.h:196
virtual int GetPenWidth() const
Definition: ws_draw_item.h:75
void MoveTo(const wxPoint &pos)
Definition: plotter.h:257
Base plotter engine class.
Definition: plotter.h:114
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
Definition: ws_draw_item.h:442
const wxPoint GetPosition() const override
Definition: ws_draw_item.h:328
SHAPE_LINE_CHAIN.
static wxString GetDefaultFileExtension()
Definition: plotter.h:617
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
void SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:390
BASE_SCREEN class implementation.
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
bool GetColorMode() const
Definition: plotter.h:144