Open file dialog fixes and minor code cleaning.

* Fix a minor problem with wxFileDialog to open a file that no longer
  exists in PCBNew.
* Make GerbView open file behavior the same as PCBNew.
* Remove redundant PCB file wild card definition.
* Add open file refactor task to the todo list.
* Fix some minor code formatting issues.
This commit is contained in:
Wayne Stambaugh 2010-05-17 16:35:46 -04:00
parent 6fba09e1bc
commit 5ce9c9a9d7
21 changed files with 124 additions and 109 deletions

View File

@ -24,7 +24,8 @@ Common
* List auto up and down scrolling. * List auto up and down scrolling.
* Integer/long/double input boxes should handle comma and dot separated values, * Integer/long/double input boxes should handle comma and dot separated values,
not only comma. not only comma.
* Push file open semantics down to one of the base frame classes ( likely candidate is
WinEDA_BasicFrame ) so that file open behavior is consistent across all applications.
ANYONE: ANYONE:
C2) Write a tool to generate DSNLEXER keyword tables (and enums) as *.cpp and C2) Write a tool to generate DSNLEXER keyword tables (and enums) as *.cpp and

View File

@ -55,17 +55,17 @@ Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] =
* that they cannot be changed. */ * that they cannot be changed. */
const wxString ProjectFileExtension( wxT( "pro" ) ); const wxString ProjectFileExtension( wxT( "pro" ) );
const wxString SchematicFileExtension( wxT( "sch" ) ); const wxString SchematicFileExtension( wxT( "sch" ) );
const wxString BoardFileExtension( wxT( "brd" ) );
const wxString NetlistFileExtension( wxT( "net" ) ); const wxString NetlistFileExtension( wxT( "net" ) );
const wxString GerberFileExtension( wxT( "pho" ) ); const wxString GerberFileExtension( wxT( "pho" ) );
const wxString PcbFileExtension( wxT( "brd" ) );
const wxString PdfFileExtension( wxT( "pdf" ) ); const wxString PdfFileExtension( wxT( "pdf" ) );
/* Proper wxFileDialog wild card definitions. */ /* Proper wxFileDialog wild card definitions. */
const wxString ProjectFileWildcard( _( "Kicad project files (*.pro)|*.pro" ) ); const wxString ProjectFileWildcard( _( "Kicad project files (*.pro)|*.pro" ) );
const wxString BoardFileWildcard( _( "Kicad PCB files (*.brd)|*.brd" ) );
const wxString SchematicFileWildcard( _( "Kicad schematic files (*.sch)|*.sch" ) ); const wxString SchematicFileWildcard( _( "Kicad schematic files (*.sch)|*.sch" ) );
const wxString NetlistFileWildcard( _( "Kicad netlist files (*.net)|*.net" ) ); const wxString NetlistFileWildcard( _( "Kicad netlist files (*.net)|*.net" ) );
const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) ); const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
const wxString PcbFileWildcard( _( "Kicad printed circuit board files (*.brd)|*.brd" ) );
const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) ); const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) );
const wxString AllFilesWildcard( _( "All files (*)|*" ) ); const wxString AllFilesWildcard( _( "All files (*)|*" ) );

View File

@ -72,7 +72,6 @@ wxArrayString g_LibName_List; // library list to load
DISPLAY_OPTIONS DisplayOpt; /* Display options for board items */ DISPLAY_OPTIONS DisplayOpt; /* Display options for board items */
/* PCB file name extension definitions. */ /* PCB file name extension definitions. */
wxString PcbExtBuffer( wxT( "brd" ) );
wxString g_SaveFileName( wxT( "$savepcb" ) ); wxString g_SaveFileName( wxT( "$savepcb" ) );
wxString NetExtBuffer( wxT( "net" ) ); wxString NetExtBuffer( wxT( "net" ) );
wxString NetCmpExtBuffer( wxT( "cmp" ) ); wxString NetCmpExtBuffer( wxT( "cmp" ) );
@ -80,11 +79,7 @@ wxString g_Shapes3DExtBuffer( wxT( "wrl" ) );
const wxString ModuleFileExtension( wxT( "mod" ) ); const wxString ModuleFileExtension( wxT( "mod" ) );
/* PCB file name wild card definitions. */ /* PCB file name wild card definitions. */
const wxString ModuleFileWildcard( const wxString ModuleFileWildcard( _( "Kicad footprint library files (*.mod)|*.mod" ) );
_( "Kicad footprint library files (*.mod)|*.mod" )
);
const wxString PcbFileWildcard(
_( "Printed circuit board files (*.brd)|*.brd" ) );
int g_CurrentVersionPCB = 1; int g_CurrentVersionPCB = 1;

View File

