Browse Source

Prevent creating too many transitions by TOOL_MANAGER

- added TOOL_INTERACTIVE::resetTransitions()
- made protected and moved TOOL_BASE::setTransitions() to TOOL_INTERACTIVE
- TOOL_MANAGER calls TOOL_INTERACTIVE::resetTransitions() instead of
setTransitions()
pull/7/merge
Maciej Suminski 8 years ago
parent
commit
76bd05a69b
  1. 2
      common/tool/common_tools.cpp
  2. 7
      common/tool/tool_interactive.cpp
  3. 23
      common/tool/tool_manager.cpp
  4. 2
      include/tool/common_tools.h
  5. 7
      include/tool/tool_base.h
  6. 13
      include/tool/tool_interactive.h
  7. 6
      include/tool/tool_manager.h
  8. 2
      pcbnew/router/length_tuner_tool.cpp
  9. 2
      pcbnew/router/length_tuner_tool.h
  10. 2
      pcbnew/router/router_tool.cpp
  11. 2
      pcbnew/router/router_tool.h
  12. 2
      pcbnew/tools/drawing_tool.cpp
  13. 2
      pcbnew/tools/drawing_tool.h
  14. 2
      pcbnew/tools/edit_tool.cpp
  15. 2
      pcbnew/tools/edit_tool.h
  16. 2
      pcbnew/tools/microwave_tool.cpp
  17. 2
      pcbnew/tools/microwave_tool.h
  18. 2
      pcbnew/tools/module_editor_tools.cpp
  19. 2
      pcbnew/tools/module_editor_tools.h
  20. 2
      pcbnew/tools/pad_tool.cpp
  21. 2
      pcbnew/tools/pad_tool.h
  22. 2
      pcbnew/tools/pcb_editor_control.cpp
  23. 2
      pcbnew/tools/pcb_editor_control.h
  24. 2
      pcbnew/tools/pcbnew_control.cpp
  25. 2
      pcbnew/tools/pcbnew_control.h
  26. 2
      pcbnew/tools/picker_tool.cpp
  27. 4
      pcbnew/tools/picker_tool.h
  28. 2
      pcbnew/tools/placement_tool.cpp
  29. 2
      pcbnew/tools/placement_tool.h
  30. 2
      pcbnew/tools/point_editor.cpp
  31. 2
      pcbnew/tools/point_editor.h
  32. 2
      pcbnew/tools/position_relative_tool.cpp
  33. 2
      pcbnew/tools/position_relative_tool.h
  34. 2
      pcbnew/tools/selection_tool.cpp
  35. 2
      pcbnew/tools/selection_tool.h
  36. 2
      pcbnew/tools/zoom_tool.cpp
  37. 4
      pcbnew/tools/zoom_tool.h

2
common/tool/common_tools.cpp

@ -206,7 +206,7 @@ int COMMON_TOOLS::ToggleCursor( const TOOL_EVENT& aEvent )
}
void COMMON_TOOLS::SetTransitions()
void COMMON_TOOLS::setTransitions()
{
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() );
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() );

7
common/tool/tool_interactive.cpp

@ -58,6 +58,13 @@ OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList )
}
void TOOL_INTERACTIVE::resetTransitions()
{
m_toolMgr->ClearTransitions( this );
setTransitions();
}
void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions )
{
m_toolMgr->ScheduleNextState( this, aState, aConditions );

23
common/tool/tool_manager.cpp

@ -372,7 +372,9 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
}
aTool->Reset( TOOL_INTERACTIVE::RUN );
aTool->SetTransitions();
if( aTool->GetType() == INTERACTIVE )
static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
// Add the tool on the front of the processing queue (it gets events first)
m_activeTools.push_front( id );
@ -417,8 +419,11 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
for( auto& state : m_toolState )
{
state.first->Reset( aReason );
state.first->SetTransitions();
TOOL_BASE* tool = state.first;
tool->Reset( aReason );
if( tool->GetType() == INTERACTIVE )
static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
}
}
@ -476,6 +481,12 @@ void TOOL_MANAGER::ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandle
}
void TOOL_MANAGER::ClearTransitions( TOOL_BASE* aTool )
{
m_toolState[aTool]->transitions.clear();
}
void TOOL_MANAGER::RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc )
{
TOOL_STATE* st = m_toolState[aTool];
@ -705,7 +716,11 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState )
}
// Set transitions to be ready for future TOOL_EVENTs
aState->theTool->SetTransitions();
TOOL_BASE* tool = aState->theTool;
if( tool->GetType() == INTERACTIVE )
static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
m_viewControls->ForceCursorPosition( false );
return it;

