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 #include <kicad_json.h>
34 
35 using json = kicad::json;
36 
37 
38 // A helper enum to handle sides of some layers (silk, mask)
39 enum ONSIDE
40 {
41  SIDE_NONE = 0, // layers not present
42  SIDE_TOP = 1, // top layer only
43  SIDE_BOTTOM = 2, // bottom layer only
44  SIDE_BOTH = SIDE_TOP|SIDE_BOTTOM // both layers
45 };
46 
47 class BOARD;
48 
54 {
55 public:
56  wxArrayString m_GerberFileList; // the list of gerber filenames (without path)
57  std::vector<PCB_LAYER_ID> m_LayerId; // the list of corresponding layer id
58 };
59 
60 
74 {
75 public:
76  GERBER_JOBFILE_WRITER( BOARD* aPcb, REPORTER* aReporter = nullptr );
77 
79  {
80  }
81 
87  void AddGbrFile( PCB_LAYER_ID aLayer, wxString& aFilename )
88  {
89  m_params.m_GerberFileList.Add( aFilename );
90  m_params.m_LayerId.push_back( aLayer );
91  }
92 
98  bool CreateJobFile( const wxString& aFullFilename );
99 
106  bool WriteJSONJobFile( const wxString& aFullFilename );
107 
108 private:
114  enum ONSIDE hasSilkLayers();
115 
121  enum ONSIDE hasSolderMasks();
122 
126  const char* sideKeyValue( enum ONSIDE aValue );
127 
131  void addJSONHeader();
132 
136  void addJSONGeneralSpecs();
137 
141  void addJSONFilesAttributes();
142 
148  void addJSONMaterialStackup();
149 
153  void addJSONDesignRules();
154 
158  std::string formatStringFromUTF32( const wxString& aText );
159 
164  double mapValue( double aUiValue );
165 
166 private:
167  BOARD* m_pcb; // The board
168  REPORTER* m_reporter; // a reporter for messages (can be null)
169  JOBFILE_PARAMS m_params; // the list of various prms and data to write in a job file
170  double m_conversionUnits; // scaling factor to convert brd units to gerber units (mm)
171  json m_json; // json document built by this class
172 };
173 
174 #endif // #ifndef GERBER_JOBFILE_WRITER_H
JOBFILE_PARAMS store the list of parameters written in Gerber job file especialy list of ....
std::string formatStringFromUTF32(const wxString &aText)
A helper function to convert a wxString ( therefore a Unicode text ) to a JSON compatible string (a e...
double mapValue(double aUiValue)
A helper function to convert a double in Pcbnew internal units to a JSON double value (in mm),...
bool CreateJobFile(const wxString &aFullFilename)
Creates a Gerber job file.
nlohmann::basic_json< json_fifo_map > json
Definition: kicad_json.h:38
void addJSONHeader()
Add the job file header in JSON format to m_JSONbuffer.
const char * sideKeyValue(enum ONSIDE aValue)
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:62
nlohmann::json json
Definition: gerbview.cpp:40
void addJSONFilesAttributes()
Add the Files Attributes section in JSON format to m_JSONbuffer.
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
bool WriteJSONJobFile(const wxString &aFullFilename)
Creates an Gerber job file in JSON format.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
void addJSONDesignRules()
Add the Design Rules section in JSON format to m_JSONbuffer.
std::vector< PCB_LAYER_ID > m_LayerId
void addJSONMaterialStackup()
Add the Material Stackup section in JSON format to m_JSONbuffer This is the ordered list of stackup l...
void addJSONGeneralSpecs()
Add the General Specs in JSON format to m_JSONbuffer.
GERBER_JOBFILE_WRITER(BOARD *aPcb, REPORTER *aReporter=nullptr)