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