Commit 0e709a12 authored by dickelbeck's avatar dickelbeck

added bool Intersects()

parent 8bfdd040
...@@ -119,7 +119,7 @@ void EDA_BaseStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC ) ...@@ -119,7 +119,7 @@ void EDA_BaseStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
// see base_struct.h // see base_struct.h
SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart, 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; EDA_BaseStruct* p = listStart;
...@@ -135,7 +135,7 @@ SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart, ...@@ -135,7 +135,7 @@ SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart,
// see base_struct.h // see base_struct.h
// many classes inherit this method, be careful: // many classes inherit this method, be careful:
SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData, SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T scanTypes[] ) const KICAD_T scanTypes[] )
{ {
KICAD_T stype; KICAD_T stype;
...@@ -143,7 +143,7 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData, ...@@ -143,7 +143,7 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData,
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' '; std::cout << GetClass().mb_str() << ' ';
#endif #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 caller wants to inspect my type
...@@ -156,7 +156,7 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData, ...@@ -156,7 +156,7 @@ SEARCH_RESULT EDA_BaseStruct::Visit( INSPECTOR* inspector, const void* testData,
} }
} }
return SEARCH_CONTINUE; return SEARCH_CONTINUE;
} }
...@@ -179,15 +179,15 @@ std::ostream& operator<<( std::ostream& out, const wxPoint& pt ) ...@@ -179,15 +179,15 @@ std::ostream& operator<<( std::ostream& out, const wxPoint& pt )
/** /**
* Function Show * Function Show
* is used to output the object tree, currently for debugging only. * is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level * @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree. * of nesting of this object within the overall tree.
* @param os The ostream& to output to. * @param os The ostream& to output to.
*/ */
void EDA_BaseStruct::Show( int nestLevel, std::ostream& os ) void EDA_BaseStruct::Show( int nestLevel, std::ostream& os )
{ {
// for now, make it look like XML: // for now, make it look like XML:
wxString s = GetClass(); wxString s = GetClass();
s = s + wxT(" "); s = s + wxT(" ");
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">\n"; NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">\n";
/* /*
...@@ -198,12 +198,12 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os ) ...@@ -198,12 +198,12 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& 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"; NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
} }
/** /**
* Function NestedSpace * Function NestedSpace
* outputs nested space for pretty indenting. * outputs nested space for pretty indenting.
* @param nestLevel The nest count * @param nestLevel The nest count
...@@ -285,14 +285,14 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref ) ...@@ -285,14 +285,14 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
dy = m_Size.y / 2; dy = m_Size.y / 2;
/* Is the ref point inside the text area ? */ /* Is the ref point inside the text area ? */
spot_cX = posref.x - m_Pos.x; spot_cX = posref.x - m_Pos.x;
spot_cY = posref.y - m_Pos.y; spot_cY = posref.y - m_Pos.y;
RotatePoint( &spot_cX, &spot_cY, -m_Orient ); RotatePoint( &spot_cX, &spot_cY, -m_Orient );
if( ( abs( spot_cX ) <= abs( dx ) ) && ( abs( spot_cY ) <= abs( dy ) ) ) if( ( abs( spot_cX ) <= abs( dx ) ) && ( abs( spot_cY ) <= abs( dy ) ) )
return true; return true;
return false; return false;
} }
...@@ -306,9 +306,9 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref ) ...@@ -306,9 +306,9 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
bool EDA_TextStruct::HitTest( EDA_Rect& refArea ) bool EDA_TextStruct::HitTest( EDA_Rect& refArea )
/*********************************************************/ /*********************************************************/
{ {
if( refArea.Inside( m_Pos ) ) if( refArea.Inside( m_Pos ) )
return true; return true;
return false; return false;
} }
/*******************************/ /*******************************/
...@@ -344,7 +344,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -344,7 +344,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
if( m_TextDrawings == NULL ) /* pointeur sur la liste des segments de dessin */ if( m_TextDrawings == NULL ) /* pointeur sur la liste des segments de dessin */
CreateDrawData(); CreateDrawData();
if( m_TextDrawings == NULL ) if( m_TextDrawings == NULL )
return; return;
...@@ -352,7 +352,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -352,7 +352,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
width = m_Width / zoom; width = m_Width / zoom;
if( display_mode == FILAIRE ) if( display_mode == FILAIRE )
width = 0; width = 0;
/* choix de la couleur du texte : */ /* choix de la couleur du texte : */
if( draw_mode != -1 ) if( draw_mode != -1 )
GRSetDrawMode( DC, draw_mode ); GRSetDrawMode( DC, draw_mode );
...@@ -374,15 +374,15 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -374,15 +374,15 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
{ {
int anchor_size = 2 * zoom; int anchor_size = 2 * zoom;
anchor_color &= MASKCOLOR; anchor_color &= MASKCOLOR;
/* calcul de la position du texte */ /* calcul de la position du texte */
int cX = m_Pos.x - offset.x; int cX = m_Pos.x - offset.x;
int cY = m_Pos.y - offset.y; int cY = m_Pos.y - offset.y;
/* trace ancre du texte */ /* trace ancre du texte */
GRLine( &panel->m_ClipBox, DC, cX - anchor_size, cY, GRLine( &panel->m_ClipBox, DC, cX - anchor_size, cY,
cX + anchor_size, cY, 0, anchor_color ); cX + anchor_size, cY, 0, anchor_color );
GRLine( &panel->m_ClipBox, DC, cX, cY - anchor_size, GRLine( &panel->m_ClipBox, DC, cX, cY - anchor_size,
cX, cY + anchor_size, 0, anchor_color ); cX, cY + anchor_size, 0, anchor_color );
} }
...@@ -392,7 +392,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -392,7 +392,7 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
nbpoints = m_TextDrawings[jj]; nbpoints = m_TextDrawings[jj];
if( nbpoints > 50 ) if( nbpoints > 50 )
nbpoints = 50; nbpoints = 50;
for( kk = 0, ll = 0; (kk < nbpoints) && (ii < m_TextDrawingsSize); kk++ ) for( kk = 0, ll = 0; (kk < nbpoints) && (ii < m_TextDrawingsSize); kk++ )
{ {
coord[ll++] = m_TextDrawings[ii++] + offset.x + m_Pos.x; coord[ll++] = m_TextDrawings[ii++] + offset.x + m_Pos.x;
...@@ -550,13 +550,13 @@ void EDA_TextStruct::CreateDrawData() ...@@ -550,13 +550,13 @@ void EDA_TextStruct::CreateDrawData()
m_ZoomLevelDrawable = m_Size.x / 3; m_ZoomLevelDrawable = m_Size.x / 3;
dx = (espacement * nbchar) / 2; dx = (espacement * nbchar) / 2;
dy = size_v / 2; /* Decalage du debut du texte / centre */ dy = size_v / 2; /* Decalage du debut du texte / centre */
ux0 = cX - dx; ux0 = cX - dx;
uy0 = cY; uy0 = cY;
dx += cX; dx += cX;
dy = cY; dy = cY;
RotatePoint( &ux0, &uy0, cX, cY, m_Orient ); RotatePoint( &ux0, &uy0, cX, cY, m_Orient );
RotatePoint( &dx, &dy, cX, cY, m_Orient ); RotatePoint( &dx, &dy, cX, cY, m_Orient );
...@@ -593,9 +593,9 @@ void EDA_TextStruct::CreateDrawData() ...@@ -593,9 +593,9 @@ void EDA_TextStruct::CreateDrawData()
coord = (int*) realloc( coord, coord_count_max * sizeof(int) ); coord = (int*) realloc( coord, coord_count_max * sizeof(int) );
} }
coord[jj] = nbpoints; coord[jj] = nbpoints;
jj = ii++; jj = ii++;
} }
plume = f_cod; plume = f_cod;
nbpoints = 0; nbpoints = 0;
break; break;
...@@ -612,20 +612,20 @@ void EDA_TextStruct::CreateDrawData() ...@@ -612,20 +612,20 @@ void EDA_TextStruct::CreateDrawData()
f_cod = *ptcar; f_cod = *ptcar;
k2 = f_cod; /* trace sur axe H */ k2 = f_cod; /* trace sur axe H */
k2 = (k2 * size_h) / 9; k2 = (k2 * size_h) / 9;
dx = k2 + ox; dx = k2 + ox;
dy = k1 + oy; dy = k1 + oy;
RotatePoint( &dx, &dy, cX, cY, m_Orient ); RotatePoint( &dx, &dy, cX, cY, m_Orient );
if( ii >= coord_count_max ) if( ii >= coord_count_max )
{ {
coord_count_max *= 2; coord_count_max *= 2;
coord = (int*) realloc( coord, coord_count_max * sizeof(int) ); coord = (int*) realloc( coord, coord_count_max * sizeof(int) );
} }
coord[ii++] = dx; coord[ii++] = dx;
coord[ii++] = dy; coord[ii++] = dy;
nbpoints++; nbpoints++;
break; break;
} }
...@@ -636,7 +636,7 @@ void EDA_TextStruct::CreateDrawData() ...@@ -636,7 +636,7 @@ void EDA_TextStruct::CreateDrawData()
/* end boucle for = end trace de 1 caractere */ /* end boucle for = end trace de 1 caractere */
ptr++; ptr++;
ox += espacement; ox += espacement;
} }
...@@ -680,16 +680,16 @@ bool EDA_Rect::Inside( const wxPoint& point ) ...@@ -680,16 +680,16 @@ bool EDA_Rect::Inside( const wxPoint& point )
if( size.x < 0 ) if( size.x < 0 )
{ {
size.x = -size.x; size.x = -size.x;
rel_posx += size.x; rel_posx += size.x;
} }
if( size.y < 0 ) if( size.y < 0 )
{ {
size.y = -size.y; size.y = -size.y;
rel_posy += size.y; rel_posy += size.y;
} }
return (rel_posx >= 0) && (rel_posy >= 0) return (rel_posx >= 0) && (rel_posy >= 0)
&& ( rel_posy <= size.y) && ( rel_posy <= size.y)
&& ( rel_posx <= size.x) && ( rel_posx <= size.x)
...@@ -697,6 +697,23 @@ bool EDA_Rect::Inside( const wxPoint& point ) ...@@ -697,6 +697,23 @@ bool EDA_Rect::Inside( const wxPoint& point )
} }
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 );
if( left < right && top < bottom )
{
return true;
}
return false;
}
/**************************************************/ /**************************************************/
EDA_Rect& EDA_Rect::Inflate( wxCoord dx, wxCoord dy ) EDA_Rect& EDA_Rect::Inflate( wxCoord dx, wxCoord dy )
/**************************************************/ /**************************************************/
......
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