Commit 2e4c17a8 authored by dickelbeck's avatar dickelbeck

beautification, commenting, and renaming

parent caa42eaf
...@@ -6,10 +6,18 @@ email address. ...@@ -6,10 +6,18 @@ email address.
2007-Aug-05 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew & common
Changed the function name of Locate( const wxPoint& ref_pos ) to bool HitTest(..)
in both class_text_mod and base_struct.
More beautification and commenting.
2007-Aug-04 UPDATE Dick Hollenbeck <dick@softplc.com> 2007-Aug-04 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================ ================================================================================
+ pcbnew + pcbnew
Read-ability formatting, I am playing with a C++ beautifier called uncrustify. Read-ability formatting, I am playing with a C++ beautifier called "uncrustify".
I had to patch it and spent 2 days getting it configured. Patch not I had to patch it and spent 2 days getting it configured. Patch not
sent upstream yet. sent upstream yet.
Fixed a bug in "display local ratsnest pad or module": if you had a small Fixed a bug in "display local ratsnest pad or module": if you had a small
......
This diff is collapsed.
/************************/ /************************/
/* Routines de rotation */ /* Routines de rotation */
/************************/ /************************/
/* Fichier TRIGO.CPP */ /* Fichier TRIGO.CPP */
#include "fctsys.h" #include "fctsys.h"
#define global extern #define global extern
...@@ -10,179 +10,210 @@ ...@@ -10,179 +10,210 @@
/***********************************/ /***********************************/
int ArcTangente(int dy, int dx) int ArcTangente( int dy, int dx )
/***********************************/ /***********************************/
/* Retourne l'arc tangente en 0.1 degres du vecteur de coord dx, dy /* Retourne l'arc tangente en 0.1 degres du vecteur de coord dx, dy
entre -1800 et 1800 * entre -1800 et 1800
Analogue a atan2 ( mais plus rapide pour les calculs si * Analogue a atan2 ( mais plus rapide pour les calculs si
l'angle est souvent 0, -1800, ou +- 900 * l'angle est souvent 0, -1800, ou +- 900
*/ */
{ {
double fangle; double fangle;
if(dy == 0) if( dy == 0 )
{ {
if(dx >= 0 ) return(0); if( dx >= 0 )
else return(-1800); return 0;
} else
return -1800;
if(dx == 0) }
{
if(dy >= 0 ) return(900); if( dx == 0 )
else return(-900); {
} if( dy >= 0 )
return 900;
if(dx == dy) else
{ return -900;
if(dx >= 0) return(450); }
else return(-1800+450);
} if( dx == dy )
{
if(dx == -dy) if( dx >= 0 )
{ return 450;
if(dx >= 0) return(-450); else
else return(1800-450); return -1800 + 450;
} }
fangle = atan2( (double)dy, (double)dx ) / M_PI * 1800; if( dx == -dy )
return( (int) round(fangle) ); {
if( dx >= 0 )
return -450;
else
return 1800 - 450;
}
fangle = atan2( (double) dy, (double) dx ) / M_PI * 1800;
return (int) round( fangle );
} }
/*********************************************/ /*********************************************/
void RotatePoint(int *pX, int *pY, int angle) void RotatePoint( int* pX, int* pY, int angle )
/*********************************************/ /*********************************************/
/* /*
Fonction surchargee! * Fonction surchargee!
calcule les nouvelles coord du point de coord pX, pY, * calcule les nouvelles coord du point de coord pX, pY,
pour une rotation de centre 0, 0, et d'angle angle ( en 1/10 degre) * pour une rotation de centre 0, 0, et d'angle angle ( en 1/10 degre)
*/ */
{ {
float fpx, fpy; float fpx, fpy;
int tmp; int tmp;
while (angle < 0) angle += 3600; while( angle < 0 )
while (angle >= 3600) angle -= 3600; angle += 3600;
if (angle == 0) return; while( angle >= 3600 )
angle -= 3600;
/* Calcul des coord :
coord: xrot = y*sin + x*cos if( angle == 0 )
yrot = y*cos - x*sin return;
*/
if( angle == 900 ) /* sin = 1, cos = 0 */ /* Calcul des coord :
{ * coord: xrot = y*sin + x*cos
tmp = *pX; * yrot = y*cos - x*sin
*pX = *pY; */
*pY = - tmp; if( angle == 900 ) /* sin = 1, cos = 0 */
} {
tmp = *pX;
else if( angle == 1800 ) /* sin = 0, cos = -1 */ *pX = *pY;
{ *pY = -tmp;
*pX = - *pX; }
*pY = - *pY; else if( angle == 1800 ) /* sin = 0, cos = -1 */
} {
*pX = -*pX;
else if( angle == 2700 ) /* sin = -1, cos = 0 */ *pY = -*pY;
{ }
tmp = *pX; else if( angle == 2700 ) /* sin = -1, cos = 0 */
*pX = - *pY; {
*pY = tmp; tmp = *pX;
} *pX = -*pY;
*pY = tmp;
else }
{ else
fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]); {
fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]); fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]);
*pX = (int)round(fpx); *pY = (int)round(fpy); fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]);
}
*pX = (int) round( fpx );
*pY = (int) round( fpy );
}
} }
/************************************************************/ /************************************************************/
void RotatePoint(int *pX, int *pY, int cx, int cy, int angle) void RotatePoint( int* pX, int* pY, int cx, int cy, int angle )
/*************************************************************/ /*************************************************************/
/* /*
Fonction surchargee! * Fonction surchargee!
calcule les nouvelles coord du point de coord pX, pY, * calcule les nouvelles coord du point de coord pX, pY,
pour une rotation de centre cx, cy, et d'angle angle ( en 1/10 degre) * pour une rotation de centre cx, cy, et d'angle angle ( en 1/10 degre)
*/ */
{ {
int ox, oy; int ox, oy;
ox = *pX - cx; oy = *pY - cy; ox = *pX - cx;
RotatePoint(&ox, &oy, angle); oy = *pY - cy;
*pX = ox + cx;
*pY = oy + cy; RotatePoint( &ox, &oy, angle );
*pX = ox + cx;
*pY = oy + cy;
} }
/*****************************************************************/ /*****************************************************************/
void RotatePoint(wxPoint *point, const wxPoint & centre, int angle) void RotatePoint( wxPoint* point, const wxPoint& centre, int angle )
/*****************************************************************/ /*****************************************************************/
/* /*
Fonction surchargee! * Fonction surchargee!
calcule les nouvelles coord du point point, * calcule les nouvelles coord du point point,
pour une rotation de centre centre, et d'angle angle ( en 1/10 degre) * pour une rotation de centre centre, et d'angle angle ( en 1/10 degre)
*/ */
{ {
int ox, oy; int ox, oy;
ox = point->x - centre.x; oy = point->y - centre.y; ox = point->x - centre.x;
RotatePoint(&ox, &oy, angle); oy = point->y - centre.y;
point->x = ox + centre.x;
point->y = oy + centre.y; RotatePoint( &ox, &oy, angle );
point->x = ox + centre.x;
point->y = oy + centre.y;
} }
/*************************************************************************/ /*************************************************************************/
void RotatePoint(double *pX, double *pY, double cx, double cy, int angle) void RotatePoint( double* pX, double* pY, double cx, double cy, int angle )
/*************************************************************************/ /*************************************************************************/
{ {
double ox, oy; double ox, oy;
ox = *pX - cx; oy = *pY - cy; ox = *pX - cx;
RotatePoint(&ox, &oy, angle); oy = *pY - cy;
*pX = ox + cx;
*pY = oy + cy; RotatePoint( &ox, &oy, angle );
*pX = ox + cx;
*pY = oy + cy;
} }
/*************************************************/ /*************************************************/
void RotatePoint(double *pX, double *pY, int angle) void RotatePoint( double* pX, double* pY, int angle )
/*************************************************/ /*************************************************/
/* Calcul des coord : /* Calcul des coord :
coord: xrot = y*sin + x*cos * coord: xrot = y*sin + x*cos
yrot = y*cos - x*sin * yrot = y*cos - x*sin
*/ */
{ {
double tmp; double tmp;
while (angle < 0) angle += 3600;
while (angle >= 3600) angle -= 3600; while( angle < 0 )
if (angle == 0) return; angle += 3600;
if( angle == 900 ) /* sin = 1, cos = 0 */
{ while( angle >= 3600 )
tmp = *pX; angle -= 3600;
*pX = *pY;
*pY = - tmp; if( angle == 0 )
} return;
else if( angle == 1800 ) /* sin = 0, cos = -1 */ if( angle == 900 ) /* sin = 1, cos = 0 */
{ {
*pX = - *pX; tmp = *pX;
*pY = - *pY; *pX = *pY;
} *pY = -tmp;
}
else if( angle == 2700 ) /* sin = -1, cos = 0 */ else if( angle == 1800 ) /* sin = 0, cos = -1 */
{ {
tmp = *pX; *pX = -*pX;
*pX = - *pY; *pY = -*pY;
*pY = tmp; }
} else if( angle == 2700 ) /* sin = -1, cos = 0 */
{
else tmp = *pX;
{ *pX = -*pY;
double fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]); *pY = tmp;
double fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]); }
*pX = fpx; *pY = fpy; else
} {
double fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]);
double fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]);
*pX = fpx;
*pY = fpy;
}
} }
...@@ -179,8 +179,14 @@ public: ...@@ -179,8 +179,14 @@ public:
const wxPoint& offset, int color, const wxPoint& offset, int color,
int draw_mode, int display_mode = FILAIRE, int anchor_color = -1 ); int draw_mode, int display_mode = FILAIRE, int anchor_color = -1 );
/* locate functions */ /**
int Locate( const wxPoint& posref ); * Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param posref A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& posref );
int Len_Size( void ); // Return the text lenght in internal units int Len_Size( void ); // Return the text lenght in internal units
}; };
......
This diff is collapsed.
This diff is collapsed.
/***************************************************/ /***************************************************/
/* class_text_module.h : texts module description */ /* class_text_module.h : texts module description */
/***************************************************/ /***************************************************/
/* Description des Textes sur Modules : */ /* Description des Textes sur Modules : */
#define TEXT_is_REFERENCE 0 #define TEXT_is_REFERENCE 0
#define TEXT_is_VALUE 1 #define TEXT_is_VALUE 1
#define TEXT_is_DIVERS 2 #define TEXT_is_DIVERS 2
class TEXTE_MODULE: public EDA_BaseStruct class TEXTE_MODULE : public EDA_BaseStruct
{ {
public: public:
int m_Layer; // layer number int m_Layer; // layer number
int m_Width; int m_Width;
wxPoint m_Pos; // Real coord wxPoint m_Pos; // Real coord
wxPoint m_Pos0; // coord du debut du texte /ancre, orient 0 wxPoint m_Pos0; // coord du debut du texte /ancre, orient 0
char m_Unused; // unused (reserved for future extensions) char m_Unused; // unused (reserved for future extensions)
char m_Miroir ; // vue normale / miroir char m_Miroir; // vue normale / miroir
char m_NoShow; // 0: visible 1: invisible (bool) char m_NoShow; // 0: visible 1: invisible (bool)
char m_Type; // 0: ref,1: val, autre = 2..255 char m_Type; // 0: ref,1: val, autre = 2..255
int m_Orient; // orientation en 1/10 degre int m_Orient; // orientation en 1/10 degre
wxSize m_Size; // dimensions (en X et Y) du texte wxSize m_Size; // dimensions (en X et Y) du texte
wxString m_Text; wxString m_Text;
public: public:
TEXTE_MODULE(MODULE * parent, int text_type = TEXT_is_DIVERS ); TEXTE_MODULE( MODULE* parent, int text_type = TEXT_is_DIVERS );
~TEXTE_MODULE(void); ~TEXTE_MODULE( void );
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
void UnLink( void ); void UnLink( void );
void Copy(TEXTE_MODULE * source); // copy structure void Copy( TEXTE_MODULE* source ); // copy structure
/* Gestion du texte */ /* Gestion du texte */
void SetWidth(int new_width); void SetWidth( int new_width );
int GetLength(void); /* text length */ int GetLength( void ); /* text length */
int Pitch(void); /* retourne le pas entre 2 caracteres */ int Pitch( void ); /* retourne le pas entre 2 caracteres */
int GetDrawRotation(void); // Return text rotation for drawings and plotting int GetDrawRotation( void ); // Return text rotation for drawings and plotting
void SetDrawCoord(void); // mise a jour des coordonnées absolues de tracé
// a partir des coord relatives
void SetLocalCoord(void); // mise a jour des coordonnées relatives
// a partir des coord absolues de tracé
/* Reading and writing data on files */
int WriteDescr( FILE * File );
int ReadDescr( FILE * File, int * LineNum = NULL);
/* drawing functions */
void Draw(WinEDA_DrawPanel * panel, wxDC * DC, wxPoint offset, int draw_mode);
/* locate functions */
int Locate(const wxPoint & posref);
};
void SetDrawCoord( void ); // mise a jour des coordonn�s absolues de trac�
// a partir des coord relatives
void SetLocalCoord( void ); // mise a jour des coordonn�s relatives
// a partir des coord absolues de trac�
/* Reading and writing data on files */
int WriteDescr( FILE* File );
int ReadDescr( FILE* File, int* LineNum = NULL );
/* drawing functions */
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, wxPoint offset, int draw_mode );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param posref A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& posref );
};
...@@ -34,6 +34,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -34,6 +34,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
{ {
bool PopupOn = GetScreen()->m_CurrentItem bool PopupOn = GetScreen()->m_CurrentItem
&& GetScreen()->m_CurrentItem->m_Flags; && GetScreen()->m_CurrentItem->m_Flags;
bool ItemFree = (GetScreen()->m_CurrentItem == 0 ) bool ItemFree = (GetScreen()->m_CurrentItem == 0 )
|| (GetScreen()->m_CurrentItem->m_Flags == 0); || (GetScreen()->m_CurrentItem->m_Flags == 0);
...@@ -63,10 +64,10 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -63,10 +64,10 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
|| (GetScreen()->m_CurrentItem->m_Flags == 0); || (GetScreen()->m_CurrentItem->m_Flags == 0);
if( ItemFree ) if( ItemFree )
{ {
//no track is currently being edited - select a segment and remove it. // no track is currently being edited - select a segment and remove it.
DrawStruct = PcbGeneralLocateAndDisplay(); DrawStruct = PcbGeneralLocateAndDisplay();
//don't let backspace delete modules!! // don't let backspace delete modules!!
if( DrawStruct && (DrawStruct->m_StructType == TYPETRACK if( DrawStruct && (DrawStruct->m_StructType == TYPETRACK
|| DrawStruct->m_StructType == TYPEVIA) ) || DrawStruct->m_StructType == TYPEVIA) )
Delete_Segment( DC, (TRACK*) DrawStruct ); Delete_Segment( DC, (TRACK*) DrawStruct );
...@@ -74,7 +75,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -74,7 +75,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
} }
else if( GetScreen()->m_CurrentItem->m_StructType == TYPETRACK ) else if( GetScreen()->m_CurrentItem->m_StructType == TYPETRACK )
{ {
//then an element is being edited - remove the last segment. // then an element is being edited - remove the last segment.
GetScreen()->m_CurrentItem = GetScreen()->m_CurrentItem =
Delete_Segment( DC, (TRACK*) GetScreen()->m_CurrentItem ); Delete_Segment( DC, (TRACK*) GetScreen()->m_CurrentItem );
GetScreen()->SetModify(); GetScreen()->SetModify();
...@@ -97,7 +98,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -97,7 +98,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
case 'O' + GR_KB_CTRL: case 'O' + GR_KB_CTRL:
{ {
//try not to duplicate save, load code etc. // try not to duplicate save, load code etc.
wxCommandEvent evt; wxCommandEvent evt;
evt.SetId( ID_LOAD_FILE ); evt.SetId( ID_LOAD_FILE );
Files_io( evt ); Files_io( evt );
...@@ -106,7 +107,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -106,7 +107,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
case 'S' + GR_KB_CTRL: case 'S' + GR_KB_CTRL:
{ {
//try not to duplicate save, load code etc. // try not to duplicate save, load code etc.
wxCommandEvent evt; wxCommandEvent evt;
evt.SetId( ID_SAVE_BOARD ); evt.SetId( ID_SAVE_BOARD );
Files_io( evt ); Files_io( evt );
...@@ -163,10 +164,18 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey, ...@@ -163,10 +164,18 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
if( module == NULL ) // no footprint found if( module == NULL ) // no footprint found
{ {
module = Locate_Prefered_Module( m_Pcb, CURSEUR_OFF_GRILLE ); module = Locate_Prefered_Module( m_Pcb, CURSEUR_OFF_GRILLE );
if( module ) // a footprint is found, but locked or on an other layer if( module )
{ {
// a footprint is found, but locked or on an other layer
if( module->IsLocked() ) if( module->IsLocked() )
DisplayInfo( this, _( "Footprint found, but locked" ) ); {
wxString msg;
msg.Printf( _("Footprint %s found, but locked"),
module->m_Reference->m_Text.GetData() );
DisplayInfo( this, msg );
}
module = NULL; module = NULL;
} }
} }
......
...@@ -426,7 +426,7 @@ EDA_BaseStruct* Locate_Cotation( BOARD* Pcb, int LayerSearch, int typeloc ) ...@@ -426,7 +426,7 @@ EDA_BaseStruct* Locate_Cotation( BOARD* Pcb, int LayerSearch, int typeloc )
pt_txt = Cotation->m_Text; pt_txt = Cotation->m_Text;
if( pt_txt ) if( pt_txt )
{ {
if( pt_txt->Locate( ref_pos ) ) if( pt_txt->HitTest( ref_pos ) )
return PtStruct; return PtStruct;
} }
...@@ -857,7 +857,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc ) ...@@ -857,7 +857,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
// hit-test the reference text // hit-test the reference text
pt_txt_mod = module->m_Reference; pt_txt_mod = module->m_Reference;
if( pt_txt_mod->Locate( ref_pos ) ) if( pt_txt_mod->HitTest( ref_pos ) )
{ {
if( PtModule ) if( PtModule )
*PtModule = module; *PtModule = module;
...@@ -866,7 +866,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc ) ...@@ -866,7 +866,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
// hit-test the value text // hit-test the value text
pt_txt_mod = module->m_Value; pt_txt_mod = module->m_Value;
if( pt_txt_mod->Locate( ref_pos ) ) if( pt_txt_mod->HitTest( ref_pos ) )
{ {
if( PtModule ) if( PtModule )
*PtModule = module; *PtModule = module;
...@@ -881,7 +881,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc ) ...@@ -881,7 +881,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
continue; continue;
pt_txt_mod = (TEXTE_MODULE*) PtStruct; pt_txt_mod = (TEXTE_MODULE*) PtStruct;
if( pt_txt_mod->Locate( ref_pos ) ) if( pt_txt_mod->HitTest( ref_pos ) )
{ {
if( PtModule ) if( PtModule )
*PtModule = module; *PtModule = module;
...@@ -1151,7 +1151,7 @@ TEXTE_PCB* Locate_Texte_Pcb( EDA_BaseStruct* PtStruct, int LayerSearch, int type ...@@ -1151,7 +1151,7 @@ TEXTE_PCB* Locate_Texte_Pcb( EDA_BaseStruct* PtStruct, int LayerSearch, int type
if( PtStruct->m_StructType != TYPETEXTE ) if( PtStruct->m_StructType != TYPETEXTE )
continue; continue;
TEXTE_PCB* pt_txt_pcb = (TEXTE_PCB*) PtStruct; TEXTE_PCB* pt_txt_pcb = (TEXTE_PCB*) PtStruct;
if( pt_txt_pcb->Locate( ref ) ) if( pt_txt_pcb->HitTest( ref ) )
{ {
if( pt_txt_pcb->m_Layer == LayerSearch ) if( pt_txt_pcb->m_Layer == LayerSearch )
return pt_txt_pcb; return pt_txt_pcb;
......
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