26#include <wx/filedlg.h> 
   27#include <wx/wfstream.h> 
   28#include <wx/zipstrm.h> 
   44#define MSG_NO_MORE_LAYER _( "<b>No more available layers</b> in GerbView to load files" ) 
   45#define MSG_NOT_LOADED _( "<b>Not loaded:</b> <i>%s</i>" ) 
   46#define MSG_OOM _( "<b>Memory was exhausted reading:</b> <i>%s</i>" ) 
   87        GetMenuBar()->Refresh();
 
 
   97    if( !filename.IsEmpty() )
 
 
  111        GetMenuBar()->Refresh();
 
 
  120    if( !filename.IsEmpty() )
 
 
  132        GetMenuBar()->Refresh();
 
 
  138                                           const wxString& dialogFiletypes,
 
  139                                           const wxString& dialogTitle, 
const int filetype )
 
  141    static int lastGerberFileWildcard = 0;
 
  142    wxArrayString filenamesList;
 
  143    wxFileName    filename = aFileName;
 
  144    wxString currentPath;
 
  146    if( !filename.IsOk() )
 
  149        if( filename.DirExists() )
 
  150            currentPath = filename.GetPath();
 
  157            if( currentPath.EndsWith( 
'\\' ) || currentPath.EndsWith( 
'/' ) )
 
  158                currentPath.RemoveLast();
 
  161        wxFileDialog dlg( 
this, dialogTitle, currentPath, filename.GetFullName(), dialogFiletypes,
 
  162                          wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
 
  164        wxArrayString dummy1, dummy2;
 
  165        const int nWildcards = wxParseCommonDialogsFilter( dialogFiletypes, dummy1, dummy2 );
 
  167        if( lastGerberFileWildcard >= 0 && lastGerberFileWildcard < nWildcards )
 
  168            dlg.SetFilterIndex( lastGerberFileWildcard );
 
  170        if( dlg.ShowModal() == wxID_CANCEL )
 
  173        lastGerberFileWildcard = dlg.GetFilterIndex();
 
  174        dlg.GetPaths( filenamesList );
 
  175        m_mruPath = currentPath = dlg.GetDirectory();
 
  179        filenamesList.Add( aFileName );
 
  180        currentPath = filename.GetPath();
 
  189    std::vector<int> fileTypesVec( filenamesList.Count(), filetype );
 
 
  219    wxFileName filename = aFileName;
 
  243    filetypes += 
_( 
"Mechanical layers" )
 
  245                         { 
"gm1", 
"gm2", 
"gm3", 
"gm4", 
"gm5", 
"gm6", 
"gm7", 
"gm8", 
"gm9" } )
 
 
  261    filetypes << wxT( 
"|" );
 
 
  270                                                    const wxArrayString& aFilenameList,
 
  271                                                    std::vector<int>*    aFileType )
 
  273    wxCHECK_MSG( aFilenameList.Count() == aFileType->size(), 
false,
 
  274                 "Mismatch in file names and file types count" );
 
  288    std::unique_ptr<WX_PROGRESS_REPORTER> progress = 
