From 724c669434f9c2ff835f89cd7d83b3fc5950f3c4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 12 May 2020 18:12:38 +0100 Subject: [PATCH] Move a few more commands to tool framework. --- eeschema/dialogs/dialog_plot_schematic.cpp | 16 +--- eeschema/eeschema_id.h | 4 - eeschema/files-io.cpp | 6 +- eeschema/menubar.cpp | 9 +- eeschema/project_rescue.cpp | 47 ---------- eeschema/sch_edit_frame.cpp | 35 ------- eeschema/sch_edit_frame.h | 27 ------ eeschema/tools/ee_actions.cpp | 12 +++ eeschema/tools/ee_actions.h | 3 + eeschema/tools/sch_editor_control.cpp | 104 +++++++++++++++++++-- eeschema/tools/sch_editor_control.h | 15 +++ 11 files changed, 135 insertions(+), 143 deletions(-) diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index 99290e9323..55229c26d1 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -1,6 +1,3 @@ -/** @file dialog_plot_schematic.cpp - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -42,22 +39,11 @@ int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO; int DIALOG_PLOT_SCHEMATIC::m_HPGLPaperSizeSelect = PAGE_SIZE_AUTO; -void SCH_EDIT_FRAME::PlotSchematic() -{ - DIALOG_PLOT_SCHEMATIC dlg( this ); - - dlg.ShowModal(); - - // save project config if the prj config has changed: - if( dlg.PrjConfigChanged() ) - SaveProjectSettings(); -} - - DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) : DIALOG_PLOT_SCHEMATIC_BASE( parent ), m_parent( parent ), m_plotFormat( PLOT_FORMAT::UNDEFINED ), + m_HPGLPenSize( 1.0 ), m_defaultLineWidth( parent, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits, true ), m_penWidth( parent, m_penWidthLabel, m_penWidthCtrl, m_penWidthUnits, true ) { diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index fc7360eb3d..65fd5e4711 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -56,10 +56,6 @@ enum id_eeschema_frm { ID_IMPORT_NON_KICAD_SCH = ID_END_LIST, - /* Schematic editor main menubar IDs. */ - ID_RESCUE_CACHED, - ID_REMAP_SYMBOLS, - /* Library editor horizontal toolbar IDs. */ ID_LIBEDIT_SELECT_PART_NUMBER, diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index de79c4cff2..a7ca57fe54 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -52,6 +52,7 @@ #include #include #include +#include > #include @@ -426,7 +427,10 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in } if( !cfg || !cfg->m_RescueNeverShow ) - RescueSymbolLibTableProject( false ); + { + SCH_EDITOR_CONTROL* editor = m_toolManager->GetTool(); + editor->RescueSymbolLibTableProject( false ); + } } // Update all symbol library links for all sheets. diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 0a6db467de..3dac39e6d7 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -269,13 +269,8 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() toolsMenu->AddSeparator(); toolsMenu->AddItem( ACTIONS::showSymbolEditor, EE_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( ID_RESCUE_CACHED, _( "Rescue Symbols..." ), - _( "Find old symbols in project and rename/rescue them" ), - rescue_xpm, EE_CONDITIONS::ShowAlways ); - - toolsMenu->AddItem( ID_REMAP_SYMBOLS, _( "Remap Symbols..." ), - _( "Remap legacy library symbols to symbol library table" ), - rescue_xpm, remapSymbolsCondition ); + toolsMenu->AddItem( EE_ACTIONS::rescueSymbols, EE_CONDITIONS::ShowAlways ); + toolsMenu->AddItem( EE_ACTIONS::remapSymbols, remapSymbolsCondition ); toolsMenu->AddSeparator(); toolsMenu->AddItem( EE_ACTIONS::editSymbolFields, EE_CONDITIONS::ShowAlways ); diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index a7e9842108..2c701e83f0 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -541,53 +541,6 @@ void RESCUER::UndoRescues() } -bool SCH_EDIT_FRAME::RescueLegacyProject( bool aRunningOnDemand ) -{ - LEGACY_RESCUER rescuer( Prj(), &GetCurrentSheet(), GetCanvas()->GetBackend() ); - - return rescueProject( rescuer, aRunningOnDemand ); -} - - -bool SCH_EDIT_FRAME::RescueSymbolLibTableProject( bool aRunningOnDemand ) -{ - SYMBOL_LIB_TABLE_RESCUER rescuer( Prj(), &GetCurrentSheet(), GetCanvas()->GetBackend() ); - - return rescueProject( rescuer, aRunningOnDemand ); -} - - -bool SCH_EDIT_FRAME::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ) -{ - if( !RESCUER::RescueProject( this, aRescuer, aRunningOnDemand ) ) - return false; - - if( aRescuer.GetCandidateCount() ) - { - LIB_VIEW_FRAME* viewer = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false ); - - if( viewer ) - viewer->ReCreateListLib(); - - if( aRunningOnDemand ) - { - SCH_SCREENS schematic; - - schematic.UpdateSymbolLinks(); - g_ConnectionGraph->Reset(); - RecalculateConnections( GLOBAL_CLEANUP ); - } - - GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); - SyncView(); - GetCanvas()->Refresh(); - OnModify(); - } - - return true; -} - - bool RESCUER::RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand ) { aRescuer.FindCandidates(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 1332d6beb3..b65ed28f66 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -201,9 +201,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit ) EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit ) - EVT_TOOL( ID_RESCUE_CACHED, SCH_EDIT_FRAME::OnRescueProject ) - EVT_MENU( ID_REMAP_SYMBOLS, SCH_EDIT_FRAME::OnRemapSymbols ) - EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings ) END_EVENT_TABLE() @@ -889,27 +886,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) } -void SCH_EDIT_FRAME::OnRescueProject( wxCommandEvent& event ) -{ - SCH_SCREENS schematic; - - if( schematic.HasNoFullyDefinedLibIds() ) - RescueLegacyProject( true ); - else - RescueSymbolLibTableProject( true ); -} - - -void SCH_EDIT_FRAME::OnRemapSymbols( wxCommandEvent& event ) -{ - DIALOG_SYMBOL_REMAP dlgRemap( this ); - - dlgRemap.ShowQuasiModal(); - - GetCanvas()->Refresh( true ); -} - - void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event ) { if( event.GetId() == wxID_EXIT ) @@ -920,17 +896,6 @@ void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event ) } -void SCH_EDIT_FRAME::Print() -{ - InvokeDialogPrintUsingPrinter( this ); - - wxFileName fn = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); - - if( fn.GetName() != NAMELESS_PROJECT ) - Prj().ConfigSave( Kiface().KifaceSearch(), GROUP_SCH_EDIT, GetProjectFileParameters() ); -} - - void SCH_EDIT_FRAME::PrintPage( RENDER_SETTINGS* aSettings ) { wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() ); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 43929577ca..fd6b6f6010 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -558,11 +558,6 @@ public: */ void SetSheetNumberAndCount(); - /** - * Show the print dialog. - */ - void Print(); - wxPageSetupDialogData& GetPageSetupData() { return m_pageSetupData; } bool GetPrintMonochrome() { return m_printMonochrome; } @@ -570,9 +565,6 @@ public: bool GetPrintSheetReference() { return m_printSheetReference; } void SetPrintSheetReference( bool aShow ) { m_printSheetReference = aShow; } - // Plot functions: - void PlotSchematic(); - void NewProject(); void LoadProject(); @@ -661,8 +653,6 @@ public: void OnOpenPcbnew( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event ); - void OnRescueProject( wxCommandEvent& event ); - void OnRemapSymbols( wxCommandEvent& aEvent ); void OnUpdatePCB( wxCommandEvent& event ); void OnAnnotate( wxCommandEvent& event ); @@ -943,23 +933,6 @@ public: */ bool CreateArchiveLibrary( const wxString& aFileName ); - /** - * Perform rescue operations to recover old projects from before certain changes were made. - * - * - Exports cached symbols that conflict with new symbols to a separate library. - * - Exports cached symbols not found in any symbol library. - * - Renames symbols named before libraries were case sensitive. - * - * @param aRunningOnDemand - indicates whether the tool has been called up by the user - * (as opposed to being run automatically). If true, an information dialog is - * displayed if there are no components to rescue. If false, the tool is silent - * if there are no components to rescue, and a "Never Show Again" button is - * displayed. - */ - bool rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ); - bool RescueLegacyProject( bool aRunningOnDemand ); - bool RescueSymbolLibTableProject( bool aRunningOnDemand ); - /** * Plot or print the current sheet to the clipboard. * diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index e991d2f96d..3fdd88707c 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -547,6 +547,18 @@ TOOL_ACTION EE_ACTIONS::schematicSetup( "eeschema.EditorControl.schematicSetup", _( "Edit schematic setup including annotation styles and electrical rules" ), options_schematic_xpm ); +TOOL_ACTION EE_ACTIONS::rescueSymbols( "eeschema.EditorControl.rescueSymbols", + AS_GLOBAL, 0, "", + _( "Rescue Symbols..." ), + _( "Find old symbols in project and rename/rescue them" ), + rescue_xpm ); + +TOOL_ACTION EE_ACTIONS::remapSymbols( "eeschema.EditorControl.remapSymbols", + AS_GLOBAL, 0, "", + _( "Remap Symbols..." ), + _( "Remap legacy library symbols to symbol library table" ), + rescue_xpm ); + TOOL_ACTION EE_ACTIONS::showBusManager( "eeschema.EditorControl.showBusManager", AS_GLOBAL, 0, "", _( "Bus Definitions..." ), _( "Manage bus definitions" ), diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index 66b2e26be6..38ec8ab1c9 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -153,6 +153,9 @@ public: static TOOL_ACTION showBusManager; static TOOL_ACTION schematicSetup; + static TOOL_ACTION rescueSymbols; + static TOOL_ACTION remapSymbols; + // Suite operations static TOOL_ACTION editWithLibEdit; static TOOL_ACTION showPcbNew; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 22e7b907ed..a43c8db15a 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -43,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -51,14 +55,10 @@ #include #include #include -#include -#include -#include -#include -#include #include // for KiROUND #include + int SCH_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent ) { m_frame->NewProject(); @@ -113,16 +113,103 @@ int SCH_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent ) } +int SCH_EDITOR_CONTROL::RescueSymbols( const TOOL_EVENT& aEvent ) +{ + SCH_SCREENS schematic; + + if( schematic.HasNoFullyDefinedLibIds() ) + RescueLegacyProject( true ); + else + RescueSymbolLibTableProject( true ); + + return 0; +} + + +bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand ) +{ + LEGACY_RESCUER rescuer( m_frame->Prj(), &m_frame->GetCurrentSheet(), + m_frame->GetCanvas()->GetBackend() ); + + return rescueProject( rescuer, aRunningOnDemand ); +} + + +bool SCH_EDITOR_CONTROL::RescueSymbolLibTableProject( bool aRunningOnDemand ) +{ + SYMBOL_LIB_TABLE_RESCUER rescuer( m_frame->Prj(), &m_frame->GetCurrentSheet(), + m_frame->GetCanvas()->GetBackend() ); + + return rescueProject( rescuer, aRunningOnDemand ); +} + + +bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ) +{ + if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) ) + return false; + + if( aRescuer.GetCandidateCount() ) + { + KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false ); + + if( viewer ) + static_cast( viewer )->ReCreateListLib(); + + if( aRunningOnDemand ) + { + SCH_SCREENS schematic; + + schematic.UpdateSymbolLinks(); + g_ConnectionGraph->Reset(); + m_frame->RecalculateConnections( GLOBAL_CLEANUP ); + } + + m_frame->GetScreen()->ClearUndoORRedoList( m_frame->GetScreen()->m_UndoList, 1 ); + m_frame->SyncView(); + m_frame->GetCanvas()->Refresh(); + m_frame->OnModify(); + } + + return true; +} + + +int SCH_EDITOR_CONTROL::RemapSymbols( const TOOL_EVENT& aEvent ) +{ + DIALOG_SYMBOL_REMAP dlgRemap( m_frame ); + + dlgRemap.ShowQuasiModal(); + + m_frame->GetCanvas()->Refresh( true ); + + return 0; +} + + int SCH_EDITOR_CONTROL::Print( const TOOL_EVENT& aEvent ) { - m_frame->Print(); + InvokeDialogPrintUsingPrinter( m_frame ); + + wxFileName fn = m_frame->Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); + + if( fn.GetName() != NAMELESS_PROJECT ) + m_frame->SaveProjectSettings(); + return 0; } int SCH_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent ) { - m_frame->PlotSchematic(); + DIALOG_PLOT_SCHEMATIC dlg( m_frame ); + + dlg.ShowModal(); + + // save project config if the prj config has changed: + if( dlg.PrjConfigChanged() ) + m_frame->SaveProjectSettings(); + return 0; } @@ -1504,6 +1591,9 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::RescueSymbols, EE_ACTIONS::rescueSymbols.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::RemapSymbols, EE_ACTIONS::remapSymbols.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::FindAndReplace, ACTIONS::find.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::FindAndReplace, ACTIONS::findAndReplace.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::FindNext, ACTIONS::findNext.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index 33b18cce69..f15ef1f691 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -58,6 +58,19 @@ public: int Plot( const TOOL_EVENT& aEvent ); int Quit( const TOOL_EVENT& aEvent ); + /** + * Perform rescue operations to recover old projects from before certain changes were made. + * + * - Exports cached symbols that conflict with new symbols to a separate library. + * - Exports cached symbols not found in any symbol library. + * - Renames symbols named before libraries were case sensitive. + */ + int RescueSymbols( const TOOL_EVENT& aEvent ); + int RemapSymbols( const TOOL_EVENT& aEvent ); + + bool RescueLegacyProject( bool aRunningOnDemand ); + bool RescueSymbolLibTableProject( bool aRunningOnDemand ); + int FindAndReplace( const TOOL_EVENT& aEvent ); int FindNext( const TOOL_EVENT& aEvent ); @@ -142,6 +155,8 @@ private: ///> copy selection to clipboard bool doCopy(); + bool rescueProject( RESCUER& aRescuer, bool aRunningOnDemand ); + bool searchSupplementaryClipboard( const wxString& aSheetFilename, SCH_SCREEN** aScreen ); void doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce );