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

74  :
75  wxPrintout( aTitle )
76  {
77  wxASSERT( aParent != NULL );
78  m_parent = aParent;
79  }
SCH_EDIT_FRAME * m_parent
#define NULL

References m_parent, and NULL.

Member Function Documentation

◆ GetPageInfo()

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

Definition at line 382 of file dialog_print_using_printer.cpp.

383 {
384  *minPage = *selPageFrom = 1;
385  *maxPage = *selPageTo = m_parent->Schematic().Root().CountSheets();
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:683
SCH_SHEET & Root() const
Definition: schematic.h:104

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

◆ HasPage()

bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 389 of file dialog_print_using_printer.cpp.

390 {
391  return m_parent->Schematic().Root().CountSheets() >= pageNum;
392 }
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:683
SCH_SHEET & Root() const
Definition: schematic.h:104

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

396 {
397  if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
398  return false;
399 
400 #ifdef DEBUG
402 
403  wxLogDebug( wxT( "Printer name: " ) +
404  m_parent->GetPageSetupData().GetPrintData().GetPrinterName() );
405  wxLogDebug( wxT( "Paper ID: %d" ),
406  m_parent->GetPageSetupData().GetPrintData().GetPaperId() );
407  wxLogDebug( wxT( "Color: %d" ),
408  (int)m_parent->GetPageSetupData().GetPrintData().GetColour() );
409  wxLogDebug( wxT( "Monochrome: %d" ), cfg->m_Printing.monochrome );
410  wxLogDebug( wxT( "Orientation: %d:" ),
411  m_parent->GetPageSetupData().GetPrintData().GetOrientation() );
412  wxLogDebug( wxT( "Quality: %d"),
413  m_parent->GetPageSetupData().GetPrintData().GetQuality() );
414 #endif
415 
416  return true;
417 }
bool monochrome
Whether or not to print in monochrome.
Definition: app_settings.h:100
EESCHEMA_SETTINGS * eeconfig() const
SCH_EDIT_FRAME * m_parent
wxPageSetupDialogData & GetPageSetupData()

References SCH_BASE_FRAME::eeconfig(), SCH_EDIT_FRAME::GetPageSetupData(), m_parent, APP_SETTINGS_BASE::m_Printing, and APP_SETTINGS_BASE::PRINTING::monochrome.

◆ OnPrintPage()

bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 352 of file dialog_print_using_printer.cpp.

353 {
354  SCH_SHEET_LIST sheetList = m_parent->Schematic().GetSheets();
355 
356  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
357  wxT( "Cannot print invalid page number." ) );
358 
359  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
360  wxT( "Cannot print page with NULL screen." ) );
361 
362  wxString msg;
363  msg.Printf( _( "Print page %d" ), page );
365  m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
366 
367  SCH_SCREEN* screen = m_parent->GetScreen();
368  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
369  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
372  screen = m_parent->GetCurrentSheet().LastScreen();
373  PrintPage( screen );
374  m_parent->SetCurrentSheet( oldsheetpath );
377 
378  return true;
379 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_SHEET_LIST.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:99
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)
#define NULL
Definition: colors.h:59
SCHEMATIC & Schematic() const
SCH_SHEET_PATH.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
#define _(s)
Definition: 3d_actions.cpp:33
SCH_SHEET_PATH & GetCurrentSheet() const

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

◆ PrintPage()

void SCH_PRINTOUT::PrintPage ( SCH_SCREEN aScreen)

Definition at line 423 of file dialog_print_using_printer.cpp.

