You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
6.6 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. /*************/
  2. /* files.cpp */
  3. /*************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "class_drawpanel.h"
  7. #include "confirm.h"
  8. #include "gestfich.h"
  9. #include "gerbview.h"
  10. #include "pcbplot.h"
  11. #include "protos.h"
  12. static void LoadDCodeFile( WinEDA_GerberFrame* frame,
  13. const wxString& FullFileName );
  14. void WinEDA_GerberFrame::OnFileHistory( wxCommandEvent& event )
  15. {
  16. wxString fn;
  17. fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
  18. if( fn != wxEmptyString )
  19. {
  20. Erase_Current_Layer( false );
  21. LoadOneGerberFile( fn, false );
  22. }
  23. }
  24. /* File commands. */
  25. void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
  26. {
  27. int id = event.GetId();
  28. switch( id )
  29. {
  30. case wxID_FILE:
  31. Erase_Current_Layer( false );
  32. LoadOneGerberFile( wxEmptyString, 0 );
  33. break;
  34. case ID_MENU_INC_LAYER_AND_APPEND_FILE:
  35. case ID_INC_LAYER_AND_APPEND_FILE:
  36. {
  37. int origLayer = getActiveLayer();
  38. if( origLayer < NB_LAYERS )
  39. {
  40. setActiveLayer(origLayer+1);
  41. if( !LoadOneGerberFile( wxEmptyString, 0 ) )
  42. setActiveLayer(origLayer);
  43. SetToolbars();
  44. }
  45. else
  46. wxMessageBox(_("Cannot increment layer number: max count reached") );
  47. }
  48. break;
  49. case ID_APPEND_FILE:
  50. LoadOneGerberFile( wxEmptyString, 0 );
  51. break;
  52. case ID_NEW_BOARD:
  53. Clear_Pcb( true );
  54. Zoom_Automatique( false );
  55. DrawPanel->Refresh();
  56. break;
  57. case ID_GERBVIEW_LOAD_DRILL_FILE:
  58. DisplayError( this, _( "Not yet available..." ) );
  59. break;
  60. case ID_GERBVIEW_LOAD_DCODE_FILE:
  61. LoadDCodeFile( this, wxEmptyString );
  62. break;
  63. case ID_SAVE_BOARD:
  64. SaveGerberFile( GetScreen()->m_FileName );
  65. break;
  66. case ID_SAVE_BOARD_AS:
  67. SaveGerberFile( wxEmptyString );
  68. break;
  69. default:
  70. DisplayError( this, wxT( "File_io Internal Error" ) );
  71. break;
  72. }
  73. }
  74. /*
  75. * Load a PCB file.
  76. *
  77. * Returns:
  78. * 0 if file not read (cancellation of order ...)
  79. * 1 if OK
  80. */
  81. bool WinEDA_GerberFrame::LoadOneGerberFile( const wxString& FullFileName,
  82. int mode )
  83. {
  84. wxString filetypes;
  85. wxFileName filename = FullFileName;
  86. ActiveScreen = GetScreen();
  87. if( !filename.IsOk() )
  88. {
  89. wxString current_path = filename.GetPath();
  90. /* Standard gerber filetypes
  91. * (See http://en.wikipedia.org/wiki/Gerber_File)
  92. * the .pho extension is the default used in Pcbnew
  93. */
  94. filetypes = _( "Gerber files (.gb* .gt* .lgr .ger .pho)" );
  95. filetypes << wxT("|");
  96. filetypes += wxT("*.gb*;*.GB*;*.gt*;*.GT*;*.gko;*.GKO;*.GPB;*.gpb;*.lgr;*.LGR;*.ger;*.GER;*.pho;*.PHO" );
  97. filetypes << wxT("|");
  98. /* Special gerber filetypes */
  99. filetypes += _( "Top layer (*.GTL)|*.GTL;*.gtl|" );
  100. filetypes += _( "Bottom layer (*.GBL)|*.GBL;*.gbl|" );
  101. filetypes += _( "Bottom solder resist (*.GBS)|*.GBS;*.gbs|" );
  102. filetypes += _( "Top solder resist (*.GTS)|*.GTS;*.gts|" );
  103. filetypes += _( "Bottom overlay (*.GBO)|*.GBO;*.gbo|" );
  104. filetypes += _( "Top overlay (*.GTO)|*.GTO;*.gto|" );
  105. filetypes += _( "Bottom paste (*.GBP)|*.GBP;*.gbp|" );
  106. filetypes += _( "Top paste (*.GTP)|*.GTP;*.gtp|" );
  107. filetypes += _( "Keep-out layer (*.GKO)|*.GKO;*.gko|" );
  108. filetypes += _( "Mechanical layers (*.GMx)|*.GM1;*.gm1;*.GM2;*.gm2;*.GM3;*.gm3|" );
  109. filetypes += _( "Top Pad Master (*.GPT)|*.GPT;*.gpt|" );
  110. filetypes += _( "Bottom Pad Master (*.GPB)|*.GPB;*.gpb|" );
  111. /* All filetypes */
  112. filetypes += AllFilesWildcard;
  113. /* Get current path if emtpy */
  114. if( current_path.IsEmpty() )
  115. current_path = wxGetCwd();
  116. wxFileDialog dlg( this,
  117. _( "Open Gerber File" ),
  118. current_path,
  119. filename.GetFullName(),
  120. filetypes,
  121. wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  122. if( dlg.ShowModal() == wxID_CANCEL )
  123. return false;
  124. filename = dlg.GetPath();
  125. }
  126. GetScreen()->m_FileName = filename.GetFullPath();
  127. wxSetWorkingDirectory( filename.GetPath() );
  128. filename.SetExt( g_PenFilenameExt );
  129. if( Read_GERBER_File( GetScreen()->m_FileName, filename.GetFullPath() ) )
  130. SetLastProject( GetScreen()->m_FileName );
  131. Zoom_Automatique( false );
  132. GetScreen()->SetRefreshReq();
  133. g_SaveTime = time( NULL );
  134. return true;
  135. }
  136. /*
  137. * Read a DCode file (not used with RX274X files , just with RS274D old files).
  138. * Note: there is no standard for DCode file.
  139. * Just read a file format created by early versions of Pcbnew.
  140. * Returns:
  141. * 0 if file not read (cancellation of order ...)
  142. * 1 if OK
  143. */
  144. static void LoadDCodeFile( WinEDA_GerberFrame* frame,
  145. const wxString& FullFileName )
  146. {
  147. wxString wildcard;
  148. wxFileName fn = FullFileName;
  149. ActiveScreen = frame->GetScreen();
  150. if( !fn.IsOk() )
  151. {
  152. wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
  153. GetChars( g_PenFilenameExt ),
  154. GetChars( g_PenFilenameExt ) );
  155. wildcard += AllFilesWildcard;
  156. fn = frame->GetScreen()->m_FileName;
  157. fn.SetExt( g_PenFilenameExt );
  158. wxFileDialog dlg( (wxWindow*) frame, _( "Load GERBER DCODE File" ),
  159. fn.GetPath(), fn.GetFullName(), wildcard,
  160. wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  161. if( dlg.ShowModal() == wxID_CANCEL )
  162. return;
  163. fn = dlg.GetPath();
  164. }
  165. frame->Read_D_Code_File( fn.GetFullPath() );
  166. frame->CopyDCodesSizeToItems();
  167. frame->GetScreen()->SetRefreshReq();
  168. }
  169. /* Save the file in ASCII PCB.
  170. */
  171. bool WinEDA_GerberFrame::SaveGerberFile( const wxString& FullFileName )
  172. {
  173. wxString wildcard;
  174. wxFileName fn = FullFileName;
  175. if( !fn.IsOk() )
  176. {
  177. fn = GetScreen()->m_FileName;
  178. wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
  179. GetChars( g_PenFilenameExt ),
  180. GetChars( g_PenFilenameExt ) );
  181. wxFileDialog dlg( this, _( "Save Gerber File" ), fn.GetPath(),
  182. fn.GetFullName(), wildcard,
  183. wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  184. if( dlg.ShowModal() == wxID_CANCEL )
  185. return false;
  186. fn = dlg.GetPath();
  187. }
  188. GetScreen()->m_FileName = fn.GetFullPath();
  189. // TODO
  190. return true;
  191. }