Schematic: import schematic sheet content, allow move and undo

Otherwise, the schematic is just plopped on the screen, causing
connections and junctions to be missing that should be present.
This commit is contained in:
Mike Williams 2024-02-13 12:18:46 -05:00
parent 3cd61a2d39
commit c92728715d
1 changed files with 32 additions and 0 deletions

View File

@ -69,7 +69,9 @@
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <tools/ee_actions.h>
#include <tools/ee_inspection_tool.h> #include <tools/ee_inspection_tool.h>
#include <tools/ee_selection_tool.h>
#include <paths.h> #include <paths.h>
#include <wx_filename.h> // For ::ResolvePossibleSymlinks #include <wx_filename.h> // For ::ResolvePossibleSymlinks
#include <widgets/wx_progress_reporters.h> #include <widgets/wx_progress_reporters.h>
@ -617,6 +619,15 @@ bool SCH_EDIT_FRAME::AppendSchematic()
bool SCH_EDIT_FRAME::AddSheetAndUpdateDisplay( const wxString aFullFileName ) bool SCH_EDIT_FRAME::AddSheetAndUpdateDisplay( const wxString aFullFileName )
{ {
SCH_COMMIT commit( m_toolManager );
EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
selectionTool->ClearSelection();
// Mark all existing items on the screen so we don't select them after appending
for( EDA_ITEM* item : GetScreen()->Items() )
item->SetFlags( SKIP_STRUCT );
if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), aFullFileName ) ) if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), aFullFileName ) )
return false; return false;
@ -627,6 +638,27 @@ bool SCH_EDIT_FRAME::AddSheetAndUpdateDisplay( const wxString aFullFileName )
OnModify(); OnModify();
HardRedraw(); // Full reinit of the current screen and the display. HardRedraw(); // Full reinit of the current screen and the display.
// Select all new items
for( EDA_ITEM* item : GetScreen()->Items() )
{
if( !item->HasFlag( SKIP_STRUCT ) )
{
commit.Added( item, GetScreen() );
selectionTool->AddItemToSel( item );
if( item->Type() == SCH_LINE_T )
item->SetFlags( STARTPOINT | ENDPOINT );
}
else
item->ClearFlags( SKIP_STRUCT );
}
// Start moving selection, cancel undoes the insertion
if( !m_toolManager->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
commit.Revert();
else
commit.Push( _( "Import Schematic Sheet Content..." ) );
UpdateHierarchyNavigator(); UpdateHierarchyNavigator();
return true; return true;