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 ) :
25 m_type( aType ),
26 m_varOverrides(),
27 m_tempOutputDirectory(),
28 m_outputPath(),
29 m_outputPathIsDirectory( aOutputIsDirectory )
30{
32 {
33 m_params.emplace_back(
34 new JOB_PARAM<wxString>( "output_dir", &m_outputPath, m_outputPath ) );
35 }
36 else
37 {
38 m_params.emplace_back(
39 new JOB_PARAM<wxString>( "output_filename", &m_outputPath, m_outputPath ) );
40 }
41}
42
43
45{
46 for( JOB_PARAM_BASE* param : m_params )
47 delete param;
48
49 m_params.clear();
50}
51
52
53void JOB::FromJson( const nlohmann::json& j )
54{
55 for( JOB_PARAM_BASE* param : m_params )
56 param->FromJson( j );
57}
58
59
60void JOB::ToJson( nlohmann::json& j ) const
61{
62 for( JOB_PARAM_BASE* param : m_params )
63 param->ToJson( j );
64}
65
66
68{
69 return wxEmptyString;
70}
71
72
73void JOB::SetTempOutputDirectory( const wxString& aBase )
74{
76}
77
78
79void PrependDirectoryToPath( wxFileName& aFileName, const wxString aDirPath )
80{
81 wxFileName fn( aDirPath + wxFileName::GetPathSeparator() + aFileName.GetFullPath() );
82
83 aFileName = fn;
84}
85
86
87wxString JOB::GetFullOutputPath() const
88{
89 if( !m_tempOutputDirectory.IsEmpty() )
90 {
92 {
93 wxFileName fn( m_outputPath );
94 if( fn.IsAbsolute() || m_outputPath.IsEmpty() )
95 {
96 fn.AssignDir( m_tempOutputDirectory );
97 }
98 else
99 {
101 }
102
103
104 return fn.GetFullPath();
105 }
106 else
107 {
108 wxFileName fn( m_outputPath );
109 if( fn.IsAbsolute() )
110 {
111 // uhhh, do nothing
112 // its a full path passed by cli, so we return as-is
113 // the job handlers should have fixed empty paths
114 }
115 else
116 {
118 }
119
120 return fn.GetFullPath();
121 }
122 }
123
124 return m_outputPath;
125}
126
127
128void JOB::SetOutputPath( const wxString& aPath )
129{
130 m_outputPath = aPath;
131}
132
133
135{
136 if( m_outputPath.IsEmpty() )
137 {
138 return false;
139 }
140
141 wxFileName fn( m_outputPath );
143 {
144 return fn.IsDir();
145 }
146 else
147 {
148 return !fn.IsDir();
149 }
150}
151
152
153KICOMMON_API void to_json( nlohmann::json& j, const JOB& f )
154{
155 f.ToJson( j );
156}
157
158
159KICOMMON_API void from_json( const nlohmann::json& j, JOB& f )
160{
161 f.FromJson( j );
162}
163
164
165JOB_PARAM_BASE::JOB_PARAM_BASE( const std::string& aJsonPath ) :
166 m_jsonPath( aJsonPath )
167{
168}
JOB_PARAM_BASE(const std::string &aJsonPath)
Definition: job.cpp:165
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:53
std::vector< JOB_PARAM_BASE * > m_params
Definition: job.h:134
JOB(const std::string &aType, bool aOutputIsDirectory)
Definition: job.cpp:24
virtual wxString GetDescription()
Definition: job.cpp:67
wxString GetFullOutputPath() const
Definition: job.cpp:87
bool OutputPathFullSpecified() const
Definition: job.cpp:134
wxString m_tempOutputDirectory
Definition: job.h:129
virtual ~JOB()
Definition: job.cpp:44
bool m_outputPathIsDirectory
Definition: job.h:132
virtual void ToJson(nlohmann::json &j) const
Definition: job.cpp:60
void SetTempOutputDirectory(const wxString &aBase)
Definition: job.cpp:73
void SetOutputPath(const wxString &aPath)
Definition: job.cpp:128
wxString m_outputPath
Definition: job.h:131
void PrependDirectoryToPath(wxFileName &aFileName, const wxString aDirPath)
Definition: job.cpp:79
KICOMMON_API void to_json(nlohmann::json &j, const JOB &f)
Definition: job.cpp:153
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition: job.cpp:159
#define KICOMMON_API
Definition: kicommon.h:28