Remove redundant bounding box calculation code from pcbnew.

This commit is contained in:
Marco Mattila 2011-09-02 00:39:38 +03:00
parent 2b216bcc39
commit b8c2e4dd6c
7 changed files with 96 additions and 333 deletions

View File

@ -198,7 +198,6 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb )
for( ; Module != NULL; Module = Module->Next() ) for( ; Module != NULL; Module = Module->Next() )
{ {
Module->Set_Rectangle_Encadrement(); Module->Set_Rectangle_Encadrement();
Module->SetRectangleExinscrit();
moduleList.push_back(Module); moduleList.push_back(Module);
} }
sort( moduleList.begin(), moduleList.end(), sortModulesbySize ); sort( moduleList.begin(), moduleList.end(), sortModulesbySize );
@ -254,12 +253,12 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb )
} }
GetScreen()->SetCrossHairPosition( current + Module->m_Pos - GetScreen()->SetCrossHairPosition( current + Module->m_Pos -
Module->m_RealBoundaryBox.GetPosition() ); Module->m_BoundaryBox.GetPosition() );
Ymax_size = MAX( Ymax_size, Module->m_RealBoundaryBox.GetHeight() ); Ymax_size = MAX( Ymax_size, Module->m_BoundaryBox.GetHeight() );
Place_Module( Module, NULL, true ); Place_Module( Module, NULL, true );
current.x += Module->m_RealBoundaryBox.GetWidth() + pas_grille; current.x += Module->m_BoundaryBox.GetWidth() + pas_grille;
} }
DrawPanel->Refresh(); DrawPanel->Refresh();

View File

