2009-11-09 14:00:22 +00:00
|
|
|
/************************************************/
|
|
|
|
/* Locate items at the current cursor position. */
|
|
|
|
/************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "pcbnew.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "gerbview.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
int ux0, uy0, dx, dy, spot_cX, spot_cY;
|
|
|
|
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
static TRACK* Locate_Zone( TRACK* start_adresse, int layer, int typeloc );
|
|
|
|
static TRACK* Locate_Zone( TRACK* start_adresse, wxPoint ref, int layer );
|
2009-11-09 14:00:22 +00:00
|
|
|
static TRACK* Locate_Pistes( TRACK* start_adresse,
|
|
|
|
int Layer,
|
|
|
|
int typeloc );
|
|
|
|
static TRACK* Locate_Pistes( TRACK* start_adresse,
|
|
|
|
wxPoint ref,
|
|
|
|
int Layer );
|
2007-08-20 19:33:15 +00:00
|
|
|
static DRAWSEGMENT* Locate_Segment_Pcb( BOARD* Pcb, int typeloc );
|
|
|
|
static TEXTE_PCB* Locate_Texte_Pcb( TEXTE_PCB* pt_txt_pcb, int typeloc );
|
|
|
|
static int distance( int seuil );
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Macro for calculating the coordinates of the cursor position.
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2009-11-09 14:00:22 +00:00
|
|
|
#define SET_REF_POS( ref ) if( typeloc == CURSEUR_ON_GRILLE ) \
|
2007-08-20 19:33:15 +00:00
|
|
|
{ ref = ActiveScreen->m_Curseur; } \
|
|
|
|
else { ref = ActiveScreen->m_MousePosition; }
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Display the character of the localized STRUCTURE and return a pointer
|
|
|
|
* to it.
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2009-11-09 14:00:22 +00:00
|
|
|
BOARD_ITEM* WinEDA_GerberFrame::Locate( int typeloc )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
TEXTE_PCB* pt_texte_pcb;
|
|
|
|
TRACK* Track, * TrackLocate;
|
|
|
|
DRAWSEGMENT* DrawSegm;
|
|
|
|
int layer;
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Locate tracks and vias, with priority to vias */
|
2008-04-17 16:25:29 +00:00
|
|
|
layer = GetScreen()->m_Active_Layer;
|
2009-01-05 05:21:35 +00:00
|
|
|
Track = Locate_Pistes( GetBoard()->m_Track, -1, typeloc );
|
2007-08-20 19:33:15 +00:00
|
|
|
if( Track != NULL )
|
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
TrackLocate = Track;
|
|
|
|
|
|
|
|
while( ( TrackLocate = Locate_Pistes( TrackLocate,
|
|
|
|
layer, typeloc ) ) != NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
Track = TrackLocate;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( TrackLocate->Type() == TYPE_VIA )
|
2007-08-20 19:33:15 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
TrackLocate = TrackLocate->Next();
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
Track->DisplayInfo( this );
|
2007-08-20 19:33:15 +00:00
|
|
|
return Track;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
pt_texte_pcb = Locate_Texte_Pcb(
|
|
|
|
(TEXTE_PCB*) GetBoard()->m_Drawings.GetFirst(), typeloc );
|
|
|
|
|
|
|
|
if( pt_texte_pcb )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-04-17 08:51:02 +00:00
|
|
|
pt_texte_pcb->DisplayInfo( this );
|
2007-08-20 19:33:15 +00:00
|
|
|
return pt_texte_pcb;
|
|
|
|
}
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( ( DrawSegm = Locate_Segment_Pcb( GetBoard(), typeloc ) ) != NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
return DrawSegm;
|
|
|
|
}
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( ( TrackLocate = Locate_Zone( GetBoard()->m_Zone,
|
2009-11-09 14:00:22 +00:00
|
|
|
GetScreen()->m_Active_Layer,
|
|
|
|
typeloc ) ) != NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-04-17 08:51:02 +00:00
|
|
|
TrackLocate->DisplayInfo( this );
|
2007-08-20 19:33:15 +00:00
|
|
|
return TrackLocate;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Locate of segments of pcb edge or draw as active layer.
|
|
|
|
* Returns:
|
|
|
|
* Pointer to START segment if found
|
|
|
|
* NULL if nothing found
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2009-11-09 14:00:22 +00:00
|
|
|
DRAWSEGMENT* Locate_Segment_Pcb( BOARD* Pcb, int typeloc )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
BOARD_ITEM* PtStruct;
|
|
|
|
DRAWSEGMENT* pts;
|
|
|
|
wxPoint ref;
|
|
|
|
PCB_SCREEN* screen = (PCB_SCREEN*) ActiveScreen;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
SET_REF_POS( ref );
|
|
|
|
|
|
|
|
PtStruct = Pcb->m_Drawings;
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct->Type() != TYPE_DRAWSEGMENT )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
pts = (DRAWSEGMENT*) PtStruct;
|
2009-11-09 14:00:22 +00:00
|
|
|
ux0 = pts->m_Start.x;
|
|
|
|
uy0 = pts->m_Start.y;
|
|
|
|
|
|
|
|
dx = pts->m_End.x - ux0;
|
|
|
|
dy = pts->m_End.y - uy0;
|
|
|
|
spot_cX = ref.x - ux0;
|
|
|
|
spot_cY = ref.y - uy0;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pts->GetLayer() != screen->m_Active_Layer )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pts->m_Shape == S_CIRCLE ) || ( pts->m_Shape == S_ARC ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
int rayon, dist, StAngle, EndAngle, MouseAngle;
|
|
|
|
rayon = (int) hypot( (double) (dx), (double) (dy) );
|
|
|
|
dist = (int) hypot( (double) (spot_cX), (double) (spot_cY) );
|
2009-11-09 14:00:22 +00:00
|
|
|
if( abs( rayon - dist ) <= ( pts->m_Width / 2 ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( pts->m_Shape == S_CIRCLE )
|
|
|
|
return pts;
|
2009-11-09 14:00:22 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
MouseAngle = (int) ArcTangente( spot_cY, spot_cX );
|
|
|
|
StAngle = (int) ArcTangente( dy, dx );
|
|
|
|
EndAngle = StAngle + pts->m_Angle;
|
|
|
|
|
|
|
|
if( EndAngle > 3600 )
|
|
|
|
{
|
|
|
|
StAngle -= 3600; EndAngle -= 3600;
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( MouseAngle >= StAngle ) && ( MouseAngle <= EndAngle ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( distance( pts->m_Width / 2 ) )
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-09 14:00:22 +00:00
|
|
|
* 1 - Locate segment of track at current cursor position.
|
|
|
|
* 2 - Locate segment of track point by point.
|
|
|
|
* Ref_pX, ref_pY.r
|
2008-04-17 16:25:29 +00:00
|
|
|
*
|
2009-11-09 14:00:22 +00:00
|
|
|
* The search begins to address start_adresse
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
TRACK* Locate_Pistes( TRACK* start_adresse, int Layer, int typeloc )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
wxPoint ref;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
SET_REF_POS( ref );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
return Locate_Pistes( start_adresse, ref, Layer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
TRACK* Locate_Pistes( TRACK* start_adresse, wxPoint ref, int Layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
TRACK* Track;
|
|
|
|
int l_piste; /* half-width of the track */
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Track = start_adresse; Track != NULL; Track = Track->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( Track->GetState( BUSY | DELETED ) )
|
|
|
|
continue;
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Calculate coordinates of the test segment. */
|
|
|
|
l_piste = Track->m_Width >> 1;
|
|
|
|
ux0 = Track->m_Start.x;
|
|
|
|
uy0 = Track->m_Start.y;
|
|
|
|
dx = Track->m_End.x;
|
|
|
|
dy = Track->m_End.y;
|
|
|
|
|
|
|
|
dx -= ux0;
|
|
|
|
dy -= uy0;
|
|
|
|
spot_cX = ref.x - ux0;
|
|
|
|
spot_cY = ref.y - uy0;
|
|
|
|
|
|
|
|
if( Track->Type() == TYPE_VIA )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( abs( spot_cX ) <= l_piste ) && ( abs( spot_cY ) <=l_piste ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
return Track;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Layer >= 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Track->GetLayer() != Layer )
|
2009-11-09 14:00:22 +00:00
|
|
|
continue;
|
2007-08-20 19:33:15 +00:00
|
|
|
if( distance( l_piste ) )
|
|
|
|
return Track;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
/*
|
2009-11-09 14:00:22 +00:00
|
|
|
* Locate zone area at the cursor position.
|
2008-04-17 16:25:29 +00:00
|
|
|
*
|
2009-11-09 14:00:22 +00:00
|
|
|
* The search begins to address start_adresse
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
TRACK* Locate_Zone( TRACK* start_adresse, int layer, int typeloc )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
wxPoint ref;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
SET_REF_POS( ref );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
return Locate_Zone( start_adresse, ref, layer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/*
|
|
|
|
* Locate zone area at point.
|
|
|
|
*
|
|
|
|
* The search begins to address start_adresse
|
|
|
|
*/
|
2007-08-20 19:33:15 +00:00
|
|
|
TRACK* Locate_Zone( TRACK* start_adresse, wxPoint ref, int layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
TRACK* Zone;
|
|
|
|
int l_segm;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Zone = start_adresse; Zone != NULL; Zone = Zone->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
l_segm = Zone->m_Width >> 1;
|
|
|
|
ux0 = Zone->m_Start.x;
|
|
|
|
uy0 = Zone->m_Start.y;
|
|
|
|
dx = Zone->m_End.x;
|
|
|
|
dy = Zone->m_End.y;
|
|
|
|
|
|
|
|
dx -= ux0;
|
|
|
|
dy -= uy0;
|
|
|
|
spot_cX = ref.x - ux0;
|
|
|
|
spot_cY = ref.y - uy0;
|
|
|
|
|
|
|
|
if( ( layer != -1 ) && ( Zone->GetLayer() != layer ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
if( distance( l_segm ) )
|
|
|
|
return Zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Location of text on the PCB:
|
|
|
|
* INPUT: char pointer to the beginning of the search area
|
|
|
|
* Return: pointer to the text description located.
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
TEXTE_PCB* Locate_Texte_Pcb( TEXTE_PCB* pt_txt_pcb, int typeloc )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
int angle;
|
|
|
|
EDA_BaseStruct* PtStruct;
|
|
|
|
wxPoint ref;
|
|
|
|
|
|
|
|
SET_REF_POS( ref );
|
|
|
|
PtStruct = (EDA_BaseStruct*) pt_txt_pcb;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct->Type() != TYPE_TEXTE )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
pt_txt_pcb = (TEXTE_PCB*) PtStruct;
|
|
|
|
|
|
|
|
angle = pt_txt_pcb->m_Orient;
|
2009-11-09 14:00:22 +00:00
|
|
|
ux0 = pt_txt_pcb->m_Pos.x;
|
|
|
|
uy0 = pt_txt_pcb->m_Pos.y;
|
2007-08-20 19:33:15 +00:00
|
|
|
dx = ( pt_txt_pcb->m_Size.x * pt_txt_pcb->GetLength() ) / 2;
|
|
|
|
dy = pt_txt_pcb->m_Size.y / 2;
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
dx *= 13;
|
|
|
|
dx /= 9; /* Character for factor 13/9. */
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Cursor in the rectangle around the center. */
|
|
|
|
spot_cX = ref.x - ux0;
|
|
|
|
spot_cY = ref.y - uy0;
|
2007-08-20 19:33:15 +00:00
|
|
|
RotatePoint( &spot_cX, &spot_cY, -angle );
|
|
|
|
if( ( abs( spot_cX ) <= abs( dx ) ) && ( abs( spot_cY ) <= abs( dy ) ) )
|
|
|
|
return pt_txt_pcb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-09 14:00:22 +00:00
|
|
|
* Calculate the distance from the cursor to a line segment:
|
|
|
|
* (Track, edge, contour module ..
|
|
|
|
* Returns:
|
|
|
|
* 0 if distance > threshold
|
|
|
|
* 1 if distance <= threshold
|
|
|
|
* Variables used (must be initialized before use, and
|
|
|
|
* are brought to the mark center on the origin of the segment)
|
|
|
|
* dx, dy = coord of extremity segment.
|
|
|
|
* spot_cX, spot_cY = coord of mouse cursor
|
|
|
|
* Search 4 cases:
|
|
|
|
* Horizontal segment
|
|
|
|
* Vertical segment
|
|
|
|
* Segment 45
|
|
|
|
* Any segment
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
int distance( int seuil )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
int cXrot, cYrot, segX, segY;
|
|
|
|
int pointX, pointY;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
segX = dx;
|
|
|
|
segY = dy;
|
|
|
|
pointX = spot_cX;
|
|
|
|
pointY = spot_cY;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Reroute coordinate for the segment in 1st quadrant (coord> = 0). */
|
|
|
|
if( segX < 0 ) /* Set > 0 if symmetrical about the axis Y. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
segX = -segX;
|
|
|
|
pointX = -pointX;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( segY < 0 ) /* Set > 0 if symmetrical about the axis X. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
segY = -segY;
|
|
|
|
pointY = -pointY;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
if( segY == 0 ) /* Horizontal track. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( abs( pointY ) <= seuil )
|
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pointX >= 0 ) && ( pointX <= segX ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
2009-11-09 14:00:22 +00:00
|
|
|
|
|
|
|
if( ( pointX < 0 ) && ( pointX >= -seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( pointX * pointX ) + ( pointY * pointY ) ) <=
|
|
|
|
( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pointX > segX ) && ( pointX <= ( segX + seuil ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( ( pointX - segX ) * ( pointX - segX ) ) +
|
|
|
|
( pointY * pointY ) ) <= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
else if( segX == 0 ) /* Vertical track. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( abs( pointX ) <= seuil )
|
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pointY >= 0 ) && ( pointY <= segY ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pointY < 0 ) && ( pointY >= -seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( (pointY * pointY ) + ( pointX * pointX ) ) <=
|
|
|
|
( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( pointY > segY ) && ( pointY <= ( segY + seuil ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( ( pointY - segY ) * ( pointY - segY ) ) +
|
|
|
|
( pointX * pointX ) ) <= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
else if( segX == segY ) /* 45 degree track. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
/* You spin axes of 45 degrees. mouse was then
|
|
|
|
* coord: x1 = x * y * cos45 + sin45
|
|
|
|
* y1 = y * cos45 - sin45 x *
|
|
|
|
* And the segment of track is horizontal.
|
|
|
|
* coord recalculation of the mouse (sin45 = cos45 = .707 = 7 / 10
|
|
|
|
* Note: sin or cos45 = .707, and when recalculating coord
|
|
|
|
* dX45 and dy45, lect coeff .707 is neglected, dx and dy are both
|
|
|
|
* actually .707
|
|
|
|
* too big. (security hole too small)
|
|
|
|
* spot_cX *, Y * must be by .707 * .707 = 0.5
|
|
|
|
*/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
cXrot = (pointX + pointY) >> 1;
|
|
|
|
cYrot = (pointY - pointX) >> 1;
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Recalculate coordinates of extremity segment, which will be vertical
|
|
|
|
* following the orientation of axes on the screen: DX45 = pointx
|
|
|
|
* (or pointy) and 1.414 is actually greater, and dy45 = 0
|
|
|
|
*
|
|
|
|
* Threshold should be .707 to reflect the difference in coeff dx, dy
|
|
|
|
*/
|
2007-08-20 19:33:15 +00:00
|
|
|
seuil *= 7; seuil /= 10;
|
2009-11-09 14:00:22 +00:00
|
|
|
if( abs( cYrot ) <= seuil )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( cXrot >= 0 ) && ( cXrot <= segX ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( cXrot < 0 ) && ( cXrot >= -seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( cXrot * cXrot ) + ( cYrot * cYrot ) )
|
|
|
|
<= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( cXrot > segX ) && ( cXrot <= ( segX + seuil ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( ( cXrot - segX ) * ( cXrot - segX ) ) +
|
|
|
|
( cYrot * cYrot ) ) <= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
else /* Any orientation. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
/* There is a change of axis (rotation), so that the segment
|
|
|
|
* track is horizontal in the new reference, */
|
2007-08-20 19:33:15 +00:00
|
|
|
int angle;
|
|
|
|
|
2008-10-29 15:26:53 +00:00
|
|
|
angle = (int) ( atan2( (double) segY, (double) segX ) * 1800 / M_PI);
|
2009-11-09 14:00:22 +00:00
|
|
|
cXrot = pointX;
|
|
|
|
cYrot = pointY;
|
|
|
|
RotatePoint( &cXrot, &cYrot, angle ); /* Rotate test point. */
|
|
|
|
RotatePoint( &segX, &segY, angle ); /* Rotate segment. */
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* The track is horizontal, following the changes to coordinate
|
|
|
|
* axis and, therefore segX = length of segment
|
|
|
|
*/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
if( abs( cYrot ) <= seuil )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( cXrot >= 0 ) && ( cXrot <= segX ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
2009-11-09 14:00:22 +00:00
|
|
|
|
|
|
|
if( ( cXrot < 0 ) && ( cXrot >= -seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( cXrot * cXrot ) + ( cYrot * cYrot ) )
|
|
|
|
<= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( cXrot > segX ) && ( cXrot <= ( segX + seuil ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
if( ( ( ( cXrot - segX ) * ( cXrot - segX ) ) +
|
|
|
|
( cYrot * cYrot ) ) <= ( seuil * seuil ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|