From 1a7491306367753ba07b050e6e0a718388d26414 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 14 Feb 2015 13:43:11 +0100 Subject: [PATCH] Minor fixes: fix issue Bug #1420910 (Linux specific). Rename eeschema/dialogs/dialog_sch_find.fbp to dialog_schematic_find_base.fbp, to be consistent with other dialogs. Pcbnew run from the project manager: add menu Save Copy As..., which is the same command as Save As ... in stand alone mode, but with the constraints of a project (no cwd change, no board filename change, and keep project settings) --- eeschema/dialogs/dialog_choose_component.cpp | 9 +++ ...ind.fbp => dialog_schematic_find_base.fbp} | 0 include/wxPcbStruct.h | 16 ++++- pcbnew/files.cpp | 66 ++++++++++++++++++- pcbnew/menubar_pcbframe.cpp | 19 +++++- pcbnew/pcbframe.cpp | 1 + pcbnew/pcbnew_id.h | 1 + 7 files changed, 105 insertions(+), 7 deletions(-) rename eeschema/dialogs/{dialog_sch_find.fbp => dialog_schematic_find_base.fbp} (100%) diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 9229944388..b16a7a9d08 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -81,7 +81,16 @@ void DIALOG_CHOOSE_COMPONENT::OnSearchBoxChange( wxCommandEvent& aEvent ) { m_search_container->UpdateSearchTerm( m_searchBox->GetLineText( 0 ) ); updateSelection(); + + // On Windows, but not on Linux, the focus is given to + // the m_libraryComponentTree, after modificatuons. + // We want the focus for m_searchBox. + // + // We cannot call SetFocus on Linux because it changes the current text selection + // and the text edit cursor position. +#ifdef __WINDOWS__ m_searchBox->SetFocus(); +#endif } diff --git a/eeschema/dialogs/dialog_sch_find.fbp b/eeschema/dialogs/dialog_schematic_find_base.fbp similarity index 100% rename from eeschema/dialogs/dialog_sch_find.fbp rename to eeschema/dialogs/dialog_schematic_find_base.fbp diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 909b7961ce..5b999e5d6f 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -848,12 +848,14 @@ public: /** * Function AppendBoardFile * appends a board file onto the current one, creating God knows what. + * the main purpose is only to allow panelizing boards. */ bool AppendBoardFile( const wxString& aFullFileName, int aCtl ); /** * Function SavePcbFile * writes the board data structures to \a a aFileName + * Creates backup when requested and update flags (modified and saved flgs) * * @param aFileName The file name to write or wxEmptyString to prompt user for * file name. @@ -864,8 +866,18 @@ public: */ bool SavePcbFile( const wxString& aFileName, bool aCreateBackupFile = CREATE_BACKUP_FILE ); - int SavePcbFormatAscii( FILE* File ); - bool WriteGeneralDescrPcb( FILE* File ); + /** + * Function SavePcbCopy + * writes the board data structures to \a a aFileName + * but unlike SavePcbFile, does not make anything else + * (no backup, borad fliename change, no flag changes ...) + * Used under a project mgr to save under a new name the current board + * + * When not under a project mgr, the full SavePcbFile is used. + * @param aFileName The file name to write. + * @return True if file was saved successfully. + */ + bool SavePcbCopy( const wxString& aFileName ); // BOARD handling diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 73e4dc4de7..5796d8ffcd 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -327,14 +327,20 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event ) break; } // Fall through - case ID_SAVE_BOARD_AS: + case ID_COPY_BOARD_AS: + case ID_SAVE_BOARD_AS: { wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() ); wxFileName fn( pro_dir, _( "noname" ), KiCadPcbFileExtension ); wxString filename = fn.GetFullPath(); if( AskSaveBoardFileName( this, &filename ) ) - SavePcbFile( filename, true ); + { + if( id == ID_COPY_BOARD_AS ) + SavePcbCopy( filename ); + else + SavePcbFile( filename, NO_BACKUP_FILE ); + } } break; @@ -412,7 +418,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in if( response == wxID_CANCEL ) return false; else if( response == wxID_YES ) - SavePcbFile( GetBoard()->GetFileName(), true ); + SavePcbFile( GetBoard()->GetFileName(), CREATE_BACKUP_FILE ); else { // response == wxID_NO, fall thru @@ -660,6 +666,8 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF wxString backupFileName; + // aCreateBackupFile == false is mainly used to write autosave files + // or new files in save as... command if( aCreateBackupFile ) { backupFileName = create_backup_file( aFileName ); @@ -733,6 +741,58 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF } +bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName ) +{ + wxFileName pcbFileName = aFileName; + + // Ensure the file ext is the right ext: + pcbFileName.SetExt( KiCadPcbFileExtension ); + + if( !IsWritable( pcbFileName ) ) + { + wxString msg = wxString::Format( _( + "No access rights to write to file '%s'" ), + GetChars( pcbFileName.GetFullPath() ) + ); + + DisplayError( this, msg ); + return false; + } + + GetBoard()->m_Status_Pcb &= ~CONNEXION_OK; + GetBoard()->SynchronizeNetsAndNetClasses(); + + // Select default Netclass before writing file. + // Useful to save default values in headers + SetCurrentNetClass( NETCLASS::Default ); + + try + { + PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::KICAD ) ); + + wxASSERT( pcbFileName.IsAbsolute() ); + + pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg = wxString::Format( _( + "Error saving board file '%s'.\n%s" ), + GetChars( pcbFileName.GetFullPath() ), + GetChars( ioe.errorText ) + ); + DisplayError( this, msg ); + + return false; + } + + DisplayInfoMessage( this, wxString::Format( _( "Board copied to:\n'%s'" ), + GetChars( pcbFileName.GetFullPath() ) ) ); + + return true; +} + + bool PCB_EDIT_FRAME::doAutoSave() { wxFileName tmpFileName = Prj().AbsolutePath( GetBoard()->GetFileName() ); diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index 479ecade6b..92008ca165 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -111,14 +111,29 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() _( "Save current board" ), KiBitmap( save_xpm ) ); - if( Kiface().IsSingle() ) // not when under a project mgr + // Save as menu: + // under a project mgr we do not want to modify the board filename + // to keep consistency with the project mgr which expects files names same as prj name + // for main files + // when not under a project mgr, we are free to change filenames, cwd ... + if( Kiface().IsSingle() ) // not when under a project mgr (pcbnew is run as stand alone) { text = AddHotkeyName( _( "Sa&ve As..." ), g_Board_Editor_Hokeys_Descr, HK_SAVE_BOARD_AS ); AddMenuItem( filesMenu, ID_SAVE_BOARD_AS, text, _( "Save the current board as..." ), KiBitmap( save_as_xpm ) ); - filesMenu->AppendSeparator(); } + // under a project mgr, we can save a copy of the board, + // but do not change the current board file name + else + { + text = AddHotkeyName( _( "Sa&ve Copy As..." ), g_Board_Editor_Hokeys_Descr, HK_SAVE_BOARD_AS ); + AddMenuItem( filesMenu, ID_COPY_BOARD_AS, text, + _( "Save a copy of the current board as..." ), + KiBitmap( save_as_xpm ) ); + } + + filesMenu->AppendSeparator(); AddMenuItem( filesMenu, ID_MENU_READ_BOARD_BACKUP_FILE, _( "Revert to Last" ), diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 0438e84b34..f715fcc13a 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -120,6 +120,7 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( ID_APPEND_FILE, PCB_EDIT_FRAME::Files_io ) EVT_MENU( ID_SAVE_BOARD_AS, PCB_EDIT_FRAME::Files_io ) + EVT_MENU( ID_COPY_BOARD_AS, PCB_EDIT_FRAME::Files_io ) EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, PCB_EDIT_FRAME::OnFileHistory ) EVT_MENU( ID_GEN_PLOT, PCB_EDIT_FRAME::ToPlotter ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 1aceb0dce9..830df53a88 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -21,6 +21,7 @@ enum pcbnew_ids ID_OPEN_MODULE_VIEWER, ID_READ_NETLIST, ID_SET_RELATIVE_OFFSET, + ID_COPY_BOARD_AS, // Right vertical tool bar command IDs. ID_PCB_HIGHLIGHT_BUTT,