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>
37#include <widgets/wx_grid.h>
39#include <confirm.h>
40
41
42extern KICOMMON_API
43std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos;
44
45
46DIALOG_DESTINATION::DIALOG_DESTINATION( wxWindow* aParent, JOBSET* aJobsFile,
47 JOBSET_DESTINATION* aDestination ) :
48 DIALOG_DESTINATION_BASE( aParent ),
49 m_jobsFile( aJobsFile ),
50 m_destination( aDestination )
51{
52 // prevent someone from failing to add the type info in the future
53 wxASSERT( JobsetDestinationTypeInfos.contains( m_destination->m_type ) );
54
55 SetTitle( wxString::Format( _( "%s Destination" ),
56 m_destination->m_outputHandler->GetDefaultDescription() ) );
57
58 if( m_destination->m_type != JOBSET_DESTINATION_T::ARCHIVE )
59 {
60 m_textArchiveFormat->Hide();
62 }
63
64 m_textCtrlOutputPath->SetValue( m_destination->m_outputHandler->GetOutputPath() );
66 m_textCtrlDescription->SetValue( m_destination->GetDescription() );
67
69}
70
71
73{
74 bool isFolder = false;
75 wxString fileWildcard = "";
76 isFolder = JobsetDestinationTypeInfos[m_destination->m_type].outputPathIsFolder;
77 fileWildcard = JobsetDestinationTypeInfos[m_destination->m_type].fileWildcard;
78
79 if( isFolder )
80 {
81 wxFileName fn;
82 fn.AssignDir( m_textCtrlOutputPath->GetValue() );
83 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
84 wxString currPath = fn.GetFullPath();
85
86 wxDirDialog dirDialog( this, _( "Select output directory" ), currPath,
87 wxDD_DEFAULT_STYLE );
88
89 if( dirDialog.ShowModal() != wxID_OK )
90 return;
91
92 wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
93
94 m_textCtrlOutputPath->SetValue( dirName.GetFullPath() );
95 }
96 else
97 {
98 wxFileName fname( m_textCtrlOutputPath->GetValue() );
99
100 wxFileDialog dlg( this, _( "Select output path" ), fname.GetPath(), fname.GetFullName(),
101 fileWildcard,
102 wxFD_OVERWRITE_PROMPT | wxFD_SAVE );
103
104 if( dlg.ShowModal() != wxID_OK )
105 return;
106
107 wxString path = dlg.GetPath();
108
109 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
110 {
111 wxFileName fn( path );
112
113 if( fn.GetExt().IsEmpty() )
115
116 path = fn.GetFullPath();
117 }
118
119 m_textCtrlOutputPath->SetValue( path );
120 }
121
122}
123
125{
126 wxString outputPath = m_textCtrlOutputPath->GetValue().Trim().Trim( false );
127
128 if( outputPath.IsEmpty() )
129 {
130 DisplayErrorMessage( this, _( "Output path cannot be empty" ) );
131 return false;
132 }
133
134 wxArrayInt selectedItems;
135 m_includeJobs->GetCheckedItems( selectedItems );
136
137 // Update the only job map
138 m_destination->m_only.clear();
139
140 if( selectedItems.size() < m_includeJobs->GetCount() )
141 {
142 for( int i : selectedItems )
143 {
144 if( m_onlyMap.contains( i ) )
145 m_destination->m_only.emplace_back( m_onlyMap[i] );
146 }
147 }
148
149 m_destination->m_outputHandler->SetOutputPath( outputPath );
150
151 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
152 {
153 JOBS_OUTPUT_ARCHIVE* archive =
154 static_cast<JOBS_OUTPUT_ARCHIVE*>( m_destination->m_outputHandler.get() );
155
157 }
158
159 m_destination->SetDescription( m_textCtrlDescription->GetValue() );
160
161 return true;
162}
163
164
166{
167 wxArrayString arrayStr;
168 std::vector<int> selectedList;
169
170 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
171 {
172 arrayStr.Add( wxString::Format( wxT( "%d. %s" ),
173 (int) arrayStr.size() + 1,
174 job.GetDescription() ) );
175
176 auto it = std::find_if( m_destination->m_only.begin(), m_destination->m_only.end(),
177 [&]( const wxString& only )
178 {
179 if( only == job.m_id )
180 return true;
181
182 return false;
183 } );
184
185 if( it != m_destination->m_only.end() )
186 selectedList.emplace_back( arrayStr.size() - 1 );
187
188 m_onlyMap.emplace( arrayStr.size() - 1, job.m_id );
189 }
190
191 if( arrayStr.size() != 0 )
192 {
193 m_includeJobs->InsertItems( arrayStr, 0 );
194
195 if( selectedList.size() )
196 {
197 for( int idx : selectedList )
198 m_includeJobs->Check( idx );
199 }
200 else
201 {
202 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
203 m_includeJobs->Check( idx );
204 }
205 }
206
207 m_choiceArchiveformat->AppendString( _( "Zip" ) );
208 m_choiceArchiveformat->SetSelection( 0 );
209
210 return true;
211}
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:194
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:40
#define KICOMMON_API
Definition kicommon.h:28
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:39