KiCad PCB EDA Suite
PLOT_CONTROLLER Class Reference

Batch plotter state object. More...

#include <plotcontroller.h>

Public Member Functions

 PLOT_CONTROLLER (BOARD *aBoard)
 Batch plotter constructor, nothing interesting here. More...
 
 ~PLOT_CONTROLLER ()
 Ensure that the last plot is closed. More...
 
PCB_PLOT_PARAMSGetPlotOptions ()
 Accessor to the plot parameters and options. More...
 
void SetLayer (int aLayer)
 
int GetLayer ()
 
bool IsPlotOpen () const
 
void ClosePlot ()
 Close the current plot, nothing happens if it isn't open. More...
 
bool OpenPlotfile (const wxString &aSuffix, PLOT_FORMAT aFormat, const wxString &aSheetName=wxEmptyString, const wxString &aSheetPath=wxEmptyString)
 Open a new plotfile; works as a factory for plotter objects/. More...
 
bool PlotLayer ()
 Plot a single layer on the current plotfile m_plotLayer is the layer to plot. More...
 
const wxString GetPlotFileName ()
 
const wxString GetPlotDirName ()
 
void SetColorMode (bool aColorMode)
 Choose color or bland and white plot mode. More...
 
bool GetColorMode ()
 

Private Attributes

int m_plotLayer
 
PCB_PLOT_PARAMS m_plotOptions
 
PLOTTERm_plotter
 This is the plotter object; it starts NULL and become instantiated when a plotfile is. More...
 
BOARDm_board
 
wxFileName m_plotFile
 

Detailed Description

Batch plotter state object.

Keeps the plot options and handles multiple plot requests. Useful in Python scripts.

Definition at line 44 of file plotcontroller.h.

Constructor & Destructor Documentation

◆ PLOT_CONTROLLER()

PLOT_CONTROLLER::PLOT_CONTROLLER ( BOARD aBoard)

Batch plotter constructor, nothing interesting here.

Definition at line 393 of file pcbplot.cpp.

394{
395 m_plotter = nullptr;
396 m_board = aBoard;
398}
PLOTTER * m_plotter
This is the plotter object; it starts NULL and become instantiated when a plotfile is.
@ UNDEFINED_LAYER
Definition: layer_ids.h:60

References m_board, m_plotLayer, m_plotter, and UNDEFINED_LAYER.

◆ ~PLOT_CONTROLLER()

PLOT_CONTROLLER::~PLOT_CONTROLLER ( )

Ensure that the last plot is closed.

Definition at line 401 of file pcbplot.cpp.

402{
403 ClosePlot();
404}
void ClosePlot()
Close the current plot, nothing happens if it isn't open.
Definition: pcbplot.cpp:411

References ClosePlot().

Member Function Documentation

◆ ClosePlot()

void PLOT_CONTROLLER::ClosePlot ( )

Close the current plot, nothing happens if it isn't open.

Definition at line 411 of file pcbplot.cpp.

412{
413 LOCALE_IO toggle;
414
415 if( m_plotter )
416 {
418
419 delete m_plotter->RenderSettings();
420 delete m_plotter;
421
422 m_plotter = nullptr;
423 }
424}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
virtual bool EndPlot()=0
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:141

References PLOTTER::EndPlot(), m_plotter, and PLOTTER::RenderSettings().

Referenced by OpenPlotfile(), and ~PLOT_CONTROLLER().

◆ GetColorMode()

bool PLOT_CONTROLLER::GetColorMode ( )
Returns
true if the current plot color mode is color or false if the current plot color mode is black and white.

Definition at line 506 of file pcbplot.cpp.

507{
508 if( !m_plotter )
509 return false;
510
511 return m_plotter->GetColorMode();
512}
bool GetColorMode() const
Definition: plotter.h:138

References PLOTTER::GetColorMode(), and m_plotter.

◆ GetLayer()

int PLOT_CONTROLLER::GetLayer ( )
inline

Definition at line 61 of file plotcontroller.h.

61{ return m_plotLayer; }

References m_plotLayer.

