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

385{
386 *minPage = *selPageFrom = 1;
387 *maxPage = *selPageTo = m_parent->Schematic().Root().CountSheets();
388}
SCH_SHEET & Root() const
Definition: schematic.h:91
SCHEMATIC & Schematic() const
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:783

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

◆ HasPage()

bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 391 of file dialog_print_using_printer.cpp.

392{
393 return m_parent->Schematic().Root().CountSheets() >= pageNum;
394}

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

398{
399 if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
400 return false;
401
402 return true;
403}

◆ OnPrintPage()

bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 355 of file dialog_print_using_printer.cpp.

356{
358
359 wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
360 wxT( "Cannot print invalid page number." ) );
361
362 wxCHECK_MSG( sheetList[ page - 1].LastScreen() != nullptr, false,
363 wxT( "Cannot print page with NULL screen." ) );
364
365 wxString msg;
366 msg.Printf( _( "Print page %d" ), page );
367 m_parent->SetMsgPanel( msg, wxEmptyString );
368
369 SCH_SCREEN* screen = m_parent->GetScreen();
370 SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
371 m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
374 screen = m_parent->GetCurrentSheet().LastScreen();
375 PrintPage( screen );
376 m_parent->SetCurrentSheet( oldsheetpath );
379
380 return true;
381}
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:86
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void PrintPage(SCH_SCREEN *aScreen)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
#define _(s)

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

