Commit 6b74b577 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Even more code comments and reformatting.

parent 3f320e4d
Loading
Loading
Loading
Loading
+49 −49
Original line number Diff line number Diff line
@@ -31,36 +31,36 @@

typedef VECTOR2I::extended_type ecoord;

static inline bool Collide( const SHAPE_CIRCLE& a, const SHAPE_CIRCLE& b, int clearance,
                            bool needMTV, VECTOR2I& aMTV )
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int aClearance,
                            bool aNeedMTV, VECTOR2I& aMTV )
{
	ecoord min_dist = clearance + a.GetRadius() + b.GetRadius();
	ecoord min_dist = aClearance + aA.GetRadius() + aB.GetRadius();
	ecoord min_dist_sq = min_dist * min_dist;
		
	const VECTOR2I delta = b.GetCenter() - a.GetCenter();
	const VECTOR2I delta = aB.GetCenter() - aA.GetCenter();

	ecoord dist_sq = delta.SquaredEuclideanNorm();

	if ( dist_sq >= min_dist_sq )
		return false;
	
	if ( needMTV )
	if ( aNeedMTV )
		aMTV = delta.Resize( sqrt ( abs( min_dist_sq - dist_sq ) ) + 1 );

	return true;
}

static inline  bool Collide( const SHAPE_RECT& a, const SHAPE_CIRCLE& b, int clearance,
                             bool needMTV, VECTOR2I& aMTV )
