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_MODULE

Public Member Functions

 GRAPHICS_IMPORTER ()
 
virtual ~GRAPHICS_IMPORTER ()
 
void SetPlugin (std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > aPlugin)
 Sets 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)
 Imports shapes from loaded file. More...
 
const std::string & GetMessages () const
 collect warning and error messages after loading/importing. More...
 
double GetImageWidthMM () const
 Get original image Wigth. More...
 
double GetImageHeightMM () const
 Get original image Height. More...
 
void SetLineWidthMM (double aWidth)
 Sets the line width for the imported outlines (in mm). More...
 
double GetLineWidthMM () const
 Returns 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 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 ()
 @breif Returns the list of objects representing the imported shapes. More...
 
virtual void AddLine (const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
 Creates an object representing a line segment. More...
 
virtual void AddCircle (const VECTOR2D &aCenter, double aRadius, double aWidth)=0
 Creates an object representing a circle. More...
 
virtual void AddArc (const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)=0
 Creates 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
 Creates an object representing a text. More...
 
virtual void AddSpline (const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
 Creates an object representing an arc. More...
 

Static Public Attributes

static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1
 

Default line thickness (in mm)

More...
 

Protected Member Functions

void addItem (std::unique_ptr< EDA_ITEM > aItem)
 

Adds an item to the imported shapes list.

More...
 

Protected Attributes

double m_millimeterToIu
 

factor to convert millimeters to Internal Units

More...
 
VECTOR2D m_offsetCoordmm
 

Offset (in mm) for imported coordinates

More...
 

Private Attributes

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

List of imported items

More...
 
std::unique_ptr< GRAPHICS_IMPORT_PLUGINm_plugin
 

Plugin used to load a file

More...
 
double m_originalWidth
 

Total image width

More...
 
double m_originalHeight
 

Total image Height;

More...
 
double m_lineWidth
 

Default line thickness for the imported graphics

More...
 
double m_scale
 Scale factor applied to the imported graphics. More...
 

Detailed Description

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

Definition at line 43 of file graphics_importer.h.

Constructor & Destructor Documentation

◆ GRAPHICS_IMPORTER()

GRAPHICS_IMPORTER::GRAPHICS_IMPORTER ( )

Definition at line 28 of file graphics_importer.cpp.

29 {
30  m_millimeterToIu = 1.0;
32  m_scale = 1.0;
33  m_originalWidth = 0.0;
34  m_originalHeight = 0.0;
35 }
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
Default line thickness (in mm)
double m_millimeterToIu
factor to convert millimeters to Internal Units
double m_lineWidth
Default line thickness for the imported graphics
double m_originalWidth
Total image width
double m_scale
Scale factor applied to the imported graphics.
double m_originalHeight
Total image Height;

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 48 of file graphics_importer.h.

49  {
50  }

Member Function Documentation

◆ AddArc()

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

Creates 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 
)
pure virtual

Creates 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

Adds an item to the imported shapes list.

Definition at line 240 of file graphics_importer.h.

241  {
242  m_items.emplace_back( std::move( aItem ) );
243  }
std::list< std::unique_ptr< EDA_ITEM > > m_items
List of imported items

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

Creates 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

Creates 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

Creates 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 102 of file graphics_importer.h.

103  {
104  return m_originalHeight;
105  }
double m_originalHeight
Total image Height;

References m_originalHeight.

◆ GetImageWidthMM()

double GRAPHICS_IMPORTER::GetImageWidthMM ( ) const
inline

Get original image Wigth.

Returns
Width of the loaded image in mm.

Definition at line 92 of file graphics_importer.h.

93  {
94  return m_originalWidth;
95  }
double m_originalWidth
Total image width

References m_originalWidth.

◆ GetImportOffsetMM()

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

Definition at line 134 of file graphics_importer.h.

135  {
136  return m_offsetCoordmm;
137  }
VECTOR2D m_offsetCoordmm
Offset (in mm) for imported coordinates

References m_offsetCoordmm.

Referenced by GRAPHICS_IMPORTER_PCBNEW::MapCoordinate().

◆ GetItems()

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

@breif Returns the list of objects representing the imported shapes.

Definition at line 174 of file graphics_importer.h.

175  {
176  return m_items;
177  }
std::list< std::unique_ptr< EDA_ITEM > > m_items
List of imported items

References m_items.

◆ GetLineWidthMM()

double GRAPHICS_IMPORTER::GetLineWidthMM ( ) const
inline

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

Definition at line 119 of file graphics_importer.h.

120  {
121  return m_lineWidth;
122  }
double m_lineWidth
Default line thickness for the imported graphics

References m_lineWidth.

Referenced by GRAPHICS_IMPORTER_PCBNEW::MapLineWidth().

◆ GetMessages()

const std::string& 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 81 of file graphics_importer.h.

82  {
83  return m_plugin->GetMessages();
84  }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file

References m_plugin.

◆ GetMillimeterToIuFactor()

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

Definition at line 157 of file graphics_importer.h.

158  {
159  return m_millimeterToIu;
160  }
double m_millimeterToIu
factor to convert millimeters to Internal Units

References m_millimeterToIu.

◆ GetScale()

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

Definition at line 126 of file graphics_importer.h.

127  {
128  return m_scale;
129  }
double m_scale
Scale factor applied to the imported graphics.

References m_scale.

◆ Import()

bool GRAPHICS_IMPORTER::Import ( double  aScale = 1.0)

Imports 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 53 of file graphics_importer.cpp.

54 {
55  if( !m_plugin )
56  {
57  wxASSERT_MSG( false, "Plugin has to be set before import." );
58  return false;
59  }
60 
61  SetScale( aScale );
62 
63  m_plugin->SetImporter( this );
64 
65  return m_plugin->Import();
66 }
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file

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 166 of file graphics_importer.h.

167  {
168  return m_scale * m_millimeterToIu;
169  }
double m_millimeterToIu
factor to convert millimeters to Internal Units
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 38 of file graphics_importer.cpp.

39 {
40  m_items.clear();
41 
42  if( !m_plugin )
43  {
44  wxASSERT_MSG( false, "Plugin has to be set before load." );
45  return false;
46  }
47 
48  m_plugin->SetImporter( this );
49 
50  return m_plugin->Load( aFileName );
51 }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file
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 to add to coordinates when importing graphic items.

The offset is always in mm

Definition at line 142 of file graphics_importer.h.

143  {
144  m_offsetCoordmm = aOffset;
145  }
VECTOR2D m_offsetCoordmm
Offset (in mm) for imported coordinates

References m_offsetCoordmm.

◆ SetLineWidthMM()

void GRAPHICS_IMPORTER::SetLineWidthMM ( double  aWidth)
inline

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

Definition at line 111 of file graphics_importer.h.

112  {
113  m_lineWidth = aWidth;
114  }
double m_lineWidth
Default line thickness for the imported graphics

References m_lineWidth.

◆ SetPlugin()

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

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

Definition at line 55 of file graphics_importer.h.

56  {
57  m_plugin = std::move( aPlugin );
58  }
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file

References m_plugin.

◆ SetScale()

void GRAPHICS_IMPORTER::SetScale ( double  aScale)
inline

Set the scale factor affecting the imported shapes.

it allows conversion between imported shapes units and mm

Definition at line 150 of file graphics_importer.h.

151  {
152  m_scale = aScale;
153  }
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

Default line thickness (in mm)

Definition at line 180 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

Definition at line 247 of file graphics_importer.h.

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

◆ m_lineWidth

double GRAPHICS_IMPORTER::m_lineWidth
private

Default line thickness for the imported graphics

Definition at line 259 of file graphics_importer.h.

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

◆ m_millimeterToIu

double GRAPHICS_IMPORTER::m_millimeterToIu
protected

factor to convert millimeters to Internal Units

Definition at line 269 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

Offset (in mm) for imported coordinates

Definition at line 272 of file graphics_importer.h.

Referenced by GetImportOffsetMM(), and SetImportOffsetMM().

◆ m_originalHeight

double GRAPHICS_IMPORTER::m_originalHeight
private

Total image Height;

Definition at line 256 of file graphics_importer.h.

Referenced by GetImageHeightMM(), and GRAPHICS_IMPORTER().

◆ m_originalWidth

double GRAPHICS_IMPORTER::m_originalWidth
private

Total image width

Definition at line 253 of file graphics_importer.h.

Referenced by GetImageWidthMM(), and GRAPHICS_IMPORTER().

◆ m_plugin

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

Plugin used to load a file

Definition at line 250 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 items

Definition at line 265 of file graphics_importer.h.

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


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