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()
This commit is contained in:
Maciej Suminski 2017-07-31 14:30:51 +02:00
parent 9e385872a0
commit 76bd05a69b
37 changed files with 79 additions and 45 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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