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" ),
57
58 if( m_destination->m_type != JOBSET_DESTINATION_T::ARCHIVE )
59 {
60 m_textArchiveFormat->Hide();
62 }
63
65 m_buttonOutputPath->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
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 m_textCtrlOutputPath->SetValue( dlg.GetPath() );
108 }
109
110}
111
113{
114 wxString outputPath = m_textCtrlOutputPath->GetValue().Trim().Trim( false );
115
116 if( outputPath.IsEmpty() )
117 {
118 DisplayErrorMessage( this, _( "Output path cannot be empty" ) );
119 return false;
120 }
121
122 wxArrayInt selectedItems;
123 m_includeJobs->GetCheckedItems( selectedItems );
124
125 // Update the only job map
126 m_destination->m_only.clear();
127
128 if( selectedItems.size() < m_includeJobs->GetCount() )
129 {
130 for( int i : selectedItems )
131 {
132 if( m_onlyMap.contains( i ) )
133 m_destination->m_only.emplace_back( m_onlyMap[i] );
134 }
135 }
136
138
139 if( m_destination->m_type == JOBSET_DESTINATION_T::ARCHIVE )
140 {
141 JOBS_OUTPUT_ARCHIVE* archive =
143
145 }
146
148
149 return true;
150}
151
152
154{
155 wxArrayString arrayStr;
156 std::vector<int> selectedList;
157
158 for( JOBSET_JOB& job : m_jobsFile->GetJobs() )
159 {
160 arrayStr.Add( wxString::Format( wxT( "%d. %s" ),
161 (int) arrayStr.size() + 1,
162 job.GetDescription() ) );
163
164 auto it = std::find_if( m_destination->m_only.begin(), m_destination->m_only.end(),
165 [&]( const wxString& only )
166 {
167 if( only == job.m_id )
168 return true;
169
170 return false;
171 } );
172
173 if( it != m_destination->m_only.end() )
174 selectedList.emplace_back( arrayStr.size() - 1 );
175
176 m_onlyMap.emplace( arrayStr.size() - 1, job.m_id );
177 }
178
179 if( arrayStr.size() != 0 )
180 {
181 m_includeJobs->InsertItems( arrayStr, 0 );
182
183 if( selectedList.size() )
184 {
185 for( int idx : selectedList )
186 m_includeJobs->Check( idx );
187 }
188 else
189 {
190 for( size_t idx = 0; idx < m_includeJobs->GetCount(); ++idx )
191 m_includeJobs->Check( idx );
192 }
193 }
194
195 m_choiceArchiveformat->AppendString( _( "Zip" ) );
196 m_choiceArchiveformat->SetSelection( 0 );
197
198 return true;
199}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
Class DIALOG_DESTINATION_BASE.
STD_BITMAP_BUTTON * m_buttonOutputPath
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={})
Definition: jobset.h:106
std::vector< JOBSET_JOB > & GetJobs()
Definition: jobset.h:112
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_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition: jobset.cpp:39
#define _(s)
KICOMMON_API std::map< JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition: jobset.cpp:39
#define KICOMMON_API
Definition: kicommon.h:28
void SetDescription(const wxString &aDescription)
Transient property, not stored for now.
Definition: jobset.cpp:165
JOBSET_DESTINATION_T m_type
Definition: jobset.h:87
JOBS_OUTPUT_HANDLER * m_outputHandler
Definition: jobset.h:89
std::vector< wxString > m_only
Definition: jobset.h:90
wxString GetDescription() const
Definition: jobset.cpp:159
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39