KiCad PCB EDA Suite
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 (C) 1992-2021 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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 /*
30  * Manage the gerber extensions (attributes) in the new X2 version
31  * only few extensions are handled
32  * See http://www.ucamco.com/files/downloads/file/81/the_gerber_file_format_specification.pdf
33  *
34  * gerber attributes in the new X2 version look like:
35  * %TF.FileFunction,Copper,L1,Top*%
36  *
37  * Currently:
38  * .FileFunction .FileFunction Identifies the file's function in the PCB.
39  * Other Standard Attributes, not yet used in Gerbview:
40  * .Part Identifies the part the file represents, e.g. a single PCB
41  * .MD5 Sets the MD5 file signature or checksum.
42  */
43 
44 #include <wx/log.h>
45 #include <X2_gerber_attributes.h>
46 #include <macros.h>
47 
48 
50 {
51 }
52 
53 
55 {
56 }
57 
58 
59 const wxString& X2_ATTRIBUTE::GetAttribute()
60 {
61  return m_Prms.Item( 0 );
62 }
63 
64 
65 const wxString& X2_ATTRIBUTE::GetPrm( int aIdx )
66 {
67  static const wxString dummy;
68 
69  if( GetPrmCount() > aIdx && aIdx >= 0 )
70  return m_Prms.Item( aIdx );
71 
72  return dummy;
73 }
74 
75 
77 {
78  wxLogMessage( wxT( "prms count %d" ), GetPrmCount() );
79 
80  for( int ii = 0; ii < GetPrmCount(); ii++ )
81  wxLogMessage( m_Prms.Item( ii ) );
82 }
83 
84 
85 bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText,
86  int& aLineNum )
87 {
88  // parse a TF, TA, TO ... command and fill m_Prms by the parameters found.
89  // the "%TF" (start of command) is already read by the caller
90 
91  bool ok = true;
92  std::string data;
93 
94  for( ; ; )
95  {
96  while( *aText )
97  {
98  switch( *aText )
99  {
100  case '%': // end of command
101  return ok; // success completion
102 
103  case ' ':
104  case '\r':
105  case '\n':
106  aText++;
107  break;
108 
109  case '*': // End of block
110  m_Prms.Add( FROM_UTF8( data.c_str() ) );
111  data.clear();
112  aText++;
113  break;
114 
115  case ',': // End of parameter (separator)
116  aText++;
117  m_Prms.Add( FROM_UTF8( data.c_str() ) );
118  data.clear();
119  break;
120 
121  default:
122  data += *aText;
123  aText++;
124  break;
125  }
126  }
127 
128  // end of current line, read another one.
129  if( aBuffer && aFile )
130  {
131  if( fgets( aBuffer, aBuffSize, aFile ) == nullptr )
132  {
133  // end of file
134  ok = false;
135  break;
136  }
137 
138  aLineNum++;
139  aText = aBuffer;
140  }
141  else
142  {
143  return ok;
144  }
145  }
146 
147  return ok;
148 }
149 
150 
152  : X2_ATTRIBUTE()
153 {
154  m_Prms = aAttributeBase.GetPrms();
155  m_z_order = 0;
156 
157  // ensure at least 7 parameters exist.
158  while( GetPrmCount() < 7 )
159  m_Prms.Add( wxEmptyString );
160 
161  set_Z_Order();
162 }
163 
164 
166 {
167  // the type of layer (Copper, Soldermask ... )
168  return m_Prms.Item( 1 );
169 }
170 
171 
173 {
174  // the brd layer identifier: Ln (for Copper type) or Top, Bot
175  return m_Prms.Item( 2 );
176 }
177 
178 
180 {
181  // the layer pair identifiers, for drill files, i.e.
182  // with m_Prms.Item( 1 ) = "Plated" or "NonPlated"
183  wxString lpair = m_Prms.Item( 2 ) + ',' + m_Prms.Item( 3 );
184  return lpair;
185 }
186 
187 
189 {
190  if( IsCopper() )
191  // the brd layer identifier: Top, Bot, Inr
192  return m_Prms.Item( 3 );
193  else
194  // the brd layer identifier: Top, Bot ( same as GetBrdLayerId() )
195  return m_Prms.Item( 2 );
196 }
197 
198 
200 {
201  if( IsCopper() )
202  return m_Prms.Item( 4 );
203  else
204  return m_Prms.Item( 3 );
205 }
206 
207 
209 {
210  // Only for drill files: the Layer Pair type (PTH, NPTH, Blind or Buried)
211  return m_Prms.Item( 4 );
212 }
213 
214 
216 {
217  // Only for drill files: the drill/routing type(Drill, Route, Mixed)
218  return m_Prms.Item( 5 );
219 }
220 
221 
223 {
224  // the filefunction label, if any
225  return GetFileType().IsSameAs( wxT( "Copper" ), false );
226 }
227 
228 
230 {
231  // the filefunction label, if any
232  return GetFileType().IsSameAs( wxT( "Plated" ), false )
233  || GetFileType().IsSameAs( wxT( "NonPlated" ), false );
234 }
235 
236 
238 {
239  m_z_order = -100; // low level
240  m_z_sub_order = 0;
241 
242  if( IsCopper() )
243  {
244  // Copper layer: the priority is the layer Id
245  m_z_order = 0;
246  wxString num = GetBrdLayerId().Mid( 1 );
247  long lnum;
248 
249  if( num.ToLong( &lnum ) )
250  m_z_sub_order = -lnum;
251  }
252 
253  if( GetFileType().IsSameAs( wxT( "Paste" ), false ) )
254  {
255  // solder paste layer: the priority is top then bottom
256  m_z_order = 1; // for top
257 
258  if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
259  m_z_order = -m_z_order;
260  }
261 
262  if( GetFileType().IsSameAs( wxT( "Soldermask" ), false ) )
263  {
264  // solder mask layer: the priority is top then bottom
265  m_z_order = 2; // for top
266 
267  if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
268  m_z_order = -m_z_order;
269  }
270 
271  if( GetFileType().IsSameAs( wxT( "Legend" ), false ) )
272  {
273  // Silk screen layer: the priority is top then bottom
274  m_z_order = 3; // for top
275 
276  if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
277  m_z_order = -m_z_order;
278  }
279 
280  if( GetFileType().IsSameAs( wxT( "Glue" ), false ) )
281  {
282  // Glue spots used to fix components to the board prior to soldering:
283  // the priority is top then bottom
284  m_z_order = 4; // for top
285 
286  if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
287  m_z_order = -m_z_order;
288  }
289 }
290 
const wxString & GetFileType()
the type of layer (Copper, Soldermask ... )
The attribute value consists of a number of substrings separated by a comma.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
const wxString & GetPrm(int aIdx)
bool IsCopper()
return true if the filefunction type is "Copper"
This file contains miscellaneous commonly used macros and functions.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
wxArrayString & GetPrms()
void set_Z_Order()
Initialize the z order priority of the current file, from its attributes.
X2_ATTRIBUTE_FILEFUNCTION(X2_ATTRIBUTE &aAttributeBase)
const wxString & GetLabel()
the filefunction label, if any
const wxString & GetBrdLayerId()
the brd layer identifier: Ln, only for Copper type or Top, Bot for other types
const wxString & GetBrdLayerSide()
the brd layer Pos: Top, Bot, Inr same as GetBrdLayerId() for non copper type
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.
void DbgListPrms()
Debug function: print using wxLogMessage le list of parameters.
const wxString & GetAttribute()
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...