KiCad PCB EDA Suite
Loading...
Searching...
No Matches
job.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) 2023 Mark Roszko <[email protected]>
5 * Copyright (C) 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#include <jobs/job.h>
22#include <wx/filename.h>
23
24JOB::JOB( const std::string& aType, bool aOutputIsDirectory, bool aIsCli ) :
25 m_type( aType ),
26 m_isCli( aIsCli ),
27 m_varOverrides(),
28 m_tempOutputDirectory(),
29 m_outputPath(),
30 m_outputPathIsDirectory( aOutputIsDirectory )
31{
33 {
34 m_params.emplace_back(
35 new JOB_PARAM<wxString>( "output_dir", &m_outputPath, m_outputPath ) );
36 }
37 else
38 {
39 m_params.emplace_back(
40 new JOB_PARAM<wxString>( "output_filename", &m_outputPath, m_outputPath ) );
41 }
42}
43
44
46{
47 for( JOB_PARAM_BASE* param : m_params )
48 delete param;
49
50 m_params.clear();
51}
52
53
54void JOB::FromJson( const nlohmann::json& j )
55{
56 for( JOB_PARAM_BASE* param : m_params )
57 param->FromJson( j );
58}
59
60
61void JOB::ToJson( nlohmann::json& j ) const
62{
63 for( JOB_PARAM_BASE* param : m_params )
64 param->ToJson( j );
65}
66
67
69{
70 return wxEmptyString;
71}
72
73
74void JOB::SetTempOutputDirectory( const wxString& aBase )
75{
77}
78
79
80void PrependDirectoryToPath( wxFileName& aFileName, const wxString aDirPath )
81{
82 wxFileName fn( aDirPath + wxFileName::GetPathSeparator() + aFileName.GetFullPath() );
83
84 aFileName = fn;
85}
86
87
88wxString JOB::GetFullOutputPath() const
89{
90 if( !m_tempOutputDirectory.IsEmpty() )
91 {
93 {
94 wxFileName fn( m_outputPath );
95 if( fn.IsAbsolute() || m_outputPath.IsEmpty() )
96 {
97 fn.AssignDir( m_tempOutputDirectory );
98 }
99 else
100 {
102 }
103
104
105 return fn.GetFullPath();
106 }
107 else
108 {
109 wxFileName fn( m_outputPath );
110 if( fn.IsAbsolute() || m_outputPath.IsEmpty() )
111 {
112 // uhhh, do nothing
113 // either its a full path passed by cli, so we return as-is
114 // or it's a empty path from either...in which case things will fail but who cares
115 // the job handlers should have fixed empty paths
116 }
117 else
118 {
120 }
121
122 return fn.GetFullPath();
123 }
124 }
125
126 return m_outputPath;
127}
128
129
130void JOB::SetOutputPath( const wxString& aPath )
131{
132 m_outputPath = aPath;
133}
134
135
137{
138 if( m_outputPath.IsEmpty() )
139 {
140 return false;
141 }
142
143 wxFileName fn( m_outputPath );
145 {
146 return fn.IsDir();
147 }
148 else
149 {
150 return !fn.IsDir();
151 }
152}
153
154
155KICOMMON_API void to_json( nlohmann::json& j, const JOB& f )
156{
157 f.ToJson( j );
158}
159
160
161KICOMMON_API void from_json( const nlohmann::json& j, JOB& f )
162{
163 f.FromJson( j );
164}
165
166
167JOB_PARAM_BASE::JOB_PARAM_BASE( const std::string& aJsonPath ) :
168 m_jsonPath( aJsonPath )
169{
170}
JOB_PARAM_BASE(const std::string &aJsonPath)
Definition: job.cpp:167
Definition: job.h:45
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:79
virtual void FromJson(const nlohmann::json &j)
Definition: job.cpp:54
std::vector< JOB_PARAM_BASE * > m_params
Definition: job.h:136
virtual wxString GetDescription()
Definition: job.cpp:68
wxString GetFullOutputPath() const
Definition: job.cpp:88
bool OutputPathFullSpecified() const
Definition: job.cpp:136
wxString m_tempOutputDirectory
Definition: job.h:131
JOB(const std::string &aType, bool aOutputIsDirectory, bool aIsCli)
Definition: job.cpp:24
virtual ~JOB()
Definition: job.cpp:45
bool m_outputPathIsDirectory
Definition: job.h:134
virtual void ToJson(nlohmann::json &j) const
Definition: job.cpp:61
void SetTempOutputDirectory(const wxString &aBase)
Definition: job.cpp:74
void SetOutputPath(const wxString &aPath)
Definition: job.cpp:130
wxString m_outputPath
Definition: job.h:133
void PrependDirectoryToPath(wxFileName &aFileName, const wxString aDirPath)
Definition: job.cpp:80
KICOMMON_API void to_json(nlohmann::json &j, const JOB &f)
Definition: job.cpp:155
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition: job.cpp:161
#define KICOMMON_API
Definition: kicommon.h:28