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

Constructor & Destructor Documentation

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

Definition at line 81 of file dialog_print_using_printer.cpp.

81  :
82  wxPrintout( aTitle )
83  {
84  wxASSERT( aParent != NULL );
85  m_parent = aParent;
86  }
SCH_EDIT_FRAME * m_parent

Member Function Documentation

void SCH_PRINTOUT::DrawPage ( SCH_SCREEN aScreen)

Definition at line 372 of file dialog_print_using_printer.cpp.

References SCH_SCREEN::Draw(), dummy(), GetDefaultLineThickness(), SCH_SCREEN::GetFileName(), SCH_SCREEN::GetPageSettings(), BASE_SCREEN::GetZoom(), GRForceBlackPen(), GRResetPenAndBrush(), IU_PER_MILS, BASE_SCREEN::m_DrawOrg, BASE_SCREEN::m_IsPrinting, BASE_SCREEN::m_StartVisu, MAX_VALUE, and BASE_SCREEN::SetZoom().

373 {
374  int oldZoom;
375  wxPoint tmp_startvisu;
376  wxSize pageSizeIU; // Page size in internal units
377  wxPoint old_org;
378  EDA_RECT oldClipBox;
379  wxRect fitRect;
380  wxDC* dc = GetDC();
381  auto panel = m_parent->GetCanvas();
382 
383  wxBusyCursor dummy;
384 
385  // Save current scale factor, offsets, and clip box.
386  tmp_startvisu = aScreen->m_StartVisu;
387  oldZoom = aScreen->GetZoom();
388  old_org = aScreen->m_DrawOrg;
389 
390  oldClipBox = *panel->GetClipBox();
391 
392  // Change clip box to print the whole page.
393  #define MAX_VALUE (INT_MAX/2) // MAX_VALUE is the max we can use in an integer
394  // and that allows calculations without overflow
395  panel->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( MAX_VALUE, MAX_VALUE ) ) );
396 
397  // Change scale factor and offset to print the whole page.
398  bool printReference = m_parent->GetPrintSheetReference();
399 
400  pageSizeIU = aScreen->GetPageSettings().GetSizeIU();
401  FitThisSizeToPaper( pageSizeIU );
402  fitRect = GetLogicalPaperRect();
403 
404  wxLogDebug( wxT( "Fit rectangle: x = %d, y = %d, w = %d, h = %d" ),
405  fitRect.x, fitRect.y, fitRect.width, fitRect.height );
406 
407  // When is the actual paper size does not match the schematic page
408  // size, the drawing is not perfectly centered on X or Y axis.
409  // Give a draw offset centers the schematic page on the paper draw area
410  // Because the sizes are fitted, only an Y or X offset is needed
411  // and both are 0 when sizes are identical.
412  // Y or Y offset is not null when the X/Y size ratio differs between
413  // the actual paper size and the schematic page
414  int xoffset = ( fitRect.width - pageSizeIU.x ) / 2;
415 
416  // For an obscure reason, OffsetLogicalOrigin creates issues,
417  // under some circumstances, when yoffset is not always null
418  // and changes from a page to another page
419  // This is only a workaround, not a fix
420  // see https://bugs.launchpad.net/kicad/+bug/1464773
421  // xoffset does not create issues.
422 #if 0 // FIX ME
423  int yoffset = ( fitRect.height - pageSizeIU.y ) / 2;
424 #else
425  // the Y centering will be not perfect, but this is less annoying
426  // than a blank page or a buggy centering
427  int yoffset = 0;
428 #endif
429  OffsetLogicalOrigin( xoffset, yoffset );
430 
431  GRResetPenAndBrush( dc );
432 
434  GRForceBlackPen( true );
435 
436  aScreen->m_IsPrinting = true;
437 
438  COLOR4D bgColor = m_parent->GetDrawBgColor();
439 
440  aScreen->Draw( panel, dc, (GR_DRAWMODE) 0 );
441 
442  if( printReference )
444  IU_PER_MILS, aScreen->GetFileName() );
445 
446  m_parent->SetDrawBgColor( bgColor );
447  aScreen->m_IsPrinting = false;
448  panel->SetClipBox( oldClipBox );
449 
450  GRForceBlackPen( false );
451 
452  aScreen->m_StartVisu = tmp_startvisu;
453  aScreen->m_DrawOrg = old_org;
454  aScreen->SetZoom( oldZoom );
455 }
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:123
#define MAX_VALUE
bool GetPrintMonochrome()
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:340
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
Definition: sch_screen.h:131
virtual void SetDrawBgColor(COLOR4D aColor)
Definition: draw_frame.h:380
bool GetPrintSheetReference()
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:198
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:375
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:204
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
SCH_DRAW_PANEL * GetCanvas() const override
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Draw all the items in the screen to aCanvas.
Definition: sch_screen.cpp:504
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
bool m_IsPrinting
Definition: base_screen.h:220
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.
Definition: eda_rect.h:44
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:183
#define IU_PER_MILS
Definition: plotter.cpp:134
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:126
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Draws on screen the page layout with the frame and the basic inscriptions.
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 333 of file dialog_print_using_printer.cpp.