2
include/tool/common_tools.h

@ -60,7 +60,7 @@ public:
int GridPreset( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
///> Pointer to the currently used edit frame.

7
include/tool/tool_base.h

@ -146,13 +146,6 @@ public:
return m_toolMgr;
}
/**
* Function SetTransitions()
* This method is meant to be overridden in order to specify handlers for events. It is called
* every time tool is reset or finished.
*/
virtual void SetTransitions() {};
TOOL_SETTINGS& GetSettings();
protected:

13
include/tool/tool_interactive.h

@ -114,7 +114,20 @@ protected:
const TOOL_EVENT evButtonDown(int aButton = BUT_ANY );
private:
/**
* This method is meant to be overridden in order to specify handlers for events. It is called
* every time tool is reset or finished.
*/
virtual void setTransitions() = 0;
/**
* Clears the current transition map and restores the default one created by setTransitions().
*/
void resetTransitions();
void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions );
friend class TOOL_MANAGER;
};
// hide TOOL_MANAGER implementation

6
include/tool/tool_manager.h

@ -307,6 +307,12 @@ public:
void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler,
const TOOL_EVENT_LIST& aConditions );
/**
* Clears the state transition map for a tool
* @param aTool is the tool that should have the transition map cleared.
*/
void ClearTransitions( TOOL_BASE* aTool );
void RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc );
/**

2
pcbnew/router/length_tuner_tool.cpp

@ -229,7 +229,7 @@ int LENGTH_TUNER_TOOL::TuneDiffPairSkew( const TOOL_EVENT& aEvent )
}
void LENGTH_TUNER_TOOL::SetTransitions()
void LENGTH_TUNER_TOOL::setTransitions()
{
Go( &LENGTH_TUNER_TOOL::routerOptionsDialog, ACT_RouterOptions.MakeEvent() );
Go( &LENGTH_TUNER_TOOL::meanderSettingsDialog, ACT_Settings.MakeEvent() );

2
pcbnew/router/length_tuner_tool.h

@ -40,7 +40,7 @@ public:
int TuneDiffPair( const TOOL_EVENT& aEvent );
int TuneDiffPairSkew( const TOOL_EVENT& aEvent );
void SetTransitions() override;
void setTransitions() override;
private:
void performTuning();

2
pcbnew/router/router_tool.cpp

@ -788,7 +788,7 @@ int ROUTER_TOOL::SettingsDialog( const TOOL_EVENT& aEvent )
}
void ROUTER_TOOL::SetTransitions()
void ROUTER_TOOL::setTransitions()
{
Go( &ROUTER_TOOL::RouteSingleTrace, PCB_ACTIONS::routerActivateSingle.MakeEvent() );
Go( &ROUTER_TOOL::RouteDiffPair, PCB_ACTIONS::routerActivateDiffPair.MakeEvent() );

2
pcbnew/router/router_tool.h

@ -43,7 +43,7 @@ public:
int SettingsDialog( const TOOL_EVENT& aEvent );
int CustomTrackWidthDialog( const TOOL_EVENT& aEvent );
void SetTransitions() override;
void setTransitions() override;
private:
int mainLoop( PNS::ROUTER_MODE aMode );

2
pcbnew/tools/drawing_tool.cpp

@ -1528,7 +1528,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
}
void DRAWING_TOOL::SetTransitions()
void DRAWING_TOOL::setTransitions()
{
Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() );
Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() );

2
pcbnew/tools/drawing_tool.h

@ -177,7 +177,7 @@ public:
int SetAnchor( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:

2
pcbnew/tools/edit_tool.cpp

@ -1124,7 +1124,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
}
void EDIT_TOOL::SetTransitions()
void EDIT_TOOL::setTransitions()
{
Go( &EDIT_TOOL::Main, PCB_ACTIONS::editActivate.MakeEvent() );
Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );

2
pcbnew/tools/edit_tool.h

@ -129,7 +129,7 @@ public:
int MeasureTool( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
///> Selection tool used for obtaining selected items

2
pcbnew/tools/microwave_tool.cpp

@ -391,7 +391,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
}
void MICROWAVE_TOOL::SetTransitions()
void MICROWAVE_TOOL::setTransitions()
{
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateGap.MakeEvent() );
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateStub.MakeEvent() );

2
pcbnew/tools/microwave_tool.h

@ -47,7 +47,7 @@ public:
bool Init() override;
///> Bind handlers to corresponding TOOL_ACTIONs
void SetTransitions() override;
void setTransitions() override;
private:

2
pcbnew/tools/module_editor_tools.cpp

@ -512,7 +512,7 @@ int MODULE_EDITOR_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent )
}
void MODULE_EDITOR_TOOLS::SetTransitions()
void MODULE_EDITOR_TOOLS::setTransitions()
{
Go( &MODULE_EDITOR_TOOLS::PlacePad, PCB_ACTIONS::placePad.MakeEvent() );
Go( &MODULE_EDITOR_TOOLS::EnumeratePads, PCB_ACTIONS::enumeratePads.MakeEvent() );

2
pcbnew/tools/module_editor_tools.h

@ -97,7 +97,7 @@ public:
int ModuleEdgeOutlines( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
};

2
pcbnew/tools/pad_tool.cpp

@ -384,7 +384,7 @@ int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent )
}
void PAD_TOOL::SetTransitions()
void PAD_TOOL::setTransitions()
{
Go( &PAD_TOOL::applyPadSettings, PCB_ACTIONS::applyPadSettings.MakeEvent() );
Go( &PAD_TOOL::copyPadSettings, PCB_ACTIONS::copyPadSettings.MakeEvent() );

2
pcbnew/tools/pad_tool.h

@ -47,7 +47,7 @@ public:
bool Init() override;
///> Bind handlers to corresponding TOOL_ACTIONs
void SetTransitions() override;
void setTransitions() override;
private:
///> Determine if there are any footprints on the board

2
pcbnew/tools/pcb_editor_control.cpp

@ -1140,7 +1140,7 @@ int PCB_EDITOR_CONTROL::UpdateSelectionRatsnest( const TOOL_EVENT& aEvent )
}
void PCB_EDITOR_CONTROL::SetTransitions()
void PCB_EDITOR_CONTROL::setTransitions()
{
// Track & via size control
Go( &PCB_EDITOR_CONTROL::TrackWidthInc, PCB_ACTIONS::trackWidthInc.MakeEvent() );

2
pcbnew/tools/pcb_editor_control.h

@ -109,7 +109,7 @@ public:
int ShowLocalRatsnest( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
///> Pointer to the currently used edit frame.

2
pcbnew/tools/pcbnew_control.cpp

@ -936,7 +936,7 @@ int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent )
}
void PCBNEW_CONTROL::SetTransitions()
void PCBNEW_CONTROL::setTransitions()
{
// Display modes
Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() );

2
pcbnew/tools/pcbnew_control.h

@ -84,7 +84,7 @@ public:
int ToBeDone( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
///> Pointer to the currently used edit frame.

2
pcbnew/tools/picker_tool.cpp

@ -89,7 +89,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
void PICKER_TOOL::SetTransitions()
void PICKER_TOOL::setTransitions()
{
Go( &PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() );
}

4
pcbnew/tools/picker_tool.h

@ -98,8 +98,8 @@ public:
m_clickHandler = aHandler;
}
///> @copydoc TOOL_INTERACTIVE::SetTransitions();
void SetTransitions() override;
///> @copydoc TOOL_INTERACTIVE::setTransitions();
void setTransitions() override;
private:
// Tool settings.

2
pcbnew/tools/placement_tool.cpp

@ -357,7 +357,7 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent )
}
void ALIGN_DISTRIBUTE_TOOL::SetTransitions()
void ALIGN_DISTRIBUTE_TOOL::setTransitions()
{
Go( &ALIGN_DISTRIBUTE_TOOL::AlignTop, PCB_ACTIONS::alignTop.MakeEvent() );
Go( &ALIGN_DISTRIBUTE_TOOL::AlignBottom, PCB_ACTIONS::alignBottom.MakeEvent() );

2
pcbnew/tools/placement_tool.h

@ -78,7 +78,7 @@ public:
int DistributeVertically( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
SELECTION_TOOL* m_selectionTool;

2
pcbnew/tools/point_editor.cpp

@ -737,7 +737,7 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const
}
void POINT_EDITOR::SetTransitions()
void POINT_EDITOR::setTransitions()
{
Go( &POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() );
Go( &POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() );

2
pcbnew/tools/point_editor.h

@ -57,7 +57,7 @@ public:
int OnSelectionChange( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
///> Selection tool used for obtaining selected items

2
pcbnew/tools/position_relative_tool.cpp

@ -187,7 +187,7 @@ void POSITION_RELATIVE_TOOL::UpdateAnchor( BOARD_ITEM* aItem )
}
void POSITION_RELATIVE_TOOL::SetTransitions()
void POSITION_RELATIVE_TOOL::setTransitions()
{
Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() );
Go( &POSITION_RELATIVE_TOOL::SelectPositionRelativeItem,

2
pcbnew/tools/position_relative_tool.h

@ -92,7 +92,7 @@ public:
void UpdateAnchor( BOARD_ITEM* aItem );
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
private:
DIALOG_POSITION_RELATIVE* m_position_relative_dialog;

2
pcbnew/tools/selection_tool.cpp

@ -594,7 +594,7 @@ bool SELECTION_TOOL::selectMultiple()
}
void SELECTION_TOOL::SetTransitions()
void SELECTION_TOOL::setTransitions()
{
Go( &SELECTION_TOOL::Main, PCB_ACTIONS::selectionActivate.MakeEvent() );
Go( &SELECTION_TOOL::CursorSelection, PCB_ACTIONS::selectionCursor.MakeEvent() );

2
pcbnew/tools/selection_tool.h

@ -133,7 +133,7 @@ public:
static const TOOL_EVENT ClearedEvent;
///> Sets up handlers for various events.
void SetTransitions() override;
void setTransitions() override;
///> Zooms the screen to center and fit the current selection.
void zoomFitSelection( void );

2
pcbnew/tools/zoom_tool.cpp

@ -134,7 +134,7 @@ bool ZOOM_TOOL::selectRegion()
}
void ZOOM_TOOL::SetTransitions()
void ZOOM_TOOL::setTransitions()
{
Go( &ZOOM_TOOL::Main, PCB_ACTIONS::zoomTool.MakeEvent() );
}

4
pcbnew/tools/zoom_tool.h

@ -37,8 +37,8 @@ public:
/// Main loop
int Main( const TOOL_EVENT& aEvent );
/// @copydoc TOOL_BASE::SetTransitions()
void SetTransitions() override;
/// @copydoc TOOL_BASE::setTransitions()
void setTransitions() override;
private:
bool selectRegion();

Loading…
Cancel
Save