KiCad PCB EDA Suite
common_plot_functions.cpp File Reference
#include <fctsys.h>
#include <base_struct.h>
#include <plotter.h>
#include <ws_painter.h>
#include <base_screen.h>
#include <gr_text.h>
#include <title_block.h>
#include "ws_draw_item.h"
#include "ws_data_item.h"
#include <wx/filename.h>

Go to the source code of this file.


wxString GetDefaultPlotExtension (PLOT_FORMAT aFormat)
 Returns the default plot extension for a format. More...
void PlotWorkSheet (PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor)

Function Documentation

◆ GetDefaultPlotExtension()

wxString GetDefaultPlotExtension ( PLOT_FORMAT  aFormat)

Returns the default plot extension for a format.

Definition at line 37 of file common_plot_functions.cpp.

38 {
39  switch( aFormat )
40  {
41  case PLOT_FORMAT::DXF:
45  case PLOT_FORMAT::PDF:
51  case PLOT_FORMAT::SVG:
53  default:
54  wxASSERT( false );
55  return wxEmptyString;
56  }
57 }
static wxString GetDefaultFileExtension()
Definition: plotter.h:866
static wxString GetDefaultFileExtension()
Definition: plotter.h:801
static wxString GetDefaultFileExtension()
Definition: plotter.h:948
static wxString GetDefaultFileExtension()
Definition: plotter.h:1179
static wxString GetDefaultFileExtension()
Definition: plotter.h:1457
static wxString GetDefaultFileExtension()
Definition: plotter.h:617

References DXF, GERBER, HPGL_PLOTTER::GetDefaultFileExtension(), PS_PLOTTER::GetDefaultFileExtension(), PDF_PLOTTER::GetDefaultFileExtension(), SVG_PLOTTER::GetDefaultFileExtension(), GERBER_PLOTTER::GetDefaultFileExtension(), DXF_PLOTTER::GetDefaultFileExtension(), HPGL, PDF, POST, and SVG.