@ -281,8 +281,7 @@ void WinEDA_CvpcbFrame::OnCloseWindow( wxCloseEvent& Event )
m_modified = false; m_modified = false;
else if( diag == 0 ) else if( diag == 0 )
{ {
if( !IsOK( this, if( !IsOK( this, _( "Problem when saving files, exit anyway ?" ) ) )
_( "Problem when saving files, exit anyway ?" ) ) )
{ {
Event.Veto(); Event.Veto();
return; return;
@ -346,7 +345,8 @@ void WinEDA_CvpcbFrame::ToFirstNA( wxCommandEvent& event )
if( selection < 0 ) if( selection < 0 )
selection = 0; selection = 0;
BOOST_FOREACH( COMPONENT & component, m_components ) { BOOST_FOREACH( COMPONENT & component, m_components )
{
if( component.m_Module.IsEmpty() && ii > selection ) if( component.m_Module.IsEmpty() && ii > selection )
{ {
m_ListCmp->SetSelection( ii ); m_ListCmp->SetSelection( ii );
@ -444,10 +444,8 @@ void WinEDA_CvpcbFrame::LoadNetList( wxCommandEvent& event )
} }
else else
{ {
newFileName = wxFileName( wxGetCwd(), _( "unnamed" ), wxT( "net" ) ); wxFileDialog dlg( this, _( "Open Net List" ), wxGetCwd(),
wxEmptyString, NetlistFileWildcard,
wxFileDialog dlg( this, _( "Open Net List" ), newFileName.GetPath(),
newFileName.GetFullName(), NetlistFileWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR ); wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )

View File

@ -176,7 +176,7 @@ bool WinEDA_App::OnInit()
wxSetWorkingDirectory( filename.GetPath() ); wxSetWorkingDirectory( filename.GetPath() );
if( frame->DrawPanel if( frame->DrawPanel
&& frame->LoadOneEEProject( filename.GetFullPath(), false ) <= 0 ) && frame->LoadOneEEProject( filename.GetFullPath(), false ) )
frame->DrawPanel->Refresh( true ); frame->DrawPanel->Refresh( true );
} }
else else

View File

@ -50,7 +50,7 @@ void WinEDA_SchematicFrame::Save_File( wxCommandEvent& event )
* Schematic root file and its subhierarchies, the configuration and the libs * Schematic root file and its subhierarchies, the configuration and the libs
* which are not already loaded) * which are not already loaded)
*/ */
int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNew ) bool WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNew )
{ {
SCH_SCREEN* screen; SCH_SCREEN* screen;
wxString FullFileName, msg; wxString FullFileName, msg;
@ -67,7 +67,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe
if( screen ) if( screen )
{ {
if( !IsOK( this, _( "Clear schematic hierarchy?" ) ) ) if( !IsOK( this, _( "Clear schematic hierarchy?" ) ) )
return FALSE; return false;
if( g_RootSheet->m_AssociatedScreen->m_FileName != m_DefaultSchematicFileName ) if( g_RootSheet->m_AssociatedScreen->m_FileName != m_DefaultSchematicFileName )
SetLastProject( g_RootSheet->m_AssociatedScreen->m_FileName ); SetLastProject( g_RootSheet->m_AssociatedScreen->m_FileName );
} }
@ -80,7 +80,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe
wxFD_OPEN | wxFD_FILE_MUST_EXIST ); wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return 0; return false;
FullFileName = dlg.GetPath(); FullFileName = dlg.GetPath();
} }
@ -127,7 +127,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe
Zoom_Automatique( TRUE ); Zoom_Automatique( TRUE );
SetSheetNumberAndCount(); SetSheetNumberAndCount();
DrawPanel->Refresh(); DrawPanel->Refresh();
return 1; return true;
} }
// Reloading configuration. // Reloading configuration.
@ -143,13 +143,6 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe
// Delete old caches. // Delete old caches.
CMP_LIBRARY::RemoveCacheLibrary(); CMP_LIBRARY::RemoveCacheLibrary();
if( IsNew )
{
if( DrawPanel )
DrawPanel->Refresh( true );
return 1;
}
/* Loading the project library cache /* Loading the project library cache
* until apr 2009 the lib is named <root_name>.cache.lib * until apr 2009 the lib is named <root_name>.cache.lib
* and after (due to code change): <root_name>-cache.lib * and after (due to code change): <root_name>-cache.lib
@ -212,9 +205,9 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNe
{ {
Zoom_Automatique( FALSE ); Zoom_Automatique( FALSE );
msg.Printf( _( "File <%s> not found." ), msg.Printf( _( "File <%s> not found." ),
g_RootSheet->m_AssociatedScreen->m_FileName.GetData() ); GetChars( g_RootSheet->m_AssociatedScreen->m_FileName ) );
DisplayInfoMessage( this, msg, 0 ); DisplayInfoMessage( this, msg, 0 );
return -1; return false;
} }
// load the project. // load the project.

View File

@ -702,7 +702,7 @@ void WinEDA_SchematicFrame::OnOpenPcbnew( wxCommandEvent& event )
if( fn.IsOk() ) if( fn.IsOk() )
{ {
fn.SetExt( BoardFileExtension ); fn.SetExt( PcbFileExtension );
wxString filename = QuoteFullPath( fn ); wxString filename = QuoteFullPath( fn );

View File

@ -39,9 +39,12 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case wxID_FILE: case wxID_FILE:
{
wxString fileName = GetScreen()->m_FileName;
Erase_Current_Layer( false ); Erase_Current_Layer( false );
LoadOneGerberFile( wxEmptyString, 0 ); LoadOneGerberFile( fileName, true );
break; break;
}
case ID_MENU_INC_LAYER_AND_APPEND_FILE: case ID_MENU_INC_LAYER_AND_APPEND_FILE:
case ID_INC_LAYER_AND_APPEND_FILE: case ID_INC_LAYER_AND_APPEND_FILE:
@ -51,18 +54,23 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
{ {
setActiveLayer(origLayer+1); setActiveLayer(origLayer+1);
if( !LoadOneGerberFile( wxEmptyString, 0 ) ) if( !LoadOneGerberFile( wxEmptyString ) )
setActiveLayer(origLayer); setActiveLayer(origLayer);
SetToolbars(); SetToolbars();
} }
else else
wxMessageBox(_("Cannot increment layer number: max count reached") ); {
wxString msg;
msg.Printf( _( "GerbView only supports a maximum of %d layers. You must first \
delete an existing layer to load any new layers." ), NB_LAYERS );
wxMessageBox( msg );
}
} }
break; break;
case ID_APPEND_FILE: case ID_APPEND_FILE:
LoadOneGerberFile( wxEmptyString, 0 ); LoadOneGerberFile( wxEmptyString );
break; break;
case ID_NEW_BOARD: case ID_NEW_BOARD:
@ -94,25 +102,15 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
} }
/* bool WinEDA_GerberFrame::LoadOneGerberFile( const wxString& aFullFileName, bool aOpenFileDialog )
* Load a PCB file.
*
* Returns:
* 0 if file not read (cancellation of order ...)
* 1 if OK
*/
bool WinEDA_GerberFrame::LoadOneGerberFile( const wxString& FullFileName,
int mode )
{ {
wxString filetypes; wxString filetypes;
wxFileName filename = FullFileName; wxFileName filename = aFullFileName;
ActiveScreen = GetScreen(); ActiveScreen = GetScreen();
if( !filename.IsOk() ) if( !filename.IsOk() || aOpenFileDialog )
{ {
wxString current_path = filename.GetPath();
/* Standard gerber filetypes /* Standard gerber filetypes
* (See http://en.wikipedia.org/wiki/Gerber_File) * (See http://en.wikipedia.org/wiki/Gerber_File)
* the .pho extension is the default used in Pcbnew * the .pho extension is the default used in Pcbnew
@ -139,9 +137,11 @@ bool WinEDA_GerberFrame::LoadOneGerberFile( const wxString& FullFileName,
/* All filetypes */ /* All filetypes */
filetypes += AllFilesWildcard; filetypes += AllFilesWildcard;
/* Get current path if emtpy */ /* Use the current working directory if the file name path does not exist. */
if( current_path.IsEmpty() ) wxString current_path = wxGetCwd();
current_path = wxGetCwd();
if( filename.DirExists() )
current_path = filename.GetPath();
wxFileDialog dlg( this, wxFileDialog dlg( this,
_( "Open Gerber File" ), _( "Open Gerber File" ),

View File

@ -61,14 +61,15 @@ IMPLEMENT_APP( WinEDA_App )
/* MacOSX: Needed for file association /* MacOSX: Needed for file association
* http://wiki.wxwidgets.org/WxMac-specific_topics * http://wiki.wxwidgets.org/WxMac-specific_topics
*/ */
void WinEDA_App::MacOpenFile(const wxString &fileName) { void WinEDA_App::MacOpenFile(const wxString &fileName)
{
wxFileName filename = fileName; wxFileName filename = fileName;
WinEDA_GerberFrame * frame = ((WinEDA_GerberFrame*)GetTopWindow()); WinEDA_GerberFrame * frame = ((WinEDA_GerberFrame*)GetTopWindow());
if( !filename.FileExists() ) if( !filename.FileExists() )
return; return;
frame->LoadOneGerberFile( fileName, FALSE ); frame->LoadOneGerberFile( fileName );
} }
@ -142,7 +143,7 @@ bool WinEDA_App::OnInit()
if( fn.FileExists() ) if( fn.FileExists() )
{ {
( (PCB_SCREEN*) frame->GetScreen() )->m_Active_Layer = ii - 1; ( (PCB_SCREEN*) frame->GetScreen() )->m_Active_Layer = ii - 1;
frame->LoadOneGerberFile( fn.GetFullPath(), FALSE ); frame->LoadOneGerberFile( fn.GetFullPath() );
} }
} }
} }

View File

@ -286,7 +286,18 @@ public:
void Files_io( wxCommandEvent& event ); void Files_io( wxCommandEvent& event );
void OnFileHistory( wxCommandEvent& event ); void OnFileHistory( wxCommandEvent& event );
bool LoadOneGerberFile( const wxString& FileName, int mode );
/**
* Load a photoplot (Gerber) file.
*
* @param aFileName - File name with full path to open or empty string to open a new
* file.
* @param aOpenFileDialog - Set to true to display the open file dialog even if
* aFileName is valid.
*
* @return - True if file was opened successfully.
*/
bool LoadOneGerberFile( const wxString& aFileName, bool aOpenFileDialog = false );
int ReadGerberFile( FILE* File, bool Append ); int ReadGerberFile( FILE* File, bool Append );
bool Read_GERBER_File( const wxString& GERBER_FullFileName, bool Read_GERBER_File( const wxString& GERBER_FullFileName,
const wxString& D_Code_FullFileName ); const wxString& D_Code_FullFileName );

View File

@ -160,9 +160,9 @@ extern bool g_ShowPageLimits; // TRUE to display the page limits
/* File name extension definitions. */ /* File name extension definitions. */
extern const wxString ProjectFileExtension; extern const wxString ProjectFileExtension;
extern const wxString SchematicFileExtension; extern const wxString SchematicFileExtension;
extern const wxString BoardFileExtension;
extern const wxString NetlistFileExtension; extern const wxString NetlistFileExtension;
extern const wxString GerberFileExtension; extern const wxString GerberFileExtension;
extern const wxString PcbFileExtension;
extern const wxString PdfFileExtension; extern const wxString PdfFileExtension;
extern const wxString ProjectFileWildcard; extern const wxString ProjectFileWildcard;
@ -170,6 +170,7 @@ extern const wxString SchematicFileWildcard;
extern const wxString BoardFileWildcard; extern const wxString BoardFileWildcard;
extern const wxString NetlistFileWildcard; extern const wxString NetlistFileWildcard;
extern const wxString GerberFileWildcard; extern const wxString GerberFileWildcard;
extern const wxString PcbFileWildcard;
extern const wxString PdfFileWildcard; extern const wxString PdfFileWildcard;
extern const wxString AllFilesWildcard; extern const wxString AllFilesWildcard;

View File

@ -23,14 +23,12 @@ extern int g_TabAllCopperLayerMask[NB_COPPER_LAYERS];
extern wxArrayString g_LibName_List; // library list to load extern wxArrayString g_LibName_List; // library list to load
extern DISPLAY_OPTIONS DisplayOpt; extern DISPLAY_OPTIONS DisplayOpt;
extern wxString PcbExtBuffer;
extern wxString g_SaveFileName; extern wxString g_SaveFileName;
extern wxString NetExtBuffer; extern wxString NetExtBuffer;
extern wxString NetCmpExtBuffer; extern wxString NetCmpExtBuffer;
extern const wxString ModuleFileExtension; extern const wxString ModuleFileExtension;
extern const wxString ModuleFileWildcard; extern const wxString ModuleFileWildcard;
extern const wxString PcbFileWildcard;
extern wxString g_ViaType_Name[4]; extern wxString g_ViaType_Name[4];

View File

@ -270,7 +270,7 @@ public:
// read and save files // read and save files
void Save_File( wxCommandEvent& event ); void Save_File( wxCommandEvent& event );
void SaveProject(); void SaveProject();
int LoadOneEEProject( const wxString& FileName, bool IsNew ); bool LoadOneEEProject( const wxString& FileName, bool IsNew );
bool LoadOneEEFile( SCH_SCREEN* screen, bool LoadOneEEFile( SCH_SCREEN* screen,
const wxString& FullFileName ); const wxString& FullFileName );
bool ReadInputStuffFile(); bool ReadInputStuffFile();

View File

@ -495,7 +495,20 @@ public:
void OnFileHistory( wxCommandEvent& event ); void OnFileHistory( wxCommandEvent& event );
void Files_io( wxCommandEvent& event ); void Files_io( wxCommandEvent& event );
bool LoadOnePcbFile( const wxString& FileName, bool Append );
/**
* Load a Kicad board (.brd) file.
*
* @param aFileName - File name including path. If empty, a file dialog will
* be displayed.
* @param aAppend - Append board file aFileName to the currently loaded file if true.
* @param aForceFileDialog - Display the file open dialog even if aFullFileName is
* valid if true.
*
* @return False if file load fails or is cancelled by the user, otherwise true.
*/
bool LoadOnePcbFile( const wxString& aFileName, bool aAppend,
bool aForceFileDialog = false );
/** /**

View File

@ -176,7 +176,7 @@ void WinEDA_MainFrame::OnRunPcbNew( wxCommandEvent& event )
{ {
wxFileName fn( m_ProjectFileName ); wxFileName fn( m_ProjectFileName );
fn.SetExt( BoardFileExtension ); fn.SetExt( PcbFileExtension );
ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( fn ) ); ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( fn ) );
} }

View File

@ -46,7 +46,7 @@ void WinEDA_MainFrame::CreateNewProject( const wxString PrjFullFileName )
/* Init pcb board filename */ /* Init pcb board filename */
m_BoardFileName = wxFileName( newProjectName.GetName(), m_BoardFileName = wxFileName( newProjectName.GetName(),
BoardFileExtension ).GetFullName(); PcbFileExtension ).GetFullName();
/* Init project filename */ /* Init project filename */
m_ProjectFileName = newProjectName; m_ProjectFileName = newProjectName;

View File

@ -425,7 +425,7 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
break; break;
case TREE_PCB: case TREE_PCB:
ext = BoardFileExtension; ext = PcbFileExtension;
break; break;
case TREE_GERBER: case TREE_GERBER:
@ -468,7 +468,7 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
break; break;
case TREE_PCB: case TREE_PCB:
ext = BoardFileWildcard; ext = PcbFileWildcard;
break; break;
case TREE_GERBER: case TREE_GERBER:
@ -704,7 +704,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
if( !fn.FileExists() ) if( !fn.FileExists() )
AddFile( fn.GetFullName(), m_root ); AddFile( fn.GetFullName(), m_root );
fn.SetExt( BoardFileExtension ); fn.SetExt( PcbFileExtension );
if( !fn.FileExists( ) ) if( !fn.FileExists( ) )
AddFile( fn.GetFullName(), m_root ); AddFile( fn.GetFullName(), m_root );

View File

@ -244,7 +244,7 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
if( (CurrentTime - g_SaveTime) > g_TimeOut ) if( (CurrentTime - g_SaveTime) > g_TimeOut )
{ {
wxString tmpFileName = GetScreen()->m_FileName; wxString tmpFileName = GetScreen()->m_FileName;
wxFileName fn = wxFileName( wxEmptyString, g_SaveFileName, PcbExtBuffer ); wxFileName fn = wxFileName( wxEmptyString, g_SaveFileName, PcbFileExtension );
bool flgmodify = GetScreen()->IsModify(); bool flgmodify = GetScreen()->IsModify();
SavePcbFile( fn.GetFullPath() ); SavePcbFile( fn.GetFullPath() );

View File

@ -47,7 +47,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case ID_LOAD_FILE: case ID_LOAD_FILE:
LoadOnePcbFile( wxEmptyString, false ); LoadOnePcbFile( GetScreen()->m_FileName, false, true );
ReCreateAuxiliaryToolbar(); ReCreateAuxiliaryToolbar();
break; break;
@ -58,7 +58,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
if( id == ID_MENU_RECOVER_BOARD ) if( id == ID_MENU_RECOVER_BOARD )
{ {
fn = wxFileName( wxEmptyString, g_SaveFileName, PcbExtBuffer ); fn = wxFileName( wxEmptyString, g_SaveFileName, PcbFileExtension );
} }
else else
{ {
@ -80,7 +80,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
} }
LoadOnePcbFile( fn.GetFullPath(), false ); LoadOnePcbFile( fn.GetFullPath(), false );
fn.SetExt( PcbExtBuffer ); fn.SetExt( PcbFileExtension );
GetScreen()->m_FileName = fn.GetFullPath(); GetScreen()->m_FileName = fn.GetFullPath();
SetTitle( GetScreen()->m_FileName ); SetTitle( GetScreen()->m_FileName );
ReCreateAuxiliaryToolbar(); ReCreateAuxiliaryToolbar();
@ -95,7 +95,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
Clear_Pcb( true ); Clear_Pcb( true );
GetScreen()->m_FileName.Printf( wxT( "%s%cnoname%s" ), GetScreen()->m_FileName.Printf( wxT( "%s%cnoname%s" ),
GetChars( wxGetCwd() ), DIR_SEP, GetChars( wxGetCwd() ), DIR_SEP,
GetChars( PcbExtBuffer ) ); GetChars( PcbFileExtension ) );
SetTitle( GetScreen()->m_FileName ); SetTitle( GetScreen()->m_FileName );
ReCreateLayerBox( NULL ); ReCreateLayerBox( NULL );
break; break;
@ -114,12 +114,8 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
} }
/** bool WinEDA_PcbFrame::LoadOnePcbFile( const wxString& aFileName, bool Append,
* Read a board file bool aForceFileDialog )
* @param FullFileName = file name. If empty, a file name will be asked
* @return 0 if fails or abort, 1 if OK
*/
bool WinEDA_PcbFrame::LoadOnePcbFile( const wxString& FullFileName, bool Append )
{ {
int ii; int ii;
FILE* source; FILE* source;
@ -144,27 +140,35 @@ the changes?" ) ) )
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
} }
wxString fileName; wxFileName fileName = aFileName;
if( FullFileName == wxEmptyString ) if( !fileName.IsOk() || !fileName.FileExists() || aForceFileDialog )
{ {
wxFileName fn = GetScreen()->m_FileName; wxString name;
wxString path = wxGetCwd();
wxFileDialog dlg( this, _( "Open Board File" ), wxEmptyString, fn.GetFullName(), if( aForceFileDialog && fileName.FileExists() )
PcbFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); {
path = fileName.GetPath();
name = fileName.GetFullName();
}
wxFileDialog dlg( this, _( "Open Board File" ), path, name, PcbFileWildcard,
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return false; return false;
fileName = dlg.GetPath(); fileName = dlg.GetPath();
if( !fileName.HasExt() )
fileName.SetExt( PcbFileExtension );
} }
else
fileName = FullFileName;
if( !Append ) if( !Append )
Clear_Pcb( false ); // pass false since we prompted above for a modified board Clear_Pcb( false ); // pass false since we prompted above for a modified board
GetScreen()->m_FileName = fileName; GetScreen()->m_FileName = fileName.GetFullPath();
/* Start read PCB file /* Start read PCB file
*/ */
@ -229,7 +233,7 @@ this file again." ) );
if ( ! new_filename.EndsWith( wxT( "-append" ) ) ) if ( ! new_filename.EndsWith( wxT( "-append" ) ) )
new_filename += wxT( "-append" ); new_filename += wxT( "-append" );
new_filename += wxT( "." ) + PcbExtBuffer; new_filename += wxT( "." ) + PcbFileExtension;
OnModify(); OnModify();
GetScreen()->m_FileName = new_filename; GetScreen()->m_FileName = new_filename;
@ -310,7 +314,7 @@ bool WinEDA_PcbFrame::SavePcbFile( const wxString& FileName )
if( FileName == wxEmptyString ) if( FileName == wxEmptyString )
{ {
wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString, wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString,
GetScreen()->m_FileName, BoardFileWildcard, GetScreen()->m_FileName, PcbFileWildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )

View File

@ -120,11 +120,11 @@ bool WinEDA_App::OnInit()
{ {
fn = argv[1]; fn = argv[1];
if( fn.GetExt() != BoardFileExtension ) if( fn.GetExt() != PcbFileExtension )
{ {
wxLogDebug( wxT( "PcbNew file <%s> has the wrong extension. \ wxLogDebug( wxT( "PcbNew file <%s> has the wrong extension. \
Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
fn.SetExt( BoardFileExtension ); fn.SetExt( PcbFileExtension );
} }
if( fn.IsOk() && fn.DirExists() ) if( fn.IsOk() && fn.DirExists() )