KiCad PCB EDA Suite
gerber_jobfile_writer.h
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 1992-2018 Jean_Pierre Charras <jp.charras at wanadoo.fr>
10  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #ifndef GERBER_JOBFILE_WRITER_H
31 #define GERBER_JOBFILE_WRITER_H
32 
33 
34 // A helper enum to handle sides of some layers (silk, mask)
35 enum ONSIDE
36 {
37  SIDE_NONE = 0, // layers not present
38  SIDE_TOP = 1, // top layer only
39  SIDE_BOTTOM = 2, // bottom layer only
40  SIDE_BOTH = SIDE_TOP|SIDE_BOTTOM // both layers
41 };
42 
43 class BOARD;
44 
50 {
51 public:
52  wxArrayString m_GerberFileList; // the list of gerber filenames (without path)
53  std::vector<PCB_LAYER_ID> m_LayerId; // the list of corresponding layer id
54 };
55 
56 
70 {
71 public:
72  GERBER_JOBFILE_WRITER( BOARD* aPcb, REPORTER* aReporter = nullptr );
73 
75  {
76  }
77 
83  void AddGbrFile( PCB_LAYER_ID aLayer, wxString& aFilename )
84  {
85  m_params.m_GerberFileList.Add( aFilename );
86  m_params.m_LayerId.push_back( aLayer );
87  }
88 
94  bool CreateJobFile( const wxString& aFullFilename );
95 
102  bool WriteJSONJobFile( const wxString& aFullFilename );
103 
104 private:
110  enum ONSIDE hasSilkLayers();
111 
117  enum ONSIDE hasSolderMasks();
118 
122  const char* sideKeyValue( enum ONSIDE aValue );
123 
127  void addJSONHeader();
128 
132  void addJSONGeneralSpecs();
133 
137  void addJSONFilesAttributes();
138 
144  void addJSONMaterialStackup();
145 
149  void addJSONDesignRules();
150 
155  void removeJSONSepararator();
156 
160  void addIndent() { m_JSONbuffer.Append( ' ', m_indent ); }
161 
165  void openBlock() { addIndent(); m_JSONbuffer << "{\n"; m_indent += 2; }
166 
170  void openArrayBlock() { addIndent(); m_JSONbuffer << "[\n"; m_indent += 2; }
171 
175  void closeBlock() { m_indent -= 2; addIndent(); m_JSONbuffer << "}\n"; }
176 
180  void closeBlockWithSep() { m_indent -= 2; addIndent(); m_JSONbuffer << "},\n"; }
181 
185  void closeArrayBlock() { m_indent -= 2; addIndent(); m_JSONbuffer << "]\n"; }
186 
190  void closeArrayBlockWithSep() { m_indent -= 2; addIndent(); m_JSONbuffer << "],\n"; }
191 
195  void addJSONObject( const wxString& aParam )
196  {
197  addIndent(); m_JSONbuffer << aParam;
198  }
199 
200  void addJSONObject( const char* aParam )
201  {
202  addIndent(); m_JSONbuffer << aParam;
203  }
204 
205 private:
206  BOARD* m_pcb; // The board
207  REPORTER* m_reporter; // a reporter for messages (can be null)
208  JOBFILE_PARAMS m_params; // the list of various prms and data to write in a job file
209  double m_conversionUnits; // scaling factor to convert brd units to gerber units (mm)
210  wxString m_JSONbuffer; // a buffer to build the JSON data
211  int m_indent; // helper for JSON format: the current indentation value
212 };
213 
214 #endif // #ifndef GERBER_JOBFILE_WRITER_H
class JOBFILE_PARAMS store the list of parameters written in Gerber job file especialy list of ...
void closeArrayBlock()
close a JSON array block: decrement indentation and add &#39;]&#39;
void addJSONObject(const wxString &aParam)
Add aParam to m_JSONbuffer, with suitable indentation.
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void closeBlock()
close a JSON block: decrement indentation and add &#39;}&#39;
void openBlock()
open a JSON block: add &#39;{&#39; and increment indentation
wxArrayString m_GerberFileList
PCB_LAYER_ID
A quick note on layer IDs:
GERBER_JOBFILE_WRITER is a class used to create Gerber job file a Gerber job file stores info to make...
void AddGbrFile(PCB_LAYER_ID aLayer, wxString &aFilename)
add a gerber file name and type in job file list
void openArrayBlock()
open a JSON array block: add &#39;[&#39; and increment indentation
void closeBlockWithSep()
close a JSON block: decrement indentation and add &#39;}&#39; and &#39;,&#39;
void closeArrayBlockWithSep()
close a JSON array block: decrement indentation and add &#39;]&#39; and &#39;,&#39;
void addJSONObject(const char *aParam)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
std::vector< PCB_LAYER_ID > m_LayerId
void addIndent()
add m_indent spaces in m_JSONbuffer