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
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 1992-2021 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
|
|
|
|
*/
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.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>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-05-04 13:02:05 +00:00
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_pin.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.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
|
|
|
|
2009-04-05 21:07:24 +00:00
|
|
|
/* Constructor and destructor for SCH_ITEM */
|
|
|
|
/* They are not inline because this creates problems with gcc at linking time
|
|
|
|
* in debug mode
|
2011-06-17 13:24:22 +00:00
|
|
|
*/
|
2009-04-05 21:07:24 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) :
|
|
|
|
EDA_ITEM( aParent, aType )
|
2009-04-05 21:07:24 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +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;
|
2019-03-30 15:57:30 +00:00
|
|
|
m_connectivity_dirty = true;
|
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;
|
2020-05-13 02:00:37 +00:00
|
|
|
m_fieldsAutoplaced = aItem.m_fieldsAutoplaced;
|
2019-03-30 15:57:30 +00:00
|
|
|
m_connectivity_dirty = true;
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 21:07:24 +00:00
|
|
|
SCH_ITEM::~SCH_ITEM()
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
// Do not let the connections container go out of scope with any objects or they
|
2011-09-30 18:15:37 +00:00
|
|
|
// will be deleted by the container will cause the Eeschema to crash. These objects
|
2010-11-10 15:30:12 +00:00
|
|
|
// are owned by the sheet object container.
|
|
|
|
if( !m_connections.empty() )
|
2011-03-25 19:16:05 +00:00
|
|
|
m_connections.clear();
|
2019-04-25 20:04:01 +00:00
|
|
|
|
|
|
|
for( const auto& it : m_connection_map )
|
|
|
|
delete it.second;
|
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
|
|
|
|
{
|
|
|
|
EDA_ITEM* parent = GetParent();
|
|
|
|
|
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
if( parent->Type() == SCHEMATIC_T )
|
|
|
|
return static_cast<SCHEMATIC*>( parent );
|
|
|
|
else
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 2;
|
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
|
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
NETCLASSPTR SCH_ITEM::NetClass( const SCH_SHEET_PATH* aSheet ) const
|
2020-07-08 18:29:16 +00:00
|
|
|
{
|
|
|
|
if( m_connection_map.size() )
|
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* connection = Connection( aSheet );
|
|
|
|
|
|
|
|
if( connection )
|
|
|
|
{
|
|
|
|
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
|
|
|
|
const wxString& netclassName = netSettings.GetNetclassName( connection->Name() );
|
2020-07-08 18:29:16 +00:00
|
|
|
|
|
|
|
return netSettings.m_NetClasses.Find( netclassName );
|
2020-10-07 14:40:12 +00:00
|
|
|
}
|
2020-07-08 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-16 00:59:12 +00:00
|
|
|
SCH_ITEM_SET& 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
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
m_connected_items[ aSheet ].insert( 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 );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
void SCH_ITEM::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
2020-01-28 15:42:42 +00:00
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
if( GetPosition().x != aItem.GetPosition().x )
|
|
|
|
return GetPosition().x < aItem.GetPosition().x;
|
|
|
|
|
2021-01-05 18:00:11 +00:00
|
|
|
if( GetPosition().y != aItem.GetPosition().y )
|
|
|
|
return GetPosition().y < aItem.GetPosition().y;
|
|
|
|
|
|
|
|
return m_Uuid < aItem.m_Uuid;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_ITEM::Plot( PLOTTER* aPlotter ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|