KiCad PCB EDA Suite
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
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 <>.
18  */
26 #pragma once
28 #include <list>
30 #include "plotter.h"
33 class HPGL_PLOTTER : public PLOTTER
34 {
35 public:
38  virtual PLOT_FORMAT GetPlotterType() const override
39  {
40  return PLOT_FORMAT::HPGL;
41  }
43  static wxString GetDefaultFileExtension()
44  {
45  return wxString( wxT( "plt" ) );
46  }
53  void SetTargetChordLength( double chord_len );
56  void SetUserCoords( bool user_coords ) { useUserCoords = user_coords; }
59  void SetUserCoordsFit( bool user_coords_fit ) { fitUserCoords = user_coords_fit; }
64  virtual bool StartPlot() override;
69  virtual bool EndPlot() override;
72  virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override
73  {
74  // This is the truth
76  }
81  virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
83  virtual void SetColor( const COLOR4D& color ) override {}
85  virtual void SetPenSpeed( int speed )
86  {
87  penSpeed = speed;
88  }
90  virtual void SetPenNumber( int number )
91  {
92  penNumber = number;
93  }
95  virtual void SetPenDiameter( double diameter );
97  virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
98  double aScale, bool aMirror ) override;
99  virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
100  int width = USE_DEFAULT_LINE_WIDTH ) override;
101  virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
102  int width = USE_DEFAULT_LINE_WIDTH ) override;
103  virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, FILL_T aFill,
104  int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
106  virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
107  OUTLINE_MODE tracemode, void* aData ) override;
121  virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, int rayon,
122  FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
123  virtual void PenTo( const wxPoint& pos, char plume ) override;
124  virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
125  OUTLINE_MODE aTraceMode, void* aData ) override;
126  virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
127  OUTLINE_MODE aTraceMode, void* aData ) override;
128  virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
129  double aOrient, OUTLINE_MODE aTraceMode, void* aData ) override;
130  virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
131  int aCornerRadius, double aOrient,
132  OUTLINE_MODE aTraceMode, void* aData ) override;
133  virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, double aOrient,
134  SHAPE_POLY_SET* aPolygons,
135  OUTLINE_MODE aTraceMode, void* aData ) override;
136  virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
137  double aPadOrient, OUTLINE_MODE aTraceMode,
138  void* aData ) override;
139  virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
140  double aOrient, OUTLINE_MODE aTraceMode,
141  void* aData ) override;
143 protected:
150  bool startItem( const DPOINT& location );
153  void flushItem();
163  bool startOrAppendItem( const DPOINT& location, const wxString& content );
165  int penSpeed;
167  double penDiameter;
174  struct HPGL_ITEM
175  {
177  lift_before( false ),
178  lift_after( false ),
179  pen_returns( false ),
180  pen( 0 ),
206  int pen;
212  wxString content;
213  };
218  static void sortItems( std::list<HPGL_ITEM>& items );
221  static const char* lineTypeCommand( PLOT_DASH_TYPE linetype );
223  std::list<HPGL_ITEM> m_items;
225 };
virtual bool EndPlot() override
HPGL end of plot: sort and emit graphics, pen return and release.
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
Line style for this command.
Definition: plotter_hpgl.h:209
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
virtual PLOT_FORMAT GetPlotterType() const override
Returns the effective plot engine in use.
Definition: plotter_hpgl.h:38
int color
Definition: DXF_plotter.cpp:57
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 void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
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
Definition: eda_shape.h:53
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.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
void SetUserCoordsFit(bool user_coords_fit)
Set whether the user coordinate system is fit to content.
Definition: plotter_hpgl.h:59
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
bool startOrAppendItem(const DPOINT &location, const wxString &content)
Start a new HPGL_ITEM with the given string if necessary, or append the string to the current item.
Represent a set of closed polygons.
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:85
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:117
int pen
Pen number for this command.
Definition: plotter_hpgl.h:206
Dashed line types.
Definition: plotter.h:104
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
Definition: plotter_hpgl.h:170
bool startItem(const DPOINT &location)
Start a new HPGL_ITEM if necessary, keeping the current one if it exists.
void SetUserCoords(bool user_coords)
Switch to the user coordinate system.
Definition: plotter_hpgl.h:56
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:90
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:43
virtual void SetColor(const COLOR4D &color) override
Definition: plotter_hpgl.h:83
virtual void FlashPadRect(const wxPoint &aPadPos, const wxSize &aSize, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
double arcMinChordDegrees
Definition: plotter_hpgl.h:169
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.
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
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:72
virtual void Arc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Plot an arc.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103