2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-11-16 11:45:53 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-06-03 15:59:00 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-19 20:20:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
2018-01-28 18:12:26 +00:00
|
|
|
* @file HPGL_plotter.cpp
|
2021-08-17 17:44:11 +00:00
|
|
|
* @brief KiCad plotter for HPGL file format.
|
2012-05-03 18:37:56 +00:00
|
|
|
* Since this plot engine is mostly intended for import in external programs,
|
|
|
|
* sadly HPGL/2 isn't supported a lot... some of the primitives use overlapped
|
2021-08-17 17:44:11 +00:00
|
|
|
* strokes to fill the shape.
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
/* Some HPGL commands:
|
|
|
|
* Note: the HPGL unit is 25 micrometers
|
|
|
|
* All commands MUST be terminated by a semi-colon or a linefeed.
|
|
|
|
* Spaces can NOT be substituted for required commas in the syntax of a command.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* AA (Arc Absolute): Angle is a floating point # (requires non integer value)
|
|
|
|
* Draws an arc with the center at (X,Y).
|
|
|
|
* A positive angle creates a counter-clockwise arc.
|
|
|
|
* If the chord angle is specified,
|
|
|
|
* this will be the number of degrees used for stepping around the arc.
|
|
|
|
* If no value is given then a default value of five degrees is used.
|
|
|
|
* AA x, y, a {,b};
|
|
|
|
*
|
|
|
|
* AR (Arc Relative):
|
|
|
|
* AR Dx, Dy, a {, b};
|
|
|
|
*
|
|
|
|
* CA (Alternate Character Set):
|
|
|
|
* CA {n};
|
|
|
|
*
|
|
|
|
* CI (Circle):
|
|
|
|
* CI r {,b};
|
|
|
|
*
|
|
|
|
* CP (Character Plot):
|
|
|
|
* CP {h, v};
|
Fix various typos
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-07-03 04:20:05 +00:00
|
|
|
* h [-127.9999 .. 127.9999] Number of characters horizontally
|
|
|
|
* v [-127.9999 .. 127.9999] Number of characters vertically
|
2012-09-18 08:39:56 +00:00
|
|
|
*
|
|
|
|
* CS (Standard Character Set):
|
|
|
|
* CS {n};
|
|
|
|
*
|
|
|
|
* DR (Relative Direction for Label Text):
|
|
|
|
* DR s, a;
|
|
|
|
*
|
|
|
|
* DI (Absolute Direction for Label Text):
|
|
|
|
* DI {s, a};
|
|
|
|
*
|
|
|
|
* DT (Define Terminator - this character becomes unavailable except to terminate a label string.
|
|
|
|
* Default is ^C control-C):
|
|
|
|
* DT t;
|
|
|
|
*
|
|
|
|
* EA (rEctangle Absolute - Unfilled, from current position to diagonal x,y):
|
|
|
|
* EA x, y;
|
|
|
|
*
|
|
|
|
* ER (rEctangle Relative - Unfilled, from current position to diagonal x,y):
|
|
|
|
* ER x,y;
|
|
|
|
*
|
|
|
|
* FT (Fill Type):
|
|
|
|
* FT {s {,l {a}}};
|
|
|
|
*
|
|
|
|
* IM (Input Mask):
|
|
|
|
* IM {f};
|
|
|
|
*
|
|
|
|
* IN (Initialize): This command instructs the controller to begin processing the HPGL plot file.
|
|
|
|
* Without this, the commands in the file are received but never executed.
|
|
|
|
* If multiple IN s are found during execution of the file,
|
|
|
|
* the controller performs a Pause/Cancel operation.
|
|
|
|
* All motion from the previous job, yet to be executed, is lost,
|
|
|
|
* and the new information is executed.
|
|
|
|
* IN;
|
|
|
|
*
|
|
|
|
* IP Input P1 and P2:
|
|
|
|
* IP {P1x, P1y {, P2x, P2y}};
|
|
|
|
*
|
|
|
|
* IW (Input Window):
|
|
|
|
* IW {XUL, YUL, XOR, YOR};
|
|
|
|
*
|
|
|
|
* LB (Label):
|
|
|
|
* LB c1 .. cn t;
|
|
|
|
*
|
|
|
|
* PA (Plot Absolute): Moves to an absolute HPGL position and sets absolute mode for
|
|
|
|
* future PU and PD commands. If no arguments follow the command,
|
|
|
|
* only absolute mode is set.
|
|
|
|
* PA {x1, y1 {{PU|PD|,} ..., ..., xn, yn}};
|
|
|
|
* P1x, P1y, P2x, P2y [Integer in ASCII]
|
|
|
|
*
|
|
|
|
* PD (Pen Down): Executes <current pen> pen then moves to the requested position
|
|
|
|
* if one is specified. This position is dependent on whether absolute
|
|
|
|
* or relative mode is set. This command performs no motion in 3-D mode,
|
|
|
|
* but the outputs and feedrates are affected.
|
|
|
|
* PD {x, y};
|
|
|
|
*
|
2016-02-10 16:02:40 +00:00
|
|
|
* PM Polygon mode
|
|
|
|
* associated commands:
|
|
|
|
* PM2 End polygon mode
|
|
|
|
* FP Fill polygon
|
|
|
|
* EP Draw polygon outline
|
|
|
|
*
|
2012-09-18 08:39:56 +00:00
|
|
|
* PR (Plot Relative): Moves to the relative position specified and sets relative mode
|
|
|
|
* for future PU and PD commands.
|
|
|
|
* If no arguments follow the command, only relative mode is set.
|
|
|
|
* PR {Dx1, Dy1 {{PU|PD|,} ..., ..., Dxn, Dyn}};
|
|
|
|
*
|
|
|
|
* PS (Paper Size):
|
|
|
|
* PS {n};
|
|
|
|
*
|
2016-02-11 12:14:46 +00:00
|
|
|
* PT (Pen Thickness): in mm
|
2012-09-18 08:39:56 +00:00
|
|
|
* PT {l};
|
|
|
|
*
|
|
|
|
* PU (Pen Up): Executes <current pen> pen then moves to the requested position
|
|
|
|
* if one is specified. This position is dependent on whether absolute
|
|
|
|
* or relative mode is set.
|
|
|
|
* This command performs no motion in 3-D mode, but the outputs
|
|
|
|
* and feedrates are affected.
|
|
|
|
* PU {x, y};
|
|
|
|
*
|
|
|
|
* RA (Rectangle Absolute - Filled, from current position to diagonal x,y):
|
|
|
|
* RA x, y;
|
|
|
|
*
|
|
|
|
* RO (Rotate Coordinate System):
|
|
|
|
* RO;
|
|
|
|
*
|
|
|
|
* RR (Rectangle Relative - Filled, from current position to diagonal x,y):
|
|
|
|
* RR x, y;
|
|
|
|
*
|
|
|
|
* SA (Select Alternate Set):
|
|
|
|
* SA;
|
|
|
|
*
|
|
|
|
* SC (Scale):
|
|
|
|
* SC {Xmin, Xmax, Ymin, Ymax};
|
|
|
|
*
|
|
|
|
* SI (Absolute Character Size):
|
|
|
|
* SI b, h;
|
|
|
|
* b [-127.9999 .. 127.9999, keine 0]
|
|
|
|
* h [-127.9999 .. 127.9999, keine 0]
|
|
|
|
*
|
|
|
|
* SL (Character Slant):
|
|
|
|
* SL {a};
|
|
|
|
* a [-3.5 .. -0.5, 0.5 .. 3.5]
|
|
|
|
*
|
|
|
|
* SP (Select Pen): Selects a new pen or tool for use.
|
|
|
|
* If no pen number or a value of zero is given,
|
|
|
|
* the controller performs an EOF (end of file command).
|
|
|
|
* Once an EOF is performed, no motion is executed,
|
|
|
|
* until a new IN command is received.
|
|
|
|
* SP n;
|
|
|
|
*
|
|
|
|
* SR (Relative Character Size):
|
|
|
|
* SR {b, h};
|
|
|
|
* b [-127.9999 .. 127.9999, keine 0]
|
|
|
|
* h [-127.9999 .. 127.9999, keine 0]
|
|
|
|
*
|
|
|
|
* SS (Select Standard Set):
|
|
|
|
* SS;
|
|
|
|
*
|
|
|
|
* TL (Tick Length):
|
|
|
|
* TL {tp {, tm}};
|
|
|
|
*
|
|
|
|
* UC (User Defined Character):
|
|
|
|
* UC {i,} x1, y1, {i,} x2, y2, ... {i,} xn, yn;
|
|
|
|
*
|
|
|
|
* VS (Velocity Select):
|
|
|
|
* VS {v {, n}};
|
2016-02-11 12:14:46 +00:00
|
|
|
* v [1 .. 40] in cm/s
|
2016-02-10 16:02:40 +00:00
|
|
|
* n [1 .. 8]
|
2012-09-18 08:39:56 +00:00
|
|
|
*
|
|
|
|
* XT (X Tick):
|
|
|
|
* XT;
|
|
|
|
*
|
|
|
|
* YT (Y Tick):
|
|
|
|
* YT;
|
|
|
|
*/
|
|
|
|
|
2020-12-19 06:36:51 +00:00
|
|
|
#include <cstdio>
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2016-02-10 16:02:40 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter_hpgl.h>
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
/// Compute the distance between two VECTOR2D points.
|
|
|
|
static double dpoint_dist( const VECTOR2D& a, const VECTOR2D& b );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
|
|
|
|
2016-02-11 12:14:46 +00:00
|
|
|
// The hpgl command to close a polygon def, fill it and plot outline:
|
|
|
|
// PM 2; ends the polygon definition and closes it if not closed
|
|
|
|
// FP; fills the polygon
|
|
|
|
// EP; draws the polygon outline. It usually gives a better look to the filled polygon
|
|
|
|
static const char hpgl_end_polygon_cmd[] = "PM 2; FP; EP;\n";
|
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2018-05-25 18:50:00 +00:00
|
|
|
// HPGL scale factor (1 Plotter Logical Unit = 1/40mm = 25 micrometers)
|
|
|
|
// PLUsPERDECIMIL = (25.4 / 10000) / 0.025
|
|
|
|
static const double PLUsPERDECIMIL = 0.1016;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2022-06-28 18:21:00 +00:00
|
|
|
HPGL_PLOTTER::HPGL_PLOTTER() :
|
|
|
|
m_arcTargetChordLength( 0 ),
|
|
|
|
m_arcMinChordDegrees( 5.0, DEGREES_T ),
|
|
|
|
m_lineStyle( PLOT_DASH_TYPE::SOLID ),
|
|
|
|
m_useUserCoords( false ),
|
|
|
|
m_fitUserCoords( false ),
|
|
|
|
m_current_item( nullptr )
|
2012-09-28 17:47:41 +00:00
|
|
|
{
|
2015-03-11 16:04:20 +00:00
|
|
|
SetPenSpeed( 40 ); // Default pen speed = 40 cm/s; Pen speed is *always* in cm
|
2012-09-28 17:47:41 +00:00
|
|
|
SetPenNumber( 1 ); // Default pen num = 1
|
2015-03-11 16:04:20 +00:00
|
|
|
SetPenDiameter( 0.0 );
|
2012-09-28 17:47:41 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
|
2012-09-18 08:39:56 +00:00
|
|
|
double aScale, bool aMirror )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotOffset = aOffset;
|
|
|
|
m_plotScale = aScale;
|
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
|
|
|
m_iuPerDeviceUnit = PLUsPERDECIMIL / aIusPerDecimil;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
// Compute the paper size in IUs.
|
2020-11-16 00:04:55 +00:00
|
|
|
m_paperSize = m_pageInfo.GetSizeMils();
|
|
|
|
m_paperSize.x *= 10.0 * aIusPerDecimil;
|
|
|
|
m_paperSize.y *= 10.0 * aIusPerDecimil;
|
|
|
|
m_plotMirror = aMirror;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
void HPGL_PLOTTER::SetTargetChordLength( double chord_len )
|
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
m_arcTargetChordLength = userToDeviceSize( chord_len );
|
2020-12-14 02:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
bool HPGL_PLOTTER::StartPlot( const wxString& aPageNumber )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-06-28 18:21:00 +00:00
|
|
|
fprintf( m_outputFile, "IN;VS%d;PU;PA;SP%d;\n", m_penSpeed, m_penNumber );
|
2016-02-11 12:14:46 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Set HPGL Pen Thickness (in mm) (useful in polygon fill command)
|
2022-06-28 18:21:00 +00:00
|
|
|
double penThicknessMM = userToDeviceSize( m_penDiameter ) / 40;
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "PT %.1f;\n", penThicknessMM );
|
2016-02-11 12:14:46 +00:00
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
bool HPGL_PLOTTER::EndPlot()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2020-12-21 23:27:31 +00:00
|
|
|
|
|
|
|
fputs( "PU;\n", m_outputFile );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
|
|
|
flushItem();
|
2020-12-14 02:01:24 +00:00
|
|
|
sortItems( m_items );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( m_items.size() > 0 )
|
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
if( m_useUserCoords )
|
2020-12-21 23:27:31 +00:00
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
if( m_fitUserCoords )
|
2020-12-21 23:27:31 +00:00
|
|
|
{
|
|
|
|
BOX2D bbox = m_items.front().bbox;
|
2022-01-16 01:06:25 +00:00
|
|
|
|
2020-12-22 16:59:57 +00:00
|
|
|
for( HPGL_ITEM const& item : m_items )
|
2020-12-21 23:27:31 +00:00
|
|
|
bbox.Merge( item.bbox );
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
fprintf( m_outputFile, "SC%.0f,%.0f,%.0f,%.0f;\n",
|
|
|
|
bbox.GetX(),
|
|
|
|
bbox.GetX() + bbox.GetWidth(),
|
|
|
|
bbox.GetY(),
|
2020-12-22 16:59:57 +00:00
|
|
|
bbox.GetY() + bbox.GetHeight() );
|
2020-12-21 23:27:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D pagesize_device( m_paperSize * m_iuPerDeviceUnit );
|
|
|
|
fprintf( m_outputFile, "SC%.0f,%.0f,%.0f,%.0f;\n",
|
|
|
|
0.0,
|
|
|
|
pagesize_device.x,
|
|
|
|
0.0,
|
|
|
|
pagesize_device.y );
|
2020-12-21 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2I loc = m_items.begin()->loc_start;
|
2020-12-14 02:01:24 +00:00
|
|
|
bool pen_up = true;
|
2020-12-13 23:38:44 +00:00
|
|
|
PLOT_DASH_TYPE current_dash = PLOT_DASH_TYPE::SOLID;
|
2022-06-28 18:21:00 +00:00
|
|
|
int current_pen = m_penNumber;
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
for( HPGL_ITEM const& item : m_items )
|
|
|
|
{
|
|
|
|
if( item.loc_start != loc || pen_up )
|
|
|
|
{
|
|
|
|
if( !pen_up )
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
fputs( "PU;", m_outputFile );
|
|
|
|
pen_up = true;
|
|
|
|
}
|
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
fprintf( m_outputFile, "PA %.0f,%.0f;", item.loc_start.x, item.loc_start.y );
|
2020-12-13 23:38:44 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( item.dashType != current_dash )
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
current_dash = item.dashType;
|
2022-06-28 18:21:00 +00:00
|
|
|
fputs( lineStyleCommand( item.dashType ), m_outputFile );
|
2020-12-13 23:38:44 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( item.pen != current_pen )
|
|
|
|
{
|
|
|
|
if( !pen_up )
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
fputs( "PU;", m_outputFile );
|
|
|
|
pen_up = true;
|
|
|
|
}
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2020-12-13 23:38:44 +00:00
|
|
|
fprintf( m_outputFile, "SP%d;", item.pen );
|
|
|
|
current_pen = item.pen;
|
|
|
|
}
|
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( pen_up && !item.lift_before )
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
fputs( "PD;", m_outputFile );
|
|
|
|
pen_up = false;
|
|
|
|
}
|
2020-12-14 02:01:24 +00:00
|
|
|
else if( !pen_up && item.lift_before )
|
|
|
|
{
|
|
|
|
fputs( "PU;", m_outputFile );
|
|
|
|
pen_up = true;
|
|
|
|
}
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2020-12-18 15:16:00 +00:00
|
|
|
fputs( static_cast<const char*>( item.content.utf8_str() ), m_outputFile );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( !item.pen_returns )
|
|
|
|
{
|
|
|
|
// Assume commands drop the pen
|
|
|
|
pen_up = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item.lift_after )
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
fputs( "PU;", m_outputFile );
|
|
|
|
pen_up = true;
|
2020-12-14 02:01:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
loc = item.loc_end;
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-12-13 23:38:44 +00:00
|
|
|
fputs( "\n", m_outputFile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "PU;PA;SP0;\n", m_outputFile );
|
|
|
|
fclose( m_outputFile );
|
2021-06-07 18:31:53 +00:00
|
|
|
m_outputFile = nullptr;
|
2010-03-31 16:59:32 +00:00
|
|
|
return true;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-11 12:14:46 +00:00
|
|
|
void HPGL_PLOTTER::SetPenDiameter( double diameter )
|
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
m_penDiameter = diameter;
|
2016-02-11 12:14:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void HPGL_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T aFill, int aWidth )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D p1_device = userToDeviceCoordinates( p1 );
|
|
|
|
VECTOR2D p2_device = userToDeviceCoordinates( p2 );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( p1 );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aFill == FILL_T::FILLED_SHAPE )
|
2020-12-14 02:01:24 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
startOrAppendItem( p1_device, wxString::Format( "RA %.0f,%.0f;",
|
|
|
|
p2_device.x,
|
|
|
|
p2_device.y ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
startOrAppendItem( p1_device, wxString::Format( "EA %.0f,%.0f;",
|
|
|
|
p2_device.x,
|
|
|
|
p2_device.y ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
|
|
|
m_current_item->loc_end = m_current_item->loc_start;
|
2022-01-16 01:06:25 +00:00
|
|
|
m_current_item->bbox.Merge( p2_device );
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void HPGL_PLOTTER::Circle( const VECTOR2I& aCenter, int aDiameter, FILL_T aFill, int aWidth )
|
2008-06-30 13:47:55 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-01-16 01:06:25 +00:00
|
|
|
double radius = userToDeviceSize( aDiameter / 2 );
|
|
|
|
VECTOR2D center_dev = userToDeviceCoordinates( aCenter );
|
|
|
|
SetCurrentLineWidth( aWidth );
|
2016-02-11 12:14:46 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
double const circumf = 2.0 * M_PI * radius;
|
2022-06-28 18:21:00 +00:00
|
|
|
double const target_chord_length = m_arcTargetChordLength;
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE chord_angle = ANGLE_360 * target_chord_length / circumf;
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2023-06-03 15:59:00 +00:00
|
|
|
chord_angle = std::clamp( m_arcMinChordDegrees, chord_angle, ANGLE_45 );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aFill == FILL_T::FILLED_SHAPE )
|
2016-02-11 12:14:46 +00:00
|
|
|
{
|
|
|
|
// Draw the filled area
|
2022-01-16 01:06:25 +00:00
|
|
|
MoveTo( aCenter );
|
|
|
|
startOrAppendItem( center_dev, wxString::Format( "PM 0;CI %g,%g;%s",
|
|
|
|
radius,
|
|
|
|
chord_angle.AsDegrees(),
|
2021-08-17 17:44:11 +00:00
|
|
|
hpgl_end_polygon_cmd ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
m_current_item->lift_before = true;
|
|
|
|
m_current_item->pen_returns = true;
|
2021-08-17 17:44:11 +00:00
|
|
|
m_current_item->bbox.Merge( BOX2D( center_dev - radius,
|
|
|
|
VECTOR2D( 2 * radius, 2 * radius ) ) );
|
2016-02-11 12:14:46 +00:00
|
|
|
PenFinish();
|
|
|
|
}
|
2008-06-30 13:47:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( radius > 0 )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
MoveTo( aCenter );
|
|
|
|
startOrAppendItem( center_dev, wxString::Format( "CI %g,%g;",
|
|
|
|
radius,
|
|
|
|
chord_angle.AsDegrees() ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
m_current_item->lift_before = true;
|
|
|
|
m_current_item->pen_returns = true;
|
2021-08-17 17:44:11 +00:00
|
|
|
m_current_item->bbox.Merge( BOX2D( center_dev - radius,
|
|
|
|
VECTOR2D( 2 * radius, 2 * radius ) ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-30 13:47:55 +00:00
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
|
2021-07-18 23:08:54 +00:00
|
|
|
void* aData )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList.size() <= 1 )
|
2009-06-28 16:50:42 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-16 01:40:40 +00:00
|
|
|
// Width less than zero is occasionally used to create background-only
|
|
|
|
// polygons. Don't set that as the plotter line width, that'll cause
|
|
|
|
// trouble. Also, later, skip plotting the outline if this is the case.
|
|
|
|
if( aWidth > 0 )
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2020-12-13 23:38:44 +00:00
|
|
|
startItem( userToDeviceCoordinates( aCornerList[0] ) );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill == FILL_T::FILLED_SHAPE )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// Draw the filled area
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
|
|
|
m_current_item->content << wxString( "PM 0;\n" ); // Start polygon
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ++ii )
|
|
|
|
LineTo( aCornerList[ii] );
|
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
int ii = aCornerList.size() - 1;
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList[ii] != aCornerList[0] )
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( aCornerList[0] );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2020-12-13 23:38:44 +00:00
|
|
|
m_current_item->content << hpgl_end_polygon_cmd; // Close, fill polygon and draw outlines
|
2020-12-14 02:01:24 +00:00
|
|
|
m_current_item->pen_returns = true;
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
2022-04-27 18:02:06 +00:00
|
|
|
else if( aWidth != 0 )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
// Plot only the polygon outline.
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
LineTo( aCornerList[ii] );
|
|
|
|
|
|
|
|
// Always close polygon if filled.
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
int ii = aCornerList.size() - 1;
|
|
|
|
|
|
|
|
if( aCornerList[ii] != aCornerList[0] )
|
|
|
|
LineTo( aCornerList[0] );
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
2020-12-14 02:01:24 +00:00
|
|
|
m_penState = 'Z';
|
2020-12-13 23:38:44 +00:00
|
|
|
flushItem();
|
2009-06-28 16:50:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
VECTOR2D lastpos_dev = userToDeviceCoordinates( m_penLastpos );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2020-12-13 23:38:44 +00:00
|
|
|
if( plume == 'U' )
|
|
|
|
{
|
2020-12-14 02:01:24 +00:00
|
|
|
m_penState = 'U';
|
2020-12-13 23:38:44 +00:00
|
|
|
flushItem();
|
|
|
|
}
|
|
|
|
else if( plume == 'D' )
|
|
|
|
{
|
2020-12-14 02:01:24 +00:00
|
|
|
m_penState = 'D';
|
2021-08-17 17:44:11 +00:00
|
|
|
startOrAppendItem( lastpos_dev, wxString::Format( "PA %.0f,%.0f;", pos_dev.x, pos_dev.y ) );
|
2020-12-13 23:38:44 +00:00
|
|
|
m_current_item->loc_end = pos_dev;
|
2020-12-21 23:27:31 +00:00
|
|
|
m_current_item->bbox.Merge( pos_dev );
|
2020-12-13 23:38:44 +00:00
|
|
|
}
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_penLastpos = pos;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
void HPGL_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
m_lineStyle = aLineStyle;
|
2020-12-14 02:01:24 +00:00
|
|
|
flushItem();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::ThickSegment( const VECTOR2I& start, const VECTOR2I& end,
|
2020-10-15 23:33:18 +00:00
|
|
|
int width, OUTLINE_MODE tracemode, void* aData )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
// Suppress overlap if pen is too big
|
2022-06-28 18:21:00 +00:00
|
|
|
if( m_penDiameter >= width )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( start );
|
|
|
|
FinishTo( end );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
segmentAsOval( start, end, width, tracemode );
|
2020-11-16 00:04:55 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
void HPGL_PLOTTER::Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
|
2023-08-22 13:06:53 +00:00
|
|
|
const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aRadius <= 0 )
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
double const radius_device = userToDeviceSize( aRadius );
|
|
|
|
double const circumf_device = 2.0 * M_PI * radius_device;
|
2022-06-28 18:21:00 +00:00
|
|
|
double const target_chord_length = m_arcTargetChordLength;
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE chord_angle = ANGLE_360 * target_chord_length / circumf_device;
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2022-06-28 18:21:00 +00:00
|
|
|
chord_angle = std::max( m_arcMinChordDegrees, std::min( chord_angle, ANGLE_45 ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D centre_device = userToDeviceCoordinates( aCenter );
|
2023-08-22 13:06:53 +00:00
|
|
|
EDA_ANGLE angle = aAngle;
|
2023-08-07 01:53:08 +00:00
|
|
|
|
2023-08-22 13:06:53 +00:00
|
|
|
if( !m_plotMirror )
|
|
|
|
angle = -angle;
|
2023-08-07 01:53:08 +00:00
|
|
|
|
2023-08-22 13:06:53 +00:00
|
|
|
EDA_ANGLE startAngle = -aStartAngle;
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2013-12-06 18:31:15 +00:00
|
|
|
// Calculate arc start point:
|
2023-08-22 13:06:53 +00:00
|
|
|
VECTOR2I cmap( aCenter.x + KiROUND( aRadius * startAngle.Cos() ),
|
|
|
|
aCenter.y - KiROUND( aRadius * startAngle.Sin() ) );
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D cmap_dev = userToDeviceCoordinates( cmap );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
startOrAppendItem( cmap_dev, wxString::Format( "AA %.0f,%.0f,%.0f,%g",
|
|
|
|
centre_device.x,
|
|
|
|
centre_device.y,
|
|
|
|
angle.AsDegrees(),
|
|
|
|
chord_angle.AsDegrees() ) );
|
2020-12-13 23:38:44 +00:00
|
|
|
|
2020-12-21 23:27:31 +00:00
|
|
|
// TODO We could compute the final position and full bounding box instead...
|
2022-01-16 01:06:25 +00:00
|
|
|
m_current_item->bbox.Merge( BOX2D( centre_device - radius_device,
|
|
|
|
VECTOR2D( radius_device * 2, radius_device * 2 ) ) );
|
2020-12-13 23:38:44 +00:00
|
|
|
m_current_item->lift_after = true;
|
|
|
|
flushItem();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode, void* aData )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-01-16 01:06:25 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I size( aSize );
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE orient( aOrient );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// The pad will be drawn as an oblong shape with size.y > size.x (Oval vertical orientation 0).
|
2009-06-28 16:50:42 +00:00
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2022-01-16 01:06:25 +00:00
|
|
|
orient += ANGLE_90;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aTraceMode == FILLED )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
int deltaxy = size.y - size.x; // distance between centers of the oval
|
|
|
|
|
2022-06-28 18:21:00 +00:00
|
|
|
FlashPadRect( aPos, VECTOR2I( size.x, deltaxy + KiROUND( m_penDiameter ) ), orient,
|
2022-01-16 01:06:25 +00:00
|
|
|
aTraceMode, aData );
|
|
|
|
|
|
|
|
VECTOR2I pt( 0, deltaxy / 2 );
|
|
|
|
RotatePoint( pt, orient );
|
|
|
|
FlashPadCircle( pt + aPos, size.x, aTraceMode, aData );
|
|
|
|
|
|
|
|
pt = VECTOR2I( 0, -deltaxy / 2 );
|
|
|
|
RotatePoint( pt, orient );
|
|
|
|
FlashPadCircle( pt + aPos, size.x, aTraceMode, aData );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2016-02-10 16:02:40 +00:00
|
|
|
else // Plot in outline mode.
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
sketchOval( aPos, size, orient, KiROUND( m_penDiameter ) );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadCircle( const VECTOR2I& pos, int diametre,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE trace_mode, void* aData )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
int radius = diametre / 2;
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
|
|
|
// if filled mode, the pen diameter is removed from diameter
|
|
|
|
// to keep the pad size
|
2022-06-28 18:21:00 +00:00
|
|
|
radius -= KiROUND( m_penDiameter ) / 2;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2022-04-27 18:02:06 +00:00
|
|
|
if( radius < 0 )
|
|
|
|
radius = 0;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
double rsize = userToDeviceSize( radius );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
if( trace_mode == FILLED ) // Plot in filled mode.
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// A filled polygon uses always the current point to start the polygon.
|
|
|
|
// Gives a correct current starting point for the circle
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( pos.x + radius, pos.y ) );
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
// Plot filled area and its outline
|
2021-12-29 19:02:50 +00:00
|
|
|
startOrAppendItem( userToDeviceCoordinates( VECTOR2I( pos.x + radius, pos.y ) ),
|
2021-08-17 17:44:11 +00:00
|
|
|
wxString::Format( "PM 0; PA %.0f,%.0f;CI %.0f;%s",
|
|
|
|
pos_dev.x, pos_dev.y, rsize, hpgl_end_polygon_cmd ) );
|
2020-12-14 02:01:24 +00:00
|
|
|
m_current_item->lift_before = true;
|
|
|
|
m_current_item->pen_returns = true;
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw outline only:
|
2020-12-14 02:01:24 +00:00
|
|
|
startOrAppendItem( pos_dev, wxString::Format( "CI %.0f;", rsize ) );
|
|
|
|
m_current_item->lift_before = true;
|
|
|
|
m_current_item->pen_returns = true;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadRect( const VECTOR2I& aPos, const VECTOR2I& aPadSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode, void* aData )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// Build rect polygon:
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> corners;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
int dx = aPadSize.x / 2;
|
|
|
|
int dy = aPadSize.y / 2;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aTraceMode == FILLED )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
// in filled mode, the pen diameter is removed from size
|
|
|
|
// to compensate the extra size due to this pen size
|
2022-06-28 18:21:00 +00:00
|
|
|
dx -= KiROUND( m_penDiameter ) / 2;
|
2016-02-10 16:02:40 +00:00
|
|
|
dx = std::max( dx, 0);
|
2022-06-28 18:21:00 +00:00
|
|
|
dy -= KiROUND( m_penDiameter ) / 2;
|
2016-02-10 16:02:40 +00:00
|
|
|
dy = std::max( dy, 0);
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2019-12-05 15:41:21 +00:00
|
|
|
corners.emplace_back( - dx, - dy );
|
|
|
|
corners.emplace_back( - dx, + dy );
|
|
|
|
corners.emplace_back( + dx, + dy );
|
|
|
|
corners.emplace_back( + dx, - dy );
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2018-05-18 08:13:46 +00:00
|
|
|
// Close polygon
|
2019-12-05 15:41:21 +00:00
|
|
|
corners.emplace_back( - dx, - dy );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
for( unsigned ii = 0; ii < corners.size(); ii++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
RotatePoint( corners[ii], aOrient );
|
|
|
|
corners[ii] += aPos;
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
PlotPoly( corners, aTraceMode == FILLED ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
|
2022-01-16 01:06:25 +00:00
|
|
|
int aCornerRadius, const EDA_ANGLE& aOrient,
|
2021-06-07 18:31:53 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I size = aSize;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
if( aTraceMode == FILLED )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2021-08-17 17:44:11 +00:00
|
|
|
// In filled mode, the pen diameter is removed from size to keep the pad size.
|
2022-06-28 18:21:00 +00:00
|
|
|
size.x -= KiROUND( m_penDiameter ) / 2;
|
2016-02-10 16:02:40 +00:00
|
|
|
size.x = std::max( size.x, 0);
|
2022-06-28 18:21:00 +00:00
|
|
|
size.y -= KiROUND( m_penDiameter ) / 2;
|
2016-02-10 16:02:40 +00:00
|
|
|
size.y = std::max( size.y, 0);
|
|
|
|
|
|
|
|
// keep aCornerRadius to a value < min size x,y < 2:
|
|
|
|
aCornerRadius = std::min( aCornerRadius, std::min( size.x, size.y ) /2 );
|
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, aPadPos, size, aOrient, aCornerRadius, 0.0, 0,
|
|
|
|
0, GetPlotterArcHighDef(), ERROR_INSIDE );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> cornerList;
|
2019-12-05 15:20:59 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
|
|
|
cornerList.reserve( poly.PointCount() );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2019-03-23 18:26:44 +00:00
|
|
|
cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2018-05-18 08:13:46 +00:00
|
|
|
if( cornerList.back() != cornerList.front() )
|
|
|
|
cornerList.push_back( cornerList.front() );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, aTraceMode == FILLED ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, SHAPE_POLY_SET* aPolygons,
|
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> cornerList;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
for( int cnt = 0; cnt < aPolygons->OutlineCount(); ++cnt )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = aPolygons->Outline( cnt );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
cornerList.clear();
|
|
|
|
cornerList.reserve( poly.PointCount() );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2020-12-16 01:33:55 +00:00
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2019-03-23 18:26:44 +00:00
|
|
|
cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2018-05-18 08:13:46 +00:00
|
|
|
if( cornerList.back() != cornerList.front() )
|
|
|
|
cornerList.push_back( cornerList.front() );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, aTraceMode == FILLED ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> cornerList;
|
2018-05-18 08:13:46 +00:00
|
|
|
cornerList.reserve( 5 );
|
2010-09-13 11:51:09 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I coord( aCorners[ii] );
|
|
|
|
RotatePoint( coord, aPadOrient );
|
2016-02-10 16:02:40 +00:00
|
|
|
coord += aPadPos;
|
|
|
|
cornerList.push_back( coord );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2018-05-18 08:13:46 +00:00
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList.front() );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, aTraceMode == FILLED ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2019-10-02 15:16:27 +00:00
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void HPGL_PLOTTER::FlashRegularPolygon( const VECTOR2I& aShapePos, int aRadius, int aCornerCount,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData )
|
2019-10-02 15:16:27 +00:00
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
wxASSERT( 0 );
|
|
|
|
}
|
2020-12-13 23:38:44 +00:00
|
|
|
|
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
bool HPGL_PLOTTER::startItem( const VECTOR2D& location )
|
2020-12-13 23:38:44 +00:00
|
|
|
{
|
|
|
|
return startOrAppendItem( location, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
void HPGL_PLOTTER::flushItem()
|
2020-12-13 23:38:44 +00:00
|
|
|
{
|
|
|
|
m_current_item = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
bool HPGL_PLOTTER::startOrAppendItem( const VECTOR2D& location, wxString const& content )
|
2020-12-13 23:38:44 +00:00
|
|
|
{
|
2020-12-14 02:01:24 +00:00
|
|
|
if( m_current_item == nullptr )
|
|
|
|
{
|
2020-12-21 23:27:31 +00:00
|
|
|
HPGL_ITEM item;
|
|
|
|
item.loc_start = location;
|
|
|
|
item.loc_end = location;
|
|
|
|
item.bbox = BOX2D( location );
|
2022-06-28 18:21:00 +00:00
|
|
|
item.pen = m_penNumber;
|
2022-06-28 18:06:17 +00:00
|
|
|
item.dashType = m_lineStyle;
|
2020-12-21 23:27:31 +00:00
|
|
|
item.content = content;
|
2020-12-13 23:38:44 +00:00
|
|
|
m_items.push_back( item );
|
|
|
|
m_current_item = &m_items.back();
|
|
|
|
return true;
|
2020-12-14 02:01:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-13 23:38:44 +00:00
|
|
|
m_current_item->content << content;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 02:01:24 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
void HPGL_PLOTTER::sortItems( std::list<HPGL_ITEM>& items )
|
|
|
|
{
|
|
|
|
if( items.size() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::list<HPGL_ITEM> target;
|
|
|
|
|
|
|
|
// Plot items are sorted to improve print time on mechanical plotters. This
|
|
|
|
// means
|
|
|
|
// 1) Avoid excess pen-switching - once a pen is selected, keep printing
|
|
|
|
// with it until no more items using that pen remain.
|
|
|
|
// 2) Within the items for one pen, avoid bouncing back and forth around
|
|
|
|
// the page; items should be sequenced with nearby items.
|
|
|
|
//
|
2021-08-17 17:44:11 +00:00
|
|
|
// This is essentially a variant of the Traveling Salesman Problem where
|
2020-12-14 02:01:24 +00:00
|
|
|
// the cities are themselves edges that must be traversed. This is of course
|
|
|
|
// a famously NP-Hard problem and this particular variant has a monstrous
|
|
|
|
// number of "cities". For now, we're using a naive nearest-neighbor search,
|
|
|
|
// which is less than optimal but (usually!) better than nothing, very
|
|
|
|
// simple to implement, and fast enough.
|
|
|
|
//
|
|
|
|
// Items are moved one at a time from `items` into `target`, searching
|
|
|
|
// each time for the first one matching the above criteria. Then, all of
|
|
|
|
// `target` is moved back into `items`.
|
|
|
|
|
|
|
|
// Get the first one started
|
|
|
|
HPGL_ITEM last_item = items.front();
|
|
|
|
items.pop_front();
|
|
|
|
target.emplace_back( last_item );
|
|
|
|
|
|
|
|
while( !items.empty() )
|
|
|
|
{
|
|
|
|
auto best_it = items.begin();
|
|
|
|
double best_dist = dpoint_dist( last_item.loc_end, best_it->loc_start );
|
|
|
|
|
|
|
|
for( auto search_it = best_it; search_it != items.end(); search_it++ )
|
|
|
|
{
|
2021-08-17 17:44:11 +00:00
|
|
|
// Immediately forget an item as "best" if another one is a better pen match
|
2020-12-14 02:01:24 +00:00
|
|
|
if( best_it->pen != last_item.pen && search_it->pen == last_item.pen )
|
|
|
|
{
|
|
|
|
best_it = search_it;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double const dist = dpoint_dist( last_item.loc_end, search_it->loc_start );
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-12-14 02:01:24 +00:00
|
|
|
if( dist < best_dist )
|
|
|
|
{
|
|
|
|
best_it = search_it;
|
|
|
|
best_dist = dist;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target.emplace_back( *best_it );
|
|
|
|
last_item = *best_it;
|
|
|
|
items.erase( best_it );
|
|
|
|
}
|
|
|
|
|
|
|
|
items.splice( items.begin(), target );
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-06-28 18:21:00 +00:00
|
|
|
const char* HPGL_PLOTTER::lineStyleCommand( PLOT_DASH_TYPE aLineStyle )
|
2020-12-14 02:01:24 +00:00
|
|
|
{
|
2022-06-28 18:21:00 +00:00
|
|
|
switch( aLineStyle )
|
2020-12-14 02:01:24 +00:00
|
|
|
{
|
2021-12-23 23:48:01 +00:00
|
|
|
case PLOT_DASH_TYPE::DASH: return "LT 2 4 1;";
|
|
|
|
case PLOT_DASH_TYPE::DOT: return "LT 1 1 1;";
|
|
|
|
case PLOT_DASH_TYPE::DASHDOT: return "LT 4 6 1;";
|
|
|
|
case PLOT_DASH_TYPE::DASHDOTDOT: return "LT 7 8 1;";
|
|
|
|
default: return "LT;";
|
2020-12-14 02:01:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
static double dpoint_dist( const VECTOR2D& a, const VECTOR2D& b )
|
2020-12-14 02:01:24 +00:00
|
|
|
{
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D diff = a - b;
|
2020-12-14 02:01:24 +00:00
|
|
|
return sqrt( diff.x * diff.x + diff.y * diff.y );
|
|
|
|
}
|