copy_to_clipboard.cpp 3.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * 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
 */
28

29 30 31 32 33 34 35 36
#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>
37
#include <draw_frame.h>
38

39
static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );
plyatov's avatar
plyatov committed
40

dickelbeck's avatar
dickelbeck committed
41

42
void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
plyatov's avatar
plyatov committed
43
{
44
    DrawPageOnClipboard( this );
dickelbeck's avatar
dickelbeck committed
45

46
    if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
dickelbeck's avatar
dickelbeck committed
47
    {
48
        if( GetScreen()->IsBlockActive() )
49
            m_canvas->SetCursor( wxCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ) );
dickelbeck's avatar
dickelbeck committed
50

51
        m_canvas->EndMouseCapture();
dickelbeck's avatar
dickelbeck committed
52
    }
plyatov's avatar
plyatov committed
53 54
}

dickelbeck's avatar
dickelbeck committed
55

plyatov's avatar
plyatov committed
56
/* copy the current page or block to the clipboard ,
dickelbeck's avatar
dickelbeck committed
57
 * to export drawings to other applications (word processing ...)
58
 * This is not suitable for copy command within Eeschema or Pcbnew
dickelbeck's avatar
dickelbeck committed
59
 */
60
bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
plyatov's avatar
plyatov committed
61
{
62
    bool    success = true;
plyatov's avatar
plyatov committed
63 64

#ifdef __WINDOWS__
dickelbeck's avatar
dickelbeck committed
65 66 67
    int     tmpzoom;
    wxPoint tmp_startvisu;
    wxPoint old_org;
68
    wxPoint DrawOffset;
dickelbeck's avatar
dickelbeck committed
69
    int     ClipboardSizeX, ClipboardSizeY;
70
    bool    DrawBlock = false;
dickelbeck's avatar
dickelbeck committed
71
    wxRect  DrawArea;
72
    BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
dickelbeck's avatar
dickelbeck committed
73

74 75
    // scale is the ratio resolution/internal units
    double  scale = 82.0 / 1000.0 / (double) screen->MilsToIuScalar();
dickelbeck's avatar
dickelbeck committed
76

77
    if( screen->IsBlockActive() )
dickelbeck's avatar
dickelbeck committed
78
    {
79
        DrawBlock = true;
80 81 82 83
        DrawArea.SetX( screen->m_BlockLocate.GetX() );
        DrawArea.SetY( screen->m_BlockLocate.GetY() );
        DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
        DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
dickelbeck's avatar
dickelbeck committed
84 85
    }

86
    /* Change frames and local settings. */
87 88 89 90 91
    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;
dickelbeck's avatar
dickelbeck committed
92

93
    screen->SetZoom( 1 );
dickelbeck's avatar
dickelbeck committed
94

jean-pierre charras's avatar
jean-pierre charras committed
95
    wxMetafileDC dc;
dickelbeck's avatar
dickelbeck committed
96

97
    EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
98
    GRResetPenAndBrush( &dc );
99
    const bool plotBlackAndWhite = false;
jean-pierre charras's avatar
jean-pierre charras committed
100
    GRForceBlackPen( plotBlackAndWhite );
101 102 103 104
    screen->m_IsPrinting = true;
    dc.SetUserScale( scale, scale );
    ClipboardSizeX = dc.MaxX() + 10;
    ClipboardSizeY = dc.MaxY() + 10;
105
    aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
106 107

    if( DrawBlock )
dickelbeck's avatar
dickelbeck committed
108
    {
109
        dc.SetClippingRegion( DrawArea );
dickelbeck's avatar
dickelbeck committed
110
    }
111

112 113
    const LSET allLayersMask = LSET().set();
    aFrame->PrintPage( &dc, allLayersMask, false );
114
    screen->m_IsPrinting = false;
115
    aFrame->GetCanvas()->SetClipBox( tmp );
116
    wxMetafile* mf = dc.Close();
117

118
    if( mf )
dickelbeck's avatar
dickelbeck committed
119
    {
120 121
        success = mf->SetClipboard( ClipboardSizeX, ClipboardSizeY );
        delete mf;
dickelbeck's avatar
dickelbeck committed
122 123 124
    }


125
    GRForceBlackPen( false );
dickelbeck's avatar
dickelbeck committed
126

127 128 129
    screen->m_StartVisu = tmp_startvisu;
    screen->m_DrawOrg   = old_org;
    screen->SetZoom( tmpzoom );
plyatov's avatar
plyatov committed
130 131
#endif

dickelbeck's avatar
dickelbeck committed
132
    return success;
plyatov's avatar
plyatov committed
133
}