nullptr;
 
  290    for( 
unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
 
  292        filename = aFilenameList[ii];
 
  294        if( !filename.IsAbsolute() )
 
  295            filename.SetPath( aPath );
 
  299        if( !filename.FileExists() )
 
  302            warning << wxT( 
"<b>" ) << 
_( 
"File not found:" ) << wxT( 
"</b><br>" )
 
  303                    << filename.GetFullPath() << wxT( 
"<br>" );
 
  313            txt.Printf( 
_( 
"<b>A gerber job file cannot be loaded as a plot file</b> " 
  315                        filename.GetFullName() );
 
  324        if( !progress && ( aFilenameList.GetCount() > 1 ) )
 
  326            progress = std::make_unique<WX_PROGRESS_REPORTER>( 
this, 
_( 
"Load Files" ), 1, 
PR_CAN_ABORT );
 
  327            progress->SetMaxProgress( aFilenameList.GetCount() - 1 );
 
  328            progress->Report( wxString::Format( 
_(
"Loading %u/%zu %s..." ),
 
  330                                                aFilenameList.GetCount(),
 
  335            progress->Report( wxString::Format( 
_(
"Loading %u/%zu %s..." ),
 
  337                                                aFilenameList.GetCount(),
 
  339            progress->KeepRefreshing();
 
  352            while( ii < aFilenameList.GetCount() )
 
  354                filename = aFilenameList[ii++];
 
  355                wxString txt = wxString::Format( 
MSG_NOT_LOADED, filename.GetFullName() );
 
  367            if( ( *aFileType )[ii] == 2 )
 
  370                    ( *aFileType )[ii] = 1;
 
  372                    ( *aFileType )[ii] = 0;
 
  375            switch( ( *aFileType )[ii] )
 
  385                        firstLoadedLayer = layer;
 
  400                        firstLoadedLayer = layer;
 
  406                wxString txt = wxString::Format( 
MSG_NOT_LOADED, filename.GetFullName() );
 
  410        catch( 
const std::bad_alloc& )
 
  412            wxString txt = wxString::Format( 
MSG_OOM, filename.GetFullName() );
 
  419            progress->AdvanceProgress();
 
 
  450    bool     foundX2Gerbers = 
false;
 
  456    wxFileName fn( aFullFileName );
 
  457    wxString   unzipDir = fn.GetPath();
 
  459    wxFFileInputStream zipFile( aFullFileName );
 
  461    if( !zipFile.IsOk() )
 
  465            msg.Printf( 
_( 
"Zip file '%s' cannot be opened." ), aFullFileName );
 
  479    wxFileName temp_fn( 
"$tempfile.tmp" );
 
  480    temp_fn.MakeAbsolute( unzipDir );
 
  481    wxString unzipped_tempfile = temp_fn.GetFullPath();
 
  485    wxZipInputStream zipArchive( zipFile );
 
  487    bool             reported_no_more_layer = 
false;
 
  490    while( ( entry = zipArchive.GetNextEntry() ) != 
nullptr )
 
  495        wxString   fname = entry->GetName();
 
  496        wxFileName uzfn = fname;
 
  497        wxString   curr_ext = uzfn.GetExt().Lower();
 
  507                msg.Printf( 
_( 
"Skipped file '%s' (gerber job file)." ), entry->GetName() );
 
  526                if( !reported_no_more_layer )
 
  529                reported_no_more_layer = 
true;
 
  544            wxFFileOutputStream temporary_ofile( unzipped_tempfile );
 
  546            if( temporary_ofile.Ok() )
 
  547                temporary_ofile.Write( zipArchive );
 
  554                    msg.Printf( 
_( 
"<b>Unable to create temporary file '%s'.</b>" ),
 
  579                    msg.Printf( 
_( 
"Skipped file '%s' (unknown type)." ), entry->GetName() );
 
  604            firstLoadedLayer = layer;
 
  610        wxRemoveFile( unzipped_tempfile );
 
  618                msg.Printf( 
_( 
"<b>unzipped file %s read error</b>" ), unzipped_tempfile );
 
  631                    foundX2Gerbers = 
true;
 
 
  656#define ZipFileExtension "zip" 
  658    wxFileName filename = aFullFileName;
 
  659    wxString currentPath;
 
  661    if( !filename.IsOk() )
 
  664        if( filename.DirExists() )
 
  665            currentPath = filename.GetPath();
 
  669        wxFileDialog dlg( 
this, 
_( 
"Open Zip File" ), currentPath, filename.GetFullName(),
 
  671                          wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
 
  673        if( dlg.ShowModal() == wxID_CANCEL )
 
  676        filename = dlg.GetPath();
 
  677        currentPath = wxGetCwd();
 
  682        currentPath = filename.GetPath();
 
  688    if( filename.IsOk() )
 
 
  730            wxString fn = file.GetFullPath();
 
  737            gerbFn += 
'"' + file.GetFullPath() + 
'"';
 
  742    if( !gerbFn.IsEmpty() )
 
 
std::vector< wxFileName > m_AcceptedFiles
 
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
 
virtual void ClearFileHistory()
Remove all files from the file history.
 
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
 
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetch the file name from the file history list.
 
void ReCreateMenuBar()
Recreate the menu bar.
 
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.
 
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
 
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
 
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
 
static bool TestFileIsExcellon(const wxString &aFullFileName)
Performs a heuristics-based check of whether the file is an Excellon drill file.
 
unsigned GetLoadedImageCount()
Get number of loaded images.
 
static void GetGerberLayerFromFilename(const wxString &filename, enum GERBER_ORDER_ENUM &order, wxString &matchedExtension)
Utility function to guess which PCB layer of a gerber/drill file corresponds to based on its file ext...
 
Hold the image data and parameters for one gerber file and layer parameters.
 
wxString m_FileName
Full File Name for this layer.
 
static bool TestFileIsRS274(const wxString &aFullFileName)
Performs a heuristics-based check of whether the file is an RS274 gerber file.
 
bool m_IsX2_file
True if a X2 gerber attribute was found in file.
 
void OnDrlFileHistory(wxCommandEvent &event)
Delete the current data and load a drill file in Excellon format selected from history list on curren...
 
void SortLayersByX2Attributes()
 
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
 
bool Read_EXCELLON_File(const wxString &aFullFileName)
 
bool LoadFileOrShowDialog(const wxString &aFileName, const wxString &dialogFiletypes, const wxString &dialogTitle, const int filetype)
Loads the file provided or shows a dialog to get the file(s) from the user.
 
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
 
void OnClearDrlFileHistory(wxCommandEvent &aEvent)
 
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
 
void syncLayerBox(bool aRebuildLayerBox=false)
Update the currently "selected" layer within m_SelLayerBox.
 
bool LoadGerberFiles(const wxString &aFileName)
Load a given Gerber file or selected file(s), if the filename is empty.
 
bool unarchiveFiles(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Extract gerber and drill files from the zip archive, and load them.
 
FILE_HISTORY m_jobFileHistory
 
void OnJobFileHistory(wxCommandEvent &event)
Delete the current data and load a gerber job file selected from the history list.
 
void OnZipFileHistory(wxCommandEvent &event)
Delete the current data and load a zip archive file selected from the history list.
 
int GetActiveLayer() const
Return the active layer.
 
GERBER_LAYER_WIDGET * m_LayersManager
 
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
change the currently active layer to aLayer and update the GERBER_LAYER_WIDGET.
 
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
 
void ClearFileHistory() override
Remove all files from the file history.
 
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
 
void SortLayersByFileExtension()
 
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
 
bool LoadListOfGerberAndDrillFiles(const wxString &aPath, const wxArrayString &aFilenameList, std::vector< int > *aFileType)
Load a list of Gerber and NC drill files and updates the view based on them.
 
bool LoadAutodetectedFiles(const wxString &aFileName)
Load a given file or selected file(s), if the filename is empty.
 
void ReFillLayerWidget()
Change out all the layers in m_Layers; called upon loading new gerber files.
 
FILE_HISTORY m_zipFileHistory
 
int getNextAvailableLayer() const
Find the next empty layer.
 
bool LoadZipArchiveFile(const wxString &aFileName)
Load a zipped archive file.
 
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
 
void OnClearZipFileHistory(wxCommandEvent &aEvent)
 
void DoWithAcceptedFiles() override
Execute action on accepted dropped file.
 
void OnGbrFileHistory(wxCommandEvent &event)
Delete the current data and loads a Gerber file selected from history list on current layer.
 
FILE_HISTORY m_drillFileHistory
 
bool LoadExcellonFiles(const wxString &aFileName)
Load a drill (EXCELLON) file or many files.
 
void OnClearJobFileHistory(wxCommandEvent &aEvent)
 
void ListSet(const wxString &aList)
Add a list of items.
 
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
 
void SetLayerHasNegatives(int aLayer, bool aNegatives=true)
Set the status of negatives presense in a particular layer.
 
LSET is a set of PCB_LAYER_IDs.
 
A pure virtual class used to derive REPORTER objects from.
 
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
 
virtual bool HasMessage() const
Returns true if any messages were reported.
 
A wrapper for reporting to a wxString object.
 
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
 
const wxString & GetMessages() const
 
#define MSG_NO_MORE_LAYER
 
#define NO_AVAILABLE_LAYERS
 
static const std::string GerberJobFileExtension
 
static const std::string GerberFileExtension
 
static const std::string ArchiveFileExtension
 
static wxString AllFilesWildcard()
 
static wxString DrillFileWildcard()
 
static wxString ZipFileWildcard()
 
#define GERBER_DRAW_LAYER(x)
 
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
 
Definition of file extensions used in Kicad.