KiCad PCB EDA Suite
Loading...
Searching...
No Matches
BITMAP_IMPORT_PLUGIN Class Reference

Import a raster image by tracing its dark areas into filled polygons. More...

#include <bitmap_import_plugin.h>

Inheritance diagram for BITMAP_IMPORT_PLUGIN:
GRAPHICS_IMPORT_PLUGIN

Public Member Functions

const wxString GetName () const override
 Return the plugin name.
 
const std::vector< std::string > GetFileExtensions () const override
 Return a vector of the file extensions handled by this plugin.
 
const wxString & GetMessages () const override
 Collect warning and error messages after loading/importing.
 
void ReportMsg (const wxString &aMessage) override
 
bool Load (const wxString &aFileName) override
 Load file for import.
 
bool LoadFromMemory (const wxMemoryBuffer &aMemBuffer) override
 Set memory buffer with content for import.
 
bool Import () override
 Actually imports the file.
 
double GetImageWidth () const override
 Return image width from original imported file.
 
double GetImageHeight () const override
 Return image height from original imported file.
 
BOX2D GetImageBBox () const override
 Return image bounding box from original imported file.
 
const wxImage & GetImage () const
 The loaded image, so a caller showing a preview does not have to read the file again.
 
void SetThreshold (double aThreshold)
 Brightness cut deciding which pixels are traced, from 0 to 1.
 
void SetInvert (bool aInvert)
 Invert the image before the threshold is applied.
 
virtual void SetImporter (GRAPHICS_IMPORTER *aImporter)
 Set the receiver of the imported shapes.
 
wxString GetWildcards () const
 Return a list of wildcards that contains the file extensions handled by this plugin, separated with a semi-colon.
 
virtual void SetLineWidthMM (double aLineWidth)
 

Static Public Attributes

static constexpr double DEFAULT_THRESHOLD = 0.5
 Used when the caller offers the user no threshold setting.
 
static constexpr int DEFAULT_DPI = 300
 Resolution assumed for images that do not carry one.
 

Protected Attributes

GRAPHICS_IMPORTER * m_importer
 Importer used to create objects representing the imported shapes.
 

Private Member Functions

double pixelSizeXmm () const
 
double pixelSizeYmm () const
 

Private Attributes

wxImage m_image
 
double m_threshold = DEFAULT_THRESHOLD
 
bool m_invert = false
 
wxString m_messages
 

Detailed Description

Import a raster image by tracing its dark areas into filled polygons.

The image is reduced to black and white at a threshold, then traced. Geometry is reported in millimetres, taken from the image resolution.

Definition at line 35 of file bitmap_import_plugin.h.

Member Function Documentation

◆ GetFileExtensions()

const std::vector< std::string > BITMAP_IMPORT_PLUGIN::GetFileExtensions ( ) const
inlineoverridevirtual

Return a vector of the file extensions handled by this plugin.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 46 of file bitmap_import_plugin.h.

◆ GetImage()

const wxImage & BITMAP_IMPORT_PLUGIN::GetImage ( ) const
inline

The loaded image, so a caller showing a preview does not have to read the file again.

Definition at line 65 of file bitmap_import_plugin.h.

References m_image.

◆ GetImageBBox()

BOX2D BITMAP_IMPORT_PLUGIN::GetImageBBox ( ) const
overridevirtual

Return image bounding box from original imported file.

Returns
Image bounding box.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 109 of file bitmap_import_plugin.cpp.

References GetImageHeight(), and GetImageWidth().

◆ GetImageHeight()

double BITMAP_IMPORT_PLUGIN::GetImageHeight ( ) const
overridevirtual

Return image height from original imported file.

Returns
Original Image height in mm.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 103 of file bitmap_import_plugin.cpp.

References m_image, and pixelSizeYmm().

Referenced by BOOST_FIXTURE_TEST_CASE(), and GetImageBBox().

◆ GetImageWidth()

double BITMAP_IMPORT_PLUGIN::GetImageWidth ( ) const
overridevirtual

Return image width from original imported file.

Returns
Original Image width in mm.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 97 of file bitmap_import_plugin.cpp.

References m_image, and pixelSizeXmm().

Referenced by BOOST_FIXTURE_TEST_CASE(), and GetImageBBox().

◆ GetMessages()

const wxString & BITMAP_IMPORT_PLUGIN::GetMessages ( ) const
inlineoverridevirtual

Collect warning and error messages after loading/importing.

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

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 52 of file bitmap_import_plugin.h.

