kicad/eeschema/lib_item.cpp

157 lines
4.3 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors.
*
* 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>
#include <settings/settings_manager.h>
#include <eeschema_settings.h>
#include <sch_draw_panel.h>
#include <widgets/msgpanel.h>
#include <lib_symbol.h>
const int fill_tab[3] = { 'N', 'F', 'f' };
LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
EDA_ITEM( aSymbol, aType ),
m_unit( aUnit ),
m_convert( aConvert ),
m_private( false )
{
}
void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
wxString msg;
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Type" ), GetTypeName() );
2021-01-26 22:54:10 +00:00
if( m_unit == 0 )
msg = _( "All" );
else
msg = LIB_SYMBOL::SubReference( m_unit, false );
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Unit" ), msg );
2021-01-26 22:54:10 +00:00
if( m_convert == LIB_ITEM::LIB_CONVERT::BASE )
msg = _( "no" );
2021-01-26 22:54:10 +00:00
else if( m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
msg = _( "yes" );
else
msg = wxT( "?" );
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Converted" ), msg );
if( IsPrivate() )
aList.emplace_back( _( "Private" ), wxEmptyString );
}
int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
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;
2021-01-26 22:54:10 +00:00
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_convert != aOther.m_convert )
2021-01-31 16:48:05 +00:00
return m_convert - aOther.m_convert;
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
2020-04-16 16:43:50 +00:00
if( IsPrivate() != aOther.IsPrivate() )
return IsPrivate() < aOther.IsPrivate();
return 0;
}
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;
}
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
{
if( Type() != aOther.Type() )
return false;
return compare( aOther, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
}
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
{
if( Type() != aOther.Type() )
return Type() < aOther.Type();
return ( compare( aOther ) < 0 );
}
2022-08-31 09:33:46 +00:00
bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
2020-11-14 18:11:28 +00:00
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
2022-08-31 09:33:46 +00:00
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
if( aContained )
return sel.Contains( GetBoundingBox() );
return sel.Intersects( GetBoundingBox() );
}
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;
}
void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
const TRANSFORM& aTransform, bool aDimmed )
{
print( aSettings, aOffset, aData, aTransform, aDimmed );
}
void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
// Basic fallback
aCount = 3;
aLayers[0] = LAYER_DEVICE;
aLayers[1] = LAYER_DEVICE_BACKGROUND;
aLayers[2] = LAYER_SELECTION_SHADOWS;
}