From 853abdac24ab282ffc6ef995fe2349093aaf94fa Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 8 Jul 2014 19:52:46 -0500 Subject: [PATCH] kicad.exe work: *) re-enable the MacOpen() support. *) fix path truncation bug. *) open *.kicad_pcb and *.sch files in the same process if they are part of the the currently open project, even from the tree view. --- kicad/class_treeproject_item.cpp | 67 +++++++++++------ kicad/class_treeproject_item.h | 14 ++-- kicad/files-io.cpp | 6 +- kicad/kicad.cpp | 26 +------ kicad/kicad.h | 15 +++- kicad/mainframe.cpp | 123 ++++++++++++++++++++----------- kicad/prjconfig.cpp | 30 ++++---- kicad/tree_project_frame.cpp | 14 ++-- 8 files changed, 172 insertions(+), 123 deletions(-) diff --git a/kicad/class_treeproject_item.cpp b/kicad/class_treeproject_item.cpp index 1c28d5701d..30ce219716 100644 --- a/kicad/class_treeproject_item.cpp +++ b/kicad/class_treeproject_item.cpp @@ -48,11 +48,12 @@ TREEPROJECT_ITEM::TREEPROJECT_ITEM( enum TreeFileType type, const wxString& data wxTreeCtrl* parent ) : wxTreeItemData() { - m_Type = type; m_parent = parent; - m_FileName = data; - m_IsRootFile = false; // true only for the root item of the tree (the project name) - m_IsPopulated = false; + + SetType( type ); + SetFileName( data ); + SetRootFile( false ); // true only for the root item of the tree (the project name) + SetPopulated( false ); } @@ -73,12 +74,9 @@ void TREEPROJECT_ITEM::SetState( int state ) const wxString TREEPROJECT_ITEM::GetDir() const { if( TREE_DIRECTORY == m_Type ) - return m_FileName; + return GetFileName(); - wxFileName filename = wxFileName( m_FileName ); - - wxString dir = filename.GetPath(); - return dir; + return wxFileName( GetFileName() ).GetPath(); } @@ -100,7 +98,7 @@ bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) else newFile = name; - if( newFile == m_FileName ) + if( newFile == GetFileName() ) return false; wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() ); @@ -123,10 +121,10 @@ type.\n Do you want to continue ?" #if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \ && ( wxMINOR_VERSION < 7 ) ) ) - if( !wxRenameFile( m_FileName, newFile ) ) + if( !wxRenameFile( GetFileName(), newFile ) ) #else - if( !wxRenameFile( m_FileName, newFile, false ) ) + if( !wxRenameFile( GetFileName(), newFile, false ) ) #endif { wxMessageDialog( m_parent, _( "Unable to rename file ... " ), @@ -156,18 +154,18 @@ bool TREEPROJECT_ITEM::Delete( bool check ) { bool success; - if( !wxDirExists( m_FileName ) ) - success = wxRemoveFile( m_FileName ); + if( !wxDirExists( GetFileName() ) ) + success = wxRemoveFile( GetFileName() ); else { wxArrayString filelist; - wxDir::GetAllFiles( m_FileName, &filelist ); + wxDir::GetAllFiles( GetFileName(), &filelist ); for( unsigned int i = 0; i < filelist.Count(); i++ ) wxRemoveFile( filelist[i] ); - success = wxRmdir( m_FileName ); + success = wxRmdir( GetFileName() ); } if( success ) @@ -188,8 +186,6 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) Pgm().App().GetTopWindow(); - AddDelimiterString( fullFileName ); - switch( GetType() ) { case TREE_PROJECT: @@ -200,16 +196,41 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) break; case TREE_SCHEMA: - mainFrame->Execute( m_parent, EESCHEMA_EXE, fullFileName ); + { + wxFileName ffn( fullFileName ); + wxFileName pro( mainFrame->GetProjectFileName() ); + + // compare all but the extension: + if( pro.GetPath()==ffn.GetPath() && pro.GetName()==ffn.GetName() ) + { + // the project's schematic is opened using the *.kiface as part of this process. + mainFrame->RunEeschema( fullFileName ); + } + else + { + // schematics not part of the project are opened in a separate process. + mainFrame->Execute( m_parent, EESCHEMA_EXE, fullFileName ); + } + } break; case TREE_LEGACY_PCB: case TREE_SEXP_PCB: { - DBG( printf( "%s: %s\n", __func__, TO_UTF8( fullFileName ) ); ) + wxFileName ffn( fullFileName ); + wxFileName pro( mainFrame->GetProjectFileName() ); - - mainFrame->Execute( m_parent, PCBNEW_EXE, fullFileName ); + // compare all but the extension: + if( pro.GetPath()==ffn.GetPath() && pro.GetName()==ffn.GetName() ) + { + // the project's BOARD is opened using the *.kiface as part of this process. + mainFrame->RunPcbNew( fullFileName ); + } + else + { + // boards not part of the project are opened in a separate process. + mainFrame->Execute( m_parent, PCBNEW_EXE, fullFileName ); + } } break; @@ -218,6 +239,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) break; case TREE_PDF: + AddDelimiterString( fullFileName ); OpenPDF( fullFileName ); break; @@ -239,6 +261,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) break; default: + AddDelimiterString( fullFileName ); OpenFile( fullFileName ); break; } diff --git a/kicad/class_treeproject_item.h b/kicad/class_treeproject_item.h index 9319410981..3793638cd6 100644 --- a/kicad/class_treeproject_item.h +++ b/kicad/class_treeproject_item.h @@ -7,7 +7,7 @@ */ class TREEPROJECT_ITEM : public wxTreeItemData { - friend class KICAD_MANAGER_FRAME; + //friend class KICAD_MANAGER_FRAME; public: @@ -17,7 +17,7 @@ public: TREEPROJECT_ITEM() : m_parent( NULL ) { } TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) : - m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent ) + m_Type( src.m_Type ), m_file_name( src.m_file_name ), m_parent( src.m_parent ) { SetState( src.m_state ); m_IsPopulated = false; @@ -26,8 +26,12 @@ public: TreeFileType GetType() const { return m_Type; } void SetType( TreeFileType aType ) { m_Type = aType; } - const wxString& GetFileName() const { return m_FileName; } - void SetFileName( const wxString& name ) { m_FileName = name; } + const wxString& GetFileName() const { return m_file_name; } + void SetFileName( const wxString& name ) + { + m_file_name = name; + // DBG(printf("%s: '%s'\n", __func__, TO_UTF8( name ) );) + } bool IsRootFile() const { return m_IsRootFile; } void SetRootFile( bool aValue ) { m_IsRootFile = aValue; } @@ -50,7 +54,7 @@ public: private: TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ... - wxString m_FileName; // Filename for a file, or directory name + wxString m_file_name; // Filename for a file, or directory name bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project) bool m_IsPopulated; // True if the name is a directory, and its content was read wxTreeCtrl* m_parent; diff --git a/kicad/files-io.cpp b/kicad/files-io.cpp index d7c724698f..6e1ca00db8 100644 --- a/kicad/files-io.cpp +++ b/kicad/files-io.cpp @@ -50,7 +50,7 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) wxString fn = GetFileFromHistory( event.GetId(), _( "KiCad project file" ), &Pgm().GetFileHistory() ); - if( fn != wxEmptyString ) + if( fn.size() ) { wxCommandEvent cmd( 0, wxID_ANY ); @@ -73,7 +73,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event ) if( dlg.ShowModal() == wxID_CANCEL ) return; - wxString msg = wxString::Format( _("\nOpen <%s>\n" ), GetChars( dlg.GetPath() ) ); + wxString msg = wxString::Format( _("\nOpen '%s'\n" ), GetChars( dlg.GetPath() ) ); PrintMsg( msg ); wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), @@ -83,7 +83,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event ) return; wxSetWorkingDirectory( dirDlg.GetPath() ); - msg.Printf( _( "Unzipping project in <%s>\n" ), GetChars( dirDlg.GetPath() ) ); + msg.Printf( _( "Unzipping project in '%s'\n" ), GetChars( dirDlg.GetPath() ) ); PrintMsg( msg ); wxFileSystem zipfilesys; diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index caea06763f..23d0d5c1c1 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -214,37 +214,17 @@ void PGM_KICAD::OnPgmExit() void PGM_KICAD::MacOpenFile( const wxString& aFileName ) { -#if 0 // I'm tired, need a rest. +#if defined(__WXMAC__) - KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) GetTopWindow(); + KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow(); - frame->SetProjectFile( aFileName ); - - wxFileName fn = aFileName; - - if( !fn.FileExists() && m_fileHistory.GetCount() ) - { - m_fileHistory.RemoveFileFromHistory( 0 ); - return; - } + frame->SetProjectFileName( aFileName ); wxCommandEvent loadEvent; loadEvent.SetId( wxID_ANY ); frame->OnLoadProject( loadEvent ); - - wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() + - wxT( " " ) + frame->GetProjectFileName(); - - if( !fn.IsDirWritable() ) - title += _( " [Read Only]" ); - - frame->SetTitle( title ); - - frame->m_LeftWin->ReCreateTreePrj(); - - frame->PrintPrjInfo(); #endif } diff --git a/kicad/kicad.h b/kicad/kicad.h index 598aff73ee..317ad498ed 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -203,7 +203,7 @@ public: * @param param = parameters to be passed to the executable. */ void Execute( wxWindow* frame, const wxString& execFile, - const wxString& param = wxEmptyString ); + wxString param = wxEmptyString ); class TERMINATE_HANDLER : public wxProcess { @@ -233,6 +233,17 @@ public: // read only accessors const wxString SchFileName(); const wxString PcbFileName(); + const wxString PcbLegacyFileName(); + + void ReCreateTreePrj(); + + /// Call this only for a PCB associated with the current project. That is, + /// it must have the same path and name as the project *.pro file. + void RunPcbNew( const wxString& aProjectBoardFileName ); + + /// Call this only for a SCH associated with the current project. That is, + /// it must have the same path and name as the project *.pro file. + void RunEeschema( const wxString& aProjectSchematicFileName ); DECLARE_EVENT_TABLE() @@ -248,7 +259,7 @@ private: LAUNCHER_PANEL* m_Launcher; wxTextCtrl* m_MessagesBox; wxAuiToolBar* m_VToolBar; // Vertical toolbar (not used) - wxFileName m_project_file_name; + wxString m_project_file_name; int m_leftWinWidth; diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 921e140080..51bb45b8c4 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -124,23 +124,27 @@ wxConfigBase* KICAD_MANAGER_FRAME::config() return ret; } + void KICAD_MANAGER_FRAME::SetProjectFileName( const wxString& aFullProjectProFileName ) { m_project_file_name = aFullProjectProFileName; - wxASSERT( m_project_file_name.IsAbsolute() ); + wxASSERT( wxFileName( m_project_file_name ).IsAbsolute() || + wxFileName( m_project_file_name ).GetName() == NAMELESS_PROJECT wxT( ".pro" ) ); } const wxString KICAD_MANAGER_FRAME::GetProjectFileName() { - return m_project_file_name.GetFullPath(); + return m_project_file_name; } const wxString KICAD_MANAGER_FRAME::SchFileName() { - wxFileName fn( GetProjectFileName(), SchematicFileExtension ); + wxFileName fn( GetProjectFileName() ); + + fn.SetExt( SchematicFileExtension ); return fn.GetFullName(); } @@ -148,12 +152,30 @@ const wxString KICAD_MANAGER_FRAME::SchFileName() const wxString KICAD_MANAGER_FRAME::PcbFileName() { - wxFileName fn( GetProjectFileName(), PcbFileExtension ); + wxFileName fn( GetProjectFileName() ); + + fn.SetExt( PcbFileExtension ); return fn.GetFullName(); } +const wxString KICAD_MANAGER_FRAME::PcbLegacyFileName() +{ + wxFileName fn( GetProjectFileName() ); + + fn.SetExt( LegacyPcbFileExtension ); + + return fn.GetFullName(); +} + + +void KICAD_MANAGER_FRAME::ReCreateTreePrj() +{ + m_LeftWin->ReCreateTreePrj(); +} + + const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search() { return Pgm().SysSearch(); @@ -227,11 +249,14 @@ void KICAD_MANAGER_FRAME::TERMINATE_HANDLER::OnTerminate( int pid, int status ) void KICAD_MANAGER_FRAME::Execute( wxWindow* frame, const wxString& execFile, - const wxString& param ) + wxString params ) { + if( params.size() ) + AddDelimiterString( params ); + TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( execFile ); - long pid = ExecuteFile( frame, execFile, param, callback ); + long pid = ExecuteFile( frame, execFile, params, callback ); if( pid > 0 ) { @@ -247,6 +272,54 @@ void KICAD_MANAGER_FRAME::Execute( wxWindow* frame, const wxString& execFile, } +void KICAD_MANAGER_FRAME::RunEeschema( const wxString& aProjectSchematicFileName ) +{ + KIWAY_PLAYER* frame = Kiway.Player( FRAME_SCH, false ); + if( !frame ) + { + frame = Kiway.Player( FRAME_SCH, true ); + frame->OpenProjectFiles( std::vector( 1, aProjectSchematicFileName ) ); + frame->Show( true ); + } + frame->Raise(); +} + + +void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event ) +{ + wxFileName fn( m_project_file_name ); + + fn.SetExt( SchematicFileExtension ); + + RunEeschema( fn.GetFullPath() ); +} + + +void KICAD_MANAGER_FRAME::RunPcbNew( const wxString& aProjectBoardFileName ) +{ + KIWAY_PLAYER* frame = Kiway.Player( FRAME_PCB, false ); + if( !frame ) + { + frame = Kiway.Player( FRAME_PCB, true ); + frame->OpenProjectFiles( std::vector( 1, aProjectBoardFileName ) ); + frame->Show( true ); + } + frame->Raise(); +} + + +void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event ) +{ + wxFileName kicad_board( PcbFileName() ); + wxFileName legacy_board( PcbLegacyFileName() ); + + wxFileName& board = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ? + kicad_board : legacy_board; + + RunPcbNew( board.GetFullPath() ); +} + + void KICAD_MANAGER_FRAME::OnRunBitmapConverter( wxCommandEvent& event ) { Execute( this, BITMAPCONVERTER_EXE ); @@ -264,27 +337,6 @@ void KICAD_MANAGER_FRAME::OnRunPageLayoutEditor( wxCommandEvent& event ) } -void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event ) -{ - wxFileName kicad_board( PcbFileName() ); - - wxFileName legacy_board( GetProjectFileName() ); - legacy_board.SetExt( LegacyPcbFileExtension ); - - wxFileName& board = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ? - kicad_board : legacy_board; - - KIWAY_PLAYER* frame = Kiway.Player( FRAME_PCB, false ); - if( !frame ) - { - frame = Kiway.Player( FRAME_PCB, true ); - frame->OpenProjectFiles( std::vector( 1, board.GetFullPath() ) ); - frame->Show( true ); - } - frame->Raise(); -} - - void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) { wxFileName fn( m_project_file_name ); @@ -302,23 +354,6 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) } -void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event ) -{ - wxFileName fn( m_project_file_name ); - - fn.SetExt( SchematicFileExtension ); - - KIWAY_PLAYER* frame = Kiway.Player( FRAME_SCH, false ); - if( !frame ) - { - frame = Kiway.Player( FRAME_SCH, true ); - frame->OpenProjectFiles( std::vector( 1, fn.GetFullPath() ) ); - frame->Show( true ); - } - frame->Raise(); -} - - void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) { // Gerbview is called without any file to open, because we do not know diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp index 501ecd6dcf..260cc03164 100644 --- a/kicad/prjconfig.cpp +++ b/kicad/prjconfig.cpp @@ -182,14 +182,13 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) { wxString title; - // this is still a mess, will work on it tomorrow. + // this is still a pr, will work on it tomorrow. ClearMsg(); if( event.GetId() != wxID_ANY ) { - int style; - + int style; bool newProject = ( event.GetId() == ID_NEW_PROJECT ) || ( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ); @@ -212,6 +211,7 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) return; wxFileName pro( dlg.GetPath() ); + pro.SetExt( ProjectFileExtension ); if( newProject ) @@ -248,40 +248,40 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) } } - SetProjectFileName( pro.GetFullName() ); + SetProjectFileName( pro.GetFullPath() ); } - wxLogDebug( wxT( "Loading KiCad project file: " ) + GetProjectFileName() ); - - // Check if project file exists and if it is not noname.pro - wxString filename = GetProjectFileName(); + wxString prj_filename = GetProjectFileName(); wxString nameless_prj = NAMELESS_PROJECT wxT( ".pro" ); - if( !wxFileExists( GetProjectFileName() ) && !filename.IsSameAs( nameless_prj ) ) + // Check if project file exists and if it is not noname.pro + if( !wxFileExists( prj_filename ) && !prj_filename.IsSameAs( nameless_prj ) ) { wxString msg = wxString::Format( _( "KiCad project file '%s' not found" ), - GetChars( GetProjectFileName() ) ); + GetChars( prj_filename ) ); DisplayError( this, msg ); return; } - wxSetWorkingDirectory( wxFileName( GetProjectFileName() ).GetPath() ); + wxSetWorkingDirectory( wxFileName( prj_filename ).GetPath() ); // was wxGetApp().ReadProjectConfig( m_ProjectFileName.GetFullPath(), // GeneralGroupName, s_KicadManagerParams, false ); - Prj().ConfigLoad( Pgm().SysSearch(), GetProjectFileName(), + Prj().ConfigLoad( Pgm().SysSearch(), prj_filename, GeneralGroupName, s_KicadManagerParams, false ); - title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + GetProjectFileName(); + title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + prj_filename; - if( !wxIsWritable( GetProjectFileName() ) ) + if( !wxFileName( prj_filename ).IsDirWritable() ) title += _( " [Read Only]" ); SetTitle( title ); - UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() ); + + if( !prj_filename.IsSameAs( nameless_prj ) ) + UpdateFileHistory( prj_filename, &Pgm().GetFileHistory() ); m_LeftWin->ReCreateTreePrj(); diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 383dd06b34..eec1659008 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -618,7 +618,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) { int tree_id; TREEPROJECT_ITEM* tree_data; - wxString FullFileName; + wxString fullFileName; wxTreeItemId curr_item = Event.GetItem(); // Ensure item is selected (Under Windows right click does not select the item) @@ -630,7 +630,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) return; tree_id = tree_data->GetType(); - FullFileName = tree_data->GetFileName(); + fullFileName = tree_data->GetFileName(); wxMenu popupMenu; @@ -684,12 +684,12 @@ void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event if( tree_data->GetType() == TREE_DIRECTORY ) return; - wxString FullFileName = tree_data->GetFileName(); - AddDelimiterString( FullFileName ); + wxString fullFileName = tree_data->GetFileName(); + AddDelimiterString( fullFileName ); wxString editorname = Pgm().GetEditorName(); if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, FullFileName ); + ExecuteFile( this, editorname, fullFileName ); } @@ -736,8 +736,6 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) { - wxString FullFileName; - TREEPROJECT_ITEM* tree_data = GetSelectedData(); if( !tree_data ) @@ -749,8 +747,6 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) { - wxString FullFileName; - wxTreeItemId itemId = Event.GetItem(); TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );