2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
|
2021-12-12 22:01:13 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-03-23 17:26:32 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors.
|
2011-10-31 20:49:48 +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
|
|
|
|
*/
|
|
|
|
|
2022-01-07 00:47:23 +00:00
|
|
|
#include <pgm_base.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <font/font.h>
|
2022-01-07 00:47:23 +00:00
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <eeschema_settings.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_symbol.h>
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2020-10-15 08:48:02 +00:00
|
|
|
const int fill_tab[3] = { 'N', 'F', 'f' };
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
|
2024-01-26 16:16:13 +00:00
|
|
|
EDA_ITEM( aSymbol, aType ),
|
|
|
|
m_unit( aUnit ),
|
|
|
|
m_bodyStyle( aConvert ),
|
|
|
|
m_private( false )
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 18:11:10 +00:00
|
|
|
wxString LIB_ITEM::GetUnitDescription( int aUnit )
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
2024-01-26 18:11:10 +00:00
|
|
|
if( aUnit == 0 )
|
|
|
|
return _( "All" );
|
|
|
|
else
|
|
|
|
return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
|
|
|
|
}
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
|
2024-01-26 18:11:10 +00:00
|
|
|
wxString LIB_ITEM::GetBodyStyleDescription( int aBodyStyle )
|
|
|
|
{
|
|
|
|
if( aBodyStyle == 0 )
|
|
|
|
return _( "All" );
|
|
|
|
else if( aBodyStyle == LIB_ITEM::BODY_STYLE::DEMORGAN )
|
|
|
|
return _( "Alternate" );
|
|
|
|
else if( aBodyStyle == LIB_ITEM::BODY_STYLE::BASE )
|
|
|
|
return _( "Standard" );
|
2010-10-08 20:40:57 +00:00
|
|
|
else
|
2024-01-26 18:11:10 +00:00
|
|
|
return wxT( "?" );
|
|
|
|
}
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2024-01-26 18:11:10 +00:00
|
|
|
void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Type" ), GetTypeName() );
|
|
|
|
|
|
|
|
if( LIB_SYMBOL* parent = GetParent() )
|
|
|
|
{
|
|
|
|
if( parent->GetUnitCount() )
|
|
|
|
aList.emplace_back( _( "Unit" ), GetUnitDescription( m_unit ) );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2024-01-26 18:11:10 +00:00
|
|
|
if( parent->HasAlternateBodyStyle() )
|
|
|
|
aList.emplace_back( _( "Body Style" ), GetBodyStyleDescription( m_bodyStyle ) );
|
|
|
|
}
|
2022-01-31 19:11:21 +00:00
|
|
|
|
|
|
|
if( IsPrivate() )
|
|
|
|
aList.emplace_back( _( "Private" ), wxEmptyString );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-03 12:20:30 +00:00
|
|
|
int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
|
2020-02-13 13:39:52 +00:00
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return Type() - aOther.Type();
|
|
|
|
|
|
|
|
// When comparing unit LIB_ITEM objects, we ignore the unit number.
|
2021-01-26 22:54:10 +00:00
|
|
|
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
|
|
|
|
return m_unit - aOther.m_unit;
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_bodyStyle != aOther.m_bodyStyle )
|
|
|
|
return m_bodyStyle - aOther.m_bodyStyle;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
if( IsPrivate() != aOther.IsPrivate() )
|
|
|
|
return IsPrivate() < aOther.IsPrivate();
|
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-09 17:41:18 +00:00
|
|
|
bool LIB_ITEM::cmp_items::operator()( const LIB_ITEM* aFirst, const LIB_ITEM* aSecond ) const
|
|
|
|
{
|
|
|
|
return aFirst->compare( *aSecond, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
2021-11-02 20:06:37 +00:00
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return false;
|
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
return compare( aOther, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
2021-11-02 20:06:37 +00:00
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return Type() < aOther.Type();
|
|
|
|
|
2012-02-27 23:02:08 +00:00
|
|
|
return ( compare( aOther ) < 0 );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_ITEM* LIB_ITEM::Duplicate() const
|
|
|
|
{
|
|
|
|
LIB_ITEM* dupe = static_cast<LIB_ITEM*>( Clone() );
|
|
|
|
const_cast<KIID&>( dupe->m_Uuid ) = KIID();
|
|
|
|
|
|
|
|
return dupe;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2019-05-05 10:33:34 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
2019-05-05 10:33:34 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I sel = aRect;
|
2019-05-05 10:33:34 +00:00
|
|
|
|
|
|
|
if ( aAccuracy )
|
2019-05-10 22:24:27 +00:00
|
|
|
sel.Inflate( aAccuracy );
|
2019-05-05 10:33:34 +00:00
|
|
|
|
|
|
|
if( aContained )
|
2019-05-10 22:24:27 +00:00
|
|
|
return sel.Contains( GetBoundingBox() );
|
2019-05-05 10:33:34 +00:00
|
|
|
|
2019-05-10 22:24:27 +00:00
|
|
|
return sel.Intersects( GetBoundingBox() );
|
2019-05-05 10:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 00:47:23 +00:00
|
|
|
const wxString& LIB_ITEM::GetDefaultFont() const
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
|
|
|
|
|
|
|
return cfg->m_Appearance.default_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
const KIFONT::METRICS& LIB_ITEM::GetFontMetrics() const
|
|
|
|
{
|
|
|
|
return KIFONT::METRICS::Default();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed )
|
2010-10-20 20:24:26 +00:00
|
|
|
{
|
2022-09-16 16:20:36 +00:00
|
|
|
print( aSettings, aOffset, aData, aTransform, aDimmed );
|
2010-10-20 20:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 3;
|
2018-10-21 12:50:31 +00:00
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
2019-07-30 01:57:41 +00:00
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|