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 392 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(), SCH_BASE_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), SCH_SCREEN::GetPageSettings(), SCH_EDIT_FRAME::GetPrintMonochrome(), SCH_EDIT_FRAME::GetPrintSheetReference(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, m_parent, BASE_SCREEN::m_StartVisu, MAX_VALUE, EDA_DRAW_PANEL::SetClipBox(), SCH_BASE_FRAME::SetDrawBgColor(), and BASE_SCREEN::SetZoom().

Referenced by OnPrintPage().

393 {
394  int oldZoom;
395  wxPoint tmp_startvisu;
396  wxSize pageSizeIU; // Page size in internal units
397  wxPoint old_org;
398  EDA_RECT oldClipBox;
399  wxRect fitRect;
400  wxDC* dc = GetDC();
401  EDA_DRAW_PANEL* panel = m_parent->GetCanvas();
402 
403  wxBusyCursor dummy;
404 
405  // Save current scale factor, offsets, and clip box.
406  tmp_startvisu = aScreen->m_StartVisu;
407  oldZoom = aScreen->GetZoom();
408  old_org = aScreen->m_DrawOrg;
409 
410  oldClipBox = *panel->GetClipBox();
411 
412  // Change clip box to print the whole page.
413  #define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
414  // and that allows calculations without overflow
415  panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
416 
417  // Change scale factor and offset to print the whole page.
418  bool printReference = m_parent->GetPrintSheetReference();
419 
420  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
421  FitThisSizeToPaper( pageSizeIU );
422  fitRect = GetLogicalPaperRect();
423 
424  wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
425  fitRect.x, fitRect.y, fitRect.width, fitRect.height );
426 
427  // When is the actual paper size does not match the schematic page
428  // size, the drawing is not perfectly centered on X or Y axis.
429  // Give a draw offset centers the schematic page on the paper draw area
430  // Because the sizes are fitted, only an Y or X offset is needed
431  // and both are 0 when sizes are identical.
432  // Y or Y offset is not null when the X/Y size ratio differs between
433  // the actual paper size and the schematic page
434  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
435 
436  // For an obscure reason, OffsetLogicalOrigin creates issues,
437  // under some circumstances, when yoffset is not always null
438  // and changes from a page to an other page
439  // This is only a workaround, not a fix
440  // see https://bugs.launchpad.net/kicad/+bug/1464773
441  // xoffset does not create issues.
442 #if 0 // FIX ME
443  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
444 #else
445  // the Y centering will be not perfect, but this is less annoying
446  // than a blank page or a buggy centering
447  int yoffset = 0;
448 #endif
449  OffsetLogicalOrigin( xoffset, yoffset );
450 
451  GRResetPenAndBrush( dc );
452 
454  GRForceBlackPen( true );
455 
456  aScreen->m_IsPrinting = true;
457 
458  COLOR4D bgColor = m_parent->GetDrawBgColor();
459 
460  aScreen->Draw( panel, dc, (GR_DRAWMODE) 0 );
461 
462  if( printReference )
464  IU_PER_MILS, aScreen->GetFileName() );
465 
466  m_parent->SetDrawBgColor( bgColor );
467  aScreen->m_IsPrinting = false;
468  panel->SetClipBox( oldClipBox );
469 
470  GRForceBlackPen( false );
471 
472  aScreen->m_StartVisu = tmp_startvisu;
473  aScreen->m_DrawOrg = old_org;
474  aScreen->SetZoom( oldZoom );
475 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:196
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
bool GetPrintMonochrome()
Definition: schframe.h:687
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
bool GetPrintSheetReference()
Definition: schframe.h:689
void SetClipBox(const EDA_RECT &aRect)
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:271
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Function Draw draws all the items in the screen to aCanvas.
Definition: sch_screen.cpp:558
EDA_RECT * GetClipBox()
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
COLOR4D GetDrawBgColor() const override
#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.
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
void SetDrawBgColor(COLOR4D aColor) override
const PAGE_INFO & GetPageSettings() const
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:77
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 346 of file eeschema/dialogs/dialog_print_using_printer.cpp.

References SCH_SHEET::CountSheets(), and g_RootSheet.

347 {
348  *minPage = *selPageFrom = 1;
349  *maxPage = *selPageTo = g_RootSheet->CountSheets();
350 }
int CountSheets()
Function CountSheets calculates the number of sheets found in "this" this number includes the full su...
Definition: sch_sheet.cpp:828
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
bool SCH_PRINTOUT::HasPage ( int  page)
override

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

References SCH_SHEET::CountSheets(), and g_RootSheet.

354 {
355  int pageCount;
356 
357  pageCount = g_RootSheet->CountSheets();
358 
359  if( pageCount >= pageNum )
360  return true;
361 
362  return false;
363 }
int CountSheets()
Function CountSheets calculates the number of sheets found in "this" this number includes the full su...
Definition: sch_sheet.cpp:828
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
bool SCH_PRINTOUT::OnBeginDocument ( int  startPage,
int  endPage 
)
override

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

References SCH_EDIT_FRAME::GetPageSetupData(), SCH_EDIT_FRAME::GetPrintMonochrome(), and m_parent.

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

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

References EDA_DRAW_FRAME::AppendMsgPanel(), EDA_DRAW_FRAME::ClearMsgPanel(), CYAN, DrawPage(), g_RootSheet, SCH_EDIT_FRAME::GetCurrentSheet(), SCH_EDIT_FRAME::GetScreen(), SCH_SHEET_PATH::LastScreen(), m_parent, SCH_EDIT_FRAME::SetCurrentSheet(), SCH_EDIT_FRAME::SetSheetNumberAndCount(), and SCH_SHEET_PATH::UpdateAllScreenReferences().

317 {
318  SCH_SHEET_LIST sheetList( g_RootSheet );
319 
320  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
321  wxT( "Cannot print invalid page number." ) );
322 
323  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
324  wxT( "Cannot print page with NULL screen." ) );
325 
326  wxString msg;
327  msg.Printf( _( "Print page %d" ), page );
329  m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
330 
331  SCH_SCREEN* screen = m_parent->GetScreen();
332  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
333  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
336  screen = m_parent->GetCurrentSheet().LastScreen();
337  DrawPage( screen );
338  m_parent->SetCurrentSheet( oldsheetpath );
341 
342  return true;
343 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Definition: schframe.cpp:580
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.
Definition: schframe.cpp:527
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
SCH_SHEET_PATH & GetCurrentSheet()
Definition: schframe.cpp:572
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:753
void SetSheetNumberAndCount()
Function SetSheetNumberAndCount Set the m_ScreenNumber and m_NumberOfScreens members for screens must...
Definition: schframe.cpp:492
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764

Member Data Documentation

SCH_EDIT_FRAME* SCH_PRINTOUT::m_parent
private

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