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 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 ( const wxString &  aFileName,
REPORTER aReporter 
)
inline

Definition at line 80 of file job_file_reader.cpp.

References m_filename, and m_reporter.

81  {
82  m_filename = aFileName;
83  m_reporter = aReporter;
84  }
GERBER_JOBFILE_READER::~GERBER_JOBFILE_READER ( )
inline

Definition at line 86 of file job_file_reader.cpp.

References ReadGerberJobFile().

86 {}

Member Function Documentation

wxArrayString& GERBER_JOBFILE_READER::GetGerberFiles ( )
inline

read a .gbrjob file

Definition at line 89 of file job_file_reader.cpp.

References m_GerberFiles.

89 { return m_GerberFiles; }
wxArrayString m_GerberFiles
bool GERBER_JOBFILE_READER::ReadGerberJobFile ( )

Definition at line 98 of file job_file_reader.cpp.

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

Referenced by ~GERBER_JOBFILE_READER().

99 {
100  // Read the gerber file */
101  FILE* jobFile = wxFopen( m_filename.GetFullPath(), wxT( "rt" ) );
102 
103  if( jobFile == nullptr )
104  return false;
105 
106  LOCALE_IO toggleIo;
107 
108  FILE_LINE_READER jobfileReader( jobFile, m_filename.GetFullPath() ); // Will close jobFile
109 
110  wxString msg;
111  wxString data;
112 
113  // detect the file format: old (deprecated) gerber format of official JSON format
114  bool json_format = false;
115 
116  char* line = jobfileReader.ReadLine();
117 
118  if( !line ) // end of file
119  return false;
120 
121  data = line;
122 
123  if( data.Contains( "{" ) )
124  json_format = true;
125 
126  if( json_format )
127  {
128  while( ( line = jobfileReader.ReadLine() ) )
129  data << '\n' << line;
130 
131  std::string err;
132  json11::Json json_parser = json11::Json::parse( TO_UTF8( data ), err );
133 
134  if( !err.empty() )
135  return false;
136 
137  for( auto& entry : json_parser["FilesAttributes"].array_items() )
138  {
139  //wxLogMessage( entry.dump().c_str() );
140  std::string name = entry["Path"].string_value();
141  //wxLogMessage( name.c_str() );
142  m_GerberFiles.Add( FormatStringFromGerber( name ) );
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:179
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
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:109
string & err
Definition: json11.cpp:598
const char * name
Definition: DXF_plotter.cpp:61
wxArrayString m_GerberFiles
wxString FormatStringFromGerber(const wxString &aString)
This helper function make the inverse conversion of formatStringToGerber() It converts a "normalized"...

Member Data Documentation

wxFileName GERBER_JOBFILE_READER::m_filename
private

Definition at line 93 of file job_file_reader.cpp.

Referenced by GERBER_JOBFILE_READER(), and ReadGerberJobFile().

wxArrayString GERBER_JOBFILE_READER::m_GerberFiles
private

Definition at line 94 of file job_file_reader.cpp.

Referenced by GetGerberFiles(), and ReadGerberJobFile().

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: