KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_jobset_output_options.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
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 std::map<JOBSET_OUTPUT_TYPE, JOBSET_OUTPUT_TYPE_INFO> JobsetOutputTypeInfos;
43
44
46 JOBSET_OUTPUT* aOutput ) :
48 m_jobsFile( aJobsFile ),
49 m_output( aOutput )
50{
51 // prevent someone from failing to add the type info in the future
52 wxASSERT( JobsetOutputTypeInfos.contains( m_output->m_type ) );
53
54 SetTitle( wxString::Format( _( "%s Output Options" ),
56
57 if( m_output->m_type != JOBSET_OUTPUT_TYPE::ARCHIVE )
58 {
59 m_textArchiveFormat->Hide();
61 }
62
64 m_buttonOutputPath->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
66
68}
69
70
72{
73 bool isFolder = false;
74 wxString fileWildcard = "";
75 isFolder = JobsetOutputTypeInfos[m_output->m_type].outputPathIsFolder;
76 fileWildcard = JobsetOutputTypeInfos[m_output->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
103 if( dlg.ShowModal() != wxID_OK )
104 return;
105
106 m_textCtrlOutputPath->SetValue( dlg.GetPath() );
107 }
108
109}
110
112{
113 wxString outputPath = m_textCtrlOutputPath->GetValue().Trim().Trim( false );
114
115 if( outputPath.IsEmpty() )
116 {
117 DisplayErrorMessage( this, _( "Output path cannot be empty" ) );
118 return false;
119 }
120
121 wxArrayInt selectedItems;
122 m_includeJobs->GetCheckedItems( selectedItems );
123
124 // Update the only job map
125 m_output->m_only.clear();
126
127 if( selectedItems.size() < m_includeJobs->GetCount() )
128 {
129 for( int i : selectedItems )
130 {
131 if( m_onlyMap.contains( i ) )
132 m_output->m_only.emplace_back( m_onlyMap[i] );
133 }
134 }
135
136 m_output->m_outputHandler->SetOutputPath( outputPath );
137
138 if( m_output->m_type == JOBSET_OUTPUT_TYPE::ARCHIVE )
139 {
140 JOBS_OUTPUT_ARCHIVE* archive =
142
144 }
145
147
148 return true;
149}
150
151
153{
154 wxArrayString arrayStr;
155 std::vector<int> selectedList;
156
157 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
158 {
159 arrayStr.Add( wxString::Format( wxT( "%d. %s" ),
160 (int) arrayStr.size() + 1,
161 job.GetDescription() ) );
162
163 auto it = std::find_if( m_output->m_only.begin(), m_output->m_only.end(),
164 [&]( const wxString& only )
165 {
166 if( only == job.m_id )
167 return true;
168
169 return false;
170 } );
171
172 if( it != m_output->m_only.end() )
173 selectedList.emplace_back( arrayStr.size() - 1 );
174
175 m_onlyMap.emplace( arrayStr.size() - 1, job.m_id );
176 }
177
178 if( arrayStr.size() != 0 )
179 {
180 m_includeJobs->InsertItems( arrayStr, 0 );
181
182 if( selectedList.size() )
183 {
184 for( int idx : selectedList )
185 m_includeJobs->Check( idx );
186 }
187 else
188 {
189 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
190 m_includeJobs->Check( idx );
191 }
192 }
193
194 m_choiceArchiveformat->AppendString( _( "Zip" ) );
195 m_choiceArchiveformat->SetSelection( 0 );
196
197 return true;
198}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Class DIALOG_JOBSET_OUTPUT_OPTIONS_BASE.
virtual void onOutputPathBrowseClicked(wxCommandEvent &event) override
DIALOG_JOBSET_OUTPUT_OPTIONS(wxWindow *aParent, JOBSET *aJobsFile, JOBSET_OUTPUT *aOutput)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
Definition: jobset.h:105
std::vector< JOBSET_JOB > & GetJobs()
Definition: jobset.h:111
void SetFormat(FORMAT format)
virtual wxString GetDefaultDescription() const
Definition: jobs_output.h:56
wxString GetOutputPath() const
Definition: jobs_output.h:54
void SetOutputPath(const wxString &aPath)
Definition: jobs_output.h:53
void SetBitmap(const wxBitmapBundle &aBmp)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
KICOMMON_API std::map< JOBSET_OUTPUT_TYPE, JOBSET_OUTPUT_TYPE_INFO > JobsetOutputTypeInfos
Definition: jobset.cpp:39
#define _(s)
KICOMMON_API std::map< JOBSET_OUTPUT_TYPE, JOBSET_OUTPUT_TYPE_INFO > JobsetOutputTypeInfos
Definition: jobset.cpp:39
#define KICOMMON_API
Definition: kicommon.h:28
wxString GetDescription() const
Definition: jobset.cpp:160
std::vector< wxString > m_only
Definition: jobset.h:89
void SetDescription(const wxString &aDescription)
Transient property, not stored for now.
Definition: jobset.cpp:166
JOBS_OUTPUT_HANDLER * m_outputHandler
Definition: jobset.h:88
JOBSET_OUTPUT_TYPE m_type
Definition: jobset.h:86
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39