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
|
|
|
|
* Copyright (C) 2015 KiCad Developers, see CHANGELOG.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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
* 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 <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <class_sch_screen.h>
|
2015-02-21 09:46:44 +00:00
|
|
|
#include <schframe.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <eeschema_config.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
|
2013-06-10 12:24:01 +00:00
|
|
|
#include <invoke_sch_dialog.h>
|
2013-06-07 20:56:55 +00:00
|
|
|
#include <dialog_print_using_printer_base.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DIALOG_PRINT_USING_PRINTER
|
|
|
|
* offers to print a schematic dialog.
|
|
|
|
*
|
|
|
|
* Derived from DIALOG_PRINT_USING_PRINTER_base created by wxFormBuilder
|
|
|
|
*/
|
|
|
|
class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DIALOG_PRINT_USING_PRINTER( SCH_EDIT_FRAME* aParent );
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
SCH_EDIT_FRAME* GetParent() const
|
|
|
|
{
|
|
|
|
return ( SCH_EDIT_FRAME* ) wxWindow::GetParent();
|
|
|
|
}
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OnCloseWindow( wxCloseEvent& event );
|
|
|
|
void OnPageSetup( wxCommandEvent& event );
|
|
|
|
void OnPrintPreview( wxCommandEvent& event );
|
|
|
|
void OnPrintButtonClick( wxCommandEvent& event );
|
2015-03-06 08:58:32 +00:00
|
|
|
void OnButtonCancelClick( wxCommandEvent& event ) { Close(); }
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
void initDialog();
|
2013-06-07 20:56:55 +00:00
|
|
|
void GetPrintOptions();
|
|
|
|
};
|
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
/**
|
|
|
|
* Custom print out for printing schematics.
|
|
|
|
*/
|
|
|
|
class SCH_PRINTOUT : public wxPrintout
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
private:
|
2015-10-02 14:07:37 +00:00
|
|
|
SCH_EDIT_FRAME* m_parent;
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
public:
|
2015-10-02 14:07:37 +00:00
|
|
|
SCH_PRINTOUT( SCH_EDIT_FRAME* aParent, const wxString& aTitle ) :
|
2009-01-17 17:32:20 +00:00
|
|
|
wxPrintout( aTitle )
|
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
wxASSERT( aParent != NULL );
|
2015-06-14 17:58:57 +00:00
|
|
|
m_parent = aParent;
|
2010-02-02 15:01:09 +00:00
|
|
|
}
|
2009-01-17 17:32:20 +00:00
|
|
|
bool OnPrintPage( int page );
|
|
|
|
bool HasPage( int page );
|
|
|
|
bool OnBeginDocument( int startPage, int endPage );
|
2010-02-02 15:01:09 +00:00
|
|
|
void GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo );
|
2011-01-30 22:22:38 +00:00
|
|
|
void DrawPage( SCH_SCREEN* aScreen );
|
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
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
bool Show( bool show ) // overload
|
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
|
|
|
|
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 ) :
|
2010-02-02 15:01:09 +00:00
|
|
|
DIALOG_PRINT_USING_PRINTER_BASE( aParent )
|
2010-01-18 17:05:31 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
wxASSERT( aParent != NULL );
|
2010-01-18 17:05:31 +00:00
|
|
|
|
2010-11-29 15:05:01 +00:00
|
|
|
m_checkReference->SetValue( aParent->GetPrintSheetReference() );
|
2010-02-02 15:01:09 +00:00
|
|
|
m_checkMonochrome->SetValue( aParent->GetPrintMonochrome() );
|
2015-06-14 17:58:57 +00:00
|
|
|
initDialog();
|
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
|
2011-05-21 09:16:57 +00:00
|
|
|
m_buttonPreview->Hide();
|
|
|
|
#endif
|
2014-11-19 17:13:55 +00:00
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
2010-02-02 15:01:09 +00:00
|
|
|
}
|
2010-01-18 17:05:31 +00:00
|
|
|
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::initDialog()
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// Initialize page specific print setup dialog settings.
|
|
|
|
const PAGE_INFO& pageInfo = parent->GetScreen()->GetPageSettings();
|
|
|
|
wxPageSetupDialogData& pageSetupDialogData = parent->GetPageSetupData();
|
|
|
|
|
|
|
|
pageSetupDialogData.SetPaperId( pageInfo.GetPaperId() );
|
|
|
|
|
|
|
|
if( pageInfo.IsCustom() )
|
|
|
|
{
|
|
|
|
if( pageInfo.IsPortrait() )
|
|
|
|
pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ),
|
|
|
|
Mils2mm( pageInfo.GetHeightMils() ) ) );
|
|
|
|
else
|
|
|
|
pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ),
|
|
|
|
Mils2mm( pageInfo.GetWidthMils() ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
pageSetupDialogData.GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
if ( GetSizer() )
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
2013-03-12 15:17:44 +00:00
|
|
|
// Rely on the policy in class DIALOG_SHIM, which centers the dialog
|
|
|
|
// initially during a runtime session but gives user the ability to move it in
|
|
|
|
// that session.
|
2012-08-15 17:55:48 +00:00
|
|
|
// This dialog may get moved and resized in Show(), but in case this is
|
|
|
|
// the first time, center it for starters.
|
|
|
|
Center();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
m_buttonPrint->SetDefault(); // on linux, this is inadequate to determine
|
|
|
|
// what ENTER does. Must also SetFocus().
|
|
|
|
m_buttonPrint->SetFocus();
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
|
2012-07-09 07:10:07 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::GetPrintOptions()
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
|
|
|
|
|
|
|
parent->SetPrintMonochrome( m_checkMonochrome->IsChecked() );
|
|
|
|
parent->SetPrintSheetReference( m_checkReference->IsChecked() );
|
|
|
|
}
|
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
if( !IsIconized() )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
parent->SetPrintDialogPosition( GetPosition() );
|
|
|
|
parent->SetPrintDialogSize( GetSize() );
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 07:10:07 +00:00
|
|
|
GetPrintOptions();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
EndDialog( wxID_CANCEL );
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Open a dialog box for printer setup (printer options, page size ...)
|
|
|
|
*/
|
2010-02-02 15:01:09 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
wxPageSetupDialog pageSetupDialog( this, &parent->GetPageSetupData() );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
pageSetupDialog.ShowModal();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
parent->GetPageSetupData() = pageSetupDialog.GetPageSetupDialogData();
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Open and display a previewer frame for printing
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-07-09 07:10:07 +00:00
|
|
|
GetPrintOptions();
|
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" );
|
2015-10-02 14:07:37 +00:00
|
|
|
wxPrintPreview* preview = new wxPrintPreview( new SCH_PRINTOUT( parent, title ),
|
|
|
|
new SCH_PRINTOUT( parent, title ),
|
2010-02-02 15:01:09 +00:00
|
|
|
&parent->GetPageSetupData().GetPrintData() );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
if( preview == NULL )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
DisplayError( this, wxT( "Print preview error!" ) );
|
2009-01-17 17:32:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 );
|
2014-11-19 17:13:55 +00:00
|
|
|
frame->SetMinSize( wxSize( 550, 350 ) );
|
2012-08-15 17:55:48 +00:00
|
|
|
|
|
|
|
// on first invocation in this runtime session, set to 2/3 size of my parent,
|
|
|
|
// but will be changed in Show() if not first time as will position.
|
2012-08-16 15:34:41 +00:00
|
|
|
frame->SetSize( (parent->GetSize() * 2) / 3 );
|
2012-08-15 17:55:48 +00:00
|
|
|
frame->Center();
|
|
|
|
|
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.
|
|
|
|
// An other reason is the fact when closing the frame without this option,
|
|
|
|
// 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
|
|
|
|
|
|
|
frame->Raise(); // Needed on Ubuntu/Unity to display the frame
|
2009-01-17 17:32:20 +00:00
|
|
|
frame->Show( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* parent = GetParent();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-07-09 07:10:07 +00:00
|
|
|
GetPrintOptions();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
wxPrintDialogData printDialogData( parent->GetPageSetupData().GetPrintData() );
|
|
|
|
printDialogData.SetMaxPage( g_RootSheet->CountSheets() );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
if( g_RootSheet->CountSheets() > 1 )
|
|
|
|
printDialogData.EnablePageNumbers( true );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
wxPrinter printer( &printDialogData );
|
2015-10-02 14:07:37 +00:00
|
|
|
SCH_PRINTOUT printout( parent, _( "Print Schematic" ) );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
if( !printer.Print( this, &printout, true ) )
|
|
|
|
{
|
|
|
|
if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
|
2010-02-02 15:01:09 +00:00
|
|
|
wxMessageBox( _( "An error occurred attempting to print the schematic." ),
|
|
|
|
_( "Printing" ), wxOK );
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
parent->GetPageSetupData() = printer.GetPrintDialogData().GetPrintData();
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
bool SCH_PRINTOUT::OnPrintPage( int page )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Print page %d" ), page );
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->ClearMsgPanel();
|
|
|
|
m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2015-10-02 16:52:54 +00:00
|
|
|
SCH_SCREEN* screen = m_parent->GetScreen();
|
|
|
|
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
|
2010-02-02 15:01:09 +00:00
|
|
|
SCH_SHEET_PATH list;
|
|
|
|
SCH_SHEET_LIST SheetList( NULL );
|
|
|
|
SCH_SHEET_PATH* sheetpath = SheetList.GetSheet( page - 1 );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->SetCurrentSheet( list );
|
2016-02-15 20:17:51 +00:00
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->SetSheetNumberAndCount();
|
|
|
|
screen = m_parent->GetCurrentSheet().LastScreen();
|
2010-02-02 15:01:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screen = NULL;
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( screen == NULL )
|
|
|
|
return false;
|
2010-02-02 15:01:09 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
DrawPage( screen );
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->SetCurrentSheet( oldsheetpath );
|
2016-02-15 20:17:51 +00:00
|
|
|
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->SetSheetNumberAndCount();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
void SCH_PRINTOUT::GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
*minPage = *selPageFrom = 1;
|
|
|
|
*maxPage = *selPageTo = g_RootSheet->CountSheets();
|
2009-01-17 17:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
bool SCH_PRINTOUT::HasPage( int pageNum )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
|
|
|
int pageCount;
|
|
|
|
|
|
|
|
pageCount = g_RootSheet->CountSheets();
|
|
|
|
if( pageCount >= pageNum )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 15:01:09 +00:00
|
|
|
bool SCH_PRINTOUT::OnBeginDocument( int startPage, int endPage )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
|
|
|
if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
|
|
|
|
return false;
|
|
|
|
|
2010-02-16 17:49:17 +00:00
|
|
|
#ifdef __WXDEBUG__
|
2010-02-02 15:01:09 +00:00
|
|
|
wxLogDebug( wxT( "Printer name: " ) +
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->GetPageSetupData().GetPrintData().GetPrinterName() );
|
2010-02-02 15:01:09 +00:00
|
|
|
wxLogDebug( wxT( "Paper ID: %d" ),
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->GetPageSetupData().GetPrintData().GetPaperId() );
|
2010-02-02 15:01:09 +00:00
|
|
|
wxLogDebug( wxT( "Color: %d" ),
|
2015-10-02 16:52:54 +00:00
|
|
|
(int)m_parent->GetPageSetupData().GetPrintData().GetColour() );
|
|
|
|
wxLogDebug( wxT( "Monochrome: %d" ), m_parent->GetPrintMonochrome() );
|
2010-02-02 15:01:09 +00:00
|
|
|
wxLogDebug( wxT( "Orientation: %d:" ),
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->GetPageSetupData().GetPrintData().GetOrientation() );
|
2010-02-02 15:01:09 +00:00
|
|
|
wxLogDebug( wxT( "Quality: %d"),
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->GetPageSetupData().GetPrintData().GetQuality() );
|
2010-09-15 17:50:47 +00:00
|
|
|
#endif
|
2010-02-02 15:01:09 +00:00
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the real print function: print the active screen
|
|
|
|
*/
|
2011-01-30 22:22:38 +00:00
|
|
|
void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen )
|
2009-01-17 17:32:20 +00:00
|
|
|
{
|
2010-02-02 15:01:09 +00:00
|
|
|
int oldZoom;
|
|
|
|
wxPoint tmp_startvisu;
|
2012-01-05 08:07:11 +00:00
|
|
|
wxSize pageSizeIU; // Page size in internal units
|
2010-02-02 15:01:09 +00:00
|
|
|
wxPoint old_org;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT oldClipBox;
|
2010-02-02 15:01:09 +00:00
|
|
|
wxRect fitRect;
|
|
|
|
wxDC* dc = GetDC();
|
2015-10-02 16:52:54 +00:00
|
|
|
EDA_DRAW_PANEL* panel = m_parent->GetCanvas();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
|
2012-01-05 08:07:11 +00:00
|
|
|
// Save current scale factor, offsets, and clip box.
|
2011-01-30 22:22:38 +00:00
|
|
|
tmp_startvisu = aScreen->m_StartVisu;
|
|
|
|
oldZoom = aScreen->GetZoom();
|
|
|
|
old_org = aScreen->m_DrawOrg;
|
2010-02-02 15:01:09 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
oldClipBox = *panel->GetClipBox();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Change clip box to print the whole page.
|
|
|
|
#define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
|
|
|
|
// and that allows calculations without overflow
|
|
|
|
panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Change scale factor and offset to print the whole page.
|
2015-10-02 16:52:54 +00:00
|
|
|
bool printReference = m_parent->GetPrintSheetReference();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2012-02-20 18:46:56 +00:00
|
|
|
pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
|
|
|
|
FitThisSizeToPaper( pageSizeIU );
|
|
|
|
fitRect = GetLogicalPaperRect();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2015-07-20 23:29:59 +00:00
|
|
|
wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
|
2015-10-08 13:52:03 +00:00
|
|
|
fitRect.x, fitRect.y, fitRect.width, fitRect.height );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
// When is the actual paper size does not match the schematic page
|
|
|
|
// size, the drawing is not perfectly centered on X or Y axis.
|
|
|
|
// Give a draw offset centers the schematic page on the paper draw area
|
|
|
|
// Because the sizes are fitted, only an Y or X offset is needed
|
|
|
|
// and both are 0 when sizes are identical.
|
|
|
|
// Y or Y offset is not null when the X/Y size ratio differs between
|
|
|
|
// the actual paper size and the schematic page
|
2012-03-26 21:45:05 +00:00
|
|
|
int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
// For an obscure reason, OffsetLogicalOrigin creates issues,
|
|
|
|
// under some circumstances, when yoffset is not always null
|
|
|
|
// and changes from a page to an other page
|
|
|
|
// This is only a workaround, not a fix
|
|
|
|
// see https://bugs.launchpad.net/kicad/+bug/1464773
|
|
|
|
// xoffset does not create issues.
|
|
|
|
#if 0 // FIX ME
|
|
|
|
int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
|
|
|
|
#else
|
|
|
|
// the Y centering will be not perfect, but this is less annoying
|
|
|
|
// than a blank page or a buggy centering
|
|
|
|
int yoffset = 0;
|
|
|
|
#endif
|
2012-03-26 21:45:05 +00:00
|
|
|
OffsetLogicalOrigin( xoffset, yoffset );
|
|
|
|
|
2009-01-17 17:32:20 +00:00
|
|
|
GRResetPenAndBrush( dc );
|
|
|
|
|
2015-10-02 16:52:54 +00:00
|
|
|
if( m_parent->GetPrintMonochrome() )
|
2010-02-02 15:01:09 +00:00
|
|
|
GRForceBlackPen( true );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
aScreen->m_IsPrinting = true;
|
|
|
|
|
2015-10-02 16:52:54 +00:00
|
|
|
EDA_COLOR_T bg_color = m_parent->GetDrawBgColor();
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2015-03-25 17:27:17 +00:00
|
|
|
aScreen->Draw( panel, dc, (GR_DRAWMODE) 0 );
|
2011-01-11 20:34:29 +00:00
|
|
|
|
|
|
|
if( printReference )
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->DrawWorkSheet( dc, aScreen, GetDefaultLineThickness(),
|
2013-05-27 09:17:37 +00:00
|
|
|
IU_PER_MILS, aScreen->GetFileName() );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
2015-10-02 16:52:54 +00:00
|
|
|
m_parent->SetDrawBgColor( bg_color );
|
2011-01-30 22:22:38 +00:00
|
|
|
aScreen->m_IsPrinting = false;
|
2011-12-29 20:11:42 +00:00
|
|
|
panel->SetClipBox( oldClipBox );
|
2009-01-17 17:32:20 +00:00
|
|
|
|
|
|
|
GRForceBlackPen( false );
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
aScreen->m_StartVisu = tmp_startvisu;
|
|
|
|
aScreen->m_DrawOrg = old_org;
|
|
|
|
aScreen->SetZoom( oldZoom );
|
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();
|
|
|
|
}
|