From e476cfcec537ba9597cbb9b08f74c1dbb4296412 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 23 Apr 2019 18:12:26 +0100 Subject: [PATCH] Move SPICE tools to modern framework. --- eeschema/CMakeLists.txt | 1 + eeschema/onleftclick.cpp | 61 -------------- eeschema/sch_edit_frame.cpp | 5 -- eeschema/sch_edit_frame.h | 1 - eeschema/schedit.cpp | 42 ---------- eeschema/tools/sch_actions.cpp | 6 ++ eeschema/tools/sch_actions.h | 4 + eeschema/tools/sch_editor_control.cpp | 111 +++++++++++++++++++++++++- eeschema/tools/sch_editor_control.h | 5 ++ 9 files changed, 126 insertions(+), 110 deletions(-) diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index a6c238c858..324f46262d 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -271,6 +271,7 @@ if( KICAD_SPICE ) sim/simulate.cpp sim/spice_simulator.cpp sim/spice_value.cpp + simulation_cursors.cpp dialogs/dialog_signal_list.cpp dialogs/dialog_signal_list_base.cpp dialogs/dialog_sim_settings.cpp diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index 1f189e7418..980711b23f 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -28,11 +28,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -85,65 +83,6 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( !item ) // If clicked on a empty area, clear any highligthed symbol GetCanvas()->GetView()->HighlightItem( nullptr, nullptr ); - - switch( GetToolId() ) - { -#ifdef KICAD_SPICE - case ID_SIM_PROBE: - { - constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T, - SCH_COMPONENT_T, - SCH_SHEET_PIN_T, - EOT }; - item = selTool->SelectPoint( aPosition, wiresAndComponents ); - - if( !item ) - break; - - std::unique_ptr netlist( BuildNetListBase() ); - - for( NETLIST_OBJECT* obj : *netlist ) - { - if( obj->m_Comp == item ) - { - SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false ); - - if( simFrame ) - simFrame->AddVoltagePlot( obj->GetNetName() ); - - break; - } - } - } - break; - - case ID_SIM_TUNE: - { - constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT }; - item = selTool->SelectPoint( aPosition, fieldsAndComponents ); - - if( !item ) - return; - - if( item->Type() != SCH_COMPONENT_T ) - { - item = static_cast( item->GetParent() ); - - if( item->Type() != SCH_COMPONENT_T ) - return; - } - - SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false ); - - if( simFrame ) - simFrame->AddTuner( static_cast( item ) ); - } - break; -#endif /* KICAD_SPICE */ - - default: - break; - } } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 6559bc1c02..d7f262e5e7 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -280,13 +280,8 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout ) EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings ) - // Tools and buttons for vertical toolbar. - EVT_TOOL( ID_NO_TOOL_SELECTED, SCH_EDIT_FRAME::OnSelectTool ) - #ifdef KICAD_SPICE EVT_TOOL( ID_SIM_SHOW, SCH_EDIT_FRAME::OnSimulate ) - EVT_TOOL( ID_SIM_PROBE, SCH_EDIT_FRAME::OnSelectTool ) - EVT_TOOL( ID_SIM_TUNE, SCH_EDIT_FRAME::OnSelectTool ) #endif /* KICAD_SPICE */ EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand ) diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 8ca97dd180..ae0ae30162 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -252,7 +252,6 @@ public: void Process_Special_Functions( wxCommandEvent& event ); void Process_Config( wxCommandEvent& event ); - void OnSelectTool( wxCommandEvent& aEvent ); /** * Processes an "Unfold Bus" command from the right-click menu. diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index cc33216378..e182ef6624 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -456,48 +456,6 @@ void SCH_EDIT_FRAME::OnCancelCurrentCommand( wxCommandEvent& aEvent ) } -void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) -{ - int id = aEvent.GetId(); - - // Stop the current command and deselect the current tool. - m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() ); - - // Same for modern toolset. - m_toolManager->DeactivateTool(); - - switch( id ) - { - case ID_NO_TOOL_SELECTED: - SetNoToolSelected(); - break; - -#ifdef KICAD_SPICE - case ID_SIM_PROBE: - SetToolID( id, -1, _( "Add a simulator probe" ) ); - //GAL TODO: m_canvas->SetCurrentCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) ); - break; - - case ID_SIM_TUNE: - SetToolID( id, -1, _( "Select a value to be tuned" ) ); - //GAL TODO: m_canvas->SetCurrentCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) ); - break; -#endif /* KICAD_SPICE */ - - default: - SetRepeatItem( NULL ); - } - - // Simulate left click event if we got here from a hot key. - if( aEvent.GetClientObject() != NULL ) - { - EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); - - OnLeftClick( nullptr, data->GetPosition() ); - } -} - - void SCH_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent ) { if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar ) diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index 9a69bd73b3..69c8326f7a 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -178,6 +178,12 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_POPUP_SCH_DELETE: return SCH_ACTIONS::remove.MakeEvent(); + + case ID_SIM_PROBE: + return SCH_ACTIONS::simProbe.MakeEvent(); + + case ID_SIM_TUNE: + return SCH_ACTIONS::simTune.MakeEvent(); } return OPT(); diff --git a/eeschema/tools/sch_actions.h b/eeschema/tools/sch_actions.h index 87761e479e..8f144df68d 100644 --- a/eeschema/tools/sch_actions.h +++ b/eeschema/tools/sch_actions.h @@ -134,6 +134,10 @@ public: static TOOL_ACTION deleteItemCursor; static TOOL_ACTION refreshPreview; + // SPICE + static TOOL_ACTION simProbe; + static TOOL_ACTION simTune; + // Net highlighting static TOOL_ACTION highlightNet; static TOOL_ACTION clearHighlight; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index add0c54045..a0a2b8b2c3 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -40,10 +41,20 @@ #include #include #include +#include +#include TOOL_ACTION SCH_ACTIONS::refreshPreview( "eeschema.EditorControl.refreshPreview", AS_GLOBAL, 0, "", "" ); +TOOL_ACTION SCH_ACTIONS::simProbe( "eeschema.Simulation.probe", + AS_GLOBAL, 0, + _( "Add a simulator probe" ), "" ); + +TOOL_ACTION SCH_ACTIONS::simTune( "eeschema.Simulation.tune", + AS_GLOBAL, 0, + _( "Select a value to be tuned" ), "" ); + TOOL_ACTION SCH_ACTIONS::highlightNet( "eeschema.EditorControl.highlightNet", AS_GLOBAL, 0, "", "" ); @@ -105,7 +116,7 @@ bool SCH_EDITOR_CONTROL::Init() lockMenu->SetTool( this ); // Add the SCH control menus to relevant other tools - SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); if( selTool ) { @@ -173,6 +184,99 @@ int SCH_EDITOR_CONTROL::CrossProbeSchToPcb( const TOOL_EVENT& aEvent ) } +#ifdef KICAD_SPICE +static bool probeSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition ) +{ + constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T, EOT }; + SCH_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool(); + + SCH_ITEM* item = selTool->SelectPoint( aPosition, wiresAndComponents ); + + if( !item ) + return false; + + std::unique_ptr netlist( aFrame->BuildNetListBase() ); + + for( NETLIST_OBJECT* obj : *netlist ) + { + if( obj->m_Comp == item ) + { + auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false ); + + if( simFrame ) + simFrame->AddVoltagePlot( obj->GetNetName() ); + + break; + } + } + + return true; +} + + +int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) +{ + Activate(); + + SCH_PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + m_frame->SetToolID( ID_SIM_PROBE, wxCURSOR_DEFAULT, _( "Add a simulator probe" ) ); + m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::PROBE ) ); + + picker->SetClickHandler( std::bind( probeSimulation, m_frame, std::placeholders::_1 ) ); + picker->Activate(); + Wait(); + + return 0; +} + + +static bool tuneSimulation( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition ) +{ + constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT }; + SCH_SELECTION_TOOL* selTool = aFrame->GetToolManager()->GetTool(); + SCH_ITEM* item = selTool->SelectPoint( aPosition, fieldsAndComponents ); + + if( !item ) + return false; + + if( item->Type() != SCH_COMPONENT_T ) + { + item = static_cast( item->GetParent() ); + + if( item->Type() != SCH_COMPONENT_T ) + return false; + } + + auto simFrame = (SIM_PLOT_FRAME*) aFrame->Kiway().Player( FRAME_SIMULATOR, false ); + + if( simFrame ) + simFrame->AddTuner( static_cast( item ) ); + + return true; +} + + +int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent ) +{ + Activate(); + + SCH_PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + m_frame->SetToolID( ID_SIM_TUNE, wxCURSOR_DEFAULT, _( "Select a value to be tuned" ) ); + m_frame->GetCanvas()->SetCursor( SIMULATION_CURSORS::GetCursor( SIMULATION_CURSORS::CURSOR::TUNE ) ); + + picker->SetClickHandler( std::bind( tuneSimulation, m_frame, std::placeholders::_1 ) ); + picker->Activate(); + Wait(); + + return 0; +} +#endif /* KICAD_SPICE */ + + // A magic cookie token for clearing the highlight static VECTOR2D CLEAR; @@ -391,6 +495,11 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::CrossProbePcbToSch, SCH_ACTIONS::crossProbeSchToPcb.MakeEvent() ); */ +#ifdef KICAD_SPICE + Go( &SCH_EDITOR_CONTROL::SimProbe, SCH_ACTIONS::simProbe.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::SimTune, SCH_ACTIONS::simTune.MakeEvent() ); +#endif /* KICAD_SPICE */ + Go( &SCH_EDITOR_CONTROL::HighlightNet, SCH_ACTIONS::highlightNet.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ClearHighlight, SCH_ACTIONS::clearHighlight.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::HighlightNetCursor, SCH_ACTIONS::highlightNetCursor.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index 02fa783009..848df16cf5 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -59,6 +59,11 @@ public: ///> Notifies pcbnew about the selected item. int CrossProbeSchToPcb( const TOOL_EVENT& aEvent ); +#ifdef KICAD_SPICE + int SimProbe( const TOOL_EVENT& aEvent ); + int SimTune( const TOOL_EVENT& aEvent ); +#endif /* KICAD_SPICE */ + ///> Highlights net under the cursor. int HighlightNet( const TOOL_EVENT& aEvent );