KiCad PCB EDA Suite
Loading...
Searching...
No Matches
job.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) 2022 Mark Roszko <[email protected]>
5 * Copyright (C) 1992-2024 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#pragma once
22
23#include <kicommon.h>
24#include <map>
25#include <wx/string.h>
27
29{
30public:
31 JOB_PARAM_BASE( const std::string& aJsonPath );
32
33 virtual ~JOB_PARAM_BASE() = default;
34
35 virtual void FromJson( const nlohmann::json& j ) const = 0;
36
37 virtual void ToJson( nlohmann::json& j ) = 0;
38
39protected:
40 std::string m_jsonPath;
41};
42
43template <typename ValueType>
45{
46public:
47
48 JOB_PARAM( const std::string& aJsonPath, ValueType* aPtr,
49 ValueType aDefault ) :
50 JOB_PARAM_BASE( aJsonPath ), m_ptr( aPtr ), m_default( aDefault )
51 {
52 }
53
54 virtual void FromJson( const nlohmann::json& j ) const override
55 {
56 *m_ptr = j.value( m_jsonPath, m_default );
57 }
58
59 virtual void ToJson( nlohmann::json& j ) override { j[m_jsonPath] = *m_ptr; }
60
61protected:
62 ValueType* m_ptr;
63 ValueType m_default;
64};
65
67{
69
70 JOB_OUTPUT( wxString outputPath ) { m_outputPath = outputPath; }
71
72 wxString m_outputPath;
73};
74
79{
80public:
81 JOB( const std::string& aType, bool aOutputIsDirectory );
82
83 virtual ~JOB();
84
85 const std::string& GetType() const { return m_type; };
86
87 const std::map<wxString, wxString>& GetVarOverrides() const { return m_varOverrides; }
88
89 void SetVarOverrides( const std::map<wxString, wxString>& aVarOverrides )
90 {
91 m_varOverrides = aVarOverrides;
92 }
93
94 virtual void FromJson( const nlohmann::json& j );
95 virtual void ToJson( nlohmann::json& j ) const;
96
97 virtual wxString GetDescription();
98
99 const std::vector<JOB_PARAM_BASE*>& GetParams() {
100 return m_params;
101 }
102
104 m_outputs.clear();
105 }
106
107 const std::vector<JOB_OUTPUT>& GetOutputs() {
108 return m_outputs;
109 }
110
111 void AddOutput( wxString aOutputPath ) {
112 m_outputs.emplace_back( aOutputPath );
113 }
114
115 void SetTempOutputDirectory( const wxString& aBase );
116
117
118 void SetOutputPath( const wxString& aPath );
119 wxString GetOutputPath() const { return m_outputPath; }
120 wxString GetFullOutputPath() const;
121
122 bool OutputPathFullSpecified() const;
123
124
125protected:
126 std::string m_type;
127 std::map<wxString, wxString> m_varOverrides;
128
130
131 wxString m_outputPath;
133
134 std::vector<JOB_PARAM_BASE*> m_params;
135
136 std::vector<JOB_OUTPUT> m_outputs;
137};
138
139KICOMMON_API void from_json( const nlohmann::json& j, JOB& f );
140KICOMMON_API void to_json( nlohmann::json& j, const JOB& f );
virtual void ToJson(nlohmann::json &j)=0
virtual void FromJson(const nlohmann::json &j) const =0
std::string m_jsonPath
Definition: job.h:40
virtual ~JOB_PARAM_BASE()=default
Definition: job.h:45
JOB_PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault)
Definition: job.h:48
virtual void ToJson(nlohmann::json &j) override
Definition: job.h:59
ValueType m_default
Definition: job.h:63
ValueType * m_ptr
Definition: job.h:62
virtual void FromJson(const nlohmann::json &j) const override
Definition: job.h:54
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:79
void SetVarOverrides(const std::map< wxString, wxString > &aVarOverrides)
Definition: job.h:89
std::vector< JOB_PARAM_BASE * > m_params
Definition: job.h:134
const std::vector< JOB_OUTPUT > & GetOutputs()
Definition: job.h:107
void AddOutput(wxString aOutputPath)
Definition: job.h:111
const std::vector< JOB_PARAM_BASE * > & GetParams()
Definition: job.h:99
std::string m_type
Definition: job.h:126
wxString m_tempOutputDirectory
Definition: job.h:129
std::vector< JOB_OUTPUT > m_outputs
Definition: job.h:136
bool m_outputPathIsDirectory
Definition: job.h:132
const std::string & GetType() const
Definition: job.h:85
std::map< wxString, wxString > m_varOverrides
Definition: job.h:127
const std::map< wxString, wxString > & GetVarOverrides() const
Definition: job.h:87
wxString GetOutputPath() const
Definition: job.h:119
void ClearExistingOutputs()
Definition: job.h:103
wxString m_outputPath
Definition: job.h:131
KICOMMON_API void to_json(nlohmann::json &j, const JOB &f)
Definition: job.cpp:154
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition: job.cpp:160
#define KICOMMON_API
Definition: kicommon.h:28
Definition: job.h:67
JOB_OUTPUT()
Definition: job.h:68
wxString m_outputPath
Definition: job.h:72
JOB_OUTPUT(wxString outputPath)
Definition: job.h:70