410{
411 // Warning:
412 // When printing many pages, changes in the current wxDC will affect all next printings
413 // because all prints are using the same wxPrinterDC after creation
414 // So be careful and reinit parameters, especially when using offsets.
415
416 VECTOR2I tmp_startvisu;
417 wxSize pageSizeIU; // Page size in internal units
418 VECTOR2I old_org;
419 wxRect fitRect;
420 wxDC* dc = GetDC();
421
422 wxBusyCursor dummy;
423
424 // Save current offsets and clip box.
425 tmp_startvisu = aScreen->m_StartVisu;
426 old_org = aScreen->m_DrawOrg;
427
428 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
431
432 // Change scale factor and offset to print the whole page.
433 bool printReference = cfg->m_Printing.title_block;
434
435 pageSizeIU = aScreen->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS );
436 FitThisSizeToPaper( pageSizeIU );
437
438 fitRect = GetLogicalPaperRect();
439
440 // When is the actual paper size does not match the schematic page size, the drawing will
441 // not be centered on X or Y axis. Give a draw offset to center the schematic page on the
442 // paper draw area.
443 int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
444 int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
445
446 // Using a wxAffineMatrix2D has a big advantage: it handles different pages orientations
447 //(PORTRAIT/LANDSCAPE), but the affine matrix is not always supported
448 if( dc->CanUseTransformMatrix() )
449 {
450 wxAffineMatrix2D matrix; // starts from a unity matrix (the current wxDC default)
451
452 // Check for portrait/landscape mismatch:
453 if( ( fitRect.width > fitRect.height ) != ( pageSizeIU.x > pageSizeIU.y ) )
454 {
455 // Rotate the coordinates, and keep the draw coordinates inside the page
456 matrix.Rotate( M_PI_2 );
457 matrix.Translate( 0, -pageSizeIU.y );
458
459 // Recalculate the offsets and page sizes according to the page rotation
460 std::swap( pageSizeIU.x, pageSizeIU.y );
461 FitThisSizeToPaper( pageSizeIU );
462 fitRect = GetLogicalPaperRect();
463
464 xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
465 yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
466
467 // All the coordinates will be rotated 90 deg when printing,
468 // so the X,Y offset vector must be rotated -90 deg before printing
469 std::swap( xoffset, yoffset );
470 yoffset = -yoffset;
471 }
472
473 matrix.Translate( xoffset, yoffset );
474 dc->SetTransformMatrix( matrix );
475 }
476 else
477 {
478 SetLogicalOrigin( 0, 0 ); // Reset all offset settings made previously.
479 // When printing previous pages (all prints are using the same wxDC)
480 OffsetLogicalOrigin( xoffset, yoffset );
481 }
482
483 dc->SetLogicalFunction( wxCOPY );
484 GRResetPenAndBrush( dc );
485
486 COLOR4D savedBgColor = m_parent->GetDrawBgColor();
488
489 if( cfg->m_Printing.background )
490 {
491 if( cfg->m_Printing.use_theme && theme )
492 bgColor = theme->GetColor( LAYER_SCHEMATIC_BACKGROUND );
493 }
494 else
495 {
496 bgColor = COLOR4D::WHITE;
497 }
498
499 m_parent->SetDrawBgColor( bgColor );
500
501 GRSFilledRect( dc, fitRect.GetX(), fitRect.GetY(), fitRect.GetRight(), fitRect.GetBottom(), 0,
502 bgColor, bgColor );
503
504 if( cfg->m_Printing.monochrome )
505 GRForceBlackPen( true );
506
508 renderSettings.SetPrintDC( dc );
509
510 if( cfg->m_Printing.use_theme && theme )
511 renderSettings.LoadColors( theme );
512
513 renderSettings.SetBackgroundColor( bgColor );
514
515 // The drawing-sheet-item print code is shared between PCBNew and Eeschema, so it's easier
516 // if they just use the PCB layer.
517 renderSettings.SetLayerColor( LAYER_DRAWINGSHEET,
518 renderSettings.GetLayerColor( LAYER_SCHEMATIC_DRAWINGSHEET ) );
519
520 renderSettings.SetDefaultFont( cfg->m_Appearance.default_font );
521
522 if( printReference )
523 {
524 m_parent->PrintDrawingSheet( &renderSettings, aScreen, aScreen->Schematic()->GetProperties(),
525 schIUScale.IU_PER_MILS, aScreen->GetFileName(), wxEmptyString );
526 }
527
528 renderSettings.SetIsPrinting( true );
529
530 aScreen->Print( &renderSettings );
531
532 m_parent->SetDrawBgColor( savedBgColor );
533
534 GRForceBlackPen( false );
535
536 aScreen->m_StartVisu = tmp_startvisu;
537 aScreen->m_DrawOrg = old_org;
538}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
VECTOR2I m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:88
VECTOR2I m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
Definition: base_screen.h:93
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
virtual void SetDrawBgColor(const COLOR4D &aColor)
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, const std::map< wxString, wxString > *aProperties, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Store schematic specific render settings.
Definition: sch_painter.h:71
const wxSize GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:162
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:79
EESCHEMA_SETTINGS * eeconfig() const
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
COLOR4D GetDrawBgColor() const override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
void Print(const RENDER_SETTINGS *aSettings)
Print all the items in the screen to aDC.
const wxString & GetFileName() const
Definition: sch_screen.h:144
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:92
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
@ WHITE
Definition: color4d.h:48
void GRForceBlackPen(bool flagforce)
Definition: gr_basic.cpp:150
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:72
void GRSFilledRect(wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition: gr_basic.cpp:413
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:217
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:382
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
std::vector< FAB_LAYER_COLOR > dummy
bool monochrome
Whether or not to print in monochrome.
Definition: app_settings.h:146
bool background
Whether or not to print background color.
Definition: app_settings.h:145
wxString color_theme
Color theme to use for printing.
Definition: app_settings.h:149
bool title_block
Whether or not to print title block.
Definition: app_settings.h:150
bool use_theme
If false, display color theme will be used.
Definition: app_settings.h:148
const double IU_PER_MILS
Definition: base_units.h:78
#define M_PI_2
Definition: transline.cpp:40

References APP_SETTINGS_BASE::PRINTING::background, APP_SETTINGS_BASE::PRINTING::color_theme, EESCHEMA_SETTINGS::APPEARANCE::default_font, dummy, SCH_BASE_FRAME::eeconfig(), COLOR_SETTINGS::GetColor(), SCH_BASE_FRAME::GetColorSettings(), SETTINGS_MANAGER::GetColorSettings(), SCH_BASE_FRAME::GetDrawBgColor(), SCH_SCREEN::GetFileName(), KIGFX::RENDER_SETTINGS::GetLayerColor(), SCH_SCREEN::GetPageSettings(), SCHEMATIC::GetProperties(), SCH_BASE_FRAME::GetRenderSettings(), PAGE_INFO::GetSizeIU(), GRForceBlackPen(), GRResetPenAndBrush(), GRSFilledRect(), EDA_IU_SCALE::IU_PER_MILS, LAYER_DRAWINGSHEET, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_DRAWINGSHEET, KIGFX::SCH_RENDER_SETTINGS::LoadColors(), EESCHEMA_SETTINGS::m_Appearance, 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(), SCH_SCREEN::Schematic(), schIUScale, KIGFX::SCH_RENDER_SETTINGS::SetBackgroundColor(), KIGFX::RENDER_SETTINGS::SetDefaultFont(), EDA_DRAW_FRAME::SetDrawBgColor(), KIGFX::RENDER_SETTINGS::SetIsPrinting(), KIGFX::RENDER_SETTINGS::SetLayerColor(), 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: