Commit 2e4c17a8 authored by dickelbeck's avatar dickelbeck

beautification, commenting, and renaming

parent caa42eaf
......@@ -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>
================================================================================
+ 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
sent upstream yet.
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"
#define global extern
......@@ -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
entre -1800 et 1800
Analogue a atan2 ( mais plus rapide pour les calculs si
l'angle est souvent 0, -1800, ou +- 900
*/
* entre -1800 et 1800
* Analogue a atan2 ( mais plus rapide pour les calculs si
* l'angle est souvent 0, -1800, ou +- 900
*/
{
double fangle;
if(dy == 0)
{
if(dx >= 0 ) return(0);
else return(-1800);
}
if(dx == 0)
{
if(dy >= 0 ) return(900);
else return(-900);
}
if(dx == dy)
{
if(dx >= 0) return(450);
else return(-1800+450);
}
if(dx == -dy)
{
if(dx >= 0) return(-450);
else return(1800-450);
}
fangle = atan2( (double)dy, (double)dx ) / M_PI * 1800;
return( (int) round(fangle) );
double fangle;
if( dy == 0 )
{
if( dx >= 0 )
return 0;
else
return -1800;
}
if( dx == 0 )
{
if( dy >= 0 )
return 900;
else
return -900;
}
if( dx == dy )
{
if( dx >= 0 )
return 450;
else
return -1800 + 450;
}
if( dx == -dy )
{
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!
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)
*/
* Fonction surchargee!
* 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)
*/
{
float fpx, fpy;
int tmp;
while (angle < 0) angle += 3600;
while (angle >= 3600) angle -= 3600;
if (angle == 0) return;
/* Calcul des coord :
coord: xrot = y*sin + x*cos
yrot = y*cos - x*sin
*/
if( angle == 900 ) /* sin = 1, cos = 0 */
{
tmp = *pX;
*pX = *pY;
*pY = - tmp;
}
else if( angle == 1800 ) /* sin = 0, cos = -1 */
{
*pX = - *pX;
*pY = - *pY;
}
else if( angle == 2700 ) /* sin = -1, cos = 0 */
{
tmp = *pX;
*pX = - *pY;
*pY = tmp;
}
else
{
fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]);
fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]);
*pX = (int)round(fpx); *pY = (int)round(fpy);
}
float fpx, fpy;
int tmp;
while( angle < 0 )
angle += 3600;
while( angle >= 3600 )
angle -= 3600;
if( angle == 0 )
return;
/* Calcul des coord :
* coord: xrot = y*sin + x*cos
* yrot = y*cos - x*sin
*/
if( angle == 900 ) /* sin = 1, cos = 0 */
{
tmp = *pX;
*pX = *pY;
*pY = -tmp;
}
else if( angle == 1800 ) /* sin = 0, cos = -1 */
{
*pX = -*pX;
*pY = -*pY;
}
else if( angle == 2700 ) /* sin = -1, cos = 0 */
{
tmp = *pX;
*pX = -*pY;
*pY = tmp;
}
else
{
fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]);
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!
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)
*/
* Fonction surchargee!
* 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)
*/
{
int ox, oy;
int ox, oy;
ox = *pX - cx; oy = *pY - cy;
RotatePoint(&ox, &oy, angle);
*pX = ox + cx;
*pY = oy + cy;
ox = *pX - cx;
oy = *pY - 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!
calcule les nouvelles coord du point point,
pour une rotation de centre centre, et d'angle angle ( en 1/10 degre)
*/
* Fonction surchargee!
* calcule les nouvelles coord du point point,
* pour une rotation de centre centre, et d'angle angle ( en 1/10 degre)
*/
{
int ox, oy;
ox = point->x - centre.x; oy = point->y - centre.y;
RotatePoint(&ox, &oy, angle);
point->x = ox + centre.x;
point->y = oy + centre.y;
int ox, oy;
ox = point->x - centre.x;
oy = point->y - 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;
ox = *pX - cx; oy = *pY - cy;
RotatePoint(&ox, &oy, angle);
*pX = ox + cx;
*pY = oy + cy;
double ox, oy;
ox = *pX - cx;
oy = *pY - 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 :
coord: xrot = y*sin + x*cos
yrot = y*cos - x*sin
*/
* coord: xrot = y*sin + x*cos
* yrot = y*cos - x*sin
*/
{
double tmp;
while (angle < 0) angle += 3600;
while (angle >= 3600) angle -= 3600;
if (angle == 0) return;
if( angle == 900 ) /* sin = 1, cos = 0 */
{
tmp = *pX;
*pX = *pY;
*pY = - tmp;
}
else if( angle == 1800 ) /* sin = 0, cos = -1 */
{
*pX = - *pX;
*pY = - *pY;
}
else if( angle == 2700 ) /* sin = -1, cos = 0 */
{
tmp = *pX;
*pX = - *pY;
*pY = tmp;
}
else
{
double fpx = (*pY * fsinus[angle]) + (*pX * fcosinus[angle]);
double fpy = (*pY * fcosinus[angle]) - (*pX * fsinus[angle]);
*pX = fpx; *pY = fpy;
}
double tmp;
while( angle < 0 )
angle += 3600;
while( angle >= 3600 )
angle -= 3600;
if( angle == 0 )
return;
if( angle == 900 ) /* sin = 1, cos = 0 */
{
tmp = *pX;
*pX = *pY;
*pY = -tmp;
}
else if( angle == 1800 ) /* sin = 0, cos = -1 */
{
*pX = -*pX;
*pY = -*pY;
}
else if( angle == 2700 ) /* sin = -1, cos = 0 */
{
tmp = *pX;
*pX = -*pY;
*pY = tmp;
}
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:
const wxPoint& offset, int color,
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
};
......
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 : */
#define TEXT_is_REFERENCE 0
#define TEXT_is_VALUE 1
#define TEXT_is_DIVERS 2
#define TEXT_is_VALUE 1
#define TEXT_is_DIVERS 2
class TEXTE_MODULE: public EDA_BaseStruct
class TEXTE_MODULE : public EDA_BaseStruct
{
public:
int m_Layer; // layer number
int m_Width;
wxPoint m_Pos; // Real coord
wxPoint m_Pos0; // coord du debut du texte /ancre, orient 0
char m_Unused; // unused (reserved for future extensions)
char m_Miroir ; // vue normale / miroir
char m_NoShow; // 0: visible 1: invisible (bool)
char m_Type; // 0: ref,1: val, autre = 2..255
int m_Orient; // orientation en 1/10 degre
wxSize m_Size; // dimensions (en X et Y) du texte
wxString m_Text;
public:
TEXTE_MODULE(MODULE * parent, int text_type = TEXT_is_DIVERS );
~TEXTE_MODULE(void);
/* supprime du chainage la structure Struct */
void UnLink( void );
void Copy(TEXTE_MODULE * source); // copy structure
/* Gestion du texte */
void SetWidth(int new_width);
int GetLength(void); /* text length */
int Pitch(void); /* retourne le pas entre 2 caracteres */
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);
};
int m_Layer; // layer number
int m_Width;
wxPoint m_Pos; // Real coord
wxPoint m_Pos0; // coord du debut du texte /ancre, orient 0
char m_Unused; // unused (reserved for future extensions)
char m_Miroir; // vue normale / miroir
char m_NoShow; // 0: visible 1: invisible (bool)
char m_Type; // 0: ref,1: val, autre = 2..255
int m_Orient; // orientation en 1/10 degre
wxSize m_Size; // dimensions (en X et Y) du texte
wxString m_Text;
public:
TEXTE_MODULE( MODULE* parent, int text_type = TEXT_is_DIVERS );
~TEXTE_MODULE( void );
/* supprime du chainage la structure Struct */
void UnLink( void );
void Copy( TEXTE_MODULE* source ); // copy structure
/* Gestion du texte */
void SetWidth( int new_width );
int GetLength( void ); /* text length */
int Pitch( void ); /* retourne le pas entre 2 caracteres */
int GetDrawRotation( void ); // Return text rotation for drawings and plotting
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,
{
bool PopupOn = GetScreen()->m_CurrentItem
&& GetScreen()->m_CurrentItem->m_Flags;
bool ItemFree = (GetScreen()->m_CurrentItem == 0 )
|| (GetScreen()->m_CurrentItem->m_Flags == 0);
......@@ -63,10 +64,10 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
|| (GetScreen()->m_CurrentItem->m_Flags == 0);
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();
//don't let backspace delete modules!!
// don't let backspace delete modules!!
if( DrawStruct && (DrawStruct->m_StructType == TYPETRACK
|| DrawStruct->m_StructType == TYPEVIA) )
Delete_Segment( DC, (TRACK*) DrawStruct );
......@@ -74,7 +75,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
}
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 =
Delete_Segment( DC, (TRACK*) GetScreen()->m_CurrentItem );
GetScreen()->SetModify();
......@@ -97,7 +98,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
case 'O' + GR_KB_CTRL:
{
//try not to duplicate save, load code etc.
// try not to duplicate save, load code etc.
wxCommandEvent evt;
evt.SetId( ID_LOAD_FILE );
Files_io( evt );
......@@ -106,7 +107,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
case 'S' + GR_KB_CTRL:
{
//try not to duplicate save, load code etc.
// try not to duplicate save, load code etc.
wxCommandEvent evt;
evt.SetId( ID_SAVE_BOARD );
Files_io( evt );
......@@ -163,10 +164,18 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* DC, int hotkey,
if( module == NULL ) // no footprint found
{
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() )
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;
}
}
......
......@@ -426,7 +426,7 @@ EDA_BaseStruct* Locate_Cotation( BOARD* Pcb, int LayerSearch, int typeloc )
pt_txt = Cotation->m_Text;
if( pt_txt )
{
if( pt_txt->Locate( ref_pos ) )
if( pt_txt->HitTest( ref_pos ) )
return PtStruct;
}
......@@ -857,7 +857,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
// hit-test the reference text
pt_txt_mod = module->m_Reference;
if( pt_txt_mod->Locate( ref_pos ) )
if( pt_txt_mod->HitTest( ref_pos ) )
{
if( PtModule )
*PtModule = module;
......@@ -866,7 +866,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
// hit-test the value text
pt_txt_mod = module->m_Value;
if( pt_txt_mod->Locate( ref_pos ) )
if( pt_txt_mod->HitTest( ref_pos ) )
{
if( PtModule )
*PtModule = module;
......@@ -881,7 +881,7 @@ TEXTE_MODULE* LocateTexteModule( BOARD* Pcb, MODULE** PtModule, int typeloc )
continue;
pt_txt_mod = (TEXTE_MODULE*) PtStruct;
if( pt_txt_mod->Locate( ref_pos ) )
if( pt_txt_mod->HitTest( ref_pos ) )
{
if( PtModule )
*PtModule = module;
......@@ -1151,7 +1151,7 @@ TEXTE_PCB* Locate_Texte_Pcb( EDA_BaseStruct* PtStruct, int LayerSearch, int type
if( PtStruct->m_StructType != TYPETEXTE )
continue;
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 )
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