KiCad PCB EDA Suite
SCH_PRINTOUT Class Reference

Custom print out for printing schematics. More...

Inheritance diagram for SCH_PRINTOUT:

Public Member Functions

 SCH_PRINTOUT (SCH_EDIT_FRAME *aParent, const wxString &aTitle)
 
bool OnPrintPage (int page) override
 
bool HasPage (int page) override
 
bool OnBeginDocument (int startPage, int endPage) override
 
void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) override
 
void DrawPage (SCH_SCREEN *aScreen)
 

Private Attributes

SCH_EDIT_FRAMEm_parent
 

Detailed Description

Custom print out for printing schematics.

Definition at line 76 of file eeschema/dialogs/dialog_print_using_printer.cpp.

Constructor & Destructor Documentation

SCH_PRINTOUT::SCH_PRINTOUT ( SCH_EDIT_FRAME aParent,
const wxString &  aTitle 
)
inline

Definition at line 82 of file eeschema/dialogs/dialog_print_using_printer.cpp.

82  :
83  wxPrintout( aTitle )
84  {
85  wxASSERT( aParent != NULL );
86  m_parent = aParent;
87  }

Member Function Documentation

void SCH_PRINTOUT::DrawPage ( SCH_SCREEN aScreen)

Definition at line 396 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References SCH_SCREEN::Draw(), EDA_DRAW_FRAME::DrawWorkSheet(), dummy(), EDA_DRAW_FRAME::GetCanvas(), EDA_DRAW_PANEL::GetClipBox(), GetDefaultLineThickness(), EDA_DRAW_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), SCH_SCREEN::GetPageSettings(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, DIALOG_PRINT_USING_PRINTER::m_parent, BASE_SCREEN::m_StartVisu, MAX_VALUE, EDA_DRAW_PANEL::SetClipBox(), EDA_DRAW_FRAME::SetDrawBgColor(), and BASE_SCREEN::SetZoom().

397 {
398  int oldZoom;
399  wxPoint tmp_startvisu;
400  wxSize pageSizeIU; // Page size in internal units
401  wxPoint old_org;
402  EDA_RECT oldClipBox;
403  wxRect fitRect;
404  wxDC* dc = GetDC();
405  EDA_DRAW_PANEL* panel = m_parent->GetCanvas();
406 
407  wxBusyCursor dummy;
408 
409  // Save current scale factor, offsets, and clip box.
410  tmp_startvisu = aScreen->m_StartVisu;
411  oldZoom = aScreen->GetZoom();
412  old_org = aScreen->m_DrawOrg;
413 
414  oldClipBox = *panel->GetClipBox();
415 
416  // Change clip box to print the whole page.
417  #define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
418  // and that allows calculations without overflow
419  panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
420 
421  // Change scale factor and offset to print the whole page.
422  bool printReference = m_parent->GetPrintSheetReference();
423 
424  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
425  FitThisSizeToPaper( pageSizeIU );
426  fitRect = GetLogicalPaperRect();
427 
428  wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
429  fitRect.x, fitRect.y, fitRect.width, fitRect.height );
430 
431  // When is the actual paper size does not match the schematic page
432  // size, the drawing is not perfectly centered on X or Y axis.
433  // Give a draw offset centers the schematic page on the paper draw area
434  // Because the sizes are fitted, only an Y or X offset is needed
435  // and both are 0 when sizes are identical.
436  // Y or Y offset is not null when the X/Y size ratio differs between
437  // the actual paper size and the schematic page
438  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
439 
440  // For an obscure reason, OffsetLogicalOrigin creates issues,
441  // under some circumstances, when yoffset is not always null
442  // and changes from a page to another page
443  // This is only a workaround, not a fix
444  // see https://bugs.launchpad.net/kicad/+bug/1464773
445  // xoffset does not create issues.
446 #if 0 // FIX ME
447  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
448 #else
449  // the Y centering will be not perfect, but this is less annoying
450  // than a blank page or a buggy centering
451  int yoffset = 0;
452 #endif
453  OffsetLogicalOrigin( xoffset, yoffset );
454 
455  GRResetPenAndBrush( dc );
456 
458  GRForceBlackPen( true );
459 
460  aScreen->m_IsPrinting = true;
461 
462  COLOR4D bgColor = m_parent->GetDrawBgColor();
463 
464  aScreen->Draw( panel, dc, (GR_DRAWMODE) 0 );
465 
466  if( printReference )
468  IU_PER_MILS, aScreen->GetFileName() );
469 
470  m_parent->SetDrawBgColor( bgColor );
471  aScreen->m_IsPrinting = false;
472  panel->SetClipBox( oldClipBox );
473 
474  GRForceBlackPen( false );
475 
476  aScreen->m_StartVisu = tmp_startvisu;
477  aScreen->m_DrawOrg = old_org;
478  aScreen->SetZoom( oldZoom );
479 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:218
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
bool GetPrintMonochrome()
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 GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
Definition: sch_screen.h:120
bool GetPrintSheetReference()
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
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:299
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Draw all the items in the screen to aCanvas.
Definition: sch_screen.cpp:525
EDA_RECT * GetClipBox()
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
COLOR4D GetDrawBgColor() const override
bool m_IsPrinting
Definition: base_screen.h:220
#define MAX_VALUE
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
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
void SetDrawBgColor(COLOR4D aColor) override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:115
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Function DrawWorkSheet Draws on screen the page layout with the frame and the basic inscriptions...
Definition: worksheet.cpp:76
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void SCH_PRINTOUT::GetPageInfo ( int *  minPage,
int *  maxPage,
int *  selPageFrom,
int *  selPageTo 
)
override

