KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_downgrade_report.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <confirm.h>
23#include <kiplatform/io.h>
24#include <kiplatform/ui.h>
26
27#include <wx/filedlg.h>
28#include <wx/filename.h>
29#include <wx/msgdlg.h>
30
31
32DIALOG_DOWNGRADE_REPORT::DIALOG_DOWNGRADE_REPORT( wxWindow* aParent, const wxString& aTargetName,
33 const COMPATIBILITY_REPORT& aReport ) :
35 m_reportText( aReport.ToText( aTargetName ) ),
36 m_reportFileName( wxS( "compatibility-report.txt" ) )
37{
38 m_reportList->AppendTextColumn( _( "Action" ), wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE );
39 m_reportList->AppendTextColumn( _( "Feature" ), wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE );
40 m_reportList->AppendTextColumn( _( "Detail" ), wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE );
41
42 auto addRows = [&]( DOWNGRADE_BUCKET aBucket, const wxString& aLabel )
43 {
44 for( const COMPAT_ENTRY& entry : aReport.Entries() )
45 {
46 if( entry.m_bucket != aBucket )
47 continue;
48
49 wxString feature = entry.m_feature;
50
51 if( entry.m_count > 1 )
52 feature += wxString::Format( wxT( " (%d)" ), entry.m_count );
53
54 wxVector<wxVariant> row;
55 row.push_back( wxVariant( aLabel ) );
56 row.push_back( wxVariant( feature ) );
57 row.push_back( wxVariant( entry.m_detail ) );
58 m_reportList->AppendItem( row );
59 }
60 };
61
62 addRows( DOWNGRADE_BUCKET::LOWER, _( "Approximate" ) );
63 addRows( DOWNGRADE_BUCKET::DROP, _( "Drop" ) );
64 addRows( DOWNGRADE_BUCKET::BLOCK, _( "Cannot export" ) );
65
66 if( aReport.IsBlocked() )
67 {
68 m_headline->SetLabel( wxString::Format( _( "This project uses features %s cannot represent." ), aTargetName ) );
69 m_sdbSizerOK->Hide();
70 SetupStandardButtons( { { wxID_CANCEL, _( "Close" ) } } );
71 m_sdbSizerCancel->SetDefault();
72 }
73 else
74 {
75 m_headline->SetLabel( wxString::Format( _( "Exporting to %s will change some features:" ), aTargetName ) );
76 SetupStandardButtons( { { wxID_OK, _( "Export" ) } } );
77 }
78
80}
81
82
83void DIALOG_DOWNGRADE_REPORT::OnSaveReport( wxCommandEvent& aEvent )
84{
85 wxFileName fn( m_reportFileName );
86 wxFileDialog dlg( this, _( "Save Compatibility Report" ), fn.GetPath(), fn.GetFullName(),
87 FILEEXT::TextFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
88
90
91 if( dlg.ShowModal() != wxID_OK )
92 return;
93
94 fn = dlg.GetPath();
95
96 if( fn.GetExt().IsEmpty() )
97 {
98 fn.SetExt( FILEEXT::TextFileExtension );
99
100 // The save dialog checked the original path, not the path with the added extension.
101 if( fn.FileExists()
102 && wxMessageBox( wxString::Format( _( "The file '%s' already exists. Overwrite it?" ), fn.GetFullPath() ),
103 _( "Save Compatibility Report" ), wxYES_NO | wxNO_DEFAULT | wxICON_WARNING, this )
104 != wxYES )
105 {
106 return;
107 }
108 }
109
110 wxScopedCharBuffer utf8 = m_reportText.ToUTF8();
111 wxString error;
112
113 if( !KIPLATFORM::IO::AtomicWriteFile( fn.GetFullPath(), utf8.data(), utf8.length(), &error ) )
114 {
115 DisplayErrorMessage( this, wxString::Format( _( "Cannot write report to file '%s'." ), fn.GetFullPath() ),
116 error );
117 return;
118 }
119
120 m_reportFileName = fn.GetFullPath();
121}
What an export to a given target will keep, approximate, drop, or block.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
const std::vector< COMPAT_ENTRY > & Entries() const
DIALOG_DOWNGRADE_REPORT_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Compatibility Report"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 386), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnSaveReport(wxCommandEvent &aEvent) override
DIALOG_DOWNGRADE_REPORT(wxWindow *aParent, const wxString &aTargetName, const COMPATIBILITY_REPORT &aReport)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
static const std::string TextFileExtension
static wxString TextFileWildcard()
bool AtomicWriteFile(const wxString &aTargetPath, const void *aData, size_t aSize, wxString *aError=nullptr)
Writes aData to aTargetPath via a sibling temp file, fsyncs the data and directory,...
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:612
One line in the compatibility report.
Definition of file extensions used in Kicad.