Stuff RecomputeIntersheetRefs into SCHEMATIC for reuse
This commit is contained in:
parent
0190606886
commit
55ca6145ea
|
@ -148,6 +148,10 @@ SCHEMATIC* EESCHEMA_HELPERS::LoadSchematic( wxString& aFileName, SCH_IO_MGR::SCH
|
||||||
|
|
||||||
schematic->ConnectionGraph()->Reset();
|
schematic->ConnectionGraph()->Reset();
|
||||||
|
|
||||||
|
schematic->SetSheetNumberAndCount();
|
||||||
|
schematic->RecomputeIntersheetRefs( true, []( SCH_GLOBALLABEL* ) { } );
|
||||||
|
schematic->CurrentSheet().UpdateAllScreenReferences();
|
||||||
|
|
||||||
schematic->CurrentSheet().LastScreen()->TestDanglingEnds( nullptr, nullptr );
|
schematic->CurrentSheet().LastScreen()->TestDanglingEnds( nullptr, nullptr );
|
||||||
|
|
||||||
return schematic;
|
return schematic;
|
||||||
|
|
|
@ -1494,63 +1494,11 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
|
||||||
|
|
||||||
void SCH_EDIT_FRAME::RecomputeIntersheetRefs( bool autoplaceUninitialized )
|
void SCH_EDIT_FRAME::RecomputeIntersheetRefs( bool autoplaceUninitialized )
|
||||||
{
|
{
|
||||||
std::map<wxString, std::set<int>>& pageRefsMap = Schematic().GetPageRefsMap();
|
Schematic().RecomputeIntersheetRefs( autoplaceUninitialized,
|
||||||
|
[&]( SCH_GLOBALLABEL* label )
|
||||||
pageRefsMap.clear();
|
{
|
||||||
|
GetCanvas()->GetView()->Update( label );
|
||||||
SCH_SCREENS screens( Schematic().Root() );
|
});
|
||||||
std::vector<int> virtualPageNumbers;
|
|
||||||
|
|
||||||
/* Iterate over screens */
|
|
||||||
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
|
|
||||||
{
|
|
||||||
virtualPageNumbers.clear();
|
|
||||||
|
|
||||||
/* Find in which sheets this screen is used */
|
|
||||||
for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() )
|
|
||||||
{
|
|
||||||
if( sheet.LastScreen() == screen )
|
|
||||||
virtualPageNumbers.push_back( sheet.GetVirtualPageNumber() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( SCH_ITEM* item : screen->Items() )
|
|
||||||
{
|
|
||||||
if( item->Type() == SCH_GLOBAL_LABEL_T )
|
|
||||||
{
|
|
||||||
SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( item );
|
|
||||||
std::set<int>& virtualpageList = pageRefsMap[ globalLabel->GetText() ];
|
|
||||||
|
|
||||||
for( const int& pageNo : virtualPageNumbers )
|
|
||||||
virtualpageList.insert( pageNo );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool show = Schematic().Settings().m_IntersheetRefsShow;
|
|
||||||
|
|
||||||
// Refresh all global labels. Note that we have to collect them first as the
|
|
||||||
// SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
|
|
||||||
|
|
||||||
std::vector<SCH_GLOBALLABEL*> globalLabels;
|
|
||||||
|
|
||||||
for( EDA_ITEM* item : GetScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
|
|
||||||
globalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
|
|
||||||
|
|
||||||
for( SCH_GLOBALLABEL* globalLabel : globalLabels )
|
|
||||||
{
|
|
||||||
std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
|
|
||||||
|
|
||||||
fields[0].SetVisible( show );
|
|
||||||
|
|
||||||
if( show )
|
|
||||||
{
|
|
||||||
if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
|
|
||||||
globalLabel->AutoplaceFields( GetScreen(), false );
|
|
||||||
|
|
||||||
GetScreen()->Update( globalLabel );
|
|
||||||
GetCanvas()->GetView()->Update( globalLabel );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include <schematic.h>
|
#include <schematic.h>
|
||||||
#include <sch_screen.h>
|
#include <sch_screen.h>
|
||||||
#include <sim/spice_settings.h>
|
#include <sim/spice_settings.h>
|
||||||
|
#include <sch_label.h>
|
||||||
|
|
||||||
SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) :
|
SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) :
|
||||||
EDA_ITEM( nullptr, SCHEMATIC_T ),
|
EDA_ITEM( nullptr, SCHEMATIC_T ),
|
||||||
|
@ -496,4 +496,66 @@ void SCHEMATIC::SetSheetNumberAndCount()
|
||||||
CurrentSheet().SetVirtualPageNumber( sheet_number );
|
CurrentSheet().SetVirtualPageNumber( sheet_number );
|
||||||
CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
|
CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
|
||||||
CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
|
CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCHEMATIC::RecomputeIntersheetRefs( bool autoplaceUninitialized, const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
|
||||||
|
{
|
||||||
|
std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
|
||||||
|
|
||||||
|
pageRefsMap.clear();
|
||||||
|
|
||||||
|
SCH_SCREENS screens( Root() );
|
||||||
|
std::vector<int> virtualPageNumbers;
|
||||||
|
|
||||||
|
/* Iterate over screens */
|
||||||
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
|
||||||
|
{
|
||||||
|
virtualPageNumbers.clear();
|
||||||
|
|
||||||
|
/* Find in which sheets this screen is used */
|
||||||
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
||||||
|
{
|
||||||
|
if( sheet.LastScreen() == screen )
|
||||||
|
virtualPageNumbers.push_back( sheet.GetVirtualPageNumber() );
|
||||||
|
}
|
||||||
|
|
||||||
|
for( SCH_ITEM* item : screen->Items() )
|
||||||
|
{
|
||||||
|
if( item->Type() == SCH_GLOBAL_LABEL_T )
|
||||||
|
{
|
||||||
|
SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( item );
|
||||||
|
std::set<int>& virtualpageList = pageRefsMap[globalLabel->GetText()];
|
||||||
|
|
||||||
|
for( const int& pageNo : virtualPageNumbers )
|
||||||
|
virtualpageList.insert( pageNo );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool show = Settings().m_IntersheetRefsShow;
|
||||||
|
|
||||||
|
// Refresh all global labels. Note that we have to collect them first as the
|
||||||
|
// SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
|
||||||
|
|
||||||
|
std::vector<SCH_GLOBALLABEL*> globalLabels;
|
||||||
|
|
||||||
|
for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
|
||||||
|
globalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
|
||||||
|
|
||||||
|
for( SCH_GLOBALLABEL* globalLabel : globalLabels )
|
||||||
|
{
|
||||||
|
std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
|
||||||
|
|
||||||
|
fields[0].SetVisible( show );
|
||||||
|
|
||||||
|
if( show )
|
||||||
|
{
|
||||||
|
if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
|
||||||
|
globalLabel->AutoplaceFields( CurrentSheet().LastScreen(), false );
|
||||||
|
|
||||||
|
CurrentSheet().LastScreen()->Update( globalLabel );
|
||||||
|
aItemCallback( globalLabel );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ class PROJECT;
|
||||||
class SCH_SCREEN;
|
class SCH_SCREEN;
|
||||||
class SCH_SHEET;
|
class SCH_SHEET;
|
||||||
class SCH_SHEET_LIST;
|
class SCH_SHEET_LIST;
|
||||||
|
class SCH_GLOBALLABEL;
|
||||||
|
|
||||||
|
|
||||||
class SCHEMATIC_IFACE
|
class SCHEMATIC_IFACE
|
||||||
|
@ -195,6 +196,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetSheetNumberAndCount();
|
void SetSheetNumberAndCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the schematic's page reference map for all global labels, and refresh the labels
|
||||||
|
* so that they are redrawn with up-to-date references.
|
||||||
|
*/
|
||||||
|
void RecomputeIntersheetRefs( bool autoplaceUninitialized,
|
||||||
|
const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
void Show( int nestLevel, std::ostream& os ) const override {}
|
void Show( int nestLevel, std::ostream& os ) const override {}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue