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-2021 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 #include <vector>
30 
31 #include <eda_item.h> // FILL_TYPE
32 #include <math/box2.h>
33 #include <plotter.h>
34 
35 
36 class HPGL_PLOTTER : public PLOTTER
37 {
38 public:
39  HPGL_PLOTTER();
40 
41  virtual PLOT_FORMAT GetPlotterType() const override
42  {
43  return PLOT_FORMAT::HPGL;
44  }
45 
46  static wxString GetDefaultFileExtension()
47  {
48  return wxString( wxT( "plt" ) );
49  }
50 
55  void SetTargetChordLength( double chord_len );
56 
58  void SetUserCoords( bool user_coords ) { useUserCoords = user_coords; }
59 
61  void SetUserCoordsFit( bool user_coords_fit ) { fitUserCoords = user_coords_fit; }
62 
63  virtual bool StartPlot() override;
64  virtual bool EndPlot() override;
65 
67  virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override
68  {
69  // This is the truth
71  }
72 
73  virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
74 
75  virtual void SetColor( COLOR4D color ) override {}
76 
77  virtual void SetPenSpeed( int speed )
78  {
79  penSpeed = speed;
80  }
81 
82  virtual void SetPenNumber( int number )
83  {
84  penNumber = number;
85  }
86 
87  virtual void SetPenDiameter( double diameter );
88 
89  virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
90  double aScale, bool aMirror ) override;
91  virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_TYPE fill,
92  int width = USE_DEFAULT_LINE_WIDTH ) override;
93  virtual void Circle( const wxPoint& pos, int diametre, FILL_TYPE fill,
94  int width = USE_DEFAULT_LINE_WIDTH ) override;
95  virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
96  FILL_TYPE aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
97  void * aData = NULL ) override;
98 
99  virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
100  OUTLINE_MODE tracemode, void* aData ) override;
101  virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
102  int rayon, FILL_TYPE fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
103  virtual void PenTo( const wxPoint& pos, char plume ) override;
104  virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
105  OUTLINE_MODE aTraceMode, void* aData ) override;
106  virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
107  OUTLINE_MODE aTraceMode, void* aData ) override;
108  virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
109  double aOrient, OUTLINE_MODE aTraceMode, void* aData ) override;
110  virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
111  int aCornerRadius, double aOrient,
112  OUTLINE_MODE aTraceMode, void* aData ) override;
113  virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, double aOrient,
114  SHAPE_POLY_SET* aPolygons,
115  OUTLINE_MODE aTraceMode, void* aData ) override;
116  virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
117  double aPadOrient, OUTLINE_MODE aTraceMode,
118  void* aData ) override;
119  virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
120  double aOrient, OUTLINE_MODE aTraceMode,
121  void* aData ) override;
122 
123 protected:
129  bool startItem( DPOINT location );
130 
132  void flushItem();
133 
141  bool startOrAppendItem( DPOINT location, wxString const& content );
142 
143  int penSpeed;
145  double penDiameter;
151 
152  struct HPGL_ITEM
153  {
155  lift_before( false ),
156  lift_after( false ),
157  pen_returns( false ),
158  pen( 0 ),
160 
163 
167 
170 
173 
178 
182 
184  int pen;
185 
188 
190  wxString content;
191  };
192 
196  static void sortItems( std::list<HPGL_ITEM>& items );
197 
199  static const char* lineTypeCommand( PLOT_DASH_TYPE linetype );
200 
201  std::list<HPGL_ITEM> m_items;
203 };
virtual bool EndPlot() override
HPGL end of plot: sort and emit graphics, pen return and release.
OUTLINE_MODE
Definition: outline_mode.h:24
virtual void FlashPadCircle(const wxPoint &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData) override
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
virtual void SetColor(COLOR4D color) override
Definition: plotter_hpgl.h:75
bool pen_returns
Whether the pen returns to its original state after the command.
Definition: plotter_hpgl.h:181
PLOT_DASH_TYPE dashType
Line style for this command.
Definition: plotter_hpgl.h:187
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:28
void flushItem()
Flush the current HPGL_ITEM and clear out the current item pointer.
BOX2D bbox
Bounding box of this item.
Definition: plotter_hpgl.h:169
bool startItem(DPOINT location)
Start a new HPGL_ITEM if necessary, keeping the current one if it exists.
virtual PLOT_FORMAT GetPlotterType() const override
Returns the effective plot engine in use.
Definition: plotter_hpgl.h:41
int color
Definition: DXF_plotter.cpp:60
static void sortItems(std::list< HPGL_ITEM > &items)
Sort a list of HPGL items to improve plotting speed on mechanical plotters.
virtual void SetPenDiameter(double diameter)
wxString content
Text of the command.
Definition: plotter_hpgl.h:190
bool useUserCoords
Definition: plotter_hpgl.h:149
std::list< HPGL_ITEM > m_items
Definition: plotter_hpgl.h:201
virtual void FlashPadTrapez(const wxPoint &aPadPos, const wxPoint *aCorners, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a trapezoidal pad.
virtual bool StartPlot() override
At the start of the HPGL plot pen speed and number are requested.
virtual void FlashPadOval(const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
virtual void FlashPadRoundRect(const wxPoint &aPadPos, const wxSize &aSize, int aCornerRadius, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
DPOINT loc_end
Location the pen will be at when it finishes.
Definition: plotter_hpgl.h:166
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
void SetUserCoordsFit(bool user_coords_fit)
Set whether the user coordinate system is fit to content.
Definition: plotter_hpgl.h:61
bool startOrAppendItem(DPOINT location, wxString const &content)
Start a new HPGL_ITEM with the given string if necessary, or append the string to the current item.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void FlashRegularPolygon(const wxPoint &aShapePos, int aDiameter, int aCornerCount, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a regular polygon.
int m_currentPenWidth
Definition: plotter.h:585
#define NULL
virtual void SetCurrentLineWidth(int width, void *aData=NULL) override
HPGL doesn't handle line thickness or color.
Definition: plotter_hpgl.h:67
Represent a set of closed polygons.
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:67
bool lift_after
Whether the pen must be lifted after the command.
Definition: plotter_hpgl.h:177
virtual void SetPenSpeed(int speed)
Definition: plotter_hpgl.h:77
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData) override
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL) override
HPGL polygon:
virtual void PenTo(const wxPoint &pos, char plume) override
moveto/lineto primitive, moves the 'pen' to the specified direction
virtual DPOINT userToDeviceSize(const wxSize &size)
Modifies size according to the plotter scale factors (wxSize version, returns a DPOINT)
Definition: plotter.cpp:124
int pen
Pen number for this command.
Definition: plotter_hpgl.h:184
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
HPGL_ITEM * m_current_item
Definition: plotter_hpgl.h:202
void SetTargetChordLength(double chord_len)
Set the target length of chords used to draw approximated circles and arcs.
Base plotter engine class.
Definition: plotter.h:121
virtual void Arc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
PLOT_DASH_TYPE dashType
Definition: plotter_hpgl.h:148
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
void SetUserCoords(bool user_coords)
Switch to the user coordinate system.
Definition: plotter_hpgl.h:58
static const char * lineTypeCommand(PLOT_DASH_TYPE linetype)
Return the plot command corresponding to a line type.
double penDiameter
Definition: plotter_hpgl.h:145
virtual void SetPenNumber(int number)
Definition: plotter_hpgl.h:82
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:46
virtual void FlashPadRect(const wxPoint &aPadPos, const wxSize &aSize, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
double arcMinChordDegrees
Definition: plotter_hpgl.h:147
bool lift_before
Whether the command should be executed with the pen lifted.
Definition: plotter_hpgl.h:172
double arcTargetChordLength
Definition: plotter_hpgl.h:146
DPOINT loc_start
Location the pen should start at.
Definition: plotter_hpgl.h:162
virtual void FlashPadCustom(const wxPoint &aPadPos, const wxSize &aSize, double aOrient, SHAPE_POLY_SET *aPolygons, OUTLINE_MODE aTraceMode, void *aData) override
virtual void SetDash(PLOT_DASH_TYPE dashed) override
HPGL supports dashed lines.
bool fitUserCoords
Definition: plotter_hpgl.h:150
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98