KiCad PCB EDA Suite
GRAPHICS_IMPORTER Class Referenceabstract

Interface that creates objects representing shapes for a given data model. More...

#include <graphics_importer.h>

Inheritance diagram for GRAPHICS_IMPORTER:
GRAPHICS_IMPORTER_BUFFER GRAPHICS_IMPORTER_PCBNEW GRAPHICS_IMPORTER_BOARD GRAPHICS_IMPORTER_FOOTPRINT

Public Member Functions

 GRAPHICS_IMPORTER ()
 
virtual ~GRAPHICS_IMPORTER ()
 
void SetPlugin (std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > aPlugin)
 Set the import plugin used to obtain shapes from a file. More...
 
bool Load (const wxString &aFileName)
 Load file and get its basic data. More...
 
bool Import (double aScale=1.0)
 Import shapes from loaded file. More...
 
const wxString & GetMessages () const
 Collect warning and error messages after loading/importing. More...
 
double GetImageWidthMM () const
 Get original image Width. More...
 
double GetImageHeightMM () const
 Get original image Height. More...
 
void SetLineWidthMM (double aWidth)
 Set the line width for the imported outlines (in mm). More...
 
double GetLineWidthMM () const
 Return the line width used for importing the outlines (in mm). More...
 
double GetScale () const
 
const VECTOR2DGetImportOffsetMM () const
 
void SetImportOffsetMM (const VECTOR2D &aOffset)
 Set the offset in millimeters to add to coordinates when importing graphic items. More...
 
void SetScale (double aScale)
 Set the scale factor affecting the imported shapes. More...
 
double GetMillimeterToIuFactor ()
 
double ImportScalingFactor () const
 
std::list< std::unique_ptr< EDA_ITEM > > & GetItems ()
 Return the list of objects representing the imported shapes. More...
 
