2009-11-20 14:55:20 +00:00
|
|
|
/*******************/
|
|
|
|
/**** Plot HPGL ****/
|
|
|
|
/*******************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "plot_common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "pcbplot.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2010-01-01 13:30:39 +00:00
|
|
|
bool WinEDA_BasePcbFrame::Genere_HPGL( const wxString& FullFileName, int Layer,
|
2009-06-29 05:30:08 +00:00
|
|
|
GRTraceMode trace_mode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
wxSize SheetSize;
|
|
|
|
wxSize BoardSize;
|
|
|
|
wxPoint BoardCenter;
|
|
|
|
bool Center = FALSE;
|
2009-06-28 16:50:42 +00:00
|
|
|
Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc;
|
2009-06-29 05:30:08 +00:00
|
|
|
double scale;
|
|
|
|
wxPoint offset;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2010-01-01 13:30:39 +00:00
|
|
|
FILE* output_file = wxFopen( FullFileName, wxT( "wt" ) );
|
|
|
|
if( output_file == NULL )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-11 18:40:39 +00:00
|
|
|
// Compute pen_dim (from g_m_HPGLPenDiam in mils) in pcb units,
|
|
|
|
// with plot scale (if Scale is 2, pen diameter is always g_m_HPGLPenDiam
|
2007-08-23 04:28:46 +00:00
|
|
|
// so apparent pen diam is real pen diam / Scale
|
2010-12-11 18:40:39 +00:00
|
|
|
int pen_diam = wxRound( (g_PcbPlotOptions.m_HPGLPenDiam * U_PCB) / g_PcbPlotOptions.m_PlotScale );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2010-12-11 18:40:39 +00:00
|
|
|
// compute pen_overlay (from g_m_HPGLPenOvr in mils)
|
2007-08-23 04:28:46 +00:00
|
|
|
// with plot scale
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.m_HPGLPenOvr < 0 )
|
|
|
|
g_PcbPlotOptions.m_HPGLPenOvr = 0;
|
|
|
|
if( g_PcbPlotOptions.m_HPGLPenOvr >= g_PcbPlotOptions.m_HPGLPenDiam )
|
|
|
|
g_PcbPlotOptions.m_HPGLPenOvr = g_PcbPlotOptions.m_HPGLPenDiam - 1;
|
|
|
|
int pen_overlay = wxRound(
|
|
|
|
g_PcbPlotOptions.m_HPGLPenOvr * 10.0 / g_PcbPlotOptions.m_PlotScale );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2009-03-18 15:38:16 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.m_PlotScale != 1.0 || g_PcbPlotOptions.m_AutoScale )
|
|
|
|
Center = true; // when scale != 1.0 we must calculate the position in page
|
|
|
|
// because actual position has no meaning
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
// Scale units from 0.0001" to HPGL plot units.
|
2009-06-28 16:50:42 +00:00
|
|
|
SheetSize.x = currentsheet->m_Size.x * U_PCB;
|
|
|
|
SheetSize.y = currentsheet->m_Size.y * U_PCB;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Calculate the center of the PCB. */
|
2007-08-23 04:28:46 +00:00
|
|
|
m_Pcb->ComputeBoundaryBox();
|
|
|
|
BoardSize = m_Pcb->m_BoundaryBox.GetSize();
|
|
|
|
BoardCenter = m_Pcb->m_BoundaryBox.Centre();
|
|
|
|
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.m_AutoScale ) // Optimum scale
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
double Xscale, Yscale;
|
|
|
|
|
|
|
|
// Fit to 80% of the page
|
2009-11-20 14:55:20 +00:00
|
|
|
Xscale = ( ( SheetSize.x * 0.8 ) / BoardSize.x );
|
|
|
|
Yscale = ( ( SheetSize.y * 0.8 ) / BoardSize.y );
|
2009-06-29 05:30:08 +00:00
|
|
|
scale = MIN( Xscale, Yscale );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
else
|
2010-12-11 18:40:39 +00:00
|
|
|
scale = g_PcbPlotOptions.m_PlotScale;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
// Calculate the page size offset.
|
2009-06-29 05:30:08 +00:00
|
|
|
if( Center )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
offset.x = wxRound( (double) BoardCenter.x -
|
|
|
|
( (double) SheetSize.x / 2.0 ) / scale );
|
|
|
|
offset.y = wxRound( (double) BoardCenter.y -
|
|
|
|
( (double) SheetSize.y / 2.0 ) / scale );
|
2009-06-29 05:30:08 +00:00
|
|
|
}
|
|
|
|
else
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
offset.x = 0;
|
|
|
|
offset.y = 0;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_paper_size( currentsheet );
|
2010-12-11 18:40:39 +00:00
|
|
|
plotter->set_viewport( offset, scale, g_PcbPlotOptions.m_PlotMirror );
|
|
|
|
plotter->set_default_line_width( g_PcbPlotOptions.m_PlotLineWidth );
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_creator( wxT( "PCBNEW-HPGL" ) );
|
|
|
|
plotter->set_filename( FullFileName );
|
2010-12-11 18:40:39 +00:00
|
|
|
plotter->set_pen_speed( g_PcbPlotOptions.m_HPGLPenSpeed );
|
|
|
|
plotter->set_pen_number( g_PcbPlotOptions.m_HPGLPenNum );
|
|
|
|
plotter->set_pen_overlap( pen_overlay );
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_pen_diameter( pen_diam );
|
|
|
|
plotter->start_plot( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
|
|
|
/* The worksheet is not significant with scale!=1... It is with
|
|
|
|
* paperscale!=1, anyway */
|
2010-12-11 18:40:39 +00:00
|
|
|
if( g_PcbPlotOptions.m_PlotFrameRef && !Center )
|
2009-06-29 05:30:08 +00:00
|
|
|
PlotWorkSheet( plotter, GetScreen() );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-06-29 05:30:08 +00:00
|
|
|
Plot_Layer( plotter, Layer, trace_mode );
|
2009-06-28 16:50:42 +00:00
|
|
|
plotter->end_plot();
|
|
|
|
delete plotter;
|
2009-03-18 15:38:16 +00:00
|
|
|
SetLocaleTo_Default();
|
2010-01-01 13:30:39 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|