KiCad PCB EDA Suite
plotter_hpgl.h
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) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
26#pragma once
27
28#include <list>
29
30#include "plotter.h"
31
32
33class HPGL_PLOTTER : public PLOTTER
34{
35public:
37
38 virtual PLOT_FORMAT GetPlotterType() const override
39 {
40 return PLOT_FORMAT::HPGL;
41 }
42
43 static wxString GetDefaultFileExtension()
44 {
45 return wxString( wxT( "plt" ) );
46 }
47
53 void SetTargetChordLength( double chord_len );
54
56 void SetUserCoords( bool user_coords ) { m_useUserCoords = user_coords; }
57
59 void SetUserCoordsFit( bool user_coords_fit ) { m_fitUserCoords = user_coords_fit; }
60
64 virtual bool StartPlot( const wxString& aPageNumber ) override;
65
69 virtual bool EndPlot() override;
70
72 virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override
73 {
74 // This is the truth
76 }
77
81 virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
82
83 virtual void SetColor( const COLOR4D& color ) override {}
84
85 virtual void SetPenSpeed( int speed )
86 {
87 m_penSpeed = speed;
88 }
89
90 virtual void SetPenNumber( int number )
91 {
92 m_penNumber = number;
93 }
94
95 virtual void SetPenDiameter( double diameter );
96
97 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
98 double aScale, bool aMirror ) override;
99 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T aFill,
100 int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
101 virtual void Circle( const VECTOR2I& aCenter, int aDiameter, FILL_T aFill,
102 int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
103 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill,
104 int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
105
106 virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
107 OUTLINE_MODE tracemode, void* aData ) override;
108
109 virtual void Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VECTOR2I& aEnd,
110 FILL_T aFill, int aWidth, int aMaxError ) override;
111
112 virtual void PenTo( const VECTOR2I& pos, char plume ) override;
113
114 virtual void FlashPadCircle( const VECTOR2I& aPadPos, int aDiameter,
115 OUTLINE_MODE aTraceMode, void* aData ) override;
116 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
117 const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
118 void* aData ) override;
119 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
120 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
121 void* aData ) override;
122 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
123 int aCornerRadius, const EDA_ANGLE& aOrient,
124 OUTLINE_MODE aTraceMode, void* aData ) override;
125 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
126 const EDA_ANGLE& aOrient, SHAPE_POLY_SET* aPolygons,
127 OUTLINE_MODE aTraceMode, void* aData ) override;
128 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
129 const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
130 void* aData ) override;
131 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
132 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
133 void* aData ) override;
134
135protected:
148 virtual void Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
149 const EDA_ANGLE& aEndAngle, int aRadius, FILL_T aFill,
150 int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
151
158 bool startItem( const VECTOR2D& location );
159
161 void flushItem();
162
171 bool startOrAppendItem( const VECTOR2D& location, const wxString& content );
172
174 {
176 lift_before( false ),
177 lift_after( false ),
178 pen_returns( false ),
179 pen( 0 ),
181
184
188
191
194
199
203
204 int pen;
206 wxString content;
207 };
208
212 static void sortItems( std::list<HPGL_ITEM>& items );
213
215 static const char* lineStyleCommand( PLOT_DASH_TYPE aLineStyle );
216
217protected:
226
227 std::list<HPGL_ITEM> m_items;
229};
int color
Definition: DXF_plotter.cpp:57
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
static const char * lineStyleCommand(PLOT_DASH_TYPE aLineStyle)
Return the plot command corresponding to a line type.
void SetUserCoordsFit(bool user_coords_fit)
Set whether the user coordinate system is fit to content.
Definition: plotter_hpgl.h:59
HPGL_ITEM * m_current_item
Definition: plotter_hpgl.h:228
virtual void SetPenSpeed(int speed)
Definition: plotter_hpgl.h:85
bool startItem(const VECTOR2D &location)
Start a new HPGL_ITEM if necessary, keeping the current one if it exists.
double m_arcTargetChordLength
Definition: plotter_hpgl.h:221
void flushItem()
Flush the current HPGL_ITEM and clear out the current item pointer.
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a trapezoidal pad.
virtual PLOT_FORMAT GetPlotterType() const override
Returns the effective plot engine in use.
Definition: plotter_hpgl.h:38
virtual void Arc(const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aEnd, FILL_T aFill, int aWidth, int aMaxError) override
Generic fallback: arc rendered as a polyline.
void SetTargetChordLength(double chord_len)
Set the target length of chords used to draw approximated circles and arcs.
virtual void SetPenNumber(int number)
Definition: plotter_hpgl.h:90
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:43
void SetUserCoords(bool user_coords)
Switch to the user coordinate system.
Definition: plotter_hpgl.h:56
static void sortItems(std::list< HPGL_ITEM > &items)
Sort a list of HPGL items to improve plotting speed on mechanical plotters.
virtual void FlashPadCircle(const VECTOR2I &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData) override
virtual bool StartPlot(const wxString &aPageNumber) override
At the start of the HPGL plot pen speed and number are requested.
EDA_ANGLE m_arcMinChordDegrees
Definition: plotter_hpgl.h:222
virtual void SetColor(const COLOR4D &color) override
Definition: plotter_hpgl.h:83
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
HPGL doesn't handle line thickness or color.
Definition: plotter_hpgl.h:72
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a regular polygon.
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
bool m_useUserCoords
Definition: plotter_hpgl.h:224
std::list< HPGL_ITEM > m_items
Definition: plotter_hpgl.h:227
virtual void SetDash(int aLineWidth, PLOT_DASH_TYPE aLineStyle) override
HPGL supports dashed lines.
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, SHAPE_POLY_SET *aPolygons, OUTLINE_MODE aTraceMode, void *aData) override
virtual void SetPenDiameter(double diameter)
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
double m_penDiameter
Definition: plotter_hpgl.h:220
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
bool m_fitUserCoords
Definition: plotter_hpgl.h:225
PLOT_DASH_TYPE m_lineStyle
Definition: plotter_hpgl.h:223
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode, void *aData) override
bool startOrAppendItem(const VECTOR2D &location, const wxString &content)
Start a new HPGL_ITEM with the given string if necessary, or append the string to the current item.
virtual void Circle(const VECTOR2I &aCenter, int aDiameter, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
virtual bool EndPlot() override
HPGL end of plot: sort and emit graphics, pen return and release.
virtual void FlashPadRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:110
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:114
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
Definition: plotter.cpp:115
int m_currentPenWidth
Definition: plotter.h:638
Represent a set of closed polygons.
FILL_T
Definition: eda_shape.h:54
OUTLINE_MODE
Definition: outline_mode.h:25
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:70
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
wxString content
Line style for this command.
Definition: plotter_hpgl.h:206
bool pen_returns
Whether the pen returns to its original state after the command.
Definition: plotter_hpgl.h:202
BOX2D bbox
Bounding box of this item.
Definition: plotter_hpgl.h:190
bool lift_after
Whether the pen must be lifted after the command.
Definition: plotter_hpgl.h:198
PLOT_DASH_TYPE dashType
Pen number for this command.
Definition: plotter_hpgl.h:205
bool lift_before
Whether the command should be executed with the pen lifted.
Definition: plotter_hpgl.h:193
VECTOR2D loc_start
Location the pen should start at.
Definition: plotter_hpgl.h:183
VECTOR2D loc_end
Location the pen will be at when it finishes.
Definition: plotter_hpgl.h:187