2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file common_plotPS_functions.cpp
|
|
|
|
* @brief Kicad: Common plot Postscript Routines
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
/* Set the plot offset for the current plotting */
|
2010-12-11 18:40:39 +00:00
|
|
|
void PS_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( !output_file );
|
2010-12-11 18:40:39 +00:00
|
|
|
plotMirror = aMirror;
|
|
|
|
plot_offset = aOffset;
|
2009-11-23 15:16:50 +00:00
|
|
|
plot_scale = aScale;
|
|
|
|
device_scale = 1; /* PS references in decimals */
|
|
|
|
set_default_line_width( 100 ); /* default line width in 1/1000 inch */
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Set the default line width (in 1/1000 inch) for the current plotting
|
2007-08-20 13:28:34 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::set_default_line_width( int width )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
default_pen_width = width; // line width in 1/1000 inch
|
2009-06-28 16:50:42 +00:00
|
|
|
current_pen_width = -1;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Set the current line width (in 1/1000 inch) for the next plot
|
2007-08-20 13:28:34 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::set_current_line_width( int width )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2008-03-22 05:55:06 +00:00
|
|
|
int pen_width;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( width >= 0 )
|
2008-03-22 05:55:06 +00:00
|
|
|
pen_width = width;
|
|
|
|
else
|
2009-06-28 16:50:42 +00:00
|
|
|
pen_width = default_pen_width;
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( pen_width != current_pen_width )
|
2009-08-28 18:03:22 +00:00
|
|
|
fprintf( output_file, "%g setlinewidth\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
user_to_device_size( pen_width ) );
|
2007-08-20 13:28:34 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
current_pen_width = pen_width;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
|
|
|
|
/* Print the postscript set color command:
|
|
|
|
* r g b setrgbcolor,
|
|
|
|
* r, g, b = color values (= 0 .. 1.0 )
|
|
|
|
*
|
|
|
|
* color = color index in ColorRefs[]
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::set_color( int color )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2009-08-21 19:13:55 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Return at invalid color index */
|
|
|
|
if( color < 0 )
|
|
|
|
return;
|
2009-08-21 19:13:55 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( color_mode )
|
2009-08-21 19:13:55 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( negative_mode )
|
|
|
|
{
|
|
|
|
fprintf( output_file, "%.3g %.3g %.3g setrgbcolor\n",
|
|
|
|
(double) 1.0 - ColorRefs[color].m_Red / 255,
|
|
|
|
(double) 1.0 - ColorRefs[color].m_Green / 255,
|
|
|
|
(double) 1.0 - ColorRefs[color].m_Blue / 255 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( output_file, "%.3g %.3g %.3g setrgbcolor\n",
|
|
|
|
(double) ColorRefs[color].m_Red / 255,
|
|
|
|
(double) ColorRefs[color].m_Green / 255,
|
|
|
|
(double) ColorRefs[color].m_Blue / 255 );
|
|
|
|
}
|
2009-08-21 19:13:55 +00:00
|
|
|
}
|
2009-08-28 18:03:22 +00:00
|
|
|
else
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
/* B/W Mode - Use BLACK or WHITE for all items
|
|
|
|
* note the 2 colors are used in B&W mode, mainly by Pcbnew to draw
|
|
|
|
* holes in white on pads in black
|
|
|
|
*/
|
|
|
|
int bwcolor = WHITE;
|
2009-08-28 18:03:22 +00:00
|
|
|
if( color != WHITE )
|
2009-11-23 15:16:50 +00:00
|
|
|
bwcolor = BLACK;
|
|
|
|
if( negative_mode )
|
|
|
|
fprintf( output_file, "%.3g %.3g %.3g setrgbcolor\n",
|
|
|
|
(double) 1.0 - ColorRefs[bwcolor].m_Red / 255,
|
|
|
|
(double) 1.0 - ColorRefs[bwcolor].m_Green / 255,
|
|
|
|
(double) 1.0 - ColorRefs[bwcolor].m_Blue / 255 );
|
|
|
|
else
|
|
|
|
fprintf( output_file, "%.3g %.3g %.3g setrgbcolor\n",
|
|
|
|
(double) ColorRefs[bwcolor].m_Red / 255,
|
|
|
|
(double) ColorRefs[bwcolor].m_Green / 255,
|
|
|
|
(double) ColorRefs[bwcolor].m_Blue / 255 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
void PS_PLOTTER::set_dash( bool dashed )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
if( dashed )
|
|
|
|
fputs( "dashedline\n", stderr );
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2009-11-23 15:16:50 +00:00
|
|
|
fputs( "solidline\n", stderr );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
void PS_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width )
|
2008-06-30 13:47:55 +00:00
|
|
|
{
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( p1 );
|
|
|
|
user_to_device_coordinates( p2 );
|
2008-06-30 13:47:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
set_current_line_width( width );
|
|
|
|
fprintf( output_file, "%d %d %d %d rect%d\n", p1.x, p1.y,
|
2009-11-23 15:16:50 +00:00
|
|
|
p2.x - p1.x, p2.y - p1.y, fill );
|
2008-06-30 13:47:55 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
void PS_PLOTTER::circle( wxPoint pos, int diametre, FILL_T fill, int width )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( pos );
|
2009-11-23 15:16:50 +00:00
|
|
|
double radius = user_to_device_size( diametre / 2.0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( radius < 1 )
|
|
|
|
radius = 1;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
set_current_line_width( width );
|
2009-11-23 15:16:50 +00:00
|
|
|
fprintf( output_file, "%d %d %g cir%d\n", pos.x, pos.y, radius, fill );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Plot an arc:
|
2007-08-20 13:28:34 +00:00
|
|
|
* StAngle, EndAngle = start and end arc in 0.1 degree
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::arc( wxPoint centre, int StAngle, int EndAngle, int radius,
|
|
|
|
FILL_T fill, int width )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
if( radius <= 0 )
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-24 17:17:03 +00:00
|
|
|
if( StAngle > EndAngle )
|
|
|
|
EXCHG( StAngle, EndAngle );
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
set_current_line_width( width );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Calculate start point.
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( centre );
|
2009-11-23 15:16:50 +00:00
|
|
|
radius = wxRound( user_to_device_size( radius ) );
|
2010-12-11 18:40:39 +00:00
|
|
|
if( plotMirror )
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%d %d %d %g %g arc%d\n", centre.x, centre.y,
|
2009-11-23 15:16:50 +00:00
|
|
|
radius, (double) -EndAngle / 10, (double) -StAngle / 10,
|
|
|
|
fill );
|
2008-03-22 05:55:06 +00:00
|
|
|
else
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%d %d %d %g %g arc%d\n", centre.x, centre.y,
|
2009-11-23 15:16:50 +00:00
|
|
|
radius, (double) StAngle / 10, (double) EndAngle / 10,
|
|
|
|
fill );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
/*
|
|
|
|
* Function PlotPoly
|
|
|
|
* Draw a polygon (filled or not) in POSTSCRIPT format
|
|
|
|
* param aCornerList = corners list
|
|
|
|
* param aFill :if true : filled polygon
|
|
|
|
* param aWidth = line width
|
2007-08-20 13:28:34 +00:00
|
|
|
*/
|
2011-04-20 08:13:21 +00:00
|
|
|
void PS_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList.size() <= 1 )
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
set_current_line_width( aWidth );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
wxPoint pos = aCornerList[0];
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( pos );
|
|
|
|
fprintf( output_file, "newpath\n%d %d moveto\n", pos.x, pos.y );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
pos = aCornerList[ii];
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( pos );
|
|
|
|
fprintf( output_file, "%d %d lineto\n", pos.x, pos.y );
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 08:05:13 +00:00
|
|
|
// Close path
|
2011-04-20 08:13:21 +00:00
|
|
|
fprintf( output_file, "poly%d\n", aFill );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/*
|
|
|
|
* Function PlotImage
|
|
|
|
* Only some plotters can plot image bitmaps
|
|
|
|
* for plotters that cannot plot a bitmap, a rectangle is plotted
|
|
|
|
* param aImage = the bitmap
|
|
|
|
* param aPos = position of the center of the bitmap
|
|
|
|
* param aScaleFactor = the scale factor to apply to the bitmap size
|
|
|
|
* (this is not the plot scale factor)
|
|
|
|
*/
|
|
|
|
void PS_PLOTTER::PlotImage( wxImage & aImage, wxPoint aPos, double aScaleFactor )
|
|
|
|
{
|
|
|
|
wxSize pix_size; // size of the bitmap in pixels
|
|
|
|
pix_size.x = aImage.GetWidth();
|
|
|
|
pix_size.y = aImage.GetHeight();
|
|
|
|
wxSize drawsize; // requested size of image
|
|
|
|
drawsize.x = wxRound( aScaleFactor * pix_size.x );
|
|
|
|
drawsize.y = wxRound( aScaleFactor * pix_size.y );
|
|
|
|
|
|
|
|
// calculate the bottom left corner position of bitmap
|
|
|
|
wxPoint start = aPos;
|
|
|
|
start.x -= drawsize.x / 2; // left
|
|
|
|
start.y += drawsize.y / 2; // bottom (Y axis reversed)
|
|
|
|
|
|
|
|
// calculate the top right corner position of bitmap
|
|
|
|
wxPoint end;
|
|
|
|
end.x = start.x + drawsize.x;
|
|
|
|
end.y = start.y - drawsize.y;
|
|
|
|
|
|
|
|
fprintf( output_file, "/origstate save def\n" );
|
|
|
|
fprintf( output_file, "/pix %d string def\n", pix_size.x );
|
|
|
|
fprintf( output_file, "/greys %d string def\n", pix_size.x );
|
|
|
|
|
|
|
|
// Locate lower-left corner of image
|
|
|
|
user_to_device_coordinates( start );
|
|
|
|
fprintf( output_file, "%d %d translate\n", start.x, start.y );
|
|
|
|
// Map image size to device
|
|
|
|
user_to_device_coordinates( end );
|
|
|
|
fprintf( output_file, "%d %d scale\n",
|
|
|
|
ABS(end.x - start.x), ABS(end.y - start.y));
|
|
|
|
|
|
|
|
// Dimensions of source image (in pixels
|
|
|
|
fprintf( output_file, "%d %d 8", pix_size.x, pix_size.y );
|
|
|
|
// Map unit square to source
|
|
|
|
fprintf( output_file, " [%d 0 0 %d 0 %d]\n", pix_size.x, -pix_size.y , pix_size.y);
|
|
|
|
// include image data in ps file
|
|
|
|
fprintf( output_file, "{currentfile pix readhexstring pop}\n" );
|
|
|
|
fprintf( output_file, "false 3 colorimage\n");
|
|
|
|
// Single data source, 3 colors, Output RGB data (hexadecimal)
|
|
|
|
int jj = 0;
|
|
|
|
for( int yy = 0; yy < pix_size.y; yy ++ )
|
|
|
|
{
|
|
|
|
for( int xx = 0; xx < pix_size.x; xx++, jj++ )
|
|
|
|
{
|
|
|
|
if( jj >= 16 )
|
|
|
|
{
|
|
|
|
jj = 0;
|
|
|
|
fprintf( output_file, "\n");
|
|
|
|
}
|
|
|
|
int red, green, blue;
|
|
|
|
red = aImage.GetRed( xx, yy) & 0xFF;
|
|
|
|
green = aImage.GetGreen( xx, yy) & 0xFF;
|
|
|
|
blue = aImage.GetBlue( xx, yy) & 0xFF;
|
|
|
|
fprintf( output_file, "%2.2X%2.2X%2.2X", red, green, blue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( output_file, "\n");
|
|
|
|
fprintf( output_file, "origstate restore\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
/* Routine to draw to a new position
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::pen_to( wxPoint pos, char plume )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
|
|
|
if( pen_state != 'Z' )
|
|
|
|
{
|
|
|
|
fputs( "stroke\n", output_file );
|
|
|
|
pen_state = 'Z';
|
|
|
|
pen_lastpos.x = -1;
|
|
|
|
pen_lastpos.y = -1;
|
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
return;
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( pos );
|
2009-11-23 15:16:50 +00:00
|
|
|
if( pen_state == 'Z' )
|
|
|
|
{
|
|
|
|
fputs( "newpath\n", output_file );
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
if( pen_state != plume || pos != pen_lastpos )
|
|
|
|
fprintf( output_file,
|
|
|
|
"%d %d %sto\n",
|
|
|
|
pos.x,
|
|
|
|
pos.y,
|
|
|
|
( plume=='D' ) ? "line" : "move" );
|
|
|
|
pen_state = plume;
|
2009-06-28 16:50:42 +00:00
|
|
|
pen_lastpos = pos;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 13:28:34 +00:00
|
|
|
/* The code within this function (and the CloseFilePS function)
|
|
|
|
* creates postscript files whose contents comply with Adobe's
|
|
|
|
* Document Structuring Convention, as documented by assorted
|
|
|
|
* details described within the following URLs:
|
2008-03-22 05:55:06 +00:00
|
|
|
*
|
2007-08-20 13:28:34 +00:00
|
|
|
* http://en.wikipedia.org/wiki/Document_Structuring_Conventions
|
|
|
|
* http://partners.adobe.com/public/developer/en/ps/5001.DSC_Spec.pdf
|
2008-03-22 05:55:06 +00:00
|
|
|
*
|
|
|
|
*
|
2007-08-20 13:28:34 +00:00
|
|
|
* BBox is the boundary box (position and size of the "client rectangle"
|
|
|
|
* for drawings (page - margins) in mils (0.001 inch)
|
|
|
|
*/
|
2010-03-31 16:59:32 +00:00
|
|
|
bool PS_PLOTTER::start_plot( FILE* fout )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( !output_file );
|
|
|
|
wxString msg;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
output_file = fout;
|
2009-11-23 15:16:50 +00:00
|
|
|
static const char* PSMacro[] =
|
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
"/line {\n",
|
|
|
|
" newpath\n",
|
|
|
|
" moveto\n",
|
|
|
|
" lineto\n",
|
|
|
|
" stroke\n",
|
2008-06-30 13:47:55 +00:00
|
|
|
"} bind def\n",
|
2008-08-05 16:06:45 +00:00
|
|
|
"/cir0 { newpath 0 360 arc stroke } bind def\n",
|
|
|
|
"/cir1 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
|
|
|
|
"/cir2 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
|
|
|
|
"/arc0 { newpath arc stroke } bind def\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
"/arc1 { newpath 4 index 4 index moveto arc closepath gsave fill ",
|
|
|
|
"grestore stroke } bind def\n",
|
|
|
|
"/arc2 { newpath 4 index 4 index moveto arc closepath gsave fill ",
|
|
|
|
"grestore stroke } bind def\n",
|
2008-08-05 16:06:45 +00:00
|
|
|
"/poly0 { stroke } bind def\n",
|
|
|
|
"/poly1 { closepath gsave fill grestore stroke } bind def\n",
|
|
|
|
"/poly2 { closepath gsave fill grestore stroke } bind def\n",
|
|
|
|
"/rect0 { rectstroke } bind def\n",
|
|
|
|
"/rect1 { rectfill } bind def\n",
|
|
|
|
"/rect2 { rectfill } bind def\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
"/linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def\n",
|
|
|
|
"/linemode1 { 1 setlinecap 1 setlinejoin } bind def\n",
|
|
|
|
"/dashedline { [50 50] 0 setdash } bind def\n",
|
|
|
|
"/solidline { [] 0 setdash } bind def\n",
|
2008-03-22 05:55:06 +00:00
|
|
|
"gsave\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
"0.0072 0.0072 scale\n", // Configure postscript for decimals.
|
2009-05-28 17:39:40 +00:00
|
|
|
"linemode1\n",
|
2008-03-22 05:55:06 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
const double DECIMIL_TO_INCH = 0.0001;
|
|
|
|
time_t time1970 = time( NULL );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
fputs( "%!PS-Adobe-3.0\n", output_file ); // Print header
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( output_file, "%%%%Creator: %s\n", TO_UTF8( creator ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
|
|
|
// A "newline" character ("\n") is not included in the following string,
|
|
|
|
// because it is provided by the ctime() function.
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%CreationDate: %s", ctime( &time1970 ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( output_file, "%%%%Title: %s\n", TO_UTF8( filename ) );
|
2009-11-23 15:16:50 +00:00
|
|
|
fprintf( output_file, "%%%%Pages: 1\n" );
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%PageOrder: Ascend\n" );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// Print boundary box in 1/72 pixels per inch, box is in deci-mils
|
2009-06-28 16:50:42 +00:00
|
|
|
const double CONV_SCALE = DECIMIL_TO_INCH * 72;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
|
|
|
// The coordinates of the lower left corner of the boundary
|
|
|
|
// box need to be "rounded down", but the coordinates of its
|
|
|
|
// upper right corner need to be "rounded up" instead.
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%BoundingBox: 0 0 %d %d\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
(int) ceil( paper_size.y * CONV_SCALE ),
|
|
|
|
(int) ceil( paper_size.x * CONV_SCALE ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
|
|
|
// Specify the size of the sheet and the name associated with that size.
|
|
|
|
// (If the "User size" option has been selected for the sheet size,
|
|
|
|
// identify the sheet size as "Custom" (rather than as "User"), but
|
|
|
|
// otherwise use the name assigned by KiCad for each sheet size.)
|
|
|
|
//
|
|
|
|
// (The Document Structuring Convention also supports sheet weight,
|
2009-11-23 15:16:50 +00:00
|
|
|
// sheet color, and sheet type properties being specified within a
|
2008-03-22 05:55:06 +00:00
|
|
|
// %%DocumentMedia comment, but they are not being specified here;
|
|
|
|
// a zero and two null strings are subsequently provided instead.)
|
|
|
|
//
|
|
|
|
// (NOTE: m_Size.y is *supposed* to be listed before m_Size.x;
|
|
|
|
// the order in which they are specified is not wrong!)
|
2011-12-22 21:57:50 +00:00
|
|
|
// Also note pageSize is given in mils, not in internal units and must be
|
|
|
|
// converted to internal units.
|
|
|
|
wxSize pageSize = pageInfo.GetSizeMils();
|
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
if( pageInfo.IsCustom() )
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%DocumentMedia: Custom %d %d 0 () ()\n",
|
2011-12-22 21:57:50 +00:00
|
|
|
wxRound( pageSize.y * 10 * CONV_SCALE ),
|
|
|
|
wxRound( pageSize.x * 10 * CONV_SCALE ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
else // a standard paper size
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%DocumentMedia: %s %d %d 0 () ()\n",
|
2011-12-22 21:57:50 +00:00
|
|
|
TO_UTF8( pageInfo.GetType() ),
|
|
|
|
wxRound( pageSize.y * 10 * CONV_SCALE ),
|
|
|
|
wxRound( pageSize.x * 10 * CONV_SCALE ) );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%Orientation: Landscape\n" );
|
|
|
|
|
|
|
|
fprintf( output_file, "%%%%EndComments\n" );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
|
|
|
// Now specify various other details.
|
|
|
|
|
|
|
|
// The following string has been specified here (rather than within
|
|
|
|
// PSMacro[]) to highlight that it has been provided to ensure that the
|
|
|
|
// contents of the postscript file comply with the details specified
|
|
|
|
// within the Document Structuring Convention.
|
2009-06-28 16:50:42 +00:00
|
|
|
fprintf( output_file, "%%%%Page: 1 1\n" );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
for( int ii = 0; PSMacro[ii] != NULL; ii++ )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
2009-06-28 16:50:42 +00:00
|
|
|
fputs( PSMacro[ii], output_file );
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// (If support for creating postscript files with a portrait orientation
|
|
|
|
// is ever provided, determine whether it would be necessary to provide
|
|
|
|
// an "else" command and then an appropriate "sprintf" command here.)
|
2009-11-23 15:16:50 +00:00
|
|
|
fprintf( output_file, "%d 0 translate 90 rotate\n", paper_size.y );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Apply the scale adjustments
|
2009-11-23 15:16:50 +00:00
|
|
|
if( plot_scale_adjX != 1.0 || plot_scale_adjY != 1.0 )
|
|
|
|
fprintf( output_file, "%g %g scale\n",
|
|
|
|
plot_scale_adjX, plot_scale_adjY );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
// Set default line width ( g_Plot_DefaultPenWidth is in user units )
|
2009-08-28 18:03:22 +00:00
|
|
|
fprintf( output_file, "%g setlinewidth\n",
|
2009-11-23 15:16:50 +00:00
|
|
|
user_to_device_size( default_pen_width ) );
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
bool PS_PLOTTER::end_plot()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
fputs( "showpage\ngrestore\n%%EOF\n", output_file );
|
|
|
|
fclose( output_file );
|
2010-03-31 16:59:32 +00:00
|
|
|
output_file = NULL;
|
|
|
|
|
|
|
|
return true;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Plot oval pad:
|
|
|
|
* pos - Position of pad.
|
|
|
|
* Dimensions dx, dy,
|
|
|
|
* Orient Orient
|
|
|
|
* The shape is drawn as a segment
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient,
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_DRAW_MODE_T modetrace )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
int x0, y0, x1, y1, delta;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// The pad is reduced to an oval by dy > dx
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
delta = size.y - size.x;
|
2009-06-28 16:50:42 +00:00
|
|
|
x0 = 0;
|
|
|
|
y0 = -delta / 2;
|
|
|
|
x1 = 0;
|
|
|
|
y1 = delta / 2;
|
|
|
|
RotatePoint( &x0, &y0, orient );
|
|
|
|
RotatePoint( &x1, &y1, orient );
|
|
|
|
|
|
|
|
if( modetrace == FILLED )
|
|
|
|
thick_segment( wxPoint( pos.x + x0, pos.y + y0 ),
|
2009-11-23 15:16:50 +00:00
|
|
|
wxPoint( pos.x + x1, pos.y + y1 ), size.x, modetrace );
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2009-11-23 15:16:50 +00:00
|
|
|
sketch_oval( pos, size, orient, -1 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot round pad or via.
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::flash_pad_circle( wxPoint pos, int diametre,
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_DRAW_MODE_T modetrace )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-01-07 06:02:38 +00:00
|
|
|
int current_line_width;
|
2009-11-23 15:16:50 +00:00
|
|
|
wxASSERT( output_file );
|
2011-02-08 18:39:41 +00:00
|
|
|
|
|
|
|
set_current_line_width( -1 );
|
2012-01-07 06:02:38 +00:00
|
|
|
current_line_width = get_current_line_width();
|
|
|
|
if( current_line_width > diametre )
|
|
|
|
current_line_width = diametre;
|
2011-02-08 18:39:41 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( modetrace == FILLED )
|
2012-01-07 06:02:38 +00:00
|
|
|
circle( pos, diametre - current_pen_width, FILLED_SHAPE, current_line_width );
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2012-01-07 06:02:38 +00:00
|
|
|
circle( pos, diametre - current_pen_width, NO_FILL, current_line_width );
|
2011-02-08 18:39:41 +00:00
|
|
|
|
|
|
|
set_current_line_width( -1 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot rectangular pad in any orientation.
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void PS_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
|
2012-01-03 17:14:17 +00:00
|
|
|
int orient, EDA_DRAW_MODE_T trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
static std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.clear();
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
set_current_line_width( -1 );
|
2009-06-28 16:50:42 +00:00
|
|
|
int w = current_pen_width;
|
|
|
|
size.x -= w;
|
|
|
|
if( size.x < 1 )
|
2009-11-23 15:16:50 +00:00
|
|
|
size.x = 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
size.y -= w;
|
|
|
|
if( size.y < 1 )
|
2009-11-23 15:16:50 +00:00
|
|
|
size.y = 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
int dx = size.x / 2;
|
|
|
|
int dy = size.y / 2;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
wxPoint corner;
|
|
|
|
corner.x = pos.x - dx;
|
|
|
|
corner.y = pos.y + dy;
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
corner.x = pos.x - dx;
|
|
|
|
corner.y = pos.y - dy;
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
corner.x = pos.x + dx;
|
|
|
|
corner.y = pos.y - dy;
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
corner.x = pos.x + dx;
|
|
|
|
corner.y = pos.y + dy,
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < cornerList.size(); ii++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
RotatePoint( &cornerList[ii], pos, orient );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
|
|
|
PlotPoly( cornerList, ( trace_mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot trapezoidal pad.
|
2010-09-13 11:51:09 +00:00
|
|
|
* aPadPos is pad position, aCorners the corners position of the basic shape
|
|
|
|
* Orientation aPadOrient in 0.1 degrees
|
|
|
|
* Plot mode FILLED or SKETCH
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2010-09-13 11:51:09 +00:00
|
|
|
void PS_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
|
2012-01-03 17:14:17 +00:00
|
|
|
int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
static std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.clear();
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2010-09-13 11:51:09 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( aCorners[ii] );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2010-09-13 11:51:09 +00:00
|
|
|
if( aTrace_Mode == FILLED )
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
set_current_line_width( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_current_line_width( -1 );
|
|
|
|
int w = current_pen_width;
|
|
|
|
// offset polygon by w
|
|
|
|
// coord[0] is assumed the lower left
|
|
|
|
// coord[1] is assumed the upper left
|
|
|
|
// coord[2] is assumed the upper right
|
|
|
|
// coord[3] is assumed the lower right
|
|
|
|
|
|
|
|
/* Trace the outline. */
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList[0].x += w;
|
|
|
|
cornerList[0].y -= w;
|
|
|
|
cornerList[1].x += w;
|
|
|
|
cornerList[1].y += w;
|
|
|
|
cornerList[2].x -= w;
|
|
|
|
cornerList[2].y += w;
|
|
|
|
cornerList[3].x -= w;
|
|
|
|
cornerList[3].y -= w;
|
2010-09-13 11:51:09 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
RotatePoint( &cornerList[ii], aPadOrient );
|
|
|
|
cornerList[ii] += aPadPos;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
PlotPoly( cornerList, ( aTrace_Mode == FILLED ) ? FILLED_SHAPE : NO_FILL );
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|