424 {
425  int oldZoom;
426  wxPoint tmp_startvisu;
427  wxSize pageSizeIU; // Page size in internal units
428  wxPoint old_org;
429  wxRect fitRect;
430  wxDC* dc = GetDC();
431 
432  wxBusyCursor dummy;
433 
434  // Save current scale factor, offsets, and clip box.
435  tmp_startvisu = aScreen->m_StartVisu;
436  oldZoom = aScreen->GetZoom();
437  old_org = aScreen->m_DrawOrg;
438 
439  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
442 
443  // Change scale factor and offset to print the whole page.
444  bool printReference = cfg->m_Printing.title_block;
445 
446  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
447  FitThisSizeToPaper( pageSizeIU );
448 
449  fitRect = GetLogicalPaperRect();
450 
451  wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
452  fitRect.x, fitRect.y, fitRect.width, fitRect.height );
453 
454  // When is the actual paper size does not match the schematic page size, the drawing will
455  // not be centered on X or Y axis. Give a draw offset to center the schematic page on the
456  // paper draw area.
457  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
458  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
459 
460  if( dc->CanUseTransformMatrix() )
461  {
462  wxAffineMatrix2D matrix = dc->GetTransformMatrix();
463 
464  // Check for portrait/landscape mismatch:
465  if( ( fitRect.width > fitRect.height ) != ( pageSizeIU.x > pageSizeIU.y ) )
466  {
467  matrix.Rotate( M_PI_2 );
468  xoffset = ( fitRect.height - pageSizeIU.x ) / 2;
469  yoffset = ( fitRect.width - pageSizeIU.y ) / 2;
470  }
471 
472  matrix.Translate( xoffset, yoffset );
473  dc->SetTransformMatrix( matrix );
474  }
475  else
476  {
477  // wxWidgets appears to have a bug when OffsetLogicalOrigin()'s yoffset changes from
478  // page to page.
479  // NB: this is a workaround, not a fix. The Y centering will be off, but this is less
480  // annoying than a blank page. See https://bugs.launchpad.net/kicad/+bug/1464773.
481  yoffset = 0;
482 
483  OffsetLogicalOrigin( xoffset, yoffset );
484  }
485 
486  dc->SetLogicalFunction( wxCOPY );
487  GRResetPenAndBrush( dc );
488 
489  aScreen->m_IsPrinting = true;
490 
491  COLOR4D savedBgColor = m_parent->GetDrawBgColor();
493 
494  if( cfg->m_Printing.background )
495  {
496  if( cfg->m_Printing.use_theme && theme )
497  bgColor = theme->GetColor( LAYER_SCHEMATIC_BACKGROUND );
498  }
499  else
500  {
501  bgColor = COLOR4D::WHITE;
502  }
503 
504  m_parent->SetDrawBgColor( bgColor );
505 
506  GRSFilledRect( nullptr, dc, fitRect.GetX(), fitRect.GetY(), fitRect.GetRight(),
507  fitRect.GetBottom(), 0, bgColor, bgColor );
508 
509  if( cfg->m_Printing.monochrome )
510  GRForceBlackPen( true );
511 
513  renderSettings.SetPrintDC( dc );
514 
515  if( cfg->m_Printing.use_theme && theme )
516  renderSettings.LoadColors( theme );
517 
518  // The worksheet item print code is shared between PCBNew and EESchema, so it's easier
519  // if they just use the PCB layer.
520  renderSettings.SetLayerColor( LAYER_WORKSHEET,
521  renderSettings.GetLayerColor( LAYER_SCHEMATIC_WORKSHEET ) );
522 
523  if( printReference )
524  {
525  m_parent->PrintWorkSheet( &renderSettings, aScreen, IU_PER_MILS, aScreen->GetFileName(),
526  wxEmptyString );
527  }
528 
529  aScreen->Print( &renderSettings );
530 
531  m_parent->SetDrawBgColor( savedBgColor );
532  aScreen->m_IsPrinting = false;
533 
534  GRForceBlackPen( false );
535 
536  aScreen->m_StartVisu = tmp_startvisu;
537  aScreen->m_DrawOrg = old_org;
538  aScreen->SetZoom( oldZoom );
539 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:120
const wxString & GetFileName() const
Definition: sch_screen.h:196
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
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:919
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:245
#define M_PI_2
Definition: transline.cpp:36
virtual void SetDrawBgColor(COLOR4D aColor)
void PrintWorkSheet(RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the page layout with the frame and the basic inscriptions.
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:103
bool title_block
Whether or not to print title block.
Definition: app_settings.h:104
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:102
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:191
bool monochrome
Whether or not to print in monochrome.
Definition: app_settings.h:100
EESCHEMA_SETTINGS * eeconfig() const
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
void Print(RENDER_SETTINGS *aSettings)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:774
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
Definition: base_screen.cpp:88
bool background
Whether or not to print background color.
Definition: app_settings.h:99
bool m_IsPrinting
Definition: base_screen.h:139
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
COLOR4D GetColor(int aLayer) const
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:138
Definition: colors.h:49
SCH_RENDER_SETTINGS Stores 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...
virtual COLOR4D GetDrawBgColor() const
void SetPrintDC(wxDC *aDC)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40

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(), EDA_DRAW_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), SCH_SCREEN::GetPageSettings(), SCH_BASE_FRAME::GetRenderSettings(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), GRSFilledRect(), IU_PER_MILS, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_WORKSHEET, LAYER_WORKSHEET, BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, 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::PrintWorkSheet(), EDA_DRAW_FRAME::SetDrawBgColor(), KIGFX::RENDER_SETTINGS::SetPrintDC(), BASE_SCREEN::SetZoom(), 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: