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 74 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 77 of file job_file_reader.cpp.

78  {
79  m_filename = aFileName;
80  m_reporter = aReporter;
81  }

References m_filename, and m_reporter.

◆ ~GERBER_JOBFILE_READER()

GERBER_JOBFILE_READER::~GERBER_JOBFILE_READER ( )
inline

Definition at line 83 of file job_file_reader.cpp.

83 {}

Member Function Documentation

◆ formatStringFromJSON()

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

Definition at line 158 of file job_file_reader.cpp.

159 {
160  // Convert a JSON string, that uses a escaped sequence of 4 hexdecimal digits
161  // to encode unicode chars
162  // Our json11 library returns in this case a UTF8 sequence. Just convert it to
163  // a wxString.
164  wxString wstr = FROM_UTF8( name.c_str() );
165  return wstr;
166 }
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:62
const char * name
Definition: DXF_plotter.cpp:61

References FROM_UTF8(), and name.

Referenced by ReadGerberJobFile().

◆ GetGerberFiles()

wxArrayString& GERBER_JOBFILE_READER::GetGerberFiles ( )
inline

read a .gbrjob file

Definition at line 86 of file job_file_reader.cpp.

86 { return m_GerberFiles; }
wxArrayString m_GerberFiles

References m_GerberFiles.

◆ ReadGerberJobFile()

bool GERBER_JOBFILE_READER::ReadGerberJobFile ( )

Definition at line 100 of file job_file_reader.cpp.

101 {
102  // Read the gerber file */
103  FILE* jobFile = wxFopen( m_filename.GetFullPath(), wxT( "rt" ) );
104 
105  if( jobFile == nullptr )
106  return false;
107 
108  LOCALE_IO toggleIo;
109 
110  FILE_LINE_READER jobfileReader( jobFile, m_filename.GetFullPath() ); // Will close jobFile
111 
112  wxString msg;
113  wxString data;
114 
115  // detect the file format: old (deprecated) gerber format of official JSON format
116  bool json_format = false;
117 
118  char* line = jobfileReader.ReadLine();
119 
120  if( !line ) // end of file
121  return false;
122 
123  data = line;
124 
125  if( data.Contains( "{" ) )
126  json_format = true;
127 
128  if( json_format )
129  {
130  while( ( line = jobfileReader.ReadLine() ) )
131  data << '\n' << line;
132 
133  std::string err;
134  json11::Json json_parser = json11::Json::parse( TO_UTF8( data ), err );
135 
136  if( !err.empty() )
137  return false;
138 
139  for( auto& entry : json_parser["FilesAttributes"].array_items() )
140  {
141  std::string name = entry["Path"].string_value();
143  }
144  }
145  else
146  {
147  if( m_reporter )
148  m_reporter->ReportTail( _( "This job file uses an outdated format. Please, recreate it." ),
150 
151  return false;
152  }
153 
154  return true;
155 }
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:154
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:111
#define _(s)
string & err
Definition: json11.cpp:650
const char * name
Definition: DXF_plotter.cpp:61
wxArrayString m_GerberFiles
wxString formatStringFromJSON(const std::string &name)

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

Member Data Documentation

◆ m_filename

wxFileName GERBER_JOBFILE_READER::m_filename
private

Definition at line 90 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 91 of file job_file_reader.cpp.

Referenced by GetGerberFiles(), and ReadGerberJobFile().

◆ m_reporter

REPORTER* GERBER_JOBFILE_READER::m_reporter
private

Definition at line 89 of file job_file_reader.cpp.

Referenced by GERBER_JOBFILE_READER(), and ReadGerberJobFile().


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