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.
This commit is contained in:
Seth Hillbrand 2017-10-25 15:21:42 -07:00 committed by Wayne Stambaugh
parent c6632bdded
commit bf32cc2555
7 changed files with 64 additions and 81 deletions

View File

@ -330,7 +330,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
screen->Append( s_wires ); screen->Append( s_wires );
// Correct and remove segments that need to be merged. // 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. // A junction could be needed to connect the end point of the last created segment.
if( screen->IsJunctionNeeded( endpoint ) ) 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, SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
bool aPutInUndoList ) bool aPutInUndoList )
{ {
@ -445,7 +494,7 @@ SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPositio
SetRepeatItem( no_connect ); SetRepeatItem( no_connect );
GetScreen()->Append( no_connect ); GetScreen()->Append( no_connect );
GetScreen()->SchematicCleanUp(); SchematicCleanUp();
OnModify(); OnModify();
m_canvas->Refresh(); m_canvas->Refresh();
SaveCopyInUndoList( no_connect, UR_NEW ); SaveCopyInUndoList( no_connect, UR_NEW );

View File

@ -261,17 +261,8 @@ public:
bool CheckIfOnDrawList( SCH_ITEM* st ); 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. * Test all of the connectable objects in the schematic for unused connection points.
*
* @return True if any connection state changes were made. * @return True if any connection state changes were made.
*/ */
bool TestDanglingEnds(); bool TestDanglingEnds();
@ -541,11 +532,6 @@ public:
*/ */
void ClearAnnotation(); 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 * Test all sheet and component objects in the schematic for duplicate time stamps
* and replaces them as necessary. * and replaces them as necessary.

View File

@ -299,7 +299,7 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet()
screen->m_FirstRedraw = false; screen->m_FirstRedraw = false;
SetCrossHairPosition( GetScrollCenterPosition() ); SetCrossHairPosition( GetScrollCenterPosition() );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
screen->SchematicCleanUp(); SchematicCleanUp();
} }
else else
{ {

View File

@ -556,7 +556,7 @@ bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
viewer->ReCreateListLib(); viewer->ReCreateListLib();
// Clean up wire ends // Clean up wire ends
GetScreen()->SchematicCleanUp(); SchematicCleanUp();
m_canvas->Refresh( true ); m_canvas->Refresh( true );
OnModify(); OnModify();

View File

@ -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 ) void SCH_SCREEN::UpdateSymbolLinks( bool aForce )
{ {
// Initialize or reinitialize the pointer to the LIB_PART for each component // 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 ); 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() int SCH_SCREENS::ReplaceDuplicateTimeStamps()
{ {
EDA_ITEMS items; EDA_ITEMS items;

View File

@ -1249,7 +1249,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event )
libeditFrame->LoadComponentAndSelectLib( id ); libeditFrame->LoadComponentAndSelectLib( id );
} }
GetScreen()->SchematicCleanUp(); SchematicCleanUp();
m_canvas->Refresh(); m_canvas->Refresh();
} }

View File

@ -908,6 +908,15 @@ private:
*/ */
SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = false ); 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. * 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. * 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 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 ); void DeleteItem( SCH_ITEM* aItem, bool aAppend = false );