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 80 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 83 of file job_file_reader.cpp.

84  {
85  m_filename = aFileName;
86  m_reporter = aReporter;
87  }

References m_filename, and m_reporter.

◆ ~GERBER_JOBFILE_READER()

GERBER_JOBFILE_READER::~GERBER_JOBFILE_READER ( )
inline

Definition at line 89 of file job_file_reader.cpp.

89 {}

Member Function Documentation

◆ formatStringFromJSON()

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

Definition at line 167 of file job_file_reader.cpp.

168 {
169  // Convert a JSON string, that uses a escaped sequence of 4 hexadecimal digits
170  // to encode unicode chars
171  // Our json11 library returns in this case a UTF8 sequence. Just convert it to
172  // a wxString.
173  wxString wstr = FROM_UTF8( name.c_str() );
174  return wstr;
175 }
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 char * name
Definition: DXF_plotter.cpp:56

References FROM_UTF8(), and name.

Referenced by ReadGerberJobFile().

◆ GetGerberFiles()

wxArrayString& GERBER_JOBFILE_READER::GetGerberFiles ( )
inline

read a .gbrjob file

Definition at line 92 of file job_file_reader.cpp.

92 { return m_GerberFiles; }
wxArrayString m_GerberFiles

References m_GerberFiles.

◆ ReadGerberJobFile()

bool GERBER_JOBFILE_READER::ReadGerberJobFile ( )

Definition at line 106 of file job_file_reader.cpp.

107 {
108  // Read the gerber file */
109  FILE* jobFile = wxFopen( m_filename.GetFullPath(), wxT( "rt" ) );
110 
111  if( jobFile == nullptr )
112  return false;
113 
114  LOCALE_IO toggleIo;
115 
116  FILE_LINE_READER jobfileReader( jobFile, m_filename.GetFullPath() ); // Will close jobFile
117 
118  wxString msg;
119  wxString data;
120 
121  // detect the file format: old (deprecated) gerber format of official JSON format
122  bool json_format = false;
123 
124  char* line = jobfileReader.ReadLine();
125 
126  if( !line ) // end of file
127  return false;
128 
129  data = line;
130 
131  if( data.Contains( wxT( "{" ) ) )
132  json_format = true;
133 
134  if( json_format )
135  {
136  while( ( line = jobfileReader.ReadLine() ) )
137  data << '\n' << line;
138 
139  try
140  {
141  json js = json::parse( TO_UTF8( data ) );
142 
143  for( json& entry : js["FilesAttributes"] )
144  {
145  std::string name = entry["Path"].get<std::string>();
147  }
148  }
149  catch( ... )
150  {
151  return false;
152  }
153  }
154  else
155  {
156  if( m_reporter )
157  m_reporter->ReportTail( _( "This job file uses an outdated format. Please recreate it." ),
159 
160  return false;
161  }
162 
163  return true;
164 }
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:214
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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)
Places the report at the end of the list, for objects that support report ordering.
Definition: reporter.h:99
nlohmann::json json
Definition: gerbview.cpp:41
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define _(s)
const char * name
Definition: DXF_plotter.cpp:56
wxArrayString m_GerberFiles
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 96 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 97 of file job_file_reader.cpp.

Referenced by GetGerberFiles(), and ReadGerberJobFile().

◆ m_reporter

REPORTER* GERBER_JOBFILE_READER::m_reporter
private

Definition at line 95 of file job_file_reader.cpp.

Referenced by GERBER_JOBFILE_READER(), and ReadGerberJobFile().


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