2015-04-25 22:26:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-09-30 05:31:48 +00:00
|
|
|
* Copyright (C) 2015-2016 Chris Pavlina <pavlina.chris@gmail.com>
|
2017-01-31 01:31:19 +00:00
|
|
|
* Copyright (C) 2015-2017 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <schframe.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <invoke_sch_dialog.h>
|
|
|
|
#include <dialog_rescue_each_base.h>
|
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2015-06-22 15:38:54 +00:00
|
|
|
#include <project_rescue.h>
|
2015-04-27 08:44:17 +00:00
|
|
|
#include <eeschema_config.h>
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
class DIALOG_RESCUE_EACH: public DIALOG_RESCUE_EACH_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* This dialog asks the user which rescuable, cached parts he wants to rescue.
|
|
|
|
* Any rejects will be pruned from aCandidates.
|
|
|
|
* @param aCaller - the SCH_EDIT_FRAME calling this
|
2015-06-22 15:38:54 +00:00
|
|
|
* @param aRescuer - the active RESCUER instance
|
2015-04-25 22:26:51 +00:00
|
|
|
* @param aAskShowAgain - if true, a "Never Show Again" button will be included
|
|
|
|
*/
|
2015-06-22 15:38:54 +00:00
|
|
|
DIALOG_RESCUE_EACH( SCH_EDIT_FRAME* aParent, RESCUER& aRescuer, bool aAskShowAgain );
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
~DIALOG_RESCUE_EACH();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SCH_EDIT_FRAME* m_Parent;
|
|
|
|
wxConfigBase* m_Config;
|
2015-06-22 15:38:54 +00:00
|
|
|
RESCUER* m_Rescuer;
|
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();
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnConflictSelect( wxDataViewEvent& event ) override;
|
|
|
|
void OnNeverShowClick( wxCommandEvent& event ) override;
|
|
|
|
void OnCancelClick( wxCommandEvent& event ) override;
|
|
|
|
void OnHandleCachePreviewRepaint( wxPaintEvent& aRepaintEvent ) override;
|
|
|
|
void OnHandleLibraryPreviewRepaint( wxPaintEvent& aRepaintEvent ) override;
|
|
|
|
void OnDialogResize( wxSizeEvent& aSizeEvent ) override;
|
2015-04-25 22:26:51 +00:00
|
|
|
void renderPreview( LIB_PART* aComponent, int aUnit, wxPanel* panel );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
DIALOG_RESCUE_EACH::DIALOG_RESCUE_EACH( SCH_EDIT_FRAME* aParent, RESCUER& aRescuer,
|
|
|
|
bool aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
: DIALOG_RESCUE_EACH_BASE( aParent ),
|
|
|
|
m_Parent( aParent ),
|
2015-06-22 15:38:54 +00:00
|
|
|
m_Rescuer( &aRescuer ),
|
|
|
|
m_AskShowAgain( aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2015-04-27 08:44:17 +00:00
|
|
|
m_Config = Kiface().KifaceSettings();
|
2015-05-04 07:35:17 +00:00
|
|
|
m_stdButtonsOK->SetDefault();
|
2015-05-13 15:09:55 +00:00
|
|
|
|
|
|
|
// Set the info message, customized to include the proper suffix.
|
2015-06-22 15:38:54 +00:00
|
|
|
wxString info_message =
|
|
|
|
_( "It looks like this project was made using older schematic component libraries.\n"
|
|
|
|
"Some parts may need to be relinked to a different symbol name, and some symbols\n"
|
2015-06-29 16:31:00 +00:00
|
|
|
"may need to be \"rescued\" (cloned and renamed) into a new library.\n"
|
|
|
|
"\n"
|
|
|
|
"The following changes are recommended to update the project." );
|
2015-05-13 15:09:55 +00:00
|
|
|
m_lblInfo->SetLabel( info_message );
|
2016-03-22 18:53:50 +00:00
|
|
|
|
|
|
|
m_componentViewOld->SetLayoutDirection( wxLayout_LeftToRight );
|
2016-03-23 01:35:44 +00:00
|
|
|
m_componentViewNew->SetLayoutDirection( wxLayout_LeftToRight );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_RESCUE_EACH::~DIALOG_RESCUE_EACH()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_RESCUE_EACH::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
m_ListOfConflicts->AppendToggleColumn( _( "Accept" ) );
|
|
|
|
m_ListOfConflicts->AppendTextColumn( _( "Symbol" ) );
|
|
|
|
m_ListOfConflicts->AppendTextColumn( _( "Action" ) );
|
2015-05-04 07:35:17 +00:00
|
|
|
m_ListOfInstances->AppendTextColumn( _( "Reference" ) );
|
|
|
|
m_ListOfInstances->AppendTextColumn( _( "Value" ) );
|
2015-04-25 22:26:51 +00:00
|
|
|
PopulateConflictList();
|
|
|
|
PopulateInstanceList();
|
|
|
|
|
|
|
|
if( !m_AskShowAgain )
|
|
|
|
m_btnNeverShowAgain->Hide();
|
|
|
|
|
|
|
|
GetSizer()->Layout();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::PopulateConflictList()
|
|
|
|
{
|
|
|
|
wxVector<wxVariant> data;
|
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 );
|
|
|
|
}
|
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;
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_COMPONENT* each_component : *m_Rescuer->GetComponents() )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2017-03-25 01:18:16 +00:00
|
|
|
if( each_component->GetLibId().Format() != TO_UTF8( selected_part.GetRequestedName() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_FIELD* valueField = each_component->GetField( 1 );
|
|
|
|
|
|
|
|
data.clear();
|
2016-02-15 20:17:51 +00:00
|
|
|
data.push_back( each_component->GetRef( & m_Parent->GetCurrentSheet() ) );
|
2015-05-04 07:35:17 +00:00
|
|
|
data.push_back( valueField ? valueField->GetText() : 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
|
|
|
|
|
|
|
m_titleInstances->SetLabelText( wxString::Format(
|
|
|
|
_( "Instances of this symbol (%d items):" ), count ) );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnHandleCachePreviewRepaint( wxPaintEvent& aRepaintEvent )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
if( selected_part.GetCacheCandidate() )
|
|
|
|
renderPreview( selected_part.GetCacheCandidate(), 0, m_componentViewOld );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnHandleLibraryPreviewRepaint( wxPaintEvent& aRepaintEvent )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
if( selected_part.GetLibCandidate() )
|
|
|
|
renderPreview( selected_part.GetLibCandidate(), 0, m_componentViewNew );
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnDialogResize( wxSizeEvent& aSizeEvent )
|
|
|
|
{
|
|
|
|
// Placeholer - I was previously doing some extra reflow here.
|
|
|
|
DIALOG_RESCUE_EACH_BASE::OnDialogResize( aSizeEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Render the preview in our m_componentView. If this gets more complicated, we should
|
|
|
|
// probably have a derived class from wxPanel; but this keeps things local.
|
2015-04-27 08:44:17 +00:00
|
|
|
// Call it only from a Paint Event, because we are using a wxPaintDC to draw the component
|
2015-04-25 22:26:51 +00:00
|
|
|
void DIALOG_RESCUE_EACH::renderPreview( LIB_PART* aComponent, int aUnit, wxPanel* aPanel )
|
|
|
|
{
|
|
|
|
wxPaintDC dc( aPanel );
|
2017-02-20 16:57:41 +00:00
|
|
|
wxColour bgColor = m_Parent->GetDrawBgColor().ToColour();
|
2015-04-25 22:26:51 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
dc.SetBackground( wxBrush( bgColor ) );
|
2015-04-25 22:26:51 +00:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
if( aComponent == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aUnit <= 0 )
|
|
|
|
aUnit = 1;
|
|
|
|
|
|
|
|
const wxSize dc_size = dc.GetSize();
|
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Find joint bounding box for everything we are about to draw.
|
2016-09-30 05:31:48 +00:00
|
|
|
EDA_RECT bBox = aComponent->GetUnitBoundingBox( aUnit, /* deMorganConvert */ 1 );
|
2015-04-25 22:26:51 +00:00
|
|
|
const double xscale = (double) dc_size.x / bBox.GetWidth();
|
|
|
|
const double yscale = (double) dc_size.y / bBox.GetHeight();
|
|
|
|
const double scale = std::min( xscale, yscale ) * 0.85;
|
|
|
|
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
|
2015-04-27 08:44:17 +00:00
|
|
|
wxPoint offset = - bBox.Centre();
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
// Avoid rendering when either dimension is zero
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
dc.GetSize( &width, &height );
|
|
|
|
if( !width || !height )
|
|
|
|
return;
|
|
|
|
|
2017-02-19 18:40:26 +00:00
|
|
|
aComponent->Draw( NULL, &dc, offset, aUnit, 1, PART_DRAW_OPTIONS::Default() );
|
2015-04-25 22:26:51 +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.
|
2015-04-27 08:44:17 +00:00
|
|
|
if( aEvent.GetEventObject() != m_ListOfConflicts )
|
|
|
|
return;
|
2015-04-25 22:26:51 +00:00
|
|
|
|
|
|
|
PopulateInstanceList();
|
|
|
|
|
2015-04-27 08:44:17 +00:00
|
|
|
m_componentViewOld->Refresh();
|
|
|
|
m_componentViewNew->Refresh();
|
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
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_RESCUE_EACH::OnNeverShowClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2015-04-28 15:07:36 +00:00
|
|
|
wxMessageDialog dlg( m_Parent,
|
|
|
|
_( "Stop showing this tool?\n"
|
|
|
|
"No changes will be made.\n\n"
|
|
|
|
"This setting can be changed from the \"Component Libraries\" dialog,\n"
|
|
|
|
"and the tool can be activated manually from the \"Tools\" menu." ),
|
|
|
|
_( "Rescue Components" ), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
|
2015-04-25 22:26:51 +00:00
|
|
|
int resp = dlg.ShowModal ();
|
|
|
|
|
|
|
|
if( resp == wxID_YES )
|
|
|
|
{
|
2016-05-12 19:45:47 +00:00
|
|
|
m_Config->Write( RescueNeverShowEntry, 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-22 15:38:54 +00:00
|
|
|
int InvokeDialogRescueEach( SCH_EDIT_FRAME* aCaller, RESCUER& aRescuer, bool aAskShowAgain )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
2015-06-22 15:38:54 +00:00
|
|
|
DIALOG_RESCUE_EACH dlg( aCaller, aRescuer, aAskShowAgain );
|
2015-04-25 22:26:51 +00:00
|
|
|
return dlg.ShowModal();
|
|
|
|
}
|