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 along
18 * with this program. If not, see <http://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
68}
69
70
72{
73 bool isFolder = false;
74 wxString fileWildcard = "";
75 isFolder = JobsetDestinationTypeInfos[m_destination->m_type].outputPathIsFolder;
76 fileWildcard = JobsetDestinationTypeInfos[m_destination->m_type].fileWildcard;
77
78 if( isFolder )
79 {
80 wxFileName fn;
81 fn.AssignDir( m_textCtrlOutputPath->GetValue() );
82 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
83 wxString currPath = fn.GetFullPath();
84
85 wxDirDialog dirDialog( this, _( "Select output directory" ), currPath,
86 wxDD_DEFAULT_STYLE );
87
88 if( dirDialog.ShowModal() != wxID_OK )
89 return;
90
91 wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
92
93 m_textCtrlOutputPath->SetValue( dirName.GetFullPath() );
94 }
95 else
96 {
97 wxFileName fname( m_textCtrlOutputPath->GetValue() );
98
99 wxFileDialog dlg( this, _( "Select output path" ), fname.GetPath(), fname.GetFullName(),
100 fileWildcard,
101 wxFD_OVERWRITE_PROMPT | wxFD_SAVE );
102
104
105 if( dlg.ShowModal() != wxID_OK )
106 return;
107
108 wxString path = dlg.GetPath();
109
110 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
111 {
112 wxFileName fn( path );
113
114 if( fn.GetExt().IsEmpty() )
116
117 path = fn.GetFullPath();
118 }
119
120 m_textCtrlOutputPath->SetValue( path );
121 }
122
123}
124
126{
127 wxString outputPath = m_textCtrlOutputPath->GetValue().Trim().Trim( false );
128
129 if( outputPath.IsEmpty() )
130 {
131 DisplayErrorMessage( this, _( "Output path cannot be empty" ) );
132 return false;
133 }
134
135 wxArrayInt selectedItems;
136 m_includeJobs->GetCheckedItems( selectedItems );
137
138 // Update the only job map
139 m_destination->m_only.clear();
140
141 if( selectedItems.size() < m_includeJobs->GetCount() )
142 {
143 for( int i : selectedItems )
144 {
145 if( m_onlyMap.contains( i ) )
146 m_destination->m_only.emplace_back( m_onlyMap[i] );
147 }
148 }
149
150 m_destination->m_outputHandler->SetOutputPath( outputPath );
151
152 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
153 {
154 JOBS_OUTPUT_ARCHIVE* archive =
155 static_cast<JOBS_OUTPUT_ARCHIVE*>( m_destination->m_outputHandler.get() );
156
158 }
159
160 m_destination->SetDescription( m_textCtrlDescription->GetValue() );
161
162 return true;
163}
164
165
167{
168 m_textCtrlDescription->SetValue( m_destination->GetDescription() );
169 m_textCtrlOutputPath->SetValue( m_destination->m_outputHandler->GetOutputPath() );
170
171 wxArrayString arrayStr;
172 std::vector<int> selectedList;
173
174 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
175 {
176 arrayStr.Add( wxString::Format( wxT( "%d. %s" ),
177 (int) arrayStr.size() + 1,
178 job.GetDescription() ) );
179
180 auto it = std::find_if( m_destination->m_only.begin(), m_destination->m_only.end(),
181 [&]( const wxString& only )
182 {
183 if( only == job.m_id )
184 return true;
185
186 return false;
187 } );
188
189 if( it != m_destination->m_only.end() )
190 selectedList.emplace_back( arrayStr.size() - 1 );
191
192 m_onlyMap.emplace( arrayStr.size() - 1, job.m_id );
193 }
194
195 if( arrayStr.size() != 0 )
196 {
197 m_includeJobs->InsertItems( arrayStr, 0 );
198
199 if( selectedList.size() )
200 {
201 for( int idx : selectedList )
202 m_includeJobs->Check( idx );
203 }
204 else
205 {
206 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
207 m_includeJobs->Check( idx );
208 }
209 }
210
211 m_choiceArchiveformat->AppendString( _( "Zip" ) );
212 m_choiceArchiveformat->SetSelection( 0 );
213
214 return true;
215}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
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
bool TransferDataFromWindow() override
virtual void onOutputPathBrowseClicked(wxCommandEvent &event) override
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:202
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:41
#define KICOMMON_API
Definition kicommon.h:28
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:717
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:39