2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2024-04-02 17:28:17 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-19 20:32:21 +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>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <eeschema_settings.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2023-04-08 15:22:34 +00:00
|
|
|
#include <sch_connection.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2024-04-05 21:35:32 +00:00
|
|
|
#include <symbol.h>
|
2024-05-13 20:41:31 +00:00
|
|
|
#include <connection_graph.h>
|
2023-04-08 15:22:34 +00:00
|
|
|
#include <trace_helpers.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2020-07-08 18:29:16 +00:00
|
|
|
#include <netclass.h>
|
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2009-04-05 21:07:24 +00:00
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2022-05-13 21:36:20 +00:00
|
|
|
// Rendering fonts is expensive (particularly when using outline fonts). At small effective
|
|
|
|
// sizes (ie: zoomed out) the visual differences between outline and/or stroke fonts and the
|
|
|
|
// bitmap font becomes immaterial, and there's often more to draw when zoomed out so the
|
|
|
|
// performance gain becomes more significant.
|
|
|
|
#define BITMAP_FONT_SIZE_THRESHOLD 3
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
wxString SCH_ITEM::GetUnitDescription( int aUnit )
|
|
|
|
{
|
|
|
|
if( aUnit == 0 )
|
|
|
|
return _( "All" );
|
|
|
|
else
|
|
|
|
return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_ITEM::GetBodyStyleDescription( int aBodyStyle )
|
|
|
|
{
|
|
|
|
if( aBodyStyle == 0 )
|
|
|
|
return _( "All" );
|
|
|
|
else if( aBodyStyle == BODY_STYLE::DEMORGAN )
|
|
|
|
return _( "Alternate" );
|
|
|
|
else if( aBodyStyle == BODY_STYLE::BASE )
|
|
|
|
return _( "Standard" );
|
|
|
|
else
|
|
|
|
return wxT( "?" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 21:07:24 +00:00
|
|
|
/* Constructor and destructor for SCH_ITEM */
|
2022-01-07 00:47:23 +00:00
|
|
|
/* They are not inline because this creates problems with gcc at linking time in debug mode */
|
2009-04-05 21:07:24 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType, int aUnit, int aBodyStyle ) :
|
|
|
|
EDA_ITEM( aParent, aType ),
|
|
|
|
m_unit( aUnit ),
|
|
|
|
m_bodyStyle( aBodyStyle ),
|
|
|
|
m_private( false )
|
2009-04-05 21:07:24 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
m_layer = LAYER_WIRE; // It's only a default, in fact
|
2020-05-13 02:00:37 +00:00
|
|
|
m_fieldsAutoplaced = FIELDS_AUTOPLACED_NO;
|
2021-11-24 13:19:50 +00:00
|
|
|
m_connectivity_dirty = false; // Item is unconnected until it is placed, so it's clean
|
2009-04-05 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_ITEM::SCH_ITEM( const SCH_ITEM& aItem ) :
|
|
|
|
EDA_ITEM( aItem )
|
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = aItem.m_layer;
|
2024-04-06 13:14:44 +00:00
|
|
|
m_unit = aItem.m_unit;
|
|
|
|
m_bodyStyle = aItem.m_bodyStyle;
|
|
|
|
m_private = aItem.m_private;
|
2020-05-13 02:00:37 +00:00
|
|
|
m_fieldsAutoplaced = aItem.m_fieldsAutoplaced;
|
2021-11-25 00:50:00 +00:00
|
|
|
m_connectivity_dirty = aItem.m_connectivity_dirty;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-21 16:54:00 +00:00
|
|
|
SCH_ITEM& SCH_ITEM::operator=( const SCH_ITEM& aItem )
|
|
|
|
{
|
|
|
|
m_layer = aItem.m_layer;
|
2024-04-06 13:14:44 +00:00
|
|
|
m_unit = aItem.m_unit;
|
|
|
|
m_bodyStyle = aItem.m_bodyStyle;
|
|
|
|
m_private = aItem.m_private;
|
2021-11-21 16:54:00 +00:00
|
|
|
m_fieldsAutoplaced = aItem.m_fieldsAutoplaced;
|
2021-11-25 00:50:00 +00:00
|
|
|
m_connectivity_dirty = aItem.m_connectivity_dirty;
|
2021-11-21 16:54:00 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 21:07:24 +00:00
|
|
|
SCH_ITEM::~SCH_ITEM()
|
|
|
|
{
|
2019-04-25 20:04:01 +00:00
|
|
|
for( const auto& it : m_connection_map )
|
|
|
|
delete it.second;
|
2024-05-13 20:41:31 +00:00
|
|
|
|
|
|
|
SCHEMATIC* sch = Schematic();
|
|
|
|
|
|
|
|
if( sch != nullptr )
|
|
|
|
sch->ConnectionGraph()->RemoveItem( this );
|
2009-04-05 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
SCH_ITEM* SCH_ITEM::Duplicate( bool doClone ) const
|
2019-05-04 13:02:05 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* newItem = (SCH_ITEM*) Clone();
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( !doClone )
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( newItem->m_Uuid ) = KIID();
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-06-27 16:06:01 +00:00
|
|
|
newItem->ClearFlags( SELECTED | BRIGHTENED );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
newItem->RunOnChildren(
|
|
|
|
[]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
aChild->ClearFlags( SELECTED | BRIGHTENED );
|
|
|
|
} );
|
2019-05-04 13:02:05 +00:00
|
|
|
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCHEMATIC* SCH_ITEM::Schematic() const
|
|
|
|
{
|
2024-06-14 14:57:57 +00:00
|
|
|
if( !SCHEMATIC::m_IsSchematicExists )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
EDA_ITEM* parent = GetParent();
|
|
|
|
|
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
if( parent->Type() == SCHEMATIC_T )
|
|
|
|
return static_cast<SCHEMATIC*>( parent );
|
|
|
|
else
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
const SYMBOL* SCH_ITEM::GetParentSymbol() const
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
const EDA_ITEM* parent = GetParent();
|
2024-04-05 21:35:32 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
if( parent->Type() == SCH_SYMBOL_T )
|
|
|
|
return static_cast<const SCH_SYMBOL*>( parent );
|
|
|
|
else if( parent->Type() == LIB_SYMBOL_T )
|
|
|
|
return static_cast<const LIB_SYMBOL*>( parent );
|
|
|
|
else
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2024-04-05 21:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SYMBOL* SCH_ITEM::GetParentSymbol()
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
EDA_ITEM* parent = GetParent();
|
2024-04-05 21:35:32 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
if( parent->Type() == SCH_SYMBOL_T )
|
|
|
|
return static_cast<SCH_SYMBOL*>( parent );
|
|
|
|
else if( parent->Type() == LIB_SYMBOL_T )
|
|
|
|
return static_cast<LIB_SYMBOL*>( parent );
|
|
|
|
else
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2024-04-05 21:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
2024-04-06 13:14:44 +00:00
|
|
|
aCount = 3;
|
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_ITEM::IsConnected( const VECTOR2I& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if(( m_flags & STRUCT_DELETED ) || ( m_flags & SKIP_STRUCT ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
return false;
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
return doIsConnected( aPosition );
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH* aSheet ) const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
if( !IsConnectable() )
|
|
|
|
return nullptr;
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
if( !aSheet )
|
|
|
|
aSheet = &Schematic()->CurrentSheet();
|
2019-04-19 15:54:29 +00:00
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
auto it = m_connection_map.find( *aSheet );
|
|
|
|
|
|
|
|
if( it == m_connection_map.end() )
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return it->second;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
void SCH_ITEM::SetConnectionGraph( CONNECTION_GRAPH* aGraph )
|
|
|
|
{
|
|
|
|
for( auto& [path, conn] : m_connection_map )
|
2023-09-19 01:02:41 +00:00
|
|
|
{
|
2023-04-08 15:22:34 +00:00
|
|
|
conn->SetGraph( aGraph );
|
2023-09-19 01:02:41 +00:00
|
|
|
|
|
|
|
for( auto& member : conn->AllMembers() )
|
|
|
|
member->SetGraph( aGraph );
|
|
|
|
}
|
2023-04-08 15:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NETCLASS> SCH_ITEM::GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet ) const
|
2020-07-08 18:29:16 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
static std::shared_ptr<NETCLASS> nullNetclass = std::make_shared<NETCLASS>( wxEmptyString );
|
|
|
|
|
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
|
|
|
|
if( schematic )
|
2020-07-08 18:29:16 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = schematic->Prj().GetProjectFile().m_NetSettings;
|
|
|
|
SCH_CONNECTION* connection = Connection( aSheet );
|
2020-10-07 14:40:12 +00:00
|
|
|
|
|
|
|
if( connection )
|
2022-08-14 11:03:18 +00:00
|
|
|
return netSettings->GetEffectiveNetClass( connection->Name() );
|
|
|
|
else
|
|
|
|
return netSettings->m_DefaultNetClass;
|
2020-07-08 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return nullNetclass;
|
2020-07-08 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-10 23:40:43 +00:00
|
|
|
void SCH_ITEM::ClearConnectedItems( const SCH_SHEET_PATH& aSheet )
|
|
|
|
{
|
|
|
|
auto it = m_connected_items.find( aSheet );
|
|
|
|
|
|
|
|
if( it != m_connected_items.end() )
|
|
|
|
it->second.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const SCH_ITEM_VEC& SCH_ITEM::ConnectedItems( const SCH_SHEET_PATH& aSheet )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
return m_connected_items[ aSheet ];
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
void SCH_ITEM::AddConnectionTo( const SCH_SHEET_PATH& aSheet, SCH_ITEM* aItem )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2024-04-10 23:40:43 +00:00
|
|
|
SCH_ITEM_VEC& vec = m_connected_items[ aSheet ];
|
2022-03-11 21:46:21 +00:00
|
|
|
|
2022-02-28 23:56:30 +00:00
|
|
|
// The vector elements are small, so reserve 1k at a time to prevent re-allocations
|
2024-04-10 23:40:43 +00:00
|
|
|
if( vec.size() == vec.capacity() )
|
|
|
|
vec.reserve( vec.size() + 4096 );
|
|
|
|
|
|
|
|
// Add item to the correct place in the sorted vector if it is not already there
|
|
|
|
auto it = std::lower_bound( vec.begin(), vec.end(), aItem );
|
2022-02-28 23:56:30 +00:00
|
|
|
|
2024-04-10 23:40:43 +00:00
|
|
|
if( it == vec.end() || *it != aItem )
|
|
|
|
vec.insert( it, aItem );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-30 00:27:08 +00:00
|
|
|
SCH_CONNECTION* SCH_ITEM::InitializeConnection( const SCH_SHEET_PATH& aSheet,
|
|
|
|
CONNECTION_GRAPH* aGraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* connection = Connection( &aSheet );
|
|
|
|
|
2023-09-19 22:52:26 +00:00
|
|
|
// N.B. Do not clear the dirty connectivity flag here because we may need
|
|
|
|
// to create a connection for a different sheet, and we don't want to
|
|
|
|
// skip the connection creation because the flag is cleared.
|
2020-10-07 14:40:12 +00:00
|
|
|
if( connection )
|
|
|
|
{
|
|
|
|
connection->Reset();
|
|
|
|
}
|
|
|
|
else
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
connection = new SCH_CONNECTION( this );
|
|
|
|
m_connection_map.insert( std::make_pair( aSheet, connection ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 15:32:54 +00:00
|
|
|
connection->SetGraph( aGraph );
|
2019-03-11 21:32:05 +00:00
|
|
|
connection->SetSheet( aSheet );
|
2019-04-05 22:27:09 +00:00
|
|
|
return connection;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* SCH_ITEM::GetOrInitConnection( const SCH_SHEET_PATH& aSheet,
|
|
|
|
CONNECTION_GRAPH* aGraph )
|
|
|
|
{
|
2022-03-11 21:46:21 +00:00
|
|
|
if( !IsConnectable() )
|
|
|
|
return nullptr;
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* connection = Connection( &aSheet );
|
|
|
|
|
|
|
|
if( connection )
|
|
|
|
return connection;
|
|
|
|
else
|
|
|
|
return InitializeConnection( aSheet, aGraph );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-07 20:43:36 +00:00
|
|
|
const wxString& SCH_ITEM::GetCachedDriverName() const
|
|
|
|
{
|
|
|
|
static wxString s_empty;
|
|
|
|
return s_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
void SCH_ITEM::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( GetClass() );
|
2011-04-05 14:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-08 17:37:47 +00:00
|
|
|
void SCH_ITEM::SwapFlags( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
EDA_ITEM_FLAGS editFlags = GetEditFlags();
|
|
|
|
EDA_ITEM_FLAGS tempFlags = GetTempFlags();
|
|
|
|
EDA_ITEM_FLAGS aItem_editFlags = aItem->GetEditFlags();
|
|
|
|
EDA_ITEM_FLAGS aItem_tempFlags = aItem->GetTempFlags();
|
|
|
|
|
|
|
|
std::swap( m_flags, aItem->m_flags );
|
|
|
|
|
|
|
|
ClearEditFlags();
|
|
|
|
SetFlags( editFlags );
|
|
|
|
ClearTempFlags();
|
|
|
|
SetFlags( tempFlags );
|
|
|
|
|
|
|
|
aItem->ClearEditFlags();
|
|
|
|
aItem->SetFlags( aItem_editFlags );
|
|
|
|
aItem->ClearTempFlags();
|
|
|
|
aItem->SetFlags( aItem_tempFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
void SCH_ITEM::ClearCaches()
|
|
|
|
{
|
|
|
|
auto clearTextCaches =
|
|
|
|
[]( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
|
|
|
|
|
|
|
|
if( text )
|
|
|
|
{
|
|
|
|
text->ClearBoundingBoxCache();
|
|
|
|
text->ClearRenderCache();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
clearTextCaches( this );
|
|
|
|
|
|
|
|
RunOnChildren( clearTextCaches );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
bool SCH_ITEM::operator==( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return compare( aOther, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_ITEM::operator<( const SCH_ITEM& aOther ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return Type() < aOther.Type();
|
2020-01-28 15:42:42 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
return ( compare( aOther ) < 0 );
|
|
|
|
}
|
2020-01-28 15:42:42 +00:00
|
|
|
|
2021-01-05 18:00:11 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
bool SCH_ITEM::cmp_items::operator()( const SCH_ITEM* aFirst, const SCH_ITEM* aSecond ) const
|
|
|
|
{
|
|
|
|
return aFirst->compare( *aSecond, COMPARE_FLAGS::EQUALITY ) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_ITEM::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return Type() - aOther.Type();
|
|
|
|
|
|
|
|
if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
|
|
|
|
return m_unit - aOther.m_unit;
|
|
|
|
|
|
|
|
if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_bodyStyle != aOther.m_bodyStyle )
|
|
|
|
return m_bodyStyle - aOther.m_bodyStyle;
|
|
|
|
|
|
|
|
if( IsPrivate() != aOther.IsPrivate() )
|
2024-04-25 17:44:46 +00:00
|
|
|
return IsPrivate() ? 1 : -1;
|
2024-04-06 13:14:44 +00:00
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::SKIP_TST_POS ) )
|
|
|
|
{
|
|
|
|
if( GetPosition().x != aOther.GetPosition().x )
|
|
|
|
return GetPosition().x - aOther.GetPosition().x;
|
2024-04-06 13:14:44 +00:00
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
if( GetPosition().y != aOther.GetPosition().y )
|
|
|
|
return GetPosition().y - aOther.GetPosition().y;
|
|
|
|
}
|
2024-04-06 13:14:44 +00:00
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
|
|
|
|
|| ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
return 0;
|
2024-04-25 17:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Uuid < aOther.m_Uuid )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( m_Uuid > aOther.m_Uuid )
|
|
|
|
return 1;
|
2024-04-06 13:14:44 +00:00
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
return 0;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2022-01-07 00:47:23 +00:00
|
|
|
const wxString& SCH_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& SCH_ITEM::GetFontMetrics() const
|
|
|
|
{
|
|
|
|
if( SCHEMATIC* schematic = Schematic() )
|
|
|
|
return schematic->Settings().m_FontMetrics;
|
|
|
|
|
|
|
|
return KIFONT::METRICS::Default();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
int SCH_ITEM::GetEffectivePenWidth( const SCH_RENDER_SETTINGS* aSettings ) const
|
|
|
|
{
|
|
|
|
// For historical reasons, a stored value of 0 means "default width" and negative
|
|
|
|
// numbers meant "don't stroke".
|
|
|
|
|
|
|
|
if( GetPenWidth() < 0 )
|
|
|
|
return 0;
|
|
|
|
else if( GetPenWidth() == 0 )
|
|
|
|
return std::max( aSettings->GetDefaultPenWidth(), aSettings->GetMinPenWidth() );
|
|
|
|
else
|
|
|
|
return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-13 21:36:20 +00:00
|
|
|
bool SCH_ITEM::RenderAsBitmap( double aWorldScale ) const
|
|
|
|
{
|
2022-08-27 18:14:57 +00:00
|
|
|
if( IsHypertext() )
|
|
|
|
return false;
|
|
|
|
|
2022-05-13 21:36:20 +00:00
|
|
|
if( const EDA_TEXT* text = dynamic_cast<const EDA_TEXT*>( this ) )
|
|
|
|
return text->GetTextHeight() * aWorldScale < BITMAP_FONT_SIZE_THRESHOLD;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
void SCH_ITEM::getSymbolEditorMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Type" ), GetFriendlyName() );
|
|
|
|
|
|
|
|
if( const SYMBOL* parent = GetParentSymbol() )
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
if( parent->GetUnitCount() )
|
|
|
|
aList.emplace_back( _( "Unit" ), GetUnitDescription( m_unit ) );
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
if( parent->HasAlternateBodyStyle() )
|
|
|
|
aList.emplace_back( _( "Body Style" ), GetBodyStyleDescription( m_bodyStyle ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( IsPrivate() )
|
|
|
|
aList.emplace_back( _( "Private" ), wxEmptyString );
|
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
static struct SCH_ITEM_DESC
|
|
|
|
{
|
|
|
|
SCH_ITEM_DESC()
|
|
|
|
{
|
2023-06-21 01:57:20 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_ITEM );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_ITEM ), TYPE_HASH( EDA_ITEM ) );
|
|
|
|
|
2024-01-24 15:17:39 +00:00
|
|
|
#ifdef NOTYET
|
2023-06-21 01:57:20 +00:00
|
|
|
// Not yet functional in UI
|
2024-01-24 15:17:39 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_ITEM, bool>( _HKI( "Locked" ),
|
|
|
|
&SCH_ITEM::SetLocked, &SCH_ITEM::IsLocked ) );
|
|
|
|
#endif
|
2024-04-06 13:14:44 +00:00
|
|
|
|
|
|
|
auto multiUnit =
|
|
|
|
[=]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( const SYMBOL* symbol = schItem->GetParentSymbol() )
|
|
|
|
return symbol->IsMulti();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto multiBodyStyle =
|
|
|
|
[=]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( const SYMBOL* symbol = schItem->GetParentSymbol() )
|
|
|
|
return symbol->HasAlternateBodyStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_ITEM, int>( _HKI( "Unit" ),
|
|
|
|
&SCH_ITEM::SetUnit, &SCH_ITEM::GetUnit ) )
|
|
|
|
.SetAvailableFunc( multiUnit )
|
|
|
|
.SetIsHiddenFromDesignEditors();
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_ITEM, int>( _HKI( "Body Style" ),
|
|
|
|
&SCH_ITEM::SetBodyStyle, &SCH_ITEM::GetBodyStyle ) )
|
|
|
|
.SetAvailableFunc( multiBodyStyle )
|
|
|
|
.SetIsHiddenFromDesignEditors();
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_ITEM, bool>( _HKI( "Private" ),
|
|
|
|
&SCH_ITEM::SetPrivate, &SCH_ITEM::IsPrivate ) )
|
|
|
|
.SetIsHiddenFromDesignEditors();
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
} _SCH_ITEM_DESC;
|
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
IMPLEMENT_ENUM_TO_WXANY( SCH_LAYER_ID )
|
2024-02-12 08:01:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
static bool lessYX( const DANGLING_END_ITEM& a, const DANGLING_END_ITEM& b )
|
|
|
|
{
|
|
|
|
const auto aPos = a.GetPosition();
|
|
|
|
const auto bPos = b.GetPosition();
|
|
|
|
return aPos.y < bPos.y ? true : ( aPos.y > bPos.y ? false : aPos.x < bPos.x );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static bool lessType( const DANGLING_END_ITEM& a, const DANGLING_END_ITEM& b )
|
|
|
|
{
|
|
|
|
return a.GetType() < b.GetType();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<DANGLING_END_ITEM>::iterator
|
|
|
|
DANGLING_END_ITEM_HELPER::get_lower_pos( std::vector<DANGLING_END_ITEM>& aItemListByPos,
|
|
|
|
const VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM needle = DANGLING_END_ITEM( PIN_END, nullptr, aPos );
|
|
|
|
auto start = aItemListByPos.begin();
|
|
|
|
auto end = aItemListByPos.end();
|
|
|
|
return std::lower_bound( start, end, needle, lessYX );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<DANGLING_END_ITEM>::iterator
|
|
|
|
DANGLING_END_ITEM_HELPER::get_lower_type( std::vector<DANGLING_END_ITEM>& aItemListByType,
|
|
|
|
const DANGLING_END_T& aType )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM needle = DANGLING_END_ITEM( aType, nullptr, VECTOR2I{} );
|
|
|
|
auto start = aItemListByType.begin();
|
|
|
|
auto end = aItemListByType.end();
|
|
|
|
return std::lower_bound( start, end, needle, lessType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DANGLING_END_ITEM_HELPER::sort_dangling_end_items(
|
|
|
|
std::vector<DANGLING_END_ITEM>& aItemListByType,
|
|
|
|
std::vector<DANGLING_END_ITEM>& aItemListByPos )
|
|
|
|
{
|
|
|
|
// WIRE_END pairs must be kept together. Hence stable sort.
|
|
|
|
std::stable_sort( aItemListByType.begin(), aItemListByType.end(), lessType );
|
|
|
|
// Sort by y first, pins are more likely to share x than y.
|
|
|
|
std::sort( aItemListByPos.begin(), aItemListByPos.end(), lessYX );
|
|
|
|
}
|