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 <nlohmann/json_fwd.hpp>
34 
35 
36 // A helper enum to handle sides of some layers (silk, mask)
37 enum ONSIDE
38 {
39  SIDE_NONE = 0, // layers not present
40  SIDE_TOP = 1, // top layer only
41  SIDE_BOTTOM = 2, // bottom layer only
42  SIDE_BOTH = SIDE_TOP|SIDE_BOTTOM // both layers
43 };
44 
45 class BOARD;
46 
52 {
53 public:
54  wxArrayString m_GerberFileList; // the list of gerber filenames (without path)
55  std::vector<PCB_LAYER_ID> m_LayerId; // the list of corresponding layer id
56 };
57 
58 
72 {
73 public:
74  GERBER_JOBFILE_WRITER( BOARD* aPcb, REPORTER* aReporter = nullptr );
75 
77  {
78  }
79 
85  void AddGbrFile( PCB_LAYER_ID aLayer, wxString& aFilename )
86  {
87  m_params.m_GerberFileList.Add( aFilename );
88  m_params.m_LayerId.push_back( aLayer );
89  }
90 
96  bool CreateJobFile( const wxString& aFullFilename );
97 
104  bool WriteJSONJobFile( const wxString& aFullFilename );
105 
106 private:
112  enum ONSIDE hasSilkLayers();
113 
119  enum ONSIDE hasSolderMasks();
120 
124  const char* sideKeyValue( enum ONSIDE aValue );
125 
129  void addJSONHeader();
130 
134  void addJSONGeneralSpecs();
135 
139  void addJSONFilesAttributes();
140 
146  void addJSONMaterialStackup();
147 
151  void addJSONDesignRules();
152 
156  std::string formatStringFromUTF32( const wxString& aText );
157 
162  double mapValue( double aUiValue );
163 
164 private:
165  BOARD* m_pcb; // The board
166  REPORTER* m_reporter; // a reporter for messages (can be null)
167  JOBFILE_PARAMS m_params; // the list of various prms and data to write in a job file
168  double m_conversionUnits; // scaling factor to convert brd units to gerber units (mm)
169  nlohmann::ordered_json m_json; // json document built by this class
170 };
171 
172 #endif // #ifndef GERBER_JOBFILE_WRITER_H
JOBFILE_PARAMS store the list of parameters written in Gerber job file especialy list of ....
nlohmann::ordered_json m_json
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.
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:64
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.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
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)