2014-10-21 18:36:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-05-25 14:48:38 +00:00
|
|
|
* Copyright (C) 2010-2016 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2016-05-26 18:13:53 +00:00
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-21 18:36:45 +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
|
|
|
|
*/
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
#include <fctsys.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <kiface_i.h>
|
2012-10-04 06:57:15 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
|
|
|
|
#include <dialog_print_using_printer_base.h>
|
|
|
|
#include <printout_controler.h>
|
|
|
|
|
|
|
|
#include <gerbview.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2016-05-25 14:48:38 +00:00
|
|
|
#include <class_gerber_file_image.h>
|
2016-05-26 07:50:49 +00:00
|
|
|
#include <class_gerber_file_image_list.h>
|
2016-05-27 08:20:17 +00:00
|
|
|
|
|
|
|
///@{
|
|
|
|
/// \ingroup config
|
|
|
|
|
|
|
|
#define OPTKEY_LAYERBASE wxT( "PlotLayer_%d" )
|
|
|
|
#define OPTKEY_PRINT_X_FINESCALE_ADJ wxT( "PrintXFineScaleAdj" )
|
|
|
|
#define OPTKEY_PRINT_Y_FINESCALE_ADJ wxT( "PrintYFineScaleAdj" )
|
|
|
|
#define OPTKEY_PRINT_SCALE wxT( "PrintScale" )
|
|
|
|
#define OPTKEY_PRINT_PAGE_FRAME wxT( "PrintPageFrame" )
|
|
|
|
#define OPTKEY_PRINT_MONOCHROME_MODE wxT( "PrintMonochrome" )
|
|
|
|
|
|
|
|
///@}
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
static double s_ScaleList[] =
|
|
|
|
{ 0, 0.5, 0.7, 0.999, 1.0, 1.4, 2.0, 3.0, 4.0 };
|
|
|
|
|
|
|
|
// Define min et max reasonnable values for print scale
|
|
|
|
#define MIN_SCALE 0.01
|
|
|
|
#define MAX_SCALE 100.0
|
|
|
|
|
|
|
|
// static print data and page setup data, to remember settings during the session
|
2014-06-27 17:07:42 +00:00
|
|
|
static wxPrintData* s_printData;
|
|
|
|
static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL;
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
// Variables locales
|
|
|
|
static PRINT_PARAMETERS s_Parameters;
|
|
|
|
|
|
|
|
|
2013-09-29 18:24:38 +00:00
|
|
|
/* Dialog to print schematic. Class derived from DIALOG_PRINT_USING_PRINTER_BASE
|
2012-10-04 06:57:15 +00:00
|
|
|
* created by wxFormBuilder
|
|
|
|
*/
|
2013-09-29 18:24:38 +00:00
|
|
|
class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_BASE
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
GERBVIEW_FRAME* m_Parent;
|
2014-06-27 17:07:42 +00:00
|
|
|
wxConfigBase* m_Config;
|
|
|
|
wxCheckBox* m_BoxSelectLayer[32];
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_PRINT_USING_PRINTER( GERBVIEW_FRAME* parent );
|
|
|
|
~DIALOG_PRINT_USING_PRINTER() {};
|
|
|
|
|
|
|
|
private:
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnCloseWindow( wxCloseEvent& event ) override;
|
2012-10-04 06:57:15 +00:00
|
|
|
void OnInitDialog( wxInitDialogEvent& event );
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnPageSetup( wxCommandEvent& event ) override;
|
|
|
|
void OnPrintPreview( wxCommandEvent& event ) override;
|
|
|
|
void OnPrintButtonClick( wxCommandEvent& event ) override;
|
|
|
|
void OnScaleSelectionClick( wxCommandEvent& event ) override;
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
void OnButtonCloseClick( wxCommandEvent& event ) override { Close(); }
|
2015-03-26 17:23:17 +00:00
|
|
|
void SetPrintParameters();
|
|
|
|
void InitValues();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool IsMirrored() { return m_Print_Mirror->IsChecked(); }
|
|
|
|
bool PrintUsingSinglePage() { return true; }
|
2014-06-27 17:07:42 +00:00
|
|
|
int SetLayerSetFromListSelection();
|
|
|
|
// Prepare print parameters. return true if OK,
|
|
|
|
// false if there is an issue (mainly no printable layers)
|
|
|
|
bool PreparePrintPrms();
|
2012-10-04 06:57:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void GERBVIEW_FRAME::ToPrinter( wxCommandEvent& event )
|
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
if( s_printData == NULL ) // First print
|
|
|
|
s_printData = new wxPrintData();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
if( !s_printData->Ok() )
|
2013-09-29 18:24:38 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Error Init Printer info" ) );
|
|
|
|
return;
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
s_printData->SetQuality( wxPRINT_QUALITY_HIGH );
|
|
|
|
s_printData->SetOrientation( GetPageSettings().IsPortrait() ?
|
2013-09-29 18:24:38 +00:00
|
|
|
wxPORTRAIT : wxLANDSCAPE );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
DIALOG_PRINT_USING_PRINTER* frame = new DIALOG_PRINT_USING_PRINTER( this );
|
|
|
|
|
|
|
|
frame->ShowModal();
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_PRINT_USING_PRINTER::DIALOG_PRINT_USING_PRINTER( GERBVIEW_FRAME* parent ) :
|
2013-09-29 18:24:38 +00:00
|
|
|
DIALOG_PRINT_USING_PRINTER_BASE( parent )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
m_Parent = parent;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
m_Config = Kiface().KifaceSettings();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
InitValues( );
|
2013-09-29 18:24:38 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
/* Problems with modal on wx-2.9 - Anyway preview is standard for OSX */
|
|
|
|
m_buttonPreview->Hide();
|
|
|
|
#endif
|
2014-11-19 17:13:55 +00:00
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::InitValues( )
|
|
|
|
{
|
|
|
|
SetFocus();
|
|
|
|
wxString msg;
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
if( s_pageSetupData == NULL )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
s_pageSetupData = new wxPageSetupDialogData;
|
2012-10-04 06:57:15 +00:00
|
|
|
// Set initial page margins.
|
2014-06-27 17:07:42 +00:00
|
|
|
// Margins are already set in Gerbview, so we can use 0
|
2015-03-26 17:23:17 +00:00
|
|
|
s_pageSetupData->SetMarginTopLeft( wxPoint( 0, 0 ) );
|
|
|
|
s_pageSetupData->SetMarginBottomRight( wxPoint( 0, 0 ) );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
s_Parameters.m_PageSetupData = s_pageSetupData;
|
2016-06-17 18:00:29 +00:00
|
|
|
GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2013-03-28 06:40:19 +00:00
|
|
|
// Create layer list
|
2016-06-17 18:00:29 +00:00
|
|
|
for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
msg = _( "Layer" );
|
|
|
|
msg << wxT( " " ) << ii + 1;
|
2016-10-04 07:51:35 +00:00
|
|
|
|
|
|
|
wxStaticBoxSizer* boxSizer = ( ii < 16 ) ? m_leftLayersBoxSizer
|
|
|
|
: m_rightLayersBoxSizer;
|
|
|
|
|
|
|
|
m_BoxSelectLayer[ii] = new wxCheckBox( boxSizer->GetStaticBox(),
|
|
|
|
wxID_ANY, msg );
|
|
|
|
boxSizer->Add( m_BoxSelectLayer[ii], wxGROW | wxLEFT | wxRIGHT | wxTOP );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
if( images->GetGbrImage( ii ) == NULL ) // Nothing loaded on this draw layer
|
2014-06-27 17:07:42 +00:00
|
|
|
m_BoxSelectLayer[ii]->Enable( false );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read the scale adjust option
|
|
|
|
int scale_idx = 4; // default selected scale = ScaleList[4] = 1.000
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
m_Config->Read( OPTKEY_PRINT_X_FINESCALE_ADJ, &s_Parameters.m_XScaleAdjust );
|
|
|
|
m_Config->Read( OPTKEY_PRINT_Y_FINESCALE_ADJ, &s_Parameters.m_YScaleAdjust );
|
|
|
|
m_Config->Read( OPTKEY_PRINT_SCALE, &scale_idx );
|
2015-03-26 17:23:17 +00:00
|
|
|
m_Config->Read( OPTKEY_PRINT_PAGE_FRAME, &s_Parameters.m_Print_Sheet_Ref, 1 );
|
|
|
|
m_Config->Read( OPTKEY_PRINT_MONOCHROME_MODE, &s_Parameters.m_Print_Black_and_White, 1 );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
// Test for a reasonnable scale value. Set to 1 if problem
|
|
|
|
if( s_Parameters.m_XScaleAdjust < MIN_SCALE ||
|
|
|
|
s_Parameters.m_YScaleAdjust < MIN_SCALE ||
|
|
|
|
s_Parameters.m_XScaleAdjust > MAX_SCALE ||
|
|
|
|
s_Parameters.m_YScaleAdjust > MAX_SCALE )
|
|
|
|
s_Parameters.m_XScaleAdjust = s_Parameters.m_YScaleAdjust = 1.0;
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
wxString layerKey;
|
|
|
|
bool option;
|
|
|
|
|
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
2014-06-27 17:07:42 +00:00
|
|
|
m_Config->Read( layerKey, &option, false );
|
|
|
|
m_BoxSelectLayer[layer]->SetValue( option );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ScaleOption->SetSelection( scale_idx );
|
|
|
|
scale_idx = m_ScaleOption->GetSelection();
|
2015-03-26 17:23:17 +00:00
|
|
|
s_Parameters.m_PrintScale = s_ScaleList[scale_idx];
|
|
|
|
m_Print_Mirror->SetValue( s_Parameters.m_PrintMirror );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( s_Parameters.m_Print_Black_and_White )
|
|
|
|
m_ModeColorOption->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_ModeColorOption->SetSelection( 0 );
|
|
|
|
|
|
|
|
s_Parameters.m_PenDefaultSize = 0;
|
|
|
|
|
|
|
|
// Create scale adjust option
|
|
|
|
msg.Printf( wxT( "%f" ), s_Parameters.m_XScaleAdjust );
|
|
|
|
m_FineAdjustXscaleOpt->SetValue( msg );
|
|
|
|
msg.Printf( wxT( "%f" ), s_Parameters.m_YScaleAdjust );
|
|
|
|
m_FineAdjustYscaleOpt->SetValue( msg );
|
|
|
|
|
|
|
|
bool enable = (s_Parameters.m_PrintScale == 1.0);
|
2015-02-26 10:33:15 +00:00
|
|
|
|
|
|
|
m_FineAdjustXscaleOpt->Enable(enable);
|
|
|
|
m_FineAdjustYscaleOpt->Enable(enable);
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 17:23:17 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
int DIALOG_PRINT_USING_PRINTER::SetLayerSetFromListSelection()
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2016-06-02 09:30:39 +00:00
|
|
|
std::vector<int> layerList;
|
2016-05-25 14:48:38 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
if( m_BoxSelectLayer[ii]->IsChecked() && m_BoxSelectLayer[ii]->IsEnabled() )
|
2016-06-02 09:30:39 +00:00
|
|
|
layerList.push_back( ii );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 09:30:39 +00:00
|
|
|
m_Parent->GetGerberLayout()->SetPrintableLayers( layerList );
|
|
|
|
s_Parameters.m_PageCount = layerList.size();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2016-06-02 09:30:39 +00:00
|
|
|
return s_Parameters.m_PageCount;
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )
|
|
|
|
{
|
|
|
|
SetPrintParameters();
|
|
|
|
|
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
m_Config->Write( OPTKEY_PRINT_X_FINESCALE_ADJ, s_Parameters.m_XScaleAdjust );
|
|
|
|
m_Config->Write( OPTKEY_PRINT_Y_FINESCALE_ADJ, s_Parameters.m_YScaleAdjust );
|
|
|
|
m_Config->Write( OPTKEY_PRINT_SCALE, m_ScaleOption->GetSelection() );
|
|
|
|
m_Config->Write( OPTKEY_PRINT_PAGE_FRAME, s_Parameters.m_Print_Sheet_Ref);
|
|
|
|
m_Config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
|
|
|
|
wxString layerKey;
|
2016-05-25 14:48:38 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
layerKey.Printf( OPTKEY_LAYERBASE, layer );
|
|
|
|
m_Config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 17:07:42 +00:00
|
|
|
|
2016-05-26 18:13:53 +00:00
|
|
|
EndModal( 0 );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 17:23:17 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::SetPrintParameters()
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
|
|
|
s_Parameters.m_PrintMirror = m_Print_Mirror->GetValue();
|
|
|
|
s_Parameters.m_Print_Black_and_White =
|
|
|
|
m_ModeColorOption->GetSelection() != 0;
|
|
|
|
|
|
|
|
// Due to negative objects in gerber objects, always use one page per image,
|
|
|
|
// because these objects create artefact when they are printed on an existing image.
|
|
|
|
s_Parameters.m_OptionPrintPage = false;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
SetLayerSetFromListSelection();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
int idx = m_ScaleOption->GetSelection();
|
2015-03-26 17:23:17 +00:00
|
|
|
s_Parameters.m_PrintScale = s_ScaleList[idx];
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2016-05-26 18:13:53 +00:00
|
|
|
// Test for a reasonnable scale value
|
|
|
|
bool ok = true;
|
|
|
|
double scaleX;
|
|
|
|
m_FineAdjustXscaleOpt->GetValue().ToDouble( &scaleX );
|
|
|
|
|
|
|
|
double scaleY;
|
|
|
|
m_FineAdjustYscaleOpt->GetValue().ToDouble( &scaleY );
|
|
|
|
|
|
|
|
if( scaleX > MAX_SCALE || scaleY > MAX_SCALE )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2016-05-26 18:13:53 +00:00
|
|
|
DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very large value" ) );
|
|
|
|
ok = false;
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
2016-05-25 14:48:38 +00:00
|
|
|
|
2016-05-26 18:13:53 +00:00
|
|
|
if( scaleX < MIN_SCALE || scaleY < MIN_SCALE )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2016-05-26 18:13:53 +00:00
|
|
|
DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very small value" ) );
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ok )
|
|
|
|
{
|
|
|
|
s_Parameters.m_XScaleAdjust = scaleX;
|
|
|
|
s_Parameters.m_YScaleAdjust = scaleY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Update actual fine scale value
|
|
|
|
m_FineAdjustXscaleOpt->SetValue( wxString::Format( "%f", s_Parameters.m_XScaleAdjust ) );
|
|
|
|
m_FineAdjustYscaleOpt->SetValue( wxString::Format( "%f", s_Parameters.m_YScaleAdjust ) );
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnScaleSelectionClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
double scale = s_ScaleList[m_ScaleOption->GetSelection()];
|
|
|
|
bool enable = (scale == 1.0);
|
2016-05-25 14:48:38 +00:00
|
|
|
|
2012-10-04 06:57:15 +00:00
|
|
|
if( m_FineAdjustXscaleOpt )
|
|
|
|
m_FineAdjustXscaleOpt->Enable(enable);
|
2016-05-25 14:48:38 +00:00
|
|
|
|
2012-10-04 06:57:15 +00:00
|
|
|
if( m_FineAdjustYscaleOpt )
|
|
|
|
m_FineAdjustYscaleOpt->Enable(enable);
|
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
// Open a dialog box for printer setup (printer options, page size ...)
|
2012-10-04 06:57:15 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event )
|
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
*s_pageSetupData = *s_printData;
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
wxPageSetupDialog pageSetupDialog(this, s_pageSetupData);
|
2012-10-04 06:57:15 +00:00
|
|
|
pageSetupDialog.ShowModal();
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
(*s_printData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData();
|
|
|
|
(*s_pageSetupData) = pageSetupDialog.GetPageSetupDialogData();
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
bool DIALOG_PRINT_USING_PRINTER::PreparePrintPrms()
|
|
|
|
{
|
2015-03-26 17:23:17 +00:00
|
|
|
SetPrintParameters();
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
// If no layer selected, we have no plot. prompt user if it happens
|
|
|
|
// because he could think there is a bug in Pcbnew:
|
2016-06-02 09:30:39 +00:00
|
|
|
if( m_Parent->GetGerberLayout()->GetPrintableLayers().size() == 0 )
|
2014-06-27 17:07:42 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "No layer selected" ) );
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open and display a previewer frame for printing
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
|
2012-10-04 06:57:15 +00:00
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
if( !PreparePrintPrms() )
|
|
|
|
return;
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
// Pass two printout objects: for preview, and possible printing.
|
|
|
|
wxString title = _( "Print Preview" );
|
|
|
|
wxPrintPreview* preview =
|
2012-11-29 01:50:58 +00:00
|
|
|
new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_Parent, title ),
|
|
|
|
new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_Parent, title ),
|
2014-06-27 17:07:42 +00:00
|
|
|
s_printData );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
if( preview == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "OnPrintPreview() problem" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Uses the parent position and size.
|
|
|
|
// @todo uses last position and size ans store them when exit in m_Config
|
|
|
|
wxPoint WPos = m_Parent->GetPosition();
|
|
|
|
wxSize WSize = m_Parent->GetSize();
|
|
|
|
|
|
|
|
wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );
|
2014-11-19 17:13:55 +00:00
|
|
|
frame->SetMinSize( wxSize( 550, 350 ) );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
frame->Initialize();
|
2014-11-19 17:13:55 +00:00
|
|
|
|
|
|
|
frame->Raise(); // Needed on Ubuntu/Unity to display the frame
|
2012-10-04 06:57:15 +00:00
|
|
|
frame->Show( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
if( !PreparePrintPrms() )
|
2012-10-04 06:57:15 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
wxPrintDialogData printDialogData( *s_printData );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
wxPrinter printer( &printDialogData );
|
|
|
|
wxString title = _( "Print" );
|
|
|
|
BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_Parent, title );
|
2012-10-04 06:57:15 +00:00
|
|
|
|
|
|
|
if( !printer.Print( this, &printout, true ) )
|
|
|
|
{
|
|
|
|
if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
|
|
|
|
DisplayError( this, _( "There was a problem printing" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-27 17:07:42 +00:00
|
|
|
*s_printData = printer.GetPrintDialogData().GetPrintData();
|
2012-10-04 06:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|