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 68 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 71 of file dialog_print_using_printer.cpp.

71  :
72  wxPrintout( aTitle )
73  {
74  wxASSERT( aParent != nullptr );
75  m_parent = aParent;
76  }
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 376 of file dialog_print_using_printer.cpp.

377 {
378  *minPage = *selPageFrom = 1;
379  *maxPage = *selPageTo = m_parent->Schematic().Root().CountSheets();
380 }
SCH_EDIT_FRAME * m_parent
SCHEMATIC & Schematic() const
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:697
SCH_SHEET & Root() const
Definition: schematic.h:92

References SCH_SHEET::CountSheets(), m_parent, SCHEMATIC::Root(), and SCH_EDIT_FRAME::Schematic().

◆ HasPage()

bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 383 of file dialog_print_using_printer.cpp.

384 {
385  return m_parent->Schematic().Root().CountSheets() >= pageNum;
386 }
SCH_EDIT_FRAME * m_parent
SCHEMATIC & Schematic() const
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:697
SCH_SHEET & Root() const
Definition: schematic.h:92

References SCH_SHEET::CountSheets(), m_parent, SCHEMATIC::Root(), and SCH_EDIT_FRAME::Schematic().

◆ OnBeginDocument()

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

Definition at line 389 of file dialog_print_using_printer.cpp.

390 {
391  if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
392  return false;
393 
394  return true;
395 }

◆ OnPrintPage()

bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 347 of file dialog_print_using_printer.cpp.

348 {
349  SCH_SHEET_LIST sheetList = m_parent->Schematic().GetSheets();
350 
351  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
352  wxT( "Cannot print invalid page number." ) );
353 
354  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != nullptr, false,
355  wxT( "Cannot print page with NULL screen." ) );
356 
357  wxString msg;
358  msg.Printf( _( "Print page %d" ), page );
359  m_parent->SetMsgPanel( msg, wxEmptyString );
360 
361  SCH_SCREEN* screen = m_parent->GetScreen();
362  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
363  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
366  screen = m_parent->GetCurrentSheet().LastScreen();
367  PrintPage( screen );
368  m_parent->SetCurrentSheet( oldsheetpath );
371 
372  return true;
373 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
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)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
SCHEMATIC & Schematic() const
#define _(s)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
SCH_SCREEN * LastScreen()
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
SCH_SHEET_PATH & GetCurrentSheet() const

References _, SCH_EDIT_FRAME::GetCurrentSheet(), SCH_EDIT_FRAME::GetScreen(), SCHEMATIC::GetSheets(), SCH_SHEET_PATH::LastScreen(), m_parent, PrintPage(), SCH_EDIT_FRAME::Schematic(), SCH_EDIT_FRAME::SetCurrentSheet(), EDA_DRAW_FRAME::SetMsgPanel(), SCH_EDIT_FRAME::SetSheetNumberAndCount(), and SCH_SHEET_PATH::UpdateAllScreenReferences().

◆ PrintPage()

void SCH_PRINTOUT::PrintPage ( SCH_SCREEN aScreen)

Definition at line 401 of file dialog_print_using_printer.cpp.