Referenced by OpenPlotfile(), and PlotLayer().

◆ GetPlotDirName()

const wxString PLOT_CONTROLLER::GetPlotDirName ( )
inline
Returns
the current plot full filename, set by OpenPlotfile

Definition at line 99 of file plotcontroller.h.

99{ return m_plotFile.GetPathWithSep(); }
wxFileName m_plotFile

References m_plotFile.

◆ GetPlotFileName()

const wxString PLOT_CONTROLLER::GetPlotFileName ( )
inline
Returns
the current plot full filename, set by OpenPlotfile

Definition at line 94 of file plotcontroller.h.

94{ return m_plotFile.GetFullPath(); }

References m_plotFile.

◆ GetPlotOptions()

PCB_PLOT_PARAMS & PLOT_CONTROLLER::GetPlotOptions ( )
inline

Accessor to the plot parameters and options.

Definition at line 58 of file plotcontroller.h.

58{ return m_plotOptions; }
PCB_PLOT_PARAMS m_plotOptions

References m_plotOptions.

Referenced by OpenPlotfile(), and PlotLayer().

◆ IsPlotOpen()

bool PLOT_CONTROLLER::IsPlotOpen ( ) const
inline
Returns
true if a plotter is initialized and can be used.

Definition at line 67 of file plotcontroller.h.

67{ return m_plotter != nullptr; }

References m_plotter.

◆ OpenPlotfile()

bool PLOT_CONTROLLER::OpenPlotfile ( const wxString &  aSuffix,
PLOT_FORMAT  aFormat,
const wxString &  aSheetName = wxEmptyString,
const wxString &  aSheetPath = wxEmptyString 
)

Open a new plotfile; works as a factory for plotter objects/.

Parameters
aSuffixis a string added to the base filename (derived from the board filename) to identify the plot file.
aFormatis the plot file format identifier.
aSheetNameis the text to be displayed in the title block that replaces ${SHEETNAME}
aSheetPathis the text to be displayed in the title block that replaces ${SHEETPATH}

Definition at line 427 of file pcbplot.cpp.

429{
430 LOCALE_IO toggle;
431
432 // Save the current format: sadly some plot routines depends on this but the main reason
433 // is that the StartPlot method uses it to dispatch the plotter creation
434 GetPlotOptions().SetFormat( aFormat );
435
436 // Ensure that the previous plot is closed
437 ClosePlot();
438
439 // Now compute the full filename for the output and start the plot (after ensuring the
440 // output directory is OK).
441
442 std::function<bool( wxString* )> textResolver =
443 [&]( wxString* token ) -> bool
444 {
445 // Handles m_board->GetTitleBlock() *and* m_board->GetProject()
446 return m_board->ResolveTextVar( token, 0 );
447 };
448
449 wxString outputDirName = GetPlotOptions().GetOutputDirectory();
450 outputDirName = ExpandTextVars( outputDirName, &textResolver, nullptr, nullptr );
451 outputDirName = ExpandEnvVarSubstitutions( outputDirName, nullptr );
452
453 wxFileName outputDir = wxFileName::DirName( outputDirName );
454 wxString boardFilename = m_board->GetFileName();
455
456 if( EnsureFileDirectoryExists( &outputDir, boardFilename ) )
457 {
458 // outputDir contains now the full path of plot files
459 m_plotFile = boardFilename;
460 m_plotFile.SetPath( outputDir.GetPath() );
461 wxString fileExt = GetDefaultPlotExtension( aFormat );
462
463 // Gerber format *can* use layer-specific file extensions (this is no longer best
464 // practice as the official file ext is now .gbr).
465 if( GetPlotOptions().GetFormat() == PLOT_FORMAT::GERBER
466 && GetPlotOptions().GetUseGerberProtelExtensions() )
467 {
468 fileExt = GetGerberProtelExtension( GetLayer() );
469 }
470
471 // Build plot filenames from the board name and layer names:
472 BuildPlotFileName( &m_plotFile, outputDir.GetPath(), aSuffix, fileExt );
473
475 m_plotFile.GetFullPath(), aSheetName, aSheetPath );
476 }
477
478 return ( m_plotter != nullptr );
479}
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: board.cpp:310
const wxString & GetFileName() const
Definition: board.h:302
wxString GetOutputDirectory() const
void SetFormat(PLOT_FORMAT aFormat)
PCB_PLOT_PARAMS & GetPlotOptions()
Accessor to the plot parameters and options.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:267
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
Definition: common.cpp:295
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:57
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Returns the default plot extension for a format.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
const wxString GetGerberProtelExtension(int aLayer)
Definition: pcbplot.cpp:42
void BuildPlotFileName(wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
Complete a plot filename.
Definition: pcbplot.cpp:361
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aFullFileName, const wxString &aSheetName, const wxString &aSheetPath)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...