Definition at line 350 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References SCH_SHEET::CountSheets(), and g_RootSheet.

351 {
352  *minPage = *selPageFrom = 1;
353  *maxPage = *selPageTo = g_RootSheet->CountSheets();
354 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets. ...
Definition: sch_sheet.cpp:625
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 357 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References SCH_SHEET::CountSheets(), and g_RootSheet.

358 {
359  int pageCount;
360 
361  pageCount = g_RootSheet->CountSheets();
362 
363  if( pageCount >= pageNum )
364  return true;
365 
366  return false;
367 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets. ...
Definition: sch_sheet.cpp:625
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
bool SCH_PRINTOUT::OnBeginDocument ( int  startPage,
int  endPage 
)
override

Definition at line 370 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References DIALOG_PRINT_USING_PRINTER::m_parent.

371 {
372  if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
373  return false;
374 
375 #ifdef __WXDEBUG__
376  wxLogDebug( wxT( "Printer name: " ) +
377  m_parent->GetPageSetupData().GetPrintData().GetPrinterName() );
378  wxLogDebug( wxT( "Paper ID: %d" ),
379  m_parent->GetPageSetupData().GetPrintData().GetPaperId() );
380  wxLogDebug( wxT( "Color: %d" ),
381  (int)m_parent->GetPageSetupData().GetPrintData().GetColour() );
382  wxLogDebug( wxT( "Monochrome: %d" ), m_parent->GetPrintMonochrome() );
383  wxLogDebug( wxT( "Orientation: %d:" ),
384  m_parent->GetPageSetupData().GetPrintData().GetOrientation() );
385  wxLogDebug( wxT( "Quality: %d"),
386  m_parent->GetPageSetupData().GetPrintData().GetQuality() );
387 #endif
388 
389  return true;
390 }
bool GetPrintMonochrome()
wxPageSetupDialogData & GetPageSetupData()
bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 320 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), EDA_DRAW_FRAME::ClearMsgPanel(), CYAN, g_RootSheet, PCB_BASE_FRAME::GetScreen(), and DIALOG_PRINT_USING_PRINTER::m_parent.

321 {
322  SCH_SHEET_LIST sheetList( g_RootSheet );
323 
324  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
325  wxT( "Cannot print invalid page number." ) );
326 
327  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
328  wxT( "Cannot print page with NULL screen." ) );
329 
330  wxString msg;
331  msg.Printf( _( "Print page %d" ), page );
333  m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
334 
335  SCH_SCREEN* screen = m_parent->GetScreen();
336  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
337  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
340  screen = m_parent->GetCurrentSheet().LastScreen();
341  DrawPage( screen );
342  m_parent->SetCurrentSheet( oldsheetpath );
345 
346  return true;
347 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_SHEET_LIST.
SCH_SCREEN * LastScreen() const
Function LastScreen.
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
SCH_SHEET_PATH & GetCurrentSheet()
Definition: colors.h:59
Class SCH_SHEET_PATH.
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:812
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:823

Member Data Documentation

SCH_EDIT_FRAME* SCH_PRINTOUT::m_parent
private

The documentation for this class was generated from the following file: