2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: copy_to_clipboard.cpp
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Created: 18 aug 2006
|
2009-11-23 15:16:50 +00:00
|
|
|
// Licence: License GNU
|
2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "wx/metafile.h"
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "class_base_screen.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-05 22:44:38 +00:00
|
|
|
extern BASE_SCREEN* ActiveScreen;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
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
|
|
|
|
2009-11-23 15:16:50 +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
|
|
|
*/
|
2009-11-23 15:16:50 +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 )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
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 ...)
|
2009-11-23 15:16:50 +00:00
|
|
|
* This is not suitable for copy command within eeschema or pcbnew
|
2008-03-05 22:44:38 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +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;
|
2009-11-23 15:16:50 +00:00
|
|
|
wxPoint DrawOffset;
|
2008-03-05 22:44:38 +00:00
|
|
|
int ClipboardSizeX, ClipboardSizeY;
|
|
|
|
bool DrawBlock = FALSE;
|
|
|
|
wxRect DrawArea;
|
2009-04-05 20:49:15 +00:00
|
|
|
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->m_Parent->m_InternalUnits;
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( ActiveScreen->m_BlockLocate.m_Command != BLOCK_IDLE )
|
2008-03-05 22:44:38 +00:00
|
|
|
{
|
|
|
|
DrawBlock = TRUE;
|
2009-07-25 04:53:39 +00:00
|
|
|
DrawArea.SetX( ActiveScreen->m_BlockLocate.GetX() );
|
|
|
|
DrawArea.SetY( ActiveScreen->m_BlockLocate.GetY() );
|
|
|
|
DrawArea.SetWidth( ActiveScreen->m_BlockLocate.GetWidth() );
|
|
|
|
DrawArea.SetHeight( ActiveScreen->m_BlockLocate.GetHeight() );
|
2008-03-05 22:44:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Change frames and local settings. */
|
2008-03-05 22:44:38 +00:00
|
|
|
tmp_startvisu = ActiveScreen->m_StartVisu;
|
|
|
|
tmpzoom = ActiveScreen->GetZoom();
|
|
|
|
old_org = ActiveScreen->m_DrawOrg;
|
|
|
|
ActiveScreen->m_DrawOrg.x = ActiveScreen->m_DrawOrg.y = 0;
|
|
|
|
ActiveScreen->m_StartVisu.x = ActiveScreen->m_StartVisu.y = 0;
|
|
|
|
|
|
|
|
ActiveScreen->SetZoom( 1 );
|
|
|
|
|
|
|
|
wxMetafileDC dc /*(wxT(""), DrawArea.GetWidth(), DrawArea.GetHeight())*/;
|
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
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 );
|
2009-11-23 15:16:50 +00:00
|
|
|
panel->m_ClipBox.SetWidth( 0x7FFFFF0 );
|
|
|
|
panel->m_ClipBox.SetHeight( 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
|
|
|
|
2009-04-13 05:58:11 +00:00
|
|
|
panel->PrintPage( &dc, Print_Sheet_Ref, -1, false );
|
|
|
|
screen->m_IsPrinting = false;
|
|
|
|
panel->m_ClipBox = tmp;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GRForceBlackPen( FALSE );
|
|
|
|
SetPenMinWidth( 1 );
|
|
|
|
|
|
|
|
ActiveScreen->m_StartVisu = tmp_startvisu;
|
|
|
|
ActiveScreen->m_DrawOrg = old_org;
|
|
|
|
ActiveScreen->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
|
|
|
}
|