2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file plothpgl.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <pcbplot.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
bool PCB_BASE_FRAME::ExportToHpglFile( const wxString& aFullFileName, int aLayer,
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_DRAW_MODE_T aTraceMode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
wxSize boardSize;
|
|
|
|
wxPoint boardCenter;
|
|
|
|
bool center = false;
|
|
|
|
double scale;
|
|
|
|
wxPoint offset;
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
FILE* output_file = wxFopen( aFullFileName, wxT( "wt" ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-01 13:30:39 +00:00
|
|
|
if( output_file == NULL )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
PCB_PLOT_PARAMS plot_opts = GetPlotSettings();
|
|
|
|
|
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
|
2012-04-05 18:27:56 +00:00
|
|
|
int pen_diam = wxRound( (plot_opts.m_HPGLPenDiam * U_PCB) /
|
|
|
|
plot_opts.m_PlotScale );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
// compute pen_overlay (from g_m_HPGLPenOvr in mils) with plot scale
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plot_opts.m_HPGLPenOvr < 0 )
|
|
|
|
plot_opts.m_HPGLPenOvr = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plot_opts.m_HPGLPenOvr >= plot_opts.m_HPGLPenDiam )
|
|
|
|
plot_opts.m_HPGLPenOvr = plot_opts.m_HPGLPenDiam - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
int pen_overlay = wxRound( plot_opts.m_HPGLPenOvr * 10.0 /
|
|
|
|
plot_opts.m_PlotScale );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plot_opts.m_PlotScale != 1.0 || plot_opts.m_AutoScale )
|
2011-12-22 21:57:50 +00:00
|
|
|
{
|
|
|
|
// when scale != 1.0 we must calculate the position in page
|
|
|
|
// because actual position has no meaning
|
|
|
|
center = true;
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
wxSize pageSizeIU = GetPageSizeIU();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
// Calculate the center of the PCB
|
|
|
|
EDA_RECT bbbox = GetBoardBoundingBox();
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
boardSize = bbbox.GetSize();
|
|
|
|
boardCenter = bbbox.Centre();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plot_opts.m_AutoScale ) // Optimum scale
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-29 05:30:08 +00:00
|
|
|
// Fit to 80% of the page
|
2011-12-22 21:57:50 +00:00
|
|
|
double Xscale = ( ( pageSizeIU.x * 0.8 ) / boardSize.x );
|
|
|
|
double Yscale = ( ( pageSizeIU.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
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2012-04-05 18:27:56 +00:00
|
|
|
scale = plot_opts.m_PlotScale;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
// Calculate the page size offset.
|
2011-12-22 21:57:50 +00:00
|
|
|
if( center )
|
2009-06-29 05:30:08 +00:00
|
|
|
{
|
2011-12-22 21:57:50 +00:00
|
|
|
offset.x = wxRound( (double) boardCenter.x -
|
|
|
|
( (double) pageSizeIU.x / 2.0 ) / scale );
|
|
|
|
offset.y = wxRound( (double) boardCenter.y -
|
|
|
|
( (double) pageSizeIU.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();
|
2011-12-22 21:57:50 +00:00
|
|
|
|
|
|
|
plotter->SetPageSettings( GetPageSettings() );
|
|
|
|
|
2012-04-05 18:27:56 +00:00
|
|
|
// why did we have to change these settings above?
|
|
|
|
SetPlotSettings( plot_opts );
|
|
|
|
|
|
|
|
plotter->set_viewport( offset, scale, plot_opts.m_PlotMirror );
|
|
|
|
plotter->set_default_line_width( plot_opts.m_PlotLineWidth );
|
2009-06-29 05:30:08 +00:00
|
|
|
plotter->set_creator( wxT( "PCBNEW-HPGL" ) );
|
2011-09-29 16:49:40 +00:00
|
|
|
plotter->set_filename( aFullFileName );
|
2012-04-05 18:27:56 +00:00
|
|
|
plotter->set_pen_speed( plot_opts.m_HPGLPenSpeed );
|
|
|
|
plotter->set_pen_number( plot_opts.m_HPGLPenNum );
|
2010-12-11 18:40:39 +00:00
|
|
|
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
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// The worksheet is not significant with scale!=1... It is with paperscale!=1, anyway
|
2012-04-05 18:27:56 +00:00
|
|
|
if( plot_opts.m_PlotFrameRef && !center )
|
2009-06-29 05:30:08 +00:00
|
|
|
PlotWorkSheet( plotter, GetScreen() );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
Plot_Layer( plotter, aLayer, aTraceMode );
|
2009-06-28 16:50:42 +00:00
|
|
|
plotter->end_plot();
|
|
|
|
delete plotter;
|
2010-01-01 13:30:39 +00:00
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|