KiCad PCB EDA Suite
copy_to_clipboard.cpp File Reference
#include <wx/clipbrd.h>
#include <fctsys.h>
#include <gr_basic.h>
#include <common.h>
#include <id.h>
#include <class_drawpanel.h>
#include <base_screen.h>
#include <confirm.h>
#include <draw_frame.h>

Go to the source code of this file.

Functions

static bool DrawPageOnClipboard (EDA_DRAW_FRAME *aFrame)
 

Function Documentation

bool DrawPageOnClipboard ( EDA_DRAW_FRAME aFrame)
static

Definition at line 60 of file copy_to_clipboard.cpp.

References EDA_DRAW_PANEL::EraseScreen(), EDA_DRAW_FRAME::GetCanvas(), EDA_DRAW_PANEL::GetClipBox(), EDA_RECT::GetHeight(), EDA_DRAW_FRAME::GetPageSizeIU(), EDA_DRAW_PANEL::GetScreen(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), BASE_SCREEN::IsBlockActive(), BASE_SCREEN::m_BlockLocate, BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, BASE_SCREEN::m_StartVisu, max, BASE_SCREEN::MilsToIuScalar(), EDA_DRAW_FRAME::PrintPage(), scale, EDA_DRAW_PANEL::SetClipBox(), BASE_SCREEN::SetZoom(), wxPoint::x, and wxPoint::y.

Referenced by EDA_DRAW_FRAME::CopyToClipboard().

61 {
62  bool DrawBlock = false;
63  wxRect DrawArea;
64  BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
65 
66  if( screen->IsBlockActive() )
67  {
68  DrawBlock = true;
69  DrawArea.SetX( screen->m_BlockLocate.GetX() );
70  DrawArea.SetY( screen->m_BlockLocate.GetY() );
71  DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
72  DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
73  }
74  else
75  DrawArea.SetSize( aFrame->GetPageSizeIU() );
76 
77  // Calculate a reasonable dc size, in pixels, and the dc scale to fit
78  // the drawings into the dc size
79  // scale is the ratio resolution (in PPI) / internal units
80  double ppi = 300; // Use 300 pixels per inch to create bitmap images on start
81  double inch2Iu = 1000.0 * (double) screen->MilsToIuScalar();
82  double scale = ppi / inch2Iu;
83 
84  wxSize dcsize = DrawArea.GetSize();
85 
86  int maxdim = std::max( dcsize.x, dcsize.y );
87  // the max size in pixels of the bitmap used to byuild the sheet copy
88  const int maxbitmapsize = 3000;
89 
90  while( int( maxdim * scale ) > maxbitmapsize )
91  {
92  ppi = ppi / 1.5;
93  scale = ppi / inch2Iu;
94  }
95 
96  dcsize.x *= scale;
97  dcsize.y *= scale;
98 
99  // Set draw offset, zoom... to values needed to draw in the memory DC
100  // after saving initial values:
101  wxPoint tmp_startvisu = screen->m_StartVisu;
102  double tmpzoom = screen->GetZoom();
103  wxPoint old_org = screen->m_DrawOrg;
104  screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
105  screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
106 
107  screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
108 
109  wxMemoryDC dc;
110  wxBitmap image( dcsize );
111  dc.SelectObject( image );
112 
113  EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
114  GRResetPenAndBrush( &dc );
115  GRForceBlackPen( false );
116  screen->m_IsPrinting = true;
117  dc.SetUserScale( scale, scale );
118 
119  aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
120  wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
121 
122  if( DrawBlock )
123  {
124  dc.SetClippingRegion( DrawArea );
125  }
126 
127  dc.Clear();
128  aFrame->GetCanvas()->EraseScreen( &dc );
129  const LSET allLayersMask = LSET().set();
130  aFrame->PrintPage( &dc, allLayersMask, false );
131  screen->m_IsPrinting = false;
132  aFrame->GetCanvas()->SetClipBox( tmp );
133 
134  bool success = true;
135 
136  if( wxTheClipboard->Open() )
137  {
138  // This data objects are held by the clipboard,
139  // so do not delete them in the app.
140  wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
141  wxTheClipboard->SetData( clipbrd_data );
142  wxTheClipboard->Close();
143  }
144  else
145  success = false;
146 
147  // Deselect Bitmap from DC in order to delete the MemoryDC safely
148  // without deleting the bitmap
149  dc.SelectObject( wxNullBitmap );
150 
151  GRForceBlackPen( false );
152 
153  screen->m_StartVisu = tmp_startvisu;
154  screen->m_DrawOrg = old_org;
155  screen->SetZoom( tmpzoom );
156 
157  return success;
158 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:218
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:372
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:340
int GetHeight() const
Definition: eda_rect.h:118
virtual const wxSize GetPageSizeIU() const =0
Function GetPageSizeIU works off of GetPageSettings() to return the size of the paper page in the int...
void SetClipBox(const EDA_RECT &aRect)
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
Definition: base_screen.h:198
bool IsBlockActive() const
Definition: base_screen.h:499
Class LSET is a set of PCB_LAYER_IDs.
virtual void PrintPage(wxDC *aDC, LSET aPrintMask, bool aPrintMirrorMode, void *aData=NULL)
Function PrintPage used to print a page Print the page pointed by current screen, set by the calling ...
Definition: draw_frame.cpp:468
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:299
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
EDA_RECT * GetClipBox()
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: base_screen.h:245
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
bool m_IsPrinting
Definition: base_screen.h:220
const int scale
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:183
int GetX() const
Definition: eda_rect.h:109
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:176
int GetWidth() const
Definition: eda_rect.h:117
int GetY() const
Definition: eda_rect.h:110
void EraseScreen(wxDC *DC)
Definition: draw_panel.cpp:557