KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_rescue_each.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <symbol_library.h>
27#include <eeschema_settings.h>
28#include <invoke_sch_dialog.h>
29#include <kiface_base.h>
30#include <project_rescue.h>
31#include <sch_symbol.h>
32#include <sch_edit_frame.h>
33#include <set>
35
36#include <wx/msgdlg.h>
37#include <wx/dcclient.h>
38
39
41{
42public:
54 DIALOG_RESCUE_EACH( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
55 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain );
57
58private:
59 bool TransferDataToWindow() override;
60 bool TransferDataFromWindow() override;
63 void OnConflictSelect( wxDataViewEvent& aEvent ) override;
64 void OnNeverShowClick( wxCommandEvent& aEvent ) override;
65 void OnCancelClick( wxCommandEvent& aEvent ) override;
66
67 // Display the 2 items (old in cache and new in library) corresponding to the
68 // selected conflict in m_ListOfConflicts
70
71private:
77};
78
79
80DIALOG_RESCUE_EACH::DIALOG_RESCUE_EACH( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
81 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain ) :
82 DIALOG_RESCUE_EACH_BASE( aParent ),
83 m_rescuer( &aRescuer ),
84 m_currentSheet( aCurrentSheet ),
85 m_askShowAgain( aAskShowAgain )
86{
87 wxASSERT( aCurrentSheet );
88
89 m_previewOldWidget = new SYMBOL_PREVIEW_WIDGET( m_previewOldPanel, &Kiway(), false, aGalBackEndType );
90 m_SizerOldPanel->Add( m_previewOldWidget, 1, wxEXPAND | wxALL, 5 );
91
92 m_previewNewWidget = new SYMBOL_PREVIEW_WIDGET( m_previewNewPanel, &Kiway(), false, aGalBackEndType );
93 m_SizerNewPanel->Add( m_previewNewWidget, 1, wxEXPAND | wxALL, 5 );
94
95 // Set the info message, customized to include the proper suffix.
96 wxString info = _( "This schematic was made using older symbol libraries which may break the "
97 "schematic. Some symbols may need to be linked to a different symbol name. "
98 "Some symbols may need to be \"rescued\" (copied and renamed) into a new library.\n\n"
99 "The following changes are recommended to update the project." );
101
102 // wxDataViewListCtrl seems to do a poor job of laying itself out so help it along here.
103 wxString header = _( "Accept" );
104 wxFont font = m_ListOfConflicts->GetFont();
105
106 font.MakeBold();
107
108 wxClientDC dc( this );
109
110 dc.SetFont( font );
111
112 int width = dc.GetTextExtent( header ).GetWidth() * 1.25;
113
114 m_ListOfConflicts->AppendToggleColumn( header, wxDATAVIEW_CELL_ACTIVATABLE, width, wxALIGN_CENTER );
115
116 header = _( "Symbol Name" );
117 width = dc.GetTextExtent( header ).GetWidth() * 2;
118 m_ListOfConflicts->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
119
120 header = _( "Action Taken" );
121 width = dc.GetTextExtent( header ).GetWidth() * 10;
122 m_ListOfConflicts->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
123
124 header = _( "Reference" );
125 width = dc.GetTextExtent( header ).GetWidth() * 2;
126 m_ListOfInstances->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
127
128 header = _( "Value" );
129 width = dc.GetTextExtent( header ).GetWidth() * 10;
130 m_ListOfInstances->AppendTextColumn( header, wxDATAVIEW_CELL_INERT, width );
131
132 m_previewOldWidget->SetLayoutDirection( wxLayout_LeftToRight );
133 m_previewNewWidget->SetLayoutDirection( wxLayout_LeftToRight );
134
135 // Make sure the HTML window is large enough. Some fun size juggling and
136 // fudge factors here but it does seem to work pretty reliably.
137 wxSize info_size = m_htmlPrompt->GetTextExtent( info );
138 wxSize prompt_size = m_htmlPrompt->GetSize();
139 wxSize font_size = m_htmlPrompt->GetTextExtent( "X" );
140 int approx_info_height = ( 2 * info_size.x / prompt_size.x ) * font_size.y;
141 m_htmlPrompt->SetSizeHints( 2 * prompt_size.x / 3, approx_info_height );
142
144 m_stdButtonsOK->SetLabel( _( "Rescue Symbols" ) );
145 m_stdButtonsCancel->SetLabel( _( "Skip Symbol Rescue" ) );
146 m_stdButtons->Layout();
147 GetSizer()->SetSizeHints( this );
148
149 Layout();
150 Center();
151}
152
153
155{
156 if( !wxDialog::TransferDataToWindow() )
157 return false;
158
161
162 if( !m_askShowAgain )
163 m_btnNeverShowAgain->Hide();
164
165 return true;
166}
167
168
170{
171 wxVector<wxVariant> data;
172
173 for( RESCUE_CANDIDATE& each_candidate : m_rescuer->m_all_candidates )
174 {
175 data.clear();
176 data.push_back( wxVariant( true ) );
177 data.push_back( each_candidate.GetRequestedName() );
178 data.push_back( each_candidate.GetActionDescription() );
179
180 m_ListOfConflicts->AppendItem( data );
181 }
182
183 if( !m_rescuer->m_all_candidates.empty() )
184 {
185 // Select the first choice
186 m_ListOfConflicts->SelectRow( 0 );
187
188 // Ensure this choice is displayed:
190 }
191}
192
193
195{
196 m_ListOfInstances->DeleteAllItems();
197
198 int row = m_ListOfConflicts->GetSelectedRow();
199
200 if( row == wxNOT_FOUND )
201 row = 0;
202
203 RESCUE_CANDIDATE& selected_part = m_rescuer->m_all_candidates[row];
204
205 wxVector<wxVariant> data;
206 int count = 0;
207
208 for( SCH_SYMBOL* eachSymbol : *m_rescuer->GetSymbols() )
209 {
210 if( eachSymbol->GetLibId().Format() != UTF8( selected_part.GetRequestedName() ) )
211 continue;
212
213 SCH_FIELD* valueField = eachSymbol->GetField( FIELD_T::VALUE );
214
215 data.clear();
216 data.push_back( eachSymbol->GetRef( m_currentSheet ) );
217 data.push_back( valueField ? valueField->GetText() : wxString( wxT( "" ) ) );
218 m_ListOfInstances->AppendItem( data );
219 count++;
220 }
221
222 wxString msg = wxString::Format( _( "Instances of this symbol (%d items):" ), count );
223 m_titleInstances->SetLabelText( msg );
224}
225
226
228{
229 int row = m_ListOfConflicts->GetSelectedRow();
230
231 if( row < 0 )
232 {
233 m_previewOldWidget->DisplayPart( nullptr, 0 );
234 m_previewNewWidget->DisplayPart( nullptr, 0 );
235 }
236 else
237 {
238 RESCUE_CANDIDATE& selected_part = m_rescuer->m_all_candidates[row];
239
240 m_previewOldWidget->DisplayPart( selected_part.GetCacheCandidate(), selected_part.GetUnit(),
241 selected_part.GetConvert() );
242 m_previewNewWidget->DisplayPart( selected_part.GetLibCandidate(), selected_part.GetUnit(),
243 selected_part.GetConvert() );
244 }
245}
246
247
248void DIALOG_RESCUE_EACH::OnConflictSelect( wxDataViewEvent& aEvent )
249{
250 // wxformbuilder connects this event to the _dialog_, not the data view.
251 // Make sure the correct item triggered it, otherwise we trigger recursively
252 // and get a stack overflow.
253 if( aEvent.GetEventObject() != m_ListOfConflicts )
254 return;
255
258}
259
260
262{
263 if( !wxDialog::TransferDataFromWindow() )
264 return false;
265
266 for( size_t index = 0; index < m_rescuer->GetCandidateCount(); ++index )
267 {
268 wxVariant val;
269 m_ListOfConflicts->GetValue( val, index, 0 );
270 bool rescue_part = val.GetBool();
271
272 if( rescue_part )
274 }
275
276 return true;
277}
278
279
280void DIALOG_RESCUE_EACH::OnNeverShowClick( wxCommandEvent& aEvent )
281{
282 wxMessageDialog dlg( GetParent(),
283 _( "Stop showing this tool?\n"
284 "No changes will be made.\n\n"
285 "This setting can be changed from the \"Preferences\" dialog,\n"
286 "and the tool can be activated manually from the \"Tools\" menu." ),
287 _( "Rescue Symbols" ), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
288 int resp = dlg.ShowModal ();
289
290 if( resp == wxID_YES )
291 {
292 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
293
294 if( cfg )
295 cfg->m_RescueNeverShow = true;
296
298 Close();
299 }
300}
301
302
303void DIALOG_RESCUE_EACH::OnCancelClick( wxCommandEvent& aEvent )
304{
307}
308
309
310int InvokeDialogRescueEach( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet,
311 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain )
312{
313 DIALOG_RESCUE_EACH dlg( aParent, aRescuer, aCurrentSheet, aGalBackEndType, aAskShowAgain );
314 return dlg.ShowQuasiModal();
315}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Class DIALOG_RESCUE_EACH_BASE.
virtual void OnCancelClick(wxCommandEvent &event)
wxDataViewListCtrl * m_ListOfConflicts
wxDataViewListCtrl * m_ListOfInstances
wxStdDialogButtonSizer * m_stdButtons
DIALOG_RESCUE_EACH(wxWindow *aParent, RESCUER &aRescuer, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain)
This dialog asks the user which rescuable, cached parts he wants to rescue.
void OnNeverShowClick(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void OnCancelClick(wxCommandEvent &aEvent) override
SYMBOL_PREVIEW_WIDGET * m_previewNewWidget
~DIALOG_RESCUE_EACH()=default
bool TransferDataFromWindow() override
void OnConflictSelect(wxDataViewEvent &aEvent) override
SYMBOL_PREVIEW_WIDGET * m_previewOldWidget
SCH_SHEET_PATH * m_currentSheet
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowQuasiModal()
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
bool AppendToPage(const wxString &aSource)
Definition: html_window.cpp:69
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
size_t GetCandidateCount()
Return the number of rescue candidates found.
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
virtual wxString GetActionDescription() const =0
Get a description of the action proposed, for displaying in the UI.
int GetUnit() const
virtual LIB_SYMBOL * GetCacheCandidate() const
Get the part that can be loaded from the project cache, if possible, or else NULL.
virtual wxString GetRequestedName() const
Get the name that was originally requested in the schematic.
int GetConvert() const
virtual LIB_SYMBOL * GetLibCandidate() const
Get the part the would be loaded from the libraries, if possible, or else NULL.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:75
void DisplayPart(LIB_SYMBOL *aSymbol, int aUnit, int aBodyStyle=0)
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:72
int InvokeDialogRescueEach(wxWindow *aParent, RESCUER &aRescuer, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain)
This dialog asks the user which rescuable, cached parts he wants to rescue.
#define _(s)
Definition for symbol library class.