Move SPICE tools to modern framework.

This commit is contained in:
Jeff Young 2019-04-23 18:12:26 +01:00
parent 3233bedc7a
commit e476cfcec5
9 changed files with 126 additions and 110 deletions

View File

@ -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

View File

@ -28,11 +28,9 @@
#include <eeschema_id.h>
#include <sch_draw_panel.h>
#include <sch_edit_frame.h>
#include <sim/sim_plot_frame.h>
#include <sch_component.h>
#include <sch_sheet.h>
#include <sch_bitmap.h>
#include <netlist_object.h>
#include <sch_view.h>
#include <tool/tool_manager.h>
#include <tools/sch_selection_tool.h>
@ -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_OBJECT_LIST> 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<SCH_ITEM*>( 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<SCH_COMPONENT*>( item ) );
}
break;
#endif /* KICAD_SPICE */
default:
break;
}
}

View File

@ -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 )

View File

@ -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.

View File

@ -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 )

View File

@ -178,6 +178,12 @@ OPT<TOOL_EVENT> 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<TOOL_EVENT>();

View File

@ -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;

View File

@ -22,6 +22,7 @@
*/
#include <fctsys.h>
#include <kiway.h>
#include <sch_view.h>
#include <sch_draw_panel.h>
#include <sch_edit_frame.h>
@ -40,10 +41,20 @@
#include <hotkeys.h>
#include <advanced_config.h>
#include <status_popup.h>
#include <simulation_cursors.h>
#include <sim/sim_plot_frame.h>
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<SELECTION_TOOL>();
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
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_SELECTION_TOOL>();
SCH_ITEM* item = selTool->SelectPoint( aPosition, wiresAndComponents );
if( !item )
return false;
std::unique_ptr<NETLIST_OBJECT_LIST> 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<SCH_PICKER_TOOL>();
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_SELECTION_TOOL>();
SCH_ITEM* item = selTool->SelectPoint( aPosition, fieldsAndComponents );
if( !item )
return false;
if( item->Type() != SCH_COMPONENT_T )
{
item = static_cast<SCH_ITEM*>( 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<SCH_COMPONENT*>( item ) );
return true;
}
int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
{
Activate();
SCH_PICKER_TOOL* picker = m_toolMgr->GetTool<SCH_PICKER_TOOL>();
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() );

View File

@ -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 );