2019-03-11 21:32:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 CERN
|
2022-08-21 19:35:02 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-02-24 13:48:02 +00:00
|
|
|
*
|
2019-03-11 21:32:05 +00:00
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <list>
|
2019-04-06 01:14:15 +00:00
|
|
|
#include <future>
|
2019-04-10 04:16:05 +00:00
|
|
|
#include <vector>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <profile.h>
|
|
|
|
#include <common.h>
|
2021-10-01 10:52:34 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <erc.h>
|
2020-12-17 19:34:09 +00:00
|
|
|
#include <pin_type.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_line.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_marker.h>
|
2019-04-03 09:14:36 +00:00
|
|
|
#include <sch_pin.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <connection_graph.h>
|
2022-08-14 11:03:18 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <widgets/ui_common.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2022-06-15 00:41:10 +00:00
|
|
|
#include <thread_pool.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
#include <advanced_config.h> // for realtime connectivity switch in release builds
|
2020-07-06 23:47:07 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
/*
|
|
|
|
* Flag to enable connectivity profiling
|
|
|
|
* @ingroup trace_env_vars
|
|
|
|
*/
|
|
|
|
static const wxChar ConnProfileMask[] = wxT( "CONN_PROFILE" );
|
|
|
|
|
2020-10-09 01:24:24 +00:00
|
|
|
/*
|
|
|
|
* Flag to enable connectivity tracing
|
|
|
|
* @ingroup trace_env_vars
|
|
|
|
*/
|
|
|
|
static const wxChar ConnTrace[] = wxT( "CONN" );
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCheckMultipleDrivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-03 03:09:02 +00:00
|
|
|
PRIORITY highest_priority = PRIORITY::INVALID;
|
2019-04-10 04:16:05 +00:00
|
|
|
std::vector<SCH_ITEM*> candidates;
|
|
|
|
std::vector<SCH_ITEM*> strong_drivers;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
m_driver = nullptr;
|
|
|
|
|
2019-03-18 22:38:06 +00:00
|
|
|
// Hierarchical labels are lower priority than local labels here,
|
|
|
|
// because on the first pass we want local labels to drive subgraphs
|
|
|
|
// so that we can identify same-sheet neighbors and link them together.
|
|
|
|
// Hierarchical labels will end up overriding the final net name if
|
|
|
|
// a higher-level sheet has a different name during the hierarchical
|
|
|
|
// pass.
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : m_drivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-05-07 01:36:01 +00:00
|
|
|
PRIORITY item_priority = GetDriverPriority( item );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
if( item_priority == PRIORITY::PIN
|
2020-11-15 13:58:21 +00:00
|
|
|
&& !static_cast<SCH_PIN*>( item )->GetParentSymbol()->IsInNetlist() )
|
2019-05-07 01:36:01 +00:00
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
if( item_priority >= PRIORITY::HIER_LABEL )
|
2019-04-08 03:54:24 +00:00
|
|
|
strong_drivers.push_back( item );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( item_priority > highest_priority )
|
|
|
|
{
|
|
|
|
candidates.clear();
|
|
|
|
candidates.push_back( item );
|
|
|
|
highest_priority = item_priority;
|
|
|
|
}
|
2019-05-05 23:48:43 +00:00
|
|
|
else if( !candidates.empty() && ( item_priority == highest_priority ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
candidates.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
if( highest_priority >= PRIORITY::HIER_LABEL )
|
2019-03-18 22:38:06 +00:00
|
|
|
m_strong_driver = true;
|
|
|
|
|
2019-04-08 03:54:24 +00:00
|
|
|
// Power pins are 5, global labels are 6
|
2020-01-03 03:09:02 +00:00
|
|
|
m_local_driver = ( highest_priority < PRIORITY::POWER_PIN );
|
2019-04-08 03:54:24 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
if( !candidates.empty() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
if( candidates.size() > 1 )
|
|
|
|
{
|
2020-01-03 03:09:02 +00:00
|
|
|
if( highest_priority == PRIORITY::SHEET_PIN )
|
2019-03-18 22:38:06 +00:00
|
|
|
{
|
|
|
|
// We have multiple options, and they are all hierarchical
|
|
|
|
// sheet pins. Let's prefer outputs over inputs.
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
for( SCH_ITEM* c : candidates )
|
2019-03-18 22:38:06 +00:00
|
|
|
{
|
2020-10-17 18:59:08 +00:00
|
|
|
SCH_SHEET_PIN* p = static_cast<SCH_SHEET_PIN*>( c );
|
2019-03-18 22:38:06 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( p->GetShape() == LABEL_FLAG_SHAPE::L_OUTPUT )
|
2019-03-18 22:38:06 +00:00
|
|
|
{
|
|
|
|
m_driver = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-05 23:09:05 +00:00
|
|
|
else
|
|
|
|
{
|
2021-11-20 00:03:53 +00:00
|
|
|
// For all other driver types, sort by quality of name
|
2019-05-05 23:09:05 +00:00
|
|
|
std::sort( candidates.begin(), candidates.end(),
|
2020-05-25 21:35:26 +00:00
|
|
|
[&]( SCH_ITEM* a, SCH_ITEM* b ) -> bool
|
2019-05-05 23:09:05 +00:00
|
|
|
{
|
2020-10-18 20:02:21 +00:00
|
|
|
// meet irreflexive requirements of std::sort
|
|
|
|
if( a == b )
|
|
|
|
return false;
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* ac = a->Connection( &m_sheet );
|
|
|
|
SCH_CONNECTION* bc = b->Connection( &m_sheet );
|
2020-05-25 21:35:26 +00:00
|
|
|
|
|
|
|
// Ensure we don't pick the subset over the superset
|
|
|
|
if( ac->IsBus() && bc->IsBus() )
|
|
|
|
return bc->IsSubsetOf( ac );
|
|
|
|
|
2022-10-28 02:54:36 +00:00
|
|
|
// Ensure we don't pick a hidden power pin on a regular symbol over
|
|
|
|
// one on a power symbol
|
|
|
|
if( a->Type() == SCH_PIN_T && b->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pa = static_cast<SCH_PIN*>( a );
|
|
|
|
SCH_PIN* pb = static_cast<SCH_PIN*>( b );
|
|
|
|
|
|
|
|
bool aPower = pa->GetLibPin()->GetParent()->IsPower();
|
|
|
|
bool bPower = pb->GetLibPin()->GetParent()->IsPower();
|
|
|
|
|
|
|
|
if( aPower && !bPower )
|
|
|
|
return true;
|
|
|
|
else if( bPower && !aPower )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& a_name = GetNameForDriver( a );
|
|
|
|
const wxString& b_name = GetNameForDriver( b );
|
2021-11-20 00:03:53 +00:00
|
|
|
bool a_lowQualityName = a_name.Contains( "-Pad" );
|
|
|
|
bool b_lowQualityName = b_name.Contains( "-Pad" );
|
|
|
|
|
|
|
|
if( a_lowQualityName && !b_lowQualityName )
|
|
|
|
return false;
|
|
|
|
else if( b_lowQualityName && !a_lowQualityName )
|
|
|
|
return true;
|
2020-10-17 18:59:08 +00:00
|
|
|
else
|
2021-11-20 00:03:53 +00:00
|
|
|
return a_name < b_name;
|
2019-05-05 23:09:05 +00:00
|
|
|
} );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 22:38:06 +00:00
|
|
|
if( !m_driver )
|
|
|
|
m_driver = candidates[0];
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 03:54:24 +00:00
|
|
|
if( strong_drivers.size() > 1 )
|
2019-04-04 02:41:26 +00:00
|
|
|
m_multiple_drivers = true;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-08 03:54:24 +00:00
|
|
|
// Drop weak drivers
|
2019-04-20 01:45:33 +00:00
|
|
|
if( m_strong_driver )
|
|
|
|
m_drivers = strong_drivers;
|
|
|
|
|
|
|
|
// Cache driver connection
|
|
|
|
if( m_driver )
|
2020-12-12 15:32:54 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
m_driver_connection = m_driver->Connection( &m_sheet );
|
2020-12-12 15:32:54 +00:00
|
|
|
m_driver_connection->ConfigureFromLabel( GetNameForDriver( m_driver ) );
|
|
|
|
m_driver_connection->SetDriver( m_driver );
|
|
|
|
m_driver_connection->ClearDirty();
|
|
|
|
}
|
2023-04-04 19:17:17 +00:00
|
|
|
else if( !m_is_bus_member )
|
2020-12-12 15:32:54 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
m_driver_connection = nullptr;
|
2020-12-12 15:32:54 +00:00
|
|
|
}
|
2019-04-08 03:54:24 +00:00
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
if( aCheckMultipleDrivers && m_multiple_drivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-03-23 19:43:33 +00:00
|
|
|
// First check if all the candidates are actually the same
|
|
|
|
bool same = true;
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& first = GetNameForDriver( candidates[0] );
|
2019-06-01 01:55:43 +00:00
|
|
|
SCH_ITEM* second_item = nullptr;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-23 19:43:33 +00:00
|
|
|
for( unsigned i = 1; i < candidates.size(); i++ )
|
|
|
|
{
|
2019-04-04 02:41:26 +00:00
|
|
|
if( GetNameForDriver( candidates[i] ) != first )
|
2019-03-23 19:43:33 +00:00
|
|
|
{
|
2019-06-01 01:55:43 +00:00
|
|
|
second_item = candidates[i];
|
2019-03-23 19:43:33 +00:00
|
|
|
same = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-23 19:43:33 +00:00
|
|
|
if( !same )
|
|
|
|
{
|
2021-01-13 04:03:31 +00:00
|
|
|
m_first_driver = m_driver;
|
|
|
|
m_second_driver = second_item;
|
2019-03-23 19:43:33 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
return ( m_driver != nullptr );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
void CONNECTION_SUBGRAPH::getAllConnectedItems( std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>>& aItems, std::set<CONNECTION_SUBGRAPH*>& aSubgraphs )
|
|
|
|
{
|
|
|
|
CONNECTION_SUBGRAPH* sg = this;
|
|
|
|
|
|
|
|
while( sg->m_absorbed_by )
|
|
|
|
sg = sg->m_absorbed_by;
|
|
|
|
|
|
|
|
aSubgraphs.insert( sg );
|
|
|
|
aSubgraphs.insert( sg->m_absorbed_subgraphs.begin(), sg->m_absorbed_subgraphs.end() );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : sg->m_items )
|
|
|
|
aItems.emplace( m_sheet, item );
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* child_sg : sg->m_hier_children )
|
|
|
|
child_sg->getAllConnectedItems( aItems, aSubgraphs );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
wxString CONNECTION_SUBGRAPH::GetNetName() const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
if( !m_driver || m_dirty )
|
|
|
|
return "";
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
if( !m_driver->Connection( &m_sheet ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
#ifdef CONNECTIVITY_DEBUG
|
2023-01-17 04:14:38 +00:00
|
|
|
wxASSERT_MSG( false, wxS( "Tried to get the net name of an item with no connection" ) );
|
2020-03-16 11:05:01 +00:00
|
|
|
#endif
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
return m_driver->Connection( &m_sheet )->Name();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
std::vector<SCH_ITEM*> CONNECTION_SUBGRAPH::GetAllBusLabels() const
|
|
|
|
{
|
|
|
|
std::vector<SCH_ITEM*> labels;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_drivers )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
|
|
|
CONNECTION_TYPE type = item->Connection( &m_sheet )->Type();
|
|
|
|
|
|
|
|
// Only consider bus vectors
|
|
|
|
if( type == CONNECTION_TYPE::BUS || type == CONNECTION_TYPE::BUS_GROUP )
|
|
|
|
labels.push_back( item );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return labels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<SCH_ITEM*> CONNECTION_SUBGRAPH::GetVectorBusLabels() const
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-10 04:16:05 +00:00
|
|
|
std::vector<SCH_ITEM*> labels;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : m_drivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* label_conn = item->Connection( &m_sheet );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
// Only consider bus vectors
|
2020-01-18 20:51:28 +00:00
|
|
|
if( label_conn->Type() == CONNECTION_TYPE::BUS )
|
2019-03-11 21:32:05 +00:00
|
|
|
labels.push_back( item );
|
2020-04-24 23:44:09 +00:00
|
|
|
|
|
|
|
break;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2020-04-24 23:44:09 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
default:
|
|
|
|
break;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return labels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
|
2019-04-04 02:41:26 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
2021-01-15 01:55:39 +00:00
|
|
|
bool forceNoConnect = m_no_connect != nullptr;
|
2020-07-06 10:51:04 +00:00
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aItem );
|
2021-01-15 01:55:39 +00:00
|
|
|
return pin->GetDefaultNetName( m_sheet, forceNoConnect );
|
2019-04-04 02:41:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2023-05-05 13:21:56 +00:00
|
|
|
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( &m_sheet, false ),
|
2023-03-08 15:31:24 +00:00
|
|
|
CTX_NETNAME );
|
2023-05-05 13:21:56 +00:00
|
|
|
|
2023-03-08 16:28:32 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
// Sheet pins need to use their parent sheet as their starting sheet or they will
|
|
|
|
// resolve variables on the current sheet first
|
2023-05-05 13:21:56 +00:00
|
|
|
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( nullptr, false ),
|
|
|
|
CTX_NETNAME );
|
|
|
|
|
2019-04-04 02:41:26 +00:00
|
|
|
default:
|
2023-01-17 04:14:38 +00:00
|
|
|
wxFAIL_MSG( wxS( "Unhandled item type in GetNameForDriver" ) );
|
2019-04-04 02:41:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const
|
2021-01-13 04:03:31 +00:00
|
|
|
{
|
2023-01-24 01:20:05 +00:00
|
|
|
auto [it, success] = m_driver_name_cache.try_emplace( aItem, driverName( aItem ) );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2023-01-24 01:20:05 +00:00
|
|
|
return it->second;
|
2021-01-13 04:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
const wxString CONNECTION_SUBGRAPH::GetNetclassForDriver( SCH_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
wxString netclass;
|
|
|
|
|
|
|
|
aItem->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
|
|
|
|
|
|
|
|
if( field->GetCanonicalName() == wxT( "Netclass" ) )
|
|
|
|
{
|
|
|
|
netclass = field->GetText();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return netclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
void CONNECTION_SUBGRAPH::Absorb( CONNECTION_SUBGRAPH* aOther )
|
|
|
|
{
|
|
|
|
wxASSERT( m_sheet == aOther->m_sheet );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : aOther->m_items )
|
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
item->Connection( &m_sheet )->SetSubgraphCode( m_code );
|
2019-04-20 01:45:33 +00:00
|
|
|
AddItem( item );
|
|
|
|
}
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
m_absorbed_subgraphs.insert( aOther );
|
|
|
|
m_absorbed_subgraphs.insert( aOther->m_absorbed_subgraphs.begin(),
|
|
|
|
aOther->m_absorbed_subgraphs.end() );
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
m_bus_neighbors.insert( aOther->m_bus_neighbors.begin(), aOther->m_bus_neighbors.end() );
|
2019-05-05 23:48:43 +00:00
|
|
|
m_bus_parents.insert( aOther->m_bus_parents.begin(), aOther->m_bus_parents.end() );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2020-01-04 15:38:43 +00:00
|
|
|
m_multiple_drivers |= aOther->m_multiple_drivers;
|
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
std::function<void( CONNECTION_SUBGRAPH* )> set_absorbed_by =
|
|
|
|
[ & ]( CONNECTION_SUBGRAPH *child )
|
|
|
|
{
|
|
|
|
child->m_absorbed_by = this;
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subchild : child->m_absorbed_subgraphs )
|
|
|
|
set_absorbed_by( subchild );
|
|
|
|
};
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
aOther->m_absorbed = true;
|
|
|
|
aOther->m_dirty = false;
|
|
|
|
aOther->m_driver = nullptr;
|
|
|
|
aOther->m_driver_connection = nullptr;
|
2023-04-21 20:25:01 +00:00
|
|
|
|
|
|
|
set_absorbed_by( aOther );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTION_SUBGRAPH::AddItem( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_items.push_back( aItem );
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
if( aItem->Connection( &m_sheet )->IsDriver() )
|
2019-04-20 01:45:33 +00:00
|
|
|
m_drivers.push_back( aItem );
|
|
|
|
|
|
|
|
if( aItem->Type() == SCH_SHEET_PIN_T )
|
|
|
|
m_hier_pins.push_back( static_cast<SCH_SHEET_PIN*>( aItem ) );
|
|
|
|
else if( aItem->Type() == SCH_HIER_LABEL_T )
|
|
|
|
m_hier_ports.push_back( static_cast<SCH_HIERLABEL*>( aItem ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTION_SUBGRAPH::UpdateItemConnections()
|
|
|
|
{
|
|
|
|
if( !m_driver_connection )
|
|
|
|
return;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : m_items )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* item_conn = item->GetOrInitConnection( m_sheet, m_graph );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2022-03-11 21:37:03 +00:00
|
|
|
if( !item_conn )
|
|
|
|
continue;
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( ( m_driver_connection->IsBus() && item_conn->IsNet() ) ||
|
|
|
|
( m_driver_connection->IsNet() && item_conn->IsBus() ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item != m_driver )
|
|
|
|
{
|
|
|
|
item_conn->Clone( *m_driver_connection );
|
|
|
|
item_conn->ClearDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
CONNECTION_SUBGRAPH::PRIORITY CONNECTION_SUBGRAPH::GetDriverPriority( SCH_ITEM* aDriver )
|
|
|
|
{
|
|
|
|
if( !aDriver )
|
2020-01-03 03:09:02 +00:00
|
|
|
return PRIORITY::NONE;
|
2019-05-07 01:36:01 +00:00
|
|
|
|
|
|
|
switch( aDriver->Type() )
|
|
|
|
{
|
2020-01-03 03:09:02 +00:00
|
|
|
case SCH_SHEET_PIN_T: return PRIORITY::SHEET_PIN;
|
|
|
|
case SCH_HIER_LABEL_T: return PRIORITY::HIER_LABEL;
|
|
|
|
case SCH_LABEL_T: return PRIORITY::LOCAL_LABEL;
|
|
|
|
case SCH_GLOBAL_LABEL_T: return PRIORITY::GLOBAL;
|
2019-05-07 01:36:01 +00:00
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_PIN* sch_pin = static_cast<SCH_PIN*>( aDriver );
|
2023-05-04 18:49:23 +00:00
|
|
|
SCH_SYMBOL* sym = sch_pin->GetParentSymbol();
|
2019-05-07 01:36:01 +00:00
|
|
|
|
2023-01-18 15:06:46 +00:00
|
|
|
if( sch_pin->IsGlobalPower() )
|
2020-01-03 03:09:02 +00:00
|
|
|
return PRIORITY::POWER_PIN;
|
2023-05-04 19:06:19 +00:00
|
|
|
else if( !sym || !sym->GetIncludeOnBoard() || sym->GetLibSymbolRef()->GetReferenceField().GetText().StartsWith( '#' ) )
|
2023-05-04 18:49:23 +00:00
|
|
|
return PRIORITY::NONE;
|
2019-05-07 01:36:01 +00:00
|
|
|
else
|
2020-01-03 03:09:02 +00:00
|
|
|
return PRIORITY::PIN;
|
2019-05-07 01:36:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
default: return PRIORITY::NONE;
|
2019-05-07 01:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
void CONNECTION_GRAPH::Merge( CONNECTION_GRAPH& aGraph )
|
|
|
|
{
|
|
|
|
std::copy( aGraph.m_items.begin(), aGraph.m_items.end(),
|
|
|
|
std::back_inserter( m_items ) );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : aGraph.m_items )
|
|
|
|
item->SetConnectionGraph( this );
|
|
|
|
|
|
|
|
std::copy( aGraph.m_subgraphs.begin(), aGraph.m_subgraphs.end(),
|
|
|
|
std::back_inserter( m_subgraphs ) );
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* sg : aGraph.m_subgraphs )
|
|
|
|
sg->m_graph = this;
|
|
|
|
|
|
|
|
std::copy( aGraph.m_driver_subgraphs.begin(),
|
|
|
|
aGraph.m_driver_subgraphs.end(),
|
|
|
|
std::back_inserter( m_driver_subgraphs ) );
|
|
|
|
|
|
|
|
std::copy( aGraph.m_global_power_pins.begin(),
|
|
|
|
aGraph.m_global_power_pins.end(),
|
|
|
|
std::back_inserter( m_global_power_pins ) );
|
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_net_name_to_subgraphs_map )
|
|
|
|
m_net_name_to_subgraphs_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_sheet_to_subgraphs_map )
|
|
|
|
m_sheet_to_subgraphs_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_net_name_to_code_map )
|
|
|
|
m_net_name_to_code_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_bus_name_to_code_map )
|
|
|
|
m_bus_name_to_code_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_net_code_to_subgraphs_map )
|
|
|
|
m_net_code_to_subgraphs_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_item_to_subgraph_map )
|
|
|
|
m_item_to_subgraph_map.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_local_label_cache )
|
|
|
|
m_local_label_cache.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
for( auto& [key, value] : aGraph.m_global_label_cache )
|
|
|
|
m_global_label_cache.insert_or_assign( key, value );
|
2023-04-08 15:22:34 +00:00
|
|
|
|
|
|
|
m_last_bus_code = std::max( m_last_bus_code, aGraph.m_last_bus_code );
|
|
|
|
m_last_net_code = std::max( m_last_net_code, aGraph.m_last_net_code );
|
|
|
|
m_last_subgraph_code = std::max( m_last_subgraph_code, aGraph.m_last_subgraph_code );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
void CONNECTION_GRAPH::Reset()
|
|
|
|
{
|
2020-01-07 05:12:37 +00:00
|
|
|
for( auto& subgraph : m_subgraphs )
|
2023-04-08 15:22:34 +00:00
|
|
|
{
|
|
|
|
/// Only delete subgraphs of which we are the owner
|
|
|
|
if( subgraph->m_graph == this )
|
|
|
|
delete subgraph;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
m_items.clear();
|
|
|
|
m_subgraphs.clear();
|
2019-04-25 04:37:10 +00:00
|
|
|
m_driver_subgraphs.clear();
|
2019-04-29 23:41:03 +00:00
|
|
|
m_sheet_to_subgraphs_map.clear();
|
2023-01-18 14:58:47 +00:00
|
|
|
m_global_power_pins.clear();
|
2019-03-11 21:32:05 +00:00
|
|
|
m_bus_alias_cache.clear();
|
|
|
|
m_net_name_to_code_map.clear();
|
|
|
|
m_bus_name_to_code_map.clear();
|
|
|
|
m_net_code_to_subgraphs_map.clear();
|
2019-04-25 03:47:57 +00:00
|
|
|
m_net_name_to_subgraphs_map.clear();
|
2020-05-24 14:46:05 +00:00
|
|
|
m_item_to_subgraph_map.clear();
|
2019-04-25 19:31:44 +00:00
|
|
|
m_local_label_cache.clear();
|
|
|
|
m_global_label_cache.clear();
|
2019-03-11 21:32:05 +00:00
|
|
|
m_last_net_code = 1;
|
|
|
|
m_last_bus_code = 1;
|
|
|
|
m_last_subgraph_code = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional,
|
|
|
|
std::function<void( SCH_ITEM* )>* aChangedItemHandler )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-12-05 19:16:18 +00:00
|
|
|
PROF_TIMER recalc_time( "CONNECTION_GRAPH::Recalculate" );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-30 15:57:30 +00:00
|
|
|
if( aUnconditional )
|
|
|
|
Reset();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-12-05 19:16:18 +00:00
|
|
|
PROF_TIMER update_items( "updateItemConnectivity" );
|
2020-07-09 22:14:27 +00:00
|
|
|
|
2020-08-26 01:52:52 +00:00
|
|
|
m_sheetList = aSheetList;
|
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : aSheetList )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-11 03:05:23 +00:00
|
|
|
std::vector<SCH_ITEM*> items;
|
2022-09-04 16:22:02 +00:00
|
|
|
// Store current unit value, to regenerate it after calculations
|
|
|
|
// (useful in complex hierarchies)
|
|
|
|
std::vector<std::pair<SCH_SYMBOL*, int>> symbolsChanged;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( item->IsConnectable() && ( aUnconditional || item->IsConnectivityDirty() ) )
|
2019-04-11 03:05:23 +00:00
|
|
|
items.push_back( item );
|
2022-08-03 15:21:02 +00:00
|
|
|
|
|
|
|
// Ensure the hierarchy info stored in SCREENS is built and up to date
|
2022-09-04 16:22:02 +00:00
|
|
|
// (multi-unit symbols)
|
2022-08-03 15:21:02 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2022-09-04 16:22:02 +00:00
|
|
|
int new_unit = symbol->GetUnitSelection( &sheet );
|
|
|
|
|
|
|
|
// Store the initial unit value, to regenerate it after calculations,
|
|
|
|
// if modified
|
|
|
|
if( symbol->GetUnit() != new_unit )
|
|
|
|
symbolsChanged.push_back( { symbol, symbol->GetUnit() } );
|
|
|
|
|
|
|
|
symbol->UpdateUnit( new_unit );
|
2022-08-03 15:21:02 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
m_items.reserve( m_items.size() + items.size() );
|
|
|
|
|
2019-04-11 03:05:23 +00:00
|
|
|
updateItemConnectivity( sheet, items );
|
2020-01-17 02:33:16 +00:00
|
|
|
|
|
|
|
// UpdateDanglingState() also adds connected items for SCH_TEXT
|
2020-12-06 21:23:16 +00:00
|
|
|
sheet.LastScreen()->TestDanglingEnds( &sheet, aChangedItemHandler );
|
2022-09-04 16:22:02 +00:00
|
|
|
|
|
|
|
// Restore the m_unit member, to avoid changes in current active sheet path
|
|
|
|
// after calculations
|
|
|
|
for( auto& item : symbolsChanged )
|
|
|
|
{
|
|
|
|
item.first->UpdateUnit( item.second );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )
|
|
|
|
update_items.Show();
|
2019-04-03 02:58:11 +00:00
|
|
|
|
2021-12-05 19:16:18 +00:00
|
|
|
PROF_TIMER build_graph( "buildConnectionGraph" );
|
2019-04-29 21:44:49 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
buildConnectionGraph( aChangedItemHandler );
|
2019-04-29 21:44:49 +00:00
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )
|
|
|
|
build_graph.Show();
|
2019-04-29 21:44:49 +00:00
|
|
|
|
|
|
|
recalc_time.Stop();
|
2020-07-09 22:14:27 +00:00
|
|
|
|
|
|
|
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )
|
|
|
|
recalc_time.Show();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> CONNECTION_GRAPH::ExtractAffectedItems(
|
|
|
|
const std::set<SCH_ITEM*> &aItems )
|
|
|
|
{
|
|
|
|
std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> retvals;
|
|
|
|
std::set<CONNECTION_SUBGRAPH*> subgraphs;
|
|
|
|
|
|
|
|
auto traverse_subgraph = [&retvals, &subgraphs]( CONNECTION_SUBGRAPH* aSubgraph )
|
|
|
|
{
|
|
|
|
// Find the primary subgraph on this sheet
|
|
|
|
while( aSubgraph->m_absorbed_by )
|
|
|
|
aSubgraph = aSubgraph->m_absorbed_by;
|
|
|
|
|
|
|
|
// Find the top most connected subgraph on all sheets
|
|
|
|
while( aSubgraph->m_hier_parent )
|
|
|
|
aSubgraph = aSubgraph->m_hier_parent;
|
|
|
|
|
|
|
|
// Recurse through all subsheets to collect connected items
|
|
|
|
aSubgraph->getAllConnectedItems( retvals, subgraphs );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : aItems )
|
|
|
|
{
|
|
|
|
auto it = m_item_to_subgraph_map.find( item );
|
|
|
|
|
|
|
|
if( it == m_item_to_subgraph_map.end() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CONNECTION_SUBGRAPH* sg = it->second;
|
|
|
|
|
|
|
|
traverse_subgraph( sg );
|
|
|
|
|
|
|
|
for( auto& bus_it : sg->m_bus_neighbors )
|
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* bus_sg : bus_it.second )
|
|
|
|
traverse_subgraph( bus_sg );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& bus_it : sg->m_bus_parents )
|
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* bus_sg : bus_it.second )
|
|
|
|
traverse_subgraph( bus_sg );
|
|
|
|
}
|
2023-04-21 20:25:01 +00:00
|
|
|
|
|
|
|
alg::delete_matching( m_items, item );
|
2023-04-08 15:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removeSubgraphs( subgraphs );
|
|
|
|
|
|
|
|
return retvals;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTION_GRAPH::removeSubgraphs( std::set<CONNECTION_SUBGRAPH*>& aSubgraphs )
|
|
|
|
{
|
|
|
|
std::sort( m_driver_subgraphs.begin(), m_driver_subgraphs.end() );
|
|
|
|
std::sort( m_subgraphs.begin(), m_subgraphs.end() );
|
|
|
|
std::set<int> codes_to_remove;
|
|
|
|
|
|
|
|
for( auto el : m_sheet_to_subgraphs_map )
|
|
|
|
{
|
|
|
|
std::sort( el.second.begin(), el.second.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* sg : aSubgraphs )
|
|
|
|
{
|
2023-05-03 20:37:11 +00:00
|
|
|
for( auto it : sg->m_bus_neighbors )
|
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* neighbor : it.second )
|
|
|
|
{
|
|
|
|
auto& parents = neighbor->m_bus_parents[it.first];
|
|
|
|
|
|
|
|
for( auto test = parents.begin(); test != parents.end(); )
|
|
|
|
{
|
|
|
|
if( *test == sg )
|
|
|
|
test = parents.erase( test );
|
|
|
|
else
|
|
|
|
++test;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parents.empty() )
|
|
|
|
neighbor->m_bus_parents.erase( it.first );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it : sg->m_bus_parents )
|
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* parent : it.second )
|
|
|
|
{
|
|
|
|
auto& neighbors = parent->m_bus_neighbors[it.first];
|
|
|
|
|
|
|
|
for( auto test = neighbors.begin(); test != neighbors.end(); )
|
|
|
|
{
|
|
|
|
if( *test == sg )
|
|
|
|
test = neighbors.erase( test );
|
|
|
|
else
|
|
|
|
++test;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( neighbors.empty() )
|
|
|
|
parent->m_bus_neighbors.erase( it.first );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
{
|
|
|
|
auto it = std::lower_bound( m_driver_subgraphs.begin(), m_driver_subgraphs.end(), sg );
|
|
|
|
|
|
|
|
if( it != m_driver_subgraphs.end() )
|
|
|
|
m_driver_subgraphs.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto it = std::lower_bound( m_subgraphs.begin(), m_subgraphs.end(), sg );
|
|
|
|
|
|
|
|
if( it != m_subgraphs.end() )
|
|
|
|
m_subgraphs.erase( it );
|
|
|
|
}
|
|
|
|
|
2023-05-12 15:57:03 +00:00
|
|
|
for( auto& el : m_sheet_to_subgraphs_map )
|
2023-04-08 15:22:34 +00:00
|
|
|
{
|
|
|
|
auto it = std::lower_bound( el.second.begin(), el.second.end(), sg );
|
|
|
|
|
|
|
|
if( it != el.second.end() )
|
|
|
|
el.second.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto remove_sg = [sg]( auto it ) -> bool
|
|
|
|
{
|
|
|
|
for( const CONNECTION_SUBGRAPH* test_sg : it->second )
|
|
|
|
{
|
|
|
|
if( sg == test_sg )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto it = m_global_label_cache.begin(); it != m_global_label_cache.end(); )
|
|
|
|
{
|
|
|
|
if( remove_sg( it ) )
|
|
|
|
it = m_global_label_cache.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_local_label_cache.begin(); it != m_local_label_cache.end(); )
|
|
|
|
{
|
|
|
|
if( remove_sg( it ) )
|
|
|
|
it = m_local_label_cache.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_net_code_to_subgraphs_map.begin(); it != m_net_code_to_subgraphs_map.end(); )
|
|
|
|
{
|
|
|
|
if( remove_sg( it ) )
|
|
|
|
{
|
|
|
|
codes_to_remove.insert( it->first.Netcode );
|
|
|
|
it = m_net_code_to_subgraphs_map.erase( it );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_net_name_to_subgraphs_map.begin(); it != m_net_name_to_subgraphs_map.end(); )
|
|
|
|
{
|
|
|
|
if( remove_sg( it ) )
|
|
|
|
it = m_net_name_to_subgraphs_map.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_item_to_subgraph_map.begin(); it != m_item_to_subgraph_map.end(); )
|
|
|
|
{
|
|
|
|
if( it->second == sg )
|
|
|
|
it = m_item_to_subgraph_map.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
2023-05-03 20:37:11 +00:00
|
|
|
|
|
|
|
|
2023-04-08 15:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_net_name_to_code_map.begin(); it != m_net_name_to_code_map.end(); )
|
|
|
|
{
|
|
|
|
if( codes_to_remove.find( it->second ) != codes_to_remove.end() )
|
|
|
|
it = m_net_name_to_code_map.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it = m_bus_name_to_code_map.begin(); it != m_bus_name_to_code_map.end(); )
|
|
|
|
{
|
|
|
|
if( codes_to_remove.find( it->second ) != codes_to_remove.end() )
|
|
|
|
it = m_bus_name_to_code_map.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* sg : aSubgraphs )
|
|
|
|
{
|
|
|
|
sg->m_code = -1;
|
|
|
|
delete sg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-07-08 21:42:05 +00:00
|
|
|
void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
|
2020-01-12 18:40:50 +00:00
|
|
|
const std::vector<SCH_ITEM*>& aItemList )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
std::map<VECTOR2I, std::vector<SCH_ITEM*>> connection_map;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : aItemList )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> points = item->GetConnectionPoints();
|
2020-01-17 02:33:16 +00:00
|
|
|
item->ConnectedItems( aSheet ).clear();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-02-11 22:18:32 +00:00
|
|
|
pin->InitializeConnection( aSheet, this );
|
2019-04-11 03:05:23 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
pin->ConnectedItems( aSheet ).clear();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
connection_map[ pin->GetTextPos() ].push_back( pin );
|
2020-07-09 22:14:27 +00:00
|
|
|
m_items.emplace_back( pin );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-10 14:10:55 +00:00
|
|
|
else if( item->Type() == SCH_SYMBOL_T )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
for( SCH_PIN* pin : symbol->GetPins( &aSheet ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-03-08 14:35:17 +00:00
|
|
|
SCH_CONNECTION* conn = pin->InitializeConnection( aSheet, this );
|
2019-04-23 02:49:24 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = pin->GetPosition();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
// because calling the first time is not thread-safe
|
2023-03-08 14:35:17 +00:00
|
|
|
wxString name = pin->GetDefaultNetName( aSheet );
|
2020-01-17 02:33:16 +00:00
|
|
|
pin->ConnectedItems( aSheet ).clear();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
// power symbol pins need to be post-processed later
|
2023-01-18 15:06:46 +00:00
|
|
|
if( pin->IsGlobalPower() )
|
2023-03-08 14:35:17 +00:00
|
|
|
{
|
|
|
|
conn->SetName( name );
|
2023-01-18 14:58:47 +00:00
|
|
|
m_global_power_pins.emplace_back( std::make_pair( aSheet, pin ) );
|
2023-03-08 14:35:17 +00:00
|
|
|
}
|
2019-04-08 01:33:47 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
connection_map[ pos ].push_back( pin );
|
2020-07-09 22:14:27 +00:00
|
|
|
m_items.emplace_back( pin );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-09 22:14:27 +00:00
|
|
|
m_items.emplace_back( item );
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* conn = item->InitializeConnection( aSheet, this );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
// Set bus/net property here so that the propagation code uses it
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
2020-01-18 20:51:28 +00:00
|
|
|
conn->SetType( item->GetLayer() == LAYER_BUS ? CONNECTION_TYPE::BUS :
|
|
|
|
CONNECTION_TYPE::NET );
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
2020-01-18 20:51:28 +00:00
|
|
|
conn->SetType( CONNECTION_TYPE::BUS );
|
2019-12-23 13:55:47 +00:00
|
|
|
// clean previous (old) links:
|
|
|
|
static_cast<SCH_BUS_BUS_ENTRY*>( item )->m_connected_bus_items[0] = nullptr;
|
|
|
|
static_cast<SCH_BUS_BUS_ENTRY*>( item )->m_connected_bus_items[1] = nullptr;
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
|
|
|
|
2019-04-03 09:14:36 +00:00
|
|
|
case SCH_PIN_T:
|
2020-01-18 20:51:28 +00:00
|
|
|
conn->SetType( CONNECTION_TYPE::NET );
|
2019-12-23 13:55:47 +00:00
|
|
|
break;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2020-01-18 20:51:28 +00:00
|
|
|
conn->SetType( CONNECTION_TYPE::NET );
|
2019-12-23 13:55:47 +00:00
|
|
|
// clean previous (old) link:
|
|
|
|
static_cast<SCH_BUS_WIRE_ENTRY*>( item )->m_connected_bus_item = nullptr;
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& point : points )
|
2019-04-11 03:05:23 +00:00
|
|
|
connection_map[ point ].push_back( item );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2019-03-30 15:57:30 +00:00
|
|
|
|
|
|
|
item->SetConnectivityDirty( false );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 03:05:23 +00:00
|
|
|
for( const auto& it : connection_map )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-10-01 19:24:54 +00:00
|
|
|
std::vector<SCH_ITEM*> connection_vec = it.second;
|
|
|
|
std::sort( connection_vec.begin(), connection_vec.end() );
|
|
|
|
connection_vec.erase( std::unique( connection_vec.begin(), connection_vec.end() ),
|
|
|
|
connection_vec.end() );
|
2021-11-25 18:36:30 +00:00
|
|
|
|
|
|
|
// Pre-scan to see if we have a bus at this location
|
|
|
|
SCH_LINE* busLine = aSheet.LastScreen()->GetBus( it.first );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-03-28 22:34:13 +00:00
|
|
|
std::mutex update_mutex;
|
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
auto update_lambda = [&]( SCH_ITEM* connected_item ) -> size_t
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
// Bus entries are special: they can have connection points in the
|
|
|
|
// middle of a wire segment, because the junction algo doesn't split
|
|
|
|
// the segment in two where you place a bus entry. This means that
|
|
|
|
// bus entries that don't land on the end of a line segment need to
|
|
|
|
// have "virtual" connection points to the segments they graphically
|
|
|
|
// touch.
|
|
|
|
if( connected_item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
// If this location only has the connection point of the bus
|
|
|
|
// entry itself, this means that either the bus entry is not
|
|
|
|
// connected to anything graphically, or that it is connected to
|
|
|
|
// a segment at some point other than at one of the endpoints.
|
|
|
|
if( connection_vec.size() == 1 )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
if( busLine )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
auto bus_entry = static_cast<SCH_BUS_WIRE_ENTRY*>( connected_item );
|
|
|
|
bus_entry->m_connected_bus_item = busLine;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-15 00:41:10 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Bus-to-bus entries are treated just like bus wires
|
|
|
|
else if( connected_item->Type() == SCH_BUS_BUS_ENTRY_T )
|
|
|
|
{
|
|
|
|
if( connection_vec.size() < 2 )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
if( busLine )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
auto bus_entry = static_cast<SCH_BUS_BUS_ENTRY*>( connected_item );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( it.first == bus_entry->GetPosition() )
|
|
|
|
bus_entry->m_connected_bus_items[0] = busLine;
|
|
|
|
else
|
|
|
|
bus_entry->m_connected_bus_items[1] = busLine;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
std::lock_guard<std::mutex> lock( update_mutex );
|
|
|
|
bus_entry->AddConnectionTo( aSheet, busLine );
|
|
|
|
busLine->AddConnectionTo( aSheet, bus_entry );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-15 00:41:10 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Change junctions to be on bus junction layer if they are touching a bus
|
|
|
|
else if( connected_item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
connected_item->SetLayer( busLine ? LAYER_BUS_JUNCTION : LAYER_JUNCTION );
|
|
|
|
}
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
SCH_ITEM_SET& connected_set = connected_item->ConnectedItems( aSheet );
|
|
|
|
connected_set.reserve( connection_vec.size() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
for( SCH_ITEM* test_item : connection_vec )
|
|
|
|
{
|
|
|
|
bool bus_connection_ok = true;
|
2022-03-28 22:34:13 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( test_item == connected_item )
|
|
|
|
continue;
|
2022-03-28 22:34:13 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Set up the link between the bus entry net and the bus
|
|
|
|
if( connected_item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
|
|
|
if( test_item->GetLayer() == LAYER_BUS )
|
2022-03-28 22:34:13 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
auto bus_entry = static_cast<SCH_BUS_WIRE_ENTRY*>( connected_item );
|
|
|
|
bus_entry->m_connected_bus_item = test_item;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-25 18:36:30 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Bus entries only connect to bus lines on the end that is touching a bus line.
|
|
|
|
// If the user has overlapped another net line with the endpoint of the bus entry
|
|
|
|
// where the entry connects to a bus, we don't want to short-circuit it.
|
2021-11-25 18:36:30 +00:00
|
|
|
if( connected_item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
bus_connection_ok = !busLine || test_item->GetLayer() == LAYER_BUS;
|
|
|
|
}
|
|
|
|
else if( test_item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
|
|
|
bus_connection_ok = !busLine || connected_item->GetLayer() == LAYER_BUS;
|
|
|
|
}
|
2021-11-25 18:36:30 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( connected_item->ConnectionPropagatesTo( test_item ) &&
|
|
|
|
test_item->ConnectionPropagatesTo( connected_item ) &&
|
|
|
|
bus_connection_ok )
|
|
|
|
{
|
|
|
|
connected_set.push_back( test_item );
|
|
|
|
}
|
|
|
|
}
|
2022-03-28 22:34:13 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// If we got this far and did not find a connected bus item for a bus entry,
|
|
|
|
// we should do a manual scan in case there is a bus item on this connection
|
|
|
|
// point but we didn't pick it up earlier because there is *also* a net item here.
|
|
|
|
if( connected_item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
|
|
|
auto bus_entry = static_cast<SCH_BUS_WIRE_ENTRY*>( connected_item );
|
|
|
|
|
|
|
|
if( !bus_entry->m_connected_bus_item )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = aSheet.LastScreen();
|
|
|
|
SCH_LINE* bus = screen->GetBus( it.first );
|
|
|
|
|
|
|
|
if( bus )
|
|
|
|
bus_entry->m_connected_bus_item = bus;
|
2021-11-25 18:36:30 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2019-04-12 03:38:32 +00:00
|
|
|
|
2022-03-28 22:34:13 +00:00
|
|
|
return 1;
|
|
|
|
};
|
2019-04-12 03:38:32 +00:00
|
|
|
|
2022-12-02 20:01:34 +00:00
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
|
|
|
|
tp.push_loop( connection_vec.size(),
|
2022-06-15 00:41:10 +00:00
|
|
|
[&]( const int a, const int b)
|
|
|
|
{
|
|
|
|
for( int ii = a; ii < b; ++ii )
|
|
|
|
update_lambda( connection_vec[ii] );
|
2022-12-02 20:01:34 +00:00
|
|
|
});
|
|
|
|
tp.wait_for_tasks();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
void CONNECTION_GRAPH::buildItemSubGraphs()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
// Recache all bus aliases for later use
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_RET( m_schematic, wxS( "Connection graph cannot be built without schematic pointer" ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_LIST all_sheets = m_schematic->GetSheets();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < all_sheets.size(); i++ )
|
|
|
|
{
|
2022-09-11 17:41:54 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : all_sheets[i].LastScreen()->GetBusAliases() )
|
2019-03-11 21:32:05 +00:00
|
|
|
m_bus_alias_cache[ alias->GetName() ] = alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build subgraphs from items (on a per-sheet basis)
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
for( SCH_ITEM* item : m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
for( const auto& it : item->m_connection_map )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = it.first;
|
|
|
|
SCH_CONNECTION* connection = it.second;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( connection->SubgraphCode() == 0 )
|
|
|
|
{
|
2021-01-07 21:54:54 +00:00
|
|
|
CONNECTION_SUBGRAPH* subgraph = new CONNECTION_SUBGRAPH( this );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
subgraph->m_code = m_last_subgraph_code++;
|
|
|
|
subgraph->m_sheet = sheet;
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
subgraph->AddItem( item );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-04 01:47:26 +00:00
|
|
|
connection->SetSubgraphCode( subgraph->m_code );
|
2020-05-24 14:46:05 +00:00
|
|
|
m_item_to_subgraph_map[item] = subgraph;
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
std::list<SCH_ITEM*> memberlist;
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
auto get_items =
|
|
|
|
[&]( SCH_ITEM* aItem ) -> bool
|
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* conn = aItem->GetOrInitConnection( sheet, this );
|
2022-03-11 21:46:21 +00:00
|
|
|
bool unique = !( aItem->GetFlags() & CANDIDATE );
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2022-03-17 17:09:02 +00:00
|
|
|
if( conn && !conn->SubgraphCode() )
|
|
|
|
aItem->SetFlags( CANDIDATE );
|
2022-03-11 21:46:21 +00:00
|
|
|
|
|
|
|
return ( unique && conn && ( conn->SubgraphCode() == 0 ) );
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
std::copy_if( item->ConnectedItems( sheet ).begin(),
|
|
|
|
item->ConnectedItems( sheet ).end(),
|
2022-03-11 21:46:21 +00:00
|
|
|
std::back_inserter( memberlist ), get_items );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
for( SCH_ITEM* connected_item : memberlist )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
if( connected_item->Type() == SCH_NO_CONNECT_T )
|
|
|
|
subgraph->m_no_connect = connected_item;
|
|
|
|
|
2021-01-07 21:54:54 +00:00
|
|
|
SCH_CONNECTION* connected_conn = connected_item->Connection( &sheet );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
wxASSERT( connected_conn );
|
|
|
|
|
|
|
|
if( connected_conn->SubgraphCode() == 0 )
|
|
|
|
{
|
|
|
|
connected_conn->SetSubgraphCode( subgraph->m_code );
|
2020-05-24 14:46:05 +00:00
|
|
|
m_item_to_subgraph_map[connected_item] = subgraph;
|
2019-05-05 23:48:43 +00:00
|
|
|
subgraph->AddItem( connected_item );
|
2022-03-28 21:51:33 +00:00
|
|
|
SCH_ITEM_SET& citemset = connected_item->ConnectedItems( sheet );
|
|
|
|
|
|
|
|
for( SCH_ITEM* citem : citemset )
|
|
|
|
{
|
|
|
|
if( citem->HasFlag( CANDIDATE ) )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-03-28 21:51:33 +00:00
|
|
|
if( get_items( citem ) )
|
|
|
|
memberlist.push_back( citem );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
for( SCH_ITEM* connected_item : memberlist )
|
|
|
|
connected_item->ClearFlags( CANDIDATE );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
subgraph->m_dirty = true;
|
|
|
|
m_subgraphs.push_back( subgraph );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
void CONNECTION_GRAPH::resolveAllDrivers()
|
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
// Resolve drivers for subgraphs and propagate connectivity info
|
2019-04-06 01:14:15 +00:00
|
|
|
std::vector<CONNECTION_SUBGRAPH*> dirty_graphs;
|
|
|
|
|
|
|
|
std::copy_if( m_subgraphs.begin(), m_subgraphs.end(), std::back_inserter( dirty_graphs ),
|
2020-03-16 11:05:01 +00:00
|
|
|
[&] ( const CONNECTION_SUBGRAPH* candidate )
|
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
return candidate->m_dirty;
|
|
|
|
} );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
std::vector<std::future<size_t>> returns( dirty_graphs.size() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
auto update_lambda = []( CONNECTION_SUBGRAPH* subgraph ) -> size_t
|
|
|
|
{
|
|
|
|
if( !subgraph->m_dirty )
|
|
|
|
return 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Special processing for some items
|
2022-07-29 21:02:35 +00:00
|
|
|
for( SCH_ITEM* item : subgraph->m_items )
|
2022-06-15 00:41:10 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
2019-04-06 01:14:15 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
subgraph->m_no_connect = item;
|
|
|
|
break;
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
subgraph->m_bus_entry = item;
|
|
|
|
break;
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
|
|
|
auto pin = static_cast<SCH_PIN*>( item );
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
|
|
|
|
subgraph->m_no_connect = item;
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
break;
|
2019-04-06 01:14:15 +00:00
|
|
|
}
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-06 01:14:15 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
subgraph->ResolveDrivers( true );
|
|
|
|
subgraph->m_dirty = false;
|
|
|
|
|
2019-04-06 01:14:15 +00:00
|
|
|
return 1;
|
|
|
|
};
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-02 20:01:34 +00:00
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
|
|
|
|
tp.push_loop( dirty_graphs.size(),
|
2022-06-15 00:41:10 +00:00
|
|
|
[&]( const int a, const int b)
|
|
|
|
{
|
|
|
|
for( int ii = a; ii < b; ++ii )
|
|
|
|
update_lambda( dirty_graphs[ii] );
|
2022-12-02 20:01:34 +00:00
|
|
|
});
|
|
|
|
tp.wait_for_tasks();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-25 03:47:57 +00:00
|
|
|
// Now discard any non-driven subgraphs from further consideration
|
|
|
|
|
2019-04-25 04:37:10 +00:00
|
|
|
std::copy_if( m_subgraphs.begin(), m_subgraphs.end(), std::back_inserter( m_driver_subgraphs ),
|
2020-03-16 11:05:01 +00:00
|
|
|
[&] ( const CONNECTION_SUBGRAPH* candidate ) -> bool
|
|
|
|
{
|
|
|
|
return candidate->m_driver;
|
2019-04-25 03:47:57 +00:00
|
|
|
} );
|
2022-03-11 21:46:21 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 03:47:57 +00:00
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
void CONNECTION_GRAPH::collectAllDriverValues()
|
|
|
|
{
|
2019-03-18 22:38:06 +00:00
|
|
|
// Check for subgraphs with the same net name but only weak drivers.
|
|
|
|
// For example, two wires that are both connected to hierarchical
|
|
|
|
// sheet pins that happen to have the same name, but are not the same.
|
|
|
|
|
2019-04-25 04:37:10 +00:00
|
|
|
for( auto&& subgraph : m_driver_subgraphs )
|
2019-03-28 03:36:35 +00:00
|
|
|
{
|
2019-04-25 03:47:57 +00:00
|
|
|
wxString full_name = subgraph->m_driver_connection->Name();
|
|
|
|
wxString name = subgraph->m_driver_connection->Name( true );
|
|
|
|
m_net_name_to_subgraphs_map[full_name].emplace_back( subgraph );
|
|
|
|
|
2020-10-09 02:25:57 +00:00
|
|
|
// For vector buses, we need to cache the prefix also, as two different instances of the
|
|
|
|
// weakly driven pin may have the same prefix but different vector start and end. We need
|
|
|
|
// to treat those as needing renaming also, because otherwise if they end up on a sheet with
|
|
|
|
// common usage, they will be incorrectly merged.
|
|
|
|
if( subgraph->m_driver_connection->Type() == CONNECTION_TYPE::BUS )
|
|
|
|
{
|
|
|
|
wxString prefixOnly = full_name.BeforeFirst( '[' ) + wxT( "[]" );
|
|
|
|
m_net_name_to_subgraphs_map[prefixOnly].emplace_back( subgraph );
|
|
|
|
}
|
|
|
|
|
2019-04-25 03:47:57 +00:00
|
|
|
subgraph->m_dirty = true;
|
|
|
|
|
2019-03-28 03:36:35 +00:00
|
|
|
if( subgraph->m_strong_driver )
|
|
|
|
{
|
2019-04-25 03:47:57 +00:00
|
|
|
SCH_ITEM* driver = subgraph->m_driver;
|
|
|
|
SCH_SHEET_PATH sheet = subgraph->m_sheet;
|
2019-03-28 03:36:35 +00:00
|
|
|
|
|
|
|
switch( driver->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2019-03-28 03:36:35 +00:00
|
|
|
{
|
|
|
|
m_local_label_cache[std::make_pair( sheet, name )].push_back( subgraph );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
|
|
|
m_global_label_cache[name].push_back( subgraph );
|
|
|
|
break;
|
|
|
|
}
|
2019-04-03 09:14:36 +00:00
|
|
|
case SCH_PIN_T:
|
2019-03-28 03:36:35 +00:00
|
|
|
{
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( driver );
|
2023-01-18 15:06:46 +00:00
|
|
|
wxASSERT( pin->IsGlobalPower() );
|
2019-03-28 03:36:35 +00:00
|
|
|
m_global_label_cache[name].push_back( subgraph );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2022-09-19 16:09:59 +00:00
|
|
|
{
|
|
|
|
UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Unexpected strong driver %s" ),
|
2023-01-12 03:27:44 +00:00
|
|
|
driver->GetItemDescription( &unitsProvider ) );
|
2019-03-28 03:36:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-09-19 16:09:59 +00:00
|
|
|
}
|
2019-03-28 03:36:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 21:46:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:35 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
void CONNECTION_GRAPH::generateBusAliasMembers()
|
|
|
|
{
|
|
|
|
std::vector<CONNECTION_SUBGRAPH*> new_subgraphs;
|
|
|
|
|
2023-06-02 21:24:05 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
2023-04-04 19:17:17 +00:00
|
|
|
{
|
2023-06-02 21:24:05 +00:00
|
|
|
SCH_ITEM_SET vec = subgraph->GetAllBusLabels();
|
2023-04-04 19:17:17 +00:00
|
|
|
|
2023-06-02 21:24:05 +00:00
|
|
|
for( SCH_ITEM* item : vec )
|
2023-04-04 19:17:17 +00:00
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
|
|
|
|
|
2023-06-02 21:24:05 +00:00
|
|
|
SCH_CONNECTION dummy( item, subgraph->m_sheet );
|
|
|
|
dummy.SetGraph( this );
|
2023-04-04 19:17:17 +00:00
|
|
|
dummy.ConfigureFromLabel( label->GetText() );
|
|
|
|
|
|
|
|
wxLogTrace( ConnTrace, wxS( "new bus label (%s)" ), label->GetText() );
|
|
|
|
|
2023-06-02 21:24:05 +00:00
|
|
|
for( const auto& conn : dummy.Members() )
|
2023-04-04 19:17:17 +00:00
|
|
|
{
|
|
|
|
wxString name = conn->FullLocalName();
|
|
|
|
|
|
|
|
CONNECTION_SUBGRAPH* new_sg = new CONNECTION_SUBGRAPH( this );
|
2023-06-02 21:24:05 +00:00
|
|
|
SCH_CONNECTION* new_conn = new SCH_CONNECTION( item, subgraph->m_sheet );
|
|
|
|
new_conn->SetGraph( this );
|
2023-04-04 19:17:17 +00:00
|
|
|
|
|
|
|
new_conn->SetName( name );
|
|
|
|
new_conn->SetType( CONNECTION_TYPE::NET );
|
|
|
|
int code = assignNewNetCode( *new_conn );
|
|
|
|
|
2023-06-02 21:24:05 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "SG(%ld), Adding full local name (%s) with sg (%d) on subsheet %s" ), subgraph->m_code,
|
|
|
|
name, code, subgraph->m_sheet.PathHumanReadable() );
|
2023-04-04 19:17:17 +00:00
|
|
|
|
|
|
|
new_sg->m_driver_connection = new_conn;
|
|
|
|
new_sg->m_code = m_last_subgraph_code++;
|
|
|
|
new_sg->m_sheet = subgraph->GetSheet();
|
|
|
|
new_sg->m_is_bus_member = true;
|
|
|
|
new_sg->m_strong_driver = true;
|
|
|
|
/// Need to figure out why these sgs are not getting connected to their bus parents
|
|
|
|
|
|
|
|
NET_NAME_CODE_CACHE_KEY key = { new_sg->GetNetName(), code };
|
|
|
|
m_net_code_to_subgraphs_map[ key ].push_back( new_sg );
|
|
|
|
m_net_name_to_subgraphs_map[ name ].push_back( new_sg );
|
|
|
|
m_subgraphs.push_back( new_sg );
|
|
|
|
new_subgraphs.push_back( new_sg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::copy( new_subgraphs.begin(), new_subgraphs.end(), std::back_inserter( m_driver_subgraphs ) );
|
|
|
|
}
|
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
void CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs()
|
2022-03-11 21:46:21 +00:00
|
|
|
{
|
2023-01-18 14:58:47 +00:00
|
|
|
// Generate subgraphs for global power pins. These will be merged with other subgraphs
|
2019-04-20 01:45:33 +00:00
|
|
|
// on the same sheet in the next loop.
|
2023-01-18 14:58:47 +00:00
|
|
|
// These are NOT limited to power symbols, we support legacy invisible + power-in pins
|
|
|
|
// on non-power symbols.
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
std::unordered_map<int, CONNECTION_SUBGRAPH*> global_power_pin_subgraphs;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
for( const auto& it : m_global_power_pins )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
SCH_SHEET_PATH sheet = it.first;
|
|
|
|
SCH_PIN* pin = it.second;
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
if( !pin->ConnectedItems( sheet ).empty() && !pin->GetLibPin()->GetParent()->IsPower() )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
// ERC will warn about this: user has wired up an invisible pin
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* connection = pin->GetOrInitConnection( sheet, this );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
|
|
|
// If this pin already has a subgraph, don't need to process
|
2022-03-11 21:46:21 +00:00
|
|
|
if( !connection || connection->SubgraphCode() > 0 )
|
2019-04-20 01:45:33 +00:00
|
|
|
continue;
|
|
|
|
|
2023-01-18 17:49:58 +00:00
|
|
|
// Proper modern power symbols get their net name from the value field
|
|
|
|
// in the symbol, but we support legacy non-power symbols with global
|
|
|
|
// power connections based on invisible, power-in, pin's names.
|
|
|
|
if( pin->GetLibPin()->GetParent()->IsPower() )
|
2023-05-05 13:21:56 +00:00
|
|
|
connection->SetName( pin->GetParentSymbol()->GetValueFieldText( true, &sheet, false ) );
|
2023-01-18 17:49:58 +00:00
|
|
|
else
|
|
|
|
connection->SetName( pin->GetShownName() );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
|
|
|
int code = assignNewNetCode( *connection );
|
|
|
|
|
|
|
|
connection->SetNetCode( code );
|
|
|
|
|
|
|
|
CONNECTION_SUBGRAPH* subgraph;
|
2023-01-18 14:58:47 +00:00
|
|
|
auto jj = global_power_pin_subgraphs.find( code );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
if( jj != global_power_pin_subgraphs.end() )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
subgraph = jj->second;
|
2019-04-20 01:45:33 +00:00
|
|
|
subgraph->AddItem( pin );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
subgraph = new CONNECTION_SUBGRAPH( this );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
|
|
|
subgraph->m_code = m_last_subgraph_code++;
|
|
|
|
subgraph->m_sheet = sheet;
|
|
|
|
|
|
|
|
subgraph->AddItem( pin );
|
|
|
|
subgraph->ResolveDrivers();
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
NET_NAME_CODE_CACHE_KEY key = { subgraph->GetNetName(), code };
|
2020-01-18 17:57:02 +00:00
|
|
|
m_net_code_to_subgraphs_map[ key ].push_back( subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
m_subgraphs.push_back( subgraph );
|
2019-04-25 04:37:10 +00:00
|
|
|
m_driver_subgraphs.push_back( subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
global_power_pin_subgraphs[code] = subgraph;
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connection->SetSubgraphCode( subgraph->m_code );
|
|
|
|
}
|
2022-03-11 21:46:21 +00:00
|
|
|
}
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
|
|
|
|
void CONNECTION_GRAPH::processSubGraphs()
|
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
// Here we do all the local (sheet) processing of each subgraph, including assigning net
|
|
|
|
// codes, merging subgraphs together that use label connections, etc.
|
|
|
|
|
2019-04-29 23:41:03 +00:00
|
|
|
// Cache remaining valid subgraphs by sheet path
|
2021-11-24 13:19:50 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
2019-04-29 23:41:03 +00:00
|
|
|
m_sheet_to_subgraphs_map[ subgraph->m_sheet ].emplace_back( subgraph );
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
std::unordered_set<CONNECTION_SUBGRAPH*> invalidated_subgraphs;
|
|
|
|
|
2020-04-19 22:20:51 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
if( subgraph->m_absorbed )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_CONNECTION* connection = subgraph->m_driver_connection;
|
|
|
|
SCH_SHEET_PATH sheet = subgraph->m_sheet;
|
2019-04-25 03:47:57 +00:00
|
|
|
wxString name = connection->Name();
|
|
|
|
|
|
|
|
// Test subgraphs with weak drivers for net name conflicts and fix them
|
|
|
|
unsigned suffix = 1;
|
|
|
|
|
2020-07-21 00:41:56 +00:00
|
|
|
auto create_new_name =
|
|
|
|
[&suffix]( SCH_CONNECTION* aConn ) -> wxString
|
|
|
|
{
|
|
|
|
wxString newName;
|
2022-07-09 22:30:52 +00:00
|
|
|
wxString suffixStr = std::to_wstring( suffix );
|
2020-07-21 00:41:56 +00:00
|
|
|
|
|
|
|
// For group buses with a prefix, we can add the suffix to the prefix.
|
|
|
|
// If they don't have a prefix, we force the creation of a prefix so that
|
|
|
|
// two buses don't get inadvertently shorted together.
|
|
|
|
if( aConn->Type() == CONNECTION_TYPE::BUS_GROUP )
|
|
|
|
{
|
|
|
|
wxString prefix = aConn->BusPrefix();
|
|
|
|
|
|
|
|
if( prefix.empty() )
|
|
|
|
prefix = wxT( "BUS" ); // So result will be "BUS_1{...}"
|
|
|
|
|
|
|
|
wxString oldName = aConn->Name().AfterFirst( '{' );
|
|
|
|
|
2022-07-09 22:30:52 +00:00
|
|
|
newName << prefix << wxT( "_" ) << suffixStr << wxT( "{" ) << oldName;
|
2020-07-21 00:41:56 +00:00
|
|
|
|
|
|
|
aConn->ConfigureFromLabel( newName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-09 22:30:52 +00:00
|
|
|
newName << aConn->Name() << wxT( "_" ) << suffixStr;
|
|
|
|
aConn->SetSuffix( wxString( wxT( "_" ) ) << suffixStr );
|
2020-07-21 00:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
suffix++;
|
|
|
|
return newName;
|
|
|
|
};
|
2019-04-25 03:47:57 +00:00
|
|
|
|
|
|
|
if( !subgraph->m_strong_driver )
|
|
|
|
{
|
2020-10-09 02:25:57 +00:00
|
|
|
std::vector<CONNECTION_SUBGRAPH*>* vec = &m_net_name_to_subgraphs_map.at( name );
|
|
|
|
|
|
|
|
// If we are a unique bus vector, check if we aren't actually unique because of another
|
|
|
|
// subgraph with a similar bus vector
|
|
|
|
if( vec->size() <= 1 && subgraph->m_driver_connection->Type() == CONNECTION_TYPE::BUS )
|
|
|
|
{
|
|
|
|
wxString prefixOnly = name.BeforeFirst( '[' ) + wxT( "[]" );
|
|
|
|
vec = &m_net_name_to_subgraphs_map.at( prefixOnly );
|
|
|
|
}
|
2019-04-25 03:47:57 +00:00
|
|
|
|
2020-10-09 02:25:57 +00:00
|
|
|
if( vec->size() > 1 )
|
2019-04-25 03:47:57 +00:00
|
|
|
{
|
2020-07-21 00:41:56 +00:00
|
|
|
wxString new_name = create_new_name( connection );
|
2019-04-25 03:47:57 +00:00
|
|
|
|
|
|
|
while( m_net_name_to_subgraphs_map.count( new_name ) )
|
2020-07-21 00:41:56 +00:00
|
|
|
new_name = create_new_name( connection );
|
2019-04-25 03:47:57 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%ld (%s) is weakly driven and not unique. Changing to %s." ),
|
2019-04-25 03:47:57 +00:00
|
|
|
subgraph->m_code, name, new_name );
|
|
|
|
|
2022-11-22 12:49:49 +00:00
|
|
|
alg::delete_matching( *vec, subgraph );
|
2019-04-25 03:47:57 +00:00
|
|
|
|
|
|
|
m_net_name_to_subgraphs_map[new_name].emplace_back( subgraph );
|
|
|
|
|
|
|
|
name = new_name;
|
|
|
|
}
|
2023-04-04 19:17:17 +00:00
|
|
|
else if( subgraph->m_driver )
|
2020-02-05 14:23:55 +00:00
|
|
|
{
|
|
|
|
// If there is no conflict, promote sheet pins to be strong drivers so that they
|
|
|
|
// will be considered below for propagation/merging.
|
|
|
|
|
2020-04-19 22:20:51 +00:00
|
|
|
// It is possible for this to generate a conflict if the sheet pin has the same
|
|
|
|
// name as a global label on the same sheet, because global merging will then treat
|
|
|
|
// this subgraph as if it had a matching local label. So, for those cases, we
|
|
|
|
// don't apply this promotion
|
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
if( subgraph->m_driver->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
2020-04-19 22:20:51 +00:00
|
|
|
bool conflict = false;
|
|
|
|
wxString global_name = connection->Name( true );
|
2020-11-23 17:03:39 +00:00
|
|
|
auto kk = m_net_name_to_subgraphs_map.find( global_name );
|
2020-02-05 14:23:55 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
if( kk != m_net_name_to_subgraphs_map.end() )
|
2020-04-19 22:20:51 +00:00
|
|
|
{
|
|
|
|
// A global will conflict if it is on the same sheet as this subgraph, since
|
|
|
|
// it would be connected by implicit local label linking
|
2020-11-23 17:03:39 +00:00
|
|
|
std::vector<CONNECTION_SUBGRAPH*>& candidates = kk->second;
|
2020-04-19 22:20:51 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( const CONNECTION_SUBGRAPH* candidate : candidates )
|
2020-04-19 22:20:51 +00:00
|
|
|
{
|
|
|
|
if( candidate->m_sheet == sheet )
|
|
|
|
conflict = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( conflict )
|
|
|
|
{
|
2020-10-09 01:24:24 +00:00
|
|
|
wxLogTrace( ConnTrace,
|
2023-01-17 04:14:38 +00:00
|
|
|
wxS( "%ld (%s) skipped for promotion due to potential conflict" ),
|
2020-10-09 01:24:24 +00:00
|
|
|
subgraph->m_code, name );
|
2020-04-19 22:20:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-19 16:09:59 +00:00
|
|
|
UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
|
|
|
|
|
2020-10-09 01:24:24 +00:00
|
|
|
wxLogTrace( ConnTrace,
|
2023-01-17 04:14:38 +00:00
|
|
|
wxS( "%ld (%s) weakly driven by unique sheet pin %s, promoting" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
subgraph->m_code, name,
|
2023-01-12 03:27:44 +00:00
|
|
|
subgraph->m_driver->GetItemDescription( &unitsProvider ) );
|
2020-04-19 22:20:51 +00:00
|
|
|
|
|
|
|
subgraph->m_strong_driver = true;
|
|
|
|
}
|
2020-02-05 14:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-25 03:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assign net codes
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( connection->IsBus() )
|
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
int code = -1;
|
|
|
|
auto it = m_bus_name_to_code_map.find( name );
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
if( it != m_bus_name_to_code_map.end() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
code = it->second;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2019-04-03 09:14:36 +00:00
|
|
|
else
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
code = m_last_bus_code++;
|
|
|
|
m_bus_name_to_code_map[ name ] = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
connection->SetBusCode( code );
|
2019-04-20 01:45:33 +00:00
|
|
|
assignNetCodesToBus( connection );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assignNewNetCode( *connection );
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Reset the flag for the next loop below
|
|
|
|
subgraph->m_dirty = true;
|
2019-04-10 06:40:24 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Next, we merge together subgraphs that have label connections, and create
|
|
|
|
// neighbor links for subgraphs that are part of a bus on the same sheet.
|
|
|
|
// For merging, we consider each possible strong driver.
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// If this subgraph doesn't have a strong driver, let's skip it, since there is no
|
|
|
|
// way it will be merged with anything.
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( !subgraph->m_strong_driver )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// candidate_subgraphs will contain each valid, non-bus subgraph on the same sheet
|
|
|
|
// as the subgraph we are considering that has a strong driver.
|
|
|
|
// Weakly driven subgraphs are not considered since they will never be absorbed or
|
|
|
|
// form neighbor links.
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
std::vector<CONNECTION_SUBGRAPH*> candidate_subgraphs;
|
2019-04-29 23:41:03 +00:00
|
|
|
std::copy_if( m_sheet_to_subgraphs_map[ subgraph->m_sheet ].begin(),
|
|
|
|
m_sheet_to_subgraphs_map[ subgraph->m_sheet ].end(),
|
2019-04-20 01:45:33 +00:00
|
|
|
std::back_inserter( candidate_subgraphs ),
|
|
|
|
[&] ( const CONNECTION_SUBGRAPH* candidate )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
return ( !candidate->m_absorbed &&
|
|
|
|
candidate->m_strong_driver &&
|
|
|
|
candidate != subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// This is a list of connections on the current subgraph to compare to the
|
|
|
|
// drivers of each candidate subgraph. If the current subgraph is a bus,
|
|
|
|
// we should consider each bus member.
|
2020-01-04 15:38:43 +00:00
|
|
|
std::vector< std::shared_ptr<SCH_CONNECTION> > connections_to_check;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Also check the main driving connection
|
|
|
|
connections_to_check.push_back( std::make_shared<SCH_CONNECTION>( *connection ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto add_connections_to_check =
|
|
|
|
[&] ( CONNECTION_SUBGRAPH* aSubgraph )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* possible_driver : aSubgraph->m_items )
|
|
|
|
{
|
|
|
|
if( possible_driver == aSubgraph->m_driver )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto c = getDefaultConnection( possible_driver, aSubgraph );
|
2019-05-13 00:23:16 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( c )
|
|
|
|
{
|
|
|
|
if( c->Type() != aSubgraph->m_driver_connection->Type() )
|
|
|
|
continue;
|
2019-05-13 00:23:16 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( c->Name( true ) == aSubgraph->m_driver_connection->Name( true ) )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
connections_to_check.push_back( c );
|
|
|
|
wxLogTrace( ConnTrace,
|
2023-01-17 04:14:38 +00:00
|
|
|
wxS( "%lu (%s): Adding secondary driver %s" ), aSubgraph->m_code,
|
2022-08-14 11:03:18 +00:00
|
|
|
aSubgraph->m_driver_connection->Name( true ),
|
|
|
|
c->Name( true ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Now add other strong drivers
|
|
|
|
// The actual connection attached to these items will have been overwritten
|
|
|
|
// by the chosen driver of the subgraph, so we need to create a dummy connection
|
|
|
|
add_connections_to_check( subgraph );
|
2019-04-06 01:14:15 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
for( unsigned i = 0; i < connections_to_check.size(); i++ )
|
|
|
|
{
|
|
|
|
auto member = connections_to_check[i];
|
|
|
|
|
|
|
|
if( member->IsBus() )
|
|
|
|
{
|
|
|
|
connections_to_check.insert( connections_to_check.end(),
|
|
|
|
member->Members().begin(),
|
|
|
|
member->Members().end() );
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
wxString test_name = member->Name( true );
|
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* candidate : candidate_subgraphs )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-04-08 15:22:34 +00:00
|
|
|
if( candidate->m_absorbed || candidate == subgraph )
|
2019-04-20 01:45:33 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool match = false;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( candidate->m_driver_connection->Name( true ) == test_name )
|
2019-04-12 03:38:32 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
match = true;
|
2019-04-12 03:38:32 +00:00
|
|
|
}
|
2019-04-20 01:45:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !candidate->m_multiple_drivers )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
for( SCH_ITEM *driver : candidate->m_drivers )
|
|
|
|
{
|
|
|
|
if( driver == candidate->m_driver )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-12 22:41:04 +00:00
|
|
|
// Sheet pins are not candidates for merging
|
|
|
|
if( driver->Type() == SCH_SHEET_PIN_T )
|
|
|
|
continue;
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( driver->Type() == SCH_PIN_T )
|
|
|
|
{
|
2019-07-27 15:28:59 +00:00
|
|
|
auto pin = static_cast<SCH_PIN*>( driver );
|
|
|
|
|
2023-02-27 14:23:34 +00:00
|
|
|
if( pin->IsGlobalPower()
|
|
|
|
&& pin->GetDefaultNetName( sheet ) == test_name )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxASSERT( driver->Type() == SCH_LABEL_T ||
|
|
|
|
driver->Type() == SCH_GLOBAL_LABEL_T ||
|
2019-05-12 22:41:04 +00:00
|
|
|
driver->Type() == SCH_HIER_LABEL_T );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
if( subgraph->GetNameForDriver( driver ) == test_name )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( match )
|
|
|
|
{
|
|
|
|
if( connection->IsBus() && candidate->m_driver_connection->IsNet() )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) has bus child %lu (%s)" ), subgraph->m_code,
|
2019-04-20 01:45:33 +00:00
|
|
|
connection->Name(), candidate->m_code, member->Name() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
subgraph->m_bus_neighbors[member].insert( candidate );
|
|
|
|
candidate->m_bus_parents[member].insert( subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) absorbs neighbor %lu (%s)" ),
|
2019-04-20 01:45:33 +00:00
|
|
|
subgraph->m_code, connection->Name(),
|
2019-05-13 00:23:16 +00:00
|
|
|
candidate->m_code, candidate->m_driver_connection->Name() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-04 15:38:43 +00:00
|
|
|
// Candidate may have other non-chosen drivers we need to follow
|
|
|
|
add_connections_to_check( candidate );
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
subgraph->Absorb( candidate );
|
|
|
|
invalidated_subgraphs.insert( subgraph );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Update any subgraph that was invalidated above
|
2020-11-23 17:03:39 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : invalidated_subgraphs )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
if( subgraph->m_absorbed )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
if( !subgraph->ResolveDrivers() )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( subgraph->m_driver_connection->IsBus() )
|
|
|
|
assignNetCodesToBus( subgraph->m_driver_connection );
|
2019-03-11 21:32:05 +00:00
|
|
|
else
|
2019-04-20 01:45:33 +00:00
|
|
|
assignNewNetCode( *subgraph->m_driver_connection );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Re-resolving drivers for %lu (%s)" ), subgraph->m_code,
|
2019-04-20 01:45:33 +00:00
|
|
|
subgraph->m_driver_connection->Name() );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(JE) This won't give the same subgraph IDs (and eventually net/graph codes)
|
|
|
|
// to the same subgraph necessarily if it runs over and over again on the same
|
|
|
|
// sheet. We need:
|
|
|
|
//
|
|
|
|
// a) a cache of net/bus codes, like used before
|
|
|
|
// b) to persist the CONNECTION_GRAPH globally so the cache is persistent,
|
|
|
|
// c) some way of trying to avoid changing net names. so we should keep track
|
|
|
|
// of the previous driver of a net, and if it comes down to choosing between
|
|
|
|
// equally-prioritized drivers, choose the one that already exists as a driver
|
|
|
|
// on some portion of the items.
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void CONNECTION_GRAPH::buildConnectionGraph( std::function<void( SCH_ITEM* )>* aChangedItemHandler )
|
2022-03-11 21:46:21 +00:00
|
|
|
{
|
|
|
|
// Recache all bus aliases for later use
|
|
|
|
wxCHECK_RET( m_schematic, wxT( "Connection graph cannot be built without schematic pointer" ) );
|
|
|
|
|
|
|
|
SCH_SHEET_LIST all_sheets = m_schematic->GetSheets();
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < all_sheets.size(); i++ )
|
|
|
|
{
|
2022-09-11 17:41:54 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : all_sheets[i].LastScreen()->GetBusAliases() )
|
2022-03-11 21:46:21 +00:00
|
|
|
m_bus_alias_cache[ alias->GetName() ] = alias;
|
|
|
|
}
|
|
|
|
|
2022-03-28 21:51:33 +00:00
|
|
|
PROF_TIMER sub_graph( "buildItemSubGraphs" );
|
2022-03-11 21:46:21 +00:00
|
|
|
buildItemSubGraphs();
|
|
|
|
|
2022-03-28 21:51:33 +00:00
|
|
|
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )
|
|
|
|
sub_graph.Show();
|
|
|
|
|
|
|
|
|
2022-03-11 21:46:21 +00:00
|
|
|
/**
|
|
|
|
* TODO(JE): Net codes are non-deterministic. Fortunately, they are also not really used for
|
|
|
|
* anything. We should consider removing them entirely and just using net names everywhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
resolveAllDrivers();
|
|
|
|
|
|
|
|
collectAllDriverValues();
|
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
generateGlobalPowerPinSubGraphs();
|
2022-03-11 21:46:21 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
generateBusAliasMembers();
|
|
|
|
|
2022-03-28 21:51:33 +00:00
|
|
|
PROF_TIMER proc_sub_graph( "ProcessSubGraphs" );
|
2022-03-11 21:46:21 +00:00
|
|
|
processSubGraphs();
|
|
|
|
|
2022-03-28 21:51:33 +00:00
|
|
|
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )
|
|
|
|
proc_sub_graph.Show();
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Absorbed subgraphs should no longer be considered
|
2021-10-01 10:52:34 +00:00
|
|
|
alg::delete_if( m_driver_subgraphs, [&]( const CONNECTION_SUBGRAPH* candidate ) -> bool
|
|
|
|
{
|
|
|
|
return candidate->m_absorbed;
|
|
|
|
} );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
|
|
|
// Store global subgraphs for later reference
|
|
|
|
std::vector<CONNECTION_SUBGRAPH*> global_subgraphs;
|
2019-04-25 04:37:10 +00:00
|
|
|
std::copy_if( m_driver_subgraphs.begin(), m_driver_subgraphs.end(),
|
2019-04-20 01:45:33 +00:00
|
|
|
std::back_inserter( global_subgraphs ),
|
2020-03-16 11:05:01 +00:00
|
|
|
[&] ( const CONNECTION_SUBGRAPH* candidate ) -> bool
|
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
return !candidate->m_local_driver;
|
|
|
|
} );
|
|
|
|
|
2019-04-29 23:41:03 +00:00
|
|
|
// Recache remaining valid subgraphs by sheet path
|
|
|
|
m_sheet_to_subgraphs_map.clear();
|
2020-11-25 22:16:06 +00:00
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
2019-04-29 23:41:03 +00:00
|
|
|
m_sheet_to_subgraphs_map[ subgraph->m_sheet ].emplace_back( subgraph );
|
|
|
|
|
2022-12-02 20:01:34 +00:00
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
|
|
|
|
tp.push_loop( m_driver_subgraphs.size(),
|
2022-06-15 00:41:10 +00:00
|
|
|
[&]( const int a, const int b)
|
2021-01-14 15:14:09 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
for( int ii = a; ii < b; ++ii )
|
|
|
|
m_driver_subgraphs[ii]->UpdateItemConnections();
|
2022-12-02 20:01:34 +00:00
|
|
|
});
|
|
|
|
tp.wait_for_tasks();
|
2021-01-14 15:14:09 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Next time through the subgraphs, we do some post-processing to handle things like
|
|
|
|
// connecting bus members to their neighboring subgraphs, and then propagate connections
|
|
|
|
// through the hierarchy
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-25 22:16:06 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-06 01:14:15 +00:00
|
|
|
if( !subgraph->m_dirty )
|
2019-03-11 21:32:05 +00:00
|
|
|
continue;
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Processing %lu (%s) for propagation" ), subgraph->m_code,
|
2021-05-10 21:54:09 +00:00
|
|
|
subgraph->m_driver_connection->Name() );
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// For subgraphs that are driven by a global (power port or label) and have more
|
|
|
|
// than one global driver, we need to seek out other subgraphs driven by the
|
|
|
|
// same name as the non-chosen driver and update them to match the chosen one.
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( !subgraph->m_local_driver && subgraph->m_multiple_drivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
for( SCH_ITEM* driver : subgraph->m_drivers )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
if( driver == subgraph->m_driver )
|
2019-03-11 21:32:05 +00:00
|
|
|
continue;
|
|
|
|
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& secondary_name = subgraph->GetNameForDriver( driver );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( secondary_name == subgraph->m_driver_connection->Name() )
|
|
|
|
continue;
|
2019-04-08 03:54:24 +00:00
|
|
|
|
2020-03-06 00:08:55 +00:00
|
|
|
bool secondary_is_global = CONNECTION_SUBGRAPH::GetDriverPriority( driver )
|
|
|
|
>= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN;
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* candidate : global_subgraphs )
|
2019-04-08 03:54:24 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
if( candidate == subgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
continue;
|
|
|
|
|
2020-03-06 00:08:55 +00:00
|
|
|
if( !secondary_is_global && candidate->m_sheet != subgraph->m_sheet )
|
|
|
|
continue;
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
SCH_CONNECTION* conn = candidate->m_driver_connection;
|
2019-04-08 03:54:24 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( conn->Name() == secondary_name )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Global %lu (%s) promoted to %s" ), candidate->m_code,
|
2019-04-20 01:45:33 +00:00
|
|
|
conn->Name(), subgraph->m_driver_connection->Name() );
|
|
|
|
|
|
|
|
conn->Clone( *subgraph->m_driver_connection );
|
2019-05-05 04:03:58 +00:00
|
|
|
|
|
|
|
candidate->m_dirty = false;
|
2023-05-09 19:11:46 +00:00
|
|
|
propagateToNeighbors( candidate, false );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// This call will handle descending the hierarchy and updating child subgraphs
|
2023-01-13 01:01:09 +00:00
|
|
|
propagateToNeighbors( subgraph, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// After processing and allowing some to be skipped if they have hierarchical
|
|
|
|
// pins connecting both up and down the hierarchy, we check to see if any of them
|
|
|
|
// have not been processed. This would indicate that they do not have off-sheet connections
|
|
|
|
// but we still need to handle the subgraph
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
|
|
|
{
|
|
|
|
if( subgraph->m_dirty )
|
|
|
|
propagateToNeighbors( subgraph, true );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
// Handle buses that have been linked together somewhere by member (net) connections.
|
|
|
|
// This feels a bit hacky, perhaps this algorithm should be revisited in the future.
|
|
|
|
|
|
|
|
// For net subgraphs that have more than one bus parent, we need to ensure that those
|
|
|
|
// buses are linked together in the final netlist. The final name of each bus might not
|
|
|
|
// match the local name that was used to establish the parent-child relationship, because
|
|
|
|
// the bus may have been renamed by a hierarchical connection. So, for each of these cases,
|
|
|
|
// we need to identify the appropriate bus members to link together (and their final names),
|
|
|
|
// and then update all instances of the old name in the hierarchy.
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
|
|
|
{
|
2021-05-10 21:54:09 +00:00
|
|
|
// All SGs should have been processed by propagateToNeighbors above
|
2023-01-17 04:14:38 +00:00
|
|
|
wxASSERT_MSG( !subgraph->m_dirty, wxS( "Subgraph not processed by propagateToNeighbors!" ) );
|
2021-05-10 21:54:09 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
if( subgraph->m_bus_parents.size() < 2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_CONNECTION* conn = subgraph->m_driver_connection;
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) has multiple bus parents" ),
|
2020-10-09 01:24:24 +00:00
|
|
|
subgraph->m_code, conn->Name() );
|
2020-01-04 15:38:43 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
wxASSERT( conn->IsNet() );
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( const auto& ii : subgraph->m_bus_parents )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
SCH_CONNECTION* link_member = ii.first.get();
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* parent : ii.second )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2019-07-27 14:51:38 +00:00
|
|
|
while( parent->m_absorbed )
|
2019-06-06 02:26:30 +00:00
|
|
|
parent = parent->m_absorbed_by;
|
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
SCH_CONNECTION* match = matchBusMember( parent->m_driver_connection, link_member );
|
|
|
|
|
|
|
|
if( !match )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Warning: could not match %s inside %lu (%s)" ),
|
2020-10-09 01:24:24 +00:00
|
|
|
conn->Name(), parent->m_code, parent->m_driver_connection->Name() );
|
2019-05-05 23:48:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( conn->Name() != match->Name() )
|
|
|
|
{
|
|
|
|
wxString old_name = match->Name();
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Updating %lu (%s) member %s to %s" ), parent->m_code,
|
2020-10-09 01:24:24 +00:00
|
|
|
parent->m_driver_connection->Name(), old_name, conn->Name() );
|
2019-05-05 23:48:43 +00:00
|
|
|
|
|
|
|
match->Clone( *conn );
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
auto jj = m_net_name_to_subgraphs_map.find( old_name );
|
|
|
|
|
|
|
|
if( jj == m_net_name_to_subgraphs_map.end() )
|
2019-05-05 23:48:43 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* old_sg : jj->second )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2019-07-27 14:51:38 +00:00
|
|
|
while( old_sg->m_absorbed )
|
2019-05-05 23:48:43 +00:00
|
|
|
old_sg = old_sg->m_absorbed_by;
|
|
|
|
|
|
|
|
old_sg->m_driver_connection->Clone( *conn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2021-01-14 15:14:09 +00:00
|
|
|
auto updateItemConnectionsTask =
|
2022-08-14 11:03:18 +00:00
|
|
|
[&]( CONNECTION_SUBGRAPH* subgraph ) -> size_t
|
2021-01-14 15:14:09 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
// Make sure weakly-driven single-pin nets get the unconnected_ prefix
|
|
|
|
if( !subgraph->m_strong_driver && subgraph->m_drivers.size() == 1 &&
|
|
|
|
subgraph->m_driver->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( subgraph->m_driver );
|
|
|
|
wxString name = pin->GetDefaultNetName( subgraph->m_sheet, true );
|
2021-01-21 19:38:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
subgraph->m_driver_connection->ConfigureFromLabel( name );
|
|
|
|
}
|
2021-01-15 01:55:39 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
subgraph->m_dirty = false;
|
|
|
|
subgraph->UpdateItemConnections();
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
// No other processing to do on buses
|
|
|
|
if( subgraph->m_driver_connection->IsBus() )
|
|
|
|
return 0;
|
2021-01-14 15:14:09 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
// As a visual aid, we can check sheet pins that are driven by themselves to see
|
|
|
|
// if they should be promoted to buses
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
if( subgraph->m_driver && subgraph->m_driver->Type() == SCH_SHEET_PIN_T )
|
2020-05-24 03:57:10 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( subgraph->m_driver );
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( SCH_SHEET* sheet = pin->GetParent() )
|
2020-05-24 03:57:10 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
wxString pinText = pin->GetText();
|
|
|
|
SCH_SCREEN* screen = sheet->GetScreen();
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
|
2020-05-24 03:57:10 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
|
2021-01-14 15:14:09 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( label->GetText() == pinText )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH path = subgraph->m_sheet;
|
|
|
|
path.push_back( sheet );
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
SCH_CONNECTION* parent_conn = label->Connection( &path );
|
2020-05-24 03:57:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( parent_conn && parent_conn->IsBus() )
|
|
|
|
subgraph->m_driver_connection->SetType( CONNECTION_TYPE::BUS );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-05-24 03:57:10 +00:00
|
|
|
}
|
2022-06-15 00:41:10 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( subgraph->m_driver_connection->IsBus() )
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-24 03:57:10 +00:00
|
|
|
}
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return 1;
|
|
|
|
};
|
2021-01-14 15:14:09 +00:00
|
|
|
|
2022-12-02 20:01:34 +00:00
|
|
|
tp.push_loop( m_driver_subgraphs.size(),
|
2022-06-15 00:41:10 +00:00
|
|
|
[&]( const int a, const int b)
|
|
|
|
{
|
|
|
|
for( int ii = a; ii < b; ++ii )
|
|
|
|
updateItemConnectionsTask( m_driver_subgraphs[ii] );
|
2022-12-02 20:01:34 +00:00
|
|
|
});
|
|
|
|
tp.wait_for_tasks();
|
2021-01-14 15:14:09 +00:00
|
|
|
|
|
|
|
m_net_code_to_subgraphs_map.clear();
|
|
|
|
m_net_name_to_subgraphs_map.clear();
|
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
|
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
NET_NAME_CODE_CACHE_KEY key = { subgraph->GetNetName(),
|
|
|
|
subgraph->m_driver_connection->NetCode() };
|
2020-01-18 17:57:02 +00:00
|
|
|
m_net_code_to_subgraphs_map[ key ].push_back( subgraph );
|
2020-05-21 03:40:31 +00:00
|
|
|
|
|
|
|
m_net_name_to_subgraphs_map[subgraph->m_driver_connection->Name()].push_back( subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
|
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = m_schematic->Prj().GetProjectFile().m_NetSettings;
|
|
|
|
std::map<wxString, wxString> oldAssignments = netSettings->m_NetClassLabelAssignments;
|
|
|
|
|
|
|
|
netSettings->m_NetClassLabelAssignments.clear();
|
|
|
|
|
|
|
|
auto dirtySubgraphs =
|
|
|
|
[&]( const std::vector<CONNECTION_SUBGRAPH*>& subgraphs )
|
|
|
|
{
|
|
|
|
if( aChangedItemHandler )
|
|
|
|
{
|
|
|
|
for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : subgraph->m_items )
|
|
|
|
(*aChangedItemHandler)( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto checkNetclassDrivers =
|
|
|
|
[&]( const std::vector<CONNECTION_SUBGRAPH*>& subgraphs )
|
|
|
|
{
|
2022-12-14 22:46:11 +00:00
|
|
|
const CONNECTION_SUBGRAPH* driverSubgraph = nullptr;
|
2022-10-02 13:59:47 +00:00
|
|
|
wxString netclass;
|
|
|
|
|
2023-04-07 00:37:09 +00:00
|
|
|
wxCHECK_RET( !subgraphs.empty(), wxT("Invalid empty subgraph" ) );
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : subgraph->m_items )
|
|
|
|
{
|
2022-10-02 13:59:47 +00:00
|
|
|
netclass = subgraph->GetNetclassForDriver( item );
|
2022-08-14 11:03:18 +00:00
|
|
|
|
|
|
|
if( !netclass.IsEmpty() )
|
2022-10-02 13:59:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-07 00:37:09 +00:00
|
|
|
if( !netclass.IsEmpty() )
|
2022-10-02 13:59:47 +00:00
|
|
|
{
|
|
|
|
driverSubgraph = subgraph;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2022-10-02 13:59:47 +00:00
|
|
|
if( netclass.IsEmpty() )
|
|
|
|
return;
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2023-04-07 00:37:09 +00:00
|
|
|
if( !driverSubgraph )
|
|
|
|
driverSubgraph = subgraphs.front();
|
|
|
|
|
2022-10-02 13:59:47 +00:00
|
|
|
const wxString netname = driverSubgraph->GetNetName();
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2022-10-02 13:59:47 +00:00
|
|
|
if( driverSubgraph->m_driver_connection->IsBus() )
|
|
|
|
{
|
|
|
|
for( const auto& member : driverSubgraph->m_driver_connection->Members() )
|
|
|
|
{
|
|
|
|
netSettings->m_NetClassLabelAssignments[ member->Name() ] = netclass;
|
|
|
|
|
|
|
|
auto ii = m_net_name_to_subgraphs_map.find( member->Name() );
|
|
|
|
|
|
|
|
if( ii != m_net_name_to_subgraphs_map.end() )
|
|
|
|
dirtySubgraphs( ii->second );
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-02 13:59:47 +00:00
|
|
|
|
|
|
|
netSettings->m_NetClassLabelAssignments[ netname ] = netclass;
|
|
|
|
|
|
|
|
if( oldAssignments[ netname ] != netclass )
|
|
|
|
dirtySubgraphs( subgraphs );
|
2022-08-14 11:03:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( const auto& [ netname, subgraphs ] : m_net_name_to_subgraphs_map )
|
|
|
|
checkNetclassDrivers( subgraphs );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
2019-04-04 01:47:26 +00:00
|
|
|
|
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
int CONNECTION_GRAPH::getOrCreateNetCode( const wxString& aNetName )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
int code;
|
2019-04-12 03:38:32 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
auto it = m_net_name_to_code_map.find( aNetName );
|
2020-11-23 17:03:39 +00:00
|
|
|
|
|
|
|
if( it == m_net_name_to_code_map.end() )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
code = m_last_net_code++;
|
2023-04-04 19:17:17 +00:00
|
|
|
m_net_name_to_code_map[ aNetName ] = code;
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
code = it->second;
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
2019-04-12 03:38:32 +00:00
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CONNECTION_GRAPH::assignNewNetCode( SCH_CONNECTION& aConnection )
|
|
|
|
{
|
|
|
|
int code = getOrCreateNetCode( aConnection.Name() );
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
aConnection.SetNetCode( code );
|
2019-04-12 03:38:32 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
return code;
|
|
|
|
}
|
2019-04-04 01:47:26 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
void CONNECTION_GRAPH::assignNetCodesToBus( SCH_CONNECTION* aConnection )
|
|
|
|
{
|
2023-04-04 10:33:07 +00:00
|
|
|
std::vector<std::shared_ptr<SCH_CONNECTION>> connections_to_check( aConnection->Members() );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < connections_to_check.size(); i++ )
|
|
|
|
{
|
2022-08-21 19:35:02 +00:00
|
|
|
const std::shared_ptr<SCH_CONNECTION>& member = connections_to_check[i];
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
if( member->IsBus() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
connections_to_check.insert( connections_to_check.end(),
|
|
|
|
member->Members().begin(),
|
|
|
|
member->Members().end() );
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
assignNewNetCode( *member );
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
|
2023-01-13 01:01:09 +00:00
|
|
|
void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, bool aForce )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
SCH_CONNECTION* conn = aSubgraph->m_driver_connection;
|
2019-05-07 01:36:01 +00:00
|
|
|
std::vector<CONNECTION_SUBGRAPH*> search_list;
|
|
|
|
std::unordered_set<CONNECTION_SUBGRAPH*> visited;
|
2020-02-05 14:23:55 +00:00
|
|
|
std::vector<SCH_CONNECTION*> stale_bus_members;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
auto visit =
|
|
|
|
[&]( CONNECTION_SUBGRAPH* aParent )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN* pin : aParent->m_hier_pins )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH path = aParent->m_sheet;
|
|
|
|
path.push_back( pin->GetParent() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
auto it = m_sheet_to_subgraphs_map.find( path );
|
2019-04-29 23:41:03 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
if( it == m_sheet_to_subgraphs_map.end() )
|
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* candidate : it->second )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
if( !candidate->m_strong_driver
|
|
|
|
|| candidate->m_hier_ports.empty()
|
|
|
|
|| visited.count( candidate ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( SCH_HIERLABEL* label : candidate->m_hier_ports )
|
|
|
|
{
|
|
|
|
if( candidate->GetNameForDriver( label ) == aParent->GetNameForDriver( pin ) )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu: found child %lu (%s)" ), aParent->m_code,
|
2020-11-23 17:03:39 +00:00
|
|
|
candidate->m_code, candidate->m_driver_connection->Name() );
|
2019-11-30 02:10:16 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
candidate->m_hier_parent = aParent;
|
2023-04-21 20:25:01 +00:00
|
|
|
aParent->m_hier_children.insert( candidate );
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
search_list.push_back( candidate );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-21 20:25:01 +00:00
|
|
|
};
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
auto propagate_bus_neighbors = [&]( CONNECTION_SUBGRAPH* aParentGraph ) {
|
|
|
|
for( const auto& kv : aParentGraph->m_bus_neighbors )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* neighbor : kv.second )
|
|
|
|
{
|
|
|
|
// May have been absorbed but won't have been deleted
|
2019-07-27 14:51:38 +00:00
|
|
|
while( neighbor->m_absorbed )
|
2019-05-05 23:48:43 +00:00
|
|
|
neighbor = neighbor->m_absorbed_by;
|
2019-03-18 22:38:06 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
SCH_CONNECTION* parent = aParentGraph->m_driver_connection;
|
2019-03-18 22:38:06 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// Now member may be out of date, since we just cloned the
|
|
|
|
// connection from higher up in the hierarchy. We need to
|
|
|
|
// figure out what the actual new connection is.
|
2019-05-05 23:48:43 +00:00
|
|
|
SCH_CONNECTION* member = matchBusMember( parent, kv.first.get() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
if( !member )
|
|
|
|
{
|
|
|
|
// Try harder: we might match on a secondary driver
|
|
|
|
for( CONNECTION_SUBGRAPH* sg : kv.second )
|
|
|
|
{
|
|
|
|
if( sg->m_multiple_drivers )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheet = sg->m_sheet;
|
|
|
|
|
|
|
|
for( SCH_ITEM* driver : sg->m_drivers )
|
|
|
|
{
|
2020-07-09 22:14:27 +00:00
|
|
|
auto c = getDefaultConnection( driver, sg );
|
2020-02-05 14:23:55 +00:00
|
|
|
member = matchBusMember( parent, c.get() );
|
|
|
|
|
|
|
|
if( member )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( member )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
// This is bad, probably an ERC error
|
|
|
|
if( !member )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Could not match bus member %s in %s" ),
|
2019-04-20 01:45:33 +00:00
|
|
|
kv.first->Name(), parent->Name() );
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
auto neighbor_conn = neighbor->m_driver_connection;
|
2019-05-05 23:48:43 +00:00
|
|
|
auto neighbor_name = neighbor_conn->Name();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
// Matching name: no update needed
|
2019-05-05 23:48:43 +00:00
|
|
|
if( neighbor_name == member->Name() )
|
2019-04-20 01:45:33 +00:00
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-12-29 21:42:30 +00:00
|
|
|
// Was this neighbor already updated from a different sheet? Don't rename it again
|
|
|
|
if( neighbor_conn->Sheet() != neighbor->m_sheet )
|
|
|
|
continue;
|
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
// Safety check against infinite recursion
|
|
|
|
wxASSERT( neighbor_conn->IsNet() );
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) connected to bus member %s (local %s)" ),
|
2020-10-09 01:24:24 +00:00
|
|
|
neighbor->m_code, neighbor_name, member->Name(), member->LocalName() );
|
2020-01-03 03:09:02 +00:00
|
|
|
|
2020-01-04 15:38:43 +00:00
|
|
|
// Take whichever name is higher priority
|
|
|
|
if( CONNECTION_SUBGRAPH::GetDriverPriority( neighbor->m_driver )
|
|
|
|
>= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN )
|
|
|
|
{
|
|
|
|
member->Clone( *neighbor_conn );
|
2020-02-05 14:23:55 +00:00
|
|
|
stale_bus_members.push_back( member );
|
2020-01-04 15:38:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
neighbor_conn->Clone( *member );
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2020-01-04 15:38:43 +00:00
|
|
|
recacheSubgraphName( neighbor, neighbor_name );
|
2019-05-08 01:31:37 +00:00
|
|
|
|
2020-01-04 15:38:43 +00:00
|
|
|
// Recurse onto this neighbor in case it needs to re-propagate
|
|
|
|
neighbor->m_dirty = true;
|
2023-01-13 01:01:09 +00:00
|
|
|
propagateToNeighbors( neighbor, aForce );
|
2020-01-04 15:38:43 +00:00
|
|
|
}
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-06-06 01:33:13 +00:00
|
|
|
// If we are a bus, we must propagate to local neighbors and then the hierarchy
|
|
|
|
if( conn->IsBus() )
|
|
|
|
propagate_bus_neighbors( aSubgraph );
|
|
|
|
|
2021-05-10 21:54:09 +00:00
|
|
|
// If we have both ports and pins, skip processing as we'll be visited by a parent or child.
|
|
|
|
// If we only have one or the other, process (we can either go bottom-up or top-down depending
|
|
|
|
// on which subgraph comes up first)
|
2023-01-20 23:20:03 +00:00
|
|
|
if( !aForce && !aSubgraph->m_hier_ports.empty() && !aSubgraph->m_hier_pins.empty() )
|
2019-04-20 01:45:33 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) has both hier ports and pins; deferring processing" ),
|
2021-05-10 21:54:09 +00:00
|
|
|
aSubgraph->m_code, conn->Name() );
|
2019-04-20 01:45:33 +00:00
|
|
|
return;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2021-05-10 21:54:09 +00:00
|
|
|
else if( aSubgraph->m_hier_ports.empty() && aSubgraph->m_hier_pins.empty() )
|
|
|
|
{
|
2023-06-02 21:24:05 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) has no hier pins or ports on sheet %s; marking clean" ),
|
|
|
|
aSubgraph->m_code, conn->Name(), aSubgraph->m_sheet.PathHumanReadable() );
|
2021-05-10 21:54:09 +00:00
|
|
|
aSubgraph->m_dirty = false;
|
2019-04-20 01:45:33 +00:00
|
|
|
return;
|
2021-05-10 21:54:09 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
visited.insert( aSubgraph );
|
2019-05-05 14:25:38 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Propagating %lu (%s) to subsheets" ),
|
2019-04-20 01:45:33 +00:00
|
|
|
aSubgraph->m_code, aSubgraph->m_driver_connection->Name() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
visit( aSubgraph );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-03-20 15:38:42 +00:00
|
|
|
for( unsigned i = 0; i < search_list.size(); i++ )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-03-20 15:38:42 +00:00
|
|
|
auto child = search_list[i];
|
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
visited.insert( child );
|
2019-05-05 14:25:38 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
visit( child );
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
child->m_dirty = false;
|
|
|
|
}
|
2019-05-05 14:25:38 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
// Now, find the best driver for this chain of subgraphs
|
2021-07-03 20:42:49 +00:00
|
|
|
CONNECTION_SUBGRAPH* bestDriver = aSubgraph;
|
2019-05-07 01:36:01 +00:00
|
|
|
CONNECTION_SUBGRAPH::PRIORITY highest =
|
|
|
|
CONNECTION_SUBGRAPH::GetDriverPriority( aSubgraph->m_driver );
|
2021-07-03 20:42:49 +00:00
|
|
|
bool bestIsStrong = ( highest >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL );
|
|
|
|
wxString bestName = aSubgraph->m_driver_connection->Name();
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
// Check if a subsheet has a higher-priority connection to the same net
|
2020-01-03 03:09:02 +00:00
|
|
|
if( highest < CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN )
|
2019-05-07 01:36:01 +00:00
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : visited )
|
|
|
|
{
|
2021-07-03 20:42:49 +00:00
|
|
|
if( subgraph == aSubgraph )
|
2021-01-19 01:23:31 +00:00
|
|
|
continue;
|
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
CONNECTION_SUBGRAPH::PRIORITY priority =
|
|
|
|
CONNECTION_SUBGRAPH::GetDriverPriority( subgraph->m_driver );
|
2019-05-05 14:25:38 +00:00
|
|
|
|
2021-01-14 15:26:53 +00:00
|
|
|
bool candidateStrong = ( priority >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL );
|
|
|
|
wxString candidateName = subgraph->m_driver_connection->Name();
|
2021-07-03 20:42:49 +00:00
|
|
|
bool shorterPath = subgraph->m_sheet.size() < bestDriver->m_sheet.size();
|
|
|
|
bool asGoodPath = subgraph->m_sheet.size() <= bestDriver->m_sheet.size();
|
2021-01-14 03:10:56 +00:00
|
|
|
|
|
|
|
// Pick a better driving subgraph if it:
|
|
|
|
// a) has a power pin or global driver
|
|
|
|
// b) is a strong driver and we're a weak driver
|
2021-02-11 22:25:02 +00:00
|
|
|
// c) is a higher priority strong driver
|
|
|
|
// d) matches our priority, is a strong driver, and has a shorter path
|
|
|
|
// e) matches our strength and is at least as short, and is alphabetically lower
|
2019-05-08 01:59:36 +00:00
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
if( ( priority >= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN ) ||
|
2021-07-03 20:42:49 +00:00
|
|
|
( !bestIsStrong && candidateStrong ) ||
|
2021-02-11 22:25:02 +00:00
|
|
|
( priority > highest && candidateStrong ) ||
|
|
|
|
( priority == highest && candidateStrong && shorterPath ) ||
|
2021-07-03 20:42:49 +00:00
|
|
|
( ( bestIsStrong == candidateStrong ) && asGoodPath && ( priority == highest ) &&
|
|
|
|
( candidateName < bestName ) ) )
|
2021-01-14 03:10:56 +00:00
|
|
|
{
|
2021-07-03 20:42:49 +00:00
|
|
|
bestDriver = subgraph;
|
|
|
|
highest = priority;
|
|
|
|
bestIsStrong = candidateStrong;
|
|
|
|
bestName = candidateName;
|
2021-01-14 03:10:56 +00:00
|
|
|
}
|
2019-05-05 04:03:58 +00:00
|
|
|
}
|
2019-05-07 01:36:01 +00:00
|
|
|
}
|
2019-05-05 04:03:58 +00:00
|
|
|
|
2021-07-03 20:42:49 +00:00
|
|
|
if( bestDriver != aSubgraph )
|
2019-05-07 01:36:01 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "%lu (%s) overridden by new driver %lu (%s)" ),
|
2021-07-03 20:42:49 +00:00
|
|
|
aSubgraph->m_code, aSubgraph->m_driver_connection->Name(), bestDriver->m_code,
|
|
|
|
bestDriver->m_driver_connection->Name() );
|
2019-05-07 01:36:01 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-07-03 20:42:49 +00:00
|
|
|
conn = bestDriver->m_driver_connection;
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : visited )
|
|
|
|
{
|
|
|
|
wxString old_name = subgraph->m_driver_connection->Name();
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2019-05-07 01:36:01 +00:00
|
|
|
subgraph->m_driver_connection->Clone( *conn );
|
2019-05-05 23:48:43 +00:00
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
if( old_name != conn->Name() )
|
|
|
|
recacheSubgraphName( subgraph, old_name );
|
2019-04-20 01:45:33 +00:00
|
|
|
|
2019-05-05 04:03:58 +00:00
|
|
|
if( conn->IsBus() )
|
2019-05-07 01:36:01 +00:00
|
|
|
propagate_bus_neighbors( subgraph );
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
2019-05-05 04:03:58 +00:00
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
// Somewhere along the way, a bus member may have been upgraded to a global or power label.
|
|
|
|
// Because this can happen anywhere, we need a second pass to update all instances of that bus
|
|
|
|
// member to have the correct connection info
|
|
|
|
if( conn->IsBus() && !stale_bus_members.empty() )
|
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
for( SCH_CONNECTION* stale_member : stale_bus_members )
|
2020-02-05 14:23:55 +00:00
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : visited )
|
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_CONNECTION* member = matchBusMember( subgraph->m_driver_connection,
|
|
|
|
stale_member );
|
2021-06-02 01:49:25 +00:00
|
|
|
|
|
|
|
if( !member )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "WARNING: failed to match stale member %s in %s." ),
|
2021-06-02 01:49:25 +00:00
|
|
|
stale_member->Name(), subgraph->m_driver_connection->Name() );
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-05 14:23:55 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "Updating %lu (%s) member %s to %s" ), subgraph->m_code,
|
2020-02-05 14:23:55 +00:00
|
|
|
subgraph->m_driver_connection->Name(), member->LocalName(),
|
|
|
|
stale_member->Name() );
|
|
|
|
|
|
|
|
member->Clone( *stale_member );
|
|
|
|
|
|
|
|
propagate_bus_neighbors( subgraph );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-05 04:03:58 +00:00
|
|
|
aSubgraph->m_dirty = false;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
std::shared_ptr<SCH_CONNECTION> CONNECTION_GRAPH::getDefaultConnection( SCH_ITEM* aItem,
|
|
|
|
CONNECTION_SUBGRAPH* aSubgraph )
|
2020-02-05 14:23:55 +00:00
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
std::shared_ptr<SCH_CONNECTION> c = std::shared_ptr<SCH_CONNECTION>( nullptr );
|
2020-02-05 14:23:55 +00:00
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aItem );
|
2020-02-05 14:23:55 +00:00
|
|
|
|
2023-01-18 15:06:46 +00:00
|
|
|
if( pin->IsGlobalPower() )
|
2020-07-09 22:14:27 +00:00
|
|
|
c = std::make_shared<SCH_CONNECTION>( aItem, aSubgraph->m_sheet );
|
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
{
|
2020-07-09 22:14:27 +00:00
|
|
|
c = std::make_shared<SCH_CONNECTION>( aItem, aSubgraph->m_sheet );
|
2020-02-05 14:23:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
if( c )
|
|
|
|
{
|
|
|
|
c->SetGraph( this );
|
|
|
|
c->ConfigureFromLabel( aSubgraph->GetNameForDriver( aItem ) );
|
|
|
|
}
|
|
|
|
|
2020-02-05 14:23:55 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_CONNECTION* CONNECTION_GRAPH::matchBusMember( SCH_CONNECTION* aBusConnection,
|
|
|
|
SCH_CONNECTION* aSearch )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aBusConnection->IsBus() );
|
|
|
|
|
|
|
|
SCH_CONNECTION* match = nullptr;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( aBusConnection->Type() == CONNECTION_TYPE::BUS )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
// Vector bus: compare against index, because we allow the name
|
|
|
|
// to be different
|
|
|
|
|
2022-02-22 13:11:17 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& bus_member : aBusConnection->Members() )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
if( bus_member->VectorIndex() == aSearch->VectorIndex() )
|
|
|
|
{
|
|
|
|
match = bus_member.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Group bus
|
2022-02-22 13:11:17 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& c : aBusConnection->Members() )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
// Vector inside group: compare names, because for bus groups
|
|
|
|
// we expect the naming to be consistent across all usages
|
|
|
|
// TODO(JE) explain this in the docs
|
2020-01-18 20:51:28 +00:00
|
|
|
if( c->Type() == CONNECTION_TYPE::BUS )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& bus_member : c->Members() )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2020-02-05 14:23:55 +00:00
|
|
|
if( bus_member->LocalName() == aSearch->LocalName() )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
match = bus_member.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-05 14:23:55 +00:00
|
|
|
else if( c->LocalName() == aSearch->LocalName() )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
|
|
|
match = c.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-09 22:14:27 +00:00
|
|
|
void CONNECTION_GRAPH::recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph,
|
|
|
|
const wxString& aOldName )
|
2019-05-05 23:48:43 +00:00
|
|
|
{
|
2022-11-22 12:49:49 +00:00
|
|
|
auto it = m_net_name_to_subgraphs_map.find( aOldName );
|
|
|
|
|
|
|
|
if( it != m_net_name_to_subgraphs_map.end() )
|
|
|
|
{
|
|
|
|
std::vector<CONNECTION_SUBGRAPH*>& vec = it->second;
|
|
|
|
alg::delete_matching( vec, aSubgraph );
|
|
|
|
}
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "recacheSubgraphName: %s => %s" ), aOldName,
|
2022-11-22 12:49:49 +00:00
|
|
|
aSubgraph->m_driver_connection->Name() );
|
2020-02-05 14:23:55 +00:00
|
|
|
|
2019-05-05 23:48:43 +00:00
|
|
|
m_net_name_to_subgraphs_map[aSubgraph->m_driver_connection->Name()].push_back( aSubgraph );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<BUS_ALIAS> CONNECTION_GRAPH::GetBusAlias( const wxString& aName )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
auto it = m_bus_alias_cache.find( aName );
|
2019-04-03 09:14:36 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
return it != m_bus_alias_cache.end() ? it->second : nullptr;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
std::vector<const CONNECTION_SUBGRAPH*> CONNECTION_GRAPH::GetBusesNeedingMigration()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-20 01:45:33 +00:00
|
|
|
std::vector<const CONNECTION_SUBGRAPH*> ret;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-02-22 13:11:17 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_subgraphs )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
// Graph is supposed to be up-to-date before calling this
|
|
|
|
wxASSERT( !subgraph->m_dirty );
|
|
|
|
|
|
|
|
if( !subgraph->m_driver )
|
|
|
|
continue;
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
SCH_CONNECTION* connection = subgraph->m_driver->Connection( &subgraph->m_sheet );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( !connection->IsBus() )
|
|
|
|
continue;
|
|
|
|
|
2023-04-04 19:17:17 +00:00
|
|
|
auto labels = subgraph->GetVectorBusLabels();
|
2019-04-20 02:03:18 +00:00
|
|
|
|
|
|
|
if( labels.size() > 1 )
|
2019-03-23 19:43:33 +00:00
|
|
|
{
|
2019-04-20 02:03:18 +00:00
|
|
|
bool different = false;
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString first = static_cast<SCH_TEXT*>( labels.at( 0 ) )->GetShownText( false );
|
2019-04-20 02:03:18 +00:00
|
|
|
|
|
|
|
for( unsigned i = 1; i < labels.size(); ++i )
|
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
if( static_cast<SCH_TEXT*>( labels.at( i ) )->GetShownText( false ) != first )
|
2019-04-20 02:03:18 +00:00
|
|
|
{
|
|
|
|
different = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !different )
|
|
|
|
continue;
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( ConnTrace, wxS( "SG %ld (%s) has multiple bus labels" ), subgraph->m_code,
|
2019-03-23 19:43:33 +00:00
|
|
|
connection->Name() );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
ret.push_back( subgraph );
|
2019-03-23 19:43:33 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-06 22:08:36 +00:00
|
|
|
wxString CONNECTION_GRAPH::GetResolvedSubgraphName( const CONNECTION_SUBGRAPH* aSubGraph ) const
|
|
|
|
{
|
|
|
|
wxString retval = aSubGraph->GetNetName();
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
// This is a hacky way to find the true subgraph net name (why do we not store it?)
|
|
|
|
// TODO: Remove once the actual netname of the subgraph is stored with the subgraph
|
|
|
|
|
|
|
|
for( auto it = m_net_name_to_subgraphs_map.begin(); it != m_net_name_to_subgraphs_map.end() && !found; ++it )
|
|
|
|
{
|
|
|
|
for( CONNECTION_SUBGRAPH* graph : it->second )
|
|
|
|
{
|
|
|
|
if( graph == aSubGraph )
|
|
|
|
{
|
|
|
|
retval = it->first;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-25 22:16:06 +00:00
|
|
|
CONNECTION_SUBGRAPH* CONNECTION_GRAPH::FindSubgraphByName( const wxString& aNetName,
|
|
|
|
const SCH_SHEET_PATH& aPath )
|
2020-05-21 03:40:31 +00:00
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
auto it = m_net_name_to_subgraphs_map.find( aNetName );
|
|
|
|
|
|
|
|
if( it == m_net_name_to_subgraphs_map.end() )
|
2020-05-21 03:40:31 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* sg : it->second )
|
2020-05-21 03:40:31 +00:00
|
|
|
{
|
|
|
|
// Cache is supposed to be valid by now
|
|
|
|
wxASSERT( sg && !sg->m_absorbed && sg->m_driver_connection );
|
|
|
|
|
|
|
|
if( sg->m_sheet == aPath && sg->m_driver_connection->Name() == aNetName )
|
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
CONNECTION_SUBGRAPH* CONNECTION_GRAPH::FindFirstSubgraphByName( const wxString& aNetName )
|
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
auto it = m_net_name_to_subgraphs_map.find( aNetName );
|
|
|
|
|
|
|
|
if( it == m_net_name_to_subgraphs_map.end() )
|
2020-05-24 14:46:05 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
wxASSERT( !it->second.empty() );
|
2020-05-24 14:46:05 +00:00
|
|
|
|
2020-11-23 17:03:39 +00:00
|
|
|
return it->second[0];
|
2020-05-24 14:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CONNECTION_SUBGRAPH* CONNECTION_GRAPH::GetSubgraphForItem( SCH_ITEM* aItem )
|
|
|
|
{
|
2020-11-23 17:03:39 +00:00
|
|
|
auto it = m_item_to_subgraph_map.find( aItem );
|
|
|
|
CONNECTION_SUBGRAPH* ret = it != m_item_to_subgraph_map.end() ? it->second : nullptr;
|
2020-05-24 14:46:05 +00:00
|
|
|
|
2020-11-24 14:13:03 +00:00
|
|
|
while( ret && ret->m_absorbed )
|
2020-05-24 14:46:05 +00:00
|
|
|
ret = ret->m_absorbed_by;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-20 17:47:12 +00:00
|
|
|
const std::vector<CONNECTION_SUBGRAPH*> CONNECTION_GRAPH::GetAllSubgraphs(
|
|
|
|
const wxString& aNetName ) const
|
|
|
|
{
|
|
|
|
std::vector<CONNECTION_SUBGRAPH*> subgraphs;
|
|
|
|
|
|
|
|
auto it = m_net_name_to_subgraphs_map.find( aNetName );
|
|
|
|
|
|
|
|
if( it == m_net_name_to_subgraphs_map.end() )
|
|
|
|
return subgraphs;
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
int CONNECTION_GRAPH::RunERC()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
int error_count = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_MSG( m_schematic, true, wxS( "Null m_schematic in CONNECTION_GRAPH::RunERC" ) );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
// We don't want to run many ERC checks more than once on a given screen even though it may
|
|
|
|
// represent multiple sheets with multiple subgraphs. We can tell these apart by drivers.
|
|
|
|
std::set<SCH_ITEM*> seenDriverInstances;
|
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : m_subgraphs )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2021-11-13 16:38:19 +00:00
|
|
|
// There shouldn't be any null sub-graph pointers.
|
|
|
|
wxCHECK2( subgraph, continue );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// Graph is supposed to be up-to-date before calling RunERC()
|
|
|
|
wxASSERT( !subgraph->m_dirty );
|
|
|
|
|
2020-12-27 20:31:48 +00:00
|
|
|
if( subgraph->m_absorbed )
|
|
|
|
continue;
|
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
if( seenDriverInstances.count( subgraph->m_driver ) )
|
|
|
|
continue;
|
|
|
|
|
2021-01-17 16:18:37 +00:00
|
|
|
if( subgraph->m_driver )
|
|
|
|
seenDriverInstances.insert( subgraph->m_driver );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
/**
|
|
|
|
* NOTE:
|
|
|
|
*
|
|
|
|
* We could check that labels attached to bus subgraphs follow the
|
|
|
|
* proper format (i.e. actually define a bus).
|
|
|
|
*
|
|
|
|
* This check doesn't need to be here right now because labels
|
|
|
|
* won't actually be connected to bus wires if they aren't in the right
|
|
|
|
* format due to their TestDanglingEnds() implementation.
|
|
|
|
*/
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_DRIVER_CONFLICT ) )
|
|
|
|
{
|
2021-01-13 04:03:31 +00:00
|
|
|
if( !ercCheckMultipleDrivers( subgraph ) )
|
2020-11-01 17:37:52 +00:00
|
|
|
error_count++;
|
|
|
|
}
|
2021-01-13 04:03:31 +00:00
|
|
|
|
|
|
|
subgraph->ResolveDrivers( false );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_BUS_TO_NET_CONFLICT ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckBusToNetConflicts( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_BUS_ENTRY_CONFLICT ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckBusToBusEntryConflicts( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_BUS_TO_BUS_CONFLICT ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckBusToBusConflicts( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_WIRE_DANGLING ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckFloatingWires( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2020-08-25 22:00:07 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED )
|
|
|
|
|| settings.IsTestEnabled( ERCE_NOCONNECT_NOT_CONNECTED )
|
|
|
|
|| settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckNoConnects( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-11-01 17:37:52 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_LABEL_NOT_CONNECTED )
|
|
|
|
|| settings.IsTestEnabled( ERCE_GLOBLABEL ) )
|
|
|
|
{
|
|
|
|
if( !ercCheckLabels( subgraph ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 01:52:52 +00:00
|
|
|
// Hierarchical sheet checking is done at the schematic level
|
2021-11-04 16:23:25 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_HIERACHICAL_LABEL )
|
|
|
|
|| settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
|
|
|
|
{
|
2020-08-26 01:52:52 +00:00
|
|
|
error_count += ercCheckHierSheets();
|
2021-11-04 16:23:25 +00:00
|
|
|
}
|
2020-08-26 01:52:52 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_NETCLASS_CONFLICT ) )
|
|
|
|
{
|
|
|
|
for( const auto& [ netname, subgraphs ] : m_net_name_to_subgraphs_map )
|
|
|
|
{
|
|
|
|
if( !ercCheckNetclassConflicts( subgraphs ) )
|
|
|
|
error_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
return error_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 04:03:31 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubgraph )
|
|
|
|
{
|
2021-11-13 16:38:19 +00:00
|
|
|
wxCHECK( aSubgraph, false );
|
2021-10-18 15:34:26 +00:00
|
|
|
/*
|
|
|
|
* This was changed late in 6.0 to fix https://gitlab.com/kicad/code/kicad/-/issues/9367
|
|
|
|
* so I'm going to leave the original code in for just a little while. If anyone comes
|
|
|
|
* across this in 7.0 development (or later), feel free to delete.
|
|
|
|
*/
|
|
|
|
#if 0
|
2021-11-13 16:38:19 +00:00
|
|
|
if( aSubgraph->m_second_driver )
|
2021-10-18 15:34:26 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* primary = aSubgraph->m_first_driver;
|
|
|
|
SCH_ITEM* secondary = aSubgraph->m_second_driver;
|
|
|
|
|
|
|
|
wxPoint pos = primary->Type() == SCH_PIN_T ?
|
|
|
|
static_cast<SCH_PIN*>( primary )->GetTransformedPosition() :
|
|
|
|
primary->GetPosition();
|
|
|
|
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& primaryName = aSubgraph->GetNameForDriver( primary );
|
|
|
|
const wxString& secondaryName = aSubgraph->GetNameForDriver( secondary );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
wxString msg = wxString::Format( _( "Both %s and %s are attached to the same "
|
|
|
|
"items; %s will be used in the netlist" ),
|
|
|
|
primaryName, secondaryName, primaryName );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DRIVER_CONFLICT );
|
|
|
|
ercItem->SetItems( primary, secondary );
|
|
|
|
ercItem->SetErrorMessage( msg );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
|
|
|
|
aSubgraph->m_sheet.LastScreen()->Append( marker );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2021-11-13 16:38:19 +00:00
|
|
|
if( aSubgraph->m_multiple_drivers )
|
2021-10-18 15:34:26 +00:00
|
|
|
{
|
|
|
|
for( SCH_ITEM* driver : aSubgraph->m_drivers )
|
|
|
|
{
|
|
|
|
if( driver == aSubgraph->m_driver )
|
|
|
|
continue;
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
if( driver->Type() == SCH_GLOBAL_LABEL_T
|
|
|
|
|| driver->Type() == SCH_HIER_LABEL_T
|
2022-10-28 02:36:40 +00:00
|
|
|
|| driver->Type() == SCH_LABEL_T
|
|
|
|
|| ( driver->Type() == SCH_PIN_T
|
2023-01-18 15:06:46 +00:00
|
|
|
&& static_cast<SCH_PIN*>( driver )->IsGlobalPower() ) )
|
2021-10-18 15:34:26 +00:00
|
|
|
{
|
2023-01-24 01:20:05 +00:00
|
|
|
const wxString& primaryName = aSubgraph->GetNameForDriver( aSubgraph->m_driver );
|
|
|
|
const wxString& secondaryName = aSubgraph->GetNameForDriver( driver );
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
if( primaryName == secondaryName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString msg = wxString::Format( _( "Both %s and %s are attached to the same "
|
|
|
|
"items; %s will be used in the netlist" ),
|
|
|
|
primaryName, secondaryName, primaryName );
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DRIVER_CONFLICT );
|
|
|
|
ercItem->SetItems( aSubgraph->m_driver, driver );
|
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, driver->GetPosition() );
|
|
|
|
aSubgraph->m_sheet.LastScreen()->Append( marker );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-01-13 04:03:31 +00:00
|
|
|
|
2021-10-18 15:34:26 +00:00
|
|
|
return true;
|
2021-01-13 04:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckNetclassConflicts( const std::vector<CONNECTION_SUBGRAPH*>& subgraphs )
|
|
|
|
{
|
|
|
|
wxString firstNetclass;
|
|
|
|
SCH_ITEM* firstNetclassDriver = nullptr;
|
|
|
|
|
|
|
|
for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : subgraph->m_items )
|
|
|
|
{
|
|
|
|
const wxString netclass = subgraph->GetNetclassForDriver( item );
|
|
|
|
|
|
|
|
if( netclass.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( netclass != firstNetclass )
|
|
|
|
{
|
|
|
|
if( !firstNetclassDriver )
|
|
|
|
{
|
|
|
|
firstNetclass = netclass;
|
|
|
|
firstNetclassDriver = item;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NETCLASS_CONFLICT );
|
|
|
|
ercItem->SetItems( firstNetclassDriver, item );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
|
|
|
|
subgraph->m_sheet.LastScreen()->Append( marker );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSubgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = aSubgraph->m_sheet;
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
SCH_ITEM* net_item = nullptr;
|
|
|
|
SCH_ITEM* bus_item = nullptr;
|
2020-05-19 02:58:28 +00:00
|
|
|
SCH_CONNECTION conn( this );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-02-15 02:35:29 +00:00
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
if( item->GetLayer() == LAYER_BUS )
|
|
|
|
bus_item = ( !bus_item ) ? item : bus_item;
|
|
|
|
else
|
|
|
|
net_item = ( !net_item ) ? item : net_item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-15 02:35:29 +00:00
|
|
|
case SCH_LABEL_T:
|
2019-03-11 21:32:05 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
SCH_TEXT* text = static_cast<SCH_TEXT*>( item );
|
2023-05-05 13:21:56 +00:00
|
|
|
conn.ConfigureFromLabel( EscapeString( text->GetShownText( false ), CTX_NETNAME ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
if( conn.IsBus() )
|
|
|
|
bus_item = ( !bus_item ) ? item : bus_item;
|
|
|
|
else
|
|
|
|
net_item = ( !net_item ) ? item : net_item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( net_item && bus_item )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_TO_NET_CONFLICT );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( net_item, bus_item );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, net_item->GetPosition() );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckBusToBusConflicts( const CONNECTION_SUBGRAPH* aSubgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2022-02-22 13:11:17 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = aSubgraph->m_sheet;
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
SCH_ITEM* label = nullptr;
|
|
|
|
SCH_ITEM* port = nullptr;
|
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
if( !label && item->Connection( &sheet )->IsBus() )
|
2019-03-11 21:32:05 +00:00
|
|
|
label = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHEET_PIN_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
if( !port && item->Connection( &sheet )->IsBus() )
|
2019-03-11 21:32:05 +00:00
|
|
|
port = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( label && port )
|
|
|
|
{
|
|
|
|
bool match = false;
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
for( const auto& member : label->Connection( &sheet )->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
for( const auto& test : port->Connection( &sheet )->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
if( test != member && member->Name() == test->Name() )
|
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( match )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !match )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_TO_BUS_CONFLICT );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( label, port );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts( const CONNECTION_SUBGRAPH* aSubgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
bool conflict = false;
|
2022-02-22 13:11:17 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = aSubgraph->m_sheet;
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
SCH_BUS_WIRE_ENTRY* bus_entry = nullptr;
|
|
|
|
SCH_ITEM* bus_wire = nullptr;
|
2020-10-28 01:53:21 +00:00
|
|
|
wxString bus_name;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-01-17 16:05:09 +00:00
|
|
|
if( !aSubgraph->m_driver_connection )
|
|
|
|
{
|
|
|
|
// Incomplete bus entry. Let the unconnected tests handle it.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-22 13:11:17 +00:00
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
{
|
|
|
|
if( !bus_entry )
|
|
|
|
bus_entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bus_entry && bus_entry->m_connected_bus_item )
|
|
|
|
{
|
|
|
|
bus_wire = bus_entry->m_connected_bus_item;
|
|
|
|
|
2019-12-23 13:55:47 +00:00
|
|
|
wxASSERT( bus_wire->Type() == SCH_LINE_T );
|
|
|
|
|
2019-12-22 15:19:05 +00:00
|
|
|
// In some cases, the connection list (SCH_CONNECTION*) can be null.
|
|
|
|
// Skip null connections.
|
2020-12-20 15:08:43 +00:00
|
|
|
if( bus_entry->Connection( &sheet )
|
|
|
|
&& bus_wire->Type() == SCH_LINE_T
|
|
|
|
&& bus_wire->Connection( &sheet ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-12-20 15:08:43 +00:00
|
|
|
conflict = true; // Assume a conflict; we'll reset if we find it's OK
|
|
|
|
|
2021-02-13 15:09:16 +00:00
|
|
|
bus_name = bus_wire->Connection( &sheet )->Name();
|
2019-12-22 15:19:05 +00:00
|
|
|
|
2022-10-30 23:17:04 +00:00
|
|
|
std::set<wxString> test_names;
|
2022-11-02 21:37:34 +00:00
|
|
|
test_names.insert( bus_entry->Connection( &sheet )->Name() );
|
|
|
|
|
2022-10-30 23:17:04 +00:00
|
|
|
wxString baseName = sheet.PathHumanReadable();
|
|
|
|
|
|
|
|
for( SCH_ITEM* driver : aSubgraph->m_drivers )
|
|
|
|
test_names.insert( baseName + aSubgraph->GetNameForDriver( driver ) );
|
2019-12-22 15:19:05 +00:00
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
for( const auto& member : bus_wire->Connection( &sheet )->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( member->Type() == CONNECTION_TYPE::BUS )
|
2019-12-22 15:19:05 +00:00
|
|
|
{
|
|
|
|
for( const auto& sub_member : member->Members() )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2022-10-30 23:17:04 +00:00
|
|
|
if( test_names.count( sub_member->Name() ) )
|
2019-12-22 15:19:05 +00:00
|
|
|
conflict = false;
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
2019-12-22 15:19:05 +00:00
|
|
|
}
|
2022-10-30 23:17:04 +00:00
|
|
|
else if( test_names.count( member->Name() ) )
|
2019-12-22 15:19:05 +00:00
|
|
|
{
|
|
|
|
conflict = false;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-03 03:09:02 +00:00
|
|
|
// Don't report warnings if this bus member has been overridden by a higher priority power pin
|
|
|
|
// or global label
|
2020-03-16 11:05:01 +00:00
|
|
|
if( conflict && CONNECTION_SUBGRAPH::GetDriverPriority( aSubgraph->m_driver )
|
2020-01-03 03:09:02 +00:00
|
|
|
>= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN )
|
2022-02-22 13:11:17 +00:00
|
|
|
{
|
2020-01-03 03:09:02 +00:00
|
|
|
conflict = false;
|
2022-02-22 13:11:17 +00:00
|
|
|
}
|
2020-01-03 03:09:02 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( conflict )
|
|
|
|
{
|
2021-02-13 15:09:16 +00:00
|
|
|
wxString netName = aSubgraph->m_driver_connection->Name();
|
2020-10-28 01:53:21 +00:00
|
|
|
wxString msg = wxString::Format( _( "Net %s is graphically connected to bus %s but is not a"
|
|
|
|
" member of that bus" ),
|
2020-12-20 15:08:43 +00:00
|
|
|
UnescapeString( netName ),
|
|
|
|
UnescapeString( bus_name ) );
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_CONFLICT );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( bus_entry, bus_wire );
|
2020-10-28 01:53:21 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, bus_entry->GetPosition() );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(JE) Check sheet pins here too?
|
2020-03-10 18:46:57 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-11-01 17:37:52 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
2020-08-25 22:00:07 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = aSubgraph->m_sheet;
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
bool ok = true;
|
2022-12-09 02:09:48 +00:00
|
|
|
SCH_PIN* pin = nullptr;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
std::set<SCH_PIN*> unique_pins;
|
|
|
|
std::set<SCH_LABEL_BASE*> unique_labels;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
wxString netName = GetResolvedSubgraphName( aSubgraph );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
auto process_subgraph = [&]( const CONNECTION_SUBGRAPH* aProcessGraph )
|
|
|
|
{
|
|
|
|
// Any subgraph that contains a no-connect should not
|
|
|
|
// more than one pin (which would indicate it is connected
|
2020-10-22 02:14:04 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
for( SCH_ITEM* item : aProcessGraph->m_items )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
2022-12-06 22:08:36 +00:00
|
|
|
{
|
2022-12-09 02:09:48 +00:00
|
|
|
case SCH_PIN_T:
|
|
|
|
{
|
|
|
|
SCH_PIN* test_pin = static_cast<SCH_PIN*>( item );
|
2022-09-10 00:17:42 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
// Only link NC to pin on the current subgraph being checked
|
|
|
|
if( aProcessGraph == aSubgraph )
|
|
|
|
pin = test_pin;
|
2022-12-06 22:08:36 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
if( std::none_of( unique_pins.begin(), unique_pins.end(),
|
|
|
|
[test_pin]( SCH_PIN* aPin )
|
|
|
|
{
|
|
|
|
return test_pin->IsStacked( aPin );
|
|
|
|
}
|
|
|
|
))
|
|
|
|
{
|
|
|
|
unique_pins.insert( test_pin );
|
2020-10-22 02:14:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
break;
|
2020-10-22 02:14:04 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
unique_labels.insert( static_cast<SCH_LABEL_BASE*>( item ) );
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
default:
|
|
|
|
break;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-09 02:09:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto it = m_net_name_to_subgraphs_map.find( netName );
|
|
|
|
|
|
|
|
if( it != m_net_name_to_subgraphs_map.end() )
|
|
|
|
{
|
|
|
|
for( const CONNECTION_SUBGRAPH* subgraph : it->second )
|
2022-12-06 22:08:36 +00:00
|
|
|
{
|
2022-12-09 02:09:48 +00:00
|
|
|
process_subgraph( subgraph );
|
2022-12-06 22:08:36 +00:00
|
|
|
}
|
2022-12-09 02:09:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
process_subgraph( aSubgraph );
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
if( aSubgraph->m_no_connect != nullptr )
|
|
|
|
{
|
|
|
|
if( unique_pins.size() > 1 && settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
|
2022-12-24 01:50:49 +00:00
|
|
|
VECTOR2I pos;
|
2022-12-13 03:29:15 +00:00
|
|
|
|
|
|
|
if( pin )
|
2022-12-24 01:50:49 +00:00
|
|
|
{
|
2022-12-13 03:29:15 +00:00
|
|
|
ercItem->SetItems( pin, aSubgraph->m_no_connect );
|
2022-12-24 01:50:49 +00:00
|
|
|
pos = pin->GetTransformedPosition();
|
|
|
|
}
|
2022-12-13 03:29:15 +00:00
|
|
|
else
|
2022-12-24 01:50:49 +00:00
|
|
|
{
|
2022-12-13 03:29:15 +00:00
|
|
|
ercItem->SetItems( aSubgraph->m_no_connect );
|
2022-12-24 01:50:49 +00:00
|
|
|
pos = aSubgraph->m_no_connect->GetPosition();
|
|
|
|
}
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2022-12-24 01:50:49 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
ok = false;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2019-04-12 01:22:19 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
if( unique_pins.empty() && unique_labels.empty() && settings.IsTestEnabled( ERCE_NOCONNECT_NOT_CONNECTED ) )
|
2019-04-12 01:22:19 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_NOT_CONNECTED );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( aSubgraph->m_no_connect );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, aSubgraph->m_no_connect->GetPosition() );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-04-12 01:22:19 +00:00
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
ok = false;
|
2019-04-12 01:22:19 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool has_other_connections = false;
|
2020-08-25 22:00:07 +00:00
|
|
|
std::vector<SCH_PIN*> pins;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
// Any subgraph that lacks a no-connect and contains a pin should also
|
2020-08-25 22:00:07 +00:00
|
|
|
// contain at least one other potential driver
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2019-04-03 09:14:36 +00:00
|
|
|
case SCH_PIN_T:
|
2020-08-25 22:00:07 +00:00
|
|
|
{
|
2022-07-18 03:15:22 +00:00
|
|
|
// Stacked pins do not count as other connections but non-stacked pins do
|
|
|
|
if( !has_other_connections && !pins.empty() )
|
|
|
|
{
|
2022-12-09 02:09:48 +00:00
|
|
|
SCH_PIN* test_pin = static_cast<SCH_PIN*>( item );
|
2022-07-18 03:15:22 +00:00
|
|
|
|
|
|
|
for( SCH_PIN* other_pin : pins )
|
|
|
|
{
|
2022-12-09 02:09:48 +00:00
|
|
|
if( !test_pin->IsStacked( other_pin ) )
|
2022-07-18 03:15:22 +00:00
|
|
|
{
|
|
|
|
has_other_connections = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 18:23:59 +00:00
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
pins.emplace_back( static_cast<SCH_PIN*>( item ) );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
2020-08-25 22:00:07 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
default:
|
2020-08-25 22:00:07 +00:00
|
|
|
if( aSubgraph->GetDriverPriority( item ) != CONNECTION_SUBGRAPH::PRIORITY::NONE )
|
2019-03-11 21:32:05 +00:00
|
|
|
has_other_connections = true;
|
2019-08-07 18:23:59 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
// For many checks, we can just use the first pin
|
2022-12-09 02:09:48 +00:00
|
|
|
pin = pins.empty() ? nullptr : pins[0];
|
2020-08-25 22:00:07 +00:00
|
|
|
|
2022-12-06 22:08:36 +00:00
|
|
|
// But if there is a power pin, it might be connected elsewhere
|
|
|
|
for( SCH_PIN* test_pin : pins )
|
|
|
|
{
|
|
|
|
if( test_pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
|
|
|
|
{
|
|
|
|
pin = test_pin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 14:58:47 +00:00
|
|
|
// Check if power input pins connect to anything else via net name,
|
|
|
|
// but not for power symbols (with visible or legacy invisible pins).
|
|
|
|
// We want to throw unconnected errors for power symbols even if they are connected to other
|
2020-08-25 22:00:07 +00:00
|
|
|
// net items by name, because usually failing to connect them graphically is a mistake
|
|
|
|
if( pin && !has_other_connections
|
2023-01-18 15:06:46 +00:00
|
|
|
&& pin->IsGlobalPower()
|
2020-08-25 22:00:07 +00:00
|
|
|
&& !pin->GetLibPin()->GetParent()->IsPower() )
|
2019-04-08 01:33:47 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
wxString name = pin->Connection( &sheet )->Name();
|
|
|
|
wxString local_name = pin->Connection( &sheet )->Name( true );
|
2019-04-08 01:33:47 +00:00
|
|
|
|
2022-02-22 13:11:17 +00:00
|
|
|
if( m_global_label_cache.count( name )
|
|
|
|
|| m_local_label_cache.count( std::make_pair( sheet, local_name ) ) )
|
2019-04-08 01:33:47 +00:00
|
|
|
{
|
2019-04-12 01:22:19 +00:00
|
|
|
has_other_connections = true;
|
2019-04-08 01:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
// Only one pin, and it's not a no-connect pin
|
2020-11-01 17:37:52 +00:00
|
|
|
if( pin && !has_other_connections
|
|
|
|
&& pin->GetType() != ELECTRICAL_PINTYPE::PT_NC
|
2021-01-22 13:04:43 +00:00
|
|
|
&& pin->GetType() != ELECTRICAL_PINTYPE::PT_NIC
|
2020-11-01 17:37:52 +00:00
|
|
|
&& settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_CONNECTED );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( pin );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetTransformedPosition() );
|
2020-03-10 18:46:57 +00:00
|
|
|
screen->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are multiple pins in this SG, they might be indirectly connected (by netname)
|
|
|
|
// rather than directly connected (by wires). We want to flag dangling pins even if they
|
|
|
|
// join nets with another pin, as it's often a mistake
|
|
|
|
if( pins.size() > 1 )
|
|
|
|
{
|
|
|
|
for( SCH_PIN* testPin : pins )
|
|
|
|
{
|
2023-01-18 14:58:47 +00:00
|
|
|
// We only apply this test to power symbols, because other symbols have
|
|
|
|
// pins that are meant to be dangling, but the power symbols have pins
|
|
|
|
// that are *not* meant to be dangling.
|
2020-11-01 17:37:52 +00:00
|
|
|
if( testPin->GetLibPin()->GetParent()->IsPower()
|
2023-01-18 15:06:46 +00:00
|
|
|
&& testPin->ConnectedItems( sheet ).empty()
|
|
|
|
&& settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
|
2020-08-25 22:00:07 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_CONNECTED );
|
|
|
|
ercItem->SetItems( testPin );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem,
|
|
|
|
testPin->GetTransformedPosition() );
|
|
|
|
screen->Append( marker );
|
|
|
|
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 22:00:07 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CONNECTION_GRAPH::ercCheckFloatingWires( const CONNECTION_SUBGRAPH* aSubgraph )
|
|
|
|
{
|
2020-08-26 01:54:14 +00:00
|
|
|
if( aSubgraph->m_driver )
|
2020-08-25 22:00:07 +00:00
|
|
|
return true;
|
|
|
|
|
2021-01-17 16:05:09 +00:00
|
|
|
std::vector<SCH_ITEM*> wires;
|
2020-08-25 22:00:07 +00:00
|
|
|
|
|
|
|
// We've gotten this far, so we know we have no valid driver. All we need to do is check
|
|
|
|
// for a wire that we can place the error on.
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T && item->GetLayer() == LAYER_WIRE )
|
2021-01-17 16:05:09 +00:00
|
|
|
wires.emplace_back( item );
|
|
|
|
else if( item->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
wires.emplace_back( item );
|
2020-08-25 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !wires.empty() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = aSubgraph->m_sheet.LastScreen();
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_WIRE_DANGLING );
|
|
|
|
ercItem->SetItems( wires[0],
|
|
|
|
wires.size() > 1 ? wires[1] : nullptr,
|
|
|
|
wires.size() > 2 ? wires[2] : nullptr,
|
|
|
|
wires.size() > 3 ? wires[3] : nullptr );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wires[0]->GetPosition() );
|
|
|
|
screen->Append( marker );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool CONNECTION_GRAPH::ercCheckLabels( const CONNECTION_SUBGRAPH* aSubgraph )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-04-25 19:10:19 +00:00
|
|
|
// Label connection rules:
|
2022-09-12 20:15:53 +00:00
|
|
|
// Any label without a no-connect needs to have at least 2 pins, otherwise it is invalid
|
2019-04-25 19:10:19 +00:00
|
|
|
// Local labels are flagged if they don't connect to any pins and don't have a no-connect
|
|
|
|
// Global labels are flagged if they appear only once, don't connect to any local labels,
|
|
|
|
// and don't have a no-connect marker
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-01-17 16:05:09 +00:00
|
|
|
if( !aSubgraph->m_driver_connection )
|
|
|
|
return true;
|
|
|
|
|
2021-01-14 00:37:05 +00:00
|
|
|
// Buses are excluded from this test: many users create buses with only a single instance
|
|
|
|
// and it's not really a problem as long as the nets in the bus pass ERC
|
|
|
|
if( aSubgraph->m_driver_connection->IsBus() )
|
|
|
|
return true;
|
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
bool ok = true;
|
|
|
|
int pinCount = 0;
|
|
|
|
bool has_nc = !!aSubgraph->m_no_connect;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
std::map<KICAD_T, std::vector<SCH_TEXT*>> label_map;
|
|
|
|
|
|
|
|
|
2021-11-28 03:34:11 +00:00
|
|
|
auto hasPins =
|
2022-09-12 20:15:53 +00:00
|
|
|
[]( const CONNECTION_SUBGRAPH* aLocSubgraph ) -> int
|
2021-11-28 03:34:11 +00:00
|
|
|
{
|
2022-12-09 02:09:48 +00:00
|
|
|
return
|
|
|
|
std::count_if( aLocSubgraph->m_items.begin(), aLocSubgraph->m_items.end(), []( const SCH_ITEM* item )
|
|
|
|
{ return item->Type() == SCH_PIN_T; } );
|
2021-11-28 03:34:11 +00:00
|
|
|
};
|
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
auto reportError = [&]( SCH_TEXT* aText, int errCode )
|
|
|
|
{
|
|
|
|
if( settings.IsTestEnabled( errCode ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( errCode );
|
|
|
|
ercItem->SetItems( aText );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, aText->GetPosition() );
|
|
|
|
aSubgraph->m_sheet.LastScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pinCount = hasPins( aSubgraph );
|
|
|
|
|
2022-02-22 13:11:17 +00:00
|
|
|
for( SCH_ITEM* item : aSubgraph->m_items )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2020-10-04 21:13:42 +00:00
|
|
|
{
|
2022-09-12 20:15:53 +00:00
|
|
|
SCH_TEXT* text = static_cast<SCH_TEXT*>( item );
|
|
|
|
|
|
|
|
label_map[item->Type()].push_back( text );
|
2020-10-04 21:13:42 +00:00
|
|
|
|
|
|
|
// Below, we'll create an ERC if the whole subgraph is unconnected. But, additionally,
|
|
|
|
// we want to error if an individual label in the subgraph is floating, even if it's
|
|
|
|
// connected to other valid things by way of another label on the same sheet.
|
2022-09-12 20:15:53 +00:00
|
|
|
if( text->IsDangling() )
|
2020-10-04 21:13:42 +00:00
|
|
|
{
|
2022-09-12 20:15:53 +00:00
|
|
|
reportError( text, ERCE_LABEL_NOT_CONNECTED );
|
|
|
|
return false;
|
2020-10-04 21:13:42 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
break;
|
2020-10-04 21:13:42 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
if( label_map.empty() )
|
2019-05-02 00:15:08 +00:00
|
|
|
return true;
|
|
|
|
|
2022-12-06 22:08:36 +00:00
|
|
|
wxString netName = GetResolvedSubgraphName( aSubgraph );
|
2022-11-21 23:16:44 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_MSG( m_schematic, true, wxS( "Null m_schematic in CONNECTION_GRAPH::ercCheckLabels" ) );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2022-09-10 00:19:29 +00:00
|
|
|
// Labels that have multiple pins connected are not dangling (may be used for naming segments)
|
|
|
|
// so leave them without errors here
|
|
|
|
if( pinCount > 1 )
|
|
|
|
return true;
|
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
for( auto& [type, label_vec] : label_map )
|
2019-11-30 02:10:16 +00:00
|
|
|
{
|
2022-09-19 20:46:01 +00:00
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
switch( type )
|
2019-11-30 02:10:16 +00:00
|
|
|
{
|
2022-09-12 20:15:53 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
if( !settings.IsTestEnabled( ERCE_GLOBLABEL ) )
|
2022-09-19 20:46:01 +00:00
|
|
|
continue;
|
2019-04-25 19:10:19 +00:00
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
break;
|
2022-09-19 20:46:01 +00:00
|
|
|
default:
|
2022-09-12 20:15:53 +00:00
|
|
|
if( !settings.IsTestEnabled( ERCE_LABEL_NOT_CONNECTED ) )
|
2022-09-19 20:46:01 +00:00
|
|
|
continue;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
break;
|
2022-09-19 20:46:01 +00:00
|
|
|
}
|
2022-09-12 20:15:53 +00:00
|
|
|
|
2022-09-19 20:46:01 +00:00
|
|
|
for( SCH_TEXT* text : label_vec )
|
|
|
|
{
|
|
|
|
int allPins = pinCount;
|
2022-09-12 20:15:53 +00:00
|
|
|
|
2022-11-21 23:16:44 +00:00
|
|
|
auto it = m_net_name_to_subgraphs_map.find( netName );
|
2022-09-12 20:15:53 +00:00
|
|
|
|
2022-09-19 20:46:01 +00:00
|
|
|
if( it != m_net_name_to_subgraphs_map.end() )
|
|
|
|
{
|
2022-09-12 20:15:53 +00:00
|
|
|
for( const CONNECTION_SUBGRAPH* neighbor : it->second )
|
|
|
|
{
|
|
|
|
if( neighbor == aSubgraph )
|
|
|
|
continue;
|
|
|
|
|
2022-12-06 22:08:36 +00:00
|
|
|
if( neighbor->m_no_connect )
|
|
|
|
has_nc = true;
|
|
|
|
|
2022-09-12 20:15:53 +00:00
|
|
|
allPins += hasPins( neighbor );
|
|
|
|
}
|
2022-09-19 20:46:01 +00:00
|
|
|
}
|
2022-09-12 20:15:53 +00:00
|
|
|
|
2022-12-09 02:09:48 +00:00
|
|
|
if( allPins == 1 && !has_nc )
|
|
|
|
{
|
|
|
|
reportError( text,
|
|
|
|
type == SCH_GLOBAL_LABEL_T ? ERCE_GLOBLABEL : ERCE_LABEL_NOT_CONNECTED );
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( allPins == 0 )
|
2022-09-19 20:46:01 +00:00
|
|
|
{
|
|
|
|
reportError( text,
|
|
|
|
type == SCH_GLOBAL_LABEL_T ? ERCE_GLOBLABEL : ERCE_LABEL_NOT_CONNECTED );
|
|
|
|
ok = false;
|
|
|
|
}
|
2022-09-12 20:15:53 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 21:13:42 +00:00
|
|
|
return ok;
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
2020-08-26 01:52:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
int CONNECTION_GRAPH::ercCheckHierSheets()
|
|
|
|
{
|
|
|
|
int errors = 0;
|
|
|
|
|
2021-01-14 00:47:28 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
|
2020-08-26 01:52:52 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : m_sheetList )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_SHEET_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_SHEET* parentSheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
std::map<wxString, SCH_SHEET_PIN*> pins;
|
2021-02-13 15:24:22 +00:00
|
|
|
std::map<wxString, SCH_HIERLABEL*> labels;
|
2020-08-26 01:52:52 +00:00
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : parentSheet->GetPins() )
|
2021-01-14 00:47:28 +00:00
|
|
|
{
|
2021-11-04 16:23:25 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_HIERACHICAL_LABEL ) )
|
|
|
|
pins[pin->GetText()] = pin;
|
2020-08-26 01:52:52 +00:00
|
|
|
|
2021-01-14 00:47:28 +00:00
|
|
|
if( pin->IsDangling() && settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_CONNECTED );
|
|
|
|
ercItem->SetItems( pin );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
|
|
|
|
sheet.LastScreen()->Append( marker );
|
|
|
|
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_HIERACHICAL_LABEL ) )
|
2020-08-26 01:52:52 +00:00
|
|
|
{
|
2021-11-04 16:23:25 +00:00
|
|
|
std::set<wxString> matchedPins;
|
|
|
|
|
|
|
|
for( SCH_ITEM* subItem : parentSheet->GetScreen()->Items() )
|
2020-08-26 01:52:52 +00:00
|
|
|
{
|
2021-11-04 16:23:25 +00:00
|
|
|
if( subItem->Type() == SCH_HIER_LABEL_T )
|
|
|
|
{
|
|
|
|
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( subItem );
|
2021-02-13 15:24:22 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
if( !pins.count( label->GetText() ) )
|
|
|
|
labels[label->GetText()] = label;
|
|
|
|
else
|
|
|
|
matchedPins.insert( label->GetText() );
|
|
|
|
}
|
2020-08-26 01:52:52 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
for( const wxString& matched : matchedPins )
|
|
|
|
pins.erase( matched );
|
2021-02-18 17:10:51 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
for( const std::pair<const wxString, SCH_SHEET_PIN*>& unmatched : pins )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Sheet pin %s has no matching hierarchical "
|
|
|
|
"label inside the sheet" ),
|
|
|
|
UnescapeString( unmatched.first ) );
|
2020-12-20 15:08:43 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_HIERACHICAL_LABEL );
|
|
|
|
ercItem->SetItems( unmatched.second );
|
|
|
|
ercItem->SetErrorMessage( msg );
|
2023-01-21 23:25:40 +00:00
|
|
|
ercItem->SetSheetSpecificPath( sheet );
|
|
|
|
ercItem->SetItemsSheetPaths( sheet );
|
2020-08-26 01:52:52 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, unmatched.second->GetPosition() );
|
|
|
|
sheet.LastScreen()->Append( marker );
|
2020-08-26 01:52:52 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2021-02-13 15:24:22 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
for( const std::pair<const wxString, SCH_HIERLABEL*>& unmatched : labels )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Hierarchical label %s has no matching "
|
|
|
|
"sheet pin in the parent sheet" ),
|
|
|
|
UnescapeString( unmatched.first ) );
|
2021-02-13 15:24:22 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
SCH_SHEET_PATH parentSheetPath = sheet;
|
|
|
|
parentSheetPath.push_back( parentSheet );
|
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_HIERACHICAL_LABEL );
|
|
|
|
ercItem->SetItems( unmatched.second );
|
|
|
|
ercItem->SetErrorMessage( msg );
|
2023-01-21 23:25:40 +00:00
|
|
|
ercItem->SetSheetSpecificPath( parentSheetPath );
|
|
|
|
ercItem->SetItemsSheetPaths( parentSheetPath );
|
2021-02-13 15:24:22 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, unmatched.second->GetPosition() );
|
|
|
|
parentSheet->GetScreen()->Append( marker );
|
2021-02-13 15:24:22 +00:00
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2021-02-13 15:24:22 +00:00
|
|
|
}
|
2020-08-26 01:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|