KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_destination.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 (C) 2024 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "dialog_destination.h"
23#include <wx/aui/auibook.h>
24#include <jobs/jobset.h>
25#include <jobs/job_registry.h>
26#include <wx/checkbox.h>
27#include <wx/menu.h>
28#include <bitmaps.h>
30#include <kicad_manager_frame.h>
31#include <vector>
32
33#include <wx/dirdlg.h>
34#include <wx/filedlg.h>
35#include <kiplatform/ui.h>
38#include <widgets/wx_grid.h>
40#include <confirm.h>
41
42
43extern KICOMMON_API
44std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos;
45
46
47DIALOG_DESTINATION::DIALOG_DESTINATION( wxWindow* aParent, JOBSET* aJobsFile,
48 JOBSET_DESTINATION* aDestination ) :
49 DIALOG_DESTINATION_BASE( aParent ),
50 m_jobsFile( aJobsFile ),
51 m_destination( aDestination )
52{
53 // prevent someone from failing to add the type info in the future
54 wxASSERT( JobsetDestinationTypeInfos.contains( m_destination->m_type ) );
55
56 SetTitle( wxString::Format( _( "%s Destination" ),
57 m_destination->m_outputHandler->GetDefaultDescription() ) );
58
59 if( m_destination->m_type != JOBSET_DESTINATION_T::ARCHIVE )
60 {
61 m_textArchiveFormat->Hide();
63 }
64
66
67 m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
68 wxCommandEventHandler( DIALOG_DESTINATION::onDeselectAllClicked ),
69 NULL, this );
70
71 m_includeJobs->Connect( wxEVT_CHECKLISTBOX,
72 wxCommandEventHandler( DIALOG_DESTINATION::onIncludeJobsCheck ),
73 NULL, this );
74
76}
77
78
80{
81 bool isFolder = false;
82 wxString fileWildcard = "";
83 isFolder = JobsetDestinationTypeInfos[m_destination->m_type].outputPathIsFolder;
84 fileWildcard = JobsetDestinationTypeInfos[m_destination->m_type].fileWildcard;
85
86 if( isFolder )
87 {
88 wxFileName fn;
89 fn.AssignDir( m_textCtrlOutputPath->GetValue() );
90 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
91 wxString currPath = fn.GetFullPath();
92
93 wxDirDialog dirDialog( this, _( "Select output directory" ), currPath,
94 wxDD_DEFAULT_STYLE );
95
96 if( dirDialog.ShowModal() != wxID_OK )
97 return;
98
99 wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
100
101 m_textCtrlOutputPath->SetValue( dirName.GetFullPath() );
102 }
103 else
104 {
105 wxFileName fname( m_textCtrlOutputPath->GetValue() );
106
107 wxFileDialog dlg( this, _( "Select output path" ), fname.GetPath(), fname.GetFullName(),
108 fileWildcard,
109 wxFD_OVERWRITE_PROMPT | wxFD_SAVE );
110
112
113 if( dlg.ShowModal() != wxID_OK )
114 return;
115
116 wxString path = dlg.GetPath();
117
118 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
119 {
120 wxFileName fn( path );
121
122 if( fn.GetExt().IsEmpty() )
124
125 path = fn.GetFullPath();
126 }
127
128 m_textCtrlOutputPath->SetValue( path );
129 }
130
131}
132
133
135{
136 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
137 {
138 m_includeJobs->Check( idx, false );
139 }
140
141 event.Skip();
142}
143
144
145void DIALOG_DESTINATION::onIncludeJobsCheck(wxCommandEvent& event)
146{
147 int clickedIndex = event.GetInt();
148
149 bool newCheckedState = m_includeJobs->IsChecked( clickedIndex );
150
151 wxArrayInt currentSelections;
152 m_includeJobs->GetSelections( currentSelections );
153
154 for( size_t i = 0; i < currentSelections.GetCount(); i++ )
155 {
156 m_includeJobs->Check( currentSelections[i], newCheckedState );
157 }
158
159 event.Skip();
160}
161
162
164{
165 wxString outputPath = m_textCtrlOutputPath->GetValue().Trim().Trim( false );
166
167 if( outputPath.IsEmpty() )
168 {
169 DisplayErrorMessage( this, _( "Output path cannot be empty" ) );
170 return false;
171 }
172
173 wxArrayInt selectedItems;
174 m_includeJobs->GetCheckedItems( selectedItems );
175
176 // Update the only job map
177 m_destination->m_only.clear();
178
179 if( selectedItems.size() < m_includeJobs->GetCount() )
180 {
181 for( int i : selectedItems )
182 {
183 if( m_onlyMap.contains( i ) )
184 m_destination->m_only.emplace_back( m_onlyMap[i] );
185 }
186 }
187
188 m_destination->m_outputHandler->SetOutputPath( outputPath );
189
190 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
191 {
192 JOBS_OUTPUT_ARCHIVE* archive =
193 static_cast<JOBS_OUTPUT_ARCHIVE*>( m_destination->m_outputHandler.get() );
194
196 }
197
198 m_destination->SetDescription( m_textCtrlDescription->GetValue() );
199
200 return true;
201}
202
203
205{
206 m_textCtrlDescription->SetValue( m_destination->GetDescription() );
207 m_textCtrlOutputPath->SetValue( m_destination->m_outputHandler->GetOutputPath() );
208
209 wxArrayString arrayStr;
210 std::vector<int> selectedList;
211
212 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
213 {
214 arrayStr.Add( wxString::Format( wxT( "%d. %s" ),
215 (int) arrayStr.size() + 1,
216 job.GetDescription() ) );
217
218 auto it = std::find_if( m_destination->m_only.begin(), m_destination->m_only.end(),
219 [&]( const wxString& only )
220 {
221 if( only == job.m_id )
222 return true;
223
224 return false;
225 } );
226
227 if( it != m_destination->m_only.end() )
228 selectedList.emplace_back( arrayStr.size() - 1 );
229
230 m_onlyMap.emplace( arrayStr.size() - 1, job.m_id );
231 }
232
233 if( arrayStr.size() != 0 )
234 {
235 m_includeJobs->InsertItems( arrayStr, 0 );
236
237 if( selectedList.size() )
238 {
239 for( int idx : selectedList )
240 m_includeJobs->Check( idx );
241 }
242 else
243 {
244 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
245 m_includeJobs->Check( idx );
246 }
247 }
248
249 m_choiceArchiveformat->AppendString( _( "Zip" ) );
250 m_choiceArchiveformat->SetSelection( 0 );
251
252 return true;
253}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
STD_BITMAP_BUTTON * m_buttonOutputPath
DIALOG_DESTINATION_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("%s Destination"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_DESTINATION(wxWindow *aParent, JOBSET *aJobsFile, JOBSET_DESTINATION *aDestination)
std::map< int, wxString > m_onlyMap
bool TransferDataToWindow() override
void onIncludeJobsCheck(wxCommandEvent &event)
bool TransferDataFromWindow() override
virtual void onOutputPathBrowseClicked(wxCommandEvent &event) override
void onDeselectAllClicked(wxCommandEvent &event)
JOBSET_DESTINATION * m_destination
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void SetFormat(FORMAT format)
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 ArchiveFileExtension
KICOMMON_API std::map< JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition jobset.cpp:42
#define KICOMMON_API
Definition kicommon.h:27
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
std::string path
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:35