Commit c64a6937 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Add user write permission tests to EESchama and other minor fixes.

* Add general purpose user write permission test function to base
  window class.
* Check user write permissions before saving project, schematic and
  library files.
* Remove displaying file dialog every time the project file is saved.
* Display absolute paths for non-root sheet file in title bar.
* Remove redundant command table entry from schematic editor.
* Remove unused variables to fix GCC 4.6 warnings.
* The usual Doxygen comment and coding style policy fixes.
parent 2b453357
...@@ -851,7 +851,7 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) ...@@ -851,7 +851,7 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas )
dx, dx0, dy, dy0, dx, dx0, dy, dy0,
delta_cx, delta_cy, delta_cx, delta_cy,
xc, yc; xc, yc;
int angle, delta_angle; int angle;
double scale; double scale;
double zpos; double zpos;
wxPoint shape_pos; wxPoint shape_pos;
...@@ -933,14 +933,12 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) ...@@ -933,14 +933,12 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas )
delta_cx = dx - dy; delta_cx = dx - dy;
delta_cy = 0; delta_cy = 0;
w = m_Size.y * scale; w = m_Size.y * scale;
delta_angle = angle + 900;
} }
else /* Vertical ellipse */ else /* Vertical ellipse */
{ {
delta_cx = 0; delta_cx = 0;
delta_cy = dy - dx; delta_cy = dy - dx;
w = m_Size.x * scale; w = m_Size.x * scale;
delta_angle = angle;
} }
RotatePoint( &delta_cx, &delta_cy, angle ); RotatePoint( &delta_cx, &delta_cy, angle );
{ {
......
...@@ -291,7 +291,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, ...@@ -291,7 +291,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize,
char* text; char* text;
bool HasData = FALSE; bool HasData = FALSE;
bool StartData = FALSE; bool StartData = FALSE;
bool EndData = FALSE;
bool EndNode = FALSE; bool EndNode = FALSE;
char string_num[512]; char string_num[512];
...@@ -338,7 +337,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, ...@@ -338,7 +337,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize,
if( *text == ']' ) if( *text == ']' )
{ {
StartData = FALSE; StartData = FALSE;
EndData = TRUE;
} }
break; break;
......
...@@ -445,3 +445,35 @@ void EDA_BASE_FRAME::CopyVersionInfoToClipboard( wxCommandEvent& event ) ...@@ -445,3 +445,35 @@ void EDA_BASE_FRAME::CopyVersionInfoToClipboard( wxCommandEvent& event )
wxTheClipboard->SetData( new wxTextDataObject( tmp ) ); wxTheClipboard->SetData( new wxTextDataObject( tmp ) );
wxTheClipboard->Close(); wxTheClipboard->Close();
} }
bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
{
wxString msg;
wxCHECK_MSG( aFileName.IsOk(), false, wxT( "Invalid file name object. Bad programmer!" ) );
if( aFileName.IsDir() && !aFileName.IsDirWritable() )
{
msg.Printf( _( "You do not have write permissions to folder <%s>." ),
GetChars( aFileName.GetPath() ) );
}
else if( !aFileName.FileExists() && !aFileName.IsDirWritable() )
{
msg.Printf( _( "You do not have write permissions to save file <%s> to folder <%s>." ),
GetChars( aFileName.GetFullName() ), GetChars( aFileName.GetPath() ) );
}
else if( aFileName.FileExists() && !aFileName.IsFileWritable() )
{
msg.Printf( _( "You do not have write permissions to save file <%s>." ),
GetChars( aFileName.GetFullPath() ) );
}
if( !msg.IsEmpty() )
{
DisplayError( this, msg );
return false;
}
return true;
}
...@@ -197,7 +197,7 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) ...@@ -197,7 +197,7 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event )
LIB_EDIT_FRAME::EnsureActiveLibExists(); LIB_EDIT_FRAME::EnsureActiveLibExists();
} }
m_Parent->SaveProjectFile( this, false ); m_Parent->SaveProjectFile();
EndModal( wxID_OK ); EndModal( wxID_OK );
} }
......
...@@ -79,16 +79,21 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -79,16 +79,21 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
// Window title format: // Window title format:
// [filename sheetpath] (/path/to/filedir) // [filename sheetpath] (/path/to/filedir)
// Often the /path/to/filedir is blank because of the FullFileName argument
// passed to LoadOneEEFile() which currently omits the path on non-root schematics.
wxFileName t( GetScreen()->GetFileName() ); wxFileName t( GetScreen()->GetFileName() );
// Often the /path/to/filedir is blank because of the FullFileName argument
// passed to LoadOneEEFile() which omits the path on non-root schematics.
// Making the path absolute solves this problem.
t.MakeAbsolute();
title = wxChar( '[' ); title = wxChar( '[' );
title << t.GetName() << wxChar( ' ' ); title << t.GetName() << wxChar( ' ' );
title << m_CurrentSheet->PathHumanReadable() << wxChar( ']' ); title << m_CurrentSheet->PathHumanReadable() << wxChar( ']' );
title << wxChar( ' ' ); title << wxChar( ' ' );
title << wxChar( '(' ) << t.GetPath() << wxChar( ')' ); title << wxChar( '(' ) << t.GetPath() << wxChar( ')' );
if( !t.IsFileWritable() )
title << _( " [Read Only]" );
#endif #endif
SetTitle( title ); SetTitle( title );
......
...@@ -59,7 +59,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -59,7 +59,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case ID_CONFIG_SAVE: case ID_CONFIG_SAVE:
schFrame->SaveProjectFile( this, false ); schFrame->SaveProjectFile();
break; break;
case ID_CONFIG_READ: case ID_CONFIG_READ:
...@@ -74,7 +74,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -74,7 +74,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
break; break;
schFrame->LoadProjectFile( dlg.GetPath(), TRUE ); schFrame->LoadProjectFile( dlg.GetPath(), true );
} }
break; break;
...@@ -127,7 +127,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -127,7 +127,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case ID_CONFIG_SAVE: case ID_CONFIG_SAVE:
SaveProjectFile( this, false ); SaveProjectFile();
break; break;
case ID_CONFIG_READ: case ID_CONFIG_READ:
...@@ -142,7 +142,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -142,7 +142,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
break; break;
LoadProjectFile( dlg.GetPath(), TRUE ); LoadProjectFile( dlg.GetPath(), true );
} }
break; break;
...@@ -251,15 +251,6 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) ...@@ -251,15 +251,6 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
} }
/**
* Return project file parameter list for EESchema.
*
* Populate the project file parameter array specific to EESchema if it hasn't
* already been populated and return a reference to the array to the caller.
* Creating the parameter list at run time has the advantage of being able
* to define local variables. The old method of statically building the array
* at compile time requiring global variable definitions.
*/
PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParameters( void ) PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParameters( void )
{ {
if( !m_projectFileParams.empty() ) if( !m_projectFileParams.empty() )
...@@ -344,19 +335,16 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParameters( void ) ...@@ -344,19 +335,16 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParameters( void )
} }
/* bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& aFileName, bool aForceReread )
* Load the Kicad project file (*.pro) settings specific to EESchema.
*/
bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& CfgFileName, bool ForceRereadConfig )
{ {
wxFileName fn; wxFileName fn;
bool IsRead = TRUE; bool IsRead = true;
wxArrayString liblist_tmp = m_ComponentLibFiles; wxArrayString liblist_tmp = m_ComponentLibFiles;
if( CfgFileName.IsEmpty() ) if( aFileName.IsEmpty() )
fn = g_RootSheet->GetScreen()->GetFileName(); fn = g_RootSheet->GetScreen()->GetFileName();
else else
fn = CfgFileName; fn = aFileName;
m_ComponentLibFiles.Clear(); m_ComponentLibFiles.Clear();
...@@ -368,16 +356,16 @@ bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& CfgFileName, bool ForceRer ...@@ -368,16 +356,16 @@ bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& CfgFileName, bool ForceRer
if( !wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, if( !wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP,
GetProjectFileParameters(), GetProjectFileParameters(),
ForceRereadConfig ? FALSE : TRUE ) ) !aForceReread ) )
{ {
m_ComponentLibFiles = liblist_tmp; m_ComponentLibFiles = liblist_tmp;
IsRead = FALSE; IsRead = false;
} }
/* User library path takes precedent over default library search paths. */ /* User library path takes precedent over default library search paths. */
wxGetApp().InsertLibraryPath( m_UserLibraryPath, 1 ); wxGetApp().InsertLibraryPath( m_UserLibraryPath, 1 );
/* If the list is void, force loadind the library "power.lib" that is /* If the list is void, force loading the library "power.lib" that is
* the "standard" library for power symbols. * the "standard" library for power symbols.
*/ */
if( m_ComponentLibFiles.GetCount() == 0 ) if( m_ComponentLibFiles.GetCount() == 0 )
...@@ -390,26 +378,17 @@ bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& CfgFileName, bool ForceRer ...@@ -390,26 +378,17 @@ bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& CfgFileName, bool ForceRer
} }
/* void SCH_EDIT_FRAME::SaveProjectFile()
* Save the Kicad project file (*.pro) settings specific to EESchema.
*/
void SCH_EDIT_FRAME::SaveProjectFile( wxWindow* displayframe, bool askoverwrite )
{ {
wxFileName fn; wxFileName fn;
fn = g_RootSheet->GetScreen()->GetFileName(); /*ConfigFileName*/ fn = g_RootSheet->GetScreen()->GetFileName(); /*ConfigFileName*/
fn.SetExt( ProjectFileExtension ); fn.SetExt( ProjectFileExtension );
int options = wxFD_SAVE; if( !IsWritable( fn ) )
if( askoverwrite )
options |= wxFD_OVERWRITE_PROMPT;
wxFileDialog dlg( displayframe, _( "Save Project Settings" ), wxGetCwd(),
fn.GetFullName(), ProjectFileWildcard, options );
if( dlg.ShowModal() == wxID_CANCEL )
return; return;
wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP, GetProjectFileParameters() ); wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() );
} }
...@@ -437,22 +416,7 @@ static const wxString FieldNamesEntry( wxT( "FieldNames" ) ); ...@@ -437,22 +416,7 @@ static const wxString FieldNamesEntry( wxT( "FieldNames" ) );
static const wxString SpiceNetNamesEntry( wxT( "SpiceUseNetNames" ) ); static const wxString SpiceNetNamesEntry( wxT( "SpiceUseNetNames" ) );
static const wxString SimulatorCommandEntry( wxT( "SimCmdLine" ) ); static const wxString SimulatorCommandEntry( wxT( "SimCmdLine" ) );
/*
* Return the EESchema applications settings list.
*
* This replaces the old statically define list that had the project
* file settings and the application settings mixed together. This
* was confusing and caused some settings to get saved and loaded
* incorrectly. Currently, only the settings that are needed at start
* up by the main window are defined here. There are other locally used
* settings scattered thoughout the EESchema source code. If you need
* to define a configuration setting that need to be loaded at run time,
* this is the place to define it.
*
* TODO: Define the configuration variables as member variables instead of
* global variables or move them to the object class where they are
* used.
*/
PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetConfigurationSettings( void ) PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetConfigurationSettings( void )
{ {
if( !m_configSettings.empty() ) if( !m_configSettings.empty() )
...@@ -545,9 +509,6 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetConfigurationSettings( void ) ...@@ -545,9 +509,6 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetConfigurationSettings( void )
} }
/*
* Load the EESchema configuration parameters.
*/
void SCH_EDIT_FRAME::LoadSettings() void SCH_EDIT_FRAME::LoadSettings()
{ {
wxASSERT( wxGetApp().m_EDA_Config != NULL ); wxASSERT( wxGetApp().m_EDA_Config != NULL );
...@@ -560,7 +521,7 @@ void SCH_EDIT_FRAME::LoadSettings() ...@@ -560,7 +521,7 @@ void SCH_EDIT_FRAME::LoadSettings()
wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() ); wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );
// This is eqired until someone gets rid of the global variable g_LayerDescription(). // This is required until someone gets rid of the global variable g_LayerDescription().
m_GridColor = g_LayerDescr.LayerColor[LAYER_GRID]; m_GridColor = g_LayerDescr.LayerColor[LAYER_GRID];
g_DrawDefaultLineThickness = cfg->Read( DefaultDrawLineWidthEntry,(long) 6 ); g_DrawDefaultLineThickness = cfg->Read( DefaultDrawLineWidthEntry,(long) 6 );
...@@ -644,9 +605,6 @@ void SCH_EDIT_FRAME::LoadSettings() ...@@ -644,9 +605,6 @@ void SCH_EDIT_FRAME::LoadSettings()
} }
/*
* Save the EESchema configuration parameters.
*/
void SCH_EDIT_FRAME::SaveSettings() void SCH_EDIT_FRAME::SaveSettings()
{ {
wxASSERT( wxGetApp().m_EDA_Config != NULL ); wxASSERT( wxGetApp().m_EDA_Config != NULL );
...@@ -718,4 +676,3 @@ void SCH_EDIT_FRAME::SaveSettings() ...@@ -718,4 +676,3 @@ void SCH_EDIT_FRAME::SaveSettings()
cfg->Write( FieldNamesEntry, record ); cfg->Write( FieldNamesEntry, record );
} }
...@@ -17,31 +17,28 @@ ...@@ -17,31 +17,28 @@
#include "sch_sheet.h" #include "sch_sheet.h"
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType )
/*****************************************************************************
* Routine to save an EESchema file. *
* FileSave controls how the file is to be saved - under what name. *
* Returns true if the file has been saved. *
*****************************************************************************/
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave )
{ {
wxString msg; wxString msg;
wxFileName schematicFileName, backupFileName; wxFileName schematicFileName, backupFileName;
FILE* f; FILE* f;
if( screen == NULL ) if( aScreen == NULL )
screen = GetScreen(); aScreen = GetScreen();
/* If no name exists in the window yet - save as new. */ /* If no name exists in the window yet - save as new. */
if( screen->GetFileName().IsEmpty() ) if( aScreen->GetFileName().IsEmpty() )
FileSave = FILE_SAVE_NEW; aSaveType = FILE_SAVE_NEW;
switch( FileSave ) switch( aSaveType )
{ {
case FILE_SAVE_AS: case FILE_SAVE_AS:
schematicFileName = screen->GetFileName(); schematicFileName = aScreen->GetFileName();
backupFileName = schematicFileName; backupFileName = schematicFileName;
if( !IsWritable( schematicFileName ) )
return false;
/* Rename the old file to a '.bak' one: */ /* Rename the old file to a '.bak' one: */
if( schematicFileName.FileExists() ) if( schematicFileName.FileExists() )
{ {
...@@ -50,23 +47,29 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave ) ...@@ -50,23 +47,29 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave )
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) ) if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{ {
DisplayError( this, wxT( "Warning: unable to rename old file" ) ); DisplayError( this, _( "Could not save backup of file <" ) +
schematicFileName.GetFullPath() + wxT( ">." ) );
} }
} }
break; break;
case FILE_SAVE_NEW: case FILE_SAVE_NEW:
{ {
schematicFileName = aScreen->GetFileName();
wxFileDialog dlg( this, _( "Schematic Files" ), wxGetCwd(), wxFileDialog dlg( this, _( "Schematic Files" ), wxGetCwd(),
screen->GetFileName(), SchematicFileWildcard, schematicFileName.GetFullName(), SchematicFileWildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return false; return false;
screen->SetFileName( dlg.GetPath() ); aScreen->SetFileName( dlg.GetPath() );
schematicFileName = dlg.GetPath(); schematicFileName = dlg.GetPath();
if( !IsWritable( schematicFileName ) )
return false;
break; break;
} }
...@@ -81,19 +84,21 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave ) ...@@ -81,19 +84,21 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave )
return false; return false;
} }
if( FileSave == FILE_SAVE_NEW ) if( aSaveType == FILE_SAVE_NEW )
screen->SetFileName( schematicFileName.GetFullPath() ); aScreen->SetFileName( schematicFileName.GetFullPath() );
bool success = screen->Save( f ); bool success = aScreen->Save( f );
if( !success ) if( !success )
{
DisplayError( this, _( "File write operation failed." ) ); DisplayError( this, _( "File write operation failed." ) );
}
else else
{ {
screen->ClrModify(); aScreen->ClrModify();
wxString msg; wxString msg;
msg.Printf( wxT("File %s saved"), GetChars(screen->GetFileName() ) ); msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) );
SetStatusText(msg, 0); SetStatusText( msg, 0 );
} }
...@@ -103,18 +108,12 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave ) ...@@ -103,18 +108,12 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* screen, int FileSave )
} }
/* Commands to save project or the current page.
*/
void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event ) void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event )
{ {
int id = event.GetId(); int id = event.GetId();
switch( id ) switch( id )
{ {
case ID_SAVE_PROJECT: /* Update Schematic File */
SaveProject();
break;
case ID_SAVE_ONE_SHEET: /* Update Schematic File */ case ID_SAVE_ONE_SHEET: /* Update Schematic File */
SaveEEFile( NULL, FILE_SAVE_AS ); SaveEEFile( NULL, FILE_SAVE_AS );
break; break;
...@@ -130,13 +129,7 @@ void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event ) ...@@ -130,13 +129,7 @@ void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event )
} }
/** bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
* Load an entire project
*
* Schematic root file and its subhierarchies, the configuration and the libs
* which are not already loaded)
*/
bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
{ {
SCH_SCREEN* screen; SCH_SCREEN* screen;
wxString FullFileName, msg; wxString FullFileName, msg;
...@@ -155,9 +148,9 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -155,9 +148,9 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
return false; return false;
} }
FullFileName = FileName; FullFileName = aFileName;
if( ( FullFileName.IsEmpty() ) && !IsNew ) if( ( FullFileName.IsEmpty() ) && !aIsNew )
{ {
wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(), wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(),
wxEmptyString, SchematicFileWildcard, wxEmptyString, SchematicFileWildcard,
...@@ -184,6 +177,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -184,6 +177,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
fn.MakeAbsolute(); fn.MakeAbsolute();
FullFileName = fn.GetFullPath(); FullFileName = fn.GetFullPath();
} }
wxLogDebug( wxT( "Loading schematic " ) + FullFileName ); wxLogDebug( wxT( "Loading schematic " ) + FullFileName );
wxSetWorkingDirectory( fn.GetPath() ); wxSetWorkingDirectory( fn.GetPath() );
...@@ -196,7 +190,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -196,7 +190,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
screen->ClrModify(); screen->ClrModify();
if( IsNew ) if( aIsNew )
{ {
screen->m_CurrentSheetDesc = &g_Sheet_A4; screen->m_CurrentSheetDesc = &g_Sheet_A4;
screen->SetZoom( 32 ); screen->SetZoom( 32 );
...@@ -233,7 +227,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -233,7 +227,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
* 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
* so if the <name>-cache.lib is not found, the old way will be tried * so if the <name>-cache.lib is not found, the old way will be tried
*/ */
fn = g_RootSheet->GetScreen()->GetFileName(); fn = g_RootSheet->GetScreen()->GetFileName();
bool use_oldcachename = false; bool use_oldcachename = false;
...@@ -263,6 +257,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -263,6 +257,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
{ {
LibCache->SetCache(); LibCache->SetCache();
msg += wxT( " OK" ); msg += wxT( " OK" );
if ( use_oldcachename ) // set the new name if ( use_oldcachename ) // set the new name
{ {
fn.SetName( cachename ); fn.SetName( cachename );
...@@ -312,28 +307,27 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew ) ...@@ -312,28 +307,27 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& FileName, bool IsNew )
} }
/** void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
* Save the entire project and create an archive for components.
*
* The library archive name is &ltroot_name&gt-cache.lib
*/
void SCH_EDIT_FRAME::SaveProject()
{ {
SCH_SCREEN* screen; SCH_SCREEN* screen;
wxFileName fn; wxFileName fn;
wxFileName tmp;
SCH_SCREENS ScreenList; SCH_SCREENS ScreenList;
fn = g_RootSheet->GetFileName();
tmp.AssignDir( fn.GetPath() );
if( !IsWritable( tmp ) )
return;
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() ) for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
{ {
D( printf( "SaveEEFile, %s\n", TO_UTF8( screen->GetFileName() ) ); ) D( printf( "SaveEEFile, %s\n", TO_UTF8( screen->GetFileName() ) ); )
SaveEEFile( screen, FILE_SAVE_AS ); SaveEEFile( screen, FILE_SAVE_AS );
} }
/* Archive components in current directory. */ wxString cachename = fn.GetName() + wxT( "-cache" );
fn = g_RootSheet->GetFileName();
wxString cachename = fn.GetName() + wxT( "-cache" );
fn.SetName( cachename ); fn.SetName( cachename );
fn.SetExt( CompLibFileExtension ); fn.SetExt( CompLibFileExtension );
LibArchive( this, fn.GetFullPath() ); LibArchive( this, fn.GetFullPath() );
} }
...@@ -286,13 +286,8 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event ) ...@@ -286,13 +286,8 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
} }
// Verify the user has write privileges before attempting to save the library file. // Verify the user has write privileges before attempting to save the library file.
if( !fn.IsDirWritable() ) if( !IsWritable( fn ) )
{
DisplayError( this,
wxString::Format( _( "You do not have permission to write to file <%s>." ),
GetChars( fn.GetFullPath() ) ) );
return; return;
}
bool success = m_library->Save( fn.GetFullPath(), true ); bool success = m_library->Save( fn.GetFullPath(), true );
......
...@@ -318,7 +318,7 @@ private: ...@@ -318,7 +318,7 @@ private:
* *
* @param aLibEntry A pointer to the LIB_ALIAS object to load. * @param aLibEntry A pointer to the LIB_ALIAS object to load.
* @param aLibrary A pointer to the CMP_LIBRARY object to load \a aLibEntry from. * @param aLibrary A pointer to the CMP_LIBRARY object to load \a aLibEntry from.
* @returns True if a copy of \aLibEntry was successfully loaded from \aLibrary. * @returns True if a copy of \a aLibEntry was successfully loaded from \aLibrary.
*/ */
bool LoadOneLibraryPartAux( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary ); bool LoadOneLibraryPartAux( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary );
......
...@@ -27,11 +27,7 @@ bool ReadSchemaDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Windo ...@@ -27,11 +27,7 @@ bool ReadSchemaDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Windo
static void LoadLayers( LINE_READER* aLine ); static void LoadLayers( LINE_READER* aLine );
/** bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFileName )
* Routine to load an EESchema file.
* Returns true if file has been loaded (at least partially.)
*/
bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFileName )
{ {
char Name1[256]; char Name1[256];
bool itemLoaded = false; bool itemLoaded = false;
...@@ -41,35 +37,35 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFile ...@@ -41,35 +37,35 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFile
wxString MsgDiag; // Error and log messages wxString MsgDiag; // Error and log messages
char* line; char* line;
if( screen == NULL ) if( aScreen == NULL )
return FALSE; return FALSE;
if( FullFileName.IsEmpty() ) if( aFullFileName.IsEmpty() )
return FALSE; return FALSE;
screen->SetCurItem( NULL ); aScreen->SetCurItem( NULL );
screen->SetFileName( FullFileName ); aScreen->SetFileName( aFullFileName );
// D(printf("LoadOneEEFile:%s\n", TO_UTF8( FullFileName ) ); ) // D(printf("LoadOneEEFile:%s\n", TO_UTF8( aFullFileName ) ); )
FILE* f; FILE* f;
if( ( f = wxFopen( FullFileName, wxT( "rt" ) ) ) == NULL ) if( ( f = wxFopen( aFullFileName, wxT( "rt" ) ) ) == NULL )
{ {
MsgDiag = _( "Failed to open " ) + FullFileName; MsgDiag = _( "Failed to open " ) + aFullFileName;
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return FALSE;
} }
// reader now owns the open FILE. // reader now owns the open FILE.
FILE_LINE_READER reader( f, FullFileName ); FILE_LINE_READER reader( f, aFullFileName );
MsgDiag = _( "Loading " ) + screen->GetFileName(); MsgDiag = _( "Loading " ) + aScreen->GetFileName();
PrintMsg( MsgDiag ); PrintMsg( MsgDiag );
if( !reader.ReadLine() if( !reader.ReadLine()
|| strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 ) || strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
{ {
MsgDiag = FullFileName + _( " is NOT an EESchema file!" ); MsgDiag = aFullFileName + _( " is NOT an EESchema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return FALSE;
} }
...@@ -87,7 +83,7 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFile ...@@ -87,7 +83,7 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFile
if( version > EESCHEMA_VERSION ) if( version > EESCHEMA_VERSION )
{ {
MsgDiag = FullFileName + _( " was created by a more recent \ MsgDiag = aFullFileName + _( " was created by a more recent \
version of EESchema and may not load correctly. Please consider updating!" ); version of EESchema and may not load correctly. Please consider updating!" );
DisplayInfoMessage( this, MsgDiag ); DisplayInfoMessage( this, MsgDiag );
} }
...@@ -96,7 +92,7 @@ version of EESchema and may not load correctly. Please consider updating!" ); ...@@ -96,7 +92,7 @@ version of EESchema and may not load correctly. Please consider updating!" );
// Compile it if the new version is unreadable by previous eeschema versions // Compile it if the new version is unreadable by previous eeschema versions
else if( version < EESCHEMA_VERSION ) else if( version < EESCHEMA_VERSION )
{ {
MsgDiag = FullFileName + _( " was created by an older version of \ MsgDiag = aFullFileName + _( " was created by an older version of \
EESchema. It will be stored in the new file format when you save this file \ EESchema. It will be stored in the new file format when you save this file \
again." ); again." );
...@@ -106,7 +102,7 @@ again." ); ...@@ -106,7 +102,7 @@ again." );
if( !reader.ReadLine() || strncmp( reader, "LIBS:", 5 ) != 0 ) if( !reader.ReadLine() || strncmp( reader, "LIBS:", 5 ) != 0 )
{ {
MsgDiag = FullFileName + _( " is NOT an EESchema file!" ); MsgDiag = aFullFileName + _( " is NOT an EESchema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return FALSE;
} }
...@@ -131,7 +127,7 @@ again." ); ...@@ -131,7 +127,7 @@ again." );
else if( line[1] == 'S' ) else if( line[1] == 'S' )
item = new SCH_SHEET(); item = new SCH_SHEET();
else if( line[1] == 'D' ) else if( line[1] == 'D' )
itemLoaded = ReadSchemaDescr( &reader, MsgDiag, screen ); itemLoaded = ReadSchemaDescr( &reader, MsgDiag, aScreen );
break; break;
case 'L': // Its a library item. case 'L': // Its a library item.
...@@ -197,8 +193,8 @@ again." ); ...@@ -197,8 +193,8 @@ again." );
} }
else else
{ {
item->SetNext( screen->GetDrawItems() ); item->SetNext( aScreen->GetDrawItems() );
screen->SetDrawItems( item ); aScreen->SetDrawItems( item );
} }
} }
...@@ -212,23 +208,23 @@ again." ); ...@@ -212,23 +208,23 @@ again." );
/* GetDrawItems() was constructed in reverse order - reverse it back: */ /* GetDrawItems() was constructed in reverse order - reverse it back: */
Phead = NULL; Phead = NULL;
while( screen->GetDrawItems() ) while( aScreen->GetDrawItems() )
{ {
Pnext = screen->GetDrawItems(); Pnext = aScreen->GetDrawItems();
screen->SetDrawItems( screen->GetDrawItems()->Next() ); aScreen->SetDrawItems( aScreen->GetDrawItems()->Next() );
Pnext->SetNext( Phead ); Pnext->SetNext( Phead );
Phead = Pnext; Phead = Pnext;
} }
screen->SetDrawItems( Phead ); aScreen->SetDrawItems( Phead );
#if 0 && defined (DEBUG) #if 0 && defined (DEBUG)
screen->Show( 0, std::cout ); aScreen->Show( 0, std::cout );
#endif #endif
screen->TestDanglingEnds(); aScreen->TestDanglingEnds();
MsgDiag = _( "Done Loading " ) + screen->GetFileName(); MsgDiag = _( "Done Loading " ) + aScreen->GetFileName();
PrintMsg( MsgDiag ); PrintMsg( MsgDiag );
return true; // Although it may be that file is only partially loaded. return true; // Although it may be that file is only partially loaded.
......
...@@ -55,10 +55,9 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) ...@@ -55,10 +55,9 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ID_NEW_PROJECT, SCH_EDIT_FRAME::OnNewProject ) EVT_TOOL( ID_NEW_PROJECT, SCH_EDIT_FRAME::OnNewProject )
EVT_TOOL( ID_LOAD_PROJECT, SCH_EDIT_FRAME::OnLoadProject ) EVT_TOOL( ID_LOAD_PROJECT, SCH_EDIT_FRAME::OnLoadProject )
EVT_MENU( ID_SAVE_PROJECT, SCH_EDIT_FRAME::Save_File ) EVT_MENU( ID_SAVE_PROJECT, SCH_EDIT_FRAME::OnSaveProject )
EVT_MENU( ID_SAVE_ONE_SHEET, SCH_EDIT_FRAME::Save_File ) EVT_MENU( ID_SAVE_ONE_SHEET, SCH_EDIT_FRAME::Save_File )
EVT_MENU( ID_SAVE_ONE_SHEET_AS, SCH_EDIT_FRAME::Save_File ) EVT_MENU( ID_SAVE_ONE_SHEET_AS, SCH_EDIT_FRAME::Save_File )
EVT_TOOL( ID_SAVE_PROJECT, SCH_EDIT_FRAME::Save_File )
EVT_MENU( ID_GEN_PLOT_PS, SCH_EDIT_FRAME::ToPlot_PS ) EVT_MENU( ID_GEN_PLOT_PS, SCH_EDIT_FRAME::ToPlot_PS )
EVT_MENU( ID_GEN_PLOT_HPGL, SCH_EDIT_FRAME::ToPlot_HPGL ) EVT_MENU( ID_GEN_PLOT_HPGL, SCH_EDIT_FRAME::ToPlot_HPGL )
EVT_MENU( ID_GEN_PLOT_SVG, SCH_EDIT_FRAME::SVG_Print ) EVT_MENU( ID_GEN_PLOT_SVG, SCH_EDIT_FRAME::SVG_Print )
...@@ -385,7 +384,7 @@ void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem ) ...@@ -385,7 +384,7 @@ void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem )
} }
void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
{ {
if( m_LibeditFrame && !m_LibeditFrame->Close() ) // Can close component editor? if( m_LibeditFrame && !m_LibeditFrame->Close() ) // Can close component editor?
return; return;
...@@ -405,7 +404,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -405,7 +404,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
switch( dialog.ShowModal() ) switch( dialog.ShowModal() )
{ {
case wxID_CANCEL: case wxID_CANCEL:
Event.Veto(); aEvent.Veto();
return; return;
case wxID_NO: case wxID_NO:
...@@ -413,7 +412,8 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -413,7 +412,8 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_OK: case wxID_OK:
case wxID_YES: case wxID_YES:
SaveProject(); wxCommandEvent tmp( ID_SAVE_PROJECT );
OnSaveProject( tmp );
break; break;
} }
} }
......
...@@ -26,7 +26,7 @@ private: ...@@ -26,7 +26,7 @@ private:
* The only constructor allowing direct input of numeric value * The only constructor allowing direct input of numeric value
* in internal units. As this is not allowed in public, it's private. * in internal units. As this is not allowed in public, it's private.
* Length objects elsewhere are created indirectly * Length objects elsewhere are created indirectly
* @param unit Length in internal units. * @param units Length in internal units.
*/ */
LENGTH( int units ) LENGTH( int units )
{ {
...@@ -660,4 +660,4 @@ public: ...@@ -660,4 +660,4 @@ public:
return LENGTH_XY( m_Y, -m_X ); return LENGTH_XY( m_Y, -m_X );
} }
}; };
#endif #endif
\ No newline at end of file
...@@ -142,9 +142,35 @@ public: ...@@ -142,9 +142,35 @@ public:
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/**
* Function GetProjectFileParameters
* returns the project file parameter list for EESchema.
*
*<p?
* Populate the project file parameter array specific to EESchema if it hasn't
* already been populated and return a reference to the array to the caller.
* Creating the parameter list at run time has the advantage of being able to
* define local variables. The old method of statically building the array at
* compile time required global variable definitions.
* </p>
*/
PARAM_CFG_ARRAY& GetProjectFileParameters( void ); PARAM_CFG_ARRAY& GetProjectFileParameters( void );
void SaveProjectFile( wxWindow* displayframe, bool askoverwrite = true );
bool LoadProjectFile( const wxString& CfgFileName, bool ForceRereadConfig ); /**
* Function SaveProjectFile
* saves changes to the project settings to the project (.pro) file.
*/
void SaveProjectFile();
/**
* Function LoadProjectFile
* soads the Kicad project file (*.pro) settings specific to EESchema.
*
* @param aFileName The project file name to load.
* @param aForceReread Force the project file to be reread if true.
* @return True if the project file was loaded correctly.
*/
bool LoadProjectFile( const wxString& aFileName, bool aForceReread );
/** /**
* Function GetDefaultFieldName * Function GetDefaultFieldName
...@@ -152,7 +178,7 @@ public: ...@@ -152,7 +178,7 @@ public:
* These field names are not modifiable, but template field names are. * These field names are not modifiable, but template field names are.
* @param aFieldNdx The field number index * @param aFieldNdx The field number index
*/ */
static wxString GetDefaultFieldName( int aFieldNdx ); static wxString GetDefaultFieldName( int aFieldNdx );
/** /**
* Function AddTemplateFieldName * Function AddTemplateFieldName
...@@ -190,8 +216,20 @@ public: ...@@ -190,8 +216,20 @@ public:
m_TemplateFieldNames.DeleteAllTemplateFieldNames(); m_TemplateFieldNames.DeleteAllTemplateFieldNames();
} }
/**
* Function GetConfigurationSettings
* returns the EESchema applications settings.
* <p>
* This replaces the old statically define list that had the project file settings and
* the application settings mixed together. This was confusing and caused some settings
* to get saved and loaded incorrectly. Currently, only the settings that are needed at
* start up by the main window are defined here. There are other locally used settings
* scattered throughout the EESchema source code. If you need to define a configuration
* setting that need to be loaded at run time, this is the place to define it.
* </p>
*/
PARAM_CFG_ARRAY& GetConfigurationSettings( void ); PARAM_CFG_ARRAY& GetConfigurationSettings( void );
void LoadSettings(); void LoadSettings();
void SaveSettings(); void SaveSettings();
...@@ -442,10 +480,43 @@ public: ...@@ -442,10 +480,43 @@ public:
void ToPostProcess( wxCommandEvent& event ); void ToPostProcess( wxCommandEvent& event );
// read and save files // read and save files
void Save_File( wxCommandEvent& event ); void Save_File( wxCommandEvent& event );
void SaveProject();
bool LoadOneEEProject( const wxString& FileName, bool IsNew ); /**
bool LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFileName ); * Function OnSaveProject
* is the command event handler to save the entire project and create a component library
* archive.
*
* The component library archive name is &ltroot_name&gt-cache.lib
*/
void OnSaveProject( wxCommandEvent& aEvent );
/**
* Function LoadOneEEProject
* load an entire project into the schematic editor.
*
* This function loads schematic root file and it's subhierarchies, the project
* configuration, and the component libraries which are not already loaded.
*
* @param aFileName The full path an file name to load.
* @param aIsNew True indicates that this is a new project and the default project
* template is loaded.
* @return True if the project loaded properly.
*/
bool LoadOneEEProject( const wxString& aFileName, bool aIsNew );
/**
* Function LoadOneEEFile
* loads the schematic (.sch) file \a aFullFileName into \a aScreen.
*
* @param aScreen Pointer to the associated SCH_SCREEN object in which to load
* \a aFullFileName.
* @param aFullFileName A reference to a wxString object containing the absolute path
* and file name to load.
* @return True if \a aFullFileName has been loaded (at least partially.)
*/
bool LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFileName );
bool ReadInputStuffFile(); bool ReadInputStuffFile();
/** /**
...@@ -466,7 +537,16 @@ public: ...@@ -466,7 +537,16 @@ public:
*/ */
bool ProcessStuffFile( FILE* aFilename, bool aSetFieldsAttributeToVisible ); bool ProcessStuffFile( FILE* aFilename, bool aSetFieldsAttributeToVisible );
bool SaveEEFile( SCH_SCREEN* screen, int FileSave ); /**
* Function SaveEEFile
* saves \a aScreen to a schematic file.
*
* @param aScreen A pointer to the SCH_SCREEN object to save. A NULL pointer saves
* the current screen.
* @param aSaveType Controls how the file is to be saved.
* @return True if the file has been saved.
*/
bool SaveEEFile( SCH_SCREEN* aScreen, int aSaveType );
// General search: // General search:
......
...@@ -223,6 +223,20 @@ public: ...@@ -223,6 +223,20 @@ public:
* Needed when the language is changed * Needed when the language is changed
*/ */
virtual void ReCreateMenuBar(); virtual void ReCreateMenuBar();
/**
* Function IsWritable
* checks if \a aFileName can be written.
* <p>
* The function performs a number of tests on \a aFileName to verify that it can
* be saved. The file name is tested for validity and if the user has write
* permissions.
* </p>
*
* @param aFileName The full path and/or file name of the file to test.
* @return False if \a aFileName cannot be written.
*/
bool IsWritable( const wxFileName& aFileName );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment