KiCad PCB EDA Suite
Loading...
Searching...
No Matches
jobset.h
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#ifndef JOBS_FILE_H
22#define JOBS_FILE_H
23
24#include <reporter.h>
26#include <jobs/job.h>
27#include <jobs/jobs_output.h>
29#include <settings/parameters.h>
31#include <ctime>
32#include <memory>
33#include <optional>
34
35class PROJECT;
36
37
39{
40public:
41 JOBSET_OUTPUT_REPORTER( const wxString& aTempDirPath, PROGRESS_REPORTER* aProgressReporter ) :
42 m_tempDirPath( aTempDirPath ),
43 m_includeDebug( false ),
44 m_progressReporter( aProgressReporter )
45 {
46 }
47
48 REPORTER& Report( const wxString& aText, SEVERITY aSeverity ) override
49 {
50 wxString text( aText );
51
52 if( aSeverity == RPT_SEVERITY_DEBUG && !m_includeDebug )
53 return *this;
54
55 if( aSeverity == RPT_SEVERITY_ACTION )
56 text.Replace( m_tempDirPath, wxEmptyString );
57
59 {
60 m_progressReporter->Report( text );
61 m_progressReporter->KeepRefreshing();
62 }
63
64 return WX_STRING_REPORTER::Report( text, aSeverity );
65 }
66
67private:
68 wxString m_tempDirPath;
71};
72
73
74
76{
78 m_job( nullptr )
79 {}
80
81 JOBSET_JOB( const wxString& id, const wxString& type, JOB* job ) :
82 m_id( id ),
83 m_type( type ),
84 m_job( job )
85 {}
86
87 wxString m_id;
88 wxString m_type;
89 wxString m_description;
90 std::shared_ptr<JOB> m_job;
91
92 wxString GetDescription() const;
93 void SetDescription( const wxString& aDescription );
94
95 bool operator==( const JOBSET_JOB& rhs ) const;
96};
97
98
100{
102 ARCHIVE
103};
104
112
113extern KICOMMON_API
114std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos;
115
116
118{
120
121 JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T type );
122
123 void InitOutputHandler();
124
125 wxString GetDescription() const;
126 void SetDescription( const wxString& aDescription );
127
128 wxString GetPathInfo() const;
129
130 bool operator==( const JOBSET_DESTINATION& rhs ) const;
131
132public:
133 wxString m_id;
136 std::shared_ptr<JOBS_OUTPUT_HANDLER> m_outputHandler;
137 std::vector<wxString> m_only;
138
140 std::optional<bool> m_lastRunSuccess;
141 std::unordered_map<wxString, std::optional<bool>> m_lastRunSuccessMap;
142 std::unordered_map<wxString, std::shared_ptr<JOBSET_OUTPUT_REPORTER>> m_lastRunReporters;
143 std::optional<wxString> m_lastResolvedOutputPath;
144};
145
146
148{
149public:
150 JOBSET( const wxString& aFilename );
151
152 virtual ~JOBSET() {}
153
154 std::vector<JOBSET_JOB>& GetJobs()
155 {
156 return m_jobs;
157 }
158
159 std::vector<JOBSET_JOB> GetJobsForDestination( JOBSET_DESTINATION* aDestination );
160
161 std::vector<JOBSET_DESTINATION>& GetDestinations() { return m_destinations; }
162
167 JOBSET_DESTINATION* FindDestination( wxString& aDestinationStr );
168
169 bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
170
171 void SetDirty( bool aFlag = true ) { m_dirty = aFlag; }
172 bool GetDirty() const { return m_dirty; }
173
174 wxString GetFullName() const { return m_fileNameWithoutPath; }
175
176 void AddNewJob( wxString aType, JOB* aJob );
177 JOBSET_DESTINATION* AddNewDestination( JOBSET_DESTINATION_T aType );
178
179 void RemoveDestination( JOBSET_DESTINATION* aDestination );
180 void MoveJobUp( size_t aJobIdx );
181 void MoveJobDown( size_t aJobIdx );
182 void RemoveJob( size_t aJobIdx );
183
184protected:
185 wxString getFileExt() const override;
186
187private:
188 std::vector<JOBSET_JOB> m_jobs;
189 std::vector<JOBSET_DESTINATION> m_destinations;
190
193};
194
195
196KICOMMON_API void to_json( nlohmann::json& j, const JOBSET_JOB& f );
197KICOMMON_API void from_json( const nlohmann::json& j, JOBSET_JOB& f );
198
199KICOMMON_API void to_json( nlohmann::json& j, const JOBSET_DESTINATION& f );
200KICOMMON_API void from_json( const nlohmann::json& j, JOBSET_DESTINATION& f );
201
202#if defined( __MINGW32__ )
205#else
206extern template class APIVISIBLE PARAM_LIST<JOBSET_JOB>;
207extern template class APIVISIBLE PARAM_LIST<JOBSET_DESTINATION>;
208#endif
209
210#endif
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
BITMAPS
A list of all bitmap identifiers.
wxString m_tempDirPath
Definition jobset.h:68
REPORTER & Report(const wxString &aText, SEVERITY aSeverity) override
Report a string with a given severity.
Definition jobset.h:48
PROGRESS_REPORTER * m_progressReporter
Definition jobset.h:70
JOBSET_OUTPUT_REPORTER(const wxString &aTempDirPath, PROGRESS_REPORTER *aProgressReporter)
Definition jobset.h:41
std::vector< JOBSET_DESTINATION > & GetDestinations()
Definition jobset.h:161
wxString m_fileNameWithoutPath
Definition jobset.h:192
bool GetDirty() const
Definition jobset.h:172
void SetDirty(bool aFlag=true)
Definition jobset.h:171
std::vector< JOBSET_DESTINATION > m_destinations
Definition jobset.h:189
std::vector< JOBSET_JOB > m_jobs
Definition jobset.h:188
std::vector< JOBSET_JOB > & GetJobs()
Definition jobset.h:154
bool m_dirty
Definition jobset.h:191
JOBSET(const wxString &aFilename)
Definition jobset.cpp:199
wxString GetFullName() const
Definition jobset.h:174
virtual ~JOBSET()
Definition jobset.h:152
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:183
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:66
REPORTER()
Definition reporter.h:75
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:68
#define APIVISIBLE
KICOMMON_API std::map< JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO > JobsetDestinationTypeInfos
Definition jobset.cpp:41
enum KICOMMON_API JOBSET_DESTINATION_T
Definition jobset.h:100
KICOMMON_API void from_json(const nlohmann::json &j, JOBSET_JOB &f)
Definition jobset.cpp:68
FOLDER
Definition jobset.h:101
KICOMMON_API void to_json(nlohmann::json &j, const JOBSET_JOB &f)
#define KICOMMON_API
Definition kicommon.h:28
SEVERITY
@ RPT_SEVERITY_DEBUG
@ RPT_SEVERITY_ACTION
std::unordered_map< wxString, std::shared_ptr< JOBSET_OUTPUT_REPORTER > > m_lastRunReporters
Definition jobset.h:142
void SetDescription(const wxString &aDescription)
Definition jobset.cpp:163
std::shared_ptr< JOBS_OUTPUT_HANDLER > m_outputHandler
Definition jobset.h:136
JOBSET_DESTINATION_T m_type
Definition jobset.h:134
wxString m_description
Definition jobset.h:135
std::vector< wxString > m_only
Transient property, not stored for now.
Definition jobset.h:137
void InitOutputHandler()
Definition jobset.cpp:139
wxString GetPathInfo() const
Definition jobset.cpp:158
wxString GetDescription() const
Definition jobset.cpp:152
std::optional< wxString > m_lastResolvedOutputPath
Definition jobset.h:143
std::optional< bool > m_lastRunSuccess
Definition jobset.h:140
std::unordered_map< wxString, std::optional< bool > > m_lastRunSuccessMap
Definition jobset.h:141
wxString m_id
Definition jobset.h:133
wxString m_id
Definition jobset.h:87
std::shared_ptr< JOB > m_job
Definition jobset.h:90
wxString m_description
Definition jobset.h:89
JOBSET_JOB(const wxString &id, const wxString &type, JOB *job)
Definition jobset.h:81
wxString m_type
Definition jobset.h:88
JOBSET_JOB()
Definition jobset.h:77
wxString GetDescription() const
Definition jobset.cpp:178
void SetDescription(const wxString &aDescription)
Definition jobset.cpp:184