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 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 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#include <common.h>
24#include <project.h>
25
26JOB::JOB( const std::string& aType, bool aOutputIsDirectory ) :
27 m_type( aType ),
31 m_outputPathIsDirectory( aOutputIsDirectory ),
34{
35 m_params.emplace_back( new JOB_PARAM<wxString>( "description",
37
39 {
40 m_params.emplace_back( new JOB_PARAM<wxString>( "output_dir",
42 }
43 else
44 {
45 m_params.emplace_back( new JOB_PARAM<wxString>( "output_filename",
47 }
48}
49
50
52{
53 for( JOB_PARAM_BASE* param : m_params )
54 delete param;
55
56 m_params.clear();
57}
58
59
60void JOB::FromJson( const nlohmann::json& j )
61{
62 for( JOB_PARAM_BASE* param : m_params )
63 param->FromJson( j );
64}
65
66
67void JOB::ToJson( nlohmann::json& j ) const
68{
69 for( JOB_PARAM_BASE* param : m_params )
70 param->ToJson( j );
71}
72
73
75{
76 return wxEmptyString;
77}
78
79
81{
82 return _( "Job Settings" );
83}
84
85
86void JOB::SetTempOutputDirectory( const wxString& aBase )
87{
89}
90
91
92void PrependDirectoryToPath( wxFileName& aFileName, const wxString aDirPath )
93{
94 wxFileName fn( aDirPath + wxFileName::GetPathSeparator() + aFileName.GetFullPath() );
95
96 aFileName = fn;
97}
98
99
100wxString JOB::ResolveOutputPath( const wxString& aPath, bool aPathIsDirectory, PROJECT* aProject ) const
101{
102 std::function<bool( wxString* )> textResolver =
103 [&]( wxString* token ) -> bool
104 {
105 if( m_titleBlock.TextVarResolver( token, aProject ) )
106 return true;
107 if( aProject )
108 return aProject->TextVarResolver( token );
109 return false;
110 };
111
112 wxString outPath = aPath;
113 outPath = ExpandTextVars( outPath, &textResolver );
114
115 if( !m_tempOutputDirectory.IsEmpty() )
116 {
117 if( aPathIsDirectory )
118 {
119 wxFileName fn( outPath );
120
121 if( fn.IsAbsolute() || outPath.IsEmpty() )
122 fn.AssignDir( m_tempOutputDirectory );
123 else
125
126 return fn.GetFullPath();
127 }
128 else
129 {
130 wxFileName fn( outPath );
131 if( fn.IsAbsolute() )
132 {
133 // uhhh, do nothing
134 // its a full path passed by cli, so we return as-is
135 // the job handlers should have fixed empty paths
136 }
137 else
138 {
140 }
141
142 return fn.GetFullPath();
143 }
144 }
145
146 return outPath;
147}
148
149
150wxString JOB::GetFullOutputPath( PROJECT* aProject ) const
151{
153 m_outputPathIsDirectory, aProject );
154}
155
156
157void JOB::SetConfiguredOutputPath( const wxString& aPath )
158{
159 m_outputPath = aPath;
160}
161
162
163KICOMMON_API void to_json( nlohmann::json& j, const JOB& f )
164{
165 f.ToJson( j );
166}
167
168
169KICOMMON_API void from_json( const nlohmann::json& j, JOB& f )
170{
171 f.FromJson( j );
172}
173
174
175JOB_PARAM_BASE::JOB_PARAM_BASE( const std::string& aJsonPath ) :
176 m_jsonPath( aJsonPath )
177{
178}
std::string m_jsonPath
Definition job.h:46
JOB_PARAM_BASE(const std::string &aJsonPath)
Definition job.cpp:175
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:183
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:157
virtual void FromJson(const nlohmann::json &j)
Definition job.cpp:60
std::vector< JOB_PARAM_BASE * > m_params
Definition job.h:274
JOB(const std::string &aType, bool aOutputIsDirectory)
Definition job.cpp:26
TITLE_BLOCK m_titleBlock
Definition job.h:260
wxString ResolveOutputPath(const wxString &aPath, bool aPathIsDirectory, PROJECT *aProject) const
Definition job.cpp:100
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
Definition job.cpp:150
virtual wxString GetDefaultDescription() const
Definition job.cpp:74
wxString m_workingOutputPath
The working output path is a transient path that takes priority over the configured output path when ...
Definition job.h:272
std::string m_type
Definition job.h:258
wxString m_tempOutputDirectory
Definition job.h:262
virtual wxString GetSettingsDialogTitle() const
Definition job.cpp:80
wxString m_description
Definition job.h:266
virtual ~JOB()
Definition job.cpp:51
bool m_outputPathIsDirectory
Definition job.h:265
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
void SetTempOutputDirectory(const wxString &aBase)
Sets the temporary output directory for the job, this is used to prefix with a given output path when...
Definition job.cpp:86
std::map< wxString, wxString > m_varOverrides
Definition job.h:259
wxString m_outputPath
Definition job.h:264
Container for project specific data.
Definition project.h:65
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:84
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:61
The common library.
#define _(s)
void PrependDirectoryToPath(wxFileName &aFileName, const wxString aDirPath)
Definition job.cpp:92
KICOMMON_API void to_json(nlohmann::json &j, const JOB &f)
Definition job.cpp:163
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition job.cpp:169
#define KICOMMON_API
Definition kicommon.h:28