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 PrintPage (SCH_SCREEN *aScreen)
 

Private Attributes

SCH_EDIT_FRAMEm_parent
 

Detailed Description

Custom print out for printing schematics.

Definition at line 61 of file dialog_print_using_printer.cpp.

Constructor & Destructor Documentation

◆ SCH_PRINTOUT()

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

Definition at line 67 of file dialog_print_using_printer.cpp.

67  :
68  wxPrintout( aTitle )
69  {
70  wxASSERT( aParent != NULL );
71  m_parent = aParent;
72  }
SCH_EDIT_FRAME * m_parent

References m_parent.

Member Function Documentation

◆ GetPageInfo()

void SCH_PRINTOUT::GetPageInfo ( int *  minPage,
int *  maxPage,
int *  selPageFrom,
int *  selPageTo 
)
override

Definition at line 315 of file dialog_print_using_printer.cpp.

316 {
317  *minPage = *selPageFrom = 1;
318  *maxPage = *selPageTo = g_RootSheet->CountSheets();
319 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets.
Definition: sch_sheet.cpp:608
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47

References SCH_SHEET::CountSheets(), and g_RootSheet.

◆ HasPage()

bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 322 of file dialog_print_using_printer.cpp.

323 {
324  return g_RootSheet->CountSheets() >= pageNum;
325 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets.
Definition: sch_sheet.cpp:608
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47

References SCH_SHEET::CountSheets(), and g_RootSheet.

◆ OnBeginDocument()

bool SCH_PRINTOUT::OnBeginDocument ( int  startPage,
int  endPage 
)
override

Definition at line 328 of file dialog_print_using_printer.cpp.

329 {
330  if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
331  return false;
332 
333 #ifdef __WXDEBUG__
334  wxLogDebug( wxT( "Printer name: " ) +
335  m_parent->GetPageSetupData().GetPrintData().GetPrinterName() );
336  wxLogDebug( wxT( "Paper ID: %d" ),
337  m_parent->GetPageSetupData().GetPrintData().GetPaperId() );
338  wxLogDebug( wxT( "Color: %d" ),
339  (int)m_parent->GetPageSetupData().GetPrintData().GetColour() );
340  wxLogDebug( wxT( "Monochrome: %d" ), m_parent->GetPrintMonochrome() );
341  wxLogDebug( wxT( "Orientation: %d:" ),
342  m_parent->GetPageSetupData().GetPrintData().GetOrientation() );
343  wxLogDebug( wxT( "Quality: %d"),
344  m_parent->GetPageSetupData().GetPrintData().GetQuality() );
345 #endif
346 
347  return true;
348 }
bool GetPrintMonochrome()
SCH_EDIT_FRAME * m_parent
wxPageSetupDialogData & GetPageSetupData()

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

◆ OnPrintPage()

bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 285 of file dialog_print_using_printer.cpp.

286 {
287  SCH_SHEET_LIST sheetList( g_RootSheet );
288 
289  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
290  wxT( "Cannot print invalid page number." ) );
291 
292  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
293  wxT( "Cannot print page with NULL screen." ) );
294 
295  wxString msg;
296  msg.Printf( _( "Print page %d" ), page );
298  m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
299 
300  SCH_SCREEN* screen = m_parent->GetScreen();
301  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
302  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
305  screen = m_parent->GetCurrentSheet().LastScreen();
306  PrintPage( screen );
307  m_parent->SetCurrentSheet( oldsheetpath );
310 
311  return true;
312 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_SHEET_LIST.
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_EDIT_FRAME * m_parent
void PrintPage(SCH_SCREEN *aScreen)
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
SCH_SHEET_PATH & GetCurrentSheet()
Definition: colors.h:59
Class SCH_SHEET_PATH.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
#define _(s)
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
SCH_SCREEN * LastScreen() const
Function LastScreen.

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

◆ PrintPage()

void SCH_PRINTOUT::PrintPage ( SCH_SCREEN aScreen)

Definition at line 354 of file dialog_print_using_printer.cpp.

355 {
356  int oldZoom;
357  wxPoint tmp_startvisu;
358  wxSize pageSizeIU; // Page size in internal units
359  wxPoint old_org;
360  wxRect fitRect;
361  wxDC* dc = GetDC();
362 
363  wxBusyCursor dummy;
364 
365  // Save current scale factor, offsets, and clip box.
366  tmp_startvisu = aScreen->m_StartVisu;
367  oldZoom = aScreen->GetZoom();
368  old_org = aScreen->m_DrawOrg;
369 
370  // Change scale factor and offset to print the whole page.
371  bool printReference = m_parent->GetPrintSheetReference();
372 
373  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
374  FitThisSizeToPaper( pageSizeIU );
375  fitRect = GetLogicalPaperRect();
376 
377  wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
378  fitRect.x, fitRect.y, fitRect.width, fitRect.height );
379 
380  // When is the actual paper size does not match the schematic page size, the drawing will
381  // not be centered on X or Y axis. Give a draw offset to center the schematic page on the
382  // paper draw area.
383  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
384  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
385 
386  if( dc->CanUseTransformMatrix() )
387  {
388  wxAffineMatrix2D matrix = dc->GetTransformMatrix();
389 
390  // Check for portrait/landscape mismatch:
391  if( ( fitRect.width > fitRect.height ) != ( pageSizeIU.x > pageSizeIU.y ) )
392  {
393  matrix.Rotate( M_PI_2 );
394  xoffset = ( fitRect.height - pageSizeIU.x ) / 2;
395  yoffset = ( fitRect.width - pageSizeIU.y ) / 2;
396  }
397 
398  matrix.Translate( xoffset, yoffset );
399  dc->SetTransformMatrix( matrix );
400  }
401  else
402  {
403  // wxWidgets appears to have a bug when OffsetLogicalOrigin()'s yoffset changes from
404  // page to page.
405  // NB: this is a workaround, not a fix. The Y centering will be off, but this is less
406  // annoying than a blank page. See https://bugs.launchpad.net/kicad/+bug/1464773.
407  yoffset = 0;
408 
409  OffsetLogicalOrigin( xoffset, yoffset );
410  }
411 
412  dc->SetLogicalFunction( wxCOPY );
413  GRResetPenAndBrush( dc );
414 
415  aScreen->m_IsPrinting = true;
416 
417  COLOR4D bgColor = m_parent->GetDrawBgColor();
419 
420  GRSFilledRect( nullptr, dc, fitRect.GetX(), fitRect.GetY(), fitRect.GetRight(),
421  fitRect.GetBottom(), 0, COLOR4D::WHITE, COLOR4D::WHITE );
422 
424  GRForceBlackPen( true );
425 
426  aScreen->Print( dc );
427 
428  if( printReference )
429  {
431  aScreen->GetFileName(), wxEmptyString,
433  }
434 
435  m_parent->SetDrawBgColor( bgColor );
436  aScreen->m_IsPrinting = false;
437 
438  GRForceBlackPen( false );
439 
440  aScreen->m_StartVisu = tmp_startvisu;
441  aScreen->m_DrawOrg = old_org;
442  aScreen->SetZoom( oldZoom );
443 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:120
const wxString & GetFileName() const
Definition: sch_screen.h:118
void PrintWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Prints the page layout with the frame and the basic inscriptions.
void GRSFilledRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, COLOR4D aColor, COLOR4D aBgColor)
Definition: gr_basic.cpp:923
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:240
bool GetPrintMonochrome()
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
virtual void SetDrawBgColor(COLOR4D aColor)
bool GetPrintSheetReference()
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:160
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:113
SCH_EDIT_FRAME * m_parent
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
Definition: base_screen.h:117
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:201
SCH_LAYER_ID
Eeschema drawing layers.
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
Definition: base_screen.cpp:86
bool m_IsPrinting
Definition: base_screen.h:139
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:112
#define IU_PER_MILS
Definition: plotter.cpp:134
Definition: colors.h:49
virtual COLOR4D GetDrawBgColor() const
void Print(wxDC *aDC)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:527
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References dummy(), GetDefaultLineThickness(), EDA_DRAW_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), GetLayerColor(), SCH_SCREEN::GetPageSettings(), SCH_EDIT_FRAME::GetPrintMonochrome(), SCH_EDIT_FRAME::GetPrintSheetReference(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), GRSFilledRect(), IU_PER_MILS, LAYER_WORKSHEET, BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, m_parent, BASE_SCREEN::m_StartVisu, SCH_SCREEN::Print(), EDA_DRAW_FRAME::PrintWorkSheet(), EDA_DRAW_FRAME::SetDrawBgColor(), BASE_SCREEN::SetZoom(), and WHITE.

Referenced by OnPrintPage().

Member Data Documentation

◆ m_parent

SCH_EDIT_FRAME* SCH_PRINTOUT::m_parent
private

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