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

A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference for the user. More...

#include <reference_image.h>

Public Member Functions

 REFERENCE_IMAGE (const EDA_IU_SCALE &aIuScale)
 
 REFERENCE_IMAGE (const REFERENCE_IMAGE &aOther)
 
 ~REFERENCE_IMAGE ()
 
REFERENCE_IMAGE & operator= (const REFERENCE_IMAGE &aOther)
 
bool operator== (const REFERENCE_IMAGE &aOther) const
 
double Similarity (const REFERENCE_IMAGE &aOther) const
 
BOX2I GetBoundingBox () const
 
bool HitTest (const BOX2I &aRect, bool aContained, int aAccuracy) const
 
VECTOR2I GetPosition () const
 
void SetPosition (const VECTOR2I &aPos)
 
VECTOR2I GetSize () const
 
double GetImageScale () const
 
void SetImageScale (double aScale)
 Set the image "zoom" value.
 
void SetWidth (int aWidth)
 
void SetHeight (int aHeight)
 
bool Flip (const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
 
void Rotate (const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
 Rotate the image about aCenter.
 
EDA_ANGLE GetOrientation () const
 
void SetOrientation (const EDA_ANGLE &aAngle)
 Set the rotation of the image content relative to the stored raster.
 
double GetOpacity () const
 
void SetOpacity (double aOpacity)
 
bool ReadImageFile (const wxString &aFullFilename)
 Read and store an image file.
 
bool ReadImageFile (wxMemoryBuffer &aBuf)
 Read and store an image file.
 
bool SetImage (const wxImage &aImage)
 Set the image from an existing wxImage.
 
void PackToBytes (std::string &aOutputBytes) const
 
bool UnpackFromBytes (const std::string &aInputBytes)
 
void SwapData (REFERENCE_IMAGE &aItem)
 
const BITMAP_BASE & GetImage () const
 Get the underlying image.
 
BITMAP_BASE & MutableImage () const
 Only use this if you really need to modify the underlying image.
 
void PlotImage (PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
 Plot the image on a plotter, turned to its stored orientation.
 
VECTOR2I GetTransformOriginOffset () const
 Get the center of scaling, etc, relative to the image center (GetPosition()).
 
void SetTransformOriginOffset (const VECTOR2I &aCenter)
 

Private Member Functions

void scaleBy (double ratio)
 
void updatePixelSizeInIU ()
 
VECTOR2I boundingSize () const
 

Private Attributes

const EDA_IU_SCALE & m_iuScale
 
VECTOR2I m_pos
 XY coordinates of center of the bitmap.
 
VECTOR2I m_transformOriginOffset
 Center of scaling, etc, relative to the image center.
 
EDA_ORIENTATION m_orientation
 Rotation of the image content relative to the raster, in [0, 360).
 
double m_opacity
 The opacity of the image, in the range [0, 1].
 
std::unique_ptr< BITMAP_BASE > m_bitmapBase
 

Detailed Description

A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference for the user.

Definition at line 41 of file reference_image.h.

Constructor & Destructor Documentation

◆ REFERENCE_IMAGE() [1/2]

REFERENCE_IMAGE::REFERENCE_IMAGE ( const EDA_IU_SCALE & aIuScale)

◆ REFERENCE_IMAGE() [2/2]

REFERENCE_IMAGE::REFERENCE_IMAGE ( const REFERENCE_IMAGE & aOther)

◆ ~REFERENCE_IMAGE()

REFERENCE_IMAGE::~REFERENCE_IMAGE ( )

Definition at line 91 of file reference_image.cpp.

Member Function Documentation

◆ boundingSize()

VECTOR2I REFERENCE_IMAGE::boundingSize ( ) const
private
Returns
the size of the axis-aligned bounding box that contains the rotated image.

Definition at line 189 of file reference_image.cpp.

References std::abs(), EDA_ANGLE::Cos(), EDA_ANGLE::IsHorizontal(), EDA_ANGLE::IsVertical(), KiROUND(), m_bitmapBase, m_orientation, EDA_ANGLE::Sin(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Flip(), GetBoundingBox(), scaleBy(), and SetPosition().

◆ Flip()

bool REFERENCE_IMAGE::Flip ( const VECTOR2I & aCentre,
FLIP_DIRECTION aFlipDirection )
Parameters
aCentre
aFlipDirectionLEFT_RIGHT or TOP_BOTTOM
Returns
false if the flip would put the coordinates out-of-bounds

Definition at line 311 of file reference_image.cpp.

References boundingSize(), BOX2< VECTOR2D >::ByCenter(), IsBOX2Safe(), m_bitmapBase, m_orientation, m_pos, m_transformOriginOffset, and MIRROR().

Referenced by BOOST_FIXTURE_TEST_CASE().

◆ GetBoundingBox()

BOX2I REFERENCE_IMAGE::GetBoundingBox ( ) const

◆ GetImage()

◆ GetImageScale()

◆ GetOpacity()

◆ GetOrientation()

◆ GetPosition()

◆ GetSize()

◆ GetTransformOriginOffset()

VECTOR2I REFERENCE_IMAGE::GetTransformOriginOffset ( ) const

Get the center of scaling, etc, relative to the image center (GetPosition()).

Definition at line 229 of file reference_image.cpp.

References m_transformOriginOffset.

Referenced by PCB_GRID_HELPER::AddConstructionItems(), BOOST_FIXTURE_TEST_CASE(), and PCB_GRID_HELPER::computeAnchors().

◆ HitTest()

bool REFERENCE_IMAGE::HitTest ( const BOX2I & aRect,
bool aContained,
int aAccuracy ) const

◆ MutableImage()

◆ operator=()

◆ operator==()

◆ PackToBytes()

void REFERENCE_IMAGE::PackToBytes ( std::string & aOutputBytes) const

Definition at line 395 of file reference_image.cpp.

References m_bitmapBase.

◆ PlotImage()

void REFERENCE_IMAGE::PlotImage ( PLOTTER * aPlotter,
const VECTOR2I & aPos,
const KIGFX::COLOR4D & aDefaultColor,
int aDefaultPensize ) const

Plot the image on a plotter, turned to its stored orientation.

This may resample the image depending on the orientation.

Parameters
aPlotterthe plotter to use.
aPosthe position of the center of the image.
aDefaultColorthe color used to plot the rectangle when bitmap is not supported.
aDefaultPensizethe pen size used to plot the rectangle when bitmap is not supported.

Definition at line 437 of file reference_image.cpp.

References ANGLE_180, ANGLE_270, ANGLE_90, EDA_ANGLE::AsRadians(), image, EDA_ANGLE::IsZero(), KiROUND(), m_bitmapBase, m_opacity, m_orientation, PLOTTER::PlotImage(), PLOTTER::SetColor(), and PLOTTER::SetCurrentLineWidth().

◆ ReadImageFile() [1/2]

◆ ReadImageFile() [2/2]

bool REFERENCE_IMAGE::ReadImageFile ( wxMemoryBuffer & aBuf)

Read and store an image file.

Initialize the bitmap used to draw this item format.

Parameters
aBufis the memory buffer containing the image file to read.
Returns
true if success reading else false.

Definition at line 371 of file reference_image.cpp.

References m_bitmapBase, and updatePixelSizeInIU().

◆ Rotate()

void REFERENCE_IMAGE::Rotate ( const VECTOR2I & aCenter,
const EDA_ANGLE & aAngle )

Rotate the image about aCenter.

The position and the transform origin follow aAngle exactly. The rotation is stored rather than turned into the raster, so the image keeps its resolution and a save followed by a load is lossless for the formats that carry the rotation.

Definition at line 332 of file reference_image.cpp.

References m_orientation, m_pos, m_transformOriginOffset, and RotatePoint().

Referenced by BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and TARGET3001_SCH_BUILDER::makePicture().

◆ scaleBy()

void REFERENCE_IMAGE::scaleBy ( double ratio)
private

◆ SetHeight()

void REFERENCE_IMAGE::SetHeight ( int aHeight)

Definition at line 257 of file reference_image.cpp.

References m_bitmapBase, and scaleBy().

◆ SetImage()

bool REFERENCE_IMAGE::SetImage ( const wxImage & aImage)

Set the image from an existing wxImage.

Definition at line 383 of file reference_image.cpp.

References m_bitmapBase, and updatePixelSizeInIU().

Referenced by BOOST_FIXTURE_TEST_CASE(), TARGET3001_SCH_BUILDER::makePicture(), and ORCAD_CONVERTER::placeBitmap().

◆ SetImageScale()

◆ SetOpacity()

◆ SetOrientation()

void REFERENCE_IMAGE::SetOrientation ( const EDA_ANGLE & aAngle)

Set the rotation of the image content relative to the stored raster.

Definition at line 347 of file reference_image.cpp.

References m_orientation.

Referenced by BOOST_AUTO_TEST_CASE(), SCH_IO_KICAD_SEXPR_PARSER::parseImage(), PCB_IO_KICAD_SEXPR_PARSER::parsePCB_REFERENCE_IMAGE(), and DIALOG_IMAGE_PROPERTIES::TransferDataFromWindow().

◆ SetPosition()

void REFERENCE_IMAGE::SetPosition ( const VECTOR2I & aPos)

◆ SetTransformOriginOffset()

void REFERENCE_IMAGE::SetTransformOriginOffset ( const VECTOR2I & aCenter)

Definition at line 235 of file reference_image.cpp.

References m_transformOriginOffset.

Referenced by BOOST_FIXTURE_TEST_CASE(), and scaleBy().

◆ SetWidth()

void REFERENCE_IMAGE::SetWidth ( int aWidth)

Definition at line 247 of file reference_image.cpp.

References m_bitmapBase, and scaleBy().

Referenced by TARGET3001_SCH_BUILDER::makePicture().

◆ Similarity()

double REFERENCE_IMAGE::Similarity ( const REFERENCE_IMAGE & aOther) const

◆ SwapData()

void REFERENCE_IMAGE::SwapData ( REFERENCE_IMAGE & aItem)

◆ UnpackFromBytes()

bool REFERENCE_IMAGE::UnpackFromBytes ( const std::string & aInputBytes)

Definition at line 412 of file reference_image.cpp.

References ReadImageFile().

◆ updatePixelSizeInIU()

void REFERENCE_IMAGE::updatePixelSizeInIU ( )
private

Member Data Documentation

◆ m_bitmapBase

◆ m_iuScale

const EDA_IU_SCALE& REFERENCE_IMAGE::m_iuScale
private

◆ m_opacity

double REFERENCE_IMAGE::m_opacity
private

The opacity of the image, in the range [0, 1].

Definition at line 198 of file reference_image.h.

Referenced by GetOpacity(), operator=(), operator==(), PlotImage(), REFERENCE_IMAGE(), REFERENCE_IMAGE(), SetOpacity(), Similarity(), and SwapData().

◆ m_orientation

EDA_ORIENTATION REFERENCE_IMAGE::m_orientation
private

Rotation of the image content relative to the raster, in [0, 360).

Definition at line 195 of file reference_image.h.

Referenced by boundingSize(), Flip(), GetOrientation(), operator=(), operator==(), PlotImage(), REFERENCE_IMAGE(), REFERENCE_IMAGE(), Rotate(), SetOrientation(), Similarity(), and SwapData().

◆ m_pos

VECTOR2I REFERENCE_IMAGE::m_pos
private

XY coordinates of center of the bitmap.

Definition at line 189 of file reference_image.h.

Referenced by Flip(), GetBoundingBox(), GetPosition(), operator=(), operator==(), REFERENCE_IMAGE(), REFERENCE_IMAGE(), Rotate(), scaleBy(), SetPosition(), Similarity(), and SwapData().

◆ m_transformOriginOffset

VECTOR2I REFERENCE_IMAGE::m_transformOriginOffset
private

Center of scaling, etc, relative to the image center.

Definition at line 192 of file reference_image.h.

Referenced by Flip(), GetTransformOriginOffset(), operator=(), operator==(), REFERENCE_IMAGE(), REFERENCE_IMAGE(), Rotate(), scaleBy(), SetTransformOriginOffset(), and SwapData().


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