References SCH_SHEET::CountSheets(), and g_RootSheet.

334 {
335  *minPage = *selPageFrom = 1;
336  *maxPage = *selPageTo = g_RootSheet->CountSheets();
337 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets. ...
Definition: sch_sheet.cpp:640
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
bool SCH_PRINTOUT::HasPage ( int  page)
override

Definition at line 340 of file dialog_print_using_printer.cpp.

References SCH_SHEET::CountSheets(), and g_RootSheet.

341 {
342  return g_RootSheet->CountSheets() >= pageNum;
343 }
int CountSheets()
Count the number of sheets found in "this" sheet includeing all of the subsheets. ...
Definition: sch_sheet.cpp:640
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
bool SCH_PRINTOUT::OnBeginDocument ( int  startPage,
int  endPage 
)
override

Definition at line 346 of file dialog_print_using_printer.cpp.

347 {
348  if( !wxPrintout::OnBeginDocument( startPage, endPage ) )
349  return false;
350 
351 #ifdef __WXDEBUG__
352  wxLogDebug( wxT( "Printer name: " ) +
353  m_parent->GetPageSetupData().GetPrintData().GetPrinterName() );
354  wxLogDebug( wxT( "Paper ID: %d" ),
355  m_parent->GetPageSetupData().GetPrintData().GetPaperId() );
356  wxLogDebug( wxT( "Color: %d" ),
357  (int)m_parent->GetPageSetupData().GetPrintData().GetColour() );
358  wxLogDebug( wxT( "Monochrome: %d" ), m_parent->GetPrintMonochrome() );
359  wxLogDebug( wxT( "Orientation: %d:" ),
360  m_parent->GetPageSetupData().GetPrintData().GetOrientation() );
361  wxLogDebug( wxT( "Quality: %d"),
362  m_parent->GetPageSetupData().GetPrintData().GetQuality() );
363 #endif
364 
365  return true;
366 }
bool GetPrintMonochrome()
SCH_EDIT_FRAME * m_parent
wxPageSetupDialogData & GetPageSetupData()
bool SCH_PRINTOUT::OnPrintPage ( int  page)
override

Definition at line 303 of file dialog_print_using_printer.cpp.

References CYAN, g_RootSheet, and SCH_SHEET_PATH::UpdateAllScreenReferences().

304 {
305  SCH_SHEET_LIST sheetList( g_RootSheet );
306 
307  wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false,
308  wxT( "Cannot print invalid page number." ) );
309 
310  wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false,
311  wxT( "Cannot print page with NULL screen." ) );
312 
313  wxString msg;
314  msg.Printf( _( "Print page %d" ), page );
316  m_parent->AppendMsgPanel( msg, wxEmptyString, CYAN );
317 
318  SCH_SCREEN* screen = m_parent->GetScreen();
319  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
320  m_parent->SetCurrentSheet( sheetList[ page - 1 ] );
323  screen = m_parent->GetCurrentSheet().LastScreen();
324  DrawPage( screen );
325  m_parent->SetCurrentSheet( oldsheetpath );
328 
329  return true;
330 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
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
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_EDIT_FRAME * m_parent
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
SCH_SHEET_PATH & GetCurrentSheet()
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.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void DrawPage(SCH_SCREEN *aScreen)
void ClearMsgPanel(void)
Clear all messages from the message panel.

Member Data Documentation

SCH_EDIT_FRAME* SCH_PRINTOUT::m_parent
private

Definition at line 78 of file dialog_print_using_printer.cpp.


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