Make sure hierarchical overrides are deterministic

Without alphabetic sorting here, we are at the mercy of
the r-tree and multithreading.
This commit is contained in:
Jon Evans 2021-01-14 10:26:53 -05:00
parent ee6ec2c35c
commit 6fb1ed2824
3 changed files with 28 additions and 22 deletions

View File

@ -1803,10 +1803,11 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph )
} }
// Now, find the best driver for this chain of subgraphs // Now, find the best driver for this chain of subgraphs
CONNECTION_SUBGRAPH* driver = aSubgraph; CONNECTION_SUBGRAPH* original = aSubgraph;
CONNECTION_SUBGRAPH::PRIORITY highest = CONNECTION_SUBGRAPH::PRIORITY highest =
CONNECTION_SUBGRAPH::GetDriverPriority( aSubgraph->m_driver ); CONNECTION_SUBGRAPH::GetDriverPriority( aSubgraph->m_driver );
bool originalStrong = ( highest >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL ); bool originalStrong = ( highest >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL );
wxString originalName = original->m_driver_connection->Name();
// Check if a subsheet has a higher-priority connection to the same net // Check if a subsheet has a higher-priority connection to the same net
if( highest < CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN ) if( highest < CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN )
@ -1816,31 +1817,36 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph )
CONNECTION_SUBGRAPH::PRIORITY priority = CONNECTION_SUBGRAPH::PRIORITY priority =
CONNECTION_SUBGRAPH::GetDriverPriority( subgraph->m_driver ); CONNECTION_SUBGRAPH::GetDriverPriority( subgraph->m_driver );
bool candidateStrong = ( priority >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL ); bool candidateStrong = ( priority >= CONNECTION_SUBGRAPH::PRIORITY::HIER_LABEL );
wxString candidateName = subgraph->m_driver_connection->Name();
// Pick a better driving subgraph if it: // Pick a better driving subgraph if it:
// a) has a power pin or global driver // a) has a power pin or global driver
// b) is a strong driver and we're a weak driver // b) is a strong driver and we're a weak driver
// c) meets or exceeds our priority, is a strong driver, and has a shorter path // c) meets or exceeds our priority, is a strong driver, and has a shorter path
// d) is weak, we're week, and is alphabetically lower
if( ( priority >= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN ) || if( ( priority >= CONNECTION_SUBGRAPH::PRIORITY::POWER_PIN ) ||
( !originalStrong && candidateStrong ) || ( !originalStrong && candidateStrong ) ||
( priority >= highest && candidateStrong && ( priority >= highest && candidateStrong &&
subgraph->m_sheet.size() < aSubgraph->m_sheet.size() ) ) subgraph->m_sheet.size() < aSubgraph->m_sheet.size() ) ||
( !originalStrong && !candidateStrong && candidateName < originalName ) )
{ {
driver = subgraph; original = subgraph;
highest = priority;
originalStrong = candidateStrong;
} }
} }
} }
if( driver != aSubgraph ) if( original != aSubgraph )
{ {
wxLogTrace( ConnTrace, "%lu (%s) overridden by new driver %lu (%s)", wxLogTrace( ConnTrace, "%lu (%s) overridden by new driver %lu (%s)",
aSubgraph->m_code, aSubgraph->m_driver_connection->Name(), aSubgraph->m_code, aSubgraph->m_driver_connection->Name(), original->m_code,
driver->m_code, driver->m_driver_connection->Name() ); original->m_driver_connection->Name() );
} }
conn = driver->m_driver_connection; conn = original->m_driver_connection;
for( CONNECTION_SUBGRAPH* subgraph : visited ) for( CONNECTION_SUBGRAPH* subgraph : visited )
{ {

View File

@ -128,13 +128,13 @@
(node (ref "J2") (pin "1") (pinfunction "Pin_1")) (node (ref "J2") (pin "1") (pinfunction "Pin_1"))
(node (ref "R1") (pin "1")) (node (ref "R1") (pin "1"))
(node (ref "R2") (pin "1"))) (node (ref "R2") (pin "1")))
(net (code "3") (name "/Sheet5CC15EF8/NEUTRAL") (net (code "3") (name "/sheet5CC165F1/LIVE_1")
(node (ref "J1") (pin "2") (pinfunction "Pin_2"))
(node (ref "R4") (pin "2")))
(net (code "4") (name "/sheet5CC165F1/NEUTRAL")
(node (ref "J2") (pin "3") (pinfunction "Pin_3")) (node (ref "J2") (pin "3") (pinfunction "Pin_3"))
(node (ref "R1") (pin "2")) (node (ref "R1") (pin "2"))
(node (ref "R3") (pin "2"))) (node (ref "R3") (pin "2")))
(net (code "4") (name "/sheet5CC165F1/LIVE_1")
(node (ref "J1") (pin "2") (pinfunction "Pin_2"))
(node (ref "R4") (pin "2")))
(net (code "5") (name "LIVE") (net (code "5") (name "LIVE")
(node (ref "J1") (pin "1") (pinfunction "Pin_1")) (node (ref "J1") (pin "1") (pinfunction "Pin_1"))
(node (ref "R2") (pin "2"))) (node (ref "R2") (pin "2")))

View File

@ -117,15 +117,15 @@
(library (logical "Device") (library (logical "Device")
(uri "/home/jon/kicad-library/kicad-symbols//Device.kicad_sym"))) (uri "/home/jon/kicad-library/kicad-symbols//Device.kicad_sym")))
(nets (nets
(net (code "1") (name "/Merge/A1") (net (code "1") (name "/Merge/D1")
(node (ref "R1") (pin "1"))
(node (ref "R3") (pin "1")))
(net (code "2") (name "/Merge/A2")
(node (ref "R1") (pin "2"))
(node (ref "R3") (pin "2")))
(net (code "3") (name "/Sub2/B1")
(node (ref "R2") (pin "1")) (node (ref "R2") (pin "1"))
(node (ref "R4") (pin "1"))) (node (ref "R4") (pin "1")))
(net (code "4") (name "/Sub2/B2") (net (code "2") (name "/Merge/D2")
(node (ref "R2") (pin "2")) (node (ref "R2") (pin "2"))
(node (ref "R4") (pin "2"))))) (node (ref "R4") (pin "2")))
(net (code "3") (name "/Sub1/B1")
(node (ref "R1") (pin "1"))
(node (ref "R3") (pin "1")))
(net (code "4") (name "/Sub1/B2")
(node (ref "R1") (pin "2"))
(node (ref "R3") (pin "2")))))