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 <class_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 61 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().

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