Commit fca1ba67 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Virtual split of TRACK/VIA::HitTest

parent 7b4b3297
...@@ -1233,64 +1233,56 @@ void VIA::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -1233,64 +1233,56 @@ void VIA::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
bool TRACK::HitTest( const wxPoint& aPosition ) bool TRACK::HitTest( const wxPoint& aPosition )
{ {
int max_dist = m_Width >> 1; return TestSegmentHit( aPosition, m_Start, m_End, m_Width / 2 );
}
if( Type() == PCB_VIA_T ) bool VIA::HitTest( const wxPoint& aPosition )
{ {
// rel_pos is aPosition relative to m_Start (or the center of the via) int max_dist = m_Width / 2;
wxPoint rel_pos = aPosition - m_Start;
double dist = (double) rel_pos.x * rel_pos.x + (double) rel_pos.y * rel_pos.y;
return dist <= (double) max_dist * max_dist;
}
return TestSegmentHit( aPosition, m_Start, m_End, max_dist ); // rel_pos is aPosition relative to m_Start (or the center of the via)
wxPoint rel_pos = aPosition - m_Start;
double dist = (double) rel_pos.x * rel_pos.x + (double) rel_pos.y * rel_pos.y;
return dist <= (double) max_dist * max_dist;
} }
bool TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const bool TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
arect.Inflate( aAccuracy );
if( aContained )
/* Tracks are a special case:
* they are considered inside the rect if one end is inside the rect */
return arect.Contains( GetStart() ) || arect.Contains( GetEnd() );
else
return arect.Intersects( GetStart(), GetEnd() );
}
bool VIA::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
{ {
EDA_RECT box; EDA_RECT box;
EDA_RECT arect = aRect; EDA_RECT arect = aRect;
arect.Inflate( aAccuracy ); arect.Inflate( aAccuracy );
if( Type() == PCB_VIA_T ) box.SetOrigin( GetStart() );
{ box.Inflate( GetWidth() / 2 );
box.SetOrigin( GetStart() );
box.Inflate( GetWidth() >> 1 );
if(aContained) if( aContained )
return arect.Contains( box ); return arect.Contains( box );
else
return arect.Intersects( box );
}
else else
{ return arect.Intersects( box );
if( aContained )
// Tracks are a specila case:
// they are considered inside the rect if one end
// is inside the rect
return arect.Contains( GetStart() ) || arect.Contains( GetEnd() );
else
return arect.Intersects( GetStart(), GetEnd() );
}
} }
VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_NUM aLayer) VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_NUM aLayer)
{ {
for( TRACK *track = this; track; track = track->Next() ) for( VIA *via = GetFirstVia( this ); via; via = GetFirstVia( via->Next() ) )
{ {
if( track->Type() != PCB_VIA_T ) if( via->HitTest( aPosition ) &&
continue; !via->GetState( BUSY | IS_DELETED ) &&
((aLayer == UNDEFINED_LAYER) || (via->IsOnLayer( aLayer ))) )
if( !track->HitTest( aPosition ) ) return via;
continue;
if( track->GetState( BUSY | IS_DELETED ) )
continue;
if( (aLayer == UNDEFINED_LAYER) || (track->IsOnLayer( aLayer )) )
return static_cast<VIA *>( track );
} }
return NULL; return NULL;
...@@ -1299,22 +1291,12 @@ VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_NUM aLayer) ...@@ -1299,22 +1291,12 @@ VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_NUM aLayer)
VIA* TRACK::GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LAYER_MSK aLayerMask ) VIA* TRACK::GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LAYER_MSK aLayerMask )
{ {
for( TRACK *trace = this; trace; trace = trace->Next() ) for( VIA *via = GetFirstVia( this, aEndTrace ); via; via = GetFirstVia( via->Next() ) )
{ {
if( trace->Type() == PCB_VIA_T ) if( via->HitTest( aPosition ) &&
{ !via->GetState( BUSY | IS_DELETED ) &&
if( aPosition == trace->m_Start ) (aLayerMask & via->GetLayerMask()) )
{ return via;
if( trace->GetState( BUSY | IS_DELETED ) == 0 )
{
if( aLayerMask & trace->GetLayerMask() )
return static_cast<VIA*>( trace );
}
}
}
if( trace == aEndTrace )
break;
} }
return NULL; return NULL;
......
...@@ -228,7 +228,7 @@ public: ...@@ -228,7 +228,7 @@ public:
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
*/ */
bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const; virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
/** /**
* Function GetVia * Function GetVia
...@@ -401,6 +401,10 @@ public: ...@@ -401,6 +401,10 @@ public:
const wxPoint& GetPosition() const { return m_Start; } // was overload const wxPoint& GetPosition() const { return m_Start; } // was overload
void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload
virtual bool HitTest( const wxPoint& aPosition );
virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
wxString GetClass() const wxString GetClass() const
{ {
return wxT( "VIA" ); return wxT( "VIA" );
...@@ -477,7 +481,11 @@ inline VIA *GetFirstVia( TRACK *aTrk, const TRACK *aStopPoint = NULL ) ...@@ -477,7 +481,11 @@ inline VIA *GetFirstVia( TRACK *aTrk, const TRACK *aStopPoint = NULL )
while( aTrk && (aTrk != aStopPoint) && (aTrk->Type() != PCB_VIA_T) ) while( aTrk && (aTrk != aStopPoint) && (aTrk->Type() != PCB_VIA_T) )
aTrk = aTrk->Next(); aTrk = aTrk->Next();
return static_cast<VIA*>( aTrk ); // It could stop because of the stop point, not on a via
if( aTrk && (aTrk->Type() == PCB_VIA_T) )
return static_cast<VIA*>( aTrk );
else
return NULL;
} }
#endif /* CLASS_TRACK_H */ #endif /* CLASS_TRACK_H */
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