← Back to team overview

kicad-developers team mailing list archive

[PATCH] Schematic Cleanup: prepare for asymmetric tests

 

Always run over the entire matrix, skip symmetric tests after passing
diagonal. This allows us to define asymmetric cleanup cases like for
(junction, line) pairs.
---
 eeschema/sch_screen.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp
index c86442e..bd60012 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -440,14 +440,25 @@ bool SCH_SCREEN::SchematicCleanUp()
         if( !( lhs_isLine || lhs_isJunction ) )
             continue;
 
-        bool restart;
+        bool restart = true;
 
-        for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? m_drawList.begin() : testItem->Next() )
+        // symmetric (junction-junction, wire-wire, ...) optimizations are
+        // only run once for each pair, so skip them after we've passed the
+        // diagonal
+        bool skip_symmetric;
+
+        for( SCH_ITEM* testItem = m_drawList.begin(); testItem; testItem = restart ? m_drawList.begin() : testItem->Next() )
         {
+            if( restart )
+                skip_symmetric = false;
+
             restart = false;
 
             if( testItem == item )
+            {
+                skip_symmetric = true;
                 continue;
+            }
 
             const auto rhs_type = testItem->Type();
 
@@ -462,7 +473,7 @@ bool SCH_SCREEN::SchematicCleanUp()
                 SCH_LINE* lhs_line = (SCH_LINE*) item;
                 SCH_LINE* rhs_line = (SCH_LINE*) testItem;
 
-                if( lhs_line->CanMerge( rhs_line ) )
+                if( !skip_symmetric && lhs_line->CanMerge( rhs_line ) )
                 {
                     // Do not merge lines meeting at a junction
                     auto lhs_start = lhs_line->GetStartPoint();
@@ -502,7 +513,7 @@ bool SCH_SCREEN::SchematicCleanUp()
             }
             else if ( lhs_isJunction && rhs_isJunction )
             {
-                if ( testItem->HitTest( item->GetPosition() ) )
+                if ( !skip_symmetric && testItem->HitTest( item->GetPosition() ) )
                 {
                     // Keep the current flags, because the deleted segment can be flagged.
                     item->SetFlags( testItem->GetFlags() );