7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-14 13:09:35 +00:00

Add height get/set to reference image properties

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/18567
This commit is contained in:
John Beard 2024-10-14 20:17:07 +08:00
parent ffebebefe7
commit 1baaf9afd0
6 changed files with 121 additions and 4 deletions

View File

@ -171,6 +171,26 @@ VECTOR2I REFERENCE_IMAGE::GetSize() const
}
void REFERENCE_IMAGE::SetWidth( int aWidth )
{
if( aWidth <= 0 )
return;
const double ratio = aWidth / (double) m_bitmapBase->GetSize().x;
scaleBy( ratio );
}
void REFERENCE_IMAGE::SetHeight( int aHeight )
{
if( aHeight <= 0 )
return;
const double ratio = aHeight / (double) m_bitmapBase->GetSize().y;
scaleBy( ratio );
}
double REFERENCE_IMAGE::GetImageScale() const
{
return m_bitmapBase->GetScale();
@ -179,15 +199,23 @@ double REFERENCE_IMAGE::GetImageScale() const
void REFERENCE_IMAGE::SetImageScale( double aScale )
{
if( aScale < 0 )
if( aScale <= 0 )
return;
const double ratio = aScale / m_bitmapBase->GetScale();
scaleBy( ratio );
}
void REFERENCE_IMAGE::scaleBy( double aRatio )
{
if( aRatio <= 0 )
return;
const VECTOR2D currentOrigin = m_pos + m_transformOriginOffset;
const VECTOR2D newOffset = m_transformOriginOffset * ratio;
const VECTOR2D newOffset = m_transformOriginOffset * aRatio;
const VECTOR2D newCenter = currentOrigin - newOffset;
const VECTOR2D newSize = m_bitmapBase->GetSize() * ratio;
const VECTOR2D newSize = m_bitmapBase->GetSize() * aRatio;
// The span of the image is limited to the size of the coordinate system
if( !IsVec2SafeXY( newSize ) )
@ -199,7 +227,7 @@ void REFERENCE_IMAGE::SetImageScale( double aScale )
if( !IsBOX2Safe( newBox ) )
return;
m_bitmapBase->SetScale( aScale );
m_bitmapBase->SetScale( m_bitmapBase->GetScale() * aRatio );
SetTransformOriginOffset( KiROUND( newOffset ) );
// Don't need to recheck the box, we just did that
m_pos = KiROUND( newCenter );

View File

@ -276,6 +276,30 @@ void SCH_BITMAP::SetImageScale( double aScale )
}
int SCH_BITMAP::GetWidth() const
{
return m_referenceImage.GetImage().GetSize().x;
}
void SCH_BITMAP::SetWidth( int aWidth )
{
m_referenceImage.SetWidth( aWidth );
}
int SCH_BITMAP::GetHeight() const
{
return m_referenceImage.GetImage().GetSize().y;
}
void SCH_BITMAP::SetHeight( int aHeight )
{
m_referenceImage.SetHeight( aHeight );
}
static struct SCH_BITMAP_DESC
{
SCH_BITMAP_DESC()
@ -313,5 +337,19 @@ static struct SCH_BITMAP_DESC
&SCH_BITMAP::GetTransformOriginOffsetY,
PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_Y_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Width" ),
&SCH_BITMAP::SetWidth,
&SCH_BITMAP::GetWidth,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Height" ),
&SCH_BITMAP::SetHeight,
&SCH_BITMAP::GetHeight,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
}
} _SCH_BITMAP_DESC;

View File

@ -123,6 +123,10 @@ private:
friend struct SCH_BITMAP_DESC;
// Property manager interfaces
int GetWidth() const;
void SetWidth( int aWidth );
int GetHeight() const;
void SetHeight( int aHeight );
int GetTransformOriginOffsetX() const;
void SetTransformOriginOffsetX( int aX );
int GetTransformOriginOffsetY() const;

View File

@ -80,6 +80,9 @@ public:
*/
void SetImageScale( double aScale );
void SetWidth( int aWidth );
void SetHeight( int aHeight );
void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
void Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle );
@ -131,6 +134,8 @@ public:
void SetTransformOriginOffset( const VECTOR2I& aCenter );
private:
void scaleBy( double ratio );
void updatePixelSizeInIU();
const EDA_IU_SCALE& m_iuScale;

View File

@ -307,6 +307,30 @@ void PCB_REFERENCE_IMAGE::SetImageScale( double aScale )
}
int PCB_REFERENCE_IMAGE::GetWidth() const
{
return m_referenceImage.GetImage().GetSize().x;
}
void PCB_REFERENCE_IMAGE::SetWidth( int aWidth )
{
m_referenceImage.SetWidth( aWidth );
}
int PCB_REFERENCE_IMAGE::GetHeight() const
{
return m_referenceImage.GetImage().GetSize().y;
}
void PCB_REFERENCE_IMAGE::SetHeight( int aHeight )
{
m_referenceImage.SetHeight( aHeight );
}
static struct PCB_REFERENCE_IMAGE_DESC
{
PCB_REFERENCE_IMAGE_DESC()
@ -340,6 +364,20 @@ static struct PCB_REFERENCE_IMAGE_DESC
PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_Y_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>(
_HKI( "Width" ),
&PCB_REFERENCE_IMAGE::SetWidth,
&PCB_REFERENCE_IMAGE::GetWidth,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>(
_HKI( "Height" ),
&PCB_REFERENCE_IMAGE::SetHeight,
&PCB_REFERENCE_IMAGE::GetHeight,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
// For future use
const wxString greyscale = _HKI( "Greyscale" );
}

View File

@ -117,6 +117,10 @@ private:
friend struct PCB_REFERENCE_IMAGE_DESC;
// Property manager interfaces
int GetWidth() const;
void SetWidth( int aWidth );
int GetHeight() const;
void SetHeight( int aHeight );
int GetTransformOriginOffsetX() const;
void SetTransformOriginOffsetX( int aX );
int GetTransformOriginOffsetY() const;