KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <eda_item.h>
26#include <font/font.h>
33#include <title_block.h>
34#include <wx/filename.h>
35
36
38{
39 switch( aFormat )
40 {
47 default: wxFAIL; return wxEmptyString;
48 }
49}
50
51
52void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
53 const PAGE_INFO& aPageInfo, const std::map<wxString, wxString>* aProperties,
54 const wxString& aSheetNumber, int aSheetCount, const wxString& aSheetName,
55 const wxString& aSheetPath, const wxString& aFilename, COLOR4D aColor,
56 bool aIsFirstPage )
57{
58 /* Note: Page sizes values are given in mils
59 */
60 double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
61 COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
62 RENDER_SETTINGS* settings = plotter->RenderSettings();
63 int defaultPenWidth = settings->GetDefaultPenWidth();
64
65 if( plotColor == COLOR4D::UNSPECIFIED )
66 plotColor = COLOR4D( RED );
67
68 DS_DRAW_ITEM_LIST drawList( unityScale );
69
70 // Print only a short filename, if aFilename is the full filename
71 wxFileName fn( aFilename );
72
73 // Prepare plot parameters
75 drawList.SetPlotterMilsToIUfactor( iusPerMil );
76 drawList.SetPageNumber( aSheetNumber );
77 drawList.SetSheetCount( aSheetCount );
78 drawList.SetFileName( fn.GetFullPath() );
79 drawList.SetSheetName( aSheetName );
80 drawList.SetSheetPath( aSheetPath );
81 drawList.SetSheetLayer( settings->GetLayerName() );
82 drawList.SetProject( aProject );
83 drawList.SetIsFirstPage( aIsFirstPage );
84 drawList.SetProperties( aProperties );
85
86 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
87
88 // Draw bitmaps first
89 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
90 {
91 if( item->Type() == WSG_BITMAP_T )
92 {
93 DS_DRAW_ITEM_BITMAP* drawItem = (DS_DRAW_ITEM_BITMAP*) item;
94 DS_DATA_ITEM_BITMAP* bitmap = (DS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
95
96 if( bitmap->m_ImageBitmap == nullptr )
97 continue;
98
99 bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
101 }
102 }
103
104 // Draw other items
105 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
106 {
107 if( item->Type() == WSG_BITMAP_T )
108 continue;
109
110 plotter->SetColor( plotColor );
112
113 switch( item->Type() )
114 {
115 case WSG_LINE_T:
116 {
117 DS_DRAW_ITEM_LINE* line = (DS_DRAW_ITEM_LINE*) item;
118 plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
119 plotter->MoveTo( line->GetStart() );
120 plotter->FinishTo( line->GetEnd() );
121 }
122 break;
123
124 case WSG_RECT_T:
125 {
126 DS_DRAW_ITEM_RECT* rect = (DS_DRAW_ITEM_RECT*) item;
127 plotter->SetCurrentLineWidth( std::max( rect->GetPenWidth(), defaultPenWidth ) );
128 plotter->MoveTo( rect->GetStart() );
129 plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetStart().y ) );
130 plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetEnd().y ) );
131 plotter->LineTo( VECTOR2I( rect->GetStart().x, rect->GetEnd().y ) );
132 plotter->FinishTo( rect->GetStart() );
133 }
134 break;
135
136 case WSG_TEXT_T:
137 {
139 KIFONT::FONT* font = text->GetFont();
140 COLOR4D color = plotColor;
141
142 if( !font )
143 {
144 font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(),
145 text->IsItalic() );
146 }
147
148 if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED )
149 color = text->GetTextColor();
150
151 int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
152
153 plotter->Text( text->GetTextPos(), color, text->GetShownText( true ),
154 text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
155 text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
156 text->IsMultilineAllowed(), font, text->GetFontMetrics() );
157 }
158 break;
159
160 case WSG_POLY_T:
161 {
163 int penWidth = poly->GetPenWidth();
164 std::vector<VECTOR2I> points;
165
166 for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
167 {
168 points.clear();
169 SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
170
171 for( int ii = 0; ii < outline.PointCount(); ii++ )
172 points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
173
174 plotter->PlotPoly( points, FILL_T::FILLED_SHAPE, penWidth );
175 }
176 }
177 break;
178
179 default:
180 wxFAIL_MSG( wxT( "PlotDrawingSheet(): Unknown drawing sheet item." ) );
181 break;
182 }
183 }
184}
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:111
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
BITMAP_BASE * m_ImageBitmap
Definition: ds_data_item.h:370
Base class to handle basic graphic items.
Definition: ds_draw_item.h:59
virtual int GetPenWidth() const
Definition: ds_draw_item.h:70
DS_DATA_ITEM * GetPeer() const
Definition: ds_draw_item.h:63
VECTOR2I GetPosition() const override
Definition: ds_draw_item.h:373
const VECTOR2I & GetStart() const
Definition: ds_draw_item.h:144
const VECTOR2I & GetEnd() const
Definition: ds_draw_item.h:146
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:401
void SetPlotterMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to plot units.
Definition: ds_draw_item.h:467
DS_DRAW_ITEM_BASE * GetFirst()
Definition: ds_draw_item.h:511
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetSheetPath(const wxString &aSheetPath)
Set the sheet path to draw/plot.
Definition: ds_draw_item.h:454
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:444
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:461
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:449
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:493
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:434
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:459
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:498
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:488
DS_DRAW_ITEM_BASE * GetNext()
Definition: ds_draw_item.h:521
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:424
SHAPE_POLY_SET & GetPolygons()
Definition: ds_draw_item.h:182
Non filled rectangle with thick segment.
Definition: ds_draw_item.h:218
const VECTOR2I & GetEnd() const
Definition: ds_draw_item.h:233
const VECTOR2I & GetStart() const
Definition: ds_draw_item.h:231
A graphic text.
Definition: ds_draw_item.h:313
static wxString GetDefaultFileExtension()
Definition: plotter_dxf.h:41
static wxString GetDefaultFileExtension()
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:43
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:146
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
static const COLOR4D BLACK
Definition: color4d.h:402
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
const wxString & GetLayerName() const
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
static wxString GetDefaultFileExtension()
Base plotter engine class.
Definition: plotter.h:105
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:109
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:244
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:254
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
double GetIUsPerDecimil() const
The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establ...
Definition: plotter.h:206
bool GetColorMode() const
Definition: plotter.h:133
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void LineTo(const VECTOR2I &pos)
Definition: plotter.h:249
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aPenWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Draw text with the plotter.
Definition: plotter.cpp:691
virtual void SetColor(const COLOR4D &color)=0
Container for project specific data.
Definition: project.h:64
static wxString GetDefaultFileExtension()
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
static wxString GetDefaultFileExtension()
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
@ RED
Definition: color4d.h:59
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Returns the default plot extension for a format.
void PlotDrawingSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, const std::map< wxString, wxString > *aProperties, const wxString &aSheetNumber, int aSheetCount, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFilename, COLOR4D aColor, bool aIsFirstPage)
@ FILLED_SHAPE
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:65
Plotting engine (HPGL)
Plotting engines similar to ps (PostScript, Gerber, svg)
@ WSG_POLY_T
Definition: typeinfo.h:217
@ WSG_LINE_T
Definition: typeinfo.h:215
@ WSG_TEXT_T
Definition: typeinfo.h:218
@ WSG_RECT_T
Definition: typeinfo.h:216
@ WSG_BITMAP_T
Definition: typeinfo.h:219
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691