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
|
|
|
* Filled primitive are not supported, but some could be using HPGL/2
|
|
|
|
* 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-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>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// HPGL scale factor (1 PLU = 1/40mm IIRC)
|
|
|
|
static const double PLUsPERDECIMIL = 0.102041;
|
2007-05-28 18:09:49 +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,
|
|
|
|
double aScale, bool aMirror )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( !outputFile );
|
|
|
|
plotOffset = aOffset;
|
|
|
|
plotScale = aScale;
|
|
|
|
iuPerDeviceUnit = PLUsPERDECIMIL / aIusPerDecimil;
|
|
|
|
/* Compute the paper size in IUs */
|
|
|
|
paperSize = pageInfo.GetSizeMils();
|
|
|
|
paperSize.x *= 10.0 * aIusPerDecimil;
|
|
|
|
paperSize.y *= 10.0 * aIusPerDecimil;
|
|
|
|
SetDefaultLineWidth( 0 ); // HPGL has pen sizes instead
|
2010-12-11 18:40:39 +00:00
|
|
|
plotMirror = aMirror;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* At the start of the HPGL plot pen speed and number are requested
|
|
|
|
*/
|
|
|
|
bool HPGL_PLOTTER::StartPlot( FILE* fout )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( !outputFile );
|
|
|
|
outputFile = fout;
|
|
|
|
fprintf( outputFile, "IN;VS%d;PU;PA;SP%d;\n", penSpeed, penNumber );
|
2010-03-31 16:59:32 +00:00
|
|
|
return true;
|
2007-05-28 18:09:49 +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-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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* HPGL circle: fill not supported
|
|
|
|
*/
|
|
|
|
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 );
|
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-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* HPGL polygon: fill not supported (but closed, at least)
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2012-05-03 18:37: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;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2011-04-20 08:13:21 +00:00
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( aCornerList[ii] );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Close polygon if filled.
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aFill )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
int ii = aCornerList.size() - 1;
|
|
|
|
if( aCornerList[ii] != aCornerList[0] )
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( aCornerList[0] );
|
2009-06-28 16:50:42 +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 );
|
2009-11-23 15:16:50 +00:00
|
|
|
switch( plume )
|
|
|
|
{
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'U':
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'D':
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case 'Z':
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "PU;", outputFile );
|
|
|
|
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 )
|
|
|
|
fprintf( outputFile, "PA %.0f,%.0fd;\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 );
|
2009-11-23 15:16:50 +00:00
|
|
|
if( dashed )
|
|
|
|
fputs( "LI 2;\n", stderr );
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2009-11-23 15:16:50 +00:00
|
|
|
fputs( "LI;\n", stderr );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::ThickSegment( const wxPoint& start, const wxPoint& end,
|
|
|
|
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;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// Suppress overlap if pen is too big or in line mode
|
|
|
|
if( (penDiameter >= width) || (tracemode == LINE) )
|
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
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::Arc( const wxPoint& centre, int StAngle, int 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
|
|
|
|
2010-12-11 18:40:39 +00:00
|
|
|
if( plotMirror )
|
2009-11-23 15:16:50 +00:00
|
|
|
angle = (StAngle - EndAngle) / 10.0;
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2009-11-23 15:16:50 +00:00
|
|
|
angle = (EndAngle - StAngle) / 10.0;
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Calculate start point,
|
2012-05-03 18:37:56 +00:00
|
|
|
wxPoint cmap;
|
|
|
|
cmap.x = (int) ( centre.x + ( radius * cos( RAD2DEG( StAngle / 10.0 ) ) ) );
|
|
|
|
cmap.y = (int) ( centre.y - ( radius * sin( RAD2DEG( StAngle / 10.0 ) ) ) );
|
|
|
|
DPOINT cmap_dev = userToDeviceCoordinates( cmap );
|
|
|
|
|
|
|
|
fprintf( outputFile,
|
|
|
|
"PU;PA %.0f,%.0f;PD;AA %.0f,%.0f,",
|
|
|
|
cmap_dev.x,
|
|
|
|
cmap_dev.y,
|
|
|
|
centre_dev.x,
|
|
|
|
centre_dev.y );
|
|
|
|
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.
|
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int orient,
|
|
|
|
EDA_DRAW_MODE_T trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2011-05-13 13:15:28 +00:00
|
|
|
int deltaxy, cx, cy;
|
2012-05-03 18:37:56 +00:00
|
|
|
wxSize size( aSize );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* The pad is reduced to an oval with size.y > size.x
|
|
|
|
* (Oval vertical orientation 0)
|
|
|
|
*/
|
2009-06-28 16:50:42 +00:00
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
|
|
|
EXCHG( size.x, size.y ); orient += 900;
|
|
|
|
if( orient >= 3600 )
|
|
|
|
orient -= 3600;
|
|
|
|
}
|
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
|
|
|
}
|
2011-12-31 05:44:00 +00:00
|
|
|
else // Plot in SKETCH 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 );
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
int delta = KiROUND( penDiameter - penOverlap );
|
|
|
|
int radius = diametre / 2;
|
2012-01-03 17:14:17 +00:00
|
|
|
|
|
|
|
if( trace_mode != LINE )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
radius = ( diametre - KiROUND( penDiameter ) ) / 2;
|
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
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
radius = 0;
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "PA %.0f,%.0fd;CI %.0f;\n",
|
|
|
|
pos_dev.x, pos_dev.y, rsize );
|
2009-11-23 15:16:50 +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
|
|
|
{
|
|
|
|
if( delta > 0 )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
while( (radius -= delta ) >= 0 )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
rsize = userToDeviceSize( radius );
|
|
|
|
fprintf( outputFile, "PA %.0f,%.0f;CI %.0f;\n",
|
|
|
|
pos_dev.x, pos_dev.y, rsize );
|
2009-06-28 16:50:42 +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,
|
|
|
|
int orient, EDA_DRAW_MODE_T trace_mode )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
wxSize size;
|
|
|
|
int delta;
|
|
|
|
int ox, oy, fx, fy;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
size.x = padsize.x / 2;
|
|
|
|
size.y = padsize.y / 2;
|
|
|
|
|
2012-01-03 17:14:17 +00:00
|
|
|
if( trace_mode != LINE )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
size.x = (padsize.x - (int) penDiameter) / 2;
|
|
|
|
size.y = (padsize.y - (int) penDiameter) / 2;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( size.x < 0 )
|
2009-11-23 15:16:50 +00:00
|
|
|
size.x = 0;
|
2009-06-28 16:50:42 +00:00
|
|
|
if( size.y < 0 )
|
2009-11-23 15:16:50 +00:00
|
|
|
size.y = 0;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// If a dimension is zero, the trace is reduced to 1 line.
|
2009-06-28 16:50:42 +00:00
|
|
|
if( size.x == 0 )
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
ox = pos.x;
|
|
|
|
oy = pos.y - size.y;
|
|
|
|
RotatePoint( &ox, &oy, pos.x, pos.y, orient );
|
|
|
|
fx = pos.x;
|
|
|
|
fy = pos.y + size.y;
|
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( wxPoint( ox, oy ) );
|
|
|
|
FinishTo( wxPoint( fx, fy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
return;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
if( size.y == 0 )
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
ox = pos.x - size.x;
|
|
|
|
oy = pos.y;
|
|
|
|
RotatePoint( &ox, &oy, pos.x, pos.y, orient );
|
|
|
|
fx = pos.x + size.x;
|
|
|
|
fy = pos.y;
|
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( wxPoint( ox, oy ) );
|
|
|
|
FinishTo( wxPoint( fx, fy ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
ox = pos.x - size.x;
|
|
|
|
oy = pos.y - size.y;
|
2009-06-28 16:50:42 +00:00
|
|
|
RotatePoint( &ox, &oy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( wxPoint( ox, oy ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
fx = pos.x - size.x;
|
|
|
|
fy = pos.y + size.y;
|
2009-06-28 16:50:42 +00:00
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
fx = pos.x + size.x;
|
|
|
|
fy = pos.y + size.y;
|
2009-06-28 16:50:42 +00:00
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
fx = pos.x + size.x;
|
|
|
|
fy = pos.y - size.y;
|
2009-06-28 16:50:42 +00:00
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
FinishTo( wxPoint( ox, oy ) );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
2011-12-31 05:44:00 +00:00
|
|
|
// Plot in filled mode.
|
2012-05-03 18:37:56 +00:00
|
|
|
delta = (int) (penDiameter - penOverlap);
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
if( delta > 0 )
|
|
|
|
while( (size.x > 0) && (size.y > 0) )
|
|
|
|
{
|
|
|
|
size.x -= delta;
|
|
|
|
size.y -= delta;
|
|
|
|
|
|
|
|
if( size.x < 0 )
|
|
|
|
size.x = 0;
|
|
|
|
if( size.y < 0 )
|
|
|
|
size.y = 0;
|
|
|
|
|
|
|
|
ox = pos.x - size.x;
|
|
|
|
oy = pos.y - size.y;
|
|
|
|
RotatePoint( &ox, &oy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( wxPoint( ox, oy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
fx = pos.x - size.x;
|
|
|
|
fy = pos.y + size.y;
|
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
fx = pos.x + size.x;
|
|
|
|
fy = pos.y + size.y;
|
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
fx = pos.x + size.x;
|
|
|
|
fy = pos.y - size.y;
|
|
|
|
RotatePoint( &fx, &fy, pos.x, pos.y, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( wxPoint( fx, fy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
FinishTo( wxPoint( ox, oy ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void HPGL_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
|
|
|
|
int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2010-09-13 11:51:09 +00:00
|
|
|
wxPoint polygone[4]; // coordinates of corners relatives to the pad
|
|
|
|
wxPoint coord[4]; // absolute coordinates of corners (coordinates in plotter space)
|
|
|
|
int move;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
move = KiROUND( penDiameter );
|
2010-09-13 11:51:09 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
polygone[ii] = aCorners[ii];
|
|
|
|
|
|
|
|
// polygone[0] is assumed the lower left
|
|
|
|
// polygone[1] is assumed the upper left
|
|
|
|
// polygone[2] is assumed the upper right
|
|
|
|
// polygone[3] is assumed the lower right
|
|
|
|
|
|
|
|
// Plot the outline:
|
2009-11-23 15:16:50 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
coord[ii] = polygone[ii];
|
|
|
|
RotatePoint( &coord[ii], aPadOrient );
|
|
|
|
coord[ii] += aPadPos;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( coord[0] );
|
|
|
|
LineTo( coord[1] );
|
|
|
|
LineTo( coord[2] );
|
|
|
|
LineTo( coord[3] );
|
|
|
|
FinishTo( coord[0] );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2010-09-13 11:51:09 +00:00
|
|
|
// Fill shape:
|
|
|
|
if( aTrace_Mode == FILLED )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
// TODO: replace this par the HPGL plot polygon.
|
2009-11-23 15:16:50 +00:00
|
|
|
int jj;
|
2011-12-31 05:44:00 +00:00
|
|
|
// Fill the shape
|
2012-05-03 18:37:56 +00:00
|
|
|
move = KiROUND( penDiameter - penOverlap );
|
2011-12-31 05:44:00 +00:00
|
|
|
// Calculate fill height.
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
if( polygone[0].y == polygone[3].y ) // Horizontal
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
jj = polygone[3].y - (int) ( penDiameter + ( 2 * penOverlap ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
2010-09-13 11:51:09 +00:00
|
|
|
else // vertical
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
jj = polygone[3].x - (int) ( penDiameter + ( 2 * penOverlap ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Calculation of dd = number of segments was traced to fill.
|
2012-05-03 18:37:56 +00:00
|
|
|
jj = jj / (int) ( penDiameter - penOverlap );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Trace the outline.
|
2009-11-23 15:16:50 +00:00
|
|
|
for( ; jj > 0; jj-- )
|
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
polygone[0].x += move;
|
|
|
|
polygone[0].y -= move;
|
|
|
|
polygone[1].x += move;
|
|
|
|
polygone[1].y += move;
|
|
|
|
polygone[2].x -= move;
|
|
|
|
polygone[2].y += move;
|
|
|
|
polygone[3].x -= move;
|
|
|
|
polygone[3].y -= move;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Test for crossed vertexes.
|
2009-11-23 15:16:50 +00:00
|
|
|
if( polygone[0].x > polygone[3].x ) /* X axis intersection on
|
|
|
|
*vertexes 0 and 3 */
|
|
|
|
{
|
|
|
|
polygone[0].x = polygone[3].x = 0;
|
|
|
|
}
|
|
|
|
if( polygone[1].x > polygone[2].x ) /* X axis intersection on
|
|
|
|
*vertexes 1 and 2 */
|
|
|
|
{
|
|
|
|
polygone[1].x = polygone[2].x = 0;
|
|
|
|
}
|
|
|
|
if( polygone[1].y > polygone[0].y ) /* Y axis intersection on
|
|
|
|
*vertexes 0 and 1 */
|
|
|
|
{
|
|
|
|
polygone[0].y = polygone[1].y = 0;
|
|
|
|
}
|
|
|
|
if( polygone[2].y > polygone[3].y ) /* Y axis intersection on
|
|
|
|
*vertexes 2 and 3 */
|
|
|
|
{
|
|
|
|
polygone[2].y = polygone[3].y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
coord[ii] = polygone[ii];
|
|
|
|
RotatePoint( &coord[ii], aPadOrient );
|
|
|
|
coord[ii] += aPadPos;
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( coord[0] );
|
|
|
|
LineTo( coord[1] );
|
|
|
|
LineTo( coord[2] );
|
|
|
|
LineTo( coord[3] );
|
|
|
|
FinishTo( coord[0] );
|
2009-11-23 15:16:50 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2012-05-03 18:37:56 +00:00
|
|
|
|