static inline  bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aClearance,
                             bool aNeedMTV, VECTOR2I& aMTV )
{
	const VECTOR2I c = b.GetCenter();
	const VECTOR2I p0 = a.GetPosition();
	const VECTOR2I size = a.GetSize();
	const ecoord r = b.GetRadius();
	const ecoord min_dist = clearance + r;
	const VECTOR2I c = aB.GetCenter();
	const VECTOR2I p0 = aA.GetPosition();
	const VECTOR2I size = aA.GetSize();
	const ecoord r = aB.GetRadius();
	const ecoord min_dist = aClearance + r;
	const ecoord min_dist_sq = min_dist * min_dist;

	if ( a.BBox( 0 ).Contains( c ) )
	if ( aA.BBox( 0 ).Contains( c ) )
		return true;
			
	const VECTOR2I vts[] = { 
@@ -86,7 +86,7 @@ static inline bool Collide( const SHAPE_RECT& a, const SHAPE_CIRCLE& b, int cle
		
			if( dist_sq < min_dist_sq )
			{
				if( !needMTV )
				if( !aNeedMTV )
					return true;
				else
				{
@@ -102,7 +102,7 @@ static inline bool Collide( const SHAPE_RECT& a, const SHAPE_CIRCLE& b, int cle

	VECTOR2I delta = c - nearest;

	if( !needMTV )
	if( !aNeedMTV )
		return true;

	if( inside )
@@ -114,12 +114,12 @@ static inline bool Collide( const SHAPE_RECT& a, const SHAPE_CIRCLE& b, int cle
}


static inline bool Collide( const SHAPE_CIRCLE& a, const SHAPE_LINE_CHAIN& b, int clearance,
                            bool needMTV, VECTOR2I& aMTV )
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
                            bool aNeedMTV, VECTOR2I& aMTV )
{
	for( int s = 0; s < b.SegmentCount(); s++ )
	for( int s = 0; s < aB.SegmentCount(); s++ )
	{
		if ( a.Collide( b.CSegment( s ), clearance ) )
		if ( aA.Collide( aB.CSegment( s ), aClearance ) )
			return true;
	}
	
@@ -127,23 +127,23 @@ static inline bool Collide( const SHAPE_CIRCLE& a, const SHAPE_LINE_CHAIN& b, in
}


static inline bool Collide( const SHAPE_LINE_CHAIN& a, const SHAPE_LINE_CHAIN& b, int clearance,
                            bool needMTV, VECTOR2I& aMTV )
static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
                            bool aNeedMTV, VECTOR2I& aMTV )
{
	for( int i = 0; i < b.SegmentCount(); i++ )
		if( a.Collide( b.CSegment(i), clearance ) )
	for( int i = 0; i < aB.SegmentCount(); i++ )
		if( aA.Collide( aB.CSegment(i), aClearance ) )
			return true;
	return false;
}


static inline bool Collide( const SHAPE_RECT& a, const SHAPE_LINE_CHAIN& b, int clearance,
                            bool needMTV, VECTOR2I& aMTV )
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
                            bool aNeedMTV, VECTOR2I& aMTV )
{
	for( int s = 0; s < b.SegmentCount(); s++ )
	for( int s = 0; s < aB.SegmentCount(); s++ )
	{
		SEG seg = b.CSegment( s );
			if( a.Collide( seg, clearance ) )
		SEG seg = aB.CSegment( s );
			if( aA.Collide( seg, aClearance ) )
				return true;
	}

@@ -151,58 +151,58 @@ static inline bool Collide( const SHAPE_RECT& a, const SHAPE_LINE_CHAIN& b, int
}


bool CollideShapes( const SHAPE* a, const SHAPE* b, int clearance, bool needMTV, VECTOR2I& aMTV )
bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
{
	switch( a->Type() )
	switch( aA->Type() )
	{
		case SH_RECT:
			switch( b->Type() )
			switch( aB->Type() )
			{
				case SH_CIRCLE:
					return Collide( *static_cast<const SHAPE_RECT*>( a ),
					        *static_cast<const SHAPE_CIRCLE*>( b ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_RECT*>( aA ),
					        *static_cast<const SHAPE_CIRCLE*>( aB ), aClearance, aNeedMTV, aMTV );

				case SH_LINE_CHAIN:
					return Collide( *static_cast<const SHAPE_RECT*>( a ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( b ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_RECT*>( aA ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( aB ), aClearance, aNeedMTV, aMTV );

				default:
					break;
			}

		case SH_CIRCLE:
			switch( b->Type() )
			switch( aB->Type() )
			{
				case SH_RECT:
					return Collide( *static_cast<const SHAPE_RECT*>( b ),
					        *static_cast<const SHAPE_CIRCLE*>( a ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_RECT*>( aB ),
					        *static_cast<const SHAPE_CIRCLE*>( aA ), aClearance, aNeedMTV, aMTV );

				case SH_CIRCLE:
					return Collide( *static_cast<const SHAPE_CIRCLE*>( a ),
					        *static_cast<const SHAPE_CIRCLE*>( b ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_CIRCLE*>( aA ),
					        *static_cast<const SHAPE_CIRCLE*>( aB ), aClearance, aNeedMTV, aMTV );

				case SH_LINE_CHAIN:
					return Collide( *static_cast<const SHAPE_CIRCLE*>( a ),
					        *static_cast<const SHAPE_LINE_CHAIN *>( b ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_CIRCLE*>( aA ),
					        *static_cast<const SHAPE_LINE_CHAIN *>( aB ), aClearance, aNeedMTV, aMTV );

				default:
					break;
			}

		case SH_LINE_CHAIN:
			switch( b->Type() )
			switch( aB->Type() )
			{
				case SH_RECT:
					return Collide( *static_cast<const SHAPE_RECT*>( b ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( a ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_RECT*>( aB ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( aA ), aClearance, aNeedMTV, aMTV );

				case SH_CIRCLE:
					return Collide( *static_cast<const SHAPE_CIRCLE*>( b ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( a ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_CIRCLE*>( aB ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( aA ), aClearance, aNeedMTV, aMTV );

				case SH_LINE_CHAIN:
					return Collide( *static_cast<const SHAPE_LINE_CHAIN*>( a ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( b ), clearance, needMTV, aMTV );
					return Collide( *static_cast<const SHAPE_LINE_CHAIN*>( aA ),
					        *static_cast<const SHAPE_LINE_CHAIN*>( aB ), aClearance, aNeedMTV, aMTV );

				default:
					break;
+2 −1
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const

void ACTION_MANAGER::runAction( const TOOL_ACTION* aAction ) const
{
    TOOL_EVENT event = aAction->GetEvent();
    TOOL_EVENT event = aAction->MakeEvent();

    m_toolMgr->ProcessEvent( event );
}
+9 −5
Original line number Diff line number Diff line
@@ -151,24 +151,28 @@ void CONTEXT_MENU::CMEventHandler::onEvent( wxEvent& aEvent )
    TOOL_EVENT evt;
    wxEventType type = aEvent.GetEventType();

    // When the currently chosen item in the menu is changed, an update event is issued.
    // For example, the selection tool can use this to dynamically highlight the current item
    // from selection clarification popup.
    if( type == wxEVT_MENU_HIGHLIGHT )
        evt = TOOL_EVENT( TC_Command, TA_ContextMenuUpdate, aEvent.GetId() );

    // One of menu entries was selected..
    else if( type == wxEVT_COMMAND_MENU_SELECTED )
    {
        if( aEvent.GetId() > m_actionId )
        {
            // Handling TOOL_ACTIONs
        // Check if there is a TOOL_ACTION for the given ID
        if( m_menu->m_toolActions.count( aEvent.GetId() ) == 1 )
                evt = m_menu->m_toolActions[aEvent.GetId()]->GetEvent();
        {
            evt = m_menu->m_toolActions[aEvent.GetId()]->MakeEvent();
        }
        else
        {
            // Handling common menu entries
            // Handling non-action menu entries (e.g. items in clarification list)
            evt = TOOL_EVENT( TC_Command, TA_ContextMenuChoice, aEvent.GetId() );
        }
    }

    // forward the action/update event to the TOOL_MANAGER
    if( m_menu->m_tool )
        m_menu->m_tool->GetManager()->ProcessEvent( evt );
}
+7 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@

using boost::optional;

///> Stores information about a mouse button state
struct TOOL_DISPATCHER::ButtonState
{
	ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent,
@@ -217,6 +218,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
	        type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
	        type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP ||
	        type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ||
	        // Event issued whem mouse retains position in screen coordinates,
	        // but changes in world coordinates (eg. autopanning)
	        type == KiGfx::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE )
	{
        VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetCursorPosition();
@@ -247,7 +250,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )

        if( type == wxEVT_KEY_UP )
        {
            if( key == WXK_ESCAPE )
            if( key == WXK_ESCAPE )     // ESC is the special key for cancelling tools
                evt = TOOL_EVENT( TC_Command, TA_CancelTool );
            else
                evt = TOOL_EVENT( TC_Keyboard, TA_KeyUp, key | mods );
@@ -261,6 +264,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
	if( evt )
		m_toolMgr->ProcessEvent( *evt );

	// pass the event to the GUI, it might still be interested in it
	aEvent.Skip();
}

@@ -270,6 +274,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( const wxCommandEvent& aEvent )
	bool activateTool = false;
	std::string toolName;
	
	// fixme: use TOOL_ACTIONs here
	switch( aEvent.GetId() )
	{
		case ID_PNS_ROUTER_TOOL:
@@ -282,6 +287,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( const wxCommandEvent& aEvent )
			break;
	}

	// do nothing if the legacy view is active
	if( activateTool && m_editFrame->IsGalCanvasActive() )
		m_toolMgr->InvokeTool( toolName );
}
+7 −2
Original line number Diff line number Diff line
@@ -25,9 +25,8 @@
#include <cstring>
#include <string>

//#include <base_struct.h>

#include <tool/tool_event.h>
#include <tool/tool_action.h>
#include <tool/tool_manager.h>

#include <boost/foreach.hpp>
@@ -55,6 +54,12 @@ static const std::string flag2string( int flag, const FlagString* exps )
}


bool TOOL_EVENT::IsAction( const TOOL_ACTION* aAction ) const
{
    return Matches( aAction->MakeEvent() );
}


const std::string TOOL_EVENT::Format() const
{
	std::string ev;
Loading