Refactor how at-load schematic normalization is called

Don't prepend "/" for nets at the top level

Revert "Don't prepend "/" for nets at the top level"

This reverts commit fa9533222f7d33eee5f3fa2320bd9f3167e28076.
This commit is contained in:
Jon Evans 2019-03-23 17:34:27 -04:00 committed by Wayne Stambaugh
parent 4bc7e6fdfa
commit 9589427960
3 changed files with 58 additions and 24 deletions

View File

@ -657,16 +657,6 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aUndo, SCH_SCREEN* aScreen )
itemList.PushItem( ITEM_PICKER( aItem, UR_DELETED ) );
};
auto add_junction = [ & ]( const wxPoint& aPosition ) -> void
{
auto junction = new SCH_JUNCTION( aPosition );
AddToScreen( junction, aScreen );
BreakSegments( aPosition, aUndo );
if( aUndo )
SaveCopyInUndoList( junction, UR_NEW, true );
};
BreakSegmentsOnJunctions( true, aScreen );
for( item = aScreen->GetDrawItems(); item; item = item->Next() )
@ -749,16 +739,6 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aUndo, SCH_SCREEN* aScreen )
if( item->GetFlags() & STRUCT_DELETED )
RemoveFromScreen( item, aScreen );
else if( item->Type() == SCH_LINE_T )
{
auto line = static_cast<SCH_LINE*>( item );
if( aScreen->IsJunctionNeeded( line->GetStartPoint(), true ) )
add_junction( line->GetStartPoint() );
if( aScreen->IsJunctionNeeded( line->GetEndPoint(), true ) )
add_junction( line->GetEndPoint() );
}
}
if( itemList.GetCount() && aUndo )
@ -768,6 +748,48 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aUndo, SCH_SCREEN* aScreen )
}
bool SCH_EDIT_FRAME::AddMissingJunctions( SCH_SCREEN* aScreen )
{
bool added = false;
auto add_junction = [ & ]( const wxPoint& aPosition ) -> void
{
auto junction = new SCH_JUNCTION( aPosition );
AddToScreen( junction, aScreen );
BreakSegments( aPosition, false );
added = true;
};
for( auto item = aScreen->GetDrawItems(); item; item = item->Next() )
{
if( item->Type() == SCH_LINE_T )
{
auto line = static_cast<SCH_LINE*>( item );
if( aScreen->IsJunctionNeeded( line->GetStartPoint(), true ) )
add_junction( line->GetStartPoint() );
if( aScreen->IsJunctionNeeded( line->GetEndPoint(), true ) )
add_junction( line->GetEndPoint() );
}
}
return added;
}
void SCH_EDIT_FRAME::NormalizeSchematicOnFirstLoad()
{
BreakSegmentsOnJunctions();
SchematicCleanUp();
SCH_SHEET_LIST list( g_RootSheet );
for( const auto& sheet : list )
AddMissingJunctions( sheet.LastScreen() );
}
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint,
bool aAppend, SCH_LINE** aNewSegment,
SCH_SCREEN* aScreen )

View File

@ -370,8 +370,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
SetScreen( g_CurrentSheet->LastScreen() );
// Ensure the schematic is fully segmented on first display
BreakSegmentsOnJunctions();
SchematicCleanUp();
NormalizeSchematicOnFirstLoad();
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet.
@ -849,8 +849,8 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
// Ensure the schematic is fully segmented on first display
BreakSegmentsOnJunctions();
SchematicCleanUp();
NormalizeSchematicOnFirstLoad();
GetScreen()->m_Initialized = true;
SCH_TYPE_COLLECTOR components;

View File

@ -1034,6 +1034,18 @@ private:
*/
bool TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend = true );
/**
* Checks all wires and adds any junctions that are missing
* (Intended to be called only on file load)
*/
bool AddMissingJunctions( SCH_SCREEN* aScreen );
/**
* Perform all cleanup and normalization steps so that the whole schematic
* is in a good state. This should only be called when loading a file.
*/
void NormalizeSchematicOnFirstLoad();
/**
* Start moving \a aItem using the mouse.
*