kicad/common/copy_to_clipboard.cpp

120 lines
3.3 KiB
C++
Raw Normal View History

2007-05-06 16:03:28 +00:00
/////////////////////////////////////////////////////////////////////////////
// Name: copy_to_clipboard.cpp
// Author: jean-pierre Charras
// Created: 18 aug 2006
// Licence: License GNU
2007-05-06 16:03:28 +00:00
/////////////////////////////////////////////////////////////////////////////
2007-05-06 16:03:28 +00:00
#include "wx/metafile.h"
#include "fctsys.h"
#include "gr_basic.h"
2007-05-06 16:03:28 +00:00
#include "common.h"
#include "id.h"
#include "class_drawpanel.h"
#include "class_base_screen.h"
#include "confirm.h"
#include "wxstruct.h"
2008-03-05 22:44:38 +00:00
static const bool s_PlotBlackAndWhite = FALSE;
static const bool Print_Sheet_Ref = TRUE;
2007-05-06 16:03:28 +00:00
2008-03-05 22:44:38 +00:00
static bool DrawPage( WinEDA_DrawPanel* panel );
2007-05-06 16:03:28 +00:00
2008-03-05 22:44:38 +00:00
/* calls the function to copy the current page or the current bock to
* the clipboard
2008-03-05 22:44:38 +00:00
*/
void WinEDA_DrawFrame::CopyToClipboard( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
2008-03-05 22:44:38 +00:00
DrawPage( DrawPanel );
if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
{
if( GetBaseScreen()->m_BlockLocate.m_Command != BLOCK_IDLE )
2008-03-05 22:44:38 +00:00
DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor =
DrawPanel->m_PanelDefaultCursor ) );
2009-12-20 19:48:58 +00:00
DrawPanel->UnManageCursor( );
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 ...)
* This is not suitable for copy command within eeschema or pcbnew
2008-03-05 22:44:38 +00:00
*/
bool DrawPage( WinEDA_DrawPanel* panel )
2007-05-06 16:03:28 +00:00
{
2008-03-05 22:44:38 +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;
wxPoint DrawOffset;
2008-03-05 22:44:38 +00:00
int ClipboardSizeX, ClipboardSizeY;
bool DrawBlock = FALSE;
wxRect DrawArea;
BASE_SCREEN* screen = panel->GetScreen();
2008-03-05 22:44:38 +00:00
/* scale is the ratio resolution/internal units */
float scale = 82.0 / panel->GetParent()->m_InternalUnits;
2008-03-05 22:44:38 +00:00
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE )
2008-03-05 22:44:38 +00:00
{
DrawBlock = TRUE;
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
}
/* Change frames and local settings. */
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
screen->SetZoom( 1 );
2008-03-05 22:44:38 +00:00
wxMetafileDC dc /*(wxT(""), DrawArea.GetWidth(), DrawArea.GetHeight())*/;
EDA_Rect tmp = panel->m_ClipBox;
GRResetPenAndBrush( &dc );
GRForceBlackPen( s_PlotBlackAndWhite );
screen->m_IsPrinting = true;
dc.SetUserScale( scale, scale );
ClipboardSizeX = dc.MaxX() + 10;
ClipboardSizeY = dc.MaxY() + 10;
panel->m_ClipBox.SetX( 0 ); panel->m_ClipBox.SetY( 0 );
panel->m_ClipBox.SetWidth( 0x7FFFFF0 );
panel->m_ClipBox.SetHeight( 0x7FFFFF0 );
if( DrawBlock )
2008-03-05 22:44:38 +00:00
{
dc.SetClippingRegion( DrawArea );
2008-03-05 22:44:38 +00:00
}
panel->PrintPage( &dc, Print_Sheet_Ref, -1, false, NULL );
screen->m_IsPrinting = false;
panel->m_ClipBox = tmp;
wxMetafile* mf = dc.Close();
if( mf )
2008-03-05 22:44:38 +00:00
{
success = mf->SetClipboard( ClipboardSizeX, ClipboardSizeY );
delete mf;
2008-03-05 22:44:38 +00:00
}
GRForceBlackPen( FALSE );
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
}