Commit 9fb2c9fe authored by charras's avatar charras

some code cleaning and comments translations. Added: EDA_Rect::Merge( EDA_Rect...

some code cleaning and comments translations. Added: EDA_Rect::Merge( EDA_Rect & aRect ) (see changelog)
parent ae459044
......@@ -5,6 +5,17 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2008-Mar-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
some code cleaning and comment translations.
added:
/** EDA_Rect::Merge( EDA_Rect & aRect )
* Modify Position and Size of this in order to contains the given rect
* mainly used to calculate bouding boxes
* @param aRect = given rect to merge with this
*/
2008-Mar-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+pcbnew
......
......@@ -9,6 +9,7 @@
#include "fctsys.h"
#include "gr_basic.h"
#include "trigo.h"
#include "macros.h"
#include "common.h"
#include "wxstruct.h"
#include "base_struct.h"
......@@ -115,14 +116,19 @@ void EDA_BaseStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
*/
{
}
#endif
// see base_struct.h
SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart,
INSPECTOR* inspector, const void* testData, const KICAD_T scanTypes[] )
INSPECTOR* inspector,
const void* testData,
const KICAD_T scanTypes[] )
{
EDA_BaseStruct* p = listStart;
for( ; p; p = p->Pnext )
{
if( SEARCH_QUIT == p->Visit( inspector, testData, scanTypes ) )
......@@ -140,11 +146,11 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData,
{
KICAD_T stype;
#if 0 && defined(DEBUG)
#if 0 && defined (DEBUG)
std::cout << GetClass().mb_str() << ' ';
#endif
for( const KICAD_T* p = scanTypes; (stype=*p) != EOT; ++p )
for( const KICAD_T* p = scanTypes; (stype = *p) != EOT; ++p )
{
// If caller wants to inspect my type
if( stype == Type() )
......@@ -160,7 +166,8 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData,
}
#if defined(DEBUG)
#if defined (DEBUG)
// A function that should have been in wxWidgets
std::ostream& operator<<( std::ostream& out, const wxSize& size )
{
......@@ -168,6 +175,7 @@ std::ostream& operator<<( std::ostream& out, const wxSize& size )
return out;
}
// A function that should have been in wxWidgets
std::ostream& operator<<( std::ostream& out, const wxPoint& pt )
{
......@@ -187,17 +195,18 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os )
{
// for now, make it look like XML:
wxString s = GetClass();
s = s + wxT(" ");
s = s + wxT( " " );
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">\n";
/*
EDA_BaseStruct* kid = m_Son;
for( ; kid; kid = kid->Pnext )
{
kid->Show( nestLevel+1, os );
}
* EDA_BaseStruct* kid = m_Son;
* for( ; kid; kid = kid->Pnext )
* {
* kid->Show( nestLevel+1, os );
* }
*/
NestedSpace( nestLevel+1, os ) << "Need ::Show() override\n";
NestedSpace( nestLevel + 1, os ) << "Need ::Show() override\n";
NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
}
......@@ -212,13 +221,14 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os )
**/
std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os )
{
for( int i=0; i<nestLevel; ++i )
for( int i = 0; i<nestLevel; ++i )
os << " "; // number of spaces here controls indent per nest level
return os;
}
#endif
#endif
/**************************************************/
......@@ -296,6 +306,7 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
return false;
}
/**
* Function HitTest (overlayed)
* tests if the given EDA_Rect intersect this object.
......@@ -311,6 +322,7 @@ bool EDA_TextStruct::HitTest( EDA_Rect& refArea )
return false;
}
/*******************************/
int EDA_TextStruct::Pitch()
/*******************************/
......@@ -701,10 +713,10 @@ bool EDA_Rect::Intersects( const EDA_Rect aRect ) const
{
// this logic taken from wxWidgets' geometry.cpp file:
int left = MAX( m_Pos.x , aRect.m_Pos.x );
int right = MIN( m_Pos.x+m_Size.x, aRect.m_Pos.x+aRect.m_Size.x );
int top = MAX( m_Pos.y , aRect.m_Pos.y );
int bottom = MIN( m_Pos.y+m_Size.y, aRect.m_Pos.y + aRect.m_Size.y );
int left = MAX( m_Pos.x, aRect.m_Pos.x );
int right = MIN( m_Pos.x + m_Size.x, aRect.m_Pos.x + aRect.m_Size.x );
int top = MAX( m_Pos.y, aRect.m_Pos.y );
int bottom = MIN( m_Pos.y + m_Size.y, aRect.m_Pos.y + aRect.m_Size.y );
if( left < right && top < bottom )
{
......@@ -750,6 +762,28 @@ EDA_Rect& EDA_Rect::Inflate( wxCoord dx, wxCoord dy )
}
/** Function Merge
* Modify Position and Size of this in order to contain the given rect
* mainly used to calculate bounding boxes
* @param aRect = given rect to merge with this
*/
void EDA_Rect::Merge( EDA_Rect& aRect )
{
Normalize(); // ensure width and height >= 0
EDA_Rect rect = aRect;
rect.Normalize(); // ensure width and height >= 0
wxPoint end = GetEnd();
wxPoint rect_end = rect.GetEnd();
// Change origin and size in order to contain the given rect
m_Pos.x = MIN( m_Pos.x, rect.m_Pos.x );
m_Pos.y = MIN( m_Pos.y, rect.m_Pos.y );
end.x = MAX( end.x, rect_end.x );
end.y = MAX( end.y, rect_end.y );
SetEnd( end );
}
/**************************/
/* class DrawPickedStruct */
/**************************/
......@@ -791,4 +825,3 @@ void DrawPickedStruct::DeleteWrapperList()
delete wrapp_struct;
}
}
......@@ -194,12 +194,20 @@ public:
operator wxRect() const { return wxRect( m_Pos, m_Size ); }
EDA_Rect& Inflate( wxCoord dx, wxCoord dy );
/** Function Merge
* Modify Position and Size of this in order to contain the given rect
* mainly used to calculate bounding boxes
* @param aRect = given rect to merge with this
*/
void Merge( EDA_Rect & aRect );
};
/********************************************************************/
/* Classes de base: servent a deriver les classes reellement utiles */
/********************************************************************/
/******************************************************/
/* Basic Classes : used classes are derived from them */
/******************************************************/
/** class EDA_BaseStruct
* Basic class, not directly used.
......
......@@ -107,7 +107,7 @@ MODULE::~MODULE()
{
NextStruct = Struct->Pnext;
switch( (Struct->Type()) )
switch( ( Struct->Type() ) )
{
case TYPEEDGEMODULE:
delete (EDGE_MODULE*) Struct;
......@@ -279,7 +279,7 @@ void MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
EDA_BaseStruct* PtStruct;
TEXTE_MODULE* PtTexte;
if ( (m_Flags & DO_NOT_DRAW) )
if( (m_Flags & DO_NOT_DRAW) )
return;
/* Draw pads */
......@@ -328,6 +328,7 @@ void MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
void MODULE::DrawEdgesOnly( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& offset, int draw_mode )
/**************************************************************/
/** Function DrawEdgesOnly
* Draws the footprint edges only to the current Device Context
* @param panel = The active Draw Panel (used to know the clip box)
......@@ -397,7 +398,7 @@ bool MODULE::Save( FILE* aFile ) const
}
fprintf( aFile, "Sc %8.8lX\n", m_TimeStamp );
fprintf( aFile, "AR %s\n", CONV_TO_UTF8(m_Path) );
fprintf( aFile, "AR %s\n", CONV_TO_UTF8( m_Path ) );
fprintf( aFile, "Op %X %X 0\n", m_CntRot90, m_CntRot180 );
// attributes
......@@ -420,7 +421,7 @@ bool MODULE::Save( FILE* aFile ) const
goto out;
// save drawing elements
for( item=m_Drawings; item; item=item->Next() )
for( item = m_Drawings; item; item = item->Next() )
{
switch( item->Type() )
{
......@@ -431,7 +432,7 @@ bool MODULE::Save( FILE* aFile ) const
break;
default:
#if defined(DEBUG)
#if defined (DEBUG)
printf( "MODULE::Save() ignoring type %d\n", item->Type() );
#endif
break;
......@@ -439,7 +440,7 @@ bool MODULE::Save( FILE* aFile ) const
}
// save the pads
for( item=m_Pads; item; item=item->Next() )
for( item = m_Pads; item; item = item->Next() )
if( !item->Save( aFile ) )
goto out;
......@@ -633,7 +634,7 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
m_ModuleStatus = 0;
if( BufCar1[0] == 'F' )
SetLocked(true);
SetLocked( true );
if( BufCar1[1] == 'P' )
m_ModuleStatus |= MODULE_is_PLACED;
break;
......@@ -667,17 +668,19 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
break;
case 'A':
if(Line[1] == 't'){
if( Line[1] == 't' )
{
/* At = (At)tributs du module */
if( strstr( PtLine, "SMD" ) )
m_Attributs |= MOD_CMS;
if( strstr( PtLine, "VIRTUAL" ) )
m_Attributs |= MOD_VIRTUAL;
}
if(Line[1] == 'R'){
if( Line[1] == 'R' )
{
//alternate reference, e.g. /478C2408/478AD1B6
sscanf( PtLine, " %s", BufLine );
m_Path = CONV_FROM_UTF8(BufLine);
m_Path = CONV_FROM_UTF8( BufLine );
}
break;
......@@ -1054,53 +1057,31 @@ void MODULE::SetRectangleExinscrit()
*/
EDA_Rect MODULE::GetBoundingBox()
{
// Calculate area without text fielsd:
// Calculate area without text fields:
SetRectangleExinscrit();
EDA_Rect area = m_RealBoundaryBox;
area.Normalize();
// Calculate extended area including text field:
EDGE_MODULE* EdgeMod = (EDGE_MODULE*) m_Drawings;
TEXTE_MODULE* text;
EDA_Rect text_area;
wxPoint textstart, textend;
wxPoint modstart = area.GetOrigin();
wxPoint modend = area.GetEnd();
for( int ii = 0 ; ; ii++ )
{
if ( ii == 0 )
text = m_Reference;
else if ( ii == 1 )
text = m_Value;
else
text_area = m_Reference->GetBoundingBox();
area.Merge( text_area );
text_area = m_Value->GetBoundingBox();
area.Merge( text_area );
EDGE_MODULE* EdgeMod = (EDGE_MODULE*) m_Drawings;
for( ; EdgeMod != NULL; EdgeMod = (EDGE_MODULE*) EdgeMod->Pnext )
{
if ( EdgeMod == NULL ) break;
text = (TEXTE_MODULE*) EdgeMod;
EdgeMod = (EDGE_MODULE*) EdgeMod->Pnext;
if( text->Type() != TYPETEXTEMODULE )
if( EdgeMod->Type() != TYPETEXTEMODULE )
continue;
text_area = ((TEXTE_MODULE*)EdgeMod)->GetBoundingBox();
area.Merge( text_area );
}
text_area = text->GetTextRect();
textstart = text_area.GetOrigin();
textend = text_area.GetEnd();
int angle = text->GetDrawRotation();
RotatePoint( &textstart, text->m_Pos, angle);
RotatePoint( &textend, text->m_Pos, angle);
modstart.x = min( modstart.x, textstart.x);
modstart.x = min( modstart.x, textend.x);
modstart.y = min( modstart.y, textstart.y);
modstart.y = min( modstart.y, textend.y);
modend.x = max( modend.x, textstart.x);
modend.x = max( modend.x, textend.x);
modend.y = max( modend.y, textstart.y);
modend.y = max( modend.y, textend.y);
}
area.SetOrigin(modstart);
area.SetEnd(modend);
return area;
}
/*******************************************************/
void MODULE::Display_Infos( WinEDA_DrawFrame* frame )
/*******************************************************/
......@@ -1135,7 +1116,7 @@ void MODULE::Display_Infos( WinEDA_DrawFrame* frame )
else
{
msg.Printf( wxT( "%8.8lX" ), m_TimeStamp );
Affiche_1_Parametre( frame, pos, _( "Netlist path" ), /*msg*/m_Path, BROWN );
Affiche_1_Parametre( frame, pos, _( "Netlist path" ), /*msg*/ m_Path, BROWN );
}
pos += 12;
......@@ -1238,6 +1219,7 @@ D_PAD* MODULE::FindPadByName( const wxString& aPadName ) const
#else
if( buf == aPadName )
#endif
return pad;
}
......@@ -1254,13 +1236,14 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T* p = scanTypes;
bool done = false;
#if 0 && defined(DEBUG)
#if 0 && defined (DEBUG)
std::cout << GetClass().mb_str() << ' ';
#endif
while( !done )
{
stype = *p;
switch( stype )
{
case TYPEMODULE:
......@@ -1286,18 +1269,23 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
case TYPEEDGEMODULE:
result = IterateForward( m_Drawings, inspector, testData, p );
// skip over any types handled in the above call.
for(;;)
for( ; ; )
{
switch( stype = *++p )
{
case TYPETEXTEMODULE:
case TYPEEDGEMODULE:
continue;
default: ;
default:
;
}
break;
}
break;
default:
......@@ -1313,7 +1301,8 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
}
#if defined(DEBUG)
#if defined (DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
......@@ -1329,35 +1318,38 @@ void MODULE::Show( int nestLevel, std::ostream& os )
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
" ref=\"" << m_Reference->m_Text.mb_str() << '"' <<
" value=\"" << m_Value->m_Text.mb_str() << '"' <<
" layer=\"" << board->GetLayerName(m_Layer).mb_str() << '"' <<
" layer=\"" << board->GetLayerName( m_Layer ).mb_str() << '"' <<
">\n";
NestedSpace( nestLevel+1, os ) <<
NestedSpace( nestLevel + 1, os ) <<
"<boundingBox" << m_BoundaryBox.m_Pos << m_BoundaryBox.m_Size << "/>\n";
NestedSpace( nestLevel+1, os ) << "<orientation tenths=\"" << m_Orient << "\"/>\n";
NestedSpace( nestLevel + 1, os ) << "<orientation tenths=\"" << m_Orient << "\"/>\n";
EDA_BaseStruct* p;
NestedSpace( nestLevel+1, os ) << "<mpads>\n";
NestedSpace( nestLevel + 1, os ) << "<mpads>\n";
p = m_Pads;
for( ; p; p = p->Pnext )
p->Show( nestLevel+2, os );
NestedSpace( nestLevel+1, os ) << "</mpads>\n";
p->Show( nestLevel + 2, os );
NestedSpace( nestLevel + 1, os ) << "</mpads>\n";
NestedSpace( nestLevel+1, os ) << "<mdrawings>\n";
NestedSpace( nestLevel + 1, os ) << "<mdrawings>\n";
p = m_Drawings;
for( ; p; p = p->Pnext )
p->Show( nestLevel+2, os );
NestedSpace( nestLevel+1, os ) << "</mdrawings>\n";
p->Show( nestLevel + 2, os );
NestedSpace( nestLevel + 1, os ) << "</mdrawings>\n";
p = m_Son;
for( ; p; p = p->Pnext )
{
p->Show( nestLevel+1, os );
p->Show( nestLevel + 1, os );
}
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
}
#endif
......@@ -158,6 +158,13 @@ public:
int Read_3D_Descr( FILE* File, int* LineNum = NULL );
/* drawing functions */
/** Function Draw
* Draw the text accordint to the footprint pos and orient
* @param panel = draw panel, Used to know the clip box
* @param DC = Current Device Context
* @param offset = draw offset (usually wxPoint(0,0)
* @param draw_mode = GR_OR, GR_XOR..
*/
void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& offset, int draw_mode );
void Draw3D( Pcb3D_GLCanvas* glcanvas );
......
......@@ -101,11 +101,12 @@ void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) // copy structure
m_Pos = source->m_Pos;
SetLayer( source->GetLayer() );
m_Miroir = source->m_Miroir; // vue normale / miroir
m_Miroir = source->m_Miroir; // Show normal / mirror
m_NoShow = source->m_NoShow; // 0: visible 1: invisible
m_Type = source->m_Type; // 0: ref,1: val, autre = 2..255
m_Orient = source->m_Orient; // orientation en 1/10 degre
m_Pos0 = source->m_Pos0; // coord du debut du texte /ancre, orient 0
m_Type = source->m_Type; // 0: ref,1: val, others = 2..255
m_Orient = source->m_Orient; // orientation in 1/10 deg
m_Pos0 = source->m_Pos0; // text coordinates relatives to the footprint ancre, orient 0
// Text coordinate ref point is the text centre
m_Size = source->m_Size;
m_Width = source->m_Width;
......@@ -114,8 +115,8 @@ void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) // copy structure
}
/* supprime du chainage la structure Struct
* les structures arrieres et avant sont chainees directement
/* Remove this from the linked list
* Update Pback and Pnext pointers
*/
void TEXTE_MODULE::UnLink()
{
......@@ -156,7 +157,7 @@ void TEXTE_MODULE:: SetWidth( int new_width )
}
// mise a jour des coordonn�s absolues pour affichage
// Update draw ccordinates
void TEXTE_MODULE:: SetDrawCoord()
{
MODULE* Module = (MODULE*) m_Parent;
......@@ -175,7 +176,7 @@ void TEXTE_MODULE:: SetDrawCoord()
}
// mise a jour des coordonn�s relatives au module
// Update "local" cooedinates (coordinates relatives to the footprint anchor point)
void TEXTE_MODULE:: SetLocalCoord()
{
MODULE* Module = (MODULE*) m_Parent;
......@@ -219,45 +220,62 @@ EDA_Rect TEXTE_MODULE::GetTextRect(void)
return area;
}
bool TEXTE_MODULE::HitTest( const wxPoint& posref )
/**
* 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 TEXTE_MODULE::HitTest( const wxPoint& refPos )
{
int mX, mY, dx, dy;
MODULE* Module = (MODULE*) m_Parent;
int angle = m_Orient;
if( Module )
angle += Module->m_Orient;
dx = ( m_Size.x * GetLength() ) / 2;
dx = (dx * 10) / 9; /* Facteur de forme des lettres : 10/9 */
dx += m_Width / 2;
dy = ( m_Size.y + m_Width ) / 2;
wxPoint rel_pos;
EDA_Rect area = GetTextRect();
/* le point de reference est tourn�de - angle
* pour se ramener a un rectangle de reference horizontal */
mX = posref.x - m_Pos.x;
mY = posref.y - m_Pos.y;
RotatePoint( &mX, &mY, -angle );
/* Rotate refPos to - angle
* to test if refPos is within area (which is relative to an horizontal text)
*/
rel_pos = refPos;
RotatePoint( &rel_pos, m_Pos, - GetDrawRotation() );
/* le point de reference est-il dans ce rectangle */
if( ( abs( mX ) <= abs( dx ) ) && ( abs( mY ) <= abs( dy ) ) )
{
if( area.Inside(rel_pos) )
return true;
}
return false;
}
/**
* Function GetBoundingBox
* returns the bounding box of this Text (according to text and footprint orientation)
*/
EDA_Rect TEXTE_MODULE::GetBoundingBox()
{
// Calculate area without text fielsd:
EDA_Rect text_area;
int angle = GetDrawRotation();
wxPoint textstart, textend;
text_area = GetTextRect();
textstart = text_area.GetOrigin();
textend = text_area.GetEnd();
RotatePoint( &textstart, m_Pos, angle);
RotatePoint( &textend, m_Pos, angle);
text_area.SetOrigin(textstart);
text_area.SetEnd(textend);
text_area.Normalize();
return text_area;
}
/******************************************************************************************/
void TEXTE_MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC, wxPoint offset, int draw_mode )
/******************************************************************************************/
/* trace 1 texte de module
* Utilise la police definie dans grfonte.h
* (Se reporter a ce fichier pour les explications complementaires)
* offset = offset de trace ( reference au centre du texte)
* draw_mode = GR_OR, GR_XOR..
/** Function Draw
* Draw the text accordint to the footprint pos and orient
* @param panel = draw panel, Used to know the clip box
* @param DC = Current Device Context
* @param offset = draw offset (usually wxPoint(0,0)
* @param draw_mode = GR_OR, GR_XOR..
*/
{
int zoom;
......
......@@ -16,15 +16,17 @@
class TEXTE_MODULE : public BOARD_ITEM
{
public:
wxPoint m_Pos; // Real coord
wxPoint m_Pos; // Real (physical)coord
int m_Width;
wxPoint m_Pos0; // coord du debut du texte /ancre, orient 0
wxPoint m_Pos0; // text coordinates relatives to the footprint ancre, orient 0
// Text coordinate ref point is the text centre
char m_Unused; // unused (reserved for future extensions)
char m_Miroir; // vue normale / miroir
char m_Miroir; // Show normal / mirror
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
char m_Type; // 0: ref,1: val, others = 2..255
int m_Orient; // orientation in 1/10 deg relative to the footprint
// Physical orient is m_Orient + m_Parent->m_Orient
wxSize m_Size; // text size
wxString m_Text;
public:
......@@ -55,10 +57,16 @@ public:
int GetDrawRotation(); // Return text rotation for drawings and plotting
/** Function GetTextRect
* @return an EDA_Rect which gives the position and size of the text area (for the O orient text and footprint)
* @return an EDA_Rect which gives the position and size of the text area (for the 0 orient text and footprint)
*/
EDA_Rect GetTextRect(void);
/**
* Function GetBoundingBox
* returns the bounding box of this Text (according to text and footprint orientation)
*/
EDA_Rect GetBoundingBox();
void SetDrawCoord(); // mise a jour des coordonn�s absolues de trac�
// a partir des coord relatives
......
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