kicad/gerbview/files.cpp

262 lines
7.3 KiB
C++
Raw Normal View History

2007-09-25 15:10:01 +00:00
/******************************************************/
/* Files.cp: Lecture / Sauvegarde des fichiers gerber */
/******************************************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "common.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "gestfich.h"
2007-05-06 16:03:28 +00:00
#include "gerbview.h"
#include "pcbplot.h"
#include "protos.h"
#include "id.h"
/* Routines locales */
2007-09-25 15:10:01 +00:00
static void LoadDCodeFile( WinEDA_GerberFrame* frame, const wxString& FullFileName, wxDC* DC );
2007-05-06 16:03:28 +00:00
void WinEDA_GerberFrame::OnFileHistory( wxCommandEvent& event )
{
wxString fn;
fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
if( fn != wxEmptyString && Clear_Pcb( true ) )
{
wxClientDC dc( DrawPanel );
DrawPanel->CursorOff( &dc );
LoadOneGerberFile( fn, &dc, false );
DrawPanel->MouseToCursorSchema();
DrawPanel->CursorOn( &dc );
}
}
/***************
***************************************/
2007-09-25 15:10:01 +00:00
void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
/********************************************************/
2007-09-25 15:10:01 +00:00
2007-05-06 16:03:28 +00:00
/* Gestion generale des commandes de lecture de fichiers
2007-09-25 15:10:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-09-25 15:10:01 +00:00
int id = event.GetId();
wxClientDC dc( DrawPanel );
DrawPanel->CursorOff( &dc );
switch( id )
{
case ID_MENU_LOAD_FILE:
case ID_LOAD_FILE:
if( Clear_Pcb( TRUE ) )
2007-09-25 15:10:01 +00:00
{
LoadOneGerberFile( wxEmptyString, &dc, 0 );
}
break;
case ID_MENU_INC_LAYER_AND_APPEND_FILE:
case ID_INC_LAYER_AND_APPEND_FILE:
{
int origLayer = GetScreen()->m_Active_Layer;
GetScreen()->m_Active_Layer++;
if( !LoadOneGerberFile( wxEmptyString, &dc, 0 ) )
GetScreen()->m_Active_Layer = origLayer;
SetToolbars();
}
2007-09-25 15:10:01 +00:00
break;
case ID_MENU_APPEND_FILE:
case ID_APPEND_FILE:
LoadOneGerberFile( wxEmptyString, &dc, 0 );
break;
case ID_MENU_NEW_BOARD:
case ID_NEW_BOARD:
Clear_Pcb( TRUE );
2007-09-25 15:10:01 +00:00
Zoom_Automatique( FALSE );
GetScreen()->SetRefreshReq();
break;
case ID_GERBVIEW_LOAD_DRILL_FILE:
DisplayError( this, _( "Not yet available..." ) );
break;
case ID_GERBVIEW_LOAD_DCODE_FILE:
LoadDCodeFile( this, wxEmptyString, &dc );
break;
case ID_SAVE_BOARD:
case ID_MENU_SAVE_BOARD:
SaveGerberFile( GetScreen()->m_FileName, &dc );
break;
case ID_MENU_SAVE_BOARD_AS:
SaveGerberFile( wxEmptyString, &dc );
break;
default:
DisplayError( this, wxT( "File_io Internal Error" ) );
break;
}
DrawPanel->MouseToCursorSchema();
DrawPanel->CursorOn( &dc );
2007-05-06 16:03:28 +00:00
}
/*******************************************************************************************/
2009-05-28 20:46:16 +00:00
bool
WinEDA_GerberFrame::LoadOneGerberFile( const wxString& FullFileName,
wxDC* DC,
int mode )
2007-05-06 16:03:28 +00:00
/*******************************************************************************************/
/*
2007-09-25 15:10:01 +00:00
* Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s
* retourne:
* 0 si fichier non lu ( annulation de commande ... )
* 1 si OK
*/
2007-05-06 16:03:28 +00:00
{
2009-05-28 20:46:16 +00:00
wxString filetypes;
wxFileName filename = FullFileName;
2007-09-25 15:10:01 +00:00
ActiveScreen = GetScreen();
2009-05-28 20:46:16 +00:00
if( !filename.IsOk() )
2007-09-25 15:10:01 +00:00
{
2009-05-28 20:46:16 +00:00
wxString current_path = filename.GetPath();
/* Standard gerber filetypes */
filetypes += _("Gerber files (.gbr .gbx .lgr .ger .pho)| \
*.gbr;*.GBR;*.gbx;*.GBX;*.lgr;*.LGR;*.ger;*.GER;*.pho;*.PHO|");
/* Special gerber filetypes */
filetypes += _("Top layer (*.GTL)|*.GTL;*.gtl|");
2009-05-28 20:51:13 +00:00
filetypes += _("Bottom layer (*.GBL)|*.GBL;*.gbl|");
2009-05-28 20:46:16 +00:00
filetypes += _("Bottom solder resist (*.GBS)|*.GBS;*.gbs|");
filetypes += _("Top solder resist (*.GTS)|*.GTS;*.gts|");
filetypes += _("Bottom overlay (*.GBO)|*.GBO;*.gbo|");
filetypes += _("Top overlay (*.GTO)|*.GTO;*.gto|");
filetypes += _("Bottom paste (*.GBP)|*.GBP;*.gto|");
filetypes += _("Top paste (*.GTP)|*.GTP;*.gtp|");
filetypes += _("Keep-out layer (*.GKO)|*.GKO;*.gko|");
filetypes += _("Mechanical layers (*.GMx)|*.GM1;*.gm1;*.GM2;*.gm2;*.GM3;*.gm3|");
filetypes += _("Top Pad Master (*.GPT)|*.GPT;*.gpt|");
filetypes += _("Bottom Pad Master (*.GPB)|*.GPB;*.gpb|");
/* All filetypes */
filetypes += AllFilesWildcard;
/* Get current path if emtpy */
if ( current_path.IsEmpty() )
current_path = wxGetCwd();
wxFileDialog dlg( this,
_( "Open Gerber File" ),
current_path,
filename.GetFullName(),
filetypes,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
2008-02-23 01:26:21 +00:00
if( dlg.ShowModal() == wxID_CANCEL )
return false;
2008-02-23 01:26:21 +00:00
2009-05-28 20:46:16 +00:00
filename = dlg.GetPath();
}
2007-09-25 15:10:01 +00:00
2009-05-28 20:46:16 +00:00
GetScreen()->m_FileName = filename.GetFullPath();
wxSetWorkingDirectory( filename.GetPath() );
filename.SetExt( g_PenFilenameExt );
2009-05-28 20:46:16 +00:00
if( Read_GERBER_File( DC, GetScreen()->m_FileName, filename.GetFullPath() ) )
2007-09-25 15:10:01 +00:00
SetLastProject( GetScreen()->m_FileName );
Zoom_Automatique( FALSE );
GetScreen()->SetRefreshReq();
g_SaveTime = time( NULL );
return true;
2007-05-06 16:03:28 +00:00
}
2007-09-25 15:10:01 +00:00
2007-05-06 16:03:28 +00:00
/**********************************************************************************************/
2007-09-25 15:10:01 +00:00
static void LoadDCodeFile( WinEDA_GerberFrame* frame, const wxString& FullFileName, wxDC* DC )
2007-05-06 16:03:28 +00:00
/**********************************************************************************************/
/*
2007-09-25 15:10:01 +00:00
* Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s
* retourne:
* 0 si fichier non lu ( annulation de commande ... )
* 1 si OK
*/
2007-05-06 16:03:28 +00:00
{
wxString wildcard;
wxFileName fn = FullFileName;
2007-09-25 15:10:01 +00:00
ActiveScreen = frame->GetScreen();
if( !fn.IsOk() )
2007-09-25 15:10:01 +00:00
{
wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
g_PenFilenameExt.c_str(), g_PenFilenameExt.c_str());
wildcard += AllFilesWildcard;
fn = frame->GetScreen()->m_FileName;
fn.SetExt( g_PenFilenameExt );
wxFileDialog dlg( ( wxWindow* )frame, _( "Load GERBER DCODE File" ),
fn.GetPath(), fn.GetFullName(), wildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
2007-09-25 15:10:01 +00:00
return;
fn = dlg.GetPath();
2007-09-25 15:10:01 +00:00
}
frame->Read_D_Code_File( fn.GetFullPath() );
2007-09-25 15:10:01 +00:00
frame->CopyDCodesSizeToItems();
frame->GetScreen()->SetRefreshReq();
2007-05-06 16:03:28 +00:00
}
/*******************************************************************************/
2007-09-25 15:10:01 +00:00
bool WinEDA_GerberFrame::SaveGerberFile( const wxString& FullFileName, wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************************************************/
2007-09-25 15:10:01 +00:00
2007-05-06 16:03:28 +00:00
/* Sauvegarde du fichier PCB en format ASCII
2007-09-25 15:10:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
wxString wildcard;
wxFileName fn = FullFileName;
2007-09-25 15:10:01 +00:00
if( !fn.IsOk() )
2007-09-25 15:10:01 +00:00
{
fn = GetScreen()->m_FileName;
wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
g_PenFilenameExt.c_str(), g_PenFilenameExt.c_str());
wxFileDialog dlg( this, _( "Save Gerber File" ), fn.GetPath(),
fn.GetFullName(), wildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
return false;
fn = dlg.GetPath();
2007-09-25 15:10:01 +00:00
}
GetScreen()->m_FileName = fn.GetFullPath();
2007-05-06 16:03:28 +00:00
// TODO
return true;
2007-05-06 16:03:28 +00:00
}