References m_messages.

◆ GetName()

const wxString BITMAP_IMPORT_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return the plugin name.

This string will be used as the description in the file dialog.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 44 of file bitmap_import_plugin.h.

◆ GetWildcards()

wxString GRAPHICS_IMPORT_PLUGIN::GetWildcards ( ) const
inlineinherited

Return a list of wildcards that contains the file extensions handled by this plugin, separated with a semi-colon.

Definition at line 61 of file graphics_import_plugin.h.

References formatWildcardExt(), and GetFileExtensions().

◆ Import()

◆ Load()

bool BITMAP_IMPORT_PLUGIN::Load ( const wxString & aFileName)
overridevirtual

Load file for import.

It is necessary to have the GRAPHICS_IMPORTER object set before.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 45 of file bitmap_import_plugin.cpp.

References m_image.

◆ LoadFromMemory()

bool BITMAP_IMPORT_PLUGIN::LoadFromMemory ( const wxMemoryBuffer & aMemBuffer)
overridevirtual

Set memory buffer with content for import.

It is necessary to have the GRAPHICS_IMPORTER object set before.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 55 of file bitmap_import_plugin.cpp.

References m_image.

Referenced by BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and BOOST_FIXTURE_TEST_CASE().

◆ pixelSizeXmm()

double BITMAP_IMPORT_PLUGIN::pixelSizeXmm ( ) const
private

Definition at line 85 of file bitmap_import_plugin.cpp.

References DEFAULT_DPI, imageResolution(), m_image, and MM_PER_INCH.

Referenced by GetImageWidth(), and Import().

◆ pixelSizeYmm()

double BITMAP_IMPORT_PLUGIN::pixelSizeYmm ( ) const
private

Definition at line 91 of file bitmap_import_plugin.cpp.

References DEFAULT_DPI, imageResolution(), m_image, and MM_PER_INCH.

Referenced by GetImageHeight(), and Import().

◆ ReportMsg()

void BITMAP_IMPORT_PLUGIN::ReportMsg ( const wxString & aMessage)
overridevirtual

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 38 of file bitmap_import_plugin.cpp.

References m_messages.

Referenced by Import().

◆ SetImporter()

◆ SetInvert()

void BITMAP_IMPORT_PLUGIN::SetInvert ( bool aInvert)
inline

Invert the image before the threshold is applied.

Definition at line 71 of file bitmap_import_plugin.h.

References m_invert.

◆ SetLineWidthMM()

virtual void GRAPHICS_IMPORT_PLUGIN::SetLineWidthMM ( double aLineWidth)
inlinevirtualinherited

Reimplemented in DXF_IMPORT_PLUGIN.

Definition at line 121 of file graphics_import_plugin.h.

◆ SetThreshold()

void BITMAP_IMPORT_PLUGIN::SetThreshold ( double aThreshold)
inline

Brightness cut deciding which pixels are traced, from 0 to 1.

Definition at line 68 of file bitmap_import_plugin.h.

References m_threshold.

Member Data Documentation

◆ DEFAULT_DPI

int BITMAP_IMPORT_PLUGIN::DEFAULT_DPI = 300
staticconstexpr

Resolution assumed for images that do not carry one.

Definition at line 42 of file bitmap_import_plugin.h.

Referenced by pixelSizeXmm(), and pixelSizeYmm().

◆ DEFAULT_THRESHOLD

double BITMAP_IMPORT_PLUGIN::DEFAULT_THRESHOLD = 0.5
staticconstexpr

Used when the caller offers the user no threshold setting.

Definition at line 39 of file bitmap_import_plugin.h.

◆ m_image

wxImage BITMAP_IMPORT_PLUGIN::m_image
private

◆ m_importer

GRAPHICS_IMPORTER* GRAPHICS_IMPORT_PLUGIN::m_importer
protectedinherited

◆ m_invert

bool BITMAP_IMPORT_PLUGIN::m_invert = false
private

Definition at line 79 of file bitmap_import_plugin.h.

Referenced by Import(), and SetInvert().

◆ m_messages

wxString BITMAP_IMPORT_PLUGIN::m_messages
private

Definition at line 80 of file bitmap_import_plugin.h.

Referenced by GetMessages(), and ReportMsg().

◆ m_threshold

double BITMAP_IMPORT_PLUGIN::m_threshold = DEFAULT_THRESHOLD
private

Definition at line 78 of file bitmap_import_plugin.h.

Referenced by Import(), and SetThreshold().


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