KiCad PCB EDA Suite
Loading...
Searching...
No Matches
job_import_utils.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef JOB_IMPORT_UTILS_H
21#define JOB_IMPORT_UTILS_H
22
23#include <kicommon.h>
24#include <json_common.h>
25#include <reporter.h>
26#include <wx/string.h>
27#include <map>
28#include <utility>
29#include <vector>
30
40
41
43 {
47 } )
48
49
54struct KICOMMON_API IMPORT_REPORT_DATA
55{
56 wxString m_sourceFile;
57 wxString m_sourceFormat;
58 wxString m_outputFile;
59
62 std::vector<std::pair<wxString, size_t>> m_statistics;
63
66 nlohmann::json m_extraJson = nlohmann::json::object();
67
68 std::vector<wxString> m_warnings;
69 std::vector<wxString> m_errors;
70};
71
72
79{
80public:
81 explicit IMPORT_MESSAGE_COLLECTOR( REPORTER& aJobReporter ) :
82 m_jobReporter( aJobReporter )
83 { }
84
86
87 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
88
89 bool HasMessage() const override { return !m_warnings.empty() || !m_errors.empty(); }
90
91 void Clear() override;
92
97 void Flush( IMPORT_REPORT_FORMAT aFormat, IMPORT_REPORT_DATA& aData );
98
99private:
100 void forward();
101
103 std::vector<wxString> m_warnings;
104 std::vector<wxString> m_errors;
105};
106
107
113KICOMMON_API bool ParseImportReportFormat( const wxString& aText, IMPORT_REPORT_FORMAT& aFormat );
114
115
120KICOMMON_API wxString DefaultImportOutputPath( const wxString& aInputFile,
121 const wxString& aKiCadExt );
122
123
132KICOMMON_API bool LoadLayerMapFile( const wxString& aFile, std::map<wxString, wxString>& aMap,
133 wxString& aError );
134
135
143 const wxString& aReportFile, const IMPORT_REPORT_DATA& aData );
144
145#endif
Reporter handed to an importer during an import job.
bool HasMessage() const override
Returns true if any messages were reported.
IMPORT_MESSAGE_COLLECTOR(REPORTER &aJobReporter)
std::vector< wxString > m_warnings
std::vector< wxString > m_errors
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual void Clear()
Definition reporter.h:162
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
REPORTER()
Definition reporter.h:75
@ NONE
Definition eda_fill.h:42
KICOMMON_API bool LoadLayerMapFile(const wxString &aFile, std::map< wxString, wxString > &aMap, wxString &aError)
Load an explicit layer-mapping file into aMap.
NLOHMANN_JSON_SERIALIZE_ENUM(IMPORT_REPORT_FORMAT, { { IMPORT_REPORT_FORMAT::NONE, "none" }, { IMPORT_REPORT_FORMAT::JSON, "json" }, { IMPORT_REPORT_FORMAT::TEXT, "text" } }) struct KICOMMON_API IMPORT_REPORT_DATA
Data describing a completed import, rendered uniformly by WriteImportReport for both the board and sc...
KICOMMON_API bool ParseImportReportFormat(const wxString &aText, IMPORT_REPORT_FORMAT &aFormat)
Parse the user-facing report format name ("none", "json" or "text") into its enum.
KICOMMON_API wxString DefaultImportOutputPath(const wxString &aInputFile, const wxString &aKiCadExt)
Build the default output path for an import by swapping the input file's extension for the given KiCa...
IMPORT_REPORT_FORMAT
Output format for the report shared by the board and schematic import jobs.
KICOMMON_API bool WriteImportReport(REPORTER *aReporter, IMPORT_REPORT_FORMAT aFormat, const wxString &aReportFile, const IMPORT_REPORT_DATA &aData)
Emit an import report in the requested format to aReportFile, or to aReporter (at INFO severity) when...
#define KICOMMON_API
Definition kicommon.h:27
SEVERITY
@ RPT_SEVERITY_UNDEFINED