kicad/common/copy_to_clipboard.cpp

116 lines
3.1 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"
static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );
2007-05-06 16:03:28 +00:00
2008-03-05 22:44:38 +00:00
void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
DrawPageOnClipboard( this );
2008-03-05 22:44:38 +00:00
if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
2008-03-05 22:44:38 +00:00
{
if( GetScreen()->IsBlockActive() )
DrawPanel->SetCursor( wxCursor( DrawPanel->GetDefaultCursor() ) );
2008-03-05 22:44:38 +00:00
DrawPanel->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 ...)
* This is not suitable for copy command within Eeschema or Pcbnew
2008-03-05 22:44:38 +00:00
*/
bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
2007-05-06 16:03:28 +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;
2008-03-05 22:44:38 +00:00
wxRect DrawArea;
BASE_SCREEN* screen = aFrame->DrawPanel->GetScreen();
2008-03-05 22:44:38 +00:00
/* scale is the ratio resolution/internal units */
float scale = 82.0 / aFrame->m_InternalUnits;
2008-03-05 22:44:38 +00:00
if( screen->IsBlockActive() )
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;
2008-03-05 22:44:38 +00:00
EDA_RECT tmp = aFrame->DrawPanel->m_ClipBox;
GRResetPenAndBrush( &dc );
const bool plotBlackAndWhite = false;
GRForceBlackPen( plotBlackAndWhite );
screen->m_IsPrinting = true;
dc.SetUserScale( scale, scale );
ClipboardSizeX = dc.MaxX() + 10;
ClipboardSizeY = dc.MaxY() + 10;
aFrame->DrawPanel->m_ClipBox.SetX( 0 );
aFrame->DrawPanel->m_ClipBox.SetY( 0 );
aFrame->DrawPanel->m_ClipBox.SetWidth( 0x7FFFFF0 );
aFrame->DrawPanel->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
}
const int maskLayer = 0xFFFFFFFF;
aFrame->PrintPage( &dc, maskLayer, false );
screen->m_IsPrinting = false;
aFrame->DrawPanel->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 );
2008-03-05 22:44:38 +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
}