2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-02-10 16:02:40 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2016 KiCad Developers, see CHANGELOG.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
|
|
|
/**
|
|
|
|
* @file common_plotHPGL_functions.cpp
|
|
|
|
* @brief KiCad: Common plot HPGL Routines
|
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
|
|
|
|
* 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};
|
|
|
|
* h [-127.9999 .. 127.9999] Anzahl der Zeichen horizontal
|
|
|
|
* v [-127.9999 .. 127.9999] Anzahl der Zeichen vertikal
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
2016-02-10 16:02:40 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2007-05-28 18:09:49 +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";
|
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
// HPGL scale factor (1 PLU = 1/40mm = 25 micrometers)
|
2012-05-03 18:37:56 +00:00
|
|
|
static const double PLUsPERDECIMIL = 0.102041;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
HPGL_PLOTTER::HPGL_PLOTTER()
|
|
|
|
{
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
|
2012-09-18 08:39:56 +00:00
|
|
|
double aScale, bool aMirror )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( !outputFile );
|
|
|
|
plotOffset = aOffset;
|
2012-09-18 08:39:56 +00:00
|
|
|
plotScale = aScale;
|
2012-08-29 20:13:47 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
2012-05-03 18:37:56 +00:00
|
|
|
iuPerDeviceUnit = PLUsPERDECIMIL / aIusPerDecimil;
|
|
|
|
/* Compute the paper size in IUs */
|
2012-09-18 08:39:56 +00:00
|
|
|
paperSize = pageInfo.GetSizeMils();
|
2012-05-03 18:37:56 +00:00
|
|
|
paperSize.x *= 10.0 * aIusPerDecimil;
|
|
|
|
paperSize.y *= 10.0 * aIusPerDecimil;
|
2012-09-18 08:39:56 +00:00
|
|
|
SetDefaultLineWidth( 0 ); // HPGL has pen sizes instead
|
2013-12-06 18:31:15 +00:00
|
|
|
m_plotMirror = aMirror;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* At the start of the HPGL plot pen speed and number are requested
|
|
|
|
*/
|
2012-10-13 18:54:33 +00:00
|
|
|
bool HPGL_PLOTTER::StartPlot()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
wxASSERT( outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "IN;VS%d;PU;PA;SP%d;\n", penSpeed, penNumber );
|
2016-02-11 12:14:46 +00:00
|
|
|
|
|
|
|
// Set HPGL Pen Thickness (in mm) (usefull in polygon fill command)
|
|
|
|
double penThicknessMM = userToDeviceSize( penDiameter )/40;
|
|
|
|
fprintf( outputFile, "PT %.1f;\n", penThicknessMM );
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* HPGL end of plot: pen return and release
|
|
|
|
*/
|
|
|
|
bool HPGL_PLOTTER::EndPlot()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
fputs( "PU;PA;SP0;\n", outputFile );
|
|
|
|
fclose( outputFile );
|
|
|
|
outputFile = NULL;
|
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 )
|
|
|
|
{
|
|
|
|
penDiameter = diameter;
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* HPGL rectangle: fill not supported
|
|
|
|
*/
|
|
|
|
void HPGL_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
DPOINT p2dev = userToDeviceCoordinates( p2 );
|
|
|
|
MoveTo( p1 );
|
|
|
|
fprintf( outputFile, "EA %.0f,%.0f;\n", p2dev.x, p2dev.y );
|
|
|
|
PenFinish();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-11 12:14:46 +00:00
|
|
|
// HPGL circle
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::Circle( const wxPoint& centre, int diameter, FILL_T fill,
|
|
|
|
int width )
|
2008-06-30 13:47:55 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
double radius = userToDeviceSize( diameter / 2 );
|
2016-02-11 12:14:46 +00:00
|
|
|
SetCurrentLineWidth( width );
|
|
|
|
|
|
|
|
if( fill == FILLED_SHAPE )
|
|
|
|
{
|
|
|
|
// Draw the filled area
|
|
|
|
MoveTo( centre );
|
|
|
|
fprintf( outputFile, "PM 0; CI %g;\n", radius );
|
|
|
|
fprintf( outputFile, hpgl_end_polygon_cmd ); // Close, fill polygon and draw outlines
|
|
|
|
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
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( centre );
|
|
|
|
fprintf( outputFile, "CI %g;\n", radius );
|
|
|
|
PenFinish();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-30 13:47:55 +00:00
|
|
|
|
|
|
|
|
2012-09-17 17:42:27 +00:00
|
|
|
/**
|
2016-02-10 16:02:40 +00:00
|
|
|
* HPGL polygon:
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
void HPGL_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
|
|
|
|
FILL_T aFill, int aWidth )
|
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;
|
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
if( aFill == 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 );
|
|
|
|
fprintf( outputFile, "PM 0;\n" ); // Start polygon
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-02-11 12:14:46 +00:00
|
|
|
fprintf( outputFile, hpgl_end_polygon_cmd ); // Close, fill polygon and draw outlines
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Plot only the polygon outline.
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
LineTo( aCornerList[ii] );
|
|
|
|
|
|
|
|
// Always close polygon if filled.
|
|
|
|
if( aFill )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Pen control logic (remove redundant pen activations)
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::penControl( char plume )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
switch( plume )
|
|
|
|
{
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'U':
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( penState != 'U' )
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "PU;", outputFile );
|
|
|
|
penState = 'U';
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'D':
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( penState != 'D' )
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "PD;", outputFile );
|
|
|
|
penState = 'D';
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'Z':
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "PU;", outputFile );
|
2012-09-18 08:39:56 +00:00
|
|
|
penState = 'U';
|
|
|
|
penLastpos.x = -1;
|
|
|
|
penLastpos.y = -1;
|
2009-11-23 15:16:50 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::PenTo( const wxPoint& pos, char plume )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
penControl( 'Z' );
|
2009-06-28 16:50:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
penControl( plume );
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( penLastpos != pos )
|
2012-08-29 17:29:45 +00:00
|
|
|
fprintf( outputFile, "PA %.0f,%.0f;\n", pos_dev.x, pos_dev.y );
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* HPGL supports dashed lines
|
|
|
|
*/
|
|
|
|
void HPGL_PLOTTER::SetDash( bool dashed )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( dashed )
|
2012-09-17 17:42:27 +00:00
|
|
|
fputs( "LI 2;\n", outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2012-09-17 17:42:27 +00:00
|
|
|
fputs( "LI;\n", outputFile );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-09-17 17:42:27 +00:00
|
|
|
void HPGL_PLOTTER::ThickSegment( const wxPoint& start, const wxPoint& end,
|
2012-05-03 18:37:56 +00:00
|
|
|
int width, EDA_DRAW_MODE_T tracemode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
wxPoint center;
|
|
|
|
wxSize size;
|
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
// Suppress overlap if pen is too big
|
|
|
|
if( 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
|
2012-05-03 18:37:56 +00:00
|
|
|
segmentAsOval( start, end, width, tracemode );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot an arc:
|
|
|
|
* Center = center coord
|
|
|
|
* Stangl, endAngle = angle of beginning and end
|
|
|
|
* Radius = radius of the arc
|
|
|
|
* Command
|
|
|
|
* PU PY x, y; PD start_arc_X AA, start_arc_Y, angle, NbSegm; PU;
|
|
|
|
* Or PU PY x, y; PD start_arc_X AA, start_arc_Y, angle, PU;
|
2008-03-22 05:55:06 +00:00
|
|
|
*/
|
2013-05-05 07:17:48 +00:00
|
|
|
void HPGL_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
|
2009-11-23 15:16:50 +00:00
|
|
|
FILL_T fill, int width )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
double angle;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( radius <= 0 )
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
DPOINT centre_dev = userToDeviceCoordinates( centre );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2013-12-06 18:31:15 +00:00
|
|
|
if( m_plotMirror )
|
2013-02-04 00:53:48 +00:00
|
|
|
angle = StAngle - EndAngle;
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2013-02-04 00:53:48 +00:00
|
|
|
angle = EndAngle - StAngle;
|
2013-12-06 18:31:15 +00:00
|
|
|
|
2013-02-04 00:53:48 +00:00
|
|
|
NORMALIZE_ANGLE_180( angle );
|
|
|
|
angle /= 10;
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2013-12-06 18:31:15 +00:00
|
|
|
// Calculate arc start point:
|
2012-05-03 18:37:56 +00:00
|
|
|
wxPoint cmap;
|
2013-05-02 18:06:58 +00:00
|
|
|
cmap.x = centre.x + KiROUND( cosdecideg( radius, StAngle ) );
|
|
|
|
cmap.y = centre.y - KiROUND( sindecideg( radius, StAngle ) );
|
2012-09-18 08:39:56 +00:00
|
|
|
DPOINT cmap_dev = userToDeviceCoordinates( cmap );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
|
|
|
fprintf( outputFile,
|
|
|
|
"PU;PA %.0f,%.0f;PD;AA %.0f,%.0f,",
|
2013-12-06 18:31:15 +00:00
|
|
|
cmap_dev.x, cmap_dev.y,
|
|
|
|
centre_dev.x, centre_dev.y );
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "%.0f", angle );
|
|
|
|
fprintf( outputFile, ";PU;\n" );
|
|
|
|
PenFinish();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot oval pad.
|
|
|
|
*/
|
2013-05-05 07:17:48 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
|
2012-05-03 18:37:56 +00:00
|
|
|
EDA_DRAW_MODE_T trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2012-09-18 08:39:56 +00:00
|
|
|
int deltaxy, cx, cy;
|
|
|
|
wxSize size( aSize );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
/* The pad will be drawn as an oblong shape with size.y > size.x
|
2009-11-23 15:16:50 +00:00
|
|
|
* (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 );
|
2013-05-02 18:06:58 +00:00
|
|
|
orient = AddAngles( orient, 900 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
deltaxy = size.y - size.x; // distance between centers of the oval
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
FlashPadRect( pos, wxSize( size.x, deltaxy + KiROUND( penDiameter ) ),
|
|
|
|
orient, trace_mode );
|
2009-06-28 16:50:42 +00:00
|
|
|
cx = 0; cy = deltaxy / 2;
|
|
|
|
RotatePoint( &cx, &cy, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
FlashPadCircle( wxPoint( cx + pos.x, cy + pos.y ), size.x, trace_mode );
|
2009-06-28 16:50:42 +00:00
|
|
|
cx = 0; cy = -deltaxy / 2;
|
|
|
|
RotatePoint( &cx, &cy, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
FlashPadCircle( wxPoint( cx + pos.x, cy + pos.y ), size.x, trace_mode );
|
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
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
sketchOval( pos, size, orient, KiROUND( 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
|
|
|
|
|
|
|
/* Plot round pad or via.
|
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadCircle( const wxPoint& pos, int diametre,
|
|
|
|
EDA_DRAW_MODE_T trace_mode )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2012-09-18 08:39:56 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
int radius = diametre / 2;
|
|
|
|
|
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
|
|
|
// if filled mode, the pen diameter is removed from diameter
|
|
|
|
// to keep the pad size
|
|
|
|
radius -= KiROUND( penDiameter ) / 2;
|
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2012-05-03 18:37:56 +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
|
|
|
|
MoveTo( wxPoint( pos.x+radius, pos.y ) );
|
|
|
|
// Plot filled area and its outline
|
2016-02-11 12:14:46 +00:00
|
|
|
fprintf( outputFile, "PM 0; PA %.0f,%.0f;CI %.0f;%s",
|
|
|
|
pos_dev.x, pos_dev.y, rsize, hpgl_end_polygon_cmd );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw outline only:
|
|
|
|
fprintf( outputFile, "PA %.0f,%.0f;CI %.0f;\n",
|
|
|
|
pos_dev.x, pos_dev.y, rsize );
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& padsize,
|
2013-05-05 07:17:48 +00:00
|
|
|
double orient, EDA_DRAW_MODE_T trace_mode )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// Build rect polygon:
|
|
|
|
std::vector<wxPoint> corners;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
int dx = padsize.x / 2;
|
|
|
|
int dy = padsize.y / 2;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
|
|
|
// in filled mode, the pen diameter is removed from size
|
|
|
|
// to compensate the extra size due to this pen size
|
|
|
|
dx -= KiROUND( penDiameter ) / 2;
|
|
|
|
dx = std::max( dx, 0);
|
|
|
|
dy -= KiROUND( penDiameter ) / 2;
|
|
|
|
dy = std::max( dy, 0);
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
corners.push_back( wxPoint( - dx, - dy ) );
|
|
|
|
corners.push_back( wxPoint( - dx, + dy ) );
|
|
|
|
corners.push_back( wxPoint( + dx, + dy ) );
|
|
|
|
corners.push_back( wxPoint( + dx, - dy ) );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
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
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
RotatePoint( &corners[ii], orient );
|
|
|
|
corners[ii] += pos;
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
PlotPoly( corners, trace_mode == FILLED ? FILLED_SHAPE : NO_FILL );
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
|
|
|
|
int aCornerRadius, double aOrient,
|
|
|
|
EDA_DRAW_MODE_T aTraceMode )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
const int segmentToCircleCount = 32;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
wxSize 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
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// in filled mode, the pen diameter is removed from size
|
|
|
|
// to keep the pad size
|
|
|
|
size.x -= KiROUND( penDiameter ) / 2;
|
|
|
|
size.x = std::max( size.x, 0);
|
|
|
|
size.y -= KiROUND( penDiameter ) / 2;
|
|
|
|
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
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
TransformRoundRectToPolygon( outline, aPadPos, size, aOrient,
|
|
|
|
aCornerRadius, segmentToCircleCount );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.reserve( segmentToCircleCount + 4 );
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
|
|
|
cornerList.push_back( wxPoint( poly.Point( ii ).x, poly.Point( ii ).y ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
PlotPoly( cornerList, aTraceMode == FILLED ? FILLED_SHAPE : NO_FILL );
|
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
|
|
|
|
SHAPE_POLY_SET* aPolygons,
|
|
|
|
EDA_DRAW_MODE_T aTraceMode )
|
|
|
|
{
|
|
|
|
std::vector< wxPoint > 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
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
for( int ii = 1; ii < poly.PointCount(); ++ii )
|
|
|
|
cornerList.push_back( wxPoint( poly.Point( ii ).x, poly.Point( ii ).y ) );
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
PlotPoly( cornerList, aTraceMode == FILLED ? FILLED_SHAPE : NO_FILL );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-09-18 08:39:56 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint* aCorners,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.reserve( 4 );
|
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
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
wxPoint coord( aCorners[ii] );
|
|
|
|
RotatePoint( &coord, aPadOrient );
|
|
|
|
coord += aPadPos;
|
|
|
|
cornerList.push_back( coord );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-09-18 08:39:56 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
PlotPoly( cornerList, aTrace_Mode == FILLED ? FILLED_SHAPE : NO_FILL );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|