402 {
403  wxPoint tmp_startvisu;
404  wxSize pageSizeIU; // Page size in internal units
405  wxPoint old_org;
406  wxRect fitRect;
407  wxDC* dc = GetDC();
408 
409  wxBusyCursor dummy;
410 
411  // Save current offsets and clip box.
412  tmp_startvisu = aScreen->m_StartVisu;
413  old_org = aScreen->m_DrawOrg;
414 
415  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
418 
419  // Change scale factor and offset to print the whole page.
420  bool printReference = cfg->m_Printing.title_block;
421 
422  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
423  FitThisSizeToPaper( pageSizeIU );
424 
425  fitRect = GetLogicalPaperRect();
426 
427  // When is the actual paper size does not match the schematic page size, the drawing will
428  // not be centered on X or Y axis. Give a draw offset to center the schematic page on the
429  // paper draw area.
430  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
431  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
432 
433  if( dc->CanUseTransformMatrix() )
434  {
435  wxAffineMatrix2D matrix = dc->GetTransformMatrix();
436 
437  // Check for portrait/landscape mismatch:
438  if( ( fitRect.width > fitRect.height ) != ( pageSizeIU.x > pageSizeIU.y ) )
439  {
440  matrix.Rotate( M_PI_2 );
441  xoffset = ( fitRect.height - pageSizeIU.x ) / 2;
442  yoffset = ( fitRect.width - pageSizeIU.y ) / 2;
443  }
444 
445  matrix.Translate( xoffset, yoffset );
446  dc->SetTransformMatrix( matrix );
447  }
448  else
449  {
450  // wxWidgets appears to have a bug when OffsetLogicalOrigin()'s yoffset changes from
451  // page to page.
452  // NB: this is a workaround, not a fix. The Y centering will be off, but this is less
453  // annoying than a blank page. See https://bugs.launchpad.net/kicad/+bug/1464773.
454  yoffset = 0;
455 
456  OffsetLogicalOrigin( xoffset, yoffset );
457  }
458 
459  dc->SetLogicalFunction( wxCOPY );
460  GRResetPenAndBrush( dc );
461 
462  COLOR4D savedBgColor = m_parent->GetDrawBgColor();
464 
465  if( cfg->m_Printing.background )
466  {
467  if( cfg->m_Printing.use_theme && theme )
468  bgColor = theme->GetColor( LAYER_SCHEMATIC_BACKGROUND );
469  }
470  else
471  {
472  bgColor = COLOR4D::WHITE;
473  }
474 
475  m_parent->SetDrawBgColor( bgColor );
476 
477  GRSFilledRect( nullptr, dc, fitRect.GetX(), fitRect.GetY(), fitRect.GetRight(),
478  fitRect.GetBottom(), 0, bgColor, bgColor );
479 
480  if( cfg->m_Printing.monochrome )
481  GRForceBlackPen( true );
482 
484  renderSettings.SetPrintDC( dc );
485 
486  if( cfg->m_Printing.use_theme && theme )
487  renderSettings.LoadColors( theme );
488 
489  // The drawing-sheet-item print code is shared between PCBNew and Eeschema, so it's easier
490  // if they just use the PCB layer.
491  renderSettings.SetLayerColor( LAYER_DRAWINGSHEET,
492  renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) );
493 
494  if( printReference )
495  {
496  m_parent->PrintDrawingSheet( &renderSettings, aScreen, IU_PER_MILS, aScreen->GetFileName(),
497  wxEmptyString );
498  }
499 
500  renderSettings.SetIsPrinting( true );
501 
502  aScreen->Print( &renderSettings );
503 
504  m_parent->SetDrawBgColor( savedBgColor );
505 
506  GRForceBlackPen( false );
507 
508  aScreen->m_StartVisu = tmp_startvisu;
509  aScreen->m_DrawOrg = old_org;
510 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:111
const wxString & GetFileName() const
Definition: sch_screen.h:145
#define M_PI_2
Definition: transline.cpp:40
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:137
bool title_block
Whether or not to print title block.
Definition: app_settings.h:138
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:136
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:132
bool monochrome
Whether or not to print in monochrome.
Definition: app_settings.h:134
EESCHEMA_SETTINGS * eeconfig() const
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
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:93
void GRForceBlackPen(bool flagforce)
Definition: gr_basic.cpp:190
drawingsheet frame and titleblock
Definition: layer_ids.h:212
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
COLOR4D GetDrawBgColor() const override
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
bool background
Whether or not to print background color.
Definition: app_settings.h:133
Definition: color4d.h:48
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
COLOR4D GetColor(int aLayer) const
void Print(const RENDER_SETTINGS *aSettings)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:729
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:88
#define IU_PER_MILS
Definition: plotter.cpp:136
Store schematic specific render settings.
Definition: sch_painter.h:70
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetPrintDC(wxDC *aDC)
virtual void SetDrawBgColor(const COLOR4D &aColor)
void GRSFilledRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition: gr_basic.cpp:838
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References APP_SETTINGS_BASE::PRINTING::background, APP_SETTINGS_BASE::PRINTING::color_theme, dummy(), SCH_BASE_FRAME::eeconfig(), COLOR_SETTINGS::GetColor(), SETTINGS_MANAGER::GetColorSettings(), SCH_BASE_FRAME::GetColorSettings(), SCH_BASE_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), SCH_SCREEN::GetPageSettings(), SCH_BASE_FRAME::GetRenderSettings(), GRForceBlackPen(), GRResetPenAndBrush(), GRSFilledRect(), IU_PER_MILS, LAYER_DRAWINGSHEET, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_DRAWINGSHEET, BASE_SCREEN::m_DrawOrg, m_parent, M_PI_2, APP_SETTINGS_BASE::m_Printing, BASE_SCREEN::m_StartVisu, APP_SETTINGS_BASE::PRINTING::monochrome, Pgm(), SCH_SCREEN::Print(), EDA_DRAW_FRAME::PrintDrawingSheet(), EDA_DRAW_FRAME::SetDrawBgColor(), KIGFX::RENDER_SETTINGS::SetPrintDC(), APP_SETTINGS_BASE::PRINTING::title_block, APP_SETTINGS_BASE::PRINTING::use_theme, 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: