KiCad PCB EDA Suite
GRAPHICS_IMPORTER_BUFFER Class Reference

#include <graphics_importer_buffer.h>

Inheritance diagram for GRAPHICS_IMPORTER_BUFFER:
GRAPHICS_IMPORTER

Public Member Functions

void AddLine (const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
 Create an object representing a line segment. More...
 
void AddCircle (const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled) override
 Create an object representing a circle. More...
 
void AddArc (const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
 Create an object representing an arc. More...
 
void AddPolygon (const std::vector< VECTOR2D > &aVertices, double aWidth) override
 
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) override
 Create an object representing a text. More...
 
void AddSpline (const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
 Create an object representing an arc. More...
 
void ImportTo (GRAPHICS_IMPORTER &aImporter)
 
void AddShape (std::unique_ptr< IMPORTED_SHAPE > &aShape)
 
std::list< std::unique_ptr< IMPORTED_SHAPE > > & GetShapes ()
 
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...
 

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

std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
 < List of imported shapes More...
 
double m_millimeterToIu
 Offset (in mm) for imported coordinates. More...
 
VECTOR2D m_offsetCoordmm
 

Detailed Description

Definition at line 320 of file graphics_importer_buffer.h.

Member Function Documentation

◆ AddArc()

void GRAPHICS_IMPORTER_BUFFER::AddArc ( const VECTOR2D aCenter,
const VECTOR2D aStart,
double  aAngle,
double  aWidth 
)
overridevirtual

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

Implements GRAPHICS_IMPORTER.

Definition at line 48 of file graphics_importer_buffer.cpp.

50 {
51  m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle, aWidth ) );
52 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::addArc(), and DXF_IMPORT_PLUGIN::insertArc().

◆ AddCircle()

void GRAPHICS_IMPORTER_BUFFER::AddCircle ( const VECTOR2D aCenter,
double  aRadius,
double  aWidth,
bool  aFilled 
)
overridevirtual

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

Implements GRAPHICS_IMPORTER.

Definition at line 42 of file graphics_importer_buffer.cpp.

43 {
44  m_shapes.push_back( make_shape<IMPORTED_CIRCLE>( aCenter, aRadius, aWidth, aFilled ) );
45 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::addCircle(), and DXF_IMPORT_PLUGIN::addPoint().

◆ addItem()

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

◆ AddLine()

void GRAPHICS_IMPORTER_BUFFER::AddLine ( const VECTOR2D aOrigin,
const VECTOR2D aEnd,
double  aWidth 
)
overridevirtual

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

Implements GRAPHICS_IMPORTER.

Definition at line 36 of file graphics_importer_buffer.cpp.

37 {
38  m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
39 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::addLine(), DXF_IMPORT_PLUGIN::insertLine(), and DXF_IMPORT_PLUGIN::insertSpline().

◆ AddPolygon()

void GRAPHICS_IMPORTER_BUFFER::AddPolygon ( const std::vector< VECTOR2D > &  aVertices,
double  aWidth 
)
overridevirtual

Implements GRAPHICS_IMPORTER.

Definition at line 55 of file graphics_importer_buffer.cpp.

56 {
57  m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices, aWidth ) );
58 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

◆ AddShape()

void GRAPHICS_IMPORTER_BUFFER::AddShape ( std::unique_ptr< IMPORTED_SHAPE > &  aShape)

Definition at line 77 of file graphics_importer_buffer.cpp.

78 {
79  m_shapes.push_back( std::move( aShape ) );
80 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::addInsert().

◆ AddSpline()

void GRAPHICS_IMPORTER_BUFFER::AddSpline ( const VECTOR2D aStart,
const VECTOR2D aBezierControl1,
const VECTOR2D aBezierControl2,
const VECTOR2D aEnd,
double  aWidth 
)
overridevirtual

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

Implements GRAPHICS_IMPORTER.

Definition at line 70 of file graphics_importer_buffer.cpp.

72 {
73  m_shapes.push_back( make_shape< IMPORTED_SPLINE >( aStart, aBezierControl1, aBezierControl2, aEnd, aWidth ) );
74 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::insertSpline().

◆ AddText()

void GRAPHICS_IMPORTER_BUFFER::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 
)
overridevirtual

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

Implements GRAPHICS_IMPORTER.

Definition at line 61 of file graphics_importer_buffer.cpp.

64 {
65  m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth,
66  aThickness, aOrientation, aHJustify, aVJustify ) );
67 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::addMText(), and DXF_IMPORT_PLUGIN::addText().

◆ GetImageHeightMM()

double GRAPHICS_IMPORTER::GetImageHeightMM ( ) const
inlineinherited

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 GRAPHICS_IMPORTER::m_originalHeight.

◆ GetImageWidthMM()

double GRAPHICS_IMPORTER::GetImageWidthMM ( ) const
inlineinherited

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 GRAPHICS_IMPORTER::m_originalWidth.

◆ GetImportOffsetMM()

const VECTOR2D& GRAPHICS_IMPORTER::GetImportOffsetMM ( ) const
inlineinherited
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 GRAPHICS_IMPORTER::m_offsetCoordmm.

Referenced by GRAPHICS_IMPORTER_PCBNEW::MapCoordinate().

◆ GetItems()

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

Return the list of objects representing the imported shapes.

Default line thickness (in mm)

Definition at line 181 of file graphics_importer.h.

References GRAPHICS_IMPORTER::m_items.

◆ GetLineWidthMM()

double GRAPHICS_IMPORTER::GetLineWidthMM ( ) const
inlineinherited

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 GRAPHICS_IMPORTER::m_lineWidth.

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

◆ GetMessages()

const wxString& GRAPHICS_IMPORTER::GetMessages ( ) const
inlineinherited

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 GRAPHICS_IMPORTER::m_plugin.

◆ GetMillimeterToIuFactor()

double GRAPHICS_IMPORTER::GetMillimeterToIuFactor ( )
inlineinherited
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 GRAPHICS_IMPORTER::m_millimeterToIu.

◆ GetScale()

double GRAPHICS_IMPORTER::GetScale ( ) const
inlineinherited
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 GRAPHICS_IMPORTER::m_scale.

◆ GetShapes()

std::list<std::unique_ptr<IMPORTED_SHAPE> >& GRAPHICS_IMPORTER_BUFFER::GetShapes ( )
inline

Definition at line 342 of file graphics_importer_buffer.h.

343  {
344  return m_shapes;
345  }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

References m_shapes.

Referenced by DXF_IMPORT_PLUGIN::addInsert().

◆ Import()

bool GRAPHICS_IMPORTER::Import ( double  aScale = 1.0)
inherited

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 GRAPHICS_IMPORTER::m_plugin, and GRAPHICS_IMPORTER::SetScale().

◆ ImportScalingFactor()

double GRAPHICS_IMPORTER::ImportScalingFactor ( ) const
inlineinherited
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 GRAPHICS_IMPORTER::m_millimeterToIu, and GRAPHICS_IMPORTER::m_scale.

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

◆ ImportTo()

void GRAPHICS_IMPORTER_BUFFER::ImportTo ( GRAPHICS_IMPORTER aImporter)

Definition at line 83 of file graphics_importer_buffer.cpp.

84 {
85  for( auto& shape : m_shapes )
86  shape->ImportTo( aImporter );
87 }
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes

Referenced by DXF_IMPORT_PLUGIN::Import().

◆ Load()

bool GRAPHICS_IMPORTER::Load ( const wxString &  aFileName)
inherited

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 GRAPHICS_IMPORTER::m_items, and GRAPHICS_IMPORTER::m_plugin.

◆ SetImportOffsetMM()

void GRAPHICS_IMPORTER::SetImportOffsetMM ( const VECTOR2D aOffset)
inlineinherited

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 GRAPHICS_IMPORTER::m_offsetCoordmm.

◆ SetLineWidthMM()

void GRAPHICS_IMPORTER::SetLineWidthMM ( double  aWidth)
inlineinherited

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 GRAPHICS_IMPORTER::m_lineWidth.

◆ SetPlugin()

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

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 GRAPHICS_IMPORTER::m_plugin.

◆ SetScale()

void GRAPHICS_IMPORTER::SetScale ( double  aScale)
inlineinherited

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 GRAPHICS_IMPORTER::m_scale.

Referenced by GRAPHICS_IMPORTER::Import().

Member Data Documentation

◆ DEFAULT_LINE_WIDTH_DFX

constexpr unsigned int GRAPHICS_IMPORTER::DEFAULT_LINE_WIDTH_DFX = 1
staticinherited

Definition at line 187 of file graphics_importer.h.

Referenced by GRAPHICS_IMPORTER::GRAPHICS_IMPORTER().

◆ m_millimeterToIu

double GRAPHICS_IMPORTER::m_millimeterToIu
protectedinherited

◆ m_offsetCoordmm

VECTOR2D GRAPHICS_IMPORTER::m_offsetCoordmm
protectedinherited

◆ m_shapes

std::list< std::unique_ptr< IMPORTED_SHAPE > > GRAPHICS_IMPORTER_BUFFER::m_shapes
protected

< List of imported shapes

Definition at line 349 of file graphics_importer_buffer.h.

Referenced by GetShapes().


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