KiCad PCB EDA Suite
GERBER_JOBFILE_READER Class Reference

this class read and parse a Gerber job file to extract useful info for GerbView More...

Public Member Functions

 GERBER_JOBFILE_READER (const wxString &aFileName, REPORTER *aReporter)
 
 ~GERBER_JOBFILE_READER ()
 
bool ReadGerberJobFile ()
 
wxArrayString & GetGerberFiles ()
 read a .gbrjob file More...
 

Private Member Functions

wxString formatStringFromJSON (const std::string &name)
 

Private Attributes

REPORTERm_reporter
 
wxFileName m_filename
 
wxArrayString m_GerberFiles
 

Detailed Description

this class read and parse a Gerber job file to extract useful info for GerbView

In a gerber job file, old (deprecated) format, data lines start by TF. (usual Gerber X2 info) TJ.B. (board info) TJ.D. (design info) TJ.L. (layers info) some others are not yet handled by Kicad M02* is the last line

In a gerber job file, JSON format, first lines are { "Header": and the block ( a JSON array) containing the filename of files to load is "FilesAttributes": [ { "Path": "interf_u-Composant.gbr", "FileFunction": "Copper,L1,Top", "FilePolarity": "Positive" }, { "Path": "interf_u-In1.Cu.gbr", "FileFunction": "Copper,L2,Inr", "FilePolarity": "Positive" }, ],

Definition at line 77 of file job_file_reader.cpp.

Constructor & Destructor Documentation

◆ GERBER_JOBFILE_READER()

GERBER_JOBFILE_READER::GERBER_JOBFILE_READER ( const wxString &  aFileName,
REPORTER aReporter 
)
inline

Definition at line 80 of file job_file_reader.cpp.

81  {
82  m_filename = aFileName;
83  m_reporter = aReporter;
84  }

References m_filename, and m_reporter.

◆ ~GERBER_JOBFILE_READER()

GERBER_JOBFILE_READER::~GERBER_JOBFILE_READER ( )
inline

Definition at line 86 of file job_file_reader.cpp.

86 {}

Member Function Documentation

◆ formatStringFromJSON()

wxString GERBER_JOBFILE_READER::formatStringFromJSON ( const std::string &  name)
private

Definition at line 164 of file job_file_reader.cpp.

165 {
166  // Convert a JSON string, that uses a escaped sequence of 4 hexdecimal digits
167  // to encode unicode chars
168  // Our json11 library returns in this case a UTF8 sequence. Just convert it to
169  // a wxString.
170  wxString wstr = FROM_UTF8( name.c_str() );
171  return wstr;
172 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
const char * name
Definition: DXF_plotter.cpp:60

References FROM_UTF8(), and name.

Referenced by ReadGerberJobFile().

◆ GetGerberFiles()

wxArrayString& GERBER_JOBFILE_READER::GetGerberFiles ( )
inline

read a .gbrjob file

Definition at line 89 of file job_file_reader.cpp.

89 { return m_GerberFiles; }
wxArrayString m_GerberFiles

References m_GerberFiles.

◆ ReadGerberJobFile()

bool GERBER_JOBFILE_READER::ReadGerberJobFile ( )

Definition at line 103 of file job_file_reader.cpp.

104 {
105  // Read the gerber file */
106  FILE* jobFile = wxFopen( m_filename.GetFullPath(), wxT( "rt" ) );
107 
108  if( jobFile == nullptr )
109  return false;
110 
111  LOCALE_IO toggleIo;
112 
113  FILE_LINE_READER jobfileReader( jobFile, m_filename.GetFullPath() ); // Will close jobFile
114 
115  wxString msg;
116  wxString data;
117 
118  // detect the file format: old (deprecated) gerber format of official JSON format
119  bool json_format = false;
120 
121  char* line = jobfileReader.ReadLine();
122 
123  if( !line ) // end of file
124  return false;
125 
126  data = line;
127 
128  if( data.Contains( "{" ) )
129  json_format = true;
130 
131  if( json_format )
132  {
133  while( ( line = jobfileReader.ReadLine() ) )
134  data << '\n' << line;
135 
136  try
137  {
138  json js = json::parse( TO_UTF8( data ) );
139 
140  for( json& entry : js["FilesAttributes"] )
141  {
142  std::string name = entry["Path"].get<std::string>();
144  }
145  }
146  catch( ... )
147  {
148  return false;
149  }
150  }
151  else
152  {
153  if( m_reporter )
154  m_reporter->ReportTail( _( "This job file uses an outdated format. Please recreate it." ),
156 
157  return false;
158  }
159 
160  return true;
161 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
bool parse(std::istream &aStream, bool aVerbose)
Parse a PCB or footprint file from the given input stream.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:94
nlohmann::json json
Definition: gerbview.cpp:40
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
const char * name
Definition: DXF_plotter.cpp:60
wxArrayString m_GerberFiles
#define _(s)
Definition: 3d_actions.cpp:33
#define TO_UTF8(wxstring)
wxString formatStringFromJSON(const std::string &name)

References _, formatStringFromJSON(), m_filename, m_GerberFiles, m_reporter, name, parse(), FILE_LINE_READER::ReadLine(), REPORTER::ReportTail(), RPT_SEVERITY_WARNING, and TO_UTF8.

Member Data Documentation

◆ m_filename

wxFileName GERBER_JOBFILE_READER::m_filename
private

Definition at line 93 of file job_file_reader.cpp.

Referenced by GERBER_JOBFILE_READER(), and ReadGerberJobFile().

◆ m_GerberFiles

wxArrayString GERBER_JOBFILE_READER::m_GerberFiles
private

Definition at line 94 of file job_file_reader.cpp.

Referenced by GetGerberFiles(), and ReadGerberJobFile().

◆ m_reporter

REPORTER* GERBER_JOBFILE_READER::m_reporter
private

Definition at line 92 of file job_file_reader.cpp.

Referenced by GERBER_JOBFILE_READER(), and ReadGerberJobFile().


The documentation for this class was generated from the following file: