KiCad PCB EDA Suite
Loading...
Searching...
No Matches
X2_gerber_attributes.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) 2010-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
24
25/*
26 * Manage the gerber extensions (attributes) in the new X2 version
27 * only few extensions are handled
28 * See http://www.ucamco.com/files/downloads/file/81/the_gerber_file_format_specification.pdf
29 *
30 * gerber attributes in the new X2 version look like:
31 * %TF.FileFunction,Copper,L1,Top*%
32 *
33 * Currently:
34 * .FileFunction .FileFunction Identifies the file's function in the PCB.
35 * Other Standard Attributes, not yet used in Gerbview:
36 * .Part Identifies the part the file represents, e.g. a single PCB
37 * .MD5 Sets the MD5 file signature or checksum.
38 */
39
40#include <wx/log.h>
42#include <string_utils.h>
43
44
48
49
53
54
56{
57 return m_Prms.Item( 0 );
58}
59
60
61const wxString& X2_ATTRIBUTE::GetPrm( int aIdx )
62{
63 static const wxString dummy;
64
65 if( GetPrmCount() > aIdx && aIdx >= 0 )
66 return m_Prms.Item( aIdx );
67
68 return dummy;
69}
70
71
73{
74 wxLogMessage( wxT( "prms count %d" ), GetPrmCount() );
75
76 for( int ii = 0; ii < GetPrmCount(); ii++ )
77 wxLogMessage( m_Prms.Item( ii ) );
78}
79
80
81bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText,
82 int& aLineNum )
83{
84 // parse a TF, TA, TO ... command and fill m_Prms by the parameters found.
85 // the "%TF" (start of command) is already read by the caller
86
87 bool ok = true;
88 std::string data;
89
90 for( ; ; )
91 {
92 while( *aText )
93 {
94 switch( *aText )
95 {
96 case '%': // end of command
97 return ok; // success completion
98
99 case ' ':
100 case '\r':
101 case '\n':
102 aText++;
103 break;
104
105 case '*': // End of block
106 m_Prms.Add( From_UTF8( data.c_str() ) );
107 data.clear();
108 aText++;
109 break;
110
111 case ',': // End of parameter (separator)
112 aText++;
113 m_Prms.Add( From_UTF8( data.c_str() ) );
114 data.clear();
115 break;
116
117 default:
118 data += *aText;
119 aText++;
120 break;
121 }
122 }
123
124 // end of current line, read another one.
125 if( aBuffer && aFile )
126 {
127 if( fgets( aBuffer, aBuffSize, aFile ) == nullptr )
128 {
129 // end of file
130 ok = false;
131 break;
132 }
133
134 aLineNum++;
135 aText = aBuffer;
136 }
137 else
138 {
139 return ok;
140 }
141 }
142
143 return ok;
144}
145
146
148 : X2_ATTRIBUTE()
149{
150 m_Prms = aAttributeBase.GetPrms();
151 m_z_order = 0;
152
153 // ensure at least 7 parameters exist.
154 while( GetPrmCount() < 7 )
155 m_Prms.Add( wxEmptyString );
156
157 set_Z_Order();
158}
159
160
162{
163 // the type of layer (Copper, Soldermask ... )
164 return m_Prms.Item( 1 );
165}
166
167
169{
170 // the brd layer identifier: Ln (for Copper type) or Top, Bot
171 return m_Prms.Item( 2 );
172}
173
174
176{
177 // the layer pair identifiers, for drill files, i.e.
178 // with m_Prms.Item( 1 ) = "Plated" or "NonPlated"
179 wxString lpair = m_Prms.Item( 2 ) + ',' + m_Prms.Item( 3 );
180 return lpair;
181}
182
183
185{
186 if( IsCopper() )
187 // the brd layer identifier: Top, Bot, Inr
188 return m_Prms.Item( 3 );
189 else
190 // the brd layer identifier: Top, Bot ( same as GetBrdLayerId() )
191 return m_Prms.Item( 2 );
192}
193
194
196{
197 if( IsCopper() )
198 return m_Prms.Item( 4 );
199 else
200 return m_Prms.Item( 3 );
201}
202
203
205{
206 // Only for drill files: the Layer Pair type (PTH, NPTH, Blind or Buried)
207 return m_Prms.Item( 4 );
208}
209
210
212{
213 // Only for drill files: the drill/routing type(Drill, Route, Mixed)
214 return m_Prms.Item( 5 );
215}
216
217
219{
220 // the filefunction label, if any
221 return GetFileType().IsSameAs( wxT( "Copper" ), false );
222}
223
224
226{
227 // the filefunction label, if any
228 return GetFileType().IsSameAs( wxT( "Plated" ), false )
229 || GetFileType().IsSameAs( wxT( "NonPlated" ), false );
230}
231
232
234{
235 m_z_order = 100; // high level
236 m_z_sub_order = 0;
237
238 if( IsCopper() )
239 {
240 // Copper layer: the priority is the layer Id
241 m_z_order = 0;
242 wxString num = GetBrdLayerId().Mid( 1 );
243 long lnum;
244
245 if( num.ToLong( &lnum ) )
246 m_z_sub_order = -lnum;
247 }
248
249 if( GetFileType().IsSameAs( wxT( "Soldermask" ), false ) )
250 {
251 // solder mask layer: the priority is top then bottom
252 m_z_order = 1; // for top
253
254 if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
256 }
257
258 if( GetFileType().IsSameAs( wxT( "Legend" ), false ) )
259 {
260 // Silk screen layer: the priority is top then bottom
261 m_z_order = 2; // for top
262
263 if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
265 }
266
267 if( GetFileType().IsSameAs( wxT( "Paste" ), false ) )
268 {
269 // solder paste layer: the priority is top then bottom
270 m_z_order = 3; // for top
271
272 if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
274 }
275
276 if( GetFileType().IsSameAs( wxT( "Glue" ), false ) )
277 {
278 // Glue spots used to fix components to the board prior to soldering:
279 // the priority is top then bottom
280 m_z_order = 4; // for top
281
282 if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
284 }
285}
286
bool IsCopper()
return true if the filefunction type is "Copper"
X2_ATTRIBUTE_FILEFUNCTION(X2_ATTRIBUTE &aAttributeBase)
const wxString & GetBrdLayerSide()
the brd layer Pos: Top, Bot, Inr same as GetBrdLayerId() for non copper type
const wxString & GetFileType()
the type of layer (Copper, Soldermask ... )
const wxString & GetLabel()
the filefunction label, if any
void set_Z_Order()
Initialize the z order priority of the current file, from its attributes.
const wxString & GetBrdLayerId()
the brd layer identifier: Ln, only for Copper type or Top, Bot for other types
const wxString & GetPrm(int aIdx)
void DbgListPrms()
Debug function: print using wxLogMessage le list of parameters.
const wxString & GetAttribute()
bool ParseAttribCmd(FILE *aFile, char *aBuffer, int aBuffSize, char *&aText, int &aLineNum)
Parse a TF command terminated with a % and fill m_Prms by the parameters found.
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...
wxArrayString & GetPrms()
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)