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 ),
28 m_varOverrides(),
29 m_tempOutputDirectory(),
30 m_outputPath(),
31 m_outputPathIsDirectory( aOutputIsDirectory ),
32 m_description(),
33 m_workingOutputPath()
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::GetFullOutputPath( 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
108 if( aProject )
109 return aProject->TextVarResolver( token );
110
111 return false;
112 };
113
114 // use the working output path (nonsaved) over the configured path if its not empty
115 wxString outPath = m_workingOutputPath.IsEmpty() ? m_outputPath : m_workingOutputPath;
116 outPath = ExpandTextVars( outPath, &textResolver );
117
118 if( !m_tempOutputDirectory.IsEmpty() )
119 {
121 {
122 wxFileName fn( outPath );
123
124 if( fn.IsAbsolute() || outPath.IsEmpty() )
125 fn.AssignDir( m_tempOutputDirectory );
126 else
128
129 return fn.GetFullPath();
130 }
131 else
132 {
133 wxFileName fn( outPath );
134 if( fn.IsAbsolute() )
135 {
136 // uhhh, do nothing
137 // its a full path passed by cli, so we return as-is
138 // the job handlers should have fixed empty paths
139 }
140 else
141 {
143 }
144
145 return fn.GetFullPath();
146 }
147 }
148
149 return m_outputPath;
150}
151
152
153void JOB::SetConfiguredOutputPath( const wxString& aPath )
154{
155 m_outputPath = aPath;
156}
157
158
159KICOMMON_API void to_json( nlohmann::json& j, const JOB& f )
160{
161 f.ToJson( j );
162}
163
164
165KICOMMON_API void from_json( const nlohmann::json& j, JOB& f )
166{
167 f.FromJson( j );
168}
169
170
171JOB_PARAM_BASE::JOB_PARAM_BASE( const std::string& aJsonPath ) :
172 m_jsonPath( aJsonPath )
173{
174}
JOB_PARAM_BASE(const std::string &aJsonPath)
Definition: job.cpp:171
Definition: job.h:50
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:182
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
virtual void FromJson(const nlohmann::json &j)
Definition: job.cpp:60
std::vector< JOB_PARAM_BASE * > m_params
Definition: job.h:261
JOB(const std::string &aType, bool aOutputIsDirectory)
Definition: job.cpp:26
TITLE_BLOCK m_titleBlock
Definition: job.h:252
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
Definition: job.cpp:100
virtual wxString GetDefaultDescription() const
Definition: job.cpp:74
wxString m_workingOutputPath
Definition: job.h:259
wxString m_tempOutputDirectory
Definition: job.h:254
virtual wxString GetSettingsDialogTitle() const
Definition: job.cpp:80
wxString m_description
Definition: job.h:258
virtual ~JOB()
Definition: job.cpp:51
bool m_outputPathIsDirectory
Definition: job.h:257
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
wxString m_outputPath
Definition: job.h:256
Container for project specific data.
Definition: project.h:64
virtual bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:73
bool TextVarResolver(wxString *aToken, const PROJECT *aProject, int aFlags=0) const
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition: common.cpp:59
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:159
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition: job.cpp:165
#define KICOMMON_API
Definition: kicommon.h:28