2011-12-29 20:11:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file copy_to_clipboard.cpp
|
|
|
|
*/
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/metafile.h>
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxstruct.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-03-28 19:26:31 +00:00
|
|
|
static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-03-28 19:26:31 +00:00
|
|
|
DrawPageOnClipboard( this );
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-02-08 14:48:38 +00:00
|
|
|
if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
|
2008-03-05 22:44:38 +00:00
|
|
|
{
|
2011-02-05 19:22:58 +00:00
|
|
|
if( GetScreen()->IsBlockActive() )
|
2012-02-28 20:14:17 +00:00
|
|
|
m_canvas->SetCursor( wxCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ) );
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture();
|
2008-03-05 22:44:38 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* copy the current page or block to the clipboard ,
|
2008-03-05 22:44:38 +00:00
|
|
|
* to export drawings to other applications (word processing ...)
|
2011-09-30 18:15:37 +00:00
|
|
|
* This is not suitable for copy command within Eeschema or Pcbnew
|
2008-03-05 22:44:38 +00:00
|
|
|
*/
|
2011-03-28 19:26:31 +00:00
|
|
|
bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
bool success = true;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2008-03-05 22:44:38 +00:00
|
|
|
int tmpzoom;
|
|
|
|
wxPoint tmp_startvisu;
|
|
|
|
wxPoint old_org;
|
2009-11-23 15:16:50 +00:00
|
|
|
wxPoint DrawOffset;
|
2008-03-05 22:44:38 +00:00
|
|
|
int ClipboardSizeX, ClipboardSizeY;
|
2011-03-28 19:26:31 +00:00
|
|
|
bool DrawBlock = false;
|
2008-03-05 22:44:38 +00:00
|
|
|
wxRect DrawArea;
|
2011-12-22 13:28:11 +00:00
|
|
|
BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2013-05-07 17:31:52 +00:00
|
|
|
// scale is the ratio resolution/internal units
|
|
|
|
double scale = 82.0 / 1000.0 / (double) screen->MilsToIuScalar();
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-02-05 19:22:58 +00:00
|
|
|
if( screen->IsBlockActive() )
|
2008-03-05 22:44:38 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
DrawBlock = true;
|
2010-02-22 19:56:32 +00:00
|
|
|
DrawArea.SetX( screen->m_BlockLocate.GetX() );
|
|
|
|
DrawArea.SetY( screen->m_BlockLocate.GetY() );
|
|
|
|
DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
|
|
|
|
DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
|
2008-03-05 22:44:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Change frames and local settings. */
|
2010-02-22 19:56:32 +00:00
|
|
|
tmp_startvisu = screen->m_StartVisu;
|
|
|
|
tmpzoom = screen->GetZoom();
|
|
|
|
old_org = screen->m_DrawOrg;
|
|
|
|
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
|
|
|
|
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
screen->SetZoom( 1 );
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
wxMetafileDC dc;
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
|
2009-04-13 05:58:11 +00:00
|
|
|
GRResetPenAndBrush( &dc );
|
2011-03-28 19:26:31 +00:00
|
|
|
const bool plotBlackAndWhite = false;
|
2011-02-27 19:54:01 +00:00
|
|
|
GRForceBlackPen( plotBlackAndWhite );
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = true;
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
ClipboardSizeX = dc.MaxX() + 10;
|
|
|
|
ClipboardSizeY = dc.MaxY() + 10;
|
2011-12-29 20:11:42 +00:00
|
|
|
aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
|
|
|
if( DrawBlock )
|
2008-03-05 22:44:38 +00:00
|
|
|
{
|
2009-04-13 05:58:11 +00:00
|
|
|
dc.SetClippingRegion( DrawArea );
|
2008-03-05 22:44:38 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2013-03-30 19:55:26 +00:00
|
|
|
aFrame->PrintPage( &dc, FULL_LAYERS, false );
|
2009-04-13 05:58:11 +00:00
|
|
|
screen->m_IsPrinting = false;
|
2011-12-29 20:11:42 +00:00
|
|
|
aFrame->GetCanvas()->SetClipBox( tmp );
|
2009-04-13 05:58:11 +00:00
|
|
|
wxMetafile* mf = dc.Close();
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
if( mf )
|
2008-03-05 22:44:38 +00:00
|
|
|
{
|
2009-04-13 05:58:11 +00:00
|
|
|
success = mf->SetClipboard( ClipboardSizeX, ClipboardSizeY );
|
|
|
|
delete mf;
|
2008-03-05 22:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 19:26:31 +00:00
|
|
|
GRForceBlackPen( false );
|
2008-03-05 22:44:38 +00:00
|
|
|
|
2010-02-22 19:56:32 +00:00
|
|
|
screen->m_StartVisu = tmp_startvisu;
|
|
|
|
screen->m_DrawOrg = old_org;
|
|
|
|
screen->SetZoom( tmpzoom );
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-05 22:44:38 +00:00
|
|
|
return success;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|