virtual void AddLine (const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
 Create an object representing a line segment. More...
 
virtual void AddCircle (const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)=0
 Create an object representing a circle. More...
 
virtual void AddArc (const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)=0
 Create an object representing an arc. More...
 
virtual void AddPolygon (const std::vector< VECTOR2D > &aVertices, double aWidth)=0
 
virtual void AddText (const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify)=0
 Create an object representing a text. More...
 
virtual void AddSpline (const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
 Create an object representing an arc. More...
 

Static Public Attributes

static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1
 

Protected Member Functions

void addItem (std::unique_ptr< EDA_ITEM > aItem)
 < Add an item to the imported shapes list. More...
 

Protected Attributes

double m_millimeterToIu
 Offset (in mm) for imported coordinates. More...
 
VECTOR2D m_offsetCoordmm
 

Private Attributes

std::list< std::unique_ptr< EDA_ITEM > > m_items
 < List of imported items More...
 
std::unique_ptr< GRAPHICS_IMPORT_PLUGINm_plugin
 Total image width. More...
 
double m_originalWidth
 Total image Height;. More...
 
double m_originalHeight
 
double m_scale
 Scale factor applied to the imported graphics. More...
 
double m_lineWidth
 

Detailed Description

Interface that creates objects representing shapes for a given data model.

Definition at line 45 of file graphics_importer.h.

Constructor & Destructor Documentation

◆ GRAPHICS_IMPORTER()

GRAPHICS_IMPORTER::GRAPHICS_IMPORTER ( )

Definition at line 29 of file graphics_importer.cpp.

30 {
31  m_millimeterToIu = 1.0;
33  m_scale = 1.0;
34  m_originalWidth = 0.0;
35  m_originalHeight = 0.0;
36 }
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
double m_millimeterToIu
Offset (in mm) for imported coordinates.
double m_originalWidth
Total image Height;.
double m_scale
Scale factor applied to the imported graphics.

References DEFAULT_LINE_WIDTH_DFX, m_lineWidth, m_millimeterToIu, m_originalHeight, m_originalWidth, and m_scale.

◆ ~GRAPHICS_IMPORTER()

virtual GRAPHICS_IMPORTER::~GRAPHICS_IMPORTER ( )
inlinevirtual

Definition at line 50 of file graphics_importer.h.

51  {
52  }

Member Function Documentation

◆ AddArc()

virtual void GRAPHICS_IMPORTER::AddArc ( const VECTOR2D aCenter,
const VECTOR2D aStart,
double  aAngle,
double  aWidth 
)
pure virtual

Create an object representing an arc.

Parameters
aCenteris the arc center point expressed in mm.
aStartis the arc arm end point expressed in mm. Its length is the arc radius.
aAngleis the arc angle expressed in degrees.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implemented in GRAPHICS_IMPORTER_BUFFER, and GRAPHICS_IMPORTER_PCBNEW.

Referenced by IMPORTED_ARC::ImportTo().

◆ AddCircle()

virtual void GRAPHICS_IMPORTER::AddCircle ( const VECTOR2D aCenter,
double  aRadius,
double  aWidth,
bool  aFilled 
)
pure virtual

Create an object representing a circle.

Parameters
aCenteris the circle center point expressed in mm.
aRadiusis the circle radius expressed in mm.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implemented in GRAPHICS_IMPORTER_BUFFER, and GRAPHICS_IMPORTER_PCBNEW.

Referenced by IMPORTED_CIRCLE::ImportTo().

◆ addItem()

void GRAPHICS_IMPORTER::addItem ( std::unique_ptr< EDA_ITEM aItem)
inlineprotected

< Add an item to the imported shapes list.

factor to convert millimeters to Internal Units

Definition at line 253 of file graphics_importer.h.

References m_items.

Referenced by GRAPHICS_IMPORTER_PCBNEW::AddArc(), GRAPHICS_IMPORTER_PCBNEW::AddCircle(), GRAPHICS_IMPORTER_PCBNEW::AddLine(), GRAPHICS_IMPORTER_PCBNEW::AddPolygon(), GRAPHICS_IMPORTER_PCBNEW::AddSpline(), and GRAPHICS_IMPORTER_PCBNEW::AddText().

◆ AddLine()

virtual void GRAPHICS_IMPORTER::AddLine ( const VECTOR2D aOrigin,
const VECTOR2D aEnd,
double  aWidth 
)
pure virtual

Create an object representing a line segment.

Parameters
aOriginis the segment origin point expressed in mm.
aEndis the segment end point expressed in mm.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implemented in GRAPHICS_IMPORTER_BUFFER, and GRAPHICS_IMPORTER_PCBNEW.

Referenced by SVG_IMPORT_PLUGIN::DrawLineSegments(), and IMPORTED_LINE::ImportTo().

◆ AddPolygon()

virtual void GRAPHICS_IMPORTER::AddPolygon ( const std::vector< VECTOR2D > &  aVertices,
double  aWidth 
)
pure virtual

◆ AddSpline()

virtual void GRAPHICS_IMPORTER::AddSpline ( const VECTOR2D aStart,
const VECTOR2D aBezierControl1,
const VECTOR2D aBezierControl2,
const VECTOR2D aEnd,
double  aWidth 
)
pure virtual

Create an object representing an arc.

Parameters
aStartis the curve start point expressed in mm.
aBezierControl1is the first Bezier control point expressed in mm.
aBezierControl2is the second Bezier control point expressed in mm.
aEndis the curve end point expressed in mm.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implemented in GRAPHICS_IMPORTER_BUFFER, and GRAPHICS_IMPORTER_PCBNEW.

Referenced by IMPORTED_SPLINE::ImportTo().

◆ AddText()

virtual void GRAPHICS_IMPORTER::AddText ( const VECTOR2D aOrigin,
const wxString &  aText,
double  aHeight,
double  aWidth,
double  aThickness,
double  aOrientation,
EDA_TEXT_HJUSTIFY_T  aHJustify,
EDA_TEXT_VJUSTIFY_T  aVJustify 
)
pure virtual

Create an object representing a text.

Parameters
aOriginis the text position.
aTextis the displayed text.
aHeightis the text height expressed in mm.
aWidthis the text width expressed in mm.
aOrientationis the text orientation angle expressed in degrees.
aHJustifyis the text horizontal justification.
aVJustifyis the text vertical justification.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implemented in GRAPHICS_IMPORTER_BUFFER, and GRAPHICS_IMPORTER_PCBNEW.

Referenced by IMPORTED_TEXT::ImportTo().

◆ GetImageHeightMM()

double GRAPHICS_IMPORTER::GetImageHeightMM ( ) const
inline

Get original image Height.

Returns
Height of the loaded image in mm.

Definition at line 107 of file graphics_importer.h.

108  {
109  return m_originalHeight;
110  }

References m_originalHeight.

◆ GetImageWidthMM()

double GRAPHICS_IMPORTER::GetImageWidthMM ( ) const
inline

Get original image Width.

Returns
Width of the loaded image in mm.

Definition at line 97 of file graphics_importer.h.

98  {
99  return m_originalWidth;
100  }
double m_originalWidth
Total image Height;.

References m_originalWidth.

◆ GetImportOffsetMM()

const VECTOR2D& GRAPHICS_IMPORTER::GetImportOffsetMM ( ) const
inline
Returns
the offset in millimeters to add to coordinates when importing graphic items.

Definition at line 139 of file graphics_importer.h.

140  {
141  return m_offsetCoordmm;
142  }

References m_offsetCoordmm.

Referenced by GRAPHICS_IMPORTER_PCBNEW::MapCoordinate().

◆ GetItems()

std::list<std::unique_ptr<EDA_ITEM> >& GRAPHICS_IMPORTER::GetItems ( )
inline

Return the list of objects representing the imported shapes.

Default line thickness (in mm)

Definition at line 181 of file graphics_importer.h.

References m_items.

◆ GetLineWidthMM()

double GRAPHICS_IMPORTER::GetLineWidthMM ( ) const
inline

Return the line width used for importing the outlines (in mm).

Definition at line 123 of file graphics_importer.h.

124  {
125  return m_lineWidth;
126  }

References m_lineWidth.

Referenced by GRAPHICS_IMPORTER_PCBNEW::MapLineWidth(), and DXF_IMPORT_PLUGIN::SetImporter().

◆ GetMessages()

const wxString& GRAPHICS_IMPORTER::GetMessages ( ) const
inline

Collect warning and error messages after loading/importing.

Returns
the list of messages in one string. Each message ends by '
'

Definition at line 87 of file graphics_importer.h.

88  {
89  return m_plugin->GetMessages();
90  }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.

References m_plugin.

◆ GetMillimeterToIuFactor()

double GRAPHICS_IMPORTER::GetMillimeterToIuFactor ( )
inline
Returns
the conversion factor from mm to internal unit

Definition at line 165 of file graphics_importer.h.

166  {
167  return m_millimeterToIu;
168  }
double m_millimeterToIu
Offset (in mm) for imported coordinates.

References m_millimeterToIu.

◆ GetScale()

double GRAPHICS_IMPORTER::GetScale ( ) const
inline
Returns
the scale factor affecting the imported shapes.

Definition at line 131 of file graphics_importer.h.

132  {
133  return m_scale;
134  }
double m_scale
Scale factor applied to the imported graphics.

References m_scale.

◆ Import()

bool GRAPHICS_IMPORTER::Import ( double  aScale = 1.0)

Import shapes from loaded file.

It is important to have the file loaded before importing.

Parameters
aScaleallow import graphic items with a non 1:1 import ratio aScale = 1.0 to import graphics with their actual size.

Definition at line 54 of file graphics_importer.cpp.

55 {
56  if( !m_plugin )
57  {
58  wxASSERT_MSG( false, "Plugin must be set before import." );
59  return false;
60  }
61 
62  SetScale( aScale );
63 
64  m_plugin->SetImporter( this );
65 
66  bool success = false;
67 
68  try
69  {
70  success = m_plugin->Import();
71  }
72  catch( const std::bad_alloc& )
73  {
74  // Memory exhaustion
75  // TODO report back an error message
76  return false;
77  }
78 
79  return success;
80 }
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.

References m_plugin, and SetScale().

◆ ImportScalingFactor()

double GRAPHICS_IMPORTER::ImportScalingFactor ( ) const
inline
Returns
the overall scale factor to convert the imported shapes dimension to mm.

Definition at line 173 of file graphics_importer.h.

174  {
175  return m_scale * m_millimeterToIu;
176  }
double m_millimeterToIu
Offset (in mm) for imported coordinates.
double m_scale
Scale factor applied to the imported graphics.

References m_millimeterToIu, and m_scale.

Referenced by GRAPHICS_IMPORTER_PCBNEW::AddText(), GRAPHICS_IMPORTER_PCBNEW::MapCoordinate(), and GRAPHICS_IMPORTER_PCBNEW::MapLineWidth().

◆ Load()

bool GRAPHICS_IMPORTER::Load ( const wxString &  aFileName)

Load file and get its basic data.

Definition at line 39 of file graphics_importer.cpp.

40 {
41  m_items.clear();
42 
43  if( !m_plugin )
44  {
45  wxASSERT_MSG( false, "Plugin must be set before load." );
46  return false;
47  }
48 
49  m_plugin->SetImporter( this );
50 
51  return m_plugin->Load( aFileName );
52 }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.
std::list< std::unique_ptr< EDA_ITEM > > m_items
< List of imported items

References m_items, and m_plugin.

◆ SetImportOffsetMM()

void GRAPHICS_IMPORTER::SetImportOffsetMM ( const VECTOR2D aOffset)
inline

Set the offset in millimeters to add to coordinates when importing graphic items.

Definition at line 147 of file graphics_importer.h.

148  {
149  m_offsetCoordmm = aOffset;
150  }

References m_offsetCoordmm.

◆ SetLineWidthMM()

void GRAPHICS_IMPORTER::SetLineWidthMM ( double  aWidth)
inline

Set the line width for the imported outlines (in mm).

Definition at line 115 of file graphics_importer.h.

116  {
117  m_lineWidth = aWidth;
118  }

References m_lineWidth.

◆ SetPlugin()

void GRAPHICS_IMPORTER::SetPlugin ( std::unique_ptr< GRAPHICS_IMPORT_PLUGIN aPlugin)
inline

Set the import plugin used to obtain shapes from a file.

Definition at line 57 of file graphics_importer.h.

58  {
59  m_plugin = std::move( aPlugin );
60 
61  if( m_plugin )
62  m_plugin->SetImporter( this );
63  }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.

References m_plugin.

◆ SetScale()

void GRAPHICS_IMPORTER::SetScale ( double  aScale)
inline

Set the scale factor affecting the imported shapes.

This allows conversion between imported shapes units and millimeters.

Definition at line 157 of file graphics_importer.h.

158  {
159  m_scale = aScale;
160  }
double m_scale
Scale factor applied to the imported graphics.

References m_scale.

Referenced by Import().

Member Data Documentation

◆ DEFAULT_LINE_WIDTH_DFX

constexpr unsigned int GRAPHICS_IMPORTER::DEFAULT_LINE_WIDTH_DFX = 1
static

Definition at line 187 of file graphics_importer.h.

Referenced by GRAPHICS_IMPORTER().

◆ m_items

std::list<std::unique_ptr<EDA_ITEM> > GRAPHICS_IMPORTER::m_items
private

< List of imported items

Plugin used to load a file

Definition at line 266 of file graphics_importer.h.

Referenced by addItem(), GetItems(), and Load().

◆ m_lineWidth

double GRAPHICS_IMPORTER::m_lineWidth
private

Definition at line 285 of file graphics_importer.h.

Referenced by GetLineWidthMM(), GRAPHICS_IMPORTER(), and SetLineWidthMM().

◆ m_millimeterToIu

double GRAPHICS_IMPORTER::m_millimeterToIu
protected

Offset (in mm) for imported coordinates.

Definition at line 259 of file graphics_importer.h.

Referenced by GetMillimeterToIuFactor(), GRAPHICS_IMPORTER(), GRAPHICS_IMPORTER_PCBNEW::GRAPHICS_IMPORTER_PCBNEW(), and ImportScalingFactor().

◆ m_offsetCoordmm

VECTOR2D GRAPHICS_IMPORTER::m_offsetCoordmm
protected

Definition at line 262 of file graphics_importer.h.

Referenced by GetImportOffsetMM(), and SetImportOffsetMM().

◆ m_originalHeight

double GRAPHICS_IMPORTER::m_originalHeight
private

Definition at line 275 of file graphics_importer.h.

Referenced by GetImageHeightMM(), and GRAPHICS_IMPORTER().

◆ m_originalWidth

double GRAPHICS_IMPORTER::m_originalWidth
private

Total image Height;.

Definition at line 272 of file graphics_importer.h.

Referenced by GetImageWidthMM(), and GRAPHICS_IMPORTER().

◆ m_plugin

std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> GRAPHICS_IMPORTER::m_plugin
private

Total image width.

Definition at line 269 of file graphics_importer.h.

Referenced by GetMessages(), Import(), Load(), and SetPlugin().

◆ m_scale

double GRAPHICS_IMPORTER::m_scale
private

Scale factor applied to the imported graphics.

1.0 does not change the size of imported items scale < 1.0 reduce the size of imported itemsDefault line thickness for the imported graphics

Definition at line 282 of file graphics_importer.h.

Referenced by GetScale(), GRAPHICS_IMPORTER(), ImportScalingFactor(), and SetScale().


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