KiCad PCB EDA Suite
GRAPHICS_IMPORTER_BUFFER Class Reference

#include <graphics_importer_buffer.h>

Inheritance diagram for GRAPHICS_IMPORTER_BUFFER:
GRAPHICS_IMPORTER

Public Types

enum  POLY_FILL_RULE { PF_NONZERO = 0 , PF_EVEN_ODD }
 

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, const EDA_ANGLE &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, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_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 ClearShapes ()
 
void PostprocessNestedPolygons ()
 
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...
 
void ClearItems ()
 Empties out the imported shapes list. More...
 
virtual void NewShape (POLY_FILL_RULE aFillRule=PF_NONZERO)
 

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
 
std::vector< POLY_FILL_RULEm_shapeFillRules
 

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

Definition at line 284 of file graphics_importer_buffer.h.

Member Enumeration Documentation

◆ POLY_FILL_RULE

Enumerator
PF_NONZERO 
PF_EVEN_ODD 

Definition at line 48 of file graphics_importer.h.

Member Function Documentation

◆ AddArc()

void GRAPHICS_IMPORTER_BUFFER::AddArc ( const VECTOR2D aCenter,
const VECTOR2D aStart,
const EDA_ANGLE 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.
aWidthis the segment thickness in mm. Use -1 for default line thickness

Implements GRAPHICS_IMPORTER.

Definition at line 53 of file graphics_importer_buffer.cpp.

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

References m_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 47 of file graphics_importer_buffer.cpp.

48{
49 m_shapes.push_back( make_shape<IMPORTED_CIRCLE>( aCenter, aRadius, aWidth, aFilled ) );
50}

References m_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 41 of file graphics_importer_buffer.cpp.

42{
43 m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
44}

References m_shapes.

Referenced by DXF_IMPORT_PLUGIN::addLine(), SVG_IMPORT_PLUGIN::DrawLineSegments(), 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 60 of file graphics_importer_buffer.cpp.

61{
62 m_shapes.push_back( make_shape<IMPORTED_POLYGON>( aVertices, aWidth ) );
63 m_shapes.back()->SetParentShapeIndex( m_shapeFillRules.size() - 1 );
64}
std::vector< POLY_FILL_RULE > m_shapeFillRules

References GRAPHICS_IMPORTER::m_shapeFillRules, and m_shapes.

Referenced by SVG_IMPORT_PLUGIN::DrawPolygon().

◆ AddShape()

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

Definition at line 84 of file graphics_importer_buffer.cpp.

85{
86 m_shapes.push_back( std::move( aShape ) );
87}

References m_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 77 of file graphics_importer_buffer.cpp.

79{
80 m_shapes.push_back( make_shape<IMPORTED_SPLINE>( aStart, aBezierControl1, aBezierControl2, aEnd, aWidth ) );
81}

References m_shapes.

Referenced by DXF_IMPORT_PLUGIN::addEllipse(), and DXF_IMPORT_PLUGIN::insertSpline().

◆ AddText()

void GRAPHICS_IMPORTER_BUFFER::AddText ( const VECTOR2D aOrigin,
const wxString &  aText,
double  aHeight,
double  aWidth,
double  aThickness,
double  aOrientation,
GR_TEXT_H_ALIGN_T  aHJustify,
GR_TEXT_V_ALIGN_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 67 of file graphics_importer_buffer.cpp.

71{
72 m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth,
73 aThickness, aOrientation, aHJustify, aVJustify ) );
74}

References m_shapes.

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

◆ ClearItems()

void GRAPHICS_IMPORTER::ClearItems ( )
inlineinherited

Empties out the imported shapes list.

Default line thickness (in mm)

Definition at line 195 of file graphics_importer.h.

References GRAPHICS_IMPORTER::m_items.

◆ ClearShapes()

void GRAPHICS_IMPORTER_BUFFER::ClearShapes ( )
inline

Definition at line 311 of file graphics_importer_buffer.h.

312 {
313 m_shapes.clear();
314 }

References m_shapes.

Referenced by DXF_IMPORT_PLUGIN::Load().

◆ GetImageHeightMM()

double GRAPHICS_IMPORTER::GetImageHeightMM ( ) const
inlineinherited

Get original image Height.

Returns
Height of the loaded image in mm.

Definition at line 113 of file graphics_importer.h.

114 {
115 return m_originalHeight;
116 }

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

104 {
105 return m_originalWidth;
106 }
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 145 of file graphics_importer.h.

146 {
147 return m_offsetCoordmm;
148 }

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.

Definition at line 187 of file graphics_importer.h.

188 {
189 return m_items;
190 }
std::list< std::unique_ptr< EDA_ITEM > > m_items
< List of imported items

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

130 {
131 return m_lineWidth;
132 }

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

94 {
95 return m_plugin->GetMessages();
96 }
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 171 of file graphics_importer.h.

172 {
173 return m_millimeterToIu;
174 }
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 137 of file graphics_importer.h.

138 {
139 return m_scale;
140 }
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 306 of file graphics_importer_buffer.h.

