2015-04-25 22:26:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-23 17:26:32 +00:00
|
|
|
* Copyright (C) 2015-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-04-25 22:26:51 +00:00
|
|
|
*
|
|
|
|
* 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 Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2015-04-25 22:26:51 +00:00
|
|
|
#include <dialog_rescue_each_base.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
|
|
|
#include <invoke_sch_dialog.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2015-06-22 15:38:54 +00:00
|
|
|
#include <project_rescue.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <set>
|
2018-08-30 21:44:50 +00:00
|
|
|
#include <symbol_preview_widget.h>
|
2019-02-05 17:14:27 +00:00
|
|
|
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
class DIALOG_RESCUE_EACH: public DIALOG_RESCUE_EACH_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* This dialog asks the user which rescuable, cached parts he wants to rescue.
|
2017-10-22 00:48:25 +00:00
|
|
|
*
|
2015-04-25 22:26:51 +00:00
|
|
|
* Any rejects will be pruned from aCandidates.
|
2017-10-22 00:48:25 +00:00
|
|
|
*
|
2017-06-26 07:11:21 +00:00
|
|
|
* @param aParent - the SCH_EDIT_FRAME calling this
|
2015-06-22 15:38:54 +00:00
|
|
|
* @param aRescuer - the active RESCUER instance
|
2019-02-05 17:14:27 +00:00
|
|
|
* @param aCurrentSheet the current sheet in the schematic editor frame
|
|
|
|
* @param aGalBackEndType the current GAL type used to render symbols
|
2015-04-25 22:26:51 +00:00
|
|
|
* @param aAskShowAgain - if true, a "Never Show Again" button will be included
|
|
|
|
*/
|
2019-02-05 17:14:27 +00:00
|
|
|
DIALOG_RESCUE_EACH( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
|
|
|
|
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain );
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
~DIALOG_RESCUE_EACH();
|
|
|
|
|
|
|
|
private:
|
2018-09-15 07:00:13 +00:00
|
|
|
SYMBOL_PREVIEW_WIDGET* m_previewNewWidget;
|
|
|
|
SYMBOL_PREVIEW_WIDGET* m_previewOldWidget;
|
2015-06-22 15:38:54 +00:00
|
|
|
RESCUER* m_Rescuer;
|
2019-02-05 17:14:27 +00:00
|
|
|
SCH_SHEET_PATH* m_currentSheet;
|
2015-04-25 22:26:51 +00:00
|
|
|
bool m_AskShowAgain;
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
bool TransferDataToWindow() override;
|
|
|
|
bool TransferDataFromWindow() override;
|
2015-04-25 22:26:51 +00:00
|
|
|
void PopulateConflictList();
|
|
|
|
void PopulateInstanceList();
|
2018-08-30 21:44:50 +00:00
|
|
|
void OnConflictSelect( wxDataViewEvent& aEvent ) override;
|
|
|
|
void OnNeverShowClick( wxCommandEvent& aEvent ) override;
|
|
|
|
void OnCancelClick( wxCommandEvent& aEvent ) override;
|
2018-09-15 07:00:13 +00:00
|
|
|
|
|
|
|
// Display the 2 items (old in cache and new in library) corresponding to the
|
|
|
|
// selected conflict in m_ListOfConflicts
|
|
|
|
void displayItemsInConflict();
|
2015-04-25 22:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-02-05 17:14:27 +00:00
|
|
|
DIALOG_RESCUE_EACH::DIALOG_RESCUE_EACH( wxWindow* aParent,
|
|
|
|
RESCUER& aRescuer,
|
|
|
|
SCH_SHEET_PATH* aCurrentSheet,
|
|
|
|
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType,
|
2017-10-22 00:48:25 +00:00
|
|
|
bool aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
: DIALOG_RESCUE_EACH_BASE( aParent ),
|
2015-06-22 15:38:54 +00:00
|
|
|
m_Rescuer( &aRescuer ),
|
2019-02-05 17:14:27 +00:00
|
|
|
m_currentSheet( aCurrentSheet ),
|
2015-06-22 15:38:54 +00:00
|
|
|
m_AskShowAgain( aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2019-02-05 17:14:27 +00:00
|
|
|
wxASSERT( aCurrentSheet );
|
|
|
|
|
2023-03-09 17:41:18 +00:00
|
|
|
m_previewOldWidget = new SYMBOL_PREVIEW_WIDGET( m_previewOldPanel, &Kiway(), aGalBackEndType );
|
2018-09-15 07:00:13 +00:00
|
|
|
m_SizerOldPanel->Add( m_previewOldWidget, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
2023-03-09 17:41:18 +00:00
|
|
|
m_previewNewWidget = new SYMBOL_PREVIEW_WIDGET( m_previewNewPanel, &Kiway(), aGalBackEndType );
|
2018-09-15 07:00:13 +00:00
|
|
|
m_SizerNewPanel->Add( m_previewNewWidget, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
2015-05-13 15:09:55 +00:00
|
|
|
// Set the info message, customized to include the proper suffix.
|
2017-11-26 23:13:42 +00:00
|
|
|
wxString info =
|
|
|
|
_( "This schematic was made using older symbol libraries which may break the "
|
|
|
|
"schematic. Some symbols may need to be linked to a different symbol name. "
|
|
|
|
"Some symbols may need to be \"rescued\" (copied and renamed) into a new library.\n\n"
|
2015-06-29 16:31:00 +00:00
|
|
|
"The following changes are recommended to update the project." );
|
2017-11-26 23:13:42 +00:00
|
|
|
m_htmlPrompt->AppendToPage( info );
|
|
|
|
|
|
|
|
// wxDataViewListCtrl seems to do a poor job of laying itself out so help it along here.
|
|
|
|
wxString header = _( "Accept" );
|
|
|
|
wxFont font = m_ListOfConflicts->GetFont();
|
|
|
|
|
|
|
|
font.MakeBold();
|
|
|
|
|
|
|
|
wxClientDC dc( this );
|
|
|
|
|
|
|
|
dc.SetFont( font );
|
|
|
|
|
2022-10-13 14:36:39 +00:00
|
|
|
int width = dc.GetTextExtent( header ).GetWidth() * 1.25;
|
2017-11-26 23:13:42 +00:00
|
|
|
|
|
|
|
m_ListOfConflicts->AppendToggleColumn( header, wxDATAVIEW_CELL_ACTIVATABLE, width,
|
|
|
|
wxALIGN_CENTER );
|
|
|
|
|
|
|
|
header = _( "Symbol Name" );
|
2018-07-26 14:38:30 +00:00
|
|
|
width = dc.GetTextExtent( header ).GetWidth() * 2;
|
2017-11-26 23:13:42 +00:00
|
|
|
m_ListOfConflicts->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
|
|
|
|
|
|
|
|
header = _( "Action Taken" );
|
2018-07-26 14:38:30 +00:00
|
|
|
width = dc.GetTextExtent( header ).GetWidth() * 10;
|
2017-11-26 23:13:42 +00:00
|
|
|
m_ListOfConflicts->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
|
|
|
|
|
|
|
|
header = _( "Reference" );
|
2018-07-26 14:38:30 +00:00
|
|
|
width = dc.GetTextExtent( header ).GetWidth() * 2;
|
2017-11-26 23:13:42 +00:00
|
|
|
m_ListOfInstances->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
|
|
|
|
|
|
|
|
header = _( "Value" );
|
2018-07-26 14:38:30 +00:00
|
|
|
width = dc.GetTextExtent( header ).GetWidth() * 10;
|
2017-11-26 23:13:42 +00:00
|
|
|
m_ListOfInstances->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
|
2016-03-22 18:53:50 +00:00
|
|
|
|
2018-08-30 21:44:50 +00:00
|
|
|
m_previewOldWidget->SetLayoutDirection( wxLayout_LeftToRight );
|
|
|
|
m_previewNewWidget->SetLayoutDirection( wxLayout_LeftToRight );
|
2018-01-06 18:18:28 +00:00
|
|
|
|
|
|
|
// Make sure the HTML window is large enough. Some fun size juggling and
|
|
|
|
// fudge factors here but it does seem to work pretty reliably.
|
2021-11-16 19:39:58 +00:00
|
|
|
wxSize info_size = m_htmlPrompt->GetTextExtent( info );
|
|
|
|
wxSize prompt_size = m_htmlPrompt->GetSize();
|
|
|
|
wxSize font_size = m_htmlPrompt->GetTextExtent( "X" );
|
|
|
|
int approx_info_height = ( 2 * info_size.x / prompt_size.x ) * font_size.y;
|
2018-01-06 18:18:28 +00:00
|
|
|
m_htmlPrompt->SetSizeHints( 2 * prompt_size.x / 3, approx_info_height );
|
2021-11-16 19:39:58 +00:00
|
|
|
|
|
|
|
SetupStandardButtons();
|
2022-10-13 14:36:39 +00:00
|
|
|
m_stdButtonsOK->SetLabel( _( "Rescue Symbols" ) );
|
|
|
|
m_stdButtonsCancel->SetLabel( _( "Skip Symbol Rescue" ) );
|
|
|
|
m_stdButtons->Layout();
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2021-11-16 19:39:58 +00:00
|
|
|
|
2018-01-06 18:18:28 +00:00
|
|
|
Layout();
|
|
|
|
Center();
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_RESCUE_EACH::~DIALOG_RESCUE_EACH()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_RESCUE_EACH::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PopulateConflictList();
|
|
|
|
PopulateInstanceList();
|
|
|
|
|
|
|
|
if( !m_AskShowAgain )
|
|
|
|
m_btnNeverShowAgain->Hide();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::PopulateConflictList()
|
|
|
|
{
|
|
|
|
wxVector<wxVariant> data;
|
2022-10-13 14:36:39 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( RESCUE_CANDIDATE& each_candidate : m_Rescuer->m_all_candidates )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
|
|
|
data.clear();
|
|
|
|
data.push_back( wxVariant( true ) );
|
2015-06-22 15:38:54 +00:00
|
|
|
data.push_back( each_candidate.GetRequestedName() );
|
|
|
|
data.push_back( each_candidate.GetActionDescription() );
|
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
m_ListOfConflicts->AppendItem( data );
|
|
|
|
}
|
2017-03-27 12:44:47 +00:00
|
|
|
|
|
|
|
if( !m_Rescuer->m_all_candidates.empty() )
|
|
|
|
{
|
|
|
|
// Select the first choice
|
|
|
|
m_ListOfConflicts->SelectRow( 0 );
|
2022-10-13 14:36:39 +00:00
|
|
|
|
2018-09-15 07:00:13 +00:00
|
|
|
// Ensure this choice is displayed:
|
|
|
|
displayItemsInConflict();
|
2017-03-27 12:44:47 +00:00
|
|
|
}
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::PopulateInstanceList()
|
|
|
|
{
|
|
|
|
m_ListOfInstances->DeleteAllItems();
|
|
|
|
|
|
|
|
int row = m_ListOfConflicts->GetSelectedRow();
|
2015-04-27 08:44:17 +00:00
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
if( row == wxNOT_FOUND )
|
|
|
|
row = 0;
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
RESCUE_CANDIDATE& selected_part = m_Rescuer->m_all_candidates[row];
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
wxVector<wxVariant> data;
|
2017-03-09 18:16:24 +00:00
|
|
|
int count = 0;
|
2017-10-22 00:48:25 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_SYMBOL* eachSymbol : *m_Rescuer->GetSymbols() )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( eachSymbol->GetLibId().Format() != UTF8( selected_part.GetRequestedName() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* valueField = eachSymbol->GetField( VALUE_FIELD );
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
data.clear();
|
2021-06-10 14:10:55 +00:00
|
|
|
data.push_back( eachSymbol->GetRef( m_currentSheet ) );
|
2023-02-12 21:29:26 +00:00
|
|
|
data.push_back( valueField ? valueField->GetText() : wxString( wxT( "" ) ) );
|
2015-04-25 22:26:51 +00:00
|
|
|
m_ListOfInstances->AppendItem( data );
|
2017-03-09 18:16:24 +00:00
|
|
|
count++;
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
2017-03-09 18:16:24 +00:00
|
|
|
|
2018-08-30 21:44:50 +00:00
|
|
|
wxString msg = wxString::Format( _( "Instances of this symbol (%d items):" ), count );
|
|
|
|
m_titleInstances->SetLabelText( msg );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-15 07:00:13 +00:00
|
|
|
void DIALOG_RESCUE_EACH::displayItemsInConflict()
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2018-08-30 21:44:50 +00:00
|
|
|
int row = m_ListOfConflicts->GetSelectedRow();
|
|
|
|
|
|
|
|
if( row < 0 )
|
|
|
|
{
|
|
|
|
m_previewOldWidget->DisplayPart( nullptr, 0 );
|
|
|
|
m_previewNewWidget->DisplayPart( nullptr, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RESCUE_CANDIDATE& selected_part = m_Rescuer->m_all_candidates[row];
|
2020-04-02 00:17:25 +00:00
|
|
|
|
|
|
|
m_previewOldWidget->DisplayPart( selected_part.GetCacheCandidate(),
|
|
|
|
selected_part.GetUnit(),
|
|
|
|
selected_part.GetConvert() );
|
|
|
|
m_previewNewWidget->DisplayPart( selected_part.GetLibCandidate(),
|
|
|
|
selected_part.GetUnit(),
|
|
|
|
selected_part.GetConvert() );
|
2018-08-30 21:44:50 +00:00
|
|
|
}
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-15 07:00:13 +00:00
|
|
|
void DIALOG_RESCUE_EACH::OnConflictSelect( wxDataViewEvent& aEvent )
|
|
|
|
{
|
|
|
|
// wxformbuilder connects this event to the _dialog_, not the data view.
|
|
|
|
// Make sure the correct item triggered it, otherwise we trigger recursively
|
|
|
|
// and get a stack overflow.
|
|
|
|
if( aEvent.GetEventObject() != m_ListOfConflicts )
|
|
|
|
return;
|
|
|
|
|
|
|
|
PopulateInstanceList();
|
|
|
|
displayItemsInConflict();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
bool DIALOG_RESCUE_EACH::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
for( size_t index = 0; index < m_Rescuer->GetCandidateCount(); ++index )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
|
|
|
wxVariant val;
|
|
|
|
m_ListOfConflicts->GetValue( val, index, 0 );
|
|
|
|
bool rescue_part = val.GetBool();
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
if( rescue_part )
|
|
|
|
m_Rescuer->m_chosen_candidates.push_back( &m_Rescuer->m_all_candidates[index] );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
2022-10-13 14:36:39 +00:00
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnNeverShowClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2019-02-05 17:14:27 +00:00
|
|
|
wxMessageDialog dlg( GetParent(),
|
2022-10-13 14:36:39 +00:00
|
|
|
_( "Stop showing this tool?\n"
|
|
|
|
"No changes will be made.\n\n"
|
|
|
|
"This setting can be changed from the \"Symbol Libraries\" dialog,\n"
|
|
|
|
"and the tool can be activated manually from the \"Tools\" menu." ),
|
|
|
|
_( "Rescue Symbols" ), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
|
2015-04-25 22:26:51 +00:00
|
|
|
int resp = dlg.ShowModal ();
|
|
|
|
|
|
|
|
if( resp == wxID_YES )
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-29 16:42:24 +00:00
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
cfg->m_RescueNeverShow = true;
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
m_Rescuer->m_chosen_candidates.clear();
|
2015-04-25 22:26:51 +00:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnCancelClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2015-06-22 15:38:54 +00:00
|
|
|
m_Rescuer->m_chosen_candidates.clear();
|
2015-04-25 22:26:51 +00:00
|
|
|
DIALOG_RESCUE_EACH_BASE::OnCancelClick( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-05 17:14:27 +00:00
|
|
|
int InvokeDialogRescueEach( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
|
|
|
|
EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2019-02-05 17:14:27 +00:00
|
|
|
DIALOG_RESCUE_EACH dlg( aParent, aRescuer, aCurrentSheet, aGalBackEndType, aAskShowAgain );
|
|
|
|
return dlg.ShowQuasiModal();
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|