References BuildPlotFileName(), ClosePlot(), EnsureFileDirectoryExists(), ExpandEnvVarSubstitutions(), ExpandTextVars(), GERBER, GetDefaultPlotExtension(), BOARD::GetFileName(), GetGerberProtelExtension(), GetLayer(), PCB_PLOT_PARAMS::GetOutputDirectory(), GetPlotOptions(), m_board, m_plotFile, m_plotter, BOARD::ResolveTextVar(), PCB_PLOT_PARAMS::SetFormat(), StartPlotBoard(), and ToLAYER_ID().

◆ PlotLayer()

bool PLOT_CONTROLLER::PlotLayer ( )

Plot a single layer on the current plotfile m_plotLayer is the layer to plot.

Definition at line 482 of file pcbplot.cpp.

483{
484 LOCALE_IO toggle;
485
486 // No plot open, nothing to do...
487 if( !m_plotter )
488 return false;
489
490 // Fully delegated to the parent
492
493 return true;
494}
void PlotOneBoardLayer(BOARD *aBoard, PLOTTER *aPlotter, PCB_LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
Plot one copper or technical layer.

References GetLayer(), GetPlotOptions(), m_board, m_plotter, PlotOneBoardLayer(), and ToLAYER_ID().

◆ SetColorMode()

void PLOT_CONTROLLER::SetColorMode ( bool  aColorMode)

Choose color or bland and white plot mode.

Parameters
aColorModeset to true to activate the plot color mode or false for black and white.

Definition at line 497 of file pcbplot.cpp.

498{
499 if( !m_plotter )
500 return;
501
502 m_plotter->SetColorMode( aColorMode );
503}
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:137

References m_plotter, and PLOTTER::SetColorMode().

◆ SetLayer()

void PLOT_CONTROLLER::SetLayer ( int  aLayer)
inline

Definition at line 60 of file plotcontroller.h.

60{ m_plotLayer = aLayer; }

References m_plotLayer.

Member Data Documentation

◆ m_board

BOARD* PLOT_CONTROLLER::m_board
private

Definition at line 122 of file plotcontroller.h.

Referenced by OpenPlotfile(), PLOT_CONTROLLER(), and PlotLayer().

◆ m_plotFile

wxFileName PLOT_CONTROLLER::m_plotFile
private

Definition at line 123 of file plotcontroller.h.

Referenced by GetPlotDirName(), GetPlotFileName(), and OpenPlotfile().

◆ m_plotLayer

int PLOT_CONTROLLER::m_plotLayer
private

Definition at line 115 of file plotcontroller.h.

Referenced by GetLayer(), PLOT_CONTROLLER(), and SetLayer().

◆ m_plotOptions

PCB_PLOT_PARAMS PLOT_CONTROLLER::m_plotOptions
private

Definition at line 116 of file plotcontroller.h.

Referenced by GetPlotOptions().

◆ m_plotter

PLOTTER* PLOT_CONTROLLER::m_plotter
private

This is the plotter object; it starts NULL and become instantiated when a plotfile is.

Definition at line 120 of file plotcontroller.h.

Referenced by ClosePlot(), GetColorMode(), IsPlotOpen(), OpenPlotfile(), PLOT_CONTROLLER(), PlotLayer(), and SetColorMode().


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