Move FixupJunctions to SCHEMATIC

This commit is contained in:
Roberto Fernandez Bautista 2022-08-18 23:19:28 +02:00
parent c4bde9c7e8
commit d063eb431b
8 changed files with 46 additions and 50 deletions

View File

@ -102,7 +102,6 @@ static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFil
sheets.AnnotatePowerSymbols();
// NOTE: This is required for multi-unit symbols to be correct
// Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
for( SCH_SHEET_PATH& sheet : sheets )
sheet.UpdateAllScreenReferences();

View File

@ -487,12 +487,16 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
RecomputeIntersheetRefs();
GetCurrentSheet().UpdateAllScreenReferences();
// re-create junctions if needed. Eeschema optimizes wires by merging
// Re-create junctions if needed. Eeschema optimizes wires by merging
// colinear segments. If a schematic is saved without a valid
// cache library or missing installed libraries, this can cause connectivity errors
// unless junctions are added.
//
// TODO: (RFB) This really needs to be put inside the Load() function of the SCH_LEGACY_PLUGIN
// I can't put it right now because of the extra code that is above to convert legacy bus-bus
// entries to bus wires
if( schFileType == SCH_IO_MGR::SCH_LEGACY )
FixupJunctions();
Schematic().FixupJunctions();
SyncView();
GetScreen()->ClearDrawingState();
@ -1254,13 +1258,6 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
GetScreen()->SetFileName( newfilename.GetFullPath() );
GetScreen()->SetContentModified();
// Only fix junctions for CADSTAR importer for now as it may cause issues with
// other importers
if( fileType == SCH_IO_MGR::SCH_CADSTAR_ARCHIVE )
{
FixupJunctions();
}
RecalculateConnections( GLOBAL_CLEANUP );
// Only perform the dangling end test on root sheet.

View File

@ -1651,42 +1651,6 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
}
void SCH_EDIT_FRAME::FixupJunctions()
{
// Save the current sheet, to retrieve it later
SCH_SHEET_PATH oldsheetpath = GetCurrentSheet();
SCH_SHEET_LIST sheetList = Schematic().GetSheets();
for( const SCH_SHEET_PATH& sheet : sheetList )
{
size_t num_undos = m_undoList.m_CommandsList.size();
SetCurrentSheet( sheet );
GetCurrentSheet().UpdateAllScreenReferences();
SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
EE_SELECTION allItems;
for( auto item : screen->Items() )
allItems.Add( item );
m_toolManager->GetTool<SCH_LINE_WIRE_BUS_TOOL>()->AddJunctionsIfNeeded( &allItems );
// Check if we modified anything during this routine
// Needs to happen for every sheet to set the proper modified flag
if( m_undoList.m_CommandsList.size() > num_undos )
OnModify();
}
// Reselect the initial sheet:
SetCurrentSheet( oldsheetpath );
GetCurrentSheet().UpdateAllScreenReferences();
SetScreen( GetCurrentSheet().LastScreen() );
}
bool SCH_EDIT_FRAME::IsContentModified() const
{
return Schematic().GetSheets().IsModified();

View File

@ -770,8 +770,6 @@ public:
const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
void FixupJunctions();
int GetSchematicJunctionSize();
void FocusOnItem( SCH_ITEM* aItem );

View File

@ -140,6 +140,9 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI
sch_plugin->SaveLibrary( libFileName.GetFullPath() );
// Need to fix up junctions after import to retain connectivity
aSchematic->FixupJunctions();
return rootSheet;
}

View File

@ -25,6 +25,8 @@
#include <project/project_file.h>
#include <project/net_settings.h>
#include <schematic.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_screen.h>
#include <sim/spice_settings.h>
#include <sch_label.h>
@ -559,3 +561,31 @@ void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLAB
}
}
}
void SCHEMATIC::FixupJunctions()
{
for( const SCH_SHEET_PATH& sheet : GetSheets() )
{
SCH_SCREEN* screen = sheet.LastScreen();
std::deque<EDA_ITEM*> allItems;
for( auto item : screen->Items() )
allItems.push_back( item );
// Add missing junctions and breakup wires as needed
for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
{
SCH_JUNCTION* junction = new SCH_JUNCTION( point );
screen->Append( junction );
// Breakup wires
for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) )
{
SCH_LINE* newSegment = wire->BreakAt( point );
screen->Append( newSegment );
}
}
}
}

View File

@ -202,6 +202,12 @@ public:
*/
void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
/**
* Add junctions to this schematic where required. This function is needed for some plugins
* (e.g. Legacy and Cadstar) in order to retain connectivity after loading.
*/
void FixupJunctions();
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override {}
#endif

View File

@ -107,7 +107,6 @@ void KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic( const wxString& aBaseName )
sheets.AnnotatePowerSymbols();
// NOTE: This is required for multi-unit symbols to be correct
// Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
for( SCH_SHEET_PATH& sheet : sheets )
sheet.UpdateAllScreenReferences();