Commit 5fd409f8 authored by Wayne Stambaugh's avatar Wayne Stambaugh

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

* Check user write permissions before saving project and net list files.
* Append read only to file name and path in title bar when the user
  does not have write privileges.
* Don't display file dialog every time the net list or project file is
  saved.
* Add save as and save project file as commands.
* Make capitalization of CVPcb consistent in all user strings.
* Doxygen comment and coding style policy fixes.
parent 8f1b5697
......@@ -4,6 +4,7 @@
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "id.h"
#include "common.h"
#include "gestfich.h"
#include "param_config.h"
......@@ -16,15 +17,6 @@
#define GROUPEQU wxT("/cvpcb/libraries")
/**
* Return project file parameter list for CVPcb.
*
* Populate the project file parameter array specific to CVPcb 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& CVPCB_MAINFRAME::GetProjectFileParameters( void )
{
if( !m_projectFileParams.empty() )
......@@ -48,19 +40,9 @@ PARAM_CFG_ARRAY& CVPCB_MAINFRAME::GetProjectFileParameters( void )
}
/**
* Reads the configuration
* 1 - bed cvpcb.cnf
* 2 - if not in path of <cvpcb.exe> / cvpcb.cnf
* 3 - If not found: init variables to default values
*
* Note:
* The path of the executable must be in cvpcb.exe.
*
*/
void CVPCB_MAINFRAME::LoadProjectFile( const wxString& FileName )
void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
{
wxFileName fn = FileName;
wxFileName fn = aFileName;
m_ModuleLibNames.Clear();
m_AliasLibNames.Clear();
......@@ -70,8 +52,7 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& FileName )
wxGetApp().RemoveLibraryPath( m_UserLibraryPath );
wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP,
GetProjectFileParameters(), FALSE );
wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters(), false );
if( m_NetlistFileExtension.IsEmpty() )
m_NetlistFileExtension = wxT( "net" );
......@@ -81,24 +62,28 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& FileName )
}
void CVPCB_MAINFRAME::Update_Config( wxCommandEvent& event )
void CVPCB_MAINFRAME::SaveProjectFile( wxCommandEvent& aEvent )
{
SaveProjectFile( m_NetlistFileName.GetFullPath() );
}
wxFileName fn = m_NetlistFileName;
fn.SetExt( ProjectFileExtension );
void CVPCB_MAINFRAME::SaveProjectFile( const wxString& fileName )
{
wxFileName fn = fileName;
if( aEvent.GetId() == ID_SAVE_PROJECT_AS || !m_NetlistFileName.IsOk() )
{
wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(),
wxEmptyString, ProjectFileWildcard, wxFD_SAVE );
fn.SetExt( ProjectFileExtension );
if( dlg.ShowModal() == wxID_CANCEL )
return;
fn = dlg.GetPath();
wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(),
fn.GetFullName(), ProjectFileWildcard, wxFD_SAVE );
if( !fn.HasExt() )
fn.SetExt( ProjectFileExtension );
}
if( dlg.ShowModal() == wxID_CANCEL )
if( !IsWritable( fn ) )
return;
wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP,
GetProjectFileParameters() );
wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() );
}
This diff is collapsed.
......@@ -41,12 +41,12 @@ const wxString titleLibLoadError( _( "Library Load Error" ) );
*/
void WinEDA_App::MacOpenFile(const wxString &fileName)
{
wxFileName filename = fileName;
wxString oldPath;
CVPCB_MAINFRAME * frame = ((CVPCB_MAINFRAME*)GetTopWindow());
wxFileName filename = fileName;
wxString oldPath;
CVPCB_MAINFRAME* frame = (CVPCB_MAINFRAME*) GetTopWindow();
if(!filename.FileExists())
return;
if( !filename.FileExists() )
return;
if( frame->m_NetlistFileName.DirExists() )
oldPath = frame->m_NetlistFileName.GetPath();
......@@ -54,39 +54,32 @@ void WinEDA_App::MacOpenFile(const wxString &fileName)
/* Update the library search path list. */
if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
wxGetApp().GetLibraryPathList().Remove( oldPath );
wxGetApp().GetLibraryPathList().Insert( filename.GetPath(), 0 );
frame->m_NetlistFileName = filename;
if( frame->ReadNetList() )
{
frame->SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + filename.GetFullPath() );
}
else
{
frame->SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() );
}
frame->ReadNetList();
}
// Create a new application object
IMPLEMENT_APP( WinEDA_App )
/************************************/
/* Called to initialize the program */
/************************************/
bool WinEDA_App::OnInit()
{
wxFileName filename;
wxString message;
CVPCB_MAINFRAME* frame = NULL;
wxFileName filename;
wxString message;
CVPCB_MAINFRAME* frame = NULL;
InitEDA_Appl( wxT( "CvPCB" ), APP_TYPE_CVPCB );
InitEDA_Appl( wxT( "CVPcb" ), APP_TYPE_CVPCB );
if( m_Checker && m_Checker->IsAnotherRunning() )
{
if( !IsOK( NULL, _( "Cvpcb is already running, Continue?" ) ) )
if( !IsOK( NULL, _( "CVPcb is already running, Continue?" ) ) )
return false;
}
......@@ -126,9 +119,7 @@ bool WinEDA_App::OnInit()
frame->LoadFootprintFiles();
frame->m_NetlistFileExtension = wxT( "net" );
frame->m_NetlistFileName.Clear();
frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() +
wxGetCwd() + wxFileName::GetPathSeparator() +
_( " [no file]" ) );
frame->UpdateTitle();
return true;
}
......@@ -44,60 +44,130 @@ protected:
bool m_isEESchemaNetlist;
PARAM_CFG_ARRAY m_projectFileParams;
public: CVPCB_MAINFRAME( const wxString& title,
long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
public:
CVPCB_MAINFRAME( const wxString& title, long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
~CVPCB_MAINFRAME();
void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event );
void OnSelectComponent( wxListEvent& event );
void Update_Config( wxCommandEvent& event );
void OnQuit( wxCommandEvent& event );
void OnCloseWindow( wxCloseEvent& Event );
void OnSize( wxSizeEvent& SizeEvent );
void OnChar( wxKeyEvent& event );
void ReCreateHToolbar();
virtual void ReCreateMenuBar();
/**
* Function SetLanguage
* is called on a language menu selection.
*/
void SetLanguage( wxCommandEvent& event );
void ToFirstNA( wxCommandEvent& event );
void ToPreviousNA( wxCommandEvent& event );
/**
* Function DelAssociations
* removes all component footprint associations already made
*/
void DelAssociations( wxCommandEvent& event );
void SaveProjectFile( wxCommandEvent& aEvent );
void SaveQuitCvpcb( wxCommandEvent& event );
/**
* Function LoadNetList
* reads a netlist selected by user when clicking on load netlist button or any entry
* in the file history menu.
*/
void LoadNetList( wxCommandEvent& event );
void ConfigCvpcb( wxCommandEvent& event );
void OnKeepOpenOnSave( wxCommandEvent& event );
void DisplayModule( wxCommandEvent& event );
void AssocieModule( wxCommandEvent& event );
void WriteStuffList( wxCommandEvent& event );
void DisplayDocFile( wxCommandEvent& event );
/**
* Function OnSelectFilteringFootprint
* is the command event handler for enabling and disabling footprint filtering.
*/
void OnSelectFilteringFootprint( wxCommandEvent& event );
void OnUpdateKeepOpenOnSave( wxUpdateUIEvent& event );
/**
* Function SetNewPkg
* set the module to the selected component and selects the next component.
*/
void SetNewPkg( const wxString& package );
void BuildCmpListBox();
void BuildFOOTPRINTS_LISTBOX();
void CreateScreenCmp();
int SaveNetList( const wxString& FullFileName );
int SaveComponentList( const wxString& FullFileName );
/**
* Function SaveNetList
* backup and save netlist (.net) file to \a aFullFileName.
*
* @param aFullFileName A reference wxString object containing the full path and
* file name of the netlist to save.
* @return 0 if an error occurred saving the netlist to \a aFullFileName.
*/
int SaveNetList( const wxString& aFullFileName );
/**
* Function SaveComponentList
* backup modules to file \a aFullFileName.
*
* @param aFullFileName Name of net list file to save.
* @returns 1 if OK, 0 if error.
*/
int SaveComponentList( const wxString& aFullFileName );
/**
* Function ReadNetList
* reads the netlist (.net) file defined by #m_NetlistFileName.
*/
bool ReadNetList();
int ReadSchematicNetlist();
void LoadProjectFile( const wxString& FileName );
void SaveProjectFile( const wxString& fileName );
/**
* Function LoadProjectFile
* reads the configuration parameter from the project (.pro) file \a aFileName
*/
void LoadProjectFile( const wxString& aFileName );
/**
* Function LoadSettings
* loads the CVPcb main frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
virtual void LoadSettings();
/**
* Function SaveSettings
* save the CVPcb frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
virtual void SaveSettings();
/**
* Function DisplayStatus()
* Displays info to the status line at bottom of the main frame
* Function DisplayStatus
* displays info to the status line at bottom of the main frame.
*/
void DisplayStatus();
/**
* Function LoadFootprintFiles
* Read the list of libraries (*.mod files) and generate the list of modules.
* reads the list of footprint (*.mod files) and generate the list of footprints.
* for each module are stored
* the module name
* documentation string
......@@ -117,13 +187,38 @@ public: CVPCB_MAINFRAME( const wxString& title,
/**
* Function LoadComponentFile
* Loads the .cmp file that stores the component/footprint association.
* @param aCmpFileName = the full filename of .cmp file to load
* loads the .cmp file \a aCmpFileName that stores the component/footprint association.
*
* @param aFileName The full filename of .cmp file to load
*/
bool LoadComponentFile( const wxString& aCmpFileName );
bool LoadComponentFile( const wxString& aFileName );
/**
* Function GetProjectFileParameters
* return project file parameter list for CVPcb.
* <p>
* Populate the project file parameter array specific to CVPcb 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.
* </p>
*
* @return A reference to a PARAM_CFG_ARRAY contain the project settings for CVPcb.
*/
PARAM_CFG_ARRAY& GetProjectFileParameters( void );
/**
* Function UpdateTitle
* sets the main window title bar text.
* <p>
* If file name defined by CVPCB_MAINFRAME::m_NetlistFileName is not set, the title is
* set to the application name appended with no file. Otherwise, the title is set to
* the full path and file name and read only is appended to the title if the user does
* not have write access to the file.
*/
void UpdateTitle();
DECLARE_EVENT_TABLE()
};
......
......@@ -10,6 +10,7 @@
#include "common.h"
#include "confirm.h"
#include "gestfich.h"
#include "id.h"
#include "cvpcb.h"
#include "cvpcb_mainframe.h"
......@@ -59,15 +60,18 @@ void DIALOG_CVPCB_CONFIG::Init()
// Load user libs paths:
wxStringTokenizer Token( m_UserLibDirBufferImg, wxT( ";\n\r" ) );
while( Token.HasMoreTokens() )
{
wxString path = Token.GetNextToken();
if( wxFileName::DirExists( path ) )
m_listUserPaths->Append( path );
}
// Display actual libraries paths:
wxPathList libpaths = wxGetApp().GetLibraryPathList();
for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ )
{
m_DefaultLibraryPathslistBox->Append( libpaths[ii] );
......@@ -102,25 +106,28 @@ void DIALOG_CVPCB_CONFIG::OnOkClick( wxCommandEvent& event )
if( m_LibPathChanged )
{
m_Parent->m_UserLibraryPath.Empty();
for( unsigned ii = 0; ii < m_listUserPaths->GetCount(); ii++ )
{
if( ii > 0 )
m_Parent->m_UserLibraryPath << wxT( ";" );
m_Parent->m_UserLibraryPath << m_listUserPaths->GetString( ii );
}
}
// Set new active library list if the lib list of if default path list
// was modified
// Set new active library list if the lib list of if default path list was modified
if( m_LibListChanged || m_LibPathChanged )
{
// Recreate lib list
m_Parent->m_ModuleLibNames.Clear();
for( unsigned ii = 0; ii < m_ListLibr->GetCount(); ii++ )
m_Parent->m_ModuleLibNames.Add( m_ListLibr->GetString( ii ) );
// Recreate equ list
m_Parent->m_AliasLibNames.Clear();
for( unsigned ii = 0; ii < m_ListEquiv->GetCount(); ii++ )
m_Parent->m_AliasLibNames.Add( m_ListEquiv->GetString( ii ) );
......@@ -128,7 +135,8 @@ void DIALOG_CVPCB_CONFIG::OnOkClick( wxCommandEvent& event )
m_Parent->BuildFOOTPRINTS_LISTBOX();
}
m_Parent->SaveProjectFile( m_Parent->m_NetlistFileName.GetFullPath() );
wxCommandEvent evt( ID_SAVE_PROJECT );
m_Parent->SaveProjectFile( evt );
EndModal( wxID_OK );
}
......@@ -144,6 +152,7 @@ void DIALOG_CVPCB_CONFIG::OnButtonUpClick( wxCommandEvent& event )
/********************************************************************/
{
wxListBox * list = m_ListLibr;
if( (event.GetId() == ID_EQU_UP) || (event.GetId() == ID_EQU_DOWN) )
{
list = m_ListEquiv;
......@@ -151,7 +160,8 @@ void DIALOG_CVPCB_CONFIG::OnButtonUpClick( wxCommandEvent& event )
wxArrayInt selections;
list->GetSelections(selections);
list->GetSelections( selections );
if ( selections.GetCount() <= 0 ) // No selection.
return;
......@@ -163,15 +173,16 @@ void DIALOG_CVPCB_CONFIG::OnButtonUpClick( wxCommandEvent& event )
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
{
int jj = selections[ii];
EXCHG( libnames[jj], libnames[jj-1]);
EXCHG( libnames[jj], libnames[jj-1] );
}
list->Set(libnames);
list->Set( libnames );
// Reselect previously selected names
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
{
int jj = selections[ii];
list->SetSelection(jj-1);
list->SetSelection( jj-1 );
}
m_LibListChanged = TRUE;
......@@ -183,6 +194,7 @@ void DIALOG_CVPCB_CONFIG::OnButtonDownClick( wxCommandEvent& event )
/*********************************************************************/
{
wxListBox * list = m_ListLibr;
if( (event.GetId() == ID_EQU_UP) || (event.GetId() == ID_EQU_DOWN) )
{
list = m_ListEquiv;
......@@ -190,7 +202,8 @@ void DIALOG_CVPCB_CONFIG::OnButtonDownClick( wxCommandEvent& event )
wxArrayInt selections;
list->GetSelections(selections);
list->GetSelections( selections );
if ( selections.GetCount() <= 0 ) // No selection.
return;
......@@ -205,7 +218,8 @@ void DIALOG_CVPCB_CONFIG::OnButtonDownClick( wxCommandEvent& event )
int jj = selections[ii];
EXCHG( libnames[jj], libnames[jj+1]);
}
list->Set(libnames);
list->Set( libnames );
// Reselect previously selected names
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
......@@ -213,6 +227,7 @@ void DIALOG_CVPCB_CONFIG::OnButtonDownClick( wxCommandEvent& event )
int jj = selections[ii];
list->SetSelection(jj+1);
}
m_LibListChanged = TRUE;
}
......@@ -229,7 +244,8 @@ void DIALOG_CVPCB_CONFIG::OnRemoveLibClick( wxCommandEvent& event )
wxArrayInt selections;
list->GetSelections(selections);
list->GetSelections( selections );
for( int ii = selections.GetCount()-1; ii >= 0; ii-- )
{
list->Delete(selections[ii] );
......@@ -256,6 +272,7 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
wildcard = FootprintAliasFileWildcard;
wxListBox * list = m_ListEquiv;
if( (event.GetId() == ID_ADD_LIB) || (event.GetId() == ID_INSERT_LIB) )
{
list = m_ListLibr;
......@@ -266,6 +283,7 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
list->GetSelections(selections);
ii = selections.GetCount();
if( ii > 0 )
ii = selections[0];
else
......@@ -273,6 +291,7 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
wxString libpath;
libpath = m_DefaultLibraryPathslistBox->GetStringSelection();
if( libpath.IsEmpty() )
libpath = wxGetApp().ReturnLastVisitedLibraryPath();
......@@ -289,6 +308,7 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
for( unsigned jj = 0; jj < Filenames.GetCount(); jj++ )
{
fn = Filenames[jj];
if( jj == 0 )
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
......@@ -300,15 +320,17 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
* is a sub path of these default paths
*/
libfilename = wxGetApp().ReturnFilenameWithRelativePathInLibPath( fn.GetFullPath() );
// Remove extension:
fn = libfilename;
fn.SetExt(wxEmptyString);
fn.SetExt( wxEmptyString );
libfilename = fn.GetFullPath();
// Add or insert new library name, if not already in list
if( list->FindString( libfilename, fn.IsCaseSensitive() ) == wxNOT_FOUND )
{
m_LibListChanged = TRUE;
if( ! insert )
list->Append( libfilename );
else
......@@ -344,25 +366,27 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
if( m_listUserPaths->FindString( path ) == wxNOT_FOUND )
{
int ipos = m_listUserPaths->GetCount();
if( event.GetId() == ID_INSERT_PATH )
{
if( ipos )
ipos--;
int jj = m_listUserPaths->GetSelection();
if( jj >= 0 )
ipos = jj;
}
// Ask the user if this is a relative path
int diag = wxMessageBox(
_( "Use a relative path?" ),
_( "Path type" ),
wxYES_NO | wxICON_QUESTION, this );
int diag = wxMessageBox( _( "Use a relative path?" ),
_( "Path type" ),
wxYES_NO | wxICON_QUESTION, this );
if( diag == wxYES )
{ // Make it relative
wxFileName fn = path;
fn.MakeRelativeTo( wxT(".") );
fn.MakeRelativeTo( wxT( "." ) );
path = fn.GetPathWithSep() + fn.GetFullName();
}
......@@ -373,13 +397,16 @@ void DIALOG_CVPCB_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
// Display actual libraries paths:
wxPathList libpaths = wxGetApp().GetLibraryPathList();
m_DefaultLibraryPathslistBox->Clear();
for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ )
{
m_DefaultLibraryPathslistBox->Append( libpaths[ii] );
}
}
else
{
DisplayError( this, _( "Path already in use" ) );
}
wxGetApp().SaveLastVisitedLibraryPath( path );
}
......@@ -391,6 +418,7 @@ void DIALOG_CVPCB_CONFIG::OnRemoveUserPath( wxCommandEvent& event )
if( ii < 0 )
ii = m_listUserPaths->GetCount() - 1;
if( ii >= 0 )
{
wxGetApp().RemoveLibraryPath( m_listUserPaths->GetStringSelection() );
......@@ -401,6 +429,7 @@ void DIALOG_CVPCB_CONFIG::OnRemoveUserPath( wxCommandEvent& event )
// Display actual libraries paths:
wxPathList libpaths = wxGetApp().GetLibraryPathList();
m_DefaultLibraryPathslistBox->Clear();
for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ )
{
m_DefaultLibraryPathslistBox->Append( libpaths[ii] );
......
......@@ -15,10 +15,7 @@
#include "build_version.h"
/*
* Set the module to the selected component
* Selects the next component
*/
void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
{
COMPONENT* Component;
......@@ -30,6 +27,7 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
return;
NumCmp = m_ListCmp->GetSelection();
if( NumCmp < 0 )
{
NumCmp = 0;
......@@ -46,9 +44,9 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
Component->m_Module = package;
msg.Printf( CMP_FORMAT, NumCmp + 1,
GetChars( Component->m_Reference ),
GetChars( Component->m_Value ),
GetChars( Component->m_Module ) );
GetChars( Component->m_Reference ),
GetChars( Component->m_Value ),
GetChars( Component->m_Module ) );
m_modified = true;
if( isUndefined )
......@@ -60,15 +58,13 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
// We activate next component:
if( NumCmp < (m_ListCmp->GetCount() - 1) )
NumCmp++;
m_ListCmp->SetSelection( NumCmp, TRUE );
DisplayStatus();
}
/*
* Read the netlist format and file components.
*/
bool CVPCB_MAINFRAME::ReadNetList()
{
wxString msg;
......@@ -81,6 +77,8 @@ bool CVPCB_MAINFRAME::ReadNetList()
msg.Printf( _( "File <%s> does not appear to be a valid Kicad net list file." ),
GetChars( m_NetlistFileName.GetFullPath() ) );
::wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this );
m_NetlistFileName.Clear();
UpdateTitle();
return false;
}
......@@ -90,7 +88,7 @@ bool CVPCB_MAINFRAME::ReadNetList()
return false;
LoadProjectFile( m_NetlistFileName.GetFullPath() );
LoadFootprintFiles( );
LoadFootprintFiles();
BuildFOOTPRINTS_LISTBOX();
m_ListCmp->Clear();
......@@ -103,6 +101,7 @@ bool CVPCB_MAINFRAME::ReadNetList()
GetChars( component.m_Value ),
GetChars( component.m_Module ) );
m_ListCmp->AppendLine( msg );
if( component.m_Module.IsEmpty() )
m_undefinedComponentCnt += 1;
}
......@@ -112,9 +111,7 @@ bool CVPCB_MAINFRAME::ReadNetList()
DisplayStatus();
/* Update the title of the main window. */
SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + m_NetlistFileName.GetFullPath() );
UpdateTitle();
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
......@@ -122,34 +119,40 @@ bool CVPCB_MAINFRAME::ReadNetList()
}
/*
* Backup and NetList cmp
* The full name of the netlist file must be in FFileName.
* The file name is deducted in cmp
*/
int CVPCB_MAINFRAME::SaveNetList( const wxString& fileName )
int CVPCB_MAINFRAME::SaveNetList( const wxString& aFullFileName )
{
wxFileName fn;
if( !fileName && m_NetlistFileName.IsOk() )
if( !aFullFileName.IsEmpty() && m_NetlistFileName.IsOk() )
{
fn = m_NetlistFileName;
}
else
fn = wxFileName( wxGetCwd(), _( "unamed" ), NetExtBuffer );
{
wxFileDialog dlg( this, _( "Save Net and Component List" ), wxGetCwd(),
wxEmptyString, NetlistFileWildcard, wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL )
return -1;
fn = dlg.GetPath();
wxFileDialog dlg( this, _( "Save Net and Component List" ), fn.GetPath(),
fn.GetFullName(), NetlistFileWildcard,
wxFD_SAVE/*| wxFD_OVERWRITE_PROMPT*/ );
if( !fn.HasExt() )
fn.SetExt( NetlistFileExtension );
if( dlg.ShowModal() == wxID_CANCEL )
return -1;
m_NetlistFileName = fn;
}
if( !IsWritable( fn.GetFullPath() ) )
return 0;
if( SaveComponentList( dlg.GetPath() ) == 0 )
if( SaveComponentList( fn.GetFullPath() ) == 0 )
{
DisplayError( this, _( "Unable to create component file (.cmp)" ) );
return 0;
}
FILE* netlist = wxFopen( dlg.GetPath(), wxT( "wt" ) );
FILE* netlist = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
if( netlist == 0 )
{
......
......@@ -29,8 +29,9 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Delete all existing menus so they can be rebuilt.
// This allows language changes of the menu text on the fly.
menuBar->Freeze();
while( menuBar->GetMenuCount() )
delete menuBar->Remove(0);
delete menuBar->Remove( 0 );
// Recreate all menus:
......@@ -46,25 +47,34 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Open Recent submenu
static wxMenu* openRecentMenu;
// Add this menu to list menu managed by m_fileHistory
// (the file history will be updated when adding/removing files in history
if( openRecentMenu )
wxGetApp().m_fileHistory.RemoveMenu( openRecentMenu );
openRecentMenu = new wxMenu();
wxGetApp().m_fileHistory.UseMenu( openRecentMenu );
wxGetApp().m_fileHistory.AddFilesToMenu( );
wxGetApp().m_fileHistory.AddFilesToMenu();
ADD_MENUITEM_WITH_HELP_AND_SUBMENU( filesMenu, openRecentMenu, -1,
_( "Open &Recent" ),
_("Open a recent opened netlist document" ),
_( "Open a recent opened netlist document" ),
open_project_xpm );
// Separator
filesMenu->AppendSeparator();
// Save
ADD_MENUITEM_WITH_HELP( filesMenu,
wxID_SAVE,
_( "&Save\tCtrl+S" ),
_( "Save net list and footprint list files" ),
save_xpm );
// Save as
ADD_MENUITEM_WITH_HELP( filesMenu,
ID_SAVE_PROJECT,
_( "&Save As..." ),
wxID_SAVEAS,
_( "Save &As..." ),
_( "Save new net list and footprint list files" ),
save_xpm );
......@@ -75,7 +85,7 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
ADD_MENUITEM_WITH_HELP( filesMenu,
wxID_EXIT,
_( "&Quit" ),
_( "Quit CvPCB" ),
_( "Quit CVPcb" ),
exit_xpm );
// Menu Preferences:
......@@ -105,10 +115,14 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Separator
preferencesMenu->AppendSeparator();
ADD_MENUITEM_WITH_HELP( preferencesMenu, ID_CONFIG_SAVE,
_( "&Save Project File" ),
_( "Save changes to the project file" ),
save_setup_xpm );
ADD_MENUITEM_WITH_HELP( preferencesMenu, ID_SAVE_PROJECT,
_( "&Save Project File" ),
_( "Save changes to the project configuration file" ),
save_setup_xpm );
ADD_MENUITEM_WITH_HELP( preferencesMenu, ID_SAVE_PROJECT_AS,
_( "&Save Project File As" ),
_( "Save changes to the project configuration to a new file" ),
save_setup_xpm );
// Menu Help:
wxMenu* helpMenu = new wxMenu;
......@@ -118,13 +132,13 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Contents
ADD_MENUITEM_WITH_HELP( helpMenu, wxID_HELP, _( "&Contents" ),
_( "Open the Cvpcb handbook" ),
_( "Open the CVPcb handbook" ),
online_help_xpm );
// About
ADD_MENUITEM_WITH_HELP( helpMenu, wxID_ABOUT,
_( "&About CvPCB" ),
_( "About CvPCB schematic to pcb converter" ),
_( "&About CVPcb" ),
_( "About CVPcb schematic to pcb converter" ),
info_xpm );
// Create the menubar and append all submenus
......
......@@ -23,22 +23,17 @@ char EnteteCmpMod[] = { "Cmp-Mod V01" };
#define titleComponentLibErr _( "Component Library Error" )
/*
* Backup modules file.
*
* @param NetlistFullFileName - Name of net list file to save.
* @returns - 1 if OK, 0 if error.
*/
int CVPCB_MAINFRAME::SaveComponentList( const wxString& NetlistFullFileName )
int CVPCB_MAINFRAME::SaveComponentList( const wxString& aFullFileName )
{
FILE* dest;
wxFileName fn( NetlistFullFileName );
wxFileName fn( aFullFileName );
char Line[1024];
wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion();
fn.SetExt( ComponentFileExtension );
dest = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
if( dest == NULL )
return 0;
......@@ -49,14 +44,10 @@ int CVPCB_MAINFRAME::SaveComponentList( const wxString& NetlistFullFileName )
BOOST_FOREACH( COMPONENT& component, m_components )
{
fprintf( dest, "\nBeginCmp\n" );
fprintf( dest, "TimeStamp = %s;\n",
TO_UTF8( component.m_TimeStamp ) );
fprintf( dest, "Reference = %s;\n",
TO_UTF8( component.m_Reference ) );
fprintf( dest, "ValeurCmp = %s;\n",
TO_UTF8( component.m_Value ) );
fprintf( dest, "IdModule = %s;\n",
TO_UTF8( component.m_Module ) );
fprintf( dest, "TimeStamp = %s;\n", TO_UTF8( component.m_TimeStamp ) );
fprintf( dest, "Reference = %s;\n", TO_UTF8( component.m_Reference ) );
fprintf( dest, "ValeurCmp = %s;\n", TO_UTF8( component.m_Value ) );
fprintf( dest, "IdModule = %s;\n", TO_UTF8( component.m_Module ) );
fprintf( dest, "EndCmp\n" );
}
......@@ -66,25 +57,22 @@ int CVPCB_MAINFRAME::SaveComponentList( const wxString& NetlistFullFileName )
}
/*
* Load list of associated components and footprints.
*/
bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& fileName )
bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& aFileName )
{
wxString timestamp, valeur, ilib, namecmp, msg;
bool read_cmp_data = FALSE, eof = FALSE;
bool read_cmp_data = false, eof = false;
char Line[1024], * ident, * data;
FILE* source;
wxFileName fn = fileName;
wxFileName fn = aFileName;
fn.SetExt( ComponentFileExtension );
source = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
if( source == NULL )
{
msg.Printf( _( "Cannot open CvPcb component file <%s>." ),
msg.Printf( _( "Cannot open CVPcb component file <%s>." ),
GetChars( fn.GetFullPath() ) );
msg << wxT("\n") << _("This is normal if you are opening a new netlist file");
msg << wxT( "\n" ) << _( "This is normal if you are opening a new netlist file" );
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
return false;
}
......@@ -115,23 +103,24 @@ bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& fileName )
/* Search the beginning of the component description. */
if( strnicmp( Line, "BeginCmp", 8 ) != 0 )
continue;
timestamp.Empty();
valeur.Empty();
ilib.Empty();
namecmp.Empty();
read_cmp_data = TRUE;
read_cmp_data = true;
while( !eof && read_cmp_data )
{
if( fgets( Line, 1024, source ) == 0 )
{
eof = TRUE;
eof = true;
break;
}
if( strnicmp( Line, "EndCmp", 6 ) == 0 )
{
read_cmp_data = TRUE;
read_cmp_data = true;
break;
}
......@@ -141,38 +130,37 @@ bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& fileName )
if( strnicmp( ident, "TimeStamp", 9 ) == 0 )
{
timestamp = FROM_UTF8( data );
timestamp.Trim( TRUE );
timestamp.Trim( FALSE );
timestamp.Trim( true );
timestamp.Trim( false );
continue;
}
if( strnicmp( ident, "Reference", 9 ) == 0 )
{
namecmp = FROM_UTF8( data );
namecmp.Trim( TRUE );
namecmp.Trim( FALSE );
namecmp.Trim( true );
namecmp.Trim( false );
continue;
}
if( strnicmp( ident, "ValeurCmp", 9 ) == 0 )
{
valeur = FROM_UTF8( data );
valeur.Trim( TRUE );
valeur.Trim( FALSE );
valeur.Trim( true );
valeur.Trim( false );
continue;
}
if( strnicmp( ident, "IdModule", 8 ) == 0 )
{
ilib = FROM_UTF8( data );
ilib.Trim( TRUE );
ilib.Trim( FALSE );
ilib.Trim( true );
ilib.Trim( false );
continue;
}
} /* End reading component description. */
/* Search corresponding component and NetList
* Update its parameters. */
/* Search corresponding component and NetList Update its parameters. */
BOOST_FOREACH( COMPONENT& component, m_components )
{
if( namecmp != component.m_Reference )
......
......@@ -22,64 +22,63 @@ void CVPCB_MAINFRAME::ReCreateHToolbar()
m_HToolBar = new EDA_TOOLBAR( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE );
m_HToolBar->AddTool( ID_CVPCB_READ_INPUT_NETLIST, wxEmptyString,
wxBitmap( open_document_xpm ),
_( "Open a net list file" ) );
wxBitmap( open_document_xpm ),
_( "Open a net list file" ) );
m_HToolBar->AddTool( ID_CVPCB_SAVEQUITCVPCB, wxEmptyString,
wxBitmap( save_xpm ),
_( "Save net list and footprint files" ) );
m_HToolBar->AddTool( wxID_SAVE, wxEmptyString, wxBitmap( save_xpm ),
_( "Save net list and footprint files" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_CREATE_CONFIGWINDOW, wxEmptyString,
wxBitmap( config_xpm ),
_( "Configuration" ) );
wxBitmap( config_xpm ),
_( "Configuration" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_CREATE_SCREENCMP, wxEmptyString,
wxBitmap( show_footprint_xpm ),
_( "View selected footprint" ) );
wxBitmap( show_footprint_xpm ),
_( "View selected footprint" ) );
m_HToolBar->AddTool( ID_CVPCB_AUTO_ASSOCIE, wxEmptyString,
wxBitmap( auto_associe_xpm ),
_( "Perform automatic footprint association" ) );
wxBitmap( auto_associe_xpm ),
_( "Perform automatic footprint association" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_GOTO_PREVIOUSNA, wxEmptyString,
wxBitmap( left_xpm ),
_( "Select previous free component" ) );
wxBitmap( left_xpm ),
_( "Select previous free component" ) );
m_HToolBar->AddTool( ID_CVPCB_GOTO_FIRSTNA, wxEmptyString,
wxBitmap( right_xpm ),
_( "Select next free component" ) );
wxBitmap( right_xpm ),
_( "Select next free component" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_DEL_ASSOCIATIONS, wxEmptyString,
wxBitmap( delete_association_xpm ),
_( "Delete all associations" ) );
wxBitmap( delete_association_xpm ),
_( "Delete all associations" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_CREATE_STUFF_FILE, wxEmptyString,
wxBitmap( export_footprint_names_xpm ),
_(
"Create export file (component/footprint list, \
used by eeschema to fill the footprint field of components)" ) );
wxBitmap( export_footprint_names_xpm ),
_( "Create export file (component/footprint list, \
used by eeschema to fill the footprint field of components)" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_PCB_DISPLAY_FOOTPRINT_DOC, wxEmptyString,
wxBitmap( datasheet_xpm ),
_( "Display footprints list documentation" ) );
wxBitmap( datasheet_xpm ),
_( "Display footprints list documentation" ) );
m_HToolBar->AddSeparator();
m_HToolBar->AddSeparator();
m_HToolBar->AddRadioTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST,
wxEmptyString,
wxBitmap( module_filtered_list_xpm ),
wxNullBitmap,
_( "Display the filtered footprint list for the current component" ) );
wxEmptyString,
wxBitmap( module_filtered_list_xpm ),
wxNullBitmap,
_( "Display the filtered footprint list for the current component" ) );
m_HToolBar->AddRadioTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST,
wxEmptyString, wxBitmap( module_full_list_xpm ),
wxNullBitmap,
_( "Display the full footprint list (without filtering)" ) );
wxEmptyString, wxBitmap( module_full_list_xpm ),
wxNullBitmap,
_( "Display the full footprint list (without filtering)" ) );
if( config )
{
......@@ -89,7 +88,6 @@ used by eeschema to fill the footprint field of components)"
m_HToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, !opt );
}
// after adding the buttons to the toolbar, must call Realize() to reflect
// the changes
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_HToolBar->Realize();
}
......@@ -21,6 +21,7 @@ enum main_id
ID_LOAD_ONE_SHEET,
ID_NEW_PROJECT,
ID_SAVE_PROJECT,
ID_SAVE_PROJECT_AS,
ID_SAVE_ONE_SHEET,
ID_SAVE_ONE_SHEET_AS,
ID_LOAD_FILE,
......
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