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 
37 
39 {
40  switch( aFormat )
41  {
48  default: wxASSERT( false ); return wxEmptyString;
49  }
50 }
51 
52 
53 
54 void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
55  const PAGE_INFO& aPageInfo, int aSheetNumber, int aNumberOfSheets,
56  const wxString &aSheetDesc, const wxString &aFilename, const COLOR4D aColor )
57 {
58  /* Note: Page sizes values are given in mils
59  */
60  double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
61 
62  COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
63 
64  if( plotColor == COLOR4D::UNSPECIFIED )
65  plotColor = COLOR4D( RED );
66 
67  plotter->SetColor( plotColor );
68  WS_DRAW_ITEM_LIST drawList;
69 
70  // Print only a short filename, if aFilename is the full filename
71  wxFileName fn( aFilename );
72 
73  // Prepare plot parameters
75  drawList.SetMilsToIUfactor( iusPerMil );
76  drawList.SetSheetNumber( aSheetNumber );
77  drawList.SetSheetCount( aNumberOfSheets );
78  drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
79  drawList.SetSheetName( aSheetDesc );
80 
81 
82  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
83 
84  // Draw item list
85  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
86  {
88 
89  switch( item->Type() )
90  {
91  case WSG_LINE_T:
92  {
93  WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
94  plotter->SetCurrentLineWidth( line->GetPenWidth() );
95  plotter->MoveTo( line->GetStart() );
96  plotter->FinishTo( line->GetEnd() );
97  }
98  break;
99 
100  case WSG_RECT_T:
101  {
102  WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
103  plotter->Rect( rect->GetStart(), rect->GetEnd(), NO_FILL, rect->GetPenWidth() );
104  }
105  break;
106 
107  case WSG_TEXT_T:
108  {
109  WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
110  plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
111  text->GetTextAngle(), text->GetTextSize(),
112  text->GetHorizJustify(), text->GetVertJustify(),
113  text->GetPenWidth(), text->IsItalic(), text->IsBold(),
114  text->IsMultilineAllowed() );
115  }
116  break;
117 
118  case WSG_POLY_T:
119  {
121  std::vector<wxPoint> points;
122 
123  for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
124  {
125  points.clear();
126  SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
127 
128  for( int ii = 0; ii < outline.PointCount(); ii++ )
129  points.push_back( wxPoint( outline.Point( ii ).x ,
130  outline.Point( ii ).y ) );
131 
132  plotter->PlotPoly( points, FILLED_SHAPE, poly->GetPenWidth() );
133  }
134  }
135  break;
136 
137  case WSG_BITMAP_T:
138  {
139  WS_DRAW_ITEM_BITMAP* drawItem = (WS_DRAW_ITEM_BITMAP*) item;
140  auto* bitmap = (WS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
141 
142  if( bitmap->m_ImageBitmap == NULL )
143  break;
144 
145  bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
147  }
148  break;
149 
150  default:
151  wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
152  break;
153  }
154  }
155 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:206
static wxString GetDefaultFileExtension()
Definition: plotter.h:830
void FinishTo(const wxPoint &pos)
Definition: plotter.h:254
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:66
bool IsBold() const
Definition: eda_text.h:167
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:208
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:425
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:404
int OutlineCount() const
Returns the number of outlines in the set
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
static wxString GetDefaultFileExtension()
Definition: plotter.h:767
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:124
virtual void SetColor(COLOR4D color)=0
SHAPE_POLY_SET & GetPolygons()
Definition: ws_draw_item.h:167
static wxString GetDefaultFileExtension()
Definition: plotter.h:909
int GetPenWidth() const
Definition: ws_draw_item.h:205
WS_DRAW_ITEM_BASE * GetNext()
Definition: ws_draw_item.h:476
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:412
double GetTextAngle() const
Definition: eda_text.h:158
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:50
WS_DRAW_ITEM_BASE * GetFirst()
Definition: ws_draw_item.h:466
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()
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
static wxString GetDefaultFileExtension()
Definition: plotter.h:1043
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:215
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, const COLOR4D aColor)
bool IsItalic() const
Definition: eda_text.h:164
static wxString GetDefaultFileExtension()
Definition: plotter.h:1270
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:102
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
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 SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:450
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
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:221
const wxPoint & GetStart() const
Definition: ws_draw_item.h:122
int GetPenWidth() const
Definition: ws_draw_item.h:121
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:432
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
bool IsMultilineAllowed() const
Definition: eda_text.h:182
void MoveTo(const wxPoint &pos)
Definition: plotter.h:244
Base plotter engine class.
Definition: plotter.h:97
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
Definition: ws_draw_item.h:441
const wxPoint GetPosition() const override
Definition: ws_draw_item.h:330
Class SHAPE_LINE_CHAIN.
static wxString GetDefaultFileExtension()
Definition: plotter.h:589
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:230
VECTOR2I & Point(int aIndex)
Function Point()
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:129
Definition: colors.h:45
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