@ -122,7 +122,6 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
for( ; Module != NULL; Module = Module->Next() ) for( ; Module != NULL; Module = Module->Next() )
{ {
Module->Set_Rectangle_Encadrement(); Module->Set_Rectangle_Encadrement();
Module->SetRectangleExinscrit();
NbTotalModules ++; NbTotalModules ++;
} }
@ -204,7 +203,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
{ {
int Angle_Rot_Module = 1800; int Angle_Rot_Module = 1800;
Rotate_Module( DC, Module, Angle_Rot_Module, false ); Rotate_Module( DC, Module, Angle_Rot_Module, false );
Module->SetRectangleExinscrit(); Module->Set_Rectangle_Encadrement();
error = RecherchePlacementModule( Module, DC ); error = RecherchePlacementModule( Module, DC );
MinCout *= OrientPenality[ii]; MinCout *= OrientPenality[ii];
if( BestScore > MinCout ) /* This orientation is best. */ if( BestScore > MinCout ) /* This orientation is best. */
@ -277,7 +276,6 @@ end_of_tst:
GetScreen()->SetCrossHairPosition( CurrPosition ); GetScreen()->SetCrossHairPosition( CurrPosition );
Module->Set_Rectangle_Encadrement(); Module->Set_Rectangle_Encadrement();
Module->SetRectangleExinscrit();
GenModuleOnBoard( Module ); GenModuleOnBoard( Module );
Module->m_ModuleStatus |= MODULE_is_PLACED; Module->m_ModuleStatus |= MODULE_is_PLACED;
@ -491,10 +489,10 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module )
int masque_layer; int masque_layer;
D_PAD* Pad; D_PAD* Pad;
ox = Module->m_RealBoundaryBox.m_Pos.x - marge; ox = Module->m_BoundaryBox.m_Pos.x - marge;
fx = Module->m_RealBoundaryBox.GetRight() + marge; fx = Module->m_BoundaryBox.GetRight() + marge;
oy = Module->m_RealBoundaryBox.m_Pos.y - marge; oy = Module->m_BoundaryBox.m_Pos.y - marge;
fy = Module->m_RealBoundaryBox.GetBottom() + marge; fy = Module->m_BoundaryBox.GetBottom() + marge;
if( ox < GetBoard()->m_BoundaryBox.m_Pos.x ) if( ox < GetBoard()->m_BoundaryBox.m_Pos.x )
ox = GetBoard()->m_BoundaryBox.m_Pos.x; ox = GetBoard()->m_BoundaryBox.m_Pos.x;
@ -571,10 +569,10 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
LastPosOK.y = GetBoard()->m_BoundaryBox.m_Pos.y; LastPosOK.y = GetBoard()->m_BoundaryBox.m_Pos.y;
cx = Module->m_Pos.x; cy = Module->m_Pos.y; cx = Module->m_Pos.x; cy = Module->m_Pos.y;
ox = Module->m_RealBoundaryBox.m_Pos.x - cx; ox = Module->m_BoundaryBox.m_Pos.x - cx;
fx = Module->m_RealBoundaryBox.m_Size.x + ox; fx = Module->m_BoundaryBox.m_Size.x + ox;
oy = Module->m_RealBoundaryBox.m_Pos.y - cy; oy = Module->m_BoundaryBox.m_Pos.y - cy;
fy = Module->m_RealBoundaryBox.m_Size.y + oy; fy = Module->m_BoundaryBox.m_Size.y + oy;
CurrPosition.x = GetBoard()->m_BoundaryBox.m_Pos.x - ox; CurrPosition.x = GetBoard()->m_BoundaryBox.m_Pos.x - ox;
CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy; CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy;
@ -626,8 +624,8 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
} }
cx = Module->m_Pos.x; cy = Module->m_Pos.y; cx = Module->m_Pos.x; cy = Module->m_Pos.y;
Module->m_RealBoundaryBox.m_Pos.x = ox + CurrPosition.x; Module->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x;
Module->m_RealBoundaryBox.m_Pos.y = oy + CurrPosition.y; Module->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y;
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, DC, Module );
@ -646,8 +644,8 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
if( DisplayChevelu ) if( DisplayChevelu )
Compute_Ratsnest_PlaceModule( DC ); Compute_Ratsnest_PlaceModule( DC );
DisplayChevelu = 0; DisplayChevelu = 0;
Module->m_RealBoundaryBox.m_Pos.x = ox + CurrPosition.x; Module->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x;
Module->m_RealBoundaryBox.m_Pos.y = oy + CurrPosition.y; Module->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y;
g_Offset_Module.y = cy - CurrPosition.y; g_Offset_Module.y = cy - CurrPosition.y;
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, DC, Module );
@ -683,8 +681,8 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
Compute_Ratsnest_PlaceModule( DC ); Compute_Ratsnest_PlaceModule( DC );
/* Regeneration of the modified variable. */ /* Regeneration of the modified variable. */
Module->m_RealBoundaryBox.m_Pos.x = ox + cx; Module->m_BoundaryBox.m_Pos.x = ox + cx;
Module->m_RealBoundaryBox.m_Pos.y = oy + cy; Module->m_BoundaryBox.m_Pos.y = oy + cy;
CurrPosition = LastPosOK; CurrPosition = LastPosOK;
GetBoard()->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK ); GetBoard()->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK );
@ -807,10 +805,10 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide )
side = BOTTOM; otherside = TOP; side = BOTTOM; otherside = TOP;
} }
ox = Module->m_RealBoundaryBox.m_Pos.x; ox = Module->m_BoundaryBox.m_Pos.x;
fx = Module->m_RealBoundaryBox.GetRight(); fx = Module->m_BoundaryBox.GetRight();
oy = Module->m_RealBoundaryBox.m_Pos.y; oy = Module->m_BoundaryBox.m_Pos.y;
fy = Module->m_RealBoundaryBox.GetBottom(); fy = Module->m_BoundaryBox.GetBottom();
error = TstRectangle( Pcb, ox, oy, fx, fy, side ); error = TstRectangle( Pcb, ox, oy, fx, fy, side );
if( error < 0 ) if( error < 0 )
@ -1031,7 +1029,6 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC )
for( ; Module != NULL; Module = Module->Next() ) for( ; Module != NULL; Module = Module->Next() )
{ {
Module->Set_Rectangle_Encadrement(); Module->Set_Rectangle_Encadrement();
Module->SetRectangleExinscrit();
moduleList.push_back(Module); moduleList.push_back(Module);
} }
sort( moduleList.begin(), moduleList.end(), Tri_PlaceModules ); sort( moduleList.begin(), moduleList.end(), Tri_PlaceModules );

