KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_older_version.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 <downgrade_target.h>
24#include <eda_base_frame.h>
25#include <wx/msgdlg.h>
26
28
29
30DIALOG_EXPORT_OLDER_VERSION::DIALOG_EXPORT_OLDER_VERSION( wxWindow* aParent, const wxArrayString& aTargets,
31 const wxArrayString& aVariants,
32 const wxString& aDefaultPath ) :
34{
35 m_targetChoice->Append( aTargets );
36 m_targetChoice->SetSelection( 0 );
37
38 m_variantChoice->Append( _( "Base design" ) );
39 m_variantChoice->Append( aVariants );
40 m_variantChoice->SetSelection( 0 );
41
42 m_targetChoice->Bind( wxEVT_CHOICE,
43 [this]( wxCommandEvent& )
44 {
46 } );
48
49 m_destPicker->SetPath( aDefaultPath );
50
51 SetupStandardButtons( { { wxID_OK, _( "Continue" ) } } );
52
54}
55
56
58{
59 return m_targetChoice->GetStringSelection();
60}
61
62
64{
65 if( !m_variantChoice->IsEnabled() || m_variantChoice->GetSelection() <= 0 )
66 return wxEmptyString;
67
68 return m_variantChoice->GetStringSelection();
69}
70
71
73{
75 bool supportsVariants = target && target->m_schVersion >= 20250922;
76 bool canFlatten = target && !supportsVariants && m_variantChoice->GetCount() > 1;
77
78 m_variantLabel->Enable( canFlatten );
79 m_variantChoice->Enable( canFlatten );
80 m_variantChoice->SetToolTip( supportsVariants ? _( "The target supports variants. All variants are exported." )
81 : _( "Choose the variant to flatten into the exported design." ) );
82}
83
84
86{
87 return m_destPicker->GetPath();
88}
89
90
95
96
98{
99 if( m_destPicker->GetPath().IsEmpty() )
100 {
101 DisplayErrorMessage( this, _( "Choose a destination folder." ) );
102 return false;
103 }
104
105 return true;
106}
107
108
110{
111 const wxString title = _( "Export for Older KiCad Version" );
112 const std::vector<DOWNGRADE_TARGET>& targets = GetDowngradeTargets();
113 wxArrayString names;
114
115 for( const DOWNGRADE_TARGET& target : targets )
116 names.Add( target.m_name );
117
118 // Probe against the oldest target. It drops the most, so its variant list covers the
119 // picker no matter which target the user chooses.
122
123 probe.m_target = targets.back().m_name;
124 probe.m_dryRun = true;
125
126 if( !aRun( probe, result ) )
127 {
128 wxMessageBox( result.m_error, title, wxOK | wxICON_ERROR, aFrame );
129 return;
130 }
131
132 wxArrayString variantNames;
133
134 for( const wxString& name : result.m_variantsFound )
135 variantNames.Add( name );
136
137 DIALOG_EXPORT_OLDER_VERSION setupDlg( aFrame, names, variantNames, aFrame->GetMruPath() );
138
139 if( setupDlg.ShowModal() != wxID_OK )
140 return;
141
143 pass.m_target = setupDlg.GetTarget();
144 pass.m_variant = setupDlg.GetVariant();
145 pass.m_folder = setupDlg.GetPath();
147 pass.m_dryRun = true;
148
150
151 if( !aRun( pass, result ) )
152 {
153 wxMessageBox( result.m_error, title, wxOK | wxICON_ERROR, aFrame );
154 return;
155 }
156
157 if( result.m_report.IsBlocked() || result.m_report.IsLossy() )
158 {
159 DIALOG_DOWNGRADE_REPORT reportDlg( aFrame, pass.m_target, result.m_report );
160
161 if( reportDlg.ShowModal() != wxID_OK || result.m_report.IsBlocked() )
162 return;
163 }
164
165 pass.m_dryRun = false;
167
168 if( !aRun( pass, result ) )
169 {
170 wxMessageBox( result.m_error, title, wxOK | wxICON_ERROR, aFrame );
171 return;
172 }
173
174 wxMessageBox( wxString::Format( _( "Exported to '%s'." ), pass.m_folder ), title, wxOK | wxICON_INFORMATION,
175 aFrame );
176}
const char * name
Shows what an export will approximate, drop, or refuse.
DIALOG_EXPORT_OLDER_VERSION_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Export for Older KiCad Version"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxString GetVariant() const
The variant to flatten, or empty for the base design.
DIALOG_EXPORT_OLDER_VERSION(wxWindow *aParent, const wxArrayString &aTargets, const wxArrayString &aVariants, const wxString &aDefaultPath)
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...
int ShowModal() override
The base frame for deriving all KiCad main window classes.
wxString GetMruPath() const
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.
void RunExportForOlderVersion(EDA_BASE_FRAME *aFrame, const DOWNGRADE_EXPORT_RUNNER &aRun)
std::function< bool(const DOWNGRADE_EXPORT_PASS &, DOWNGRADE_EXPORT_RESULT &)> DOWNGRADE_EXPORT_RUNNER
const std::vector< DOWNGRADE_TARGET > & GetDowngradeTargets()
Supported downgrade targets, newest first.
const DOWNGRADE_TARGET * FindDowngradeTarget(const wxString &aNameOrId)
Match a user-supplied target string against name or stable id, case-insensitively.
#define _(s)
Base window classes and related definitions.
What one pass of an export is asked to do.
wxString m_variant
Variant to flatten, empty for the base design.
wxString m_target
Target release name.
bool m_dryRun
Classify only, write nothing.
wxString m_folder
Destination, empty on a dry run.
What the flow needs back from a pass.
An older KiCad release we can export a project back to.
int m_schVersion
SEXPR_SCHEMATIC_FILE_VERSION for the target.
wxString result
Test unit parsing edge cases and error handling.