307 {
308 return m_shapes;
309 }

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, wxT( "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.

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

180 {
181 return m_scale * m_millimeterToIu;
182 }

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 90 of file graphics_importer_buffer.cpp.

91{
92 for( std::unique_ptr<IMPORTED_SHAPE>& shape : m_shapes )
93 shape->ImportTo( aImporter );
94}

References m_shapes.

Referenced by DXF_IMPORT_PLUGIN::Import(), and SVG_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, wxT( "Plugin must be set before load." ) );
46 return false;
47 }
48
49 m_plugin->SetImporter( this );
50
51 return m_plugin->Load( aFileName );
52}

References GRAPHICS_IMPORTER::m_items, and GRAPHICS_IMPORTER::m_plugin.

◆ NewShape()

void GRAPHICS_IMPORTER::NewShape ( POLY_FILL_RULE  aFillRule = PF_NONZERO)
virtualinherited

Definition at line 83 of file graphics_importer.cpp.

84{
85 m_shapeFillRules.push_back( aFillRule );
86}

References GRAPHICS_IMPORTER::m_shapeFillRules.

Referenced by SVG_IMPORT_PLUGIN::Import().

◆ PostprocessNestedPolygons()

void GRAPHICS_IMPORTER_BUFFER::PostprocessNestedPolygons ( )

Definition at line 173 of file graphics_importer_buffer.cpp.

174{
175 int curShapeIdx = -1;
176 double lastWidth = 0;
177
178 std::list<std::unique_ptr<IMPORTED_SHAPE>> newShapes;
179 std::vector<IMPORTED_POLYGON*> polypaths;
180
181 for( std::unique_ptr<IMPORTED_SHAPE>& shape : m_shapes )
182 {
183 IMPORTED_POLYGON* poly = dynamic_cast<IMPORTED_POLYGON*>( shape.get() );
184
185 if( !poly || poly->GetParentShapeIndex() < 0 )
186 {
187 newShapes.push_back( shape->clone() );
188 continue;
189 }
190
191 int index = poly->GetParentShapeIndex();
192
193 if( index != curShapeIdx && curShapeIdx >= 0 )
194 {
195 convertPolygon( newShapes, polypaths, m_shapeFillRules[curShapeIdx], lastWidth );
196 polypaths.clear();
197 }
198
199 curShapeIdx = index;
200 lastWidth = poly->GetWidth();
201 polypaths.push_back( poly );
202 }
203
204 if( curShapeIdx >= 0 )
205 convertPolygon( newShapes, polypaths, m_shapeFillRules[curShapeIdx], lastWidth );
206
207 m_shapes.swap( newShapes );
208}
int GetParentShapeIndex() const
static void convertPolygon(std::list< std::unique_ptr< IMPORTED_SHAPE > > &aShapes, std::vector< IMPORTED_POLYGON * > &aPaths, GRAPHICS_IMPORTER::POLY_FILL_RULE aFillRule, double aWidth)

References convertPolygon(), IMPORTED_SHAPE::GetParentShapeIndex(), IMPORTED_POLYGON::GetWidth(), GRAPHICS_IMPORTER::m_shapeFillRules, and m_shapes.

Referenced by SVG_IMPORT_PLUGIN::Import().

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

154 {
155 m_offsetCoordmm = aOffset;
156 }

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

122 {
123 m_lineWidth = aWidth;
124 }

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

64 {
65 m_plugin = std::move( aPlugin );
66
67 if( m_plugin )
68 m_plugin->SetImporter( this );
69 }

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

164 {
165 m_scale = aScale;
166 }

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
staticconstexprinherited

Definition at line 201 of file graphics_importer.h.

Referenced by GRAPHICS_IMPORTER::GRAPHICS_IMPORTER().

◆ m_items

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

< List of imported items

Plugin used to load a file

Definition at line 284 of file graphics_importer.h.

Referenced by GRAPHICS_IMPORTER::addItem(), GRAPHICS_IMPORTER::ClearItems(), GRAPHICS_IMPORTER::GetItems(), and GRAPHICS_IMPORTER::Load().

◆ m_lineWidth

double GRAPHICS_IMPORTER::m_lineWidth
privateinherited

◆ m_millimeterToIu

double GRAPHICS_IMPORTER::m_millimeterToIu
protectedinherited

◆ m_offsetCoordmm

VECTOR2D GRAPHICS_IMPORTER::m_offsetCoordmm
protectedinherited

◆ m_originalHeight

double GRAPHICS_IMPORTER::m_originalHeight
privateinherited

◆ m_originalWidth

double GRAPHICS_IMPORTER::m_originalWidth
privateinherited

Total image Height;.

Definition at line 290 of file graphics_importer.h.

Referenced by GRAPHICS_IMPORTER::GetImageWidthMM(), and GRAPHICS_IMPORTER::GRAPHICS_IMPORTER().

◆ m_plugin

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

◆ m_scale

double GRAPHICS_IMPORTER::m_scale
privateinherited

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 Default line thickness for the imported graphics

Definition at line 300 of file graphics_importer.h.

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

◆ m_shapeFillRules

std::vector<POLY_FILL_RULE> GRAPHICS_IMPORTER::m_shapeFillRules
protectedinherited

◆ m_shapes

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

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