Added some comments & asserts.

This commit is contained in:
Maciej Suminski 2013-12-03 15:17:43 +01:00
parent 08fd9d8cbd
commit bec2e9b178
5 changed files with 29 additions and 5 deletions

View File

@ -44,6 +44,8 @@ ACTION_MANAGER::~ACTION_MANAGER()
void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction )
{
assert( aAction->GetId() == -1 ); // Check if the TOOL_ACTION was not registered before
assert( m_actionNameIndex.find( aAction->m_name ) == m_actionNameIndex.end() );
assert( m_actionIdIndex.find( aAction->m_id ) == m_actionIdIndex.end() );
aAction->setId( MakeActionId( aAction->m_name ) );

View File

@ -120,6 +120,11 @@ TOOL_MANAGER::~TOOL_MANAGER()
void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
{
wxASSERT_MSG( m_toolNameIndex.find( aTool->GetName() ) == m_toolNameIndex.end(),
wxT( "Adding two tools with the same name may result in unexpected behaviour.") );
wxASSERT_MSG( m_toolIdIndex.find( aTool->GetId() ) == m_toolIdIndex.end(),
wxT( "Adding two tools with the same ID may result in unexpected behaviour.") );
TOOL_STATE* st = new TOOL_STATE;
st->theTool = aTool;
@ -227,7 +232,10 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
wxASSERT( aTool != NULL );
if( !isRegistered( aTool ) )
{
wxASSERT_MSG( false, wxT( "You cannot run unregistered tools" ) );
return false;
}
TOOL_STATE* state = m_toolState[aTool];
@ -334,10 +342,11 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
// Go() method that match the event.
if( st->transitions.size() )
{
BOOST_FOREACH( TRANSITION tr, st->transitions )
BOOST_FOREACH( TRANSITION& tr, st->transitions )
{
if( tr.first.Matches( aEvent ) )
{
// as the state changes, the transition table has to be set up again
st->transitions.clear();
// no tool context allocated yet? Create one.
@ -351,6 +360,9 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
if( !st->cofunc->Running() )
finishTool( st ); // The couroutine has finished immediately?
// there is no point in further checking, as transitions got cleared
break;
}
}
}
@ -406,8 +418,6 @@ void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
if( it != m_activeTools.end() )
m_activeTools.erase( it );
else
wxLogWarning( wxT( "Tried to finish inactive tool" ) );
aState->idle = true;
delete aState->cofunc;

View File

@ -321,6 +321,9 @@ public:
if( m_commandId && aEvent.m_commandId )
return *m_commandId == *aEvent.m_commandId;
// Command-type event has to contain either id or string
assert( false );
}
return true;

View File

@ -609,7 +609,7 @@ void PCB_BASE_FRAME::UseGalCanvas( bool aEnable )
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
m_toolManager->SetEnvironment( m_Pcb, m_galCanvas->GetView(),
m_galCanvas->GetViewControls(), this );
m_galCanvas->GetViewControls(), this );
ViewReloadBoard( m_Pcb );
}

View File

@ -68,7 +68,16 @@ public:
KIGFX::VIEW_GROUP* group;
/// Checks if there is anything selected
bool Empty() const { return items.empty(); }
bool Empty() const
{
return items.empty();
}
/// Returns the number of selected parts
int Size() const
{
return items.size();
}
};
/// @copydoc TOOL_INTERACTIVE::Reset()