2011-08-31 14:59:20 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 jean-pierre.charras
|
2023-09-25 10:06:23 +00:00
|
|
|
* Copyright (C) 2011-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
/**
|
|
|
|
* @file sch_bitmap.cpp
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2019-07-05 08:25:23 +00:00
|
|
|
#include <base_units.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <common.h>
|
2020-04-24 13:36:10 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_bitmap.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_BITMAP::SCH_BITMAP( const VECTOR2I& pos ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_ITEM( nullptr, SCH_BITMAP_T )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
m_pos = pos;
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = LAYER_NOTES; // used only to draw/plot a rectangle,
|
2011-08-31 14:59:20 +00:00
|
|
|
// when a bitmap cannot be drawn or plotted
|
2023-04-22 14:13:55 +00:00
|
|
|
m_bitmapBase = new BITMAP_BASE();
|
2023-09-25 10:06:23 +00:00
|
|
|
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) :
|
|
|
|
SCH_ITEM( aSchBitmap )
|
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
m_pos = aSchBitmap.m_pos;
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = aSchBitmap.m_layer;
|
2023-04-22 14:13:55 +00:00
|
|
|
m_bitmapBase = new BITMAP_BASE( *aSchBitmap.m_bitmapBase );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
SCH_BITMAP& SCH_BITMAP::operator=( const SCH_ITEM& aItem )
|
2012-01-09 20:26:55 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( Type() == aItem.Type(), *this,
|
|
|
|
wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
|
|
|
|
GetClass() );
|
|
|
|
|
|
|
|
if( &aItem != this )
|
|
|
|
{
|
|
|
|
SCH_ITEM::operator=( aItem );
|
|
|
|
|
|
|
|
SCH_BITMAP* bitmap = (SCH_BITMAP*) &aItem;
|
|
|
|
|
2023-04-22 14:13:55 +00:00
|
|
|
delete m_bitmapBase;
|
|
|
|
m_bitmapBase = new BITMAP_BASE( *bitmap->m_bitmapBase );
|
2016-07-11 19:48:46 +00:00
|
|
|
m_pos = bitmap->m_pos;
|
2012-01-09 20:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
bool SCH_BITMAP::ReadImageFile( const wxString& aFullFilename )
|
|
|
|
{
|
2023-04-22 14:13:55 +00:00
|
|
|
if( m_bitmapBase->ReadImageFile( aFullFilename ) )
|
2023-01-17 16:19:44 +00:00
|
|
|
{
|
2023-09-25 10:06:23 +00:00
|
|
|
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
|
2023-01-17 16:19:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-07 01:16:20 +00:00
|
|
|
bool SCH_BITMAP::ReadImageFile( wxMemoryBuffer& aBuffer )
|
|
|
|
{
|
|
|
|
if( m_bitmapBase->ReadImageFile( aBuffer ) )
|
|
|
|
{
|
2023-09-25 10:06:23 +00:00
|
|
|
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
|
2023-09-07 01:16:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_BITMAP::Clone() const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
|
|
|
return new SCH_BITMAP( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_BITMAP::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
2023-07-08 17:37:47 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
|
2021-07-16 20:13:26 +00:00
|
|
|
wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
|
|
|
|
aItem->GetClass() ) );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
SCH_BITMAP* item = (SCH_BITMAP*) aItem;
|
2016-07-11 19:48:46 +00:00
|
|
|
std::swap( m_pos, item->m_pos );
|
2023-04-22 14:13:55 +00:00
|
|
|
std::swap( m_bitmapBase, item->m_bitmapBase );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_BITMAP::GetBoundingBox() const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2023-04-22 14:13:55 +00:00
|
|
|
BOX2I bbox = m_bitmapBase->GetBoundingBox();
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.Move( m_pos );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return bbox;
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
void SCH_BITMAP::Print( const SCH_RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = m_pos + aOffset;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2023-07-02 22:59:38 +00:00
|
|
|
m_bitmapBase->DrawBitmap( aSettings->GetPrintDC(), pos, aSettings->GetBackgroundColor() );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
VECTOR2I SCH_BITMAP::GetSize() const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2023-04-22 14:13:55 +00:00
|
|
|
return m_bitmapBase->GetSize();
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_BITMAP::MirrorVertically( int aCenter )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2023-04-22 14:13:55 +00:00
|
|
|
m_bitmapBase->Mirror( true );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_BITMAP::MirrorHorizontally( int aCenter )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.x, aCenter );
|
2023-04-22 14:13:55 +00:00
|
|
|
m_bitmapBase->Mirror( false );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void SCH_BITMAP::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2024-04-04 22:51:22 +00:00
|
|
|
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_270 : ANGLE_90 );
|
|
|
|
m_bitmapBase->Rotate( aRotateCCW );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_BITMAP::Show( int nestLevel, std::ostream& os ) const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I rect = GetBoundingBox();
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
return rect.Contains( aPosition );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_BITMAP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I rect = aRect;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
void SCH_BITMAP::Plot( PLOTTER* aPlotter, bool aBackground,
|
|
|
|
const SCH_PLOT_SETTINGS& aPlotSettings ) const
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
{
|
2023-04-22 14:13:55 +00:00
|
|
|
m_bitmapBase->PlotImage( aPlotter, m_pos,
|
2023-10-21 20:52:51 +00:00
|
|
|
aPlotter->RenderSettings()->GetLayerColor( GetLayer() ),
|
|
|
|
aPlotter->RenderSettings()->GetDefaultPenWidth() );
|
2022-02-10 19:49:25 +00:00
|
|
|
}
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
2017-02-20 12:20:39 +00:00
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_BITMAP::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::image;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
2018-10-16 12:20:09 +00:00
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_BITMAP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2019-07-05 08:25:23 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Bitmap" ), wxEmptyString );
|
2019-07-05 08:25:23 +00:00
|
|
|
|
2023-04-22 14:13:55 +00:00
|
|
|
aList.emplace_back( _( "PPI" ), wxString::Format( wxT( "%d "), GetImage()->GetPPI() ) );
|
|
|
|
aList.emplace_back( _( "Scale" ), wxString::Format( wxT( "%f "), GetImageScale() ) );
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetSize().x ) );
|
|
|
|
aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetSize().y ) );
|
2019-07-05 08:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-16 12:20:09 +00:00
|
|
|
void SCH_BITMAP::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2019-08-01 04:52:22 +00:00
|
|
|
aCount = 2;
|
2019-02-08 05:26:27 +00:00
|
|
|
aLayers[0] = LAYER_DRAW_BITMAPS;
|
2019-08-01 04:52:22 +00:00
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
2018-10-16 12:20:09 +00:00
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct SCH_BITMAP_DESC
|
|
|
|
{
|
|
|
|
SCH_BITMAP_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_BITMAP );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_BITMAP ), TYPE_HASH( SCH_ITEM ) );
|
|
|
|
}
|
|
|
|
} _SCH_BITMAP_DESC;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_BITMAP::operator==( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_BITMAP* bitmap = static_cast<const SCH_BITMAP*>( &aItem );
|
|
|
|
|
|
|
|
if( GetPosition() != bitmap->GetPosition() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetSize() != bitmap->GetSize() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetImage() != bitmap->GetImage() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_BITMAP::Similarity( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
if( m_Uuid == aItem.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
const SCH_BITMAP* bitmap = static_cast<const SCH_BITMAP*>( &aItem );
|
|
|
|
|
|
|
|
if( GetImage() != bitmap->GetImage() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
// If it is the same image but a different UUID and a different size,
|
|
|
|
// then it _might be different_.
|
|
|
|
if( GetSize() != bitmap->GetSize() )
|
|
|
|
return 0.5;
|
|
|
|
|
|
|
|
return 1.0;
|
|
|
|
}
|