Commit ae459044 authored by dickelbeck's avatar dickelbeck

Patch originating from Jonas Diemer

parent a1edf838
...@@ -962,13 +962,17 @@ void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, EDA_BaseStruct* DrawStruct ...@@ -962,13 +962,17 @@ void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, EDA_BaseStruct* DrawStruct
{ {
screen->RemoveFromDrawList( DrawStruct ); screen->RemoveFromDrawList( DrawStruct );
if( DrawStruct->Type() == DRAW_SEGMENT_STRUCT_TYPE ) if( (DrawStruct->Type() == DRAW_SEGMENT_STRUCT_TYPE) ||
(DrawStruct->Type() == DRAW_JUNCTION_STRUCT_TYPE) ||
(DrawStruct->Type() == DRAW_LIB_ITEM_STRUCT_TYPE) )
{ {
D( printf("PostDirtyRect()\n"); ) panel->PostDirtyRect( DrawStruct->GetBoundingBox() );
panel->PostDirtyRect( ((EDA_DrawLineStruct*)DrawStruct)->GetBoundingBox() );
} }
else else
{
D( DrawStruct->Show( 0, std::cout ); ) // tell me which classes still need GetBoundingBox support
RedrawOneStruct( panel, DC, DrawStruct, g_XorMode ); RedrawOneStruct( panel, DC, DrawStruct, g_XorMode );
}
/* Unlink the structure */ /* Unlink the structure */
DrawStruct->Pnext = DrawStruct->Pback = NULL; // Only one struct -> no link DrawStruct->Pnext = DrawStruct->Pback = NULL; // Only one struct -> no link
......
...@@ -241,7 +241,7 @@ void EDA_DrawLineStruct::Show( int nestLevel, std::ostream& os ) ...@@ -241,7 +241,7 @@ void EDA_DrawLineStruct::Show( int nestLevel, std::ostream& os )
EDA_Rect EDA_DrawLineStruct::GetBoundingBox() const EDA_Rect EDA_DrawLineStruct::GetBoundingBox()
{ {
int width = 25; int width = 25;
...@@ -257,7 +257,49 @@ EDA_Rect EDA_DrawLineStruct::GetBoundingBox() const ...@@ -257,7 +257,49 @@ EDA_Rect EDA_DrawLineStruct::GetBoundingBox() const
return ret; return ret;
} }
EDA_Rect DrawJunctionStruct::GetBoundingBox()
{
int width = DRAWJUNCTION_SIZE * 2;
int xmin = m_Pos.x - DRAWJUNCTION_SIZE ;
int ymin = m_Pos.y - DRAWJUNCTION_SIZE;
EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( width, width ) );
return ret;
};
EDA_Rect EDA_SchComponentStruct::GetBoundingBox()
{
const int PADDING = 40;
int xmin, xmax, ymin, ymax;
// This gives a reasonable approximation (but some things are missing so...
EDA_Rect ret = GetBoundaryBox();
xmin = ret.m_Pos.x;
ymin = ret.m_Pos.y;
xmax = ret.m_Pos.x + ret.m_Size.x;
ymax = ret.m_Pos.y + ret.m_Size.y;
// Include BoundingBoxes of fields
for( int i = REFERENCE; i < NUMBER_OF_FIELDS; i++ )
{
EDA_Rect box = m_Field[i].GetBoundaryBox();
xmin = MIN( xmin, box.m_Pos.x);
ymin = MIN( ymin, box.m_Pos.y);
xmax = MAX( xmax, box.m_Pos.x + box.m_Size.x);
ymax = MAX( ymax, box.m_Pos.y + box.m_Size.y);
}
// ... add padding TODO: improve this
ret.m_Pos.x = xmin - PADDING;
ret.m_Pos.y = ymin - PADDING;
ret.m_Size.x = xmax - xmin + 2*PADDING;
ret.m_Size.y = ymax - ymin + 2*PADDING;
D( printf("final box: %d,%d, %d,%d\n", ret.m_Pos.x, ret.m_Pos.y, ret.m_Size.x, ret.m_Size.y); )
return ret;
}
/****************************/ /****************************/
/* Class DrawPolylineStruct */ /* Class DrawPolylineStruct */
......
...@@ -234,7 +234,7 @@ EDA_SchComponentStruct::EDA_SchComponentStruct( const wxPoint& pos ) : ...@@ -234,7 +234,7 @@ EDA_SchComponentStruct::EDA_SchComponentStruct( const wxPoint& pos ) :
/************************************************/ /************************************************/
EDA_Rect EDA_SchComponentStruct::GetBoundaryBox() EDA_Rect EDA_SchComponentStruct::GetBoundaryBox() const
/************************************************/ /************************************************/
{ {
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
...@@ -733,7 +733,7 @@ bool PartTextStruct::IsVoid() ...@@ -733,7 +733,7 @@ bool PartTextStruct::IsVoid()
/********************************************/ /********************************************/
EDA_Rect PartTextStruct::GetBoundaryBox() EDA_Rect PartTextStruct::GetBoundaryBox() const
/********************************************/ /********************************************/
/* return /* return
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
void PartTextCopy( PartTextStruct* target ); void PartTextCopy( PartTextStruct* target );
void Place( WinEDA_DrawFrame* frame, wxDC* DC ); void Place( WinEDA_DrawFrame* frame, wxDC* DC );
EDA_Rect GetBoundaryBox(); EDA_Rect GetBoundaryBox() const;
bool IsVoid(); bool IsVoid();
void SwapData( PartTextStruct* copyitem ); void SwapData( PartTextStruct* copyitem );
}; };
...@@ -123,7 +123,8 @@ public: ...@@ -123,7 +123,8 @@ public:
wxPoint GetScreenCoord( const wxPoint& coord ); wxPoint GetScreenCoord( const wxPoint& coord );
void Display_Infos( WinEDA_DrawFrame* frame ); void Display_Infos( WinEDA_DrawFrame* frame );
void ClearAnnotation(); void ClearAnnotation();
EDA_Rect GetBoundaryBox(); EDA_Rect GetBoundaryBox() const;
EDA_Rect GetBoundingBox();
const wxString& ReturnFieldName( int aFieldNdx ) const; const wxString& ReturnFieldName( int aFieldNdx ) const;
......
...@@ -91,12 +91,7 @@ public: ...@@ -91,12 +91,7 @@ public:
return m_Start == m_End; return m_Start == m_End;
} }
EDA_Rect GetBoundingBox();
/**
* Function GetBoundingBox
* returns the bounding box of this TRACK
*/
EDA_Rect GetBoundingBox() const;
virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode,
int Color = -1 ); int Color = -1 );
...@@ -234,6 +229,7 @@ public: ...@@ -234,6 +229,7 @@ public:
return wxT( "DrawJunction" ); return wxT( "DrawJunction" );
} }
EDA_Rect GetBoundingBox();
DrawJunctionStruct* GenCopy(); DrawJunctionStruct* GenCopy();
virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
......
/*********************************************************************/ /*********************************************************************/
/* base_struct.h : Basic classes for most kicad item descriptions */ /* base_struct.h : Basic classes for most kicad item descriptions */
/*********************************************************************/ /*********************************************************************/
#ifndef BASE_STRUCT_H #ifndef BASE_STRUCT_H
...@@ -125,6 +125,78 @@ public: ...@@ -125,6 +125,78 @@ public:
}; };
/**
* Class EDA_Rect
* handles the component boundary box.
* This class is similar to wxRect, but some wxRect functions are very curious,
* so I prefer this suitable class
*/
class EDA_Rect
{
public:
wxPoint m_Pos; // Rectangle Origin
wxSize m_Size; // Rectangle Size
public:
EDA_Rect() { };
EDA_Rect( const wxPoint& aPos, const wxSize& aSize ) :
m_Pos( aPos ), m_Size( aSize )
{}
wxPoint Centre()
{
return wxPoint( m_Pos.x + (m_Size.x >> 1), m_Pos.y + (m_Size.y >> 1) );
}
void Normalize(); // Ensure the height and width are >= 0
bool Inside( const wxPoint& point ); // Return TRUE if point is in Rect
bool Inside( int x, int y ) { return Inside( wxPoint( x, y ) ); }
wxSize GetSize() { return m_Size; }
int GetX() { return m_Pos.x; }
int GetY() { return m_Pos.y; }
wxPoint GetOrigin() { return m_Pos; }
wxPoint GetPosition() { return m_Pos; }
wxPoint GetEnd() { return wxPoint( GetRight(), GetBottom() ); }
int GetWidth() { return m_Size.x; }
int GetHeight() { return m_Size.y; }
int GetRight() { return m_Pos.x + m_Size.x; }
int GetBottom() { return m_Pos.y + m_Size.y; }
void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
void SetSize( const wxSize& size ) { m_Size = size; }
void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y += offset.y; }
void SetX( int val ) { m_Pos.x = val; }
void SetY( int val ) { m_Pos.y = val; }
void SetWidth( int val ) { m_Size.x = val; }
void SetHeight( int val ) { m_Size.y = val; }
void SetEnd( const wxPoint& pos )
{
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
}
/**
* Function Intersects
* @return bool - true if the argument rectangle intersects this rectangle.
*/
bool Intersects( const EDA_Rect aRect ) const;
/**
* Function operator(wxRect)
* overloads the cast operator to return a wxRect
*/
operator wxRect() const { return wxRect( m_Pos, m_Size ); }
EDA_Rect& Inflate( wxCoord dx, wxCoord dy );
};
/********************************************************************/ /********************************************************************/
/* Classes de base: servent a deriver les classes reellement utiles */ /* Classes de base: servent a deriver les classes reellement utiles */
/********************************************************************/ /********************************************************************/
...@@ -268,6 +340,19 @@ public: ...@@ -268,6 +340,19 @@ public:
return false; // derived classes should override this function return false; // derived classes should override this function
} }
/**
* Function GetBoundingBox
* returns the orthogonal, bounding box of this object for display purposes.
* This box should be an enclosing perimeter for visible components of this
* object, and the units should be in the pcb or schematic coordinate system.
* It is OK to overestimate the size by a few counts.
*/
virtual EDA_Rect GetBoundingBox()
{
// return a zero-sized box per default. derived classes should override this
EDA_Rect ret( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
return ret;
}
/** /**
* Function IterateForward * Function IterateForward
...@@ -414,7 +499,7 @@ public: ...@@ -414,7 +499,7 @@ public:
virtual ~EDA_TextStruct(); virtual ~EDA_TextStruct();
void CreateDrawData(); void CreateDrawData();
int GetLength() { return m_Text.Length(); }; int GetLength() const { return m_Text.Length(); };
/** Function Pitch() /** Function Pitch()
* @return distance between 2 caracteres * @return distance between 2 caracteres
...@@ -600,74 +685,4 @@ public: ...@@ -600,74 +685,4 @@ public:
DrawPickedStruct* Next() { return (DrawPickedStruct*) Pnext; } DrawPickedStruct* Next() { return (DrawPickedStruct*) Pnext; }
}; };
/**
* Class EDA_Rect
* handles the component boundary box.
* This class is similar to wxRect, but some wxRect functions are very curious,
* so I prefer this suitable class
*/
class EDA_Rect
{
public:
wxPoint m_Pos; // Rectangle Origin
wxSize m_Size; // Rectangle Size
public:
EDA_Rect() { };
EDA_Rect( const wxPoint& aPos, const wxSize& aSize ) :
m_Pos( aPos ), m_Size( aSize )
{}
wxPoint Centre()
{
return wxPoint( m_Pos.x + (m_Size.x >> 1), m_Pos.y + (m_Size.y >> 1) );
}
void Normalize(); // Ensure the height and width are >= 0
bool Inside( const wxPoint& point ); // Return TRUE if point is in Rect
bool Inside( int x, int y ) { return Inside( wxPoint( x, y ) ); }
wxSize GetSize() { return m_Size; }
int GetX() { return m_Pos.x; }
int GetY() { return m_Pos.y; }
wxPoint GetOrigin() { return m_Pos; }
wxPoint GetPosition() { return m_Pos; }
wxPoint GetEnd() { return wxPoint( GetRight(), GetBottom() ); }
int GetWidth() { return m_Size.x; }
int GetHeight() { return m_Size.y; }
int GetRight() { return m_Pos.x + m_Size.x; }
int GetBottom() { return m_Pos.y + m_Size.y; }
void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
void SetSize( const wxSize& size ) { m_Size = size; }
void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y += offset.y; }
void SetX( int val ) { m_Pos.x = val; }
void SetY( int val ) { m_Pos.y = val; }
void SetWidth( int val ) { m_Size.x = val; }
void SetHeight( int val ) { m_Size.y = val; }
void SetEnd( const wxPoint& pos )
{
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
}
/**
* Function Intersects
* @return bool - true if the argument rectangle intersects this rectangle.
*/
bool Intersects( const EDA_Rect aRect ) const;
/**
* Function operator(wxRect)
* overloads the cast operator to return a wxRect
*/
operator wxRect() const { return wxRect( m_Pos, m_Size ); }
EDA_Rect& Inflate( wxCoord dx, wxCoord dy );
};
#endif /* BASE_STRUCT_H */ #endif /* BASE_STRUCT_H */
...@@ -219,7 +219,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) ...@@ -219,7 +219,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
} }
EDA_Rect TRACK::GetBoundingBox() const EDA_Rect TRACK::GetBoundingBox()
{ {
// end of track is round, this is its radius, rounded up // end of track is round, this is its radius, rounded up
int radius = ( m_Width+1 )/2; int radius = ( m_Width+1 )/2;
......
...@@ -67,12 +67,7 @@ public: ...@@ -67,12 +67,7 @@ public:
return m_Start; // it had to be start or end. return m_Start; // it had to be start or end.
} }
EDA_Rect GetBoundingBox();
/**
* Function GetBoundingBox
* returns the bounding box of this TRACK
*/
EDA_Rect GetBoundingBox() const;
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
......
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