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() || m_outputPath.IsEmpty() )
110 {
111 // uhhh, do nothing
112 // either its a full path passed by cli, so we return as-is
113 // or it's a empty path from either...in which case things will fail but who cares
114 // the job handlers should have fixed empty paths
115 }
116 else
117 {
119 }
120
121 return fn.GetFullPath();
122 }
123 }
124
125 return m_outputPath;
126}
127
128
129void JOB::SetOutputPath( const wxString& aPath )
130{
131 m_outputPath = aPath;
132}
133
134
136{
137 if( m_outputPath.IsEmpty() )
138 {
139 return false;
140 }
141
142 wxFileName fn( m_outputPath );
144 {
145 return fn.IsDir();
146 }
147 else
148 {
149 return !fn.IsDir();
150 }
151}
152
153
154KICOMMON_API void to_json( nlohmann::json& j, const JOB& f )
155{
156 f.ToJson( j );
157}
158
159
160KICOMMON_API void from_json( const nlohmann::json& j, JOB& f )
161{
162 f.FromJson( j );
163}
164
165
166JOB_PARAM_BASE::JOB_PARAM_BASE( const std::string& aJsonPath ) :
167 m_jsonPath( aJsonPath )
168{
169}
JOB_PARAM_BASE(const std::string &aJsonPath)
Definition: job.cpp:166
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:135
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:129
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:154
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition: job.cpp:160
#define KICOMMON_API
Definition: kicommon.h:28