Commit 22045b61 authored by Maciej Suminski's avatar Maciej Suminski

Converted tabs to spaces. Removed trailing whitespaces.

parent ac489ece
...@@ -78,21 +78,21 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -78,21 +78,21 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
/* Generic events for the Tool Dispatcher */ /* Generic events for the Tool Dispatcher */
Connect( wxEVT_MOTION, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOTION, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_LEFT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_LEFT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_LEFT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_LEFT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_RIGHT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_RIGHT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_RIGHT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_RIGHT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) );
Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
Connect( KiGfx::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE, Connect( KiGfx::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
m_refreshTimer.SetOwner( this ); m_refreshTimer.SetOwner( this );
Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
...@@ -171,7 +171,7 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) ...@@ -171,7 +171,7 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true ); m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true );
m_pendingRefresh = true; m_pendingRefresh = true;
} }
} }
void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
...@@ -223,13 +223,13 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) ...@@ -223,13 +223,13 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
{ {
if( !m_eventDispatcher ) if( !m_eventDispatcher )
{ {
aEvent.Skip(); aEvent.Skip();
return; return;
} }
else else
{ {
m_eventDispatcher->DispatchWxEvent( aEvent ); m_eventDispatcher->DispatchWxEvent( aEvent );
} }
......
...@@ -159,7 +159,6 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV ) ...@@ -159,7 +159,6 @@ void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
b = q; b = q;
break; break;
} }
} }
...@@ -168,7 +167,7 @@ COLOR4D& COLOR4D::Saturate( double aFactor ) ...@@ -168,7 +167,7 @@ COLOR4D& COLOR4D::Saturate( double aFactor )
double h, s, v; double h, s, v;
ToHSV( h, s, v ); ToHSV( h, s, v );
FromHSV( h, aFactor, 1.0 ); FromHSV( h, aFactor, 1.0 );
return *this; return *this;
} }
...@@ -127,7 +127,7 @@ void OPENGL_GAL::BeginDrawing() ...@@ -127,7 +127,7 @@ void OPENGL_GAL::BeginDrawing()
glViewport( 0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y ); glViewport( 0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y );
// Create the screen transformation // Create the screen transformation
glOrtho( 0, (GLint) screenSize.x, 0, (GLsizei) screenSize.y, glOrtho( 0, (GLint) screenSize.x, 0, (GLsizei) screenSize.y,
-depthRange.x, -depthRange.y ); -depthRange.x, -depthRange.y );
// Prepare rendering target buffers // Prepare rendering target buffers
......
...@@ -49,7 +49,7 @@ void strokedCircle( vec2 aCoord, float aRadius, float aWidth ) ...@@ -49,7 +49,7 @@ void strokedCircle( vec2 aCoord, float aRadius, float aWidth )
float innerRadius = aRadius - ( aWidth / 2 ); float innerRadius = aRadius - ( aWidth / 2 );
float relWidth = innerRadius / outerRadius; float relWidth = innerRadius / outerRadius;
if( ( dot( aCoord, aCoord ) < 1.0f ) && if( ( dot( aCoord, aCoord ) < 1.0f ) &&
( dot( aCoord, aCoord ) > relWidth * relWidth ) ) ( dot( aCoord, aCoord ) > relWidth * relWidth ) )
gl_FragColor = gl_Color; gl_FragColor = gl_Color;
else else
......
...@@ -42,23 +42,23 @@ void main() ...@@ -42,23 +42,23 @@ void main()
{ {
// Pass attributes to the fragment shader // Pass attributes to the fragment shader
shaderParams = attrShaderParams; shaderParams = attrShaderParams;
if( shaderParams[0] == SHADER_LINE ) if( shaderParams[0] == SHADER_LINE )
{ {
float lineWidth = shaderParams[3]; float lineWidth = shaderParams[3];
float worldScale = gl_ModelViewMatrix[0][0]; float worldScale = gl_ModelViewMatrix[0][0];
float scale; float scale;
// Make lines appear to be at least 1 pixel wide // Make lines appear to be at least 1 pixel wide
if( worldScale * lineWidth < MIN_WIDTH ) if( worldScale * lineWidth < MIN_WIDTH )
scale = MIN_WIDTH / ( worldScale * lineWidth ); scale = MIN_WIDTH / ( worldScale * lineWidth );
else else
scale = 1.0f; scale = 1.0f;
gl_Position = gl_ModelViewProjectionMatrix * gl_Position = gl_ModelViewProjectionMatrix *
( gl_Vertex + vec4( shaderParams.yz * scale, 0.0, 0.0 ) ); ( gl_Vertex + vec4( shaderParams.yz * scale, 0.0, 0.0 ) );
} }
else if( ( shaderParams[0] == SHADER_STROKED_CIRCLE ) || else if( ( shaderParams[0] == SHADER_STROKED_CIRCLE ) ||
( shaderParams[0] == SHADER_FILLED_CIRCLE ) ) ( shaderParams[0] == SHADER_FILLED_CIRCLE ) )
{ {
// Compute relative circle coordinates basing on indices // Compute relative circle coordinates basing on indices
...@@ -69,7 +69,7 @@ void main() ...@@ -69,7 +69,7 @@ void main()
circleCoords = vec2( sqrt( 3.0f ), -1.0f ); circleCoords = vec2( sqrt( 3.0f ), -1.0f );
else if( shaderParams[1] == 3.0f ) else if( shaderParams[1] == 3.0f )
circleCoords = vec2( 0.0f, 2.0f ); circleCoords = vec2( 0.0f, 2.0f );
// Semicircle // Semicircle
else if( shaderParams[1] == 4.0f ) else if( shaderParams[1] == 4.0f )
circleCoords = vec2( -3.0f / sqrt( 3.0f ), 0.0f ); circleCoords = vec2( -3.0f / sqrt( 3.0f ), 0.0f );
...@@ -81,7 +81,7 @@ void main() ...@@ -81,7 +81,7 @@ void main()
// Make the line appear to be at least 1 pixel wide // Make the line appear to be at least 1 pixel wide
float lineWidth = shaderParams[3]; float lineWidth = shaderParams[3];
float worldScale = gl_ModelViewMatrix[0][0]; float worldScale = gl_ModelViewMatrix[0][0];
// Make lines appear to be at least 1 pixel width // Make lines appear to be at least 1 pixel width
if( worldScale * lineWidth < MIN_WIDTH ) if( worldScale * lineWidth < MIN_WIDTH )
shaderParams[3] = shaderParams[3] / ( worldScale * lineWidth ); shaderParams[3] = shaderParams[3] / ( worldScale * lineWidth );
...@@ -93,7 +93,7 @@ void main() ...@@ -93,7 +93,7 @@ void main()
// Pass through the coordinates like in the fixed pipeline // Pass through the coordinates like in the fixed pipeline
gl_Position = ftransform(); gl_Position = ftransform();
} }
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
} }
...@@ -32,38 +32,38 @@ template<typename T> int sgn( T val ) { ...@@ -32,38 +32,38 @@ template<typename T> int sgn( T val ) {
bool SEG::PointCloserThan( const VECTOR2I& aP, int dist ) const bool SEG::PointCloserThan( const VECTOR2I& aP, int dist ) const
{ {
VECTOR2I d = b - a; VECTOR2I d = b - a;
ecoord dist_sq = (ecoord) dist * dist; ecoord dist_sq = (ecoord) dist * dist;
SEG::ecoord l_squared = d.Dot( d ); SEG::ecoord l_squared = d.Dot( d );
SEG::ecoord t = d.Dot( aP - a ); SEG::ecoord t = d.Dot( aP - a );
if( t <= 0 || !l_squared ) if( t <= 0 || !l_squared )
return ( aP - a ).SquaredEuclideanNorm() < dist_sq; return ( aP - a ).SquaredEuclideanNorm() < dist_sq;
else if( t >= l_squared ) else if( t >= l_squared )
return ( aP - b ).SquaredEuclideanNorm() < dist_sq; return ( aP - b ).SquaredEuclideanNorm() < dist_sq;
int dxdy = abs( d.x ) - abs( d.y ); int dxdy = abs( d.x ) - abs( d.y );
if( ( dxdy >= -1 && dxdy <= 1 ) || abs( d.x ) <= 1 || abs( d.y ) <= 1 ) if( ( dxdy >= -1 && dxdy <= 1 ) || abs( d.x ) <= 1 || abs( d.y ) <= 1 )
{ {
int ca = -sgn( d.y ); int ca = -sgn( d.y );
int cb = sgn( d.x ); int cb = sgn( d.x );
int cc = -ca * a.x - cb * a.y; int cc = -ca * a.x - cb * a.y;
ecoord num = ca * aP.x + cb * aP.y + cc; ecoord num = ca * aP.x + cb * aP.y + cc;
num *= num; num *= num;
if( ca && cb ) if( ca && cb )
num >>= 1; num >>= 1;
if( num > ( dist_sq + 100 ) ) if( num > ( dist_sq + 100 ) )
return false; return false;
else if( num < ( dist_sq - 100 ) ) else if( num < ( dist_sq - 100 ) )
return true; return true;
} }
VECTOR2I nearest; VECTOR2I nearest;
nearest.x = a.x + rescale( t, (ecoord)d.x, l_squared ); nearest.x = a.x + rescale( t, (ecoord)d.x, l_squared );
nearest.y = a.y + rescale( t, (ecoord)d.y, l_squared ); nearest.y = a.y + rescale( t, (ecoord)d.y, l_squared );
...@@ -71,7 +71,7 @@ bool SEG::PointCloserThan( const VECTOR2I& aP, int dist ) const ...@@ -71,7 +71,7 @@ bool SEG::PointCloserThan( const VECTOR2I& aP, int dist ) const
} }
SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const
{ {
// fixme: rather inefficient.... // fixme: rather inefficient....
if( Intersect( aSeg ) ) if( Intersect( aSeg ) )
...@@ -91,62 +91,62 @@ SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const ...@@ -91,62 +91,62 @@ SEG::ecoord SEG::SquaredDistance( const SEG& aSeg ) const
return m; return m;
} }
OPT_VECTOR2I SEG::Intersect( const SEG& aSeg, bool aIgnoreEndpoints, bool aLines ) const OPT_VECTOR2I SEG::Intersect( const SEG& aSeg, bool aIgnoreEndpoints, bool aLines ) const
{ {
const VECTOR2I e ( b - a ); const VECTOR2I e ( b - a );
const VECTOR2I f ( aSeg.b - aSeg.a ); const VECTOR2I f ( aSeg.b - aSeg.a );
const VECTOR2I ac ( aSeg.a - a ); const VECTOR2I ac ( aSeg.a - a );
ecoord d = f.Cross( e ); ecoord d = f.Cross( e );
ecoord p = f.Cross( ac ); ecoord p = f.Cross( ac );
ecoord q = e.Cross( ac ); ecoord q = e.Cross( ac );
if( d == 0 ) if( d == 0 )
return OPT_VECTOR2I(); return OPT_VECTOR2I();
if ( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) ) if ( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) )
return OPT_VECTOR2I(); return OPT_VECTOR2I();
if ( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) ) if ( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) )
return OPT_VECTOR2I(); return OPT_VECTOR2I();
if ( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) ) if ( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) )
return OPT_VECTOR2I(); return OPT_VECTOR2I();
VECTOR2I ip( aSeg.a.x + rescale( q, (ecoord)f.x, d ), VECTOR2I ip( aSeg.a.x + rescale( q, (ecoord)f.x, d ),
aSeg.a.y + rescale( q, (ecoord)f.y, d ) ); aSeg.a.y + rescale( q, (ecoord)f.y, d ) );
return ip; return ip;
} }
bool SEG::ccw( const VECTOR2I& a, const VECTOR2I& b, const VECTOR2I& c ) const bool SEG::ccw( const VECTOR2I& a, const VECTOR2I& b, const VECTOR2I& c ) const
{ {
return (ecoord)( c.y - a.y ) * ( b.x - a.x ) > (ecoord)( b.y - a.y ) * ( c.x - a.x ); return (ecoord)( c.y - a.y ) * ( b.x - a.x ) > (ecoord)( b.y - a.y ) * ( c.x - a.x );
} }
bool SEG::Collide( const SEG& aSeg, int aClearance ) const bool SEG::Collide( const SEG& aSeg, int aClearance ) const
{ {
// check for intersection // check for intersection
// fixme: move to a method // fixme: move to a method
if( ccw( a, aSeg.a, aSeg.b ) != ccw( b, aSeg.a, aSeg.b ) && if( ccw( a, aSeg.a, aSeg.b ) != ccw( b, aSeg.a, aSeg.b ) &&
ccw( a, b, aSeg.a ) != ccw( a, b, aSeg.b ) ) ccw( a, b, aSeg.a ) != ccw( a, b, aSeg.b ) )
return true; return true;
#define CHK(_seg, _pt) \ #define CHK(_seg, _pt) \
if( (_seg).PointCloserThan (_pt, aClearance ) ) return true; if( (_seg).PointCloserThan (_pt, aClearance ) ) return true;
CHK( *this, aSeg.a ); CHK( *this, aSeg.a );
CHK( *this, aSeg.b ); CHK( *this, aSeg.b );
CHK( aSeg, a ); CHK( aSeg, a );
CHK( aSeg, b ); CHK( aSeg, b );
#undef CHK #undef CHK
return false; return false;
} }
bool SEG::Contains( const VECTOR2I& aP ) const bool SEG::Contains( const VECTOR2I& aP ) const
{ {
return PointCloserThan( aP, 1 ); return PointCloserThan( aP, 1 );
} }
This diff is collapsed.
This diff is collapsed.
/* /*
Boost::Context assembly wrapper - done to avoid compiling the whole boost binary library Boost::Context assembly wrapper - done to avoid compiling the whole boost binary library
which may be unpleasant, in particular under Windows (we don't support VC++, while boost::context which may be unpleasant, in particular under Windows (we don't support VC++, while boost::context
does not support mingw */ does not support mingw */
#ifdef __APPLE__ #ifdef __APPLE__
......
...@@ -9,39 +9,39 @@ ...@@ -9,39 +9,39 @@
.align 2 .align 2
_make_fcontext: _make_fcontext:
mov 0x4(%esp),%eax mov 0x4(%esp),%eax
lea -0x34(%eax),%eax lea -0x34(%eax),%eax
and $0xfffffff0,%eax and $0xfffffff0,%eax
mov 0x4(%esp),%ecx mov 0x4(%esp),%ecx
mov %ecx,0x18(%eax) mov %ecx,0x18(%eax)
mov 0x8(%esp),%edx mov 0x8(%esp),%edx
mov %edx,0x1c(%eax) mov %edx,0x1c(%eax)
neg %edx neg %edx
lea (%edx,%ecx,1),%ecx lea (%edx,%ecx,1),%ecx
mov %ecx,0x20(%eax) mov %ecx,0x20(%eax)
mov 0xc(%esp),%ecx mov 0xc(%esp),%ecx
mov %ecx,0x14(%eax) mov %ecx,0x14(%eax)
stmxcsr 0x2c(%eax) stmxcsr 0x2c(%eax)
fnstcw 0x30(%eax) fnstcw 0x30(%eax)
lea -0x1c(%eax),%edx lea -0x1c(%eax),%edx
mov %edx,0x10(%eax) mov %edx,0x10(%eax)
mov $0x0,%ecx mov $0x0,%ecx
mov %ecx,(%edx) mov %ecx,(%edx)
mov %fs:0x18,%ecx mov %fs:0x18,%ecx
mov (%ecx),%edx mov (%ecx),%edx
inc %edx inc %edx
je _make_fcontext+0x4c // <_make_fcontext+0x4c> je _make_fcontext+0x4c // <_make_fcontext+0x4c>
dec %edx dec %edx
xchg %edx,%ecx xchg %edx,%ecx
jmp _make_fcontext+0x42 // <_make_fcontext+0x42> jmp _make_fcontext+0x42 // <_make_fcontext+0x42>
mov 0x4(%ecx),%ecx mov 0x4(%ecx),%ecx
mov 0x10(%eax),%edx mov 0x10(%eax),%edx
mov %ecx,0x18(%edx) mov %ecx,0x18(%edx)
mov $0xffffffff,%ecx mov $0xffffffff,%ecx
mov %ecx,0x14(%edx) mov %ecx,0x14(%edx)
lea 0x14(%edx),%ecx lea 0x14(%edx),%ecx
mov %ecx,0x24(%eax) mov %ecx,0x24(%eax)
ret ret
finish: finish:
xor %eax,%eax xor %eax,%eax
......
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
CONTEXT_MENU::CONTEXT_MENU() : CONTEXT_MENU::CONTEXT_MENU() :
m_titleSet( false ), m_handler( this ), m_tool( NULL ) m_titleSet( false ), m_handler( this ), m_tool( NULL )
{ {
m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ),
NULL, &m_handler ); NULL, &m_handler );
m_menu.Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), m_menu.Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ),
NULL, &m_handler ); NULL, &m_handler );
// Workaround for the case when mouse cursor never reaches menu (it hangs up tools using menu) // Workaround for the case when mouse cursor never reaches menu (it hangs up tools using menu)
wxMenuEvent menuEvent( wxEVT_MENU_HIGHLIGHT, -1, &m_menu ); wxMenuEvent menuEvent( wxEVT_MENU_HIGHLIGHT, -1, &m_menu );
m_menu.AddPendingEvent( menuEvent ); m_menu.AddPendingEvent( menuEvent );
} }
...@@ -72,16 +72,16 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) ...@@ -72,16 +72,16 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle )
// TODO handle an empty string (remove title and separator) // TODO handle an empty string (remove title and separator)
// Unfortunately wxMenu::SetTitle() does nothing.. // Unfortunately wxMenu::SetTitle() does nothing..
if( m_titleSet ) if( m_titleSet )
{ {
m_menu.FindItemByPosition( 0 )->SetItemLabel( aTitle ); m_menu.FindItemByPosition( 0 )->SetItemLabel( aTitle );
} }
else else
{ {
m_menu.InsertSeparator( 0 ); m_menu.InsertSeparator( 0 );
m_menu.Insert( 0, new wxMenuItem( &m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) ); m_menu.Insert( 0, new wxMenuItem( &m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) );
m_titleSet = true; m_titleSet = true;
} }
} }
...@@ -92,7 +92,7 @@ void CONTEXT_MENU::Add( const wxString& aLabel, int aId ) ...@@ -92,7 +92,7 @@ void CONTEXT_MENU::Add( const wxString& aLabel, int aId )
wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
"undefined behaviour" ) ); "undefined behaviour" ) );
#endif #endif
m_menu.Append( new wxMenuItem( &m_menu, aId, aLabel, wxEmptyString, wxITEM_NORMAL ) ); m_menu.Append( new wxMenuItem( &m_menu, aId, aLabel, wxEmptyString, wxITEM_NORMAL ) );
} }
...@@ -104,7 +104,7 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) ...@@ -104,7 +104,7 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
if( aAction.HasHotKey() ) if( aAction.HasHotKey() )
menuEntry = wxString( ( aAction.GetMenuItem() + '\t' + getHotKeyDescription( aAction ) ).c_str(), menuEntry = wxString( ( aAction.GetMenuItem() + '\t' + getHotKeyDescription( aAction ) ).c_str(),
wxConvUTF8 ); wxConvUTF8 );
else else
menuEntry = wxString( aAction.GetMenuItem().c_str(), wxConvUTF8 ); menuEntry = wxString( aAction.GetMenuItem().c_str(), wxConvUTF8 );
...@@ -117,13 +117,13 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) ...@@ -117,13 +117,13 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
void CONTEXT_MENU::Clear() void CONTEXT_MENU::Clear()
{ {
m_titleSet = false; m_titleSet = false;
// Remove all the entries from context menu // Remove all the entries from context menu
for( unsigned i = 0; i < m_menu.GetMenuItemCount(); ++i ) for( unsigned i = 0; i < m_menu.GetMenuItemCount(); ++i )
m_menu.Destroy( m_menu.FindItemByPosition( 0 ) ); m_menu.Destroy( m_menu.FindItemByPosition( 0 ) );
m_toolActions.clear(); m_toolActions.clear();
} }
......
...@@ -27,23 +27,23 @@ ...@@ -27,23 +27,23 @@
KiGfx::VIEW* TOOL_BASE::getView() const KiGfx::VIEW* TOOL_BASE::getView() const
{ {
return m_toolMgr->GetView(); return m_toolMgr->GetView();
} }
KiGfx::VIEW_CONTROLS* TOOL_BASE::getViewControls() const KiGfx::VIEW_CONTROLS* TOOL_BASE::getViewControls() const
{ {
return m_toolMgr->GetViewControls(); return m_toolMgr->GetViewControls();
} }
wxWindow* TOOL_BASE::getEditFrameInt() const wxWindow* TOOL_BASE::getEditFrameInt() const
{ {
return m_toolMgr->GetEditFrame(); return m_toolMgr->GetEditFrame();
} }
EDA_ITEM* TOOL_BASE::getModelInt() const EDA_ITEM* TOOL_BASE::getModelInt() const
{ {
return m_toolMgr->GetModel(); return m_toolMgr->GetModel();
} }
This diff is collapsed.
...@@ -35,22 +35,22 @@ using namespace std; ...@@ -35,22 +35,22 @@ using namespace std;
struct FlagString struct FlagString
{ {
int flag; int flag;
std::string str; std::string str;
}; };
static const std::string flag2string( int flag, const FlagString* exps ) static const std::string flag2string( int flag, const FlagString* exps )
{ {
std::string rv; std::string rv;
for( int i = 0; exps[i].str.length(); i++ ) for( int i = 0; exps[i].str.length(); i++ )
{ {
if( exps[i].flag & flag ) if( exps[i].flag & flag )
rv += exps[i].str + " "; rv += exps[i].str + " ";
} }
return rv; return rv;
} }
...@@ -62,97 +62,97 @@ bool TOOL_EVENT::IsAction( const TOOL_ACTION* aAction ) const ...@@ -62,97 +62,97 @@ bool TOOL_EVENT::IsAction( const TOOL_ACTION* aAction ) const
const std::string TOOL_EVENT::Format() const const std::string TOOL_EVENT::Format() const
{ {
std::string ev; std::string ev;
const FlagString categories[] = { const FlagString categories[] = {
{ TC_Mouse, "mouse" }, { TC_Mouse, "mouse" },
{ TC_Keyboard, "keyboard" }, { TC_Keyboard, "keyboard" },
{ TC_Command, "command" }, { TC_Command, "command" },
{ TC_Message, "message" }, { TC_Message, "message" },
{ TC_View, "view" }, { TC_View, "view" },
{ 0, "" } { 0, "" }
}; };
const FlagString actions[] = { const FlagString actions[] = {
{ TA_MouseClick, "click" }, { TA_MouseClick, "click" },
{ TA_MouseUp, "button-up" }, { TA_MouseUp, "button-up" },
{ TA_MouseDown, "button-down" }, { TA_MouseDown, "button-down" },
{ TA_MouseDrag, "drag" }, { TA_MouseDrag, "drag" },
{ TA_MouseMotion, "motion" }, { TA_MouseMotion, "motion" },
{ TA_MouseWheel, "wheel" }, { TA_MouseWheel, "wheel" },
{ TA_KeyUp, "key-up" }, { TA_KeyUp, "key-up" },
{ TA_KeyDown, "key-down" }, { TA_KeyDown, "key-down" },
{ TA_ViewRefresh, "view-refresh" }, { TA_ViewRefresh, "view-refresh" },
{ TA_ViewZoom, "view-zoom" }, { TA_ViewZoom, "view-zoom" },
{ TA_ViewPan, "view-pan" }, { TA_ViewPan, "view-pan" },
{ TA_ViewDirty, "view-dirty" }, { TA_ViewDirty, "view-dirty" },
{ TA_ChangeLayer, "change-layer" }, { TA_ChangeLayer, "change-layer" },
{ TA_CancelTool, "cancel-tool" }, { TA_CancelTool, "cancel-tool" },
{ TA_ContextMenuUpdate, "context-menu-update" }, { TA_ContextMenuUpdate, "context-menu-update" },
{ TA_ContextMenuChoice, "context-menu-choice" }, { TA_ContextMenuChoice, "context-menu-choice" },
{ TA_Action, "action" }, { TA_Action, "action" },
{ 0, "" } { 0, "" }
}; };
const FlagString buttons[] = { const FlagString buttons[] = {
{ MB_None, "none" }, { MB_None, "none" },
{ MB_Left, "left" }, { MB_Left, "left" },
{ MB_Right, "right" }, { MB_Right, "right" },
{ MB_Middle, "middle" }, { MB_Middle, "middle" },
{ 0, "" } { 0, "" }
}; };
const FlagString modifiers[] = { const FlagString modifiers[] = {
{ MD_ModShift, "shift" }, { MD_ModShift, "shift" },
{ MD_ModCtrl, "ctrl" }, { MD_ModCtrl, "ctrl" },
{ MD_ModAlt, "alt" }, { MD_ModAlt, "alt" },
{ 0, "" } { 0, "" }
}; };
ev = "category: "; ev = "category: ";
ev += flag2string( m_category, categories ); ev += flag2string( m_category, categories );
ev += " action: "; ev += " action: ";
ev += flag2string( m_actions, actions ); ev += flag2string( m_actions, actions );
if( m_actions & TA_Mouse ) if( m_actions & TA_Mouse )
{ {
ev += " btns: "; ev += " btns: ";
ev += flag2string( m_mouseButtons, buttons ); ev += flag2string( m_mouseButtons, buttons );
} }
if( m_actions & TA_Keyboard ) if( m_actions & TA_Keyboard )
{ {
char tmp[128]; char tmp[128];
sprintf( tmp, "key: %d", m_keyCode ); sprintf( tmp, "key: %d", m_keyCode );
ev += tmp; ev += tmp;
} }
if( m_actions & ( TA_Mouse | TA_Keyboard ) ) if( m_actions & ( TA_Mouse | TA_Keyboard ) )
{ {
ev += " mods: "; ev += " mods: ";
ev += flag2string( m_modifiers, modifiers ); ev += flag2string( m_modifiers, modifiers );
} }
if( m_commandId ) if( m_commandId )
{ {
char tmp[128]; char tmp[128];
sprintf( tmp, "cmd-id: %d", *m_commandId ); sprintf( tmp, "cmd-id: %d", *m_commandId );
ev += tmp; ev += tmp;
} }
if( m_commandStr ) if( m_commandStr )
ev += "cmd-str: " + ( *m_commandStr ); ev += "cmd-str: " + ( *m_commandStr );
return ev; return ev;
} }
const std::string TOOL_EVENT_LIST::Format() const const std::string TOOL_EVENT_LIST::Format() const
{ {
string s; string s;
BOOST_FOREACH( TOOL_EVENT e, m_events )
s += e.Format() + " ";
BOOST_FOREACH( TOOL_EVENT e, m_events ) return s;
s += e.Format() + " ";
return s;
} }
...@@ -30,13 +30,13 @@ ...@@ -30,13 +30,13 @@
#include <tool/context_menu.h> #include <tool/context_menu.h>
TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) : TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) :
TOOL_BASE( TOOL_Interactive, aId, aName ) TOOL_BASE( TOOL_Interactive, aId, aName )
{}; {};
TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) : TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) :
TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName ) TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName )
{}; {};
TOOL_INTERACTIVE::~TOOL_INTERACTIVE() TOOL_INTERACTIVE::~TOOL_INTERACTIVE()
...@@ -46,18 +46,18 @@ TOOL_INTERACTIVE::~TOOL_INTERACTIVE() ...@@ -46,18 +46,18 @@ TOOL_INTERACTIVE::~TOOL_INTERACTIVE()
OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList ) OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList )
{ {
return m_toolMgr->ScheduleWait( this, aEventList ); return m_toolMgr->ScheduleWait( this, aEventList );
} }
void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions ) void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions )
{ {
m_toolMgr->ScheduleNextState( this, aState, aConditions ); m_toolMgr->ScheduleNextState( this, aState, aConditions );
} }
void TOOL_INTERACTIVE::SetContextMenu( CONTEXT_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger ) void TOOL_INTERACTIVE::SetContextMenu( CONTEXT_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger )
{ {
aMenu->setTool( this ); aMenu->setTool( this );
m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger ); m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
} }
This diff is collapsed.
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
{ {
return m_view; return m_view;
} }
/** /**
* Function GetViewControls() * Function GetViewControls()
* Returns a pointer to the VIEW_CONTROLS instance used in the panel. * Returns a pointer to the VIEW_CONTROLS instance used in the panel.
......
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
* Saturates the color to a given factor (in HSV model) * Saturates the color to a given factor (in HSV model)
*/ */
COLOR4D& Saturate( double aFactor ); COLOR4D& Saturate( double aFactor );
/** /**
* Function Brightened * Function Brightened
* Returns a color that is brighter by a given factor, without modifying object. * Returns a color that is brighter by a given factor, without modifying object.
......
...@@ -172,11 +172,11 @@ private: ...@@ -172,11 +172,11 @@ private:
void programInfo( GLuint aProgram ); void programInfo( GLuint aProgram );
/** /**
* @brief Get the shader information. * @brief Get the shader information.
* *
* @param aShader is the shader number. * @param aShader is the shader number.
*/ */
void shaderInfo( GLuint aShader ); void shaderInfo( GLuint aShader );
/** /**
* @brief Read the shader source file * @brief Read the shader source file
......
This diff is collapsed.
...@@ -36,109 +36,109 @@ ...@@ -36,109 +36,109 @@
*/ */
enum ShapeType { enum ShapeType {
SH_RECT = 0, ///> axis-aligned rectangle SH_RECT = 0, ///> axis-aligned rectangle
SH_SEGMENT, ///> line segment SH_SEGMENT, ///> line segment
SH_LINE_CHAIN, ///> line chain (polyline) SH_LINE_CHAIN, ///> line chain (polyline)
SH_CIRCLE ///> circle SH_CIRCLE ///> circle
}; };
/** /**
* Class SHAPE * Class SHAPE
* *
* Represents an abstract shape on 2D plane. * Represents an abstract shape on 2D plane.
*/ */
class SHAPE { class SHAPE {
protected: protected:
typedef VECTOR2I::extended_type ecoord; typedef VECTOR2I::extended_type ecoord;
public: public:
/** /**
* Constructor * Constructor
* *
* Creates an empty shape of type aType * Creates an empty shape of type aType
*/ */
SHAPE ( ShapeType aType ) : m_type( aType ) { }; SHAPE ( ShapeType aType ) : m_type( aType ) { };
// Destructor // Destructor
virtual ~SHAPE() {}; virtual ~SHAPE() {};
/** /**
* Function Type() * Function Type()
* *
* Returns the type of the shape. * Returns the type of the shape.
* @retval the type * @retval the type
*/ */
ShapeType Type() const { return m_type; } ShapeType Type() const { return m_type; }
/** /**
* Function Clone() * Function Clone()
* *
* Returns a dynamically allocated copy of the shape * Returns a dynamically allocated copy of the shape
* @retval copy of the shape * @retval copy of the shape
*/ */
virtual SHAPE* Clone() const { virtual SHAPE* Clone() const {
assert( false ); assert( false );
return NULL; return NULL;
}; };
/** /**
* Function Collide() * Function Collide()
* *
* Checks if the boundary of shape (this) lies closer to the point aP than aClearance, indicating * Checks if the boundary of shape (this) lies closer to the point aP than aClearance, indicating
* a collision. * a collision.
* @return true, if there is a collision. * @return true, if there is a collision.
*/ */
virtual bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const virtual bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const
{ {
return Collide( SEG( aP, aP ), aClearance ); return Collide( SEG( aP, aP ), aClearance );
} }
/** /**
* Function Collide() * Function Collide()
* *
* Checks if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating * Checks if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating
* a collision. * a collision.
* @param aShape shape to check collision against * @param aShape shape to check collision against
* @param aClearance minimum clearance * @param aClearance minimum clearance
* @param aMTV minimum translation vector * @param aMTV minimum translation vector
* @return true, if there is a collision. * @return true, if there is a collision.
*/ */
virtual bool Collide( const SHAPE* aShape, int aClerance, VECTOR2I& aMTV ) const; virtual bool Collide( const SHAPE* aShape, int aClerance, VECTOR2I& aMTV ) const;
virtual bool Collide( const SHAPE* aShape, int aClerance = 0 ) const; virtual bool Collide( const SHAPE* aShape, int aClerance = 0 ) const;
/** /**
* Function Collide() * Function Collide()
* *
* Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating * Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating
* a collision. * a collision.
* @return true, if there is a collision. * @return true, if there is a collision.
*/ */
virtual bool Collide( const SEG& aSeg, int aClearance = 0 ) const = 0; virtual bool Collide( const SEG& aSeg, int aClearance = 0 ) const = 0;
/** /**
* Function Collide() * Function Collide()
* *
* Computes a bounding box of the shape, with a margin of aClearance * Computes a bounding box of the shape, with a margin of aClearance
* a collision. * a collision.
* @aClearance how much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape. * @aClearance how much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
* @return the bounding box. * @return the bounding box.
*/ */
virtual const BOX2I BBox( int aClearance = 0 ) const = 0; virtual const BOX2I BBox( int aClearance = 0 ) const = 0;
/** /**
* Function Centre() * Function Centre()
* *
* Computes a center-of-mass of the shape * Computes a center-of-mass of the shape
* @return the center-of-mass point * @return the center-of-mass point
*/ */
virtual VECTOR2I Centre() const virtual VECTOR2I Centre() const
{ {
return BBox( 0 ).Centre(); // if nothing better is available.... return BBox( 0 ).Centre(); // if nothing better is available....
} }
private: private:
///> type of our shape ///> type of our shape
ShapeType m_type; ShapeType m_type;
}; };
......
...@@ -30,48 +30,48 @@ ...@@ -30,48 +30,48 @@
class SHAPE_CIRCLE : public SHAPE { class SHAPE_CIRCLE : public SHAPE {
public: public:
SHAPE_CIRCLE(): SHAPE_CIRCLE():
SHAPE( SH_CIRCLE ), m_radius( 0 ) {}; SHAPE( SH_CIRCLE ), m_radius( 0 ) {};
SHAPE_CIRCLE( const VECTOR2I& aCenter, int aRadius ):
SHAPE( SH_CIRCLE ), m_radius( aRadius ), m_center( aCenter ) {};
~SHAPE_CIRCLE() {}; SHAPE_CIRCLE( const VECTOR2I& aCenter, int aRadius ):
SHAPE( SH_CIRCLE ), m_radius( aRadius ), m_center( aCenter ) {};
const BOX2I BBox( int aClearance = 0 ) const ~SHAPE_CIRCLE() {};
{
const VECTOR2I rc( m_radius + aClearance, m_radius + aClearance );
return BOX2I( m_center - rc, rc * 2 );
}
bool Collide( const SEG& aSeg, int aClearance = 0 ) const const BOX2I BBox( int aClearance = 0 ) const
{ {
int rc = aClearance + m_radius; const VECTOR2I rc( m_radius + aClearance, m_radius + aClearance );
return aSeg.Distance( m_center ) <= rc; return BOX2I( m_center - rc, rc * 2 );
} }
void SetRadius( int aRadius ) bool Collide( const SEG& aSeg, int aClearance = 0 ) const
{ {
m_radius = aRadius; int rc = aClearance + m_radius;
} return aSeg.Distance( m_center ) <= rc;
}
void SetCenter( const VECTOR2I& aCenter ) void SetRadius( int aRadius )
{ {
m_center = aCenter; m_radius = aRadius;
} }
int GetRadius() const void SetCenter( const VECTOR2I& aCenter )
{ {
return m_radius; m_center = aCenter;
} }
const VECTOR2I GetCenter() const int GetRadius() const
{ {
return m_center; return m_radius;
} }
const VECTOR2I GetCenter() const
{
return m_center;
}
private: private:
int m_radius; int m_radius;
VECTOR2I m_center; VECTOR2I m_center;
}; };
#endif #endif
...@@ -276,11 +276,11 @@ class SHAPE_INDEX ...@@ -276,11 +276,11 @@ class SHAPE_INDEX
{ {
BOX2I box = aShape->BBox(); BOX2I box = aShape->BBox();
box.Inflate( aMinDistance ); box.Inflate( aMinDistance );
int min[2] = { box.GetX(), box.GetY() };
int max[2] = { box.GetRight(), box.GetBottom() };
return this->m_tree->Search( min, max, aVisitor ); int min[2] = { box.GetX(), box.GetY() };
int max[2] = { box.GetRight(), box.GetBottom() };
return this->m_tree->Search( min, max, aVisitor );
} }
/** /**
......
...@@ -29,205 +29,205 @@ ...@@ -29,205 +29,205 @@
template <class T> const SHAPE* defaultShapeFunctor( const T aItem ) template <class T> const SHAPE* defaultShapeFunctor( const T aItem )
{ {
return aItem->GetShape(); return aItem->GetShape();
} }
template <class T, const SHAPE* (ShapeFunctor)(const T) = defaultShapeFunctor<T> > template <class T, const SHAPE* (ShapeFunctor)(const T) = defaultShapeFunctor<T> >
class SHAPE_INDEX_LIST { class SHAPE_INDEX_LIST {
struct ShapeEntry { struct ShapeEntry {
ShapeEntry( T aParent ) ShapeEntry( T aParent )
{ {
shape = ShapeFunctor( aParent ); shape = ShapeFunctor( aParent );
bbox = shape->BBox( 0 ); bbox = shape->BBox( 0 );
parent = aParent; parent = aParent;
} }
~ShapeEntry() ~ShapeEntry()
{ {
} }
T parent; T parent;
const SHAPE* shape; const SHAPE* shape;
BOX2I bbox; BOX2I bbox;
}; };
typedef std::vector<ShapeEntry> ShapeVec; typedef std::vector<ShapeEntry> ShapeVec;
typedef typename std::vector<ShapeEntry>::iterator ShapeVecIter; typedef typename std::vector<ShapeEntry>::iterator ShapeVecIter;
public: public:
// "Normal" iterator interface, for STL algorithms. // "Normal" iterator interface, for STL algorithms.
class iterator { class iterator {
public: public:
iterator() {}; iterator() {};
iterator( ShapeVecIter aCurrent ) iterator( ShapeVecIter aCurrent )
: m_current( aCurrent ) {}; : m_current( aCurrent ) {};
iterator( const iterator &aB ) : iterator( const iterator &aB ) :
m_current( aB.m_current ) {}; m_current( aB.m_current ) {};
T operator*() const T operator*() const
{ {
return (*m_current).parent; return (*m_current).parent;
} }
void operator++() void operator++()
{ {
++m_current; ++m_current;
} }
iterator& operator++( int aDummy ) iterator& operator++( int aDummy )
{ {
++m_current; ++m_current;
return *this; return *this;
} }
bool operator==( const iterator& aRhs ) const bool operator==( const iterator& aRhs ) const
{ {
return m_current == aRhs.m_current; return m_current == aRhs.m_current;
} }
bool operator!=( const iterator& aRhs ) const bool operator!=( const iterator& aRhs ) const
{ {
return m_current != aRhs.m_current; return m_current != aRhs.m_current;
} }
const iterator& operator=( const iterator& aRhs ) const iterator& operator=( const iterator& aRhs )
{ {
m_current = aRhs.m_current; m_current = aRhs.m_current;
return *this; return *this;
} }
private: private:
ShapeVecIter m_current; ShapeVecIter m_current;
}; };
// "Query" iterator, for iterating over a set of spatially matching shapes. // "Query" iterator, for iterating over a set of spatially matching shapes.
class query_iterator { class query_iterator {
public: public:
query_iterator() query_iterator()
{ {
} }
query_iterator( ShapeVecIter aCurrent, ShapeVecIter aEnd, SHAPE* aShape, query_iterator( ShapeVecIter aCurrent, ShapeVecIter aEnd, SHAPE* aShape,
int aMinDistance, bool aExact ) : int aMinDistance, bool aExact ) :
m_end( aEnd ), m_end( aEnd ),
m_current( aCurrent ), m_current( aCurrent ),
m_shape( aShape ), m_shape( aShape ),
m_minDistance( aMinDistance ), m_minDistance( aMinDistance ),
m_exact( aExact ) m_exact( aExact )
{ {
if( aShape ) if( aShape )
{ {
m_refBBox = aShape->BBox(); m_refBBox = aShape->BBox();
next(); next();
} }
} }
query_iterator( const query_iterator &aB ) : query_iterator( const query_iterator &aB ) :
m_end( aB.m_end ), m_end( aB.m_end ),
m_current( aB.m_current ), m_current( aB.m_current ),
m_shape( aB.m_shape ), m_shape( aB.m_shape ),
m_minDistance( aB.m_minDistance ), m_minDistance( aB.m_minDistance ),
m_exact( aB.m_exact ), m_exact( aB.m_exact ),
m_refBBox( aB.m_refBBox ) m_refBBox( aB.m_refBBox )
{ {
} }
T operator*() const T operator*() const
{ {
return (*m_current).parent; return (*m_current).parent;
} }
query_iterator& operator++() query_iterator& operator++()
{ {
++m_current; ++m_current;
next(); next();
return *this; return *this;
} }
query_iterator& operator++( int aDummy ) query_iterator& operator++( int aDummy )
{ {
++m_current; ++m_current;
next(); next();
return *this; return *this;
} }
bool operator==( const query_iterator& aRhs ) const bool operator==( const query_iterator& aRhs ) const
{ {
return m_current == aRhs.m_current; return m_current == aRhs.m_current;
} }
bool operator!=( const query_iterator& aRhs ) const bool operator!=( const query_iterator& aRhs ) const
{ {
return m_current != aRhs.m_current; return m_current != aRhs.m_current;
} }
const query_iterator& operator=( const query_iterator& aRhs ) const query_iterator& operator=( const query_iterator& aRhs )
{ {
m_end = aRhs.m_end; m_end = aRhs.m_end;
m_current = aRhs.m_current; m_current = aRhs.m_current;
m_shape = aRhs.m_shape; m_shape = aRhs.m_shape;
m_minDistance = aRhs.m_minDistance; m_minDistance = aRhs.m_minDistance;
m_exact = aRhs.m_exact; m_exact = aRhs.m_exact;
m_refBBox = aRhs.m_refBBox; m_refBBox = aRhs.m_refBBox;
return *this; return *this;
} }
private: private:
void next() void next()
{ {
while( m_current != m_end ) while( m_current != m_end )
{ {
if( m_refBBox.Distance( m_current->bbox ) <= m_minDistance ) if( m_refBBox.Distance( m_current->bbox ) <= m_minDistance )
{ {
if( !m_exact || m_current->shape->Collide( m_shape, m_minDistance ) ) if( !m_exact || m_current->shape->Collide( m_shape, m_minDistance ) )
return; return;
} }
++m_current; ++m_current;
} }
} }
ShapeVecIter m_end; ShapeVecIter m_end;
ShapeVecIter m_current; ShapeVecIter m_current;
BOX2I m_refBBox; BOX2I m_refBBox;
bool m_exact; bool m_exact;
SHAPE *m_shape; SHAPE *m_shape;
int m_minDistance; int m_minDistance;
}; };
void Add( T aItem ) void Add( T aItem )
{ {
ShapeEntry s( aItem ); ShapeEntry s( aItem );
m_shapes.push_back(s); m_shapes.push_back(s);
} }
void Remove( const T aItem ) void Remove( const T aItem )
{ {
ShapeVecIter i; ShapeVecIter i;
for( i = m_shapes.begin(); i != m_shapes.end(); ++i ) for( i = m_shapes.begin(); i != m_shapes.end(); ++i )
{ {
if( i->parent == aItem ) if( i->parent == aItem )
break; break;
} }
if( i == m_shapes.end() ) if( i == m_shapes.end() )
return; return;
m_shapes.erase( i ); m_shapes.erase( i );
} }
int Size() const int Size() const
{ {
return m_shapes.size(); return m_shapes.size();
} }
template<class Visitor> template<class Visitor>
int Query( const SHAPE *aShape, int aMinDistance, Visitor &aV, bool aExact = true ) //const int Query( const SHAPE *aShape, int aMinDistance, Visitor &aV, bool aExact = true ) //const
{ {
ShapeVecIter i; ShapeVecIter i;
...@@ -251,33 +251,33 @@ public: ...@@ -251,33 +251,33 @@ public:
return n; return n;
} }
void Clear() void Clear()
{ {
m_shapes.clear(); m_shapes.clear();
} }
query_iterator qbegin( SHAPE* aShape, int aMinDistance, bool aExact ) query_iterator qbegin( SHAPE* aShape, int aMinDistance, bool aExact )
{ {
return query_iterator( m_shapes.begin(), m_shapes.end(), aShape, aMinDistance, aExact ); return query_iterator( m_shapes.begin(), m_shapes.end(), aShape, aMinDistance, aExact );
} }
const query_iterator qend() const query_iterator qend()
{ {
return query_iterator( m_shapes.end(), m_shapes.end(), NULL, 0, false ); return query_iterator( m_shapes.end(), m_shapes.end(), NULL, 0, false );
} }
iterator begin() iterator begin()
{ {
return iterator( m_shapes.begin() ); return iterator( m_shapes.begin() );
} }
iterator end() iterator end()
{ {
return iterator( m_shapes.end() ); return iterator( m_shapes.end() );
} }
private: private:
ShapeVec m_shapes; ShapeVec m_shapes;
}; };
#endif #endif
This diff is collapsed.
...@@ -31,114 +31,114 @@ ...@@ -31,114 +31,114 @@
#include <geometry/seg.h> #include <geometry/seg.h>
class SHAPE_RECT : public SHAPE { class SHAPE_RECT : public SHAPE {
public: public:
/** /**
* Constructor * Constructor
* Creates an empty (0-sized) rectangle * Creates an empty (0-sized) rectangle
*/ */
SHAPE_RECT() : SHAPE_RECT() :
SHAPE( SH_RECT ), m_w( 0 ), m_h( 0 ) {}; SHAPE( SH_RECT ), m_w( 0 ), m_h( 0 ) {};
/** /**
* Constructor * Constructor
* Creates a rectangle defined by top-left corner (aX0, aY0), width aW and height aH. * Creates a rectangle defined by top-left corner (aX0, aY0), width aW and height aH.
*/ */
SHAPE_RECT( int aX0, int aY0, int aW, int aH ) : SHAPE_RECT( int aX0, int aY0, int aW, int aH ) :
SHAPE( SH_RECT ), m_p0( aX0, aY0 ), m_w( aW ), m_h( aH ) {}; SHAPE( SH_RECT ), m_p0( aX0, aY0 ), m_w( aW ), m_h( aH ) {};
/** /**
* Constructor * Constructor
* Creates a rectangle defined by top-left corner aP0, width aW and height aH. * Creates a rectangle defined by top-left corner aP0, width aW and height aH.
*/ */
SHAPE_RECT( const VECTOR2I &aP0, int aW, int aH ) : SHAPE_RECT( const VECTOR2I &aP0, int aW, int aH ) :
SHAPE( SH_RECT ), m_p0( aP0 ), m_w( aW ), m_h( aH ) {}; SHAPE( SH_RECT ), m_p0( aP0 ), m_w( aW ), m_h( aH ) {};
/// @copydoc SHAPE::BBox() /// @copydoc SHAPE::BBox()
const BOX2I BBox(int aClearance = 0) const const BOX2I BBox(int aClearance = 0) const
{ {
BOX2I bbox( VECTOR2I( m_p0.x - aClearance, m_p0.y - aClearance ), BOX2I bbox( VECTOR2I( m_p0.x - aClearance, m_p0.y - aClearance ),
VECTOR2I( m_w + 2 * aClearance, m_h + 2 * aClearance ) ); VECTOR2I( m_w + 2 * aClearance, m_h + 2 * aClearance ) );
//printf("bb : %s\n",bbox.Format().c_str()); //printf("bb : %s\n",bbox.Format().c_str());
return bbox; return bbox;
} }
/** /**
* Function Diagonal() * Function Diagonal()
* *
* Returns length of the diagonal of the rectangle * Returns length of the diagonal of the rectangle
* @return diagonal length * @return diagonal length
*/ */
int Diagonal() const int Diagonal() const
{ {
return VECTOR2I( m_w, m_h ).EuclideanNorm(); return VECTOR2I( m_w, m_h ).EuclideanNorm();
} }
/// @copydoc SHAPE::Collide() /// @copydoc SHAPE::Collide()
bool Collide( const SEG& aSeg, int aClearance = 0 ) const bool Collide( const SEG& aSeg, int aClearance = 0 ) const
{ {
//VECTOR2I pmin = VECTOR2I(std::min(aSeg.a.x, aSeg.b.x), std::min(aSeg.a.y, aSeg.b.y)); //VECTOR2I pmin = VECTOR2I(std::min(aSeg.a.x, aSeg.b.x), std::min(aSeg.a.y, aSeg.b.y));
//VECTOR2I pmax = VECTOR2I(std::max(aSeg.a.x, aSeg.b.x), std::max(aSeg.a.y, aSeg.b.y)); //VECTOR2I pmax = VECTOR2I(std::max(aSeg.a.x, aSeg.b.x), std::max(aSeg.a.y, aSeg.b.y));
//BOX2I r(pmin, VECTOR2I(pmax.x - pmin.x, pmax.y - pmin.y)); //BOX2I r(pmin, VECTOR2I(pmax.x - pmin.x, pmax.y - pmin.y));
//if (BBox(0).SquaredDistance(r) > aClearance * aClearance) //if (BBox(0).SquaredDistance(r) > aClearance * aClearance)
// return false; // return false;
if( BBox( 0 ).Contains( aSeg.a ) || BBox( 0 ).Contains( aSeg.b ) ) if( BBox( 0 ).Contains( aSeg.a ) || BBox( 0 ).Contains( aSeg.b ) )
return true; return true;
VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ), VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y + m_h ), VECTOR2I( m_p0.x, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ), VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
VECTOR2I( m_p0.x + m_w, m_p0.y ), VECTOR2I( m_p0.x + m_w, m_p0.y ),
VECTOR2I( m_p0.x, m_p0.y ) }; VECTOR2I( m_p0.x, m_p0.y ) };
for( int i = 0; i < 4; i++ ) for( int i = 0; i < 4; i++ )
{ {
SEG s( vts[i], vts[i + 1], i ); SEG s( vts[i], vts[i + 1], i );
if( s.Distance( aSeg ) <= aClearance ) if( s.Distance( aSeg ) <= aClearance )
return true; return true;
} }
return false; return false;
}; };
/** /**
* Function GetPosition() * Function GetPosition()
* *
* @return top-left corner of the rectangle * @return top-left corner of the rectangle
*/ */
const VECTOR2I& GetPosition() const { return m_p0; } const VECTOR2I& GetPosition() const { return m_p0; }
/** /**
* Function GetSize() * Function GetSize()
* *
* @return size of the rectangle * @return size of the rectangle
*/ */
const VECTOR2I GetSize() const { return VECTOR2I( m_w, m_h ); } const VECTOR2I GetSize() const { return VECTOR2I( m_w, m_h ); }
/** /**
* Function GetWidth() * Function GetWidth()
* *
* @return width of the rectangle * @return width of the rectangle
*/ */
const int GetWidth() const { return m_w; } const int GetWidth() const { return m_w; }
/** /**
* Function GetHeight() * Function GetHeight()
* *
* @return height of the rectangle * @return height of the rectangle
*/ */
const int GetHeight() const { return m_h; } const int GetHeight() const { return m_h; }
private: private:
///> Top-left corner ///> Top-left corner
VECTOR2I m_p0; VECTOR2I m_p0;
///> Width ///> Width
int m_w; int m_w;
///> Height ///> Height
int m_h; int m_h;
}; };
#endif // __SHAPE_RECT_H #endif // __SHAPE_RECT_H
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
BOX2( const Vec& aPos, const Vec& aSize ) : BOX2( const Vec& aPos, const Vec& aSize ) :
m_Pos( aPos ), m_Pos( aPos ),
m_Size( aSize ) m_Size( aSize )
{ {
Normalize(); Normalize();
} }
...@@ -420,7 +420,7 @@ public: ...@@ -420,7 +420,7 @@ public:
ecoord_type y2 = m_Pos.y + m_Size.y; ecoord_type y2 = m_Pos.y + m_Size.y;
ecoord_type xdiff = std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type)0 ); ecoord_type xdiff = std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type)0 );
ecoord_type ydiff = std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type)0 ); ecoord_type ydiff = std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type)0 );
return xdiff * xdiff + ydiff * ydiff; return xdiff * xdiff + ydiff * ydiff;
} }
ecoord_type Distance( const Vec& aP ) const ecoord_type Distance( const Vec& aP ) const
......
...@@ -224,7 +224,7 @@ public: ...@@ -224,7 +224,7 @@ public:
/// Division with a factor /// Division with a factor
VECTOR2<T> operator/( const T& aFactor ) const; VECTOR2<T> operator/( const T& aFactor ) const;
/// Equality operator /// Equality operator
const bool operator==( const VECTOR2<T>& aVector ) const; const bool operator==( const VECTOR2<T>& aVector ) const;
......
...@@ -37,105 +37,105 @@ class TOOL_INTERACTIVE; ...@@ -37,105 +37,105 @@ class TOOL_INTERACTIVE;
* Defines the structure of a context (usually right-click) popup menu * Defines the structure of a context (usually right-click) popup menu
* for a given tool. * for a given tool.
*/ */
class CONTEXT_MENU class CONTEXT_MENU
{ {
public: public:
///> Default constructor ///> Default constructor
CONTEXT_MENU(); CONTEXT_MENU();
///> Copy constructor ///> Copy constructor
CONTEXT_MENU( const CONTEXT_MENU& aMenu ); CONTEXT_MENU( const CONTEXT_MENU& aMenu );
/** /**
* Function SetTitle() * Function SetTitle()
* Sets title for the context menu. The title is shown as a text label shown on the top of * Sets title for the context menu. The title is shown as a text label shown on the top of
* the menu. * the menu.
* @param aTitle is the new title. * @param aTitle is the new title.
*/ */
void SetTitle( const wxString& aTitle ); void SetTitle( const wxString& aTitle );
/** /**
* Function Add() * Function Add()
* Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is * Adds an entry to the menu. After highlighting/selecting the entry, a TOOL_EVENT command is
* sent that contains ID of the entry. * sent that contains ID of the entry.
* @param aLabel is the text label show in the menu. * @param aLabel is the text label show in the menu.
* @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry.
*/ */
void Add( const wxString& aLabel, int aId ); void Add( const wxString& aLabel, int aId );
/** /**
* Function Add() * Function Add()
* Adds an entry to the menu, basing on the TOOL_ACTION object. After selecting the entry, * Adds an entry to the menu, basing on the TOOL_ACTION object. After selecting the entry,
* a TOOL_EVENT command containing name of the action is sent. * a TOOL_EVENT command containing name of the action is sent.
* @param aAction is the action to be added to menu entry. * @param aAction is the action to be added to menu entry.
*/ */
void Add( const TOOL_ACTION& aAction ); void Add( const TOOL_ACTION& aAction );
/** /**
* Function Clear() * Function Clear()
* Removes all the entries from the menu (as well as its title). It leaves the menu in the * Removes all the entries from the menu (as well as its title). It leaves the menu in the
* initial state. * initial state.
*/ */
void Clear(); void Clear();
/** /**
* Function GetMenu() * Function GetMenu()
* Returns the instance of wxMenu object used to display the menu. * Returns the instance of wxMenu object used to display the menu.
*/ */
wxMenu* GetMenu() const wxMenu* GetMenu() const
{ {
return const_cast<wxMenu*>( &m_menu ); return const_cast<wxMenu*>( &m_menu );
} }
private: private:
///> Class CMEventHandler takes care of handling menu events. After reception of particular ///> Class CMEventHandler takes care of handling menu events. After reception of particular
///> events, it translates them to TOOL_EVENTs that may control tools. ///> events, it translates them to TOOL_EVENTs that may control tools.
class CMEventHandler : public wxEvtHandler class CMEventHandler : public wxEvtHandler
{ {
public: public:
///> Default constructor ///> Default constructor
///> aMenu is the CONTEXT_MENU instance for which it handles events. ///> aMenu is the CONTEXT_MENU instance for which it handles events.
CMEventHandler( CONTEXT_MENU* aMenu ) : m_menu( aMenu ) {}; CMEventHandler( CONTEXT_MENU* aMenu ) : m_menu( aMenu ) {};
///> Handler for menu events. ///> Handler for menu events.
void onEvent( wxEvent& aEvent ); void onEvent( wxEvent& aEvent );
private: private:
///> CONTEXT_MENU instance for which it handles events. ///> CONTEXT_MENU instance for which it handles events.
CONTEXT_MENU* m_menu; CONTEXT_MENU* m_menu;
}; };
friend class TOOL_INTERACTIVE; friend class TOOL_INTERACTIVE;
/** /**
* Function setTool() * Function setTool()
* Sets a tool that is the creator of the menu. * Sets a tool that is the creator of the menu.
* @param aTool is the tool that created the menu. * @param aTool is the tool that created the menu.
*/ */
void setTool( TOOL_INTERACTIVE* aTool ) void setTool( TOOL_INTERACTIVE* aTool )
{ {
m_tool = aTool; m_tool = aTool;
} }
/** /**
* Function getHotKeyDescription() * Function getHotKeyDescription()
* Returns a hot key in the string format accepted by wxMenu. * Returns a hot key in the string format accepted by wxMenu.
* @param aAction is the action with hot key to be translated.. * @param aAction is the action with hot key to be translated..
* @return Hot key in the string format compatible with wxMenu. * @return Hot key in the string format compatible with wxMenu.
*/ */
std::string getHotKeyDescription( const TOOL_ACTION& aAction ) const; std::string getHotKeyDescription( const TOOL_ACTION& aAction ) const;
///> Flag indicating that the menu title was set up. ///> Flag indicating that the menu title was set up.
bool m_titleSet; bool m_titleSet;
///> Instance of wxMenu used for display of the context menu. ///> Instance of wxMenu used for display of the context menu.
wxMenu m_menu; wxMenu m_menu;
///> Instance of menu event handler. ///> Instance of menu event handler.
CMEventHandler m_handler; CMEventHandler m_handler;
///> Creator of the menu ///> Creator of the menu
TOOL_INTERACTIVE* m_tool; TOOL_INTERACTIVE* m_tool;
/// Menu items with ID higher than that are considered TOOL_ACTIONs /// Menu items with ID higher than that are considered TOOL_ACTIONs
static const int m_actionId = 10000; static const int m_actionId = 10000;
......
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
/** /**
Class COROUNTINE. Class COROUNTINE.
Implements a coroutine. Wikipedia has a good explanation: Implements a coroutine. Wikipedia has a good explanation:
"Coroutines are computer program components that generalize subroutines to "Coroutines are computer program components that generalize subroutines to
allow multiple entry points for suspending and resuming execution at certain locations. allow multiple entry points for suspending and resuming execution at certain locations.
Coroutines are well-suited for implementing more familiar program components such as cooperative Coroutines are well-suited for implementing more familiar program components such as cooperative
tasks, exceptions, event loop, iterators, infinite lists and pipes." tasks, exceptions, event loop, iterators, infinite lists and pipes."
In other words, a coroutine can be considered a lightweight thread - which can be In other words, a coroutine can be considered a lightweight thread - which can be
preempted only when it deliberately yields the control to the caller. This way, preempted only when it deliberately yields the control to the caller. This way,
we avoid concurrency problems such as locking / race conditions. we avoid concurrency problems such as locking / race conditions.
...@@ -56,82 +56,82 @@ template<class ReturnType, class ArgType> ...@@ -56,82 +56,82 @@ template<class ReturnType, class ArgType>
class COROUTINE class COROUTINE
{ {
public: public:
COROUTINE() COROUTINE()
{ {
m_stackSize = c_defaultStackSize; m_stackSize = c_defaultStackSize;
m_stack = NULL; m_stack = NULL;
m_saved = NULL; m_saved = NULL;
} }
/** /**
* Constructor * Constructor
* Creates a coroutine from a member method of an object * Creates a coroutine from a member method of an object
*/ */
template<class T> template<class T>
COROUTINE( T* object, ReturnType (T::*ptr)( ArgType ) ) : COROUTINE( T* object, ReturnType (T::*ptr)( ArgType ) ) :
m_func( object, ptr ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize ) m_func( object, ptr ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize )
{ {
} }
/** /**
* Constructor * Constructor
* Creates a coroutine from a delegate object * Creates a coroutine from a delegate object
*/ */
COROUTINE( DELEGATE<ReturnType, ArgType> aEntry ) : COROUTINE( DELEGATE<ReturnType, ArgType> aEntry ) :
m_func( aEntry ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize ) m_func( aEntry ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize )
{}; {};
~COROUTINE() ~COROUTINE()
{ {
if( m_saved ) if( m_saved )
delete m_saved; delete m_saved;
if( m_stack ) if( m_stack )
free( m_stack ); free( m_stack );
} }
/** /**
* Function Yield() * Function Yield()
* *
* Stops execution of the coroutine and returns control to the caller. * Stops execution of the coroutine and returns control to the caller.
* After a yield, Call() or Resume() methods invoked by the caller will * After a yield, Call() or Resume() methods invoked by the caller will
* immediately return true, indicating that we are not done yet, just asleep. * immediately return true, indicating that we are not done yet, just asleep.
*/ */
void Yield() void Yield()
{ {
boost::context::jump_fcontext( m_self, m_saved, 0 ); boost::context::jump_fcontext( m_self, m_saved, 0 );
} }
/** /**
* Function Yield() * Function Yield()
* *
* Yield with a value - passes a value of given type to the caller. * Yield with a value - passes a value of given type to the caller.
* Useful for implementing generator objects. * Useful for implementing generator objects.
*/ */
void Yield( ReturnType& retVal ) void Yield( ReturnType& retVal )
{ {
m_retVal = retVal; m_retVal = retVal;
boost::context::jump_fcontext( m_self, m_saved, 0 ); boost::context::jump_fcontext( m_self, m_saved, 0 );
} }
/** /**
<F11>* Function SetEntry() <F11>* Function SetEntry()
* *
* Defines the entry point for the coroutine, if not set in the constructor. * Defines the entry point for the coroutine, if not set in the constructor.
*/ */
void SetEntry( DELEGATE<ReturnType, ArgType> aEntry ) void SetEntry( DELEGATE<ReturnType, ArgType> aEntry )
{ {
m_func = aEntry; m_func = aEntry;
} }
/* Function Call() /* Function Call()
* *
* Starts execution of a coroutine, passing args as its arguments. * Starts execution of a coroutine, passing args as its arguments.
* @return true, if the coroutine has yielded and false if it has finished its * @return true, if the coroutine has yielded and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Call( ArgType args ) bool Call( ArgType args )
{ {
// fixme: Clean up stack stuff. Add a guard // fixme: Clean up stack stuff. Add a guard
m_stack = malloc( c_defaultStackSize ); m_stack = malloc( c_defaultStackSize );
// align to 16 bytes // align to 16 bytes
...@@ -145,87 +145,87 @@ public: ...@@ -145,87 +145,87 @@ public:
// off we go! // off we go!
boost::context::jump_fcontext( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); boost::context::jump_fcontext( m_saved, m_self, reinterpret_cast<intptr_t>( this ) );
return m_running; return m_running;
} }
/** /**
* Function Resume() * Function Resume()
* *
* Resumes execution of a previously yielded coroutine. * Resumes execution of a previously yielded coroutine.
* @return true, if the coroutine has yielded again and false if it has finished its * @return true, if the coroutine has yielded again and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Resume() bool Resume()
{ {
boost::context::jump_fcontext( m_saved, m_self, 0 ); boost::context::jump_fcontext( m_saved, m_self, 0 );
return m_running; return m_running;
} }
/** /**
* Function ReturnValue() * Function ReturnValue()
* *
* Returns the yielded value (the argument Yield() was called with) * Returns the yielded value (the argument Yield() was called with)
*/ */
const ReturnType& ReturnValue() const const ReturnType& ReturnValue() const
{ {
return m_retVal; return m_retVal;
} }
/** /**
* Function Running() * Function Running()
* *
* @return true, if the coroutine is active * @return true, if the coroutine is active
*/ */
bool Running() const bool Running() const
{ {
return m_running; return m_running;
} }
private: private:
static const int c_defaultStackSize = 2000000; // fixme: make configurable static const int c_defaultStackSize = 2000000; // fixme: make configurable
/* real entry point of the coroutine */ /* real entry point of the coroutine */
static void callerStub( intptr_t data ) static void callerStub( intptr_t data )
{ {
// get pointer to self // get pointer to self
COROUTINE<ReturnType, ArgType>* cor = reinterpret_cast<COROUTINE<ReturnType, ArgType>*>( data ); COROUTINE<ReturnType, ArgType>* cor = reinterpret_cast<COROUTINE<ReturnType, ArgType>*>( data );
// call the coroutine method // call the coroutine method
cor->m_retVal = cor->m_func( *cor->m_args ); cor->m_retVal = cor->m_func( *cor->m_args );
cor->m_running = false; cor->m_running = false;
// go back to wherever we came from. // go back to wherever we came from.
boost::context::jump_fcontext( cor->m_self, cor->m_saved, 0 ); //reinterpret_cast<intptr_t>( this )); boost::context::jump_fcontext( cor->m_self, cor->m_saved, 0 ); //reinterpret_cast<intptr_t>( this ));
} }
template <typename T> struct strip_ref template <typename T> struct strip_ref
{ {
typedef T result; typedef T result;
}; };
template <typename T> struct strip_ref<T&> template <typename T> struct strip_ref<T&>
{ {
typedef T result; typedef T result;
}; };
DELEGATE<ReturnType, ArgType> m_func; DELEGATE<ReturnType, ArgType> m_func;
///< pointer to coroutine entry arguments. Stripped of references ///< pointer to coroutine entry arguments. Stripped of references
///< to avoid compiler errors. ///< to avoid compiler errors.
typename strip_ref<ArgType>::result* m_args; typename strip_ref<ArgType>::result* m_args;
ReturnType m_retVal; ReturnType m_retVal;
///< saved caller context ///< saved caller context
boost::context::fcontext_t* m_saved; boost::context::fcontext_t* m_saved;
///< saved coroutine context ///< saved coroutine context
boost::context::fcontext_t* m_self; boost::context::fcontext_t* m_self;
///< coroutine stack ///< coroutine stack
void* m_stack; void* m_stack;
size_t m_stackSize; size_t m_stackSize;
bool m_running; bool m_running;
}; };
#endif #endif
This diff is collapsed.
...@@ -9,40 +9,40 @@ typedef COROUTINE<int, int> MyCoroutine; ...@@ -9,40 +9,40 @@ typedef COROUTINE<int, int> MyCoroutine;
class MyClass { class MyClass {
public: public:
int CountTo(int n) int CountTo(int n)
{ {
printf("%s: Coroutine says hi. I will count from 1 to %d and yield each value.\n", __FUNCTION__, n); printf("%s: Coroutine says hi. I will count from 1 to %d and yield each value.\n", __FUNCTION__, n);
for(int i = 1; i <= n; i++) for(int i = 1; i <= n; i++)
{ {
printf("%s: Yielding %d\n", __FUNCTION__, i); printf("%s: Yielding %d\n", __FUNCTION__, i);
cofunc.Yield(i); cofunc.Yield(i);
} }
} }
void Run() void Run()
{ {
cofunc = MyCoroutine (this, &MyClass::CountTo); cofunc = MyCoroutine (this, &MyClass::CountTo);
printf("%s: Calling coroutine that will count from 1 to 5.\n", __FUNCTION__); printf("%s: Calling coroutine that will count from 1 to 5.\n", __FUNCTION__);
cofunc.Call(5); cofunc.Call(5);
while (cofunc.Running()) while (cofunc.Running())
{ {
printf("%s: Got value: %d\n", __FUNCTION__, cofunc.ReturnValue()); printf("%s: Got value: %d\n", __FUNCTION__, cofunc.ReturnValue());
cofunc.Resume(); cofunc.Resume();
} }
printf("%s: Done!\n", __FUNCTION__); printf("%s: Done!\n", __FUNCTION__);
} }
MyCoroutine cofunc; MyCoroutine cofunc;
}; };
main() main()
{ {
MyClass obj; MyClass obj;
obj.Run(); obj.Run();
return 0; return 0;
} }
This diff is collapsed.
This diff is collapsed.
...@@ -33,12 +33,12 @@ class TOOL_MANAGER; ...@@ -33,12 +33,12 @@ class TOOL_MANAGER;
class PCB_BASE_FRAME; class PCB_BASE_FRAME;
namespace KiGfx { namespace KiGfx {
class VIEW; class VIEW;
}; };
/** /**
* Class TOOL_DISPATCHER * Class TOOL_DISPATCHER
* *
* - takes wx events, * - takes wx events,
* - fixes all wx quirks (mouse warping, panning, ordering problems, etc) * - fixes all wx quirks (mouse warping, panning, ordering problems, etc)
* - translates coordinates to world space * - translates coordinates to world space
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File mode changed from 100755 to 100644
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment