25 #include <wx/wfstream.h> 26 #include <wx/zipstrm.h> 39 #define MSG_NO_MORE_LAYER _( "<b>No more available layers</b> in GerbView to load files" ) 40 #define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" ) 87 if( !filename.IsEmpty() )
105 if( !filename.IsEmpty() )
118 static int lastGerberFileWildcard = 0;
120 wxArrayString filenamesList;
121 wxFileName filename = aFullFileName;
122 wxString currentPath;
124 if( !filename.IsOk() )
136 filetypes =
_(
"Gerber files (.g* .lgr .pho)" );
137 filetypes << wxT(
"|");
138 filetypes += wxT(
"*.g*;*.G*;*.pho;*.PHO" );
139 filetypes << wxT(
"|");
142 filetypes +=
_(
"Top layer (*.GTL)|*.GTL;*.gtl|" );
143 filetypes +=
_(
"Bottom layer (*.GBL)|*.GBL;*.gbl|" );
144 filetypes +=
_(
"Bottom solder resist (*.GBS)|*.GBS;*.gbs|" );
145 filetypes +=
_(
"Top solder resist (*.GTS)|*.GTS;*.gts|" );
146 filetypes +=
_(
"Bottom overlay (*.GBO)|*.GBO;*.gbo|" );
147 filetypes +=
_(
"Top overlay (*.GTO)|*.GTO;*.gto|" );
148 filetypes +=
_(
"Bottom paste (*.GBP)|*.GBP;*.gbp|" );
149 filetypes +=
_(
"Top paste (*.GTP)|*.GTP;*.gtp|" );
150 filetypes +=
_(
"Keep-out layer (*.GKO)|*.GKO;*.gko|" );
151 filetypes +=
_(
"Mechanical layers (*.GMx)|*.GM1;*.gm1;*.GM2;*.gm2;*.GM3;*.gm3|" );
152 filetypes +=
_(
"Top Pad Master (*.GPT)|*.GPT;*.gpt|" );
153 filetypes +=
_(
"Bottom Pad Master (*.GPB)|*.GPB;*.gpb|" );
159 if( filename.DirExists() )
160 currentPath = filename.GetPath();
167 if( currentPath.EndsWith(
'\\' ) || currentPath.EndsWith(
'/' ) )
168 currentPath.RemoveLast();
171 wxFileDialog dlg(
this,
_(
"Open Gerber File(s)" ), currentPath, filename.GetFullName(),
173 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
174 dlg.SetFilterIndex( lastGerberFileWildcard );
176 if( dlg.ShowModal() == wxID_CANCEL )
179 lastGerberFileWildcard = dlg.GetFilterIndex();
180 dlg.GetPaths( filenamesList );
181 m_mruPath = currentPath = dlg.GetDirectory();
185 filenamesList.Add( aFullFileName );
186 m_mruPath = currentPath = filename.GetPath();
199 const wxArrayString& aFilenameList,
200 const std::vector<int>* aFileType )
214 std::unique_ptr<WX_PROGRESS_REPORTER> progress =
nullptr;
216 for(
unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
218 filename = aFilenameList[ii];
220 if( !filename.IsAbsolute() )
221 filename.SetPath( aPath );
225 if( !filename.FileExists() )
228 warning <<
"<b>" <<
_(
"File not found:" ) <<
"</b><br>" 229 << filename.GetFullPath() <<
"<br>";
237 if( !progress && ( aFilenameList.GetCount() > 1 ) )
239 progress = std::make_unique<WX_PROGRESS_REPORTER>(
this,
240 _(
"Loading Gerber files..." ), 1,
false );
241 progress->SetMaxProgress( aFilenameList.GetCount() - 1 );
249 progress->KeepRefreshing();
254 visibility[ layer ] =
true;
256 if( aFileType && (*aFileType)[ii] == 1 )
268 _(
"<b>A gerber job file cannot be loaded as a plot file</b> <i>%s</i>" ),
269 filename.GetFullName() );
286 while( ii < aFilenameList.GetCount() )
288 filename = aFilenameList[ii++];
300 progress->AdvanceProgress();
338 wxArrayString filenamesList;
339 wxFileName filename = aFullFileName;
340 wxString currentPath;
342 if( !filename.IsOk() )
345 filetypes << wxT(
"|" );
351 if( filename.DirExists() )
352 currentPath = filename.GetPath();
356 wxFileDialog dlg(
this,
_(
"Open NC (Excellon) Drill File(s)" ),
357 currentPath, filename.GetFullName(), filetypes,
358 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
360 if( dlg.ShowModal() == wxID_CANCEL )
363 dlg.GetPaths( filenamesList );
364 currentPath = wxGetCwd();
369 filenamesList.Add( aFullFileName );
370 currentPath = filename.GetPath();
382 for(
unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
384 filename = filenamesList[ii];
386 if( !filename.IsAbsolute() )
387 filename.SetPath( currentPath );
407 while( ii < filenamesList.GetCount() )
409 filename = filenamesList[ii++];
444 wxFileName fn( aFullFileName );
445 wxString unzipDir = fn.GetPath();
447 wxFFileInputStream zipFile( aFullFileName );
449 if( !zipFile.IsOk() )
453 msg.Printf(
_(
"Zip file \"%s\" cannot be opened" ), aFullFileName );
467 wxFileName temp_fn(
"$tempfile.tmp" );
468 temp_fn.MakeAbsolute( unzipDir );
469 wxString unzipped_tempfile = temp_fn.GetFullPath();
473 wxZipInputStream zipArchive( zipFile );
475 bool reported_no_more_layer =
false;
477 while( ( entry = zipArchive.GetNextEntry() ) )
479 wxString fname = entry->GetName();
480 wxFileName uzfn = fname;
481 wxString curr_ext = uzfn.GetExt().Lower();
491 if( curr_ext[0] !=
'g' && curr_ext !=
"pho" && curr_ext !=
"drl" )
495 msg.Printf(
_(
"Info: skip file \"%s\" (unknown type)\n" ), entry->GetName() );
507 msg.Printf(
_(
"Info: skip file \"%s\" (gerber job file)\n" ), entry->GetName() );
522 if( !reported_no_more_layer )
525 reported_no_more_layer =
true;
538 wxFFileOutputStream temporary_ofile( unzipped_tempfile );
540 if( temporary_ofile.Ok() )
541 temporary_ofile.Write( zipArchive );
548 msg.Printf(
_(
"<b>Unable to create temporary file \"%s\"</b>\n"),
557 if( curr_ext[0] ==
'g' || curr_ext ==
"pho" )
570 wxRemoveFile( unzipped_tempfile );
578 msg.Printf(
_(
"<b>unzipped file %s read error</b>\n"), unzipped_tempfile );
600 #define ZipFileExtension "zip" 602 wxFileName filename = aFullFileName;
603 wxString currentPath;
605 if( !filename.IsOk() )
608 if( filename.DirExists() )
609 currentPath = filename.GetPath();
613 wxFileDialog dlg(
this,
_(
"Open Zip File" ), currentPath, filename.GetFullName(),
614 ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
616 if( dlg.ShowModal() == wxID_CANCEL )
619 filename = dlg.GetPath();
620 currentPath = wxGetCwd();
625 currentPath = filename.GetPath();
632 if( filename.IsOk() )
void syncLayerBox(bool aRebuildLayerBox=false)
Update the currently "selected" layer within m_SelLayerBox.
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
void OnClearDrlFileHistory(wxCommandEvent &aEvent)
FILE_HISTORY m_jobFileHistory
GERBER_LAYER_WIDGET * m_LayersManager
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
Hold the image data and parameters for one gerber file and layer parameters.
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
change the currently active layer to aLayer and update the GERBER_LAYER_WIDGET.
void OnGbrFileHistory(wxCommandEvent &event)
Delete the current data and loads a Gerber file selected from history list on current layer.
wxString ZipFileWildcard()
A pure virtual class used to derive REPORTER objects from.
void Erase_Current_DrawLayer(bool query)
void OnClearZipFileHistory(wxCommandEvent &aEvent)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
wxString AllFilesWildcard()
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
void OnClearJobFileHistory(wxCommandEvent &aEvent)
FILE_HISTORY m_zipFileHistory
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
LSET is a set of PCB_LAYER_IDs.
bool unarchiveFiles(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Extract gerber and drill files from the zip archive, and load them.
#define NO_AVAILABLE_LAYERS
bool LoadGerberFiles(const wxString &aFileName)
Load a photoplot (Gerber) file or many files.
bool LoadListOfGerberAndDrillFiles(const wxString &aPath, const wxArrayString &aFilenameList, const std::vector< int > *aFileType=nullptr)
Load a list of Gerber and NC drill files and updates the view based on them.
void ListSet(const wxString &aList)
Add a list of items.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
bool LoadZipArchiveFile(const wxString &aFileName)
Load a zipped archive file.
const std::string GerberJobFileExtension
Definition of file extensions used in Kicad.
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
FILE_HISTORY m_drillFileHistory
#define MSG_NO_MORE_LAYER
wxString DrillFileWildcard()
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
A wrapper for reporting to a wxString object.
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
int GetActiveLayer() const
Return the active layer.
void OnJobFileHistory(wxCommandEvent &event)
Delete the current data and load a gerber job file selected from the history list.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void OnDrlFileHistory(wxCommandEvent &event)
Delete the current data and load a drill file in Excellon format selected from history list on curren...
bool LoadExcellonFiles(const wxString &aFileName)
Load a drill (EXCELLON) file or many files.
void OnZipFileHistory(wxCommandEvent &event)
Delete the current data and load a zip archive file selected from the history list.
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
int getNextAvailableLayer(int aLayer=0) const
Find the next empty layer starting at aLayer and returns it to the caller.
void ReFillLayerWidget()
Change out all the layers in m_Layers; called upon loading new gerber files.
bool Read_EXCELLON_File(const wxString &aFullFileName)