From bf32cc25556ac887c3f12c1aedd562c6167be1f5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 25 Oct 2017 15:21:42 -0700 Subject: [PATCH] Eeschema: Moving SchematicCleanup to SCH_EDIT_FRAME SchematicCleanup function moved from SCH_SCREEN to SCH_EDIT_FRAME to allow access to the undo stack as we are changing the schematic. --- eeschema/bus-wire-junction.cpp | 53 +++++++++++++++++++++++++++-- eeschema/class_sch_screen.h | 14 -------- eeschema/hierarch.cpp | 2 +- eeschema/project_rescue.cpp | 2 +- eeschema/sch_screen.cpp | 62 ---------------------------------- eeschema/schframe.cpp | 2 +- eeschema/schframe.h | 10 ++++++ 7 files changed, 64 insertions(+), 81 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index fa0175463e..410f830f6c 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -330,7 +330,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) screen->Append( s_wires ); // Correct and remove segments that need to be merged. - screen->SchematicCleanUp(); + SchematicCleanUp(); // A junction could be needed to connect the end point of the last created segment. if( screen->IsJunctionNeeded( endpoint ) ) @@ -417,6 +417,55 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) } +bool SCH_EDIT_FRAME::SchematicCleanUp() +{ + bool modified = false; + + for( SCH_ITEM* item = GetScreen()->GetDrawItems() ; item; item = item->Next() ) + { + if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) ) + continue; + + bool restart; + + for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? GetScreen()->GetDrawItems() : testItem->Next() ) + { + restart = false; + + if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) ) + { + SCH_LINE* line = (SCH_LINE*) item; + + if( line->MergeOverlap( (SCH_LINE*) testItem ) ) + { + // Keep the current flags, because the deleted segment can be flagged. + item->SetFlags( testItem->GetFlags() ); + DeleteItem( testItem ); + restart = true; + modified = true; + } + } + 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 ); + restart = true; + modified = true; + } + } + } + } + + GetScreen()->TestDanglingEnds(); + + return modified; +} + + SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList ) { @@ -445,7 +494,7 @@ SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPositio SetRepeatItem( no_connect ); GetScreen()->Append( no_connect ); - GetScreen()->SchematicCleanUp(); + SchematicCleanUp(); OnModify(); m_canvas->Refresh(); SaveCopyInUndoList( no_connect, UR_NEW ); diff --git a/eeschema/class_sch_screen.h b/eeschema/class_sch_screen.h index 92c564d830..7bd647ff57 100644 --- a/eeschema/class_sch_screen.h +++ b/eeschema/class_sch_screen.h @@ -261,17 +261,8 @@ public: bool CheckIfOnDrawList( SCH_ITEM* st ); - /** - * Perform routine schematic cleaning including breaking wire and buses and - * deleting identical objects superimposed on top of each other. - * - * @return True if any schematic clean up was performed. - */ - bool SchematicCleanUp(); - /** * Test all of the connectable objects in the schematic for unused connection points. - * * @return True if any connection state changes were made. */ bool TestDanglingEnds(); @@ -541,11 +532,6 @@ public: */ void ClearAnnotation(); - /** - * Merge and break wire segments in the entire schematic hierarchy. - */ - void SchematicCleanUp(); - /** * Test all sheet and component objects in the schematic for duplicate time stamps * and replaces them as necessary. diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index d66aa4ea98..c41c821644 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -299,7 +299,7 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() screen->m_FirstRedraw = false; SetCrossHairPosition( GetScrollCenterPosition() ); m_canvas->MoveCursorToCrossHair(); - screen->SchematicCleanUp(); + SchematicCleanUp(); } else { diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index ed2485d583..0af8db5171 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -556,7 +556,7 @@ bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ) viewer->ReCreateListLib(); // Clean up wire ends - GetScreen()->SchematicCleanUp(); + SchematicCleanUp(); m_canvas->Refresh( true ); OnModify(); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index edc90bc4b0..11837dc80c 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -435,55 +435,6 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer ) } -bool SCH_SCREEN::SchematicCleanUp() -{ - bool modified = false; - - for( SCH_ITEM* item = m_drawList.begin() ; item; item = item->Next() ) - { - if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) ) - continue; - - bool restart; - - for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? m_drawList.begin() : testItem->Next() ) - { - restart = false; - - if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) ) - { - SCH_LINE* line = (SCH_LINE*) item; - - if( line->MergeOverlap( (SCH_LINE*) testItem ) ) - { - // Keep the current flags, because the deleted segment can be flagged. - item->SetFlags( testItem->GetFlags() ); - DeleteItem( testItem ); - restart = true; - modified = true; - } - } - 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 ); - restart = true; - modified = true; - } - } - } - } - - TestDanglingEnds(); - - return modified; -} - - void SCH_SCREEN::UpdateSymbolLinks( bool aForce ) { // Initialize or reinitialize the pointer to the LIB_PART for each component @@ -1375,19 +1326,6 @@ void SCH_SCREENS::ClearAnnotation() m_screens[i]->ClearAnnotation( NULL ); } - -void SCH_SCREENS::SchematicCleanUp() -{ - for( size_t i = 0; i < m_screens.size(); i++ ) - { - // if wire list has changed, delete the undo/redo list to avoid - // pointer problems with deleted data. - if( m_screens[i]->SchematicCleanUp() ) - m_screens[i]->ClearUndoRedoList(); - } -} - - int SCH_SCREENS::ReplaceDuplicateTimeStamps() { EDA_ITEMS items; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index c6808858a0..ea0043ad9f 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -1249,7 +1249,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) libeditFrame->LoadComponentAndSelectLib( id ); } - GetScreen()->SchematicCleanUp(); + SchematicCleanUp(); m_canvas->Refresh(); } diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 1e3e46dd87..a583ab46f8 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -908,6 +908,15 @@ private: */ SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = false ); + /** + * Function SchematicCleanUp + * performs routine schematic cleaning including breaking wire and buses and + * deleting identical objects superimposed on top of each other. + * + * @return True if any schematic clean up was performed. + */ + bool SchematicCleanUp(); + /** * Start moving \a aItem using the mouse. * @@ -1072,6 +1081,7 @@ public: * Remove \a aItem from the current screen and saves it in the undo list. * * @param aItem The item to remove from the current screen. + * @param aAppend True if we are updating a previous Undo state */ void DeleteItem( SCH_ITEM* aItem, bool aAppend = false );