Commit c1e3416a authored by dickelbeck's avatar dickelbeck

searching and beautifying

parent 66080848
......@@ -5,6 +5,20 @@ Please add newer entries at the top, list the date and your name with
email address.
2007-Aug-08 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew & common
* Renamed locate.cpp's distance() to DistanceTest() and moved it to trigo.cpp.
Pass more parameters to DistanceTest and removed globals that were used by
distance() in locate.cpp.
Moved and renamed DistanceTest function proto from protos.h to trigo.h.
* Implemented HitTest() for class_cotation, class_mire, and a few other classes
by factoring out existing code from locate.cpp. locate.cpp should operate
exactly the same as before.
* Detected that the suspected class_module hit-testing bug was not real,
i.e. no bug found.
2007-aug-08 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+ eeschema
......
......@@ -9,6 +9,163 @@
#include "trigo.h"
/*****************************/
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY )
/*****************************/
/*
* Calcul de la distance du curseur souris a un segment de droite :
* ( piste, edge, contour module ..
* retourne:
* false si distance > seuil
* true si distance <= seuil
* Variables utilisees ( doivent etre initialisees avant appel , et
* sont ramenees au repere centre sur l'origine du segment)
* dx, dy = coord de l'extremite segment.
* spot_cX,spot_cY = coord du curseur souris
* la recherche se fait selon 4 cas:
* segment horizontal
* segment vertical
* segment 45
* segment quelconque
*/
{
int cXrot, cYrot, /* coord du point (souris) dans le repere tourne */
segX, segY; /* coord extremite segment tj >= 0 */
int pointX, pointY; /* coord point a tester dans repere modifie dans lequel
* segX et segY sont >=0 */
segX = dx; segY = dy; pointX = spot_cX; pointY = spot_cY;
/*Recalcul coord pour que le segment soit dans 1er quadrant (coord >= 0)*/
if( segX < 0 ) /* mise en >0 par symetrie par rapport a l'axe Y */
{
segX = -segX; pointX = -pointX;
}
if( segY < 0 ) /* mise en > 0 par symetrie par rapport a l'axe X */
{
segY = -segY; pointY = -pointY;
}
if( segY == 0 ) /* piste Horizontale */
{
if( abs( pointY ) <= seuil )
{
if( (pointX >= 0) && (pointX <= segX) )
return 1;
/* Etude des extremites : cercle de rayon seuil */
if( (pointX < 0) && (pointX >= -seuil) )
{
if( ( (pointX * pointX) + (pointY * pointY) ) <= (seuil * seuil) )
return true;
}
if( (pointX > segX) && ( pointX <= (segX + seuil) ) )
{
if( ( ( (pointX - segX) * (pointX - segX) ) + (pointY * pointY) ) <=
(seuil * seuil) )
return true;
}
}
}
else if( segX == 0 ) /* piste verticale */
{
if( abs( pointX ) <= seuil )
{
if( (pointY >= 0 ) && (pointY <= segY) )
return true;
if( (pointY < 0) && (pointY >= -seuil) )
{
if( ( (pointY * pointY) + (pointX * pointX) ) <= (seuil * seuil) )
return true;
}
if( (pointY > segY) && ( pointY <= (segY + seuil) ) )
{
if( ( ( (pointY - segY) * (pointY - segY) ) + (pointX * pointX) ) <=
(seuil * seuil) )
return true;
}
}
}
else if( segX == segY ) /* piste a 45 degre */
{
/* on fait tourner les axes de 45 degre. la souris a alors les
* coord : x1 = x*cos45 + y*sin45
* y1 = y*cos45 - x*sin45
* et le segment de piste est alors horizontal.
* recalcul des coord de la souris ( sin45 = cos45 = .707 = 7/10
* remarque : sin ou cos45 = .707, et lors du recalcul des coord
* dx45 et dy45, lec coeff .707 est neglige, dx et dy sont en fait .707 fois
* trop grands. (c.a.d trop petits)
* spot_cX,Y doit etre * par .707 * .707 = 0.5 */
cXrot = (pointX + pointY) >> 1;
cYrot = (pointY - pointX) >> 1;
/* recalcul des coord de l'extremite du segment , qui sera vertical
* suite a l'orientation des axes sur l'ecran : dx45 = pointX (ou pointY)
* et est en fait 1,414 plus grand , et dy45 = 0 */
// seuil doit etre * .707 pour tenir compte du coeff de reduction sur dx,dy
seuil *= 7; seuil /= 10;
if( abs( cYrot ) <= seuil ) /* ok sur axe vertical) */
{
if( (cXrot >= 0) && (cXrot <= segX) )
return true;
/* Etude des extremites : cercle de rayon seuil */
if( (cXrot < 0) && (cXrot >= -seuil) )
{
if( ( (cXrot * cXrot) + (cYrot * cYrot) ) <= (seuil * seuil) )
return true;
}
if( (cXrot > segX) && ( cXrot <= (segX + seuil) ) )
{
if( ( ( (cXrot - segX) * (cXrot - segX) ) + (cYrot * cYrot) ) <= (seuil * seuil) )
return true;
}
}
}
else /* orientation quelconque */
{
/* On fait un changement d'axe (rotation) de facon a ce que le segment
* de piste soit horizontal dans le nouveau repere */
int angle;
angle = (int) ( atan2( (float) segY, (float) segX ) * 1800 / M_PI);
cXrot = pointX; cYrot = pointY;
RotatePoint( &cXrot, &cYrot, angle ); /* Rotation du point a tester */
RotatePoint( &segX, &segY, angle ); /* Rotation du segment */
/* la piste est Horizontale , par suite des modifs de coordonnes
* et d'axe, donc segX = longueur du segment */
if( abs( cYrot ) <= seuil ) /* ok sur axe vertical) */
{
if( (cXrot >= 0) && (cXrot <= segX) )
return true;
/* Etude des extremites : cercle de rayon seuil */
if( (cXrot < 0) && (cXrot >= -seuil) )
{
if( ( (cXrot * cXrot) + (cYrot * cYrot) ) <= (seuil * seuil) )
return true;
}
if( (cXrot > segX) && ( cXrot <= (segX + seuil) ) )
{
if( ( ( (cXrot - segX) * (cXrot - segX) ) + (cYrot * cYrot) ) <= (seuil * seuil) )
return true;
}
}
}
return false;
}
/***********************************/
int ArcTangente( int dy, int dx )
/***********************************/
......@@ -217,3 +374,5 @@ void RotatePoint( double* pX, double* pY, int angle )
*pY = fpy;
}
}
......@@ -235,7 +235,6 @@ public:
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
......@@ -264,7 +263,7 @@ public:
* @param typeloc
* @return EDA_BaseStruct* - if a direct hit, else NULL.
*/
EDA_BaseStruct* FindPadOrModule( const wxPoint& refPos, int layer, int typeloc );
EDA_BaseStruct* FindPadOrModule( const wxPoint& refPos, int layer );
#endif
};
......@@ -322,6 +321,27 @@ public:
void UnLink( void );
void Copy( DRAWSEGMENT* source );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& ref_pos );
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT("pgraphic");
}
#endif
};
......
......@@ -7,7 +7,7 @@
#define TRIGO_H
/* Prototype des fonctions de TRIGO.CC */
/* Prototype des fonctions de trigo.cpp */
void RotatePoint(int *pX, int *pY, int angle);
void RotatePoint(int *pX, int *pY, int cx, int cy, int angle);
void RotatePoint(wxPoint *point, const wxPoint & centre, int angle);
......@@ -19,6 +19,7 @@ int ArcTangente(int dy, int dx);
Analogue a atan2 ( mais plus rapide pour les caculs si
l'angle est souvent 0, -1800, ou +- 900 */
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );
......
......@@ -290,75 +290,64 @@ void BOARD::Show( int nestLevel, std::ostream& os )
// see pcbstruct.h
EDA_BaseStruct* BOARD::FindPadOrModule( const wxPoint& refPos, int layer, int typeloc )
EDA_BaseStruct* BOARD::FindPadOrModule( const wxPoint& refPos, int layer )
{
class PadOrModule : public INSPECTOR
{
public:
EDA_BaseStruct* found;
int layer;
int typeloc;
PadOrModule( int alayer, int atypeloc ) :
found(0),
layer(alayer),
typeloc(atypeloc) {}
PadOrModule( int alayer ) :
found(0), // found is NULL
layer(alayer)
{
}
SEARCH_RESULT Inspect( EDA_BaseStruct* testItem, const void* testData )
{
const wxPoint* refPos = (const wxPoint*) testData;
const wxPoint& refPos = *(const wxPoint*) testData;
if( testItem->m_StructType == TYPEMODULE )
if( testItem->m_StructType == TYPEPAD )
{
int mlayer = ((MODULE*)testItem)->m_Layer;
if( typeloc & MATCH_LAYER )
{
if( layer != mlayer )
return SEARCH_CONTINUE;
}
if( typeloc & VISIBLE_ONLY )
{
if( !IsModuleLayerVisible(mlayer) )
return SEARCH_CONTINUE;
}
if( testItem->HitTest( *refPos ) )
if( testItem->HitTest( refPos ) )
{
found = testItem;
return SEARCH_QUIT;
}
}
else if( testItem->m_StructType == TYPEPAD )
else if( testItem->m_StructType == TYPEMODULE )
{
if( testItem->HitTest( *refPos ) )
int mlayer = ((MODULE*)testItem)->m_Layer;
// consider only visible modules
if( IsModuleLayerVisible( mlayer ) )
{
found = testItem;
return SEARCH_QUIT;
if( testItem->HitTest( refPos ) )
{
// save regardless of layer test, but only quit if
// layer matches, otherwise use this item if no future
// layer match.
found = testItem;
if( layer == mlayer )
return SEARCH_QUIT;
}
}
}
else { int debug=1; /* this should not happen, because of scanTypes */ }
return SEARCH_CONTINUE;
}
};
PadOrModule inspector1( layer, MATCH_LAYER );
PadOrModule inspector2( layer, VISIBLE_ONLY );
PadOrModule inspector( layer );
// search only for PADs first, then MODULES, and preferably a layer match
static const KICAD_T scanTypes[] = { TYPEPAD, TYPEMODULE, EOT };
// search the current layer first
if( SEARCH_QUIT == IterateForward( m_Modules, &inspector1, &refPos, scanTypes ) )
return inspector1.found;
// if not found, set layer to don't care and search again
if( SEARCH_QUIT == IterateForward( m_Modules, &inspector2, &refPos, scanTypes ) )
return inspector2.found;
IterateForward( m_Modules, &inspector, &refPos, scanTypes );
return NULL;
return inspector.found;
}
#endif
This diff is collapsed.
......@@ -6,42 +6,62 @@
#include "base_struct.h"
class COTATION: public EDA_BaseStruct
class COTATION : public EDA_BaseStruct
{
public:
int m_Layer; // 0.. 32 ( NON bit a bit)
int m_Width;
wxPoint m_Pos;
int m_Shape;
int m_Unit; /* 0 = inches, 1 = mm */
int m_Value; /* valeur en unites PCB de la cote */
public:
int m_Layer; // 0.. 32 ( NON bit a bit)
int m_Width;
wxPoint m_Pos;
int m_Shape;
int m_Unit; /* 0 = inches, 1 = mm */
int m_Value; /* valeur en unites PCB de la cote */
TEXTE_PCB * m_Text; /* pour affichage du texte */
int Barre_ox, Barre_oy, Barre_fx, Barre_fy;
int TraitG_ox, TraitG_oy, TraitG_fx, TraitG_fy;
int TraitD_ox, TraitD_oy, TraitD_fx, TraitD_fy;
int FlecheD1_ox, FlecheD1_oy, FlecheD1_fx, FlecheD1_fy;
int FlecheD2_ox, FlecheD2_oy, FlecheD2_fx, FlecheD2_fy;
int FlecheG1_ox, FlecheG1_oy, FlecheG1_fx, FlecheG1_fy;
int FlecheG2_ox, FlecheG2_oy, FlecheG2_fx, FlecheG2_fy;
TEXTE_PCB* m_Text; /* pour affichage du texte */
int Barre_ox, Barre_oy, Barre_fx, Barre_fy;
int TraitG_ox, TraitG_oy, TraitG_fx, TraitG_fy;
int TraitD_ox, TraitD_oy, TraitD_fx, TraitD_fy;
int FlecheD1_ox, FlecheD1_oy, FlecheD1_fx, FlecheD1_fy;
int FlecheD2_ox, FlecheD2_oy, FlecheD2_fx, FlecheD2_fy;
int FlecheG1_ox, FlecheG1_oy, FlecheG1_fx, FlecheG1_fy;
int FlecheG2_ox, FlecheG2_oy, FlecheG2_fx, FlecheG2_fy;
public:
COTATION(EDA_BaseStruct * StructFather);
~COTATION(void);
public:
COTATION( EDA_BaseStruct* StructFather );
~COTATION( void );
bool ReadCotationDescr(FILE * File, int * LineNum);
bool WriteCotationDescr(FILE * File);
bool ReadCotationDescr( FILE* File, int* LineNum );
bool WriteCotationDescr( FILE* File );
/* supprime du chainage la structure Struct */
void UnLink( void );
/* supprime du chainage la structure Struct */
void UnLink( void );
/* Modification du texte de la cotation */
void SetText(const wxString & NewText);
/* Modification du texte de la cotation */
void SetText( const wxString& NewText );
void Copy(COTATION * source);
void Copy( COTATION* source );
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset, int mode_color);
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int mode_color );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& ref_pos );
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT( "DIMENSION" );
}
#endif
};
#endif // #define COTATION_H
#endif // #define COTATION_H
......@@ -438,6 +438,73 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool EDGE_MODULE::HitTest( const wxPoint& ref_pos )
{
int uxf, uyf;
int rayon, dist;
int dx, dy, spot_cX, spot_cY;
int ux0, uy0;
ux0 = m_Start.x;
uy0 = m_Start.y;
uxf = m_End.x;
uyf = m_End.y;
switch( m_Shape )
{
case S_SEGMENT:
/* recalcul des coordonnees avec ux0,uy0 = origine des coord. */
spot_cX = ref_pos.x - ux0;
spot_cY = ref_pos.y - uy0;
dx = uxf - ux0;
dy = uyf - uy0;
if( DistanceTest( m_Width/2, dx, dy, spot_cX, spot_cY ) )
return true;
break;
case S_CIRCLE:
rayon = (int) hypot( (double) (uxf - ux0), (double) (uyf - uy0) );
dist = (int) hypot( (double) (ref_pos.x - ux0), (double) (ref_pos.y - uy0) );
if( abs( rayon - dist ) <= m_Width )
return true;
break;
case S_ARC:
rayon = (int) hypot( (double) (uxf - ux0), (double) (uyf - uy0) );
dist = (int) hypot( (double) (ref_pos.x - ux0), (double) (ref_pos.y - uy0) );
if( abs( rayon - dist ) > m_Width )
break;
/* pour un arc, controle complementaire */
int mouseAngle = (int) ArcTangente( ref_pos.y - uy0, ref_pos.x - ux0 );
int stAngle = (int) ArcTangente( uyf - uy0, uxf - ux0 );
int endAngle = stAngle + m_Angle;
if( endAngle > 3600 )
{
stAngle -= 3600;
endAngle -= 3600;
}
if( (mouseAngle >= stAngle) && (mouseAngle <= endAngle) )
return true;
break;
}
return false; // an unknown m_Shape also returns false
}
#if defined(DEBUG)
/**
* Function Show
......
......@@ -41,6 +41,14 @@ public:
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
int draw_mode );
void Draw3D( Pcb3D_GLCanvas* glcanvas );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& refPos );
#if defined(DEBUG)
/**
......@@ -50,7 +58,7 @@ public:
*/
virtual wxString GetClass() const
{
return wxT( "GRAPHIC" );
return wxT( "MGRAPHIC" );
// return wxT( "EDGE" ); ?
}
......
......@@ -9,15 +9,15 @@
#include "pcbnew.h"
MIREPCB::MIREPCB(EDA_BaseStruct * StructFather):
EDA_BaseStruct( StructFather, TYPEMIRE)
MIREPCB::MIREPCB( EDA_BaseStruct* StructFather ) :
EDA_BaseStruct( StructFather, TYPEMIRE )
{
m_Shape = 0;
m_Size = 5000;
m_Shape = 0;
m_Size = 5000;
}
MIREPCB::~MIREPCB(void)
MIREPCB::~MIREPCB( void )
{
}
......@@ -25,161 +25,186 @@ MIREPCB::~MIREPCB(void)
/***************************/
void MIREPCB::UnLink( void )
/***************************/
/* supprime du chainage la structure Struct
les structures arrieres et avant sont chainees directement
* les structures arrieres et avant sont chainees directement
*/
{
/* Modification du chainage arriere */
if( Pback )
{
if( Pback->m_StructType != TYPEPCB)
{
Pback->Pnext = Pnext;
}
else /* Le chainage arriere pointe sur la structure "Pere" */
{
((BOARD*)Pback)->m_Drawings = Pnext;
}
}
/* Modification du chainage avant */
if( Pnext) Pnext->Pback = Pback;
Pnext = Pback = NULL;
/* Modification du chainage arriere */
if( Pback )
{
if( Pback->m_StructType != TYPEPCB )
{
Pback->Pnext = Pnext;
}
else /* Le chainage arriere pointe sur la structure "Pere" */
{
( (BOARD*) Pback )->m_Drawings = Pnext;
}
}
/* Modification du chainage avant */
if( Pnext )
Pnext->Pback = Pback;
Pnext = Pback = NULL;
}
/**********************************/
void MIREPCB::Copy(MIREPCB * source)
void MIREPCB::Copy( MIREPCB* source )
/**********************************/
{
m_Layer = source->m_Layer;
m_Width = source->m_Width;
m_Pos = source->m_Pos;
m_Shape = source->m_Shape;
m_Size = source->m_Size;
m_TimeStamp = GetTimeStamp();
m_Layer = source->m_Layer;
m_Width = source->m_Width;
m_Pos = source->m_Pos;
m_Shape = source->m_Shape;
m_Size = source->m_Size;
m_TimeStamp = GetTimeStamp();
}
/**************************************************************/
bool MIREPCB::ReadMirePcbDescr(FILE * File, int * LineNum)
bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum )
/**************************************************************/
/* Lecture de la description de 1 segment type Drawing PCB
*/
*/
{
char Line[256];
while( GetLine(File, Line, LineNum ) != NULL )
{
if(strnicmp(Line,"$End",4 ) == 0 ) return TRUE; /* fin de liste */
if(Line[0] == 'P')
{
sscanf( Line+2," %X %d %d %d %d %d %lX",
&m_Shape, &m_Layer,
&m_Pos.x, &m_Pos.y,
&m_Size, &m_Width, &m_TimeStamp );
if ( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if ( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
}
}
return FALSE;
char Line[256];
while( GetLine( File, Line, LineNum ) != NULL )
{
if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE; /* fin de liste */
if( Line[0] == 'P' )
{
sscanf( Line + 2, " %X %d %d %d %d %d %lX",
&m_Shape, &m_Layer,
&m_Pos.x, &m_Pos.y,
&m_Size, &m_Width, &m_TimeStamp );
if( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
}
}
return FALSE;
}
/************************************************/
bool MIREPCB::WriteMirePcbDescr(FILE * File)
bool MIREPCB::WriteMirePcbDescr( FILE* File )
/************************************************/
{
if( GetState(DELETED) ) return FALSE;
fprintf( File, "$MIREPCB\n");
fprintf( File,"Po %X %d %d %d %d %d %8.8lX\n",
m_Shape, m_Layer,
m_Pos.x, m_Pos.y,
m_Size, m_Width, m_TimeStamp );
fprintf( File, "$EndMIREPCB\n");
return TRUE;
if( GetState( DELETED ) )
return FALSE;
fprintf( File, "$MIREPCB\n" );
fprintf( File, "Po %X %d %d %d %d %d %8.8lX\n",
m_Shape, m_Layer,
m_Pos.x, m_Pos.y,
m_Size, m_Width, m_TimeStamp );
fprintf( File, "$EndMIREPCB\n" );
return TRUE;
}
/**********************************************************/
void MIREPCB::Draw(WinEDA_DrawPanel * panel, wxDC * DC,
const wxPoint & offset, int mode_color)
void MIREPCB::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& offset, int mode_color )
/**********************************************************/
/* Affichage de 1 mire : 2 segments + 1 cercle
le cercle a pour rayon le demi rayon de la mire
les 2 traits ont pour longueur le diametre de la mire
*/
* le cercle a pour rayon le demi rayon de la mire
* les 2 traits ont pour longueur le diametre de la mire
*/
{
int rayon, ox, oy, gcolor, width;
int dx1,dx2, dy1, dy2;
int typeaff;
int zoom;
ox = m_Pos.x + offset.x;
oy = m_Pos.y + offset.y;
gcolor = g_DesignSettings.m_LayerColor[m_Layer];
if ( (gcolor & ITEM_NOT_SHOW) != 0 ) return;
zoom = panel->GetZoom();
GRSetDrawMode(DC, mode_color);
typeaff = DisplayOpt.DisplayDrawItems;
width = m_Width;
if( width/zoom < 2 ) typeaff = FILAIRE;
/* Trace du cercle: */
rayon = m_Size / 4;
switch( typeaff )
{
case FILAIRE:
width = 0;
case FILLED:
GRCircle(&panel->m_ClipBox, DC, ox, oy, rayon, width, gcolor);
break;
case SKETCH:
GRCircle(&panel->m_ClipBox, DC, ox, oy, rayon + (width/2), gcolor) ;
GRCircle(&panel->m_ClipBox, DC, ox, oy, rayon - (width/2), gcolor) ;
break;
}
/* Trace des 2 traits */
rayon = m_Size/2;
dx1 = rayon, dy1 = 0;
dx2 = 0, dy2 = rayon;
if( m_Shape) /* Forme X */
{
dx1 = dy1 = (rayon * 7)/5;
dx2 = dx1; dy2 = -dy1;
}
switch( typeaff )
{
case FILAIRE:
case FILLED:
GRLine(&panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1, width, gcolor);
GRLine(&panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2, width, gcolor);
break;
case SKETCH:
GRCSegm(&panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1,
width, gcolor);
GRCSegm(&panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2,
width, gcolor);
break;
}
int rayon, ox, oy, gcolor, width;
int dx1, dx2, dy1, dy2;
int typeaff;
int zoom;
ox = m_Pos.x + offset.x;
oy = m_Pos.y + offset.y;
gcolor = g_DesignSettings.m_LayerColor[m_Layer];
if( (gcolor & ITEM_NOT_SHOW) != 0 )
return;
zoom = panel->GetZoom();
GRSetDrawMode( DC, mode_color );
typeaff = DisplayOpt.DisplayDrawItems;
width = m_Width;
if( width / zoom < 2 )
typeaff = FILAIRE;
/* Trace du cercle: */
rayon = m_Size / 4;
switch( typeaff )
{
case FILAIRE:
width = 0;
case FILLED:
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon, width, gcolor );
break;
case SKETCH:
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon + (width / 2), gcolor );
GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon - (width / 2), gcolor );
break;
}
/* Trace des 2 traits */
rayon = m_Size / 2;
dx1 = rayon, dy1 = 0;
dx2 = 0, dy2 = rayon;
if( m_Shape ) /* Forme X */
{
dx1 = dy1 = (rayon * 7) / 5;
dx2 = dx1; dy2 = -dy1;
}
switch( typeaff )
{
case FILAIRE:
case FILLED:
GRLine( &panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1, width, gcolor );
GRLine( &panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2, width, gcolor );
break;
case SKETCH:
GRCSegm( &panel->m_ClipBox, DC, ox - dx1, oy - dy1,
ox + dx1, oy + dy1,
width, gcolor );
GRCSegm( &panel->m_ClipBox, DC, ox - dx2, oy - dy2,
ox + dx2, oy + dy2,
width, gcolor );
break;
}
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool MIREPCB::HitTest( const wxPoint& refPos )
{
int dX = refPos.x - m_Pos.x;
int dY = refPos.y - m_Pos.y;
int rayon = m_Size / 2;
return abs(dX)<=rayon && abs(dY)<=rayon;
}
......@@ -7,31 +7,38 @@
#include "base_struct.h"
class MIREPCB: public EDA_BaseStruct
{
public:
int m_Layer; // 0.. 32 ( NON bit a bit)
int m_Width;
wxPoint m_Pos;
int m_Shape; // bit 0 : 0 = forme +, 1 = forme X
int m_Size;
public:
MIREPCB(EDA_BaseStruct * StructFather);
~MIREPCB(void);
bool WriteMirePcbDescr(FILE * File);
bool ReadMirePcbDescr(FILE * File, int * LineNum);
/* supprime du chainage la structure Struct */
void UnLink( void );
void Copy(MIREPCB * source);
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset, int mode_color);
class MIREPCB : public EDA_BaseStruct
{
public:
int m_Layer; // 0.. 32 ( NON bit a bit)
int m_Width;
wxPoint m_Pos;
int m_Shape; // bit 0 : 0 = forme +, 1 = forme X
int m_Size;
public:
MIREPCB( EDA_BaseStruct* StructFather );
~MIREPCB( void );
bool WriteMirePcbDescr( FILE* File );
bool ReadMirePcbDescr( FILE* File, int* LineNum );
/* supprime du chainage la structure Struct */
void UnLink( void );
void Copy( MIREPCB* source );
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int mode_color );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& refPos );
};
#endif // #define MIRE_H
#endif // #define MIRE_H
......@@ -144,7 +144,6 @@ public:
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
......
This diff is collapsed.
......@@ -10,84 +10,135 @@
/* Type des Vias (shape)*/
/* Forme des Vias ( parametre .shape ) */
#define VIA_NORMALE 3 /* type via : traversante (throught via) */
#define VIA_ENTERREE 2 /* type via : enterree ou aveugle (blind via) */
#define VIA_BORGNE 1 /* type via : borgne ou demi-traversante (buried via) */
#define VIA_NOT_DEFINED 0 /* reserved */
#define SQUARE_VIA 0x80000000 /* Flag pour forme carree */
#define VIA_NORMALE 3 /* type via : traversante (throught via) */
#define VIA_ENTERREE 2 /* type via : enterree ou aveugle (blind via) */
#define VIA_BORGNE 1 /* type via : borgne ou demi-traversante (buried via) */
#define VIA_NOT_DEFINED 0 /* reserved */
#define SQUARE_VIA 0x80000000 /* Flag pour forme carree */
/***/
class TRACK: public EDA_BaseLineStruct
class TRACK : public EDA_BaseLineStruct
{
public:
int m_Shape; // vias: shape and type, Track = shape..
int m_Drill; // for vias: via drill (- 1 for default value)
EDA_BaseStruct * start,* end; // pointers on a connected item (pad or track)
int m_NetCode; // Net number
int m_Sous_Netcode; /* In rastnest routines : for the current net,
block number (number common to the current connected items found) */
// chain = 0 indique une connexion non encore traitee
int m_Param; // Auxiliary variable ( used in some computations )
int m_Shape; // vias: shape and type, Track = shape..
int m_Drill; // for vias: via drill (- 1 for default value)
EDA_BaseStruct* start, * end; // pointers on a connected item (pad or track)
int m_NetCode; // Net number
int m_Sous_Netcode; /* In rastnest routines : for the current net,
* block number (number common to the current connected items found) */
public:
TRACK(EDA_BaseStruct * StructFather, DrawStructureType idtype = TYPETRACK);
TRACK(const TRACK & track);
TRACK * Next(void); // Retourne le chainage avant
TRACK * Back(void) // Retourne le chainage avant
{
return (TRACK*) Pback;
}
/* supprime du chainage la structure Struct */
void UnLink( void );
// Read/write data
bool WriteTrackDescr(FILE * File);
/* Ajoute un element a la liste */
void Insert(BOARD * Pcb, EDA_BaseStruct * InsertPoint);
/* Recherche du meilleur point d'insertion */
TRACK * GetBestInsertPoint( BOARD * Pcb);
// chain = 0 indique une connexion non encore traitee
int m_Param; // Auxiliary variable ( used in some computations )
/* Copie d'un Element d'une chaine de n elements */
TRACK * Copy( int NbSegm = 1 );
/* Recherche du debut du net
( les elements sont classes par net_code croissant ) */
TRACK * GetStartNetCode(int NetCode );
/* Recherche de la fin du net */
TRACK * GetEndNetCode(int NetCode);
/* Display on screen: */
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, int draw_mode);
/* divers */
int Shape(void) { return m_Shape & 0xFF; }
int ReturnMaskLayer(void);
int IsPointOnEnds(const wxPoint & point, int min_dist = 0);
bool IsNull(void); // return TRUE if segment lenght = 0
public:
TRACK( EDA_BaseStruct* StructFather, DrawStructureType idtype = TYPETRACK );
TRACK( const TRACK& track );
TRACK* Next( void ); // Retourne le chainage avant
TRACK* Back( void ) // Retourne le chainage avant
{
return (TRACK*) Pback;
}
/* supprime du chainage la structure Struct */
void UnLink( void );
// Read/write data
bool WriteTrackDescr( FILE* File );
/* Ajoute un element a la liste */
void Insert( BOARD* Pcb, EDA_BaseStruct* InsertPoint );
/* Recherche du meilleur point d'insertion */
TRACK* GetBestInsertPoint( BOARD* Pcb );
/* Copie d'un Element d'une chaine de n elements */
TRACK* Copy( int NbSegm = 1 );
/* Recherche du debut du net
* ( les elements sont classes par net_code croissant ) */
TRACK* GetStartNetCode( int NetCode );
/* Recherche de la fin du net */
TRACK* GetEndNetCode( int NetCode );
/* Display on screen: */
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode );
/* divers */
int Shape( void ) { return m_Shape & 0xFF; }
int ReturnMaskLayer( void );
int IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
bool IsNull( void ); // return TRUE if segment lenght = 0
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& refPos );
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT("TRACK");
}
#endif
};
class SEGZONE: public TRACK
class SEGZONE : public TRACK
{
public:
SEGZONE(EDA_BaseStruct * StructFather);
SEGZONE( EDA_BaseStruct* StructFather );
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT("ZONE");
}
#endif
};
class SEGVIA: public TRACK
class SEGVIA : public TRACK
{
public:
SEGVIA(EDA_BaseStruct * StructFather);
bool IsViaOnLayer(int layer);
void SetLayerPair(int top_layer, int bottom_layer);
void ReturnLayerPair(int * top_layer, int * bottom_layer);
SEGVIA( EDA_BaseStruct* StructFather );
bool IsViaOnLayer( int layer );
void SetLayerPair( int top_layer, int bottom_layer );
void ReturnLayerPair( int* top_layer, int* bottom_layer );
#if defined(DEBUG)
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT("VIA");
}
#endif
};
#endif /* CLASS_TRACK_H */
......@@ -16,6 +16,7 @@
#endif
#include "protos.h"
#include "trigo.h"
/**************************************************************/
......@@ -165,6 +166,61 @@ bool DRAWSEGMENT::ReadDrawSegmentDescr( FILE* File, int* LineNum )
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool DRAWSEGMENT::HitTest( const wxPoint& ref_pos )
{
int ux0 = m_Start.x;
int uy0 = m_Start.y;
/* recalcul des coordonnees avec ux0, uy0 = origine des coordonnees */
int dx = m_End.x - ux0;
int dy = m_End.y - uy0;
int spot_cX = ref_pos.x - ux0;
int spot_cY = ref_pos.y - uy0;
if( m_Shape==S_CIRCLE || m_Shape==S_ARC )
{
int rayon, dist, stAngle, endAngle, mouseAngle;
rayon = (int) hypot( (double) (dx), (double) (dy) );
dist = (int) hypot( (double) (spot_cX), (double) (spot_cY) );
if( abs( rayon - dist ) <= (m_Width / 2) )
{
if( m_Shape == S_CIRCLE )
return true;
/* pour un arc, controle complementaire */
mouseAngle = (int) ArcTangente( spot_cY, spot_cX );
stAngle = (int) ArcTangente( dy, dx );
endAngle = stAngle + m_Angle;
if( endAngle > 3600 )
{
stAngle -= 3600;
endAngle -= 3600;
}
if( mouseAngle >= stAngle && mouseAngle <= endAngle )
return true;
}
}
else
{
if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
return true;
}
return false;
}
/*******************/
/* Classe MARQUEUR */
/*******************/
......
This diff is collapsed.
......@@ -128,8 +128,7 @@ void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
#if defined(DEBUG)
DrawStruct = m_Pcb->FindPadOrModule(
GetScreen()->RefPos(true),
GetScreen()->m_Active_Layer,
VISIBLE_ONLY );
GetScreen()->m_Active_Layer );
#else
DrawStruct = PcbGeneralLocateAndDisplay();
#endif
......
This diff is collapsed.
......@@ -198,24 +198,6 @@ D_PAD * Fast_Locate_Pad_Connecte(BOARD * Pcb, const wxPoint & ref_pos, int layer
(bonne position ET bonne couche). */
int distance(int seuil);
/*
Calcul de la distance du curseur souris a un segment de droite :
( piste, edge, contour module ..
retourne:
0 si distance > seuil
1 si distance <= seuil
Variables utilisees ( externes doivent etre initialisees avant appel , et
sont ramenees au repere centre sur l'origine du segment)
dx, dy = coord de l'extremite segment.
spot_cX,spot_cY = coord du curseur souris
la recherche se fait selon 4 cas:
segment horizontal
segment vertical
segment 45
segment quelconque
*/
TRACK * Locate_Zone(TRACK * start_adresse,int layer, int typeloc);
TRACK * Locate_Zone(TRACK * start_adresse, const wxPoint & ref_pos,int layer);
/*
......
......@@ -122,5 +122,5 @@ public:
WinEDA_PcbFrame * m_Parent;
};
#endif
// _ZONES_H_
#endif // _ZONES_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