From 70c30bce7455c4f1ac51fff9331abbd48fc3191d Mon Sep 17 00:00:00 2001 From: Moses McKnight Date: Wed, 20 Jun 2012 11:52:29 +0200 Subject: [PATCH] Commit patches from Moses McKnight, to avoid duplicate junctions. --- eeschema/bus-wire-junction.cpp | 27 ++++----------------------- eeschema/onleftclick.cpp | 19 +++++++++++++------ eeschema/sch_screen.cpp | 19 +++++++++++++++++-- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index ce1de8d5b4..8f642869e6 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -255,14 +255,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) screen->SetCurItem( NULL ); m_canvas->EndMouseCapture( -1, -1, wxEmptyString, false ); - DLIST< SCH_ITEM > tmp; - - for( item = s_wires.begin(); item != NULL; item = item->Next() ) - tmp.PushBack( (SCH_ITEM*) item->Clone() ); - - // Temporarily add the new segments to the schematic item list to test if any - // junctions are required. - screen->Append( tmp ); + screen->Append( s_wires ); // Correct and remove segments that need merged. screen->SchematicCleanUp( NULL, DC ); @@ -271,27 +264,15 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) // removed by a cleanup, a junction may be needed to connect the segment's end point // which is also the same as the previous segment's start point. if( screen->IsJunctionNeeded( segment->GetEndPoint() ) ) - s_wires.Append( AddJunction( DC, segment->GetEndPoint() ) ); + screen->Append( AddJunction( DC, segment->GetEndPoint() ) ); else if( screen->IsJunctionNeeded( segment->GetStartPoint() ) ) - s_wires.Append( AddJunction( DC, segment->GetStartPoint() ) ); + screen->Append( AddJunction( DC, segment->GetStartPoint() ) ); // Automatically place a junction on the start point if necessary because the cleanup // can suppress intermediate points by merging wire segments. if( screen->IsJunctionNeeded( s_startPoint ) ) - s_wires.Append( AddJunction( DC, s_startPoint ) ); + screen->Append( AddJunction( DC, s_startPoint ) ); - // Make a copy of the original wires, buses, and junctions. - for( item = s_oldWires.begin(); item != NULL; item = item->Next() ) - tmp.PushBack( (SCH_ITEM*) item->Clone() ); - - // Restore the old wires. - if( tmp.GetCount() != 0 ) - screen->ReplaceWires( tmp ); - - // Now add the new wires and any required junctions to the schematic item list. - screen->Append( s_wires ); - - screen->SchematicCleanUp( NULL, DC ); m_canvas->Refresh(); // Put the snap shot of the previous wire, buses, and junctions in the undo/redo list. diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index 2fc952c46e..1fcd2085b9 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -86,6 +86,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) + item->GetClass() + wxT( "> is already being edited." ) ); item->ClearFlags(); + break; } } else @@ -124,9 +125,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_NOCONN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { - m_itemToRepeat = AddNoConnect( aDC, gridPosition ); - GetScreen()->SetCurItem( m_itemToRepeat ); - m_canvas->SetAutoPanRequest( true ); + if( false == GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) ) + { + m_itemToRepeat = AddNoConnect( aDC, gridPosition ); + GetScreen()->SetCurItem( m_itemToRepeat ); + m_canvas->SetAutoPanRequest( true ); + } } else { @@ -138,9 +142,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_JUNCTION_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { - m_itemToRepeat = AddJunction( aDC, gridPosition, true ); - GetScreen()->SetCurItem( m_itemToRepeat ); - m_canvas->SetAutoPanRequest( true ); + if( false == GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) ) + { + m_itemToRepeat = AddJunction( aDC, gridPosition, true ); + GetScreen()->SetCurItem( m_itemToRepeat ); + m_canvas->SetAutoPanRequest( true ); + } } else { diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 70687437d7..4426612cfb 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -434,14 +434,14 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) for( ; item != NULL; item = item->Next() ) { - if( item->Type() != SCH_LINE_T ) + if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) ) continue; testItem = item->Next(); while( testItem ) { - if( testItem->Type() == SCH_LINE_T ) + if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) ) { SCH_LINE* line = (SCH_LINE*) item; @@ -458,6 +458,21 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) testItem = testItem->Next(); } } + else if ( ( ( item->Type() == SCH_JUNCTION_T ) && ( testItem->Type() == SCH_JUNCTION_T ) ) && ( testItem != item ) ) + { + if ( testItem->HitTest( item->GetPosition() ) ) + { + // Keep the current flags, because the deleted segment can be flagged. + item->SetFlags( testItem->GetFlags() ); + DeleteItem( testItem ); + testItem = m_drawList.begin(); + modified = true; + } + else + { + testItem = testItem->Next(); + } + } else { testItem = testItem->Next();