25 #include <wx/filedlg.h> 26 #include <wx/wfstream.h> 27 #include <wx/zipstrm.h> 41 #define MSG_NO_MORE_LAYER _( "<b>No more available layers</b> in GerbView to load files" ) 42 #define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" ) 43 #define MSG_OOM _( "\n<b>Memory was exhausted reading:</b> <i>%s</i>" ) 90 if( !filename.IsEmpty() )
108 if( !filename.IsEmpty() )
121 static int lastGerberFileWildcard = 0;
123 wxArrayString filenamesList;
124 wxFileName filename = aFullFileName;
125 wxString currentPath;
127 if( !filename.IsOk() )
139 filetypes =
_(
"Gerber files (.g* .lgr .pho)" );
140 filetypes << wxT(
"|");
141 filetypes += wxT(
"*.g*;*.G*;*.pho;*.PHO" );
142 filetypes << wxT(
"|");
154 filetypes +=
_(
"Mechanical layers" ) +
AddFileExtListToFilter( {
"GM1",
"GM2",
"GM3",
"GM4",
"GM5",
"GM6",
"GM7",
"GM8",
"GM9" } ) + wxT(
"|" );
162 if( filename.DirExists() )
163 currentPath = filename.GetPath();
170 if( currentPath.EndsWith(
'\\' ) || currentPath.EndsWith(
'/' ) )
171 currentPath.RemoveLast();
174 wxFileDialog dlg(
this,
_(
"Open Gerber File(s)" ), currentPath, filename.GetFullName(),
176 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
177 dlg.SetFilterIndex( lastGerberFileWildcard );
179 if( dlg.ShowModal() == wxID_CANCEL )
182 lastGerberFileWildcard = dlg.GetFilterIndex();
183 dlg.GetPaths( filenamesList );
184 m_mruPath = currentPath = dlg.GetDirectory();
188 filenamesList.Add( aFullFileName );
189 m_mruPath = currentPath = filename.GetPath();
212 const wxArrayString& aFilenameList,
213 const std::vector<int>* aFileType )
227 std::unique_ptr<WX_PROGRESS_REPORTER> progress =
nullptr;
229 for(
unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
231 filename = aFilenameList[ii];
233 if( !filename.IsAbsolute() )
234 filename.SetPath( aPath );
238 if( !filename.FileExists() )
241 warning << wxT(
"<b>" ) <<
_(
"File not found:" ) << wxT(
"</b><br>" )
242 << filename.GetFullPath() << wxT(
"<br>" );
250 if( !progress && ( aFilenameList.GetCount() > 1 ) )
252 progress = std::make_unique<WX_PROGRESS_REPORTER>(
this,
253 _(
"Loading Gerber files..." ), 1,
255 progress->SetMaxProgress( aFilenameList.GetCount() - 1 );
258 aFilenameList.GetCount(),
265 aFilenameList.GetCount(),
267 progress->KeepRefreshing();
276 if( aFileType && ( *aFileType )[ii] == 1 )
287 txt.Printf(
_(
"<b>A gerber job file cannot be loaded as a plot file</b> " 289 filename.GetFullName() );
309 while( ii < aFilenameList.GetCount() )
311 filename = aFilenameList[ii++];
323 catch(
const std::bad_alloc& )
332 progress->AdvanceProgress();
368 wxArrayString filenamesList;
369 wxFileName filename = aFullFileName;
370 wxString currentPath;
372 if( !filename.IsOk() )
375 filetypes << wxT(
"|" );
381 if( filename.DirExists() )
382 currentPath = filename.GetPath();
386 wxFileDialog dlg(
this,
_(
"Open NC (Excellon) Drill File(s)" ),
387 currentPath, filename.GetFullName(), filetypes,
388 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
390 if( dlg.ShowModal() == wxID_CANCEL )
393 dlg.GetPaths( filenamesList );
394 currentPath = wxGetCwd();
399 filenamesList.Add( aFullFileName );
400 currentPath = filename.GetPath();
412 for(
unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
414 filename = filenamesList[ii];
416 if( !filename.IsAbsolute() )
417 filename.SetPath( currentPath );
437 while( ii < filenamesList.GetCount() )
439 filename = filenamesList[ii++];
474 wxFileName fn( aFullFileName );
475 wxString unzipDir = fn.GetPath();
477 wxFFileInputStream zipFile( aFullFileName );
479 if( !zipFile.IsOk() )
483 msg.Printf(
_(
"Zip file '%s' cannot be opened." ), aFullFileName );
497 wxFileName temp_fn(
"$tempfile.tmp" );
498 temp_fn.MakeAbsolute( unzipDir );
499 wxString unzipped_tempfile = temp_fn.GetFullPath();
503 wxZipInputStream zipArchive( zipFile );
505 bool reported_no_more_layer =
false;
507 while( ( entry = zipArchive.GetNextEntry() ) )
509 wxString fname = entry->GetName();
510 wxFileName uzfn = fname;
511 wxString curr_ext = uzfn.GetExt().Lower();
521 if( curr_ext[0] !=
'g' && curr_ext != wxT(
"pho" ) && curr_ext != wxT(
"drl" ) )
525 msg.Printf(
_(
"Skipped file '%s' (unknown type).\n" ), entry->GetName() );
537 msg.Printf(
_(
"Skipped file '%s' (gerber job file).\n" ), entry->GetName() );
552 if( !reported_no_more_layer )
555 reported_no_more_layer =
true;
568 wxFFileOutputStream temporary_ofile( unzipped_tempfile );
570 if( temporary_ofile.Ok() )
571 temporary_ofile.Write( zipArchive );
578 msg.Printf(
_(
"<b>Unable to create temporary file '%s'.</b>\n"),
587 if( curr_ext[0] ==
'g' || curr_ext == wxT(
"pho" ) )
604 wxRemoveFile( unzipped_tempfile );
612 msg.Printf(
_(
"<b>unzipped file %s read error</b>\n"), unzipped_tempfile );
634 #define ZipFileExtension "zip" 636 wxFileName filename = aFullFileName;
637 wxString currentPath;
639 if( !filename.IsOk() )
642 if( filename.DirExists() )
643 currentPath = filename.GetPath();
647 wxFileDialog dlg(
this,
_(
"Open Zip File" ), currentPath, filename.GetFullName(),
648 ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
650 if( dlg.ShowModal() == wxID_CANCEL )
653 filename = dlg.GetPath();
654 currentPath = wxGetCwd();
659 currentPath = filename.GetPath();
666 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 given Gerber file or selected file(s), if the filename is empty.
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.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
FILE_HISTORY m_drillFileHistory
#define MSG_NO_MORE_LAYER
unsigned GetLoadedImageCount()
Get number of loaded images.
wxString DrillFileWildcard()
#define GERBER_DRAW_LAYER(x)
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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 SetLayerHasNegatives(int aLayer, bool aNegatives=true)
Set the status of negatives presense in a particular layer.
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.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
void ReFillLayerWidget()
Change out all the layers in m_Layers; called upon loading new gerber files.
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
bool Read_EXCELLON_File(const wxString &aFullFileName)