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 <math/box2.h>
32 #include <plotter.h>
33 
34 
35 class HPGL_PLOTTER : public PLOTTER
36 {
37 public:
38  HPGL_PLOTTER();
39 
40  virtual PLOT_FORMAT GetPlotterType() const override
41  {
42  return PLOT_FORMAT::HPGL;
43  }
44 
45  static wxString GetDefaultFileExtension()
46  {
47  return wxString( wxT( "plt" ) );
48  }
49 
54  void SetTargetChordLength( double chord_len );
55 
57  void SetUserCoords( bool user_coords ) { useUserCoords = user_coords; }
58 
60  void SetUserCoordsFit( bool user_coords_fit ) { fitUserCoords = user_coords_fit; }
61 
65  virtual bool StartPlot() override;
66 
70  virtual bool EndPlot() override;
71 
73  virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override
74  {
75  // This is the truth
77  }
78 
82  virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
83 
84  virtual void SetColor( const COLOR4D& color ) override {}
85 
86  virtual void SetPenSpeed( int speed )
87  {
88  penSpeed = speed;
89  }
90 
91  virtual void SetPenNumber( int number )
92  {
93  penNumber = number;
94  }
95 
96  virtual void SetPenDiameter( double diameter );
97 
98  virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
99  double aScale, bool aMirror ) override;
100  virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_TYPE fill,
101  int width = USE_DEFAULT_LINE_WIDTH ) override;
102  virtual void Circle( const wxPoint& pos, int diametre, FILL_TYPE fill,
103  int width = USE_DEFAULT_LINE_WIDTH ) override;
104  virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
105  FILL_TYPE aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
106  void* aData = nullptr ) override;
107 
108  virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
109  OUTLINE_MODE tracemode, void* aData ) override;
110 
123  virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
124  int rayon, FILL_TYPE fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
125  virtual void PenTo( const wxPoint& pos, char plume ) override;
126  virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
127  OUTLINE_MODE aTraceMode, void* aData ) override;
128  virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
129  OUTLINE_MODE aTraceMode, void* aData ) override;
130  virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
131  double aOrient, OUTLINE_MODE aTraceMode, void* aData ) override;
132  virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
133  int aCornerRadius, double aOrient,
134  OUTLINE_MODE aTraceMode, void* aData ) override;
135  virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, double aOrient,
136  SHAPE_POLY_SET* aPolygons,
137  OUTLINE_MODE aTraceMode, void* aData ) override;
138  virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
139  double aPadOrient, OUTLINE_MODE aTraceMode,
140  void* aData ) override;
141  virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
142  double aOrient, OUTLINE_MODE aTraceMode,
143  void* aData ) override;
144 
145 protected:
151  bool startItem( DPOINT location );
152 
154  void flushItem();
155 
163  bool startOrAppendItem( DPOINT location, wxString const& content );
164 
165  int penSpeed;
167  double penDiameter;
173 
174  struct HPGL_ITEM
175  {
177  lift_before( false ),
178  lift_after( false ),
179  pen_returns( false ),
180  pen( 0 ),
182 
185 
189 
192 
195 
200 
204 
206  int pen;
207 
210 
212  wxString content;
213  };
214 
218  static void sortItems( std::list<HPGL_ITEM>& items );
219 
221  static const char* lineTypeCommand( PLOT_DASH_TYPE linetype );
222 
223  std::list<HPGL_ITEM> m_items;
225 };
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)
bool pen_returns
Whether the pen returns to its original state after the command.
Definition: plotter_hpgl.h:203
PLOT_DASH_TYPE dashType
Line style for this command.
Definition: plotter_hpgl.h:209
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:191
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:40
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:212
bool useUserCoords
Definition: plotter_hpgl.h:171
std::list< HPGL_ITEM > m_items
Definition: plotter_hpgl.h:223
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:188
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:60
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:595
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:199
virtual void SetPenSpeed(int speed)
Definition: plotter_hpgl.h:86
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData) override
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)
Modify 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:206
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:224
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
Plot an arc.
PLOT_DASH_TYPE dashType
Definition: plotter_hpgl.h:170
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:57
static const char * lineTypeCommand(PLOT_DASH_TYPE linetype)
Return the plot command corresponding to a line type.
double penDiameter
Definition: plotter_hpgl.h:167
virtual void SetPenNumber(int number)
Definition: plotter_hpgl.h:91
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:45
virtual void SetColor(const COLOR4D &color) override
Definition: plotter_hpgl.h:84
virtual void FlashPadRect(const wxPoint &aPadPos, const wxSize &aSize, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
double arcMinChordDegrees
Definition: plotter_hpgl.h:169
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
bool lift_before
Whether the command should be executed with the pen lifted.
Definition: plotter_hpgl.h:194
double arcTargetChordLength
Definition: plotter_hpgl.h:168
DPOINT loc_start
Location the pen should start at.
Definition: plotter_hpgl.h:184
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:172
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
HPGL doesn't handle line thickness or color.
Definition: plotter_hpgl.h:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103