Decouple SCH_EDIT_FRAME from symbol rescue and remap dialogs.

Do not keep pointer to SCH_EDIT_FRAME in the rescuer object to prevent
it from creating dialogs with itself as the parent when call from the
rescue dialog which is itself a grandchild of the frame window.
This commit is contained in:
Wayne Stambaugh 2019-02-05 12:14:27 -05:00
parent 0c6ec7dbb3
commit 44cb979e91
6 changed files with 121 additions and 72 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2015-2019 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,6 +33,8 @@
#include <project_rescue.h> #include <project_rescue.h>
#include <eeschema_config.h> #include <eeschema_config.h>
#include <symbol_preview_widget.h> #include <symbol_preview_widget.h>
#include <class_draw_panel_gal.h>
class DIALOG_RESCUE_EACH: public DIALOG_RESCUE_EACH_BASE class DIALOG_RESCUE_EACH: public DIALOG_RESCUE_EACH_BASE
{ {
@ -44,18 +46,21 @@ public:
* *
* @param aParent - the SCH_EDIT_FRAME calling this * @param aParent - the SCH_EDIT_FRAME calling this
* @param aRescuer - the active RESCUER instance * @param aRescuer - the active RESCUER instance
* @param aCurrentSheet the current sheet in the schematic editor frame
* @param aGalBackEndType the current GAL type used to render symbols
* @param aAskShowAgain - if true, a "Never Show Again" button will be included * @param aAskShowAgain - if true, a "Never Show Again" button will be included
*/ */
DIALOG_RESCUE_EACH( SCH_EDIT_FRAME* aParent, RESCUER& aRescuer, bool aAskShowAgain ); DIALOG_RESCUE_EACH( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain );
~DIALOG_RESCUE_EACH(); ~DIALOG_RESCUE_EACH();
private: private:
SCH_EDIT_FRAME* m_Parent;
SYMBOL_PREVIEW_WIDGET* m_previewNewWidget; SYMBOL_PREVIEW_WIDGET* m_previewNewWidget;
SYMBOL_PREVIEW_WIDGET* m_previewOldWidget; SYMBOL_PREVIEW_WIDGET* m_previewOldWidget;
wxConfigBase* m_Config; wxConfigBase* m_Config;
RESCUER* m_Rescuer; RESCUER* m_Rescuer;
SCH_SHEET_PATH* m_currentSheet;
bool m_AskShowAgain; bool m_AskShowAgain;
bool TransferDataToWindow() override; bool TransferDataToWindow() override;
@ -72,17 +77,22 @@ private:
}; };
DIALOG_RESCUE_EACH::DIALOG_RESCUE_EACH( SCH_EDIT_FRAME* aParent, RESCUER& aRescuer, DIALOG_RESCUE_EACH::DIALOG_RESCUE_EACH( wxWindow* aParent,
RESCUER& aRescuer,
SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType,
bool aAskShowAgain ) bool aAskShowAgain )
: DIALOG_RESCUE_EACH_BASE( aParent ), : DIALOG_RESCUE_EACH_BASE( aParent ),
m_Parent( aParent ),
m_Rescuer( &aRescuer ), m_Rescuer( &aRescuer ),
m_currentSheet( aCurrentSheet ),
m_AskShowAgain( aAskShowAgain ) m_AskShowAgain( aAskShowAgain )
{ {
m_previewOldWidget = new SYMBOL_PREVIEW_WIDGET( m_previewOldPanel, Kiway(), m_Parent->GetGalCanvas()->GetBackend() ); wxASSERT( aCurrentSheet );
m_previewOldWidget = new SYMBOL_PREVIEW_WIDGET( m_previewOldPanel, Kiway(), aGalBackEndType );
m_SizerOldPanel->Add( m_previewOldWidget, 1, wxEXPAND | wxALL, 5 ); m_SizerOldPanel->Add( m_previewOldWidget, 1, wxEXPAND | wxALL, 5 );
m_previewNewWidget = new SYMBOL_PREVIEW_WIDGET( m_previewNewPanel, Kiway(), m_Parent->GetGalCanvas()->GetBackend() ); m_previewNewWidget = new SYMBOL_PREVIEW_WIDGET( m_previewNewPanel, Kiway(), aGalBackEndType );
m_SizerNewPanel->Add( m_previewNewWidget, 1, wxEXPAND | wxALL, 5 ); m_SizerNewPanel->Add( m_previewNewWidget, 1, wxEXPAND | wxALL, 5 );
m_Config = Kiface().KifaceSettings(); m_Config = Kiface().KifaceSettings();
@ -212,7 +222,7 @@ void DIALOG_RESCUE_EACH::PopulateInstanceList()
SCH_FIELD* valueField = each_component->GetField( 1 ); SCH_FIELD* valueField = each_component->GetField( 1 );
data.clear(); data.clear();
data.push_back( each_component->GetRef( & m_Parent->GetCurrentSheet() ) ); data.push_back( each_component->GetRef( m_currentSheet ) );
data.push_back( valueField ? valueField->GetText() : wxT( "" ) ); data.push_back( valueField ? valueField->GetText() : wxT( "" ) );
m_ListOfInstances->AppendItem( data ); m_ListOfInstances->AppendItem( data );
count++; count++;
@ -274,7 +284,7 @@ bool DIALOG_RESCUE_EACH::TransferDataFromWindow()
void DIALOG_RESCUE_EACH::OnNeverShowClick( wxCommandEvent& aEvent ) void DIALOG_RESCUE_EACH::OnNeverShowClick( wxCommandEvent& aEvent )
{ {
wxMessageDialog dlg( m_Parent, wxMessageDialog dlg( GetParent(),
_( "Stop showing this tool?\n" _( "Stop showing this tool?\n"
"No changes will be made.\n\n" "No changes will be made.\n\n"
"This setting can be changed from the \"Symbol Libraries\" dialog,\n" "This setting can be changed from the \"Symbol Libraries\" dialog,\n"
@ -298,8 +308,9 @@ void DIALOG_RESCUE_EACH::OnCancelClick( wxCommandEvent& aEvent )
} }
int InvokeDialogRescueEach( SCH_EDIT_FRAME* aCaller, RESCUER& aRescuer, bool aAskShowAgain ) int InvokeDialogRescueEach( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain )
{ {
DIALOG_RESCUE_EACH dlg( aCaller, aRescuer, aAskShowAgain ); DIALOG_RESCUE_EACH dlg( aParent, aRescuer, aCurrentSheet, aGalBackEndType, aAskShowAgain );
return dlg.ShowModal(); return dlg.ShowQuasiModal();
} }

View File

@ -6,7 +6,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2017-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2019 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -32,12 +32,14 @@
#include <wx_html_report_panel.h> #include <wx_html_report_panel.h>
#include <class_library.h> #include <class_library.h>
#include <project_rescue.h>
#include <sch_io_mgr.h> #include <sch_io_mgr.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_component.h> #include <sch_component.h>
#include <sch_screen.h> #include <sch_screen.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <viewlib_frame.h>
#include <env_paths.h> #include <env_paths.h>
#include <dialog_symbol_remap.h> #include <dialog_symbol_remap.h>
@ -85,7 +87,21 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
// Ignore the never show rescue setting for one last rescue of legacy symbol // Ignore the never show rescue setting for one last rescue of legacy symbol
// libraries before remapping to the symbol library table. This ensures the // libraries before remapping to the symbol library table. This ensures the
// best remapping results. // best remapping results.
parent->RescueLegacyProject( false ); LEGACY_RESCUER rescuer( Prj(), &parent->GetCurrentSheet(),
parent->GetGalCanvas()->GetBackend() );
if( RESCUER::RescueProject( this, rescuer, false ) )
{
LIB_VIEW_FRAME* viewer = (LIB_VIEW_FRAME*) parent->Kiway().Player( FRAME_SCH_VIEWER, false );
if( viewer )
viewer->ReCreateListLib();
parent->GetScreen()->ClearUndoORRedoList( parent->GetScreen()->m_UndoList, 1 );
parent->SyncView();
parent->GetCanvas()->Refresh();
parent->OnModify();
}
// The schematic is fully loaded, any legacy library symbols have been rescued. Now // The schematic is fully loaded, any legacy library symbols have been rescued. Now
// check to see if the schematic has not been converted to the symbol library table // check to see if the schematic has not been converted to the symbol library table

View File

@ -4,7 +4,7 @@
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2013 CERN (www.cern.ch) * Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License

View File

@ -1,9 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2013-2017 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2013-2019 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -43,12 +42,14 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <list> #include <list>
#include <class_draw_panel_gal.h>
class wxFrame; class wxFrame;
class wxDialog; class wxDialog;
class LIB_PART; class LIB_PART;
class PART_LIBS; class PART_LIBS;
class SCH_COMPONENT; class SCH_COMPONENT;
class SCH_SHEET_PATH;
class RESCUER; class RESCUER;
// Often this is not used in the prototypes, since wxFrame is good enough and would // Often this is not used in the prototypes, since wxFrame is good enough and would
@ -56,14 +57,17 @@ class RESCUER;
class SCH_EDIT_FRAME; class SCH_EDIT_FRAME;
/** /**
* Function InvokeDialogRescueEach
* This dialog asks the user which rescuable, cached parts he wants to rescue. * This dialog asks the user which rescuable, cached parts he wants to rescue.
* Any rejects will be pruned from aCandidates. * Any rejects will be pruned from \a aCandidates.
* @param aCaller - the SCH_EDIT_FRAME calling this *
* @param aParent - the wxWindow object calling this dialog
* @param aRescuer - the active RESCUER instance * @param aRescuer - the active RESCUER instance
* @param aCurrentSheet the current sheet in the schematic editor frame
* @param aGalBackEndType the current GAL type used to render symbols
* @param aAskShowAgain - if true, a "Never Show Again" button will be included * @param aAskShowAgain - if true, a "Never Show Again" button will be included
*/ */
int InvokeDialogRescueEach( SCH_EDIT_FRAME* aCaller, RESCUER& aRescuer, bool aAskShowAgain ); int InvokeDialogRescueEach( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain );
/// Create the modeless DIALOG_ERC and show it, return something to /// Create the modeless DIALOG_ERC and show it, return something to
/// destroy or close it. The dialog will have ID_DIALOG_ERC from id.h /// destroy or close it. The dialog will have ID_DIALOG_ERC from id.h
@ -82,9 +86,9 @@ int InvokeDialogUpdateFields( SCH_EDIT_FRAME* aCaller,
const std::list<SCH_COMPONENT*> aComponents, bool aCreateUndoEntry ); const std::list<SCH_COMPONENT*> aComponents, bool aCreateUndoEntry );
/** /**
* Function InvokeDialogNetList * Create and shows NETLIST_DIALOG and returns whatever
* creates and shows NETLIST_DIALOG and returns whatever
* NETLIST_DIALOG::ShowModal() returns. * NETLIST_DIALOG::ShowModal() returns.
*
* @param int - NET_PLUGIN_CHANGE means user added or deleted a plugin, * @param int - NET_PLUGIN_CHANGE means user added or deleted a plugin,
* wxID_OK, or wxID_CANCEL. * wxID_OK, or wxID_CANCEL.
*/ */

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015 Chris Pavlina <pavlina.chris@gmail.com> * Copyright (C) 2015 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2015-2018 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2015-2019 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -378,7 +378,7 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(), cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
true ); true );
lib_match = aRescuer.GetFrame()->GetLibPart( part_id ); lib_match = SchGetLibPart( part_id, aRescuer.GetPrj()->SchSymbolLibTable() );
if( !cache_match && !lib_match ) if( !cache_match && !lib_match )
continue; continue;
@ -464,11 +464,13 @@ bool RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction( RESCUER* aRescuer )
} }
RESCUER::RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject ) RESCUER::RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType )
{ {
get_components( m_components ); get_components( m_components );
m_prj = &aProject; m_prj = &aProject;
m_edit_frame = &aEditFrame; m_currentSheet = aCurrentSheet;
m_galBackEndType = aGalBackEndType;
} }
@ -510,7 +512,7 @@ void RESCUER::UndoRescues()
bool SCH_EDIT_FRAME::RescueLegacyProject( bool aRunningOnDemand ) bool SCH_EDIT_FRAME::RescueLegacyProject( bool aRunningOnDemand )
{ {
LEGACY_RESCUER rescuer( *this, Prj() ); LEGACY_RESCUER rescuer( Prj(), &GetCurrentSheet(), GetGalCanvas()->GetBackend() );
return rescueProject( rescuer, aRunningOnDemand ); return rescueProject( rescuer, aRunningOnDemand );
} }
@ -518,21 +520,40 @@ bool SCH_EDIT_FRAME::RescueLegacyProject( bool aRunningOnDemand )
bool SCH_EDIT_FRAME::RescueSymbolLibTableProject( bool aRunningOnDemand ) bool SCH_EDIT_FRAME::RescueSymbolLibTableProject( bool aRunningOnDemand )
{ {
SYMBOL_LIB_TABLE_RESCUER rescuer( *this, Prj() ); SYMBOL_LIB_TABLE_RESCUER rescuer( Prj(), &GetCurrentSheet(), GetGalCanvas()->GetBackend() );
return rescueProject( rescuer, aRunningOnDemand ); return rescueProject( rescuer, aRunningOnDemand );
} }
bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ) bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
{
if( !RESCUER::RescueProject( this, aRescuer, aRunningOnDemand ) )
return false;
LIB_VIEW_FRAME* viewer = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
if( viewer )
viewer->ReCreateListLib();
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
SyncView();
GetCanvas()->Refresh();
OnModify();
return true;
}
bool RESCUER::RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand )
{ {
aRescuer.FindCandidates(); aRescuer.FindCandidates();
if( ! aRescuer.GetCandidateCount() ) if( !aRescuer.GetCandidateCount() )
{ {
if( aRunningOnDemand ) if( aRunningOnDemand )
{ {
wxMessageDialog dlg( this, _( "This project has nothing to rescue." ), wxMessageDialog dlg( aParent, _( "This project has nothing to rescue." ),
_( "Project Rescue Helper" ) ); _( "Project Rescue Helper" ) );
dlg.ShowModal(); dlg.ShowModal();
} }
@ -541,20 +562,18 @@ bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
} }
aRescuer.RemoveDuplicates(); aRescuer.RemoveDuplicates();
aRescuer.InvokeDialog( aParent, !aRunningOnDemand );
aRescuer.InvokeDialog( !aRunningOnDemand );
// If no symbols were rescued, let the user know what's going on. He might // If no symbols were rescued, let the user know what's going on. He might
// have clicked cancel by mistake, and should have some indication of that. // have clicked cancel by mistake, and should have some indication of that.
if( !aRescuer.GetChosenCandidateCount() ) if( !aRescuer.GetChosenCandidateCount() )
{ {
wxMessageDialog dlg( this, _( "No symbols were rescued." ), wxMessageDialog dlg( aParent, _( "No symbols were rescued." ),
_( "Project Rescue Helper" ) ); _( "Project Rescue Helper" ) );
dlg.ShowModal(); dlg.ShowModal();
// Set the modified flag even on Cancel. Many users seem to instinctively want to Save at // Set the modified flag even on Cancel. Many users seem to instinctively want to Save at
// this point, due to the reloading of the symbols, so we'll make the save button active. // this point, due to the reloading of the symbols, so we'll make the save button active.
OnModify();
return true; return true;
} }
@ -566,17 +585,7 @@ bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
return false; return false;
} }
aRescuer.WriteRescueLibrary( this ); aRescuer.WriteRescueLibrary( aParent );
LIB_VIEW_FRAME* viewer = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
if( viewer )
viewer->ReCreateListLib();
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
SyncView();
GetCanvas()->Refresh();
OnModify();
return true; return true;
} }
@ -620,9 +629,10 @@ void LEGACY_RESCUER::FindCandidates()
} }
void LEGACY_RESCUER::InvokeDialog( bool aAskShowAgain ) void LEGACY_RESCUER::InvokeDialog( wxWindow* aParent, bool aAskShowAgain )
{ {
InvokeDialogRescueEach( m_edit_frame, static_cast< RESCUER& >( *this ), aAskShowAgain ); InvokeDialogRescueEach( aParent, static_cast< RESCUER& >( *this ), m_currentSheet,
m_galBackEndType, aAskShowAgain );
} }
@ -658,7 +668,7 @@ void LEGACY_RESCUER::OpenRescueLibrary()
} }
bool LEGACY_RESCUER::WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) bool LEGACY_RESCUER::WriteRescueLibrary( wxWindow *aParent )
{ {
try try
{ {
@ -670,7 +680,7 @@ bool LEGACY_RESCUER::WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame )
msg.Printf( _( "Failed to create symbol library file \"%s\"" ), msg.Printf( _( "Failed to create symbol library file \"%s\"" ),
m_rescue_lib->GetFullFileName() ); m_rescue_lib->GetFullFileName() );
DisplayError( aEditFrame, msg ); DisplayError( aParent, msg );
return false; return false;
} }
@ -750,9 +760,10 @@ void LEGACY_RESCUER::AddPart( LIB_PART* aNewPart )
} }
SYMBOL_LIB_TABLE_RESCUER::SYMBOL_LIB_TABLE_RESCUER( SCH_EDIT_FRAME& aEditFrame, SYMBOL_LIB_TABLE_RESCUER::SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject,
PROJECT& aProject ) : SCH_SHEET_PATH* aCurrentSheet,
RESCUER( aEditFrame, aProject ) EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
RESCUER( aProject, aCurrentSheet, aGalBackEndType )
{ {
m_properties = std::make_unique<PROPERTIES>(); m_properties = std::make_unique<PROPERTIES>();
} }
@ -764,9 +775,10 @@ void SYMBOL_LIB_TABLE_RESCUER::FindCandidates()
} }
void SYMBOL_LIB_TABLE_RESCUER::InvokeDialog( bool aAskShowAgain ) void SYMBOL_LIB_TABLE_RESCUER::InvokeDialog( wxWindow* aParent, bool aAskShowAgain )
{ {
InvokeDialogRescueEach( m_edit_frame, static_cast< RESCUER& >( *this ), aAskShowAgain ); InvokeDialogRescueEach( aParent, static_cast< RESCUER& >( *this ), m_currentSheet,
m_galBackEndType, aAskShowAgain );
} }
@ -777,7 +789,7 @@ void SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary()
} }
bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent )
{ {
wxString msg; wxString msg;
wxFileName fn = GetRescueLibraryFileName(); wxFileName fn = GetRescueLibraryFileName();
@ -793,7 +805,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame )
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg.Printf( _( "Failed to save rescue library %s." ), fn.GetFullPath() ); msg.Printf( _( "Failed to save rescue library %s." ), fn.GetFullPath() );
DisplayErrorMessage( aEditFrame, msg, ioe.What() ); DisplayErrorMessage( aParent, msg, ioe.What() );
return false; return false;
} }
@ -817,7 +829,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame )
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg.Printf( _( "Error occurred saving project specific symbol library table." ) ); msg.Printf( _( "Error occurred saving project specific symbol library table." ) );
DisplayErrorMessage( aEditFrame, msg, ioe.What() ); DisplayErrorMessage( aParent, msg, ioe.What() );
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015 Chris Pavlina <pavlina.chris@gmail.com> * Copyright (C) 2015 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2015-2017 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2015-2019 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -45,6 +45,7 @@
#include <class_libentry.h> #include <class_libentry.h>
#include <sch_legacy_plugin.h> #include <sch_legacy_plugin.h>
#include <class_draw_panel_gal.h>
class LIB_PART; class LIB_PART;
@ -52,6 +53,7 @@ class SCH_COMPONENT;
class RESCUER; class RESCUER;
class SCH_EDIT_FRAME; class SCH_EDIT_FRAME;
class SCH_LEGACY_PLUGIN; class SCH_LEGACY_PLUGIN;
class SCH_SHEET_PATH;
enum RESCUE_TYPE enum RESCUE_TYPE
@ -219,7 +221,8 @@ protected:
std::vector<SCH_COMPONENT*> m_components; std::vector<SCH_COMPONENT*> m_components;
PROJECT* m_prj; PROJECT* m_prj;
SCH_EDIT_FRAME* m_edit_frame; EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType;
SCH_SHEET_PATH* m_currentSheet;
boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates; boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
std::vector<RESCUE_CANDIDATE*> m_chosen_candidates; std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
@ -227,7 +230,8 @@ protected:
std::vector<RESCUE_LOG> m_rescue_log; std::vector<RESCUE_LOG> m_rescue_log;
public: public:
RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject ); RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
/** /**
* Writes out the rescue library. Called after successful PerformAction()s. If this fails, * Writes out the rescue library. Called after successful PerformAction()s. If this fails,
@ -235,7 +239,7 @@ public:
* *
* @return True on success. * @return True on success.
*/ */
virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) = 0; virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
virtual void OpenRescueLibrary() = 0; virtual void OpenRescueLibrary() = 0;
@ -251,9 +255,7 @@ public:
* *
* @param aAskShowAgain - whether the "Never Show Again" button should be visible * @param aAskShowAgain - whether the "Never Show Again" button should be visible
*/ */
virtual void InvokeDialog( bool aAskShowAgain ) = 0; virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
SCH_EDIT_FRAME* GetFrame() { return m_edit_frame; }
/** /**
* Filter out duplicately named rescue candidates. * Filter out duplicately named rescue candidates.
@ -297,6 +299,8 @@ public:
* Reverse the effects of all rescues on the project. * Reverse the effects of all rescues on the project.
*/ */
void UndoRescues(); void UndoRescues();
static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
}; };
@ -306,18 +310,19 @@ private:
std::unique_ptr<PART_LIB> m_rescue_lib; std::unique_ptr<PART_LIB> m_rescue_lib;
public: public:
LEGACY_RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject ) : LEGACY_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
RESCUER( aEditFrame, aProject ) EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
RESCUER( aProject, aCurrentSheet, aGalBackEndType )
{ {
} }
virtual void FindCandidates() override; virtual void FindCandidates() override;
virtual void InvokeDialog( bool aAskShowAgain ) override; virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
virtual void OpenRescueLibrary() override; virtual void OpenRescueLibrary() override;
virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) override; virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
virtual void AddPart( LIB_PART* aNewPart ) override; virtual void AddPart( LIB_PART* aNewPart ) override;
}; };
@ -331,15 +336,16 @@ private:
std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties
public: public:
SYMBOL_LIB_TABLE_RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject ); SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
virtual void FindCandidates() override; virtual void FindCandidates() override;
virtual void InvokeDialog( bool aAskShowAgain ) override; virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
virtual void OpenRescueLibrary() override; virtual void OpenRescueLibrary() override;
virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) override; virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
virtual void AddPart( LIB_PART* aNewPart ) override; virtual void AddPart( LIB_PART* aNewPart ) override;
}; };