From 48f19c031a3cc71cc065a7beede056c3564ad440 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 21 Mar 2017 11:22:03 +0100 Subject: [PATCH] Fix a few issues when importing a .ses specctra session file. (potential crash due to missing update of ratsnet data, add missing traces in GAL mode) --- pcbnew/dialogs/dialog_freeroute_exchange.cpp | 6 --- pcbnew/dialogs/dialog_global_deletion.cpp | 10 ++-- pcbnew/specctra_import.cpp | 49 ++++++++++---------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/pcbnew/dialogs/dialog_freeroute_exchange.cpp b/pcbnew/dialogs/dialog_freeroute_exchange.cpp index f84bd7e29c..bdfb2a8160 100644 --- a/pcbnew/dialogs/dialog_freeroute_exchange.cpp +++ b/pcbnew/dialogs/dialog_freeroute_exchange.cpp @@ -104,12 +104,6 @@ void DIALOG_FREEROUTE::OnExportButtonClick( wxCommandEvent& event ) void DIALOG_FREEROUTE::OnImportButtonClick( wxCommandEvent& event ) { m_Parent->ImportSpecctraSession( event ); - - /* Connectivity must be rebuild. - * because for large board it can take some time, this is made only on demand - */ - if( IsOK( this, _("Do you want to rebuild connectivity data ?" ) ) ) - m_Parent->Compile_Ratsnest( NULL, true ); } diff --git a/pcbnew/dialogs/dialog_global_deletion.cpp b/pcbnew/dialogs/dialog_global_deletion.cpp index 9477925e3c..85e88363c9 100644 --- a/pcbnew/dialogs/dialog_global_deletion.cpp +++ b/pcbnew/dialogs/dialog_global_deletion.cpp @@ -224,7 +224,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() } } - commit.Push( wxT( "Global delete" ) ); + commit.Push( "Global delete" ); if( m_DelMarkers->GetValue() ) pcb->DeleteMARKERs(); @@ -233,7 +233,9 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() m_Parent->Compile_Ratsnest( NULL, true ); // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch - // TODO necessary? if not, remove rn_data.h header as well - //if( m_Parent->IsGalCanvasActive() ) - //pcb->GetRatsnest()->ProcessBoard(); + if( m_Parent->IsGalCanvasActive() ) + pcb->GetRatsnest()->ProcessBoard(); + else + m_Parent->GetCanvas()->Refresh(); + } diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index 2326eb17ad..b75626ab36 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include @@ -62,14 +64,6 @@ void PCB_EDIT_FRAME::ImportSpecctraDesign( wxCommandEvent& event ) void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) { -/* - if( GetScreen()->IsModify() ) - { - if( !IsOK( this, _( "Board Modified: Continue ?" ) ) ) - return; - } -*/ - wxString fullFileName = GetBoard()->GetFileName(); wxString path; wxString name; @@ -93,6 +87,13 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) if( fullFileName == wxEmptyString ) return; + SetCurItem( NULL ); + + // To avoid issues with undo/redo lists (dangling pointers) + // clear the lists + // todo: use undo/redo feature + GetScreen()->ClearUndoRedoList(); + SPECCTRA_DB db; LOCALE_IO toggle; @@ -116,18 +117,24 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) OnModify(); GetBoard()->m_Status_Pcb = 0; - /* At this point we should call Compile_Ratsnest() - * but this could be time consumming. - * So if incorrect number of Connected and No connected pads is accepted - * until Compile_Ratsnest() is called (when track tool selected for instance) - * leave the next line commented - * Otherwise uncomment this line - */ - //Compile_Ratsnest( NULL, true ); + Compile_Ratsnest( NULL, true ); + GetBoard()->GetRatsnest()->ProcessBoard(); + + if( GetGalCanvas() ) // Update view: + { + auto view = GetGalCanvas()->GetView(); + + // Update footprint positions + view->RecacheAllItems(); + + // add imported tracks (previous tracks are removed, therfore all are new) + for( TRACK* track = GetBoard()->m_Track; track; track = track->Next() ) + view->Add( track ); + } SetStatusText( wxString( _( "Session file imported and merged OK." ) ) ); - m_canvas->Refresh( true ); + Refresh(); } @@ -488,14 +495,6 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IO_ERROR ) PATH* path = (PATH*) wire->shape; for( unsigned pt=0; ptpoints.size()-1; ++pt ) { - /* a debugging aid, may come in handy - if( path->points[pt].x == 547800 - && path->points[pt].y == -380250 ) - { - int breakhere = 1; - } - */ - TRACK* track = makeTRACK( path, pt, netoutCode ); aBoard->Add( track ); }