View File

@ -761,94 +761,20 @@ unsigned BOARD::GetNodesCount()
bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly )
{ {
int rayon, cx, cy, d, xmin, ymin, xmax, ymax;
bool hasItems = false; bool hasItems = false;
EDA_RECT area;
xmin = ymin = INT_MAX;
xmax = ymax = INT_MIN;
// Check segments, dimensions, texts, and fiducials // Check segments, dimensions, texts, and fiducials
for( EDA_ITEM* PtStruct = m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Next() ) for( BOARD_ITEM* item = m_Drawings; item != NULL; item = item->Next() )
{ {
switch( PtStruct->Type() ) if( aBoardEdgesOnly && item->Type() != TYPE_DRAWSEGMENT && item->GetLayer() != EDGE_N )
{ continue;
case TYPE_DRAWSEGMENT:
{
DRAWSEGMENT* ptr;
ptr = (DRAWSEGMENT*) PtStruct;
d = (ptr->m_Width / 2) + 1;
if( aBoardEdgesOnly && ptr->GetLayer() != EDGE_N ) if( !hasItems )
break; area = item->GetBoundingBox();
else
if( ptr->m_Shape == S_CIRCLE ) area.Merge( item->GetBoundingBox() );
{ hasItems = true;
cx = ptr->m_Start.x; cy = ptr->m_Start.y;
rayon = (int) hypot( (double) ( ptr->m_End.x - cx ),
(double) ( ptr->m_End.y - cy ) );
rayon += d;
xmin = MIN( xmin, cx - rayon );
ymin = MIN( ymin, cy - rayon );
xmax = MAX( xmax, cx + rayon );
ymax = MAX( ymax, cy + rayon );
hasItems = true;
}
else
{
cx = MIN( ptr->m_Start.x, ptr->m_End.x );
cy = MIN( ptr->m_Start.y, ptr->m_End.y );
xmin = MIN( xmin, cx - d );
ymin = MIN( ymin, cy - d );
cx = MAX( ptr->m_Start.x, ptr->m_End.x );
cy = MAX( ptr->m_Start.y, ptr->m_End.y );
xmax = MAX( xmax, cx + d );
ymax = MAX( ymax, cy + d );
hasItems = true;
}
break;
}
case TYPE_DIMENSION:
{
if( aBoardEdgesOnly )
break;
EDA_RECT rect = ((DIMENSION*) PtStruct)->GetBoundingBox();
xmin = MIN( xmin, rect.GetX() );
ymin = MIN( ymin, rect.GetY() );
xmax = MAX( xmax, rect.GetRight() );
ymax = MAX( ymax, rect.GetBottom() );
hasItems = true;
break;
}
case TYPE_TEXTE:
{
if( aBoardEdgesOnly )
break;
EDA_RECT rect = ((TEXTE_PCB*) PtStruct)->GetTextBox( -1 );
xmin = MIN( xmin, rect.GetX() );
ymin = MIN( ymin, rect.GetY() );
xmax = MAX( xmax, rect.GetRight() );
ymax = MAX( ymax, rect.GetBottom() );
hasItems = true;
break;
}
case TYPE_MIRE:
{
if( aBoardEdgesOnly )
break;
EDA_RECT rect = ((DIMENSION*) PtStruct)->GetBoundingBox();
xmin = MIN( xmin, rect.GetX() );
ymin = MIN( ymin, rect.GetY() );
xmax = MAX( xmax, rect.GetRight() );
ymax = MAX( ymax, rect.GetBottom() );
hasItems = true;
break;
}
default:
break;
}
} }
if( !aBoardEdgesOnly ) if( !aBoardEdgesOnly )
@ -856,41 +782,30 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly )
// Check modules // Check modules
for( MODULE* module = m_Modules; module; module = module->Next() ) for( MODULE* module = m_Modules; module; module = module->Next() )
{ {
EDA_RECT bBox = module->GetBoundingBox(); if( !hasItems )
xmin = MIN( xmin, bBox.GetX() ); area = module->GetBoundingBox();
ymin = MIN( ymin, bBox.GetY() ); else
xmax = MAX( xmax, bBox.GetRight() ); area.Merge( module->GetBoundingBox() );
ymax = MAX( ymax, bBox.GetBottom() );
hasItems = true; hasItems = true;
} }
// Check tracks // Check tracks
for( TRACK* track = m_Track; track; track = track->Next() ) for( TRACK* track = m_Track; track; track = track->Next() )
{ {
d = ( track->m_Width / 2 ) + 1; if( !hasItems )
cx = MIN( track->m_Start.x, track->m_End.x ); area = track->GetBoundingBox();
cy = MIN( track->m_Start.y, track->m_End.y ); else
xmin = MIN( xmin, cx - d ); area.Merge( track->GetBoundingBox() );
ymin = MIN( ymin, cy - d );
cx = MAX( track->m_Start.x, track->m_End.x );
cy = MAX( track->m_Start.y, track->m_End.y );
xmax = MAX( xmax, cx + d );
ymax = MAX( ymax, cy + d );
hasItems = true; hasItems = true;
} }
// Check segment zones // Check segment zones
for( TRACK* track = m_Zone; track; track = track->Next() ) for( TRACK* track = m_Zone; track; track = track->Next() )
{ {
d = ( track->m_Width / 2 ) + 1; if( !hasItems )
cx = MIN( track->m_Start.x, track->m_End.x ); area = track->GetBoundingBox();
cy = MIN( track->m_Start.y, track->m_End.y ); else
xmin = MIN( xmin, cx - d ); area.Merge( track->GetBoundingBox() );
ymin = MIN( ymin, cy - d );
cx = MAX( track->m_Start.x, track->m_End.x );
cy = MAX( track->m_Start.y, track->m_End.y );
xmax = MAX( xmax, cx + d );
ymax = MAX( ymax, cy + d );
hasItems = true; hasItems = true;
} }
@ -898,11 +813,12 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly )
for( unsigned int i = 0; i < m_ZoneDescriptorList.size(); i++ ) for( unsigned int i = 0; i < m_ZoneDescriptorList.size(); i++ )
{ {
ZONE_CONTAINER* aZone = m_ZoneDescriptorList[i]; ZONE_CONTAINER* aZone = m_ZoneDescriptorList[i];
EDA_RECT bBox = aZone->GetBoundingBox();
xmin = MIN( xmin, bBox.GetX() ); if( !hasItems )
ymin = MIN( ymin, bBox.GetY() ); area = aZone->GetBoundingBox();
xmax = MAX( xmax, bBox.GetRight() ); else
ymax = MAX( ymax, bBox.GetBottom() ); area.Merge( aZone->GetBoundingBox() );
area.Merge( aZone->GetBoundingBox() );
hasItems = true; hasItems = true;
} }
} }
@ -911,23 +827,20 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly )
{ {
if( m_PcbFrame->m_Draw_Sheet_Ref ) if( m_PcbFrame->m_Draw_Sheet_Ref )
{ {
xmin = ymin = 0; area.SetOrigin( 0, 0 );
xmax = m_PcbFrame->GetScreen()->ReturnPageSize().x; area.SetEnd( m_PcbFrame->GetScreen()->ReturnPageSize().x,
ymax = m_PcbFrame->GetScreen()->ReturnPageSize().y; m_PcbFrame->GetScreen()->ReturnPageSize().y );
} }
else else
{ {
xmin = -m_PcbFrame->GetScreen()->ReturnPageSize().x / 2; area.SetOrigin( -m_PcbFrame->GetScreen()->ReturnPageSize().x / 2,
ymin = -m_PcbFrame->GetScreen()->ReturnPageSize().y / 2; -m_PcbFrame->GetScreen()->ReturnPageSize().y / 2 );
xmax = m_PcbFrame->GetScreen()->ReturnPageSize().x / 2; area.SetEnd( m_PcbFrame->GetScreen()->ReturnPageSize().x / 2,
ymax = m_PcbFrame->GetScreen()->ReturnPageSize().y / 2; m_PcbFrame->GetScreen()->ReturnPageSize().y / 2 );
} }
} }
m_BoundaryBox.SetX( xmin ); m_BoundaryBox = area;
m_BoundaryBox.SetY( ymin );
m_BoundaryBox.SetWidth( xmax - xmin );
m_BoundaryBox.SetHeight( ymax - ymin );
return hasItems; return hasItems;
} }