Referenced by GENDRILL_WRITER_BASE::CreateMapFilesSet(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

◆ PlotWorkSheet()

void PlotWorkSheet ( PLOTTER plotter,
const PROJECT aProject,
const TITLE_BLOCK aTitleBlock,
const PAGE_INFO aPageInfo,
int  aSheetNumber,
int  aNumberOfSheets,
const wxString &  aSheetDesc,
const wxString &  aFilename,
COLOR4D  aColor 

Definition at line 60 of file common_plot_functions.cpp.

63 {
64  /* Note: Page sizes values are given in mils
65  */
66  double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
67  COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
68  int defaultPenWidth = plotter->RenderSettings()->GetDefaultPenWidth();
70  if( plotColor == COLOR4D::UNSPECIFIED )
71  plotColor = COLOR4D( RED );
73  plotter->SetColor( plotColor );
74  WS_DRAW_ITEM_LIST drawList;
76  // Print only a short filename, if aFilename is the full filename
77  wxFileName fn( aFilename );
79  // Prepare plot parameters
81  drawList.SetMilsToIUfactor( iusPerMil );
82  drawList.SetSheetNumber( aSheetNumber );
83  drawList.SetSheetCount( aNumberOfSheets );
84  drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
85  drawList.SetSheetName( aSheetDesc );
86  drawList.SetProject( aProject );
88  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
90  // Draw item list
91  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
92  {
95  switch( item->Type() )
96  {
97  case WSG_LINE_T:
98  {
99  WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
100  plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
101  plotter->MoveTo( line->GetStart() );
102  plotter->FinishTo( line->GetEnd() );
103  }
104  break;
106  case WSG_RECT_T:
107  {
108  WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
109  int penWidth = std::max( rect->GetPenWidth(), defaultPenWidth );
110  plotter->Rect( rect->GetStart(), rect->GetEnd(), NO_FILL, penWidth );
111  }
112  break;
114  case WSG_TEXT_T:
115  {
116  WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
117  int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
118  plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
119  text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
120  text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
121  text->IsMultilineAllowed() );
122  }
123  break;
125  case WSG_POLY_T:
126  {
128  int penWidth = std::max( poly->GetPenWidth(), defaultPenWidth );
129  std::vector<wxPoint> points;
131  for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
132  {
133  points.clear();
134  SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
136  for( int ii = 0; ii < outline.PointCount(); ii++ )
137  points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
139  plotter->PlotPoly( points, FILLED_SHAPE, penWidth );
140  }
141  }
142  break;
144  case WSG_BITMAP_T:
145  {
147  auto* bitmap = (WS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
149  if( bitmap->m_ImageBitmap == NULL )
150  break;
152  bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
154  }
155  break;
157  default:
158  wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
159  break;
160  }
161  }
162 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:211
void FinishTo(const wxPoint &pos)
Definition: plotter.h:267
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:70
bool IsBold() const
Definition: eda_text.h:183
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:213
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:429
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:408
int OutlineCount() const
Returns the number of outlines in the set
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:133
virtual void SetColor(COLOR4D color)=0
SHAPE_POLY_SET & GetPolygons()
Definition: ws_draw_item.h:175
Definition: ws_draw_item.h:480
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:416
double GetTextAngle() const
Definition: eda_text.h:174
Definition: ws_draw_item.h:470
Definition: color4d.h:44
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Function PlotPoly.
wxPoint GetPosition() const override
Definition: ws_draw_item.h:331
int PointCount() const
Function PointCount()
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:222
bool IsItalic() const
Definition: eda_text.h:180
const VECTOR2I & CPoint(int aIndex) const
Function Point()
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:119
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
#define NULL
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:454
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
const wxSize & GetTextSize() const
Definition: eda_text.h:239
const wxPoint & GetStart() const
Definition: ws_draw_item.h:131
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:436
double GetIUsPerDecimil() const
The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establ...
Definition: plotter.h:220
Definition: color4d.h:59
bool IsMultilineAllowed() const
Definition: eda_text.h:197
virtual int GetPenWidth() const
Definition: ws_draw_item.h:78
void MoveTo(const wxPoint &pos)
Definition: plotter.h:257
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
Definition: ws_draw_item.h:445
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
void SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:393
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:134
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
bool GetColorMode() const
Definition: plotter.h:144

References BLACK, WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), SHAPE_LINE_CHAIN::CPoint(), FILLED_SHAPE, PLOTTER::FinishTo(), PLOTTER::GetColorMode(), KIGFX::RENDER_SETTINGS::GetDefaultPenWidth(), EDA_TEXT::GetEffectiveTextPenWidth(), WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_RECT::GetEnd(), WS_DRAW_ITEM_LIST::GetFirst(), EDA_TEXT::GetHorizJustify(), PLOTTER::GetIUsPerDecimil(), WS_DRAW_ITEM_LIST::GetNext(), WS_DRAW_ITEM_BASE::GetPeer(), WS_DRAW_ITEM_BASE::GetPenWidth(), WS_DRAW_ITEM_POLYPOLYGONS::GetPolygons(), WS_DRAW_ITEM_BITMAP::GetPosition(), EDA_TEXT::GetShownText(), WS_DRAW_ITEM_LINE::GetStart(), WS_DRAW_ITEM_RECT::GetStart(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetVertJustify(), EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMultilineAllowed(), PLOTTER::MoveTo(), NO_FILL, NULL, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), PLOTTER::PlotPoly(), SHAPE_LINE_CHAIN::PointCount(), PLOTTER::Rect(), RED, PLOTTER::RenderSettings(), PLOTTER::SetColor(), PLOTTER::SetCurrentLineWidth(), WS_DRAW_ITEM_LIST::SetDefaultPenSize(), WS_DRAW_ITEM_LIST::SetFileName(), WS_DRAW_ITEM_LIST::SetMilsToIUfactor(), WS_DRAW_ITEM_LIST::SetProject(), WS_DRAW_ITEM_LIST::SetSheetCount(), WS_DRAW_ITEM_LIST::SetSheetName(), WS_DRAW_ITEM_LIST::SetSheetNumber(), PLOTTER::Text(), PLOTTER::USE_DEFAULT_LINE_WIDTH, WSG_BITMAP_T, WSG_LINE_T, WSG_POLY_T, WSG_RECT_T, WSG_TEXT_T, VECTOR2< T >::x, and VECTOR2< T >::y.