2014-10-21 15:48:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-10-08 11:59:00 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-09-10 18:53:03 +00:00
|
|
|
* Copyright (C) 2015-2023 KiCad Developers, see AUTHORS.TXT for contributors.
|
2014-10-21 15:48:00 +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
|
|
|
|
*/
|
2009-01-17 17:32:20 +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 <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2023-02-19 03:40:07 +00:00
|
|
|
#include <math/vector2wx.h>
|
2020-05-16 14:47:43 +00:00
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2023-11-23 13:29:07 +00:00
|
|
|
#include "dialog_print_using_printer_base.h"
|
2020-04-14 12:25:00 +00:00
|
|
|
#include <sch_painter.h>
|
2021-06-03 22:32:32 +00:00
|
|
|
#include <wx/print.h>
|
2021-06-03 11:49:49 +00:00
|
|
|
#include <wx/printdlg.h>
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2023-11-24 16:43:04 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
|
2023-11-23 13:29:07 +00:00
|
|
|
#include "sch_printout.h"
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DIALOG_PRINT_USING_PRINTER( SCH_EDIT_FRAME* aParent );
|
2018-07-22 22:27:59 +00:00
|
|
|
~DIALOG_PRINT_USING_PRINTER() override;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
protected:
|
2023-01-11 20:29:16 +00:00
|
|
|
void OnOutputChoice( wxCommandEvent& event ) override;
|
2020-05-16 14:47:43 +00:00
|
|
|
void OnUseColorThemeChecked( wxCommandEvent& event ) override;
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
private:
|
2018-07-22 22:27:59 +00:00
|
|
|
bool TransferDataToWindow() override;
|
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnPageSetup( wxCommandEvent& event ) override;
|
|
|
|
void OnPrintPreview( wxCommandEvent& event ) override;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
void SavePrintOptions();
|
2019-08-13 16:59:43 +00:00
|
|
|
|
|
|
|
SCH_EDIT_FRAME* m_parent;
|
2023-11-24 16:43:04 +00:00
|
|
|
bool m_useCairo;
|
2013-06-07 20:56:55 +00:00
|
|
|
};
|
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
/**
|
|
|
|
* Custom schematic print preview frame.
|
2015-10-02 16:52:54 +00:00
|
|
|
* This derived preview frame remembers its size and position during a session
|
2009-01-17 17:32:20 +00:00
|
|
|
*/
|
2010-02-02 15:01:09 +00:00
|
|
|
class SCH_PREVIEW_FRAME : public wxPreviewFrame
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
public:
|
2015-10-02 16:52:54 +00:00
|
|
|
SCH_PREVIEW_FRAME( wxPrintPreview* aPreview, wxWindow* aParent,
|
2010-02-02 15:01:09 +00:00
|
|
|
const wxString& aTitle, const wxPoint& aPos = wxDefaultPosition,
|
|
|
|
const wxSize& aSize = wxDefaultSize ) :
|
|
|
|
wxPreviewFrame( aPreview, aParent, aTitle, aPos, aSize )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
}
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool Show( bool show ) override
|
2010-02-02 15:01:09 +00:00
|
|
|
{
|
2012-08-15 17:55:48 +00:00
|
|
|
bool ret;
|
|
|
|
|
|
|
|
// Show or hide the window. If hiding, save current position and size.
|
|
|
|
// If showing, use previous position and size.
|
|
|
|
if( show )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2012-08-15 17:55:48 +00:00
|
|
|
ret = wxPreviewFrame::Show( show );
|
|
|
|
|
|
|
|
if( s_size.x != 0 && s_size.y != 0 )
|
|
|
|
SetSize( s_pos.x, s_pos.y, s_size.x, s_size.y, 0 );
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
2012-08-15 17:55:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Save the dialog's position & size before hiding
|
|
|
|
s_size = GetSize();
|
|
|
|
s_pos = GetPosition();
|
2010-02-02 15:01:09 +00:00
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
ret = wxPreviewFrame::Show( show );
|
|
|
|
}
|
2015-10-02 14:07:37 +00:00
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
return ret;
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
private:
|
2012-08-15 17:55:48 +00:00
|
|
|
static wxPoint s_pos;
|
|
|
|
static wxSize s_size;
|
2010-02-02 15:01:09 +00:00
|
|
|
};
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2016-02-27 19:35:45 +00:00
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
wxPoint SCH_PREVIEW_FRAME::s_pos;
|
|
|
|
wxSize SCH_PREVIEW_FRAME::s_size;
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DIALOG_PRINT_USING_PRINTER::DIALOG_PRINT_USING_PRINTER( SCH_EDIT_FRAME* aParent ) :
|
2019-08-13 16:59:43 +00:00
|
|
|
DIALOG_PRINT_USING_PRINTER_BASE( aParent ),
|
|
|
|
m_parent( aParent )
|
2010-01-18 17:05:31 +00:00
|
|
|
{
|
2020-05-16 14:47:43 +00:00
|
|
|
wxASSERT( aParent );
|
2023-11-24 16:43:04 +00:00
|
|
|
m_useCairo = ADVANCED_CFG::GetCfg().m_EnableEeschemaPrintCairo;
|
2018-07-22 22:27:59 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Print" ) },
|
|
|
|
{ wxID_APPLY, _( "Print Preview" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
2011-05-21 09:16:57 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2012-01-05 08:07:11 +00:00
|
|
|
// Problems with modal on wx-2.9 - Anyway preview is standard for OSX
|
2018-07-22 22:27:59 +00:00
|
|
|
m_sdbSizer1Apply->Hide();
|
2011-05-21 09:16:57 +00:00
|
|
|
#endif
|
2023-11-24 16:43:04 +00:00
|
|
|
#if defined(__WXGTK__)
|
|
|
|
// Preview using Cairo does not work on GTK,
|
|
|
|
// but this platform provide native print preview
|
|
|
|
if( m_useCairo )
|
|
|
|
m_sdbSizer1Apply->Hide();
|
|
|
|
#endif
|
2014-11-19 17:13:55 +00:00
|
|
|
|
2018-07-22 22:27:59 +00:00
|
|
|
m_sdbSizer1OK->SetFocus();
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-07-22 22:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_PRINT_USING_PRINTER::~DIALOG_PRINT_USING_PRINTER()
|
|
|
|
{
|
2020-05-16 14:47:43 +00:00
|
|
|
SavePrintOptions();
|
2010-02-02 15:01:09 +00:00
|
|
|
}
|
2010-01-18 17:05:31 +00:00
|
|
|
|
|
|
|
|
2018-07-22 22:27:59 +00:00
|
|
|
bool DIALOG_PRINT_USING_PRINTER::TransferDataToWindow()
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2020-05-16 14:47:43 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
|
|
|
|
2022-04-24 15:30:20 +00:00
|
|
|
if( cfg->m_Printing.monochrome )
|
|
|
|
{
|
|
|
|
m_checkBackgroundColor->SetValue( false );
|
|
|
|
m_checkBackgroundColor->Enable( false );
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
m_checkReference->SetValue( cfg->m_Printing.title_block );
|
2023-01-11 20:29:16 +00:00
|
|
|
m_colorPrint->SetSelection( cfg->m_Printing.monochrome ? 1 : 0 );
|
2020-05-16 14:47:43 +00:00
|
|
|
m_checkBackgroundColor->SetValue( cfg->m_Printing.background );
|
|
|
|
m_checkUseColorTheme->SetValue( cfg->m_Printing.use_theme );
|
|
|
|
|
|
|
|
m_colorTheme->Clear();
|
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
int minwidth = width;
|
|
|
|
|
|
|
|
wxString target = cfg->m_Printing.use_theme ? cfg->m_Printing.color_theme : cfg->m_ColorTheme;
|
|
|
|
|
|
|
|
for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
|
|
|
|
{
|
|
|
|
int pos = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
|
|
|
|
|
|
|
|
if( settings->GetFilename() == target )
|
|
|
|
m_colorTheme->SetSelection( pos );
|
|
|
|
|
|
|
|
m_colorTheme->GetTextExtent( settings->GetName(), &width, &height );
|
|
|
|
minwidth = std::max( minwidth, width );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_colorTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
|
|
|
|
|
|
|
|
m_colorTheme->Enable( cfg->m_Printing.use_theme );
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// Initialize page specific print setup dialog settings.
|
2019-08-13 16:59:43 +00:00
|
|
|
const PAGE_INFO& pageInfo = m_parent->GetScreen()->GetPageSettings();
|
|
|
|
wxPageSetupDialogData& pageSetupDialogData = m_parent->GetPageSetupData();
|
2012-03-26 21:45:05 +00:00
|
|
|
|
|
|
|
pageSetupDialogData.SetPaperId( pageInfo.GetPaperId() );
|
|
|
|
|
|
|
|
if( pageInfo.IsCustom() )
|
|
|
|
{
|
|
|
|
if( pageInfo.IsPortrait() )
|
2022-08-29 23:30:25 +00:00
|
|
|
pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
|
|
|
|
EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
|
2012-03-26 21:45:05 +00:00
|
|
|
else
|
2022-08-29 23:30:25 +00:00
|
|
|
pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
|
|
|
|
EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
|
2012-03-26 21:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pageSetupDialogData.GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
|
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
Layout();
|
|
|
|
|
2018-07-22 22:27:59 +00:00
|
|
|
return true;
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnUseColorThemeChecked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_colorTheme->Enable( m_checkUseColorTheme->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-11 20:29:16 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnOutputChoice( wxCommandEvent& event )
|
2012-07-09 07:10:07 +00:00
|
|
|
{
|
2023-01-11 20:29:16 +00:00
|
|
|
long sel = event.GetSelection();
|
|
|
|
m_checkBackgroundColor->Enable( sel == 0 );
|
2020-05-16 14:47:43 +00:00
|
|
|
|
2023-01-11 20:29:16 +00:00
|
|
|
if( sel )
|
2020-05-16 14:47:43 +00:00
|
|
|
m_checkBackgroundColor->SetValue( false );
|
|
|
|
else
|
|
|
|
m_checkBackgroundColor->SetValue( m_parent->eeconfig()->m_Printing.background );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::SavePrintOptions()
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
|
|
|
|
2023-01-11 20:29:16 +00:00
|
|
|
cfg->m_Printing.monochrome = !!m_colorPrint->GetSelection();
|
2020-05-16 14:47:43 +00:00
|
|
|
cfg->m_Printing.title_block = m_checkReference->IsChecked();
|
2022-04-24 15:30:20 +00:00
|
|
|
|
|
|
|
if( m_checkBackgroundColor->IsEnabled() )
|
2022-09-16 22:33:39 +00:00
|
|
|
cfg->m_Printing.background = m_checkBackgroundColor->IsChecked();
|
|
|
|
else
|
|
|
|
cfg->m_Printing.background = false;
|
2022-04-24 15:30:20 +00:00
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
cfg->m_Printing.use_theme = m_checkUseColorTheme->IsChecked();
|
|
|
|
|
|
|
|
COLOR_SETTINGS* theme = static_cast<COLOR_SETTINGS*>(
|
|
|
|
m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) );
|
|
|
|
|
|
|
|
if( theme && m_checkUseColorTheme->IsChecked() )
|
|
|
|
cfg->m_Printing.color_theme = theme->GetFilename();
|
2012-07-09 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2019-08-13 16:59:43 +00:00
|
|
|
wxPageSetupDialog pageSetupDialog( this, &m_parent->GetPageSetupData() );
|
2010-02-02 15:01:09 +00:00
|
|
|
pageSetupDialog.ShowModal();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2019-08-13 16:59:43 +00:00
|
|
|
m_parent->GetPageSetupData() = pageSetupDialog.GetPageSetupDialogData();
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2020-05-16 14:47:43 +00:00
|
|
|
SavePrintOptions();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
// Pass two printout objects: for preview, and possible printing.
|
2010-02-02 15:01:09 +00:00
|
|
|
wxString title = _( "Preview" );
|
2023-11-24 16:43:04 +00:00
|
|
|
wxPrintPreview* preview = new wxPrintPreview( new SCH_PRINTOUT( m_parent, title, m_useCairo ),
|
|
|
|
new SCH_PRINTOUT( m_parent, title, m_useCairo ),
|
2019-08-13 16:59:43 +00:00
|
|
|
&m_parent->GetPageSetupData().GetPrintData() );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
preview->SetZoom( 100 );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
SCH_PREVIEW_FRAME* frame = new SCH_PREVIEW_FRAME( preview, this, title );
|
|
|
|
|
2015-10-08 11:59:00 +00:00
|
|
|
// On wxGTK, set the flag wxTOPLEVEL_EX_DIALOG is mandatory, if we want
|
|
|
|
// close the frame using the X box in caption, when the preview frame is run
|
|
|
|
// from a dialog
|
2015-10-08 13:52:03 +00:00
|
|
|
frame->SetExtraStyle( frame->GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
|
|
|
|
|
2015-10-08 11:59:00 +00:00
|
|
|
// We use here wxPreviewFrame_WindowModal option to make the wxPrintPreview frame
|
|
|
|
// modal for its caller only.
|
2018-04-08 10:28:59 +00:00
|
|
|
// another reason is the fact when closing the frame without this option,
|
2015-10-08 11:59:00 +00:00
|
|
|
// all top level frames are reenabled.
|
|
|
|
// With this option, only the parent is reenabled.
|
|
|
|
// Reenabling all top level frames should be made by the parent dialog.
|
|
|
|
frame->InitializeWithModality( wxPreviewFrame_WindowModal );
|
2014-11-19 17:13:55 +00:00
|
|
|
|
2022-10-17 08:49:28 +00:00
|
|
|
// on first invocation in this runtime session, set to 3/4 size of parent,
|
|
|
|
// but will be changed in Show() if not first time as will position.
|
|
|
|
// Must be called after InitializeWithModality because otherwise in some wxWidget
|
|
|
|
// versions it is not always taken in account
|
|
|
|
frame->SetMinSize( wxSize( 650, 500 ) );
|
|
|
|
frame->SetSize( (m_parent->GetSize() * 3) / 4 );
|
|
|
|
|
2014-11-19 17:13:55 +00:00
|
|
|
frame->Raise(); // Needed on Ubuntu/Unity to display the frame
|
2009-01-17 17:32:20 +00:00
|
|
|
frame->Show( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-22 22:27:59 +00:00
|
|
|
bool DIALOG_PRINT_USING_PRINTER::TransferDataFromWindow()
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2019-08-13 16:59:43 +00:00
|
|
|
if( Pgm().m_Printing )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Previous print job not yet complete." ) );
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2020-05-16 14:47:43 +00:00
|
|
|
SavePrintOptions();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
int sheet_count = m_parent->Schematic().Root().CountSheets();
|
|
|
|
|
2023-09-10 18:53:03 +00:00
|
|
|
wxPrintData data = m_parent->GetPageSetupData().GetPrintData();
|
|
|
|
|
|
|
|
#if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 2, 3 )
|
|
|
|
// In GTK, the default bottom margin is bigger by 0.31 inches for
|
|
|
|
// Letter, Legal, A4 paper sizes (see gtk_paper_size_get_default_bottom_margin).
|
|
|
|
//
|
|
|
|
// wxWidgets doesn't handle this properly when paper is in
|
|
|
|
// landscape orientation.
|
|
|
|
//
|
|
|
|
// Using custom page size avoids the problematic
|
|
|
|
// gtk_page_setup_set_paper_size_and_default_margins call in wxWidgets.
|
|
|
|
|
|
|
|
wxPaperSize paperId = data.GetPaperId();
|
|
|
|
const wxChar* paperType = nullptr;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
std::set<wxPaperSize> letterSizes = {
|
|
|
|
// na_letter
|
|
|
|
wxPAPER_LETTER,
|
|
|
|
wxPAPER_LETTERSMALL,
|
|
|
|
wxPAPER_NOTE,
|
|
|
|
wxPAPER_LETTER_TRANSVERSE,
|
|
|
|
wxPAPER_LETTER_ROTATED
|
|
|
|
};
|
|
|
|
|
|
|
|
std::set<wxPaperSize> legalSizes = {
|
|
|
|
// na_legal
|
|
|
|
wxPAPER_LEGAL
|
|
|
|
};
|
|
|
|
|
|
|
|
std::set<wxPaperSize> a4Sizes = {
|
|
|
|
// iso_a4
|
|
|
|
wxPAPER_A4,
|
|
|
|
wxPAPER_A4SMALL,
|
|
|
|
wxPAPER_A4_TRANSVERSE,
|
|
|
|
wxPAPER_A4_ROTATED
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
if( letterSizes.count( paperId ) )
|
|
|
|
paperType = PAGE_INFO::USLetter;
|
|
|
|
else if( legalSizes.count( paperId ) )
|
|
|
|
paperType = PAGE_INFO::USLegal;
|
|
|
|
else if( a4Sizes.count( paperId ) )
|
|
|
|
paperType = PAGE_INFO::A4;
|
|
|
|
|
|
|
|
if( paperType )
|
|
|
|
{
|
|
|
|
PAGE_INFO pageInfo( paperType, data.GetOrientation() == wxPORTRAIT );
|
|
|
|
|
|
|
|
if( pageInfo.IsPortrait() )
|
|
|
|
data.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
|
|
|
|
EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
|
|
|
|
else
|
|
|
|
data.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
|
|
|
|
EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
|
|
|
|
|
|
|
|
data.SetOrientation( pageInfo.GetWxOrientation() );
|
|
|
|
data.SetPaperId( wxPAPER_NONE );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxPrintDialogData printDialogData( data );
|
2020-05-13 02:00:37 +00:00
|
|
|
printDialogData.SetMaxPage( sheet_count );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
if( sheet_count > 1 )
|
2010-02-02 15:01:09 +00:00
|
|
|
printDialogData.EnablePageNumbers( true );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
wxPrinter printer( &printDialogData );
|
2023-11-24 16:43:04 +00:00
|
|
|
SCH_PRINTOUT printout( m_parent, _( "Print Schematic" ), m_useCairo );
|
2018-04-23 09:17:28 +00:00
|
|
|
|
2019-08-13 16:59:43 +00:00
|
|
|
Pgm().m_Printing = true;
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2019-08-13 16:59:43 +00:00
|
|
|
if( !printer.Print( this, &printout, true ) )
|
|
|
|
{
|
|
|
|
if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
|
|
|
|
DisplayError( this, _( "An error occurred attempting to print the schematic." ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_parent->GetPageSetupData() = printer.GetPrintDialogData().GetPrintData();
|
|
|
|
}
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2019-08-13 16:59:43 +00:00
|
|
|
Pgm().m_Printing = false;
|
2018-07-22 22:27:59 +00:00
|
|
|
|
|
|
|
return true;
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
int InvokeDialogPrintUsingPrinter( SCH_EDIT_FRAME* aCaller )
|
|
|
|
{
|
|
|
|
DIALOG_PRINT_USING_PRINTER dlg( aCaller );
|
|
|
|
|
|
|
|
return dlg.ShowModal();
|
|
|
|
}
|