View File

@ -623,94 +623,10 @@ int MODULE::ReadDescr( LINE_READER* aReader )
} }
/* Update the bounding rectangle of the module
*
* The bounding box includes outlines and pads, but not the fields.
* The rectangle is:
* for orientation 0
* coordinates relative to the module anchor.
*/
void MODULE::Set_Rectangle_Encadrement() void MODULE::Set_Rectangle_Encadrement()
{ {
int width; m_BoundaryBox = GetFootPrintRect();
int cx, cy, uxf, uyf, rayon; m_Surface = ABS( (double) m_BoundaryBox.GetWidth() * m_BoundaryBox.GetHeight() );
int xmax, ymax;
int xmin, ymin;
/* Initial coordinates of the module has a nonzero limit value. */
xmin = ymin = -250;
xmax = ymax = 250;
for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst();
edge; edge = edge->Next() )
{
if( edge->Type() != TYPE_EDGE_MODULE )
continue;
width = edge->m_Width / 2;
switch( edge->m_Shape )
{
case S_ARC:
case S_CIRCLE:
{
cx = edge->m_Start0.x;
cy = edge->m_Start0.y; // center
uxf = edge->m_End0.x;
uyf = edge->m_End0.y;
rayon = (int) hypot( (double) ( cx - uxf ), (double) ( cy - uyf ) );
rayon += width;
xmin = MIN( xmin, cx - rayon );
ymin = MIN( ymin, cy - rayon );
xmax = MAX( xmax, cx + rayon );
ymax = MAX( ymax, cy + rayon );
break;
}
case S_SEGMENT:
xmin = MIN( xmin, edge->m_Start0.x - width );
xmin = MIN( xmin, edge->m_End0.x - width );
ymin = MIN( ymin, edge->m_Start0.y - width );
ymin = MIN( ymin, edge->m_End0.y - width );
xmax = MAX( xmax, edge->m_Start0.x + width );
xmax = MAX( xmax, edge->m_End0.x + width );
ymax = MAX( ymax, edge->m_Start0.y + width );
ymax = MAX( ymax, edge->m_End0.y + width );
break;
case S_POLYGON:
{
std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
for( unsigned ii = 0; ii < polyPoints.size(); ii++ )
{
wxPoint pt = polyPoints[ii];
xmin = MIN( xmin, (pt.x - width) );
ymin = MIN( ymin, (pt.y - width) );
xmax = MAX( xmax, (pt.x + width) );
ymax = MAX( ymax, (pt.y + width) );
}
break;
}
}
}
/* Pads: find the min and max coordinates and update the bounding box.
*/
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )
{
rayon = pad->m_ShapeMaxRadius;
cx = pad->m_Pos0.x;
cy = pad->m_Pos0.y;
xmin = MIN( xmin, cx - rayon );
ymin = MIN( ymin, cy - rayon );
xmax = MAX( xmax, cx + rayon );
ymax = MAX( ymax, cy + rayon );
}
m_BoundaryBox.m_Pos.x = xmin;
m_BoundaryBox.m_Pos.y = ymin;
m_BoundaryBox.SetWidth( xmax - xmin );
m_BoundaryBox.SetHeight( ymax - ymin );
} }
@ -723,60 +639,27 @@ EDA_RECT MODULE::GetFootPrintRect() const
area.Inflate( 500 ); // Give a min size area.Inflate( 500 ); // Give a min size
for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst(); edge; edge = edge->Next() ) for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst(); edge; edge = edge->Next() )
{ if( edge->Type() == TYPE_TEXTE_MODULE )
if( edge->Type() != TYPE_EDGE_MODULE ) // Should not occur area.Merge( edge->GetBoundingBox() );
continue;
area.Merge( edge->GetBoundingBox() );
}
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() ) for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )
{
area.Merge( pad->GetBoundingBox() ); area.Merge( pad->GetBoundingBox() );
}
return area; return area;
} }
/* Equivalent to Module::Set_Rectangle_Encadrement() but in board coordinates:
* Updates the module bounding box on the board
* The rectangle is the rectangle with outlines and pads, but not the fields
* Also updates the surface (.M_Surface) module.
*/
void MODULE::SetRectangleExinscrit()
{
m_RealBoundaryBox = GetFootPrintRect();
m_Surface = ABS( (double) m_RealBoundaryBox.GetWidth() * m_RealBoundaryBox.GetHeight() );
}
/**
* Function GetBoundingBox
* returns the full bounding box of this Footprint, including fields
* Mainly used to redraw the screen area occupied by the footprint
*/
EDA_RECT MODULE::GetBoundingBox() const EDA_RECT MODULE::GetBoundingBox() const
{ {
EDA_RECT area = GetFootPrintRect(); EDA_RECT area = GetFootPrintRect();
// Calculate extended area including text field: // Calculate extended area including text field:
EDA_RECT text_area; area.Merge( m_Reference->GetBoundingBox() );
text_area = m_Reference->GetBoundingBox(); area.Merge( m_Value->GetBoundingBox() );
area.Merge( text_area );
text_area = m_Value->GetBoundingBox();
area.Merge( text_area );
for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst(); edge; edge = edge->Next() ) for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst(); edge; edge = edge->Next() )
{ if( edge->Type() == TYPE_TEXTE_MODULE )
if( edge->Type() != TYPE_TEXTE_MODULE ) area.Merge( edge->GetBoundingBox() );
continue;
text_area = ( (TEXTE_MODULE*) edge )->GetBoundingBox();
area.Merge( text_area );
}
// Add the Clearance shape size: (shape around the pads when the // Add the Clearance shape size: (shape around the pads when the
// clearance is shown. Not optimized, but the draw cost is small // clearance is shown. Not optimized, but the draw cost is small
@ -866,49 +749,30 @@ void MODULE::DisplayInfo( EDA_DRAW_FRAME* frame )
} }
/** bool MODULE::HitTest( const wxPoint& aRefPos )
* 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 MODULE::HitTest( const wxPoint& refPos )
{ {
/* Calculation of the cursor coordinate relative to module */ if( m_BoundaryBox.Contains( aRefPos ) )
wxPoint pos = refPos - m_Pos;
RotatePoint( &pos, -m_Orient );
/* Check if cursor is in the rectangle. */
if( m_BoundaryBox.Contains( pos ) )
return true; return true;
return false; return false;
} }
/** bool MODULE::HitTest( EDA_RECT& aRefArea )
* Function HitTest (overlaid)
* tests if the given EDA_RECT intersect the bounds of this object.
* @param refArea : the given EDA_RECT
* @return bool - true if a hit, else false
*/
bool MODULE::HitTest( EDA_RECT& refArea )
{ {
bool is_out_of_box = false; if( m_BoundaryBox.m_Pos.x < aRefArea.GetX() )
return false;
SetRectangleExinscrit(); if( m_BoundaryBox.m_Pos.y < aRefArea.GetY() )
return false;
if( m_RealBoundaryBox.m_Pos.x < refArea.GetX() ) if( m_BoundaryBox.GetRight() > aRefArea.GetRight() )
is_out_of_box = true; return false;
if( m_RealBoundaryBox.m_Pos.y < refArea.GetY() )
is_out_of_box = true;
if( m_RealBoundaryBox.GetRight() > refArea.GetRight() )
is_out_of_box = true;
if( m_RealBoundaryBox.GetBottom() > refArea.GetBottom() )
is_out_of_box = true;
return is_out_of_box ? false : true; if( m_BoundaryBox.GetBottom() > aRefArea.GetBottom() )
return false;
return true;
} }

View File

@ -58,9 +58,7 @@ public:
* routing. */ * routing. */
int m_ModuleStatus; /* For autoplace: flags (LOCKED, int m_ModuleStatus; /* For autoplace: flags (LOCKED,
* AUTOPLACED) */ * AUTOPLACED) */
EDA_RECT m_BoundaryBox; /* Bounding box coordinates relatives EDA_RECT m_BoundaryBox; /* Bounding box : coordinates on board,
* to the anchor, orient 0*/
EDA_RECT m_RealBoundaryBox; /* Bounding box : coordinates on board,
* real orientation */ * real orientation */
int m_PadNum; // Pad count int m_PadNum; // Pad count
int m_AltPadNum; /* Pad with netcode > 0 (active pads) int m_AltPadNum; /* Pad with netcode > 0 (active pads)
@ -115,31 +113,25 @@ public:
* void Add( BOARD_ITEM* aBoardItem, bool doInsert = true ); * void Add( BOARD_ITEM* aBoardItem, bool doInsert = true );
*/ */
/** /**
* Function Set_Rectangle_Encadrement * Function Set_Rectangle_Encadrement
* calculates the bounding box for orient 0 at origin = module anchor) * calculates the bounding box in board coordinates.
*/ */
void Set_Rectangle_Encadrement(); void Set_Rectangle_Encadrement();
/**
* Function SetRectangleExinscrit
* Calculates the real bounding box according to the board position,
* and real orientation and also calculates the area value (used in
* automatic placement)
*/
void SetRectangleExinscrit();
/** /**
* Function GetFootPrintRect() * Function GetFootPrintRect()
* Returns the area of the module footprint excluding any text. * Returns the area of the module footprint excluding any text.
* @return EDA_RECT - The rectangle containing the footprint.
*/ */
EDA_RECT GetFootPrintRect() const; EDA_RECT GetFootPrintRect() const;
/** /**
* Function GetBoundingBox * Function GetBoundingBox
* returns the bounding box of this Footprint * returns the bounding box of this
* Mainly used to redraw the screen area occupied by the footprint * tootprint. Mainly used to redraw the screen area occupied by
* the footprint.
* @return EDA_RECT - The rectangle containing the footprint and texts.
*/ */
EDA_RECT GetBoundingBox() const; EDA_RECT GetBoundingBox() const;
@ -261,19 +253,19 @@ public:
/** /**
* Function HitTest * Function HitTest
* tests if the given wxPoint is within the bounds of this object. * tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test * @param aRefPos is a wxPoint to test.
* @return bool - true if a hit, else false * @return bool - true if a hit, else false.
*/ */
bool HitTest( const wxPoint& refPos ); bool HitTest( const wxPoint& aRefPos );
/** /**
* Function HitTest (overlaid) * Function HitTest (overlaid)
* tests if the given EDA_RECT intersect the bounds of this object. * tests if the given EDA_RECT intersect the bounds of this object.
* @param refArea : the given EDA_RECT * @param aRefArea is the given EDA_RECT.
* @return bool - true if a hit, else false * @return bool - true if a hit, else false.
*/ */
bool HitTest( EDA_RECT& refArea ); bool HitTest( EDA_RECT& aRefArea );
/** /**
* Function GetReference * Function GetReference

View File

@ -135,6 +135,8 @@ public:
virtual BITMAP_DEF GetMenuImage() const { return add_text_xpm; } virtual BITMAP_DEF GetMenuImage() const { return add_text_xpm; }
virtual EDA_RECT GetBoundingBox() const { return GetTextBox(); };
#if defined(DEBUG) #if defined(DEBUG)
/** /**
* Function Show * Function Show

View File

@ -209,13 +209,9 @@ MODULE* Locate_Prefered_Module( BOARD* aPcb, const wxPoint& aPosition, int aActi
/* Test of minimum size to choosing the best candidate. */ /* Test of minimum size to choosing the best candidate. */
int offx = pt_module->m_BoundaryBox.m_Size.x / 2 + EDA_RECT bb = pt_module->GetFootPrintRect();
pt_module->m_BoundaryBox.m_Pos.x + int offx = bb.GetX() + bb.GetWidth() / 2;
pt_module->m_Pos.x; int offy = bb.GetY() + bb.GetHeight() / 2;
int offy = pt_module->m_BoundaryBox.m_Size.y / 2
+ pt_module->m_BoundaryBox.m_Pos.y
+ pt_module->m_Pos.y;
//off x & offy point to the middle of the box. //off x & offy point to the middle of the box.
int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy ); int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy );