KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fab_sections.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 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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "fab_sections.h"
21
22#include <array>
23
24#include <magic_enum.hpp>
25
26namespace FAB
27{
28
29namespace
30{
31
32constexpr size_t SECTION_COUNT = static_cast<size_t>( SECTION::COUNT );
33constexpr size_t MODE_COUNT = static_cast<size_t>( MODE::COUNT );
34
38
39// IPC-2581C Table 4 p 80
40// The rows follow SECTION and the columns follow MODE
41constexpr std::array<std::array<SECTION_RULE, MODE_COUNT>, SECTION_COUNT> TABLE_4 = { {
42 // UserDef BOM Stackup Fab Assembly Test Stencil DFX
43 /* K */ { { O, N, N, O, O, N, N, N } },
44 /* B */ { { O, Y, O, O, Y, Y, N, N } },
45 /* C */ { { O, N, N, N, Y, Y, O, N } },
46 /* A */ { { O, N, N, N, Y, Y, N, N } },
47 /* S */ { { O, N, Y, Y, N, N, N, N } },
48 /* U */ { { O, N, O, Y, Y, Y, Y, N } },
49 /* M */ { { O, N, N, Y, N, N, O, N } },
50 /* P */ { { O, N, N, N, O, N, Y, N } },
51 /* L */ { { O, N, N, Y, Y, Y, O, N } },
52 /* R */ { { O, N, O, Y, Y, Y, O, N } },
53 /* D */ { { O, N, O, O, O, O, O, N } },
54 /* O */ { { O, N, Y, Y, Y, Y, O, N } },
55 /* I */ { { O, N, Y, Y, N, N, N, N } },
56 /* E */ { { O, N, O, O, N, N, N, N } },
57 /* F */ { { O, N, O, O, N, N, N, N } },
58 /* G */ { { O, N, N, O, O, O, N, N } },
59 /* Y */ { { O, N, N, Y, O, Y, N, N } },
60 /* X */ { { O, O, O, O, O, O, O, Y } },
61} };
62
63constexpr std::array<char, SECTION_COUNT> SECTION_KEYS = {
64 'K', 'B', 'C', 'A', 'S', 'U', 'M', 'P', 'L', 'R', 'D', 'O', 'I', 'E', 'F', 'G', 'Y', 'X'
65};
66
67SECTION_SET sectionsWithRule( MODE aMode, SECTION_RULE aRule )
68{
69 SECTION_SET set;
70
71 for( size_t ii = 0; ii < SECTION_COUNT; ++ii )
72 {
73 SECTION section = static_cast<SECTION>( ii );
74
75 if( SectionRule( aMode, section ) == aRule )
76 set.Set( section );
77 }
78
79 return set;
80}
81
82} // namespace
83
84
85char SectionKeyChar( SECTION aSection )
86{
87 return SECTION_KEYS[static_cast<size_t>( aSection )];
88}
89
90
91std::optional<SECTION> SectionFromKeyChar( char aKey )
92{
93 for( size_t ii = 0; ii < SECTION_COUNT; ++ii )
94 {
95 if( SECTION_KEYS[ii] == aKey )
96 return static_cast<SECTION>( ii );
97 }
98
99 return std::nullopt;
100}
101
102
104{
105 return TABLE_4[static_cast<size_t>( aSection )][static_cast<size_t>( aMode )];
106}
107
108
110{
111 return sectionsWithRule( aMode, SECTION_RULE::REQUIRED );
112}
113
114
116{
117 return sectionsWithRule( aMode, SECTION_RULE::RULE_OPTIONAL );
118}
119
120
122{
123 switch( aMode )
124 {
125 // This set keeps an unconfigured export the same as before
126 case MODE::USERDEF:
127 return LegacySections();
128
129 case MODE::STACKUP:
130 return { SECTION::DIELECTRIC };
131
132 // Section 4.1.3.3 gives KSUMLROIEF as its FABRICATION example
133 case MODE::FABRICATION:
135
136 case MODE::ASSEMBLY:
138
139 default:
140 return {};
141 }
142}
143
144
146{
147 return { SECTION::DFX };
148}
149
150
152{
153 SECTION_SET set;
154 set.set();
155
156 // We didn't emit these previously, so maintain the same output
157 // until/unless this is set by user
158 set.Set( SECTION::LOGICAL_NET, false );
159 set.Set( SECTION::PHYSICAL_NET, false );
160
161 return set & ~UnsupportedSections();
162}
163
164
165bool NeedsCadData( const SECTION_SET& aSet )
166{
167 SECTION_SET inCadData = aSet;
168 inCadData.Set( SECTION::BOM_AVL, false );
169
170 return inCadData.any();
171}
172
173
174wxString SectionKeyString( const SECTION_SET& aSet )
175{
176 wxString key;
177
178 for( size_t ii = 0; ii < SECTION_COUNT; ++ii )
179 {
180 if( aSet.test( ii ) )
181 key << SECTION_KEYS[ii];
182 }
183
184 return key;
185}
186
187
188bool SectionSetFromKeyString( const wxString& aKey, SECTION_SET& aResult )
189{
190 SECTION_SET set;
191
192 for( wxUniChar ch : aKey )
193 {
194 if( !ch.IsAscii() )
195 return false;
196
197 std::optional<SECTION> section = SectionFromKeyChar( static_cast<char>( ch ) );
198
199 if( !section )
200 return false;
201
202 set.Set( *section );
203 }
204
205 aResult = set;
206 return true;
207}
208
209
210wxString ModeToken( MODE aMode )
211{
212 std::string_view name = magic_enum::enum_name( aMode );
213 return wxString::FromAscii( name.data(), name.size() );
214}
215
216
217std::optional<MODE> ModeFromToken( const wxString& aToken )
218{
219 if( aToken.IsEmpty() )
220 return std::nullopt;
221
223
224 return mode == MODE::COUNT ? std::nullopt : std::optional<MODE>( mode );
225}
226
227
228} // namespace FAB
const char * name
Set of schema sections.
SECTION_SET & Set(SECTION aSection, bool aOn=true)
static DATA_SET DataSetFromToken(const wxString &aToken)
Read a data set token in upper case or in lower case An empty token is USERDEF.
std::optional< SECTION > SectionFromKeyChar(char aKey)
Return the schema section for a Table 4 key character.
JOB_EXPORT_PCB_FAB::DATA_SET MODE
Columns of Table 4 The job owns the enum so that every layer shares one type.
wxString SectionKeyString(const SECTION_SET &aSet)
Give aSet as a sectionKey attribute value.
SECTION_RULE SectionRule(MODE aMode, SECTION aSection)
Return the Table 4 cell for aMode and aSection.
SECTION_RULE
Table 4 cell values N O and Y.
SECTION
Schema sections of the IPC-2581C function mode table, Table 4 p 80.
SECTION_SET RequiredSections(MODE aMode)
Schema sections that Table 4 marks Y for aMode.
bool SectionSetFromKeyString(const wxString &aKey, SECTION_SET &aResult)
Read a sectionKey attribute value Return false for an unknown character.
SECTION_SET OptionalSections(MODE aMode)
Schema sections that Table 4 marks O for aMode.
SECTION_SET RecommendedOptionalSections(MODE aMode)
Optional schema sections that aMode selects by default.
SECTION_SET UnsupportedSections()
Schema sections that no KiCad board supplies.
std::optional< MODE > ModeFromToken(const wxString &aToken)
Read a Table 4 function mode token in upper case or in lower case.
wxString ModeToken(MODE aMode)
Table 4 function mode token such as FABRICATION.
SECTION_SET LegacySections()
Schema sections of the content that KiCad wrote before the function modes.
bool NeedsCadData(const SECTION_SET &aSet)
True if an included schema section needs an Ecad/CadData element.
char SectionKeyChar(SECTION aSection)
Return the Table 4 key character for aSection.