KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gerbview/files.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <wx/debug.h>
26#include <wx/filedlg.h>
27#include <wx/wfstream.h>
28#include <wx/zipstrm.h>
29#include <reporter.h>
31#include <gerbview_frame.h>
32#include <gerbview_id.h>
33#include <gerber_file_image.h>
35#include <excellon_image.h>
36#include <lset.h>
38#include <view/view.h>
41#include <tool/tool_manager.h>
42
43// HTML Messages used more than one time:
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>" )
47
48
49void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
50{
51 wxString fn;
52
53 fn = GetFileFromHistory( event.GetId(), _( "Gerber files" ) );
54
55 if( !fn.IsEmpty() )
56 {
57 LoadGerberFiles( fn );
58 }
59}
60
61void GERBVIEW_FRAME::OnClearGbrFileHistory( wxCommandEvent& aEvent )
62{
64}
65
66
67void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event )
68{
69 wxString fn;
70
71 fn = GetFileFromHistory( event.GetId(), _( "Drill files" ), &m_drillFileHistory );
72
73 if( !fn.IsEmpty() )
74 {
76 }
77}
78
79
80void GERBVIEW_FRAME::OnClearDrlFileHistory( wxCommandEvent& aEvent )
81{
83}
84
85
86void GERBVIEW_FRAME::OnZipFileHistory( wxCommandEvent& event )
87{
88 wxString filename;
89 filename = GetFileFromHistory( event.GetId(), _( "Zip files" ), &m_zipFileHistory );
90
91 if( !filename.IsEmpty() )
92 {
93 LoadZipArchiveFile( filename );
94 }
95}
96
97
98void GERBVIEW_FRAME::OnClearZipFileHistory( wxCommandEvent& aEvent )
99{
101}
102
103
104void GERBVIEW_FRAME::OnJobFileHistory( wxCommandEvent& event )
105{
106 wxString filename = GetFileFromHistory( event.GetId(), _( "Job files" ), &m_jobFileHistory );
107
108 if( !filename.IsEmpty() )
109 LoadGerberJobFile( filename );
110}
111
112
113void GERBVIEW_FRAME::OnClearJobFileHistory( wxCommandEvent& aEvent )
114{
116}
117
118
119bool GERBVIEW_FRAME::LoadFileOrShowDialog( const wxString& aFileName,
120 const wxString& dialogFiletypes,
121 const wxString& dialogTitle, const int filetype )
122{
123 static int lastGerberFileWildcard = 0;
124 wxArrayString filenamesList;
125 wxFileName filename = aFileName;
126 wxString currentPath;
127
128 if( !filename.IsOk() )
129 {
130 // Use the current working directory if the file name path does not exist.
131 if( filename.DirExists() )
132 currentPath = filename.GetPath();
133 else
134 {
135 currentPath = m_mruPath;
136
137 // On wxWidgets 3.1 (bug?) the path in wxFileDialog is ignored when
138 // finishing by the dir separator. Remove it if any:
139 if( currentPath.EndsWith( '\\' ) || currentPath.EndsWith( '/' ) )
140 currentPath.RemoveLast();
141 }
142
143 wxFileDialog dlg( this, dialogTitle, currentPath, filename.GetFullName(), dialogFiletypes,
144 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
145
146 wxArrayString dummy1, dummy2;
147 const int nWildcards = wxParseCommonDialogsFilter( dialogFiletypes, dummy1, dummy2 );
148
149 if( lastGerberFileWildcard >= 0 && lastGerberFileWildcard < nWildcards )
150 dlg.SetFilterIndex( lastGerberFileWildcard );
151
152 if( dlg.ShowModal() == wxID_CANCEL )
153 return false;
154
155 lastGerberFileWildcard = dlg.GetFilterIndex();
156 dlg.GetPaths( filenamesList );
157 m_mruPath = currentPath = dlg.GetDirectory();
158 }
159 else
160 {
161 filenamesList.Add( aFileName );
162 currentPath = filename.GetPath();
163 m_mruPath = currentPath;
164 }
165
166 // Set the busy cursor
167 wxBusyCursor wait;
168
169 bool isFirstFile = GetImagesList()->GetLoadedImageCount() == 0;
170
171 std::vector<int> fileTypesVec( filenamesList.Count(), filetype );
172 bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList, &fileTypesVec );
173
174 // Auto zoom / sort is only applied when no other files have been loaded
175 if( isFirstFile )
176 {
177 int ly = GetActiveLayer();
178
180 Zoom_Automatique( false );
181
182 // Ensure the initial active graphic layer is updated after sorting.
183 SetActiveLayer( ly, true );
184 }
185
186 return success;
187}
188
189
190bool GERBVIEW_FRAME::LoadAutodetectedFiles( const wxString& aFileName )
191{
192 // 2 = autodetect files
193 return LoadFileOrShowDialog( aFileName, FILEEXT::AllFilesWildcard(), _( "Open Autodetected File(s)" ),
194 2 );
195}
196
197
198bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFileName )
199{
200 wxString filetypes;
201 wxFileName filename = aFileName;
202
203 /* Standard gerber filetypes
204 * (See http://en.wikipedia.org/wiki/Gerber_File)
205 * The .gbr (.pho in legacy files) extension is the default used in Pcbnew; however
206 * there are a lot of other extensions used for gerber files. Because the first letter
207 * is usually g, we accept g* as extension.
208 * (Mainly internal copper layers do not have specific extension, and filenames are like
209 * *.g1, *.g2 *.gb1 ...)
210 * Now (2014) Ucamco (the company which manages the Gerber format) encourages use of .gbr
211 * only and the Gerber X2 file format.
212 */
213 filetypes = _( "Gerber files" ) + AddFileExtListToFilter( { "g*", "pho" } ) + wxT( "|" );
214
215 /* Special gerber filetypes */
216 filetypes += _( "Top layer" ) + AddFileExtListToFilter( { "gtl" } ) + wxT( "|" );
217 filetypes += _( "Bottom layer" ) + AddFileExtListToFilter( { "gbl" } ) + wxT( "|" );
218 filetypes += _( "Bottom solder resist" ) + AddFileExtListToFilter( { "gbs" } ) + wxT( "|" );
219 filetypes += _( "Top solder resist" ) + AddFileExtListToFilter( { "gts" } ) + wxT( "|" );
220 filetypes += _( "Bottom overlay" ) + AddFileExtListToFilter( { "gbo" } ) + wxT( "|" );
221 filetypes += _( "Top overlay" ) + AddFileExtListToFilter( { "gto" } ) + wxT( "|" );
222 filetypes += _( "Bottom paste" ) + AddFileExtListToFilter( { "gbp" } ) + wxT( "|" );
223 filetypes += _( "Top paste" ) + AddFileExtListToFilter( { "gtp" } ) + wxT( "|" );
224 filetypes += _( "Keep-out layer" ) + AddFileExtListToFilter( { "gko" } ) + wxT( "|" );
225 filetypes += _( "Mechanical layers" )
227 { "gm1", "gm2", "gm3", "gm4", "gm5", "gm6", "gm7", "gm8", "gm9" } )
228 + wxT( "|" );
229 filetypes += _( "Top Pad Master" ) + AddFileExtListToFilter( { "gpt" } ) + wxT( "|" );
230 filetypes += _( "Bottom Pad Master" ) + AddFileExtListToFilter( { "gpb" } ) + wxT( "|" );
231
232 // All filetypes
233 filetypes += FILEEXT::AllFilesWildcard();
234
235 // 0 = gerber files
236 return LoadFileOrShowDialog( aFileName, filetypes, _( "Open Gerber File(s)" ), 0 );
237}
238
239
240bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFileName )
241{
242 wxString filetypes = FILEEXT::DrillFileWildcard();
243 filetypes << wxT( "|" );
244 filetypes += FILEEXT::AllFilesWildcard();
245
246 // 1 = drill files
247 return LoadFileOrShowDialog( aFileName, filetypes, _( "Open NC (Excellon) Drill File(s)" ), 1 );
248}
249
250
252 const wxArrayString& aFilenameList,
253 std::vector<int>* aFileType )
254{
255 wxCHECK_MSG( aFilenameList.Count() == aFileType->size(), false,
256 "Mismatch in file names and file types count" );
257
258 wxFileName filename;
259
260 // Read gerber files: each file is loaded on a new GerbView layer
261 bool success = true;
262 int layer = GetActiveLayer();
263 int firstLoadedLayer = NO_AVAILABLE_LAYERS;
265
266 // Manage errors when loading files
267 WX_STRING_REPORTER reporter;
268
269 // Create progress dialog (only used if more than 1 file to load
270 std::unique_ptr<WX_PROGRESS_REPORTER> progress = nullptr;
271
272 for( unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
273 {
274 filename = aFilenameList[ii];
275
276 if( !filename.IsAbsolute() )
277 filename.SetPath( aPath );
278
279 // Check for non existing files, to avoid creating broken or useless data
280 // and report all in one error list:
281 if( !filename.FileExists() )
282 {
283 wxString warning;
284 warning << wxT( "<b>" ) << _( "File not found:" ) << wxT( "</b><br>" )
285 << filename.GetFullPath() << wxT( "<br>" );
286 reporter.Report( warning, RPT_SEVERITY_WARNING );
287 success = false;
288 continue;
289 }
290
291 if( filename.GetExt() == FILEEXT::GerberJobFileExtension.c_str() )
292 {
293 //We cannot read a gerber job file as a gerber plot file: skip it
294 wxString txt;
295 txt.Printf( _( "<b>A gerber job file cannot be loaded as a plot file</b> "
296 "<i>%s</i>" ),
297 filename.GetFullName() );
298 success = false;
299 reporter.Report( txt, RPT_SEVERITY_ERROR );
300 continue;
301 }
302
303
304 m_lastFileName = filename.GetFullPath();
305
306 if( !progress && ( aFilenameList.GetCount() > 1 ) )
307 {
308 progress = std::make_unique<WX_PROGRESS_REPORTER>( this, _( "Load Files" ), 1, PR_CAN_ABORT );
309 progress->SetMaxProgress( aFilenameList.GetCount() - 1 );
310 progress->Report( wxString::Format( _("Loading %u/%zu %s..." ),
311 ii+1,
312 aFilenameList.GetCount(),
313 m_lastFileName ) );
314 }
315 else if( progress )
316 {
317 progress->Report( wxString::Format( _("Loading %u/%zu %s..." ),
318 ii+1,
319 aFilenameList.GetCount(),
320 m_lastFileName ) );
321 progress->KeepRefreshing();
322 }
323
324
325 // Make sure we have a layer available to load into
326 layer = getNextAvailableLayer();
327
328 if( layer == NO_AVAILABLE_LAYERS )
329 {
330 success = false;
332
333 // Report the name of not loaded files:
334 while( ii < aFilenameList.GetCount() )
335 {
336 filename = aFilenameList[ii++];
337 wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
338 reporter.Report( txt, RPT_SEVERITY_ERROR );
339 }
340 break;
341 }
342
343 SetActiveLayer( layer, false );
344 visibility[ layer ] = true;
345
346 try
347 {
348 // 2 = Autodetect
349 if( ( *aFileType )[ii] == 2 )
350 {
351 if( EXCELLON_IMAGE::TestFileIsExcellon( filename.GetFullPath() ) )
352 ( *aFileType )[ii] = 1;
353 else if( GERBER_FILE_IMAGE::TestFileIsRS274( filename.GetFullPath() ) )
354 ( *aFileType )[ii] = 0;
355 }
356
357 switch( ( *aFileType )[ii] )
358 {
359 case 0:
360
361 if( Read_GERBER_File( filename.GetFullPath() ) )
362 {
363 UpdateFileHistory( filename.GetFullPath() );
364
365 if( firstLoadedLayer == NO_AVAILABLE_LAYERS )
366 {
367 firstLoadedLayer = layer;
368 }
369 }
370
371 break;
372
373 case 1:
374
375 if( Read_EXCELLON_File( filename.GetFullPath() ) )
376 {
377 UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory );
378
379 // Select the first added layer by default when done loading
380 if( firstLoadedLayer == NO_AVAILABLE_LAYERS )
381 {
382 firstLoadedLayer = layer;
383 }
384 }
385
386 break;
387 default:
388 wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
389 reporter.Report( txt, RPT_SEVERITY_ERROR );
390 }
391 }
392 catch( const std::bad_alloc& )
393 {
394 wxString txt = wxString::Format( MSG_OOM, filename.GetFullName() );
395 reporter.Report( txt, RPT_SEVERITY_ERROR );
396 success = false;
397 continue;
398 }
399
400 if( progress )
401 progress->AdvanceProgress();
402 }
403
404 if( !success )
405 {
406 wxSafeYield(); // Allows slice of time to redraw the screen
407 // to refresh widgets, before displaying messages
408 HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
409 mbox.ListSet( reporter.GetMessages() );
410 mbox.ShowModal();
411 }
412
414
415 if( firstLoadedLayer != NO_AVAILABLE_LAYERS )
416 SetActiveLayer( firstLoadedLayer, true );
417
418 // Synchronize layers tools with actual active layer:
420
422 syncLayerBox( true );
423
424 GetCanvas()->Refresh();
425
426 return success;
427}
428
429
430bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter )
431{
432 bool foundX2Gerbers = false;
433 wxString msg;
434 int firstLoadedLayer = NO_AVAILABLE_LAYERS;
436
437 // Extract the path of aFullFileName. We use it to store temporary files
438 wxFileName fn( aFullFileName );
439 wxString unzipDir = fn.GetPath();
440
441 wxFFileInputStream zipFile( aFullFileName );
442
443 if( !zipFile.IsOk() )
444 {
445 if( aReporter )
446 {
447 msg.Printf( _( "Zip file '%s' cannot be opened." ), aFullFileName );
448 aReporter->Report( msg, RPT_SEVERITY_ERROR );
449 }
450
451 return false;
452 }
453
454 // Update the list of recent zip files.
455 UpdateFileHistory( aFullFileName, &m_zipFileHistory );
456
457 // The unzipped file in only a temporary file. Give it a filename
458 // which cannot conflict with an usual filename.
459 // TODO: make Read_GERBER_File() and Read_EXCELLON_File() able to
460 // accept a stream, and avoid using a temp file.
461 wxFileName temp_fn( "$tempfile.tmp" );
462 temp_fn.MakeAbsolute( unzipDir );
463 wxString unzipped_tempfile = temp_fn.GetFullPath();
464
465
466 bool success = true;
467 wxZipInputStream zipArchive( zipFile );
468 wxZipEntry* entry;
469 bool reported_no_more_layer = false;
470 KIGFX::VIEW* view = GetCanvas()->GetView();
471
472 while( ( entry = zipArchive.GetNextEntry() ) != nullptr )
473 {
474 if( entry->IsDir() )
475 continue;
476
477 wxString fname = entry->GetName();
478 wxFileName uzfn = fname;
479 wxString curr_ext = uzfn.GetExt().Lower();
480
481 // The archive contains Gerber and/or Excellon drill files. Use the right loader.
482 // However it can contain a few other files (reports, pdf files...),
483 // which will be skipped.
484 if( curr_ext == FILEEXT::GerberJobFileExtension.c_str() )
485 {
486 //We cannot read a gerber job file as a gerber plot file: skip it
487 if( aReporter )
488 {
489 msg.Printf( _( "Skipped file '%s' (gerber job file)." ), entry->GetName() );
490 aReporter->Report( msg, RPT_SEVERITY_WARNING );
491 }
492
493 continue;
494 }
495
496 wxString matchedExt;
497 enum GERBER_ORDER_ENUM order;
498 GERBER_FILE_IMAGE_LIST::GetGerberLayerFromFilename( fname, order, matchedExt );
499
500 int layer = getNextAvailableLayer();
501
502 if( layer == NO_AVAILABLE_LAYERS )
503 {
504 success = false;
505
506 if( aReporter )
507 {
508 if( !reported_no_more_layer )
510
511 reported_no_more_layer = true;
512
513 // Report the name of not loaded files:
514 msg.Printf( MSG_NOT_LOADED, entry->GetName() );
515 aReporter->Report( msg, RPT_SEVERITY_ERROR );
516 }
517
518 delete entry;
519 continue;
520 }
521
522 SetActiveLayer( layer, false );
523
524 // Create the unzipped temporary file:
525 {
526 wxFFileOutputStream temporary_ofile( unzipped_tempfile );
527
528 if( temporary_ofile.Ok() )
529 temporary_ofile.Write( zipArchive );
530 else
531 {
532 success = false;
533
534 if( aReporter )
535 {
536 msg.Printf( _( "<b>Unable to create temporary file '%s'.</b>" ),
537 unzipped_tempfile );
538 aReporter->Report( msg, RPT_SEVERITY_ERROR );
539 }
540 }
541 }
542
543 bool read_ok = true;
544
545 // Try to parse files if we can't tell from file extension
546 if( order == GERBER_ORDER_ENUM::GERBER_LAYER_UNKNOWN )
547 {
548 if( EXCELLON_IMAGE::TestFileIsExcellon( unzipped_tempfile ) )
549 {
550 order = GERBER_ORDER_ENUM::GERBER_DRILL;
551 }
552 else if( GERBER_FILE_IMAGE::TestFileIsRS274( unzipped_tempfile ) )
553 {
554 // If we have no way to know what layer it is, just guess
555 order = GERBER_ORDER_ENUM::GERBER_TOP_COPPER;
556 }
557 else
558 {
559 if( aReporter )
560 {
561 msg.Printf( _( "Skipped file '%s' (unknown type)." ), entry->GetName() );
562 aReporter->Report( msg, RPT_SEVERITY_WARNING );
563 }
564 }
565 }
566
567 if( order == GERBER_ORDER_ENUM::GERBER_DRILL )
568 {
569 read_ok = Read_EXCELLON_File( unzipped_tempfile );
570 }
571 else if( order != GERBER_ORDER_ENUM::GERBER_LAYER_UNKNOWN )
572 {
573 // Read gerber files: each file is loaded on a new GerbView layer
574 read_ok = Read_GERBER_File( unzipped_tempfile );
575
576 if( read_ok )
577 {
578 if( GERBER_FILE_IMAGE* gbrImage = GetGbrImage( layer ) )
579 view->SetLayerHasNegatives( GERBER_DRAW_LAYER( layer ), gbrImage->HasNegativeItems() );
580 }
581 }
582
583 // Select the first added layer by default when done loading
584 if( read_ok && firstLoadedLayer == NO_AVAILABLE_LAYERS )
585 {
586 firstLoadedLayer = layer;
587 }
588
589 delete entry;
590
591 // The unzipped file is only a temporary file, delete it.
592 wxRemoveFile( unzipped_tempfile );
593
594 if( !read_ok )
595 {
596 success = false;
597
598 if( aReporter )
599 {
600 msg.Printf( _( "<b>unzipped file %s read error</b>" ), unzipped_tempfile );
601 aReporter->Report( msg, RPT_SEVERITY_ERROR );
602 }
603 }
604 else
605 {
606 GERBER_FILE_IMAGE* gerber_image = GetGbrImage( layer );
607 visibility[ layer ] = true;
608
609 if( gerber_image )
610 {
611 gerber_image->m_FileName = fname;
612 if( gerber_image->m_IsX2_file )
613 foundX2Gerbers = true;
614 }
615
616 layer = getNextAvailableLayer();
617 SetActiveLayer( layer, false );
618 }
619 }
620
621 if( foundX2Gerbers )
623 else
625
627
628 // Select the first layer loaded so we don't show another layer on top after
629 if( firstLoadedLayer != NO_AVAILABLE_LAYERS )
630 SetActiveLayer( firstLoadedLayer, true );
631
632 return success;
633}
634
635
636bool GERBVIEW_FRAME::LoadZipArchiveFile( const wxString& aFullFileName )
637{
638#define ZipFileExtension "zip"
639
640 wxFileName filename = aFullFileName;
641 wxString currentPath;
642
643 if( !filename.IsOk() )
644 {
645 // Use the current working directory if the file name path does not exist.
646 if( filename.DirExists() )
647 currentPath = filename.GetPath();
648 else
649 currentPath = m_mruPath;
650
651 wxFileDialog dlg( this, _( "Open Zip File" ), currentPath, filename.GetFullName(),
653 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
654
655 if( dlg.ShowModal() == wxID_CANCEL )
656 return false;
657
658 filename = dlg.GetPath();
659 currentPath = wxGetCwd();
660 m_mruPath = currentPath;
661 }
662 else
663 {
664 currentPath = filename.GetPath();
665 m_mruPath = currentPath;
666 }
667
668 WX_STRING_REPORTER reporter;
669
670 if( filename.IsOk() )
671 unarchiveFiles( filename.GetFullPath(), &reporter );
672
673 Zoom_Automatique( false );
674
675 // Synchronize layers tools with actual active layer:
679 syncLayerBox();
680
681 if( reporter.HasMessage() )
682 {
683 wxSafeYield(); // Allows slice of time to redraw the screen
684 // to refresh widgets, before displaying messages
685 HTML_MESSAGE_BOX mbox( this, _( "Messages" ) );
686 mbox.ListSet( reporter.GetMessages() );
687 mbox.ShowModal();
688 }
689
690 return true;
691}
692
694{
695 wxString gerbFn; // param to be sent with action event.
696
697 for( const wxFileName& file : m_AcceptedFiles )
698 {
699 if( file.GetExt() == FILEEXT::ArchiveFileExtension )
700 {
701 wxString fn = file.GetFullPath();
702 // Open zip archive in editor
704 }
705 else
706 {
707 // Store FileName in variable to open later
708 gerbFn += '"' + file.GetFullPath() + '"';
709 }
710 }
711
712 // Open files in editor
713 if( !gerbFn.IsEmpty() )
715}
int ShowModal() override
std::vector< wxFileName > m_AcceptedFiles
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
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.
wxString m_mruPath
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.
Definition: readgerb.cpp:139
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.
wxString m_lastFileName
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.
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
Definition: readgerb.cpp:41
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...
Definition: view.h:66
void SetLayerHasNegatives(int aLayer, bool aNegatives=true)
Set the status of negatives presense in a particular layer.
Definition: view.h:461
void UpdateLayerIcons()
Update all layer manager icons (layers only).
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition: reporter.h:102
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
A wrapper for reporting to a wxString object.
Definition: reporter.h:190
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:96
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:74
const wxString & GetMessages() const
Definition: reporter.cpp:83
#define _(s)
#define MSG_NOT_LOADED
#define MSG_OOM
#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)
Definition: layer_ids.h:528
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
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.
#define PR_CAN_ABORT