KiCad PCB EDA Suite
Loading...
Searching...
No Matches
job_export_pcb_fab.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <magic_enum.hpp>
23
24
45
47 {
50 } )
51
52
53JOB_EXPORT_PCB_FAB::JOB_EXPORT_PCB_FAB( const std::string& aType ) : JOB( aType, false )
54{
55 m_params.emplace_back( new JOB_PARAM<wxString>( "drawing_sheet", &m_drawingSheet, m_drawingSheet ) );
56 m_params.emplace_back( new JOB_PARAM<UNITS>( "units", &m_units, m_units ) );
57 m_params.emplace_back( new JOB_PARAM<int>( "precision", &m_precision, m_precision ) );
58 m_params.emplace_back( new JOB_PARAM_LIST<wxString>( "variant_names", &m_variantNames, m_variantNames ) );
59 m_params.emplace_back( new JOB_PARAM<bool>( "check_zones", &m_checkZonesBeforeExport,
60 m_checkZonesBeforeExport ) );
61 m_params.emplace_back( new JOB_PARAM<wxString>( "field_bom_map.mfg_pn", &m_colMfgPn,
62 m_colMfgPn ) );
63 m_params.emplace_back( new JOB_PARAM<DATA_SET>( "data_set", &m_dataSet, m_dataSet ) );
64 m_params.emplace_back( new JOB_PARAM<NET_NAMES>( "net_names", &m_netNames, m_netNames ) );
65}
66
67
69{
70 if( aToken.IsEmpty() )
71 return DATA_SET::USERDEF;
72
73 // The magic_enum comparison folds ASCII only, so tr_TR cannot break FABRICATION
74 return magic_enum::enum_cast<DATA_SET>( std::string( aToken.ToUTF8() ), magic_enum::case_insensitive )
75 .value_or( DATA_SET::COUNT );
76}
77
78
80{
81 nlohmann::json token = aDataSet;
82
83 // COUNT has no token, and the CLI asks from a static constructor where a throw aborts
84 return token.is_string() ? token.get<std::string>() : std::string();
85}
86
87
88void JOB_EXPORT_PCB_FAB::FromJson( const nlohmann::json& aJson )
89{
90 JOB::FromJson( aJson );
91
92 if( !aJson.contains( "variant_names" ) )
93 {
94 wxString legacy = aJson.value( "variant", wxString() );
95
96 if( !legacy.IsEmpty() )
97 {
98 m_variantNames = { legacy };
99 }
100 }
101
102 // Older files hold an empty key when nothing was chosen, so only the flag marks an empty choice
103 wxString sections = aJson.value( "sections", wxString() );
104
105 if( !sections.IsEmpty() || aJson.value( "custom_sections", false ) )
106 m_sections = sections;
107 else
108 m_sections.reset();
109}
110
111
112void JOB_EXPORT_PCB_FAB::ToJson( nlohmann::json& aJson ) const
113{
114 JOB::ToJson( aJson );
115 aJson["variant"] = m_variantNames.empty() ? wxString() : m_variantNames.front();
116 aJson["sections"] = m_sections.value_or( wxString() );
117 aJson["custom_sections"] = m_sections && m_sections->IsEmpty();
118}
void FromJson(const nlohmann::json &aJson) override
DATA_SET
Columns of the IPC-2581C function mode table, Table 4 p 80.
static std::string DataSetToken(DATA_SET aDataSet)
Lower case token that the job file and the CLI use for aDataSet Empty when it has none.
JOB_EXPORT_PCB_FAB(const std::string &aType)
void ToJson(nlohmann::json &aJson) const override
std::optional< wxString > m_sections
Section key that replaces the optional sections of the data set Unset lets the data set select them a...
static DATA_SET DataSetFromToken(const wxString &aToken)
Read a data set token in upper case or in lower case An empty token is USERDEF.
NET_NAMES
An anonymous name keeps the connections.
std::vector< wxString > m_variantNames
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:184
virtual void FromJson(const nlohmann::json &j)
Definition job.cpp:60
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
NLOHMANN_JSON_SERIALIZE_ENUM(JOB_EXPORT_PCB_FAB::UNITS, { { JOB_EXPORT_PCB_FAB::UNITS::INCH, "in" }, { JOB_EXPORT_PCB_FAB::UNITS::MM, "mm" }, }) NLOHMANN_JSON_SERIALIZE_ENUM(JOB_EXPORT_PCB_FAB