diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 9a3875211a..a1cba61a8d 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -962,13 +962,17 @@ void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, EDA_BaseStruct* 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( ((EDA_DrawLineStruct*)DrawStruct)->GetBoundingBox() ); + panel->PostDirtyRect( DrawStruct->GetBoundingBox() ); } else + { + D( DrawStruct->Show( 0, std::cout ); ) // tell me which classes still need GetBoundingBox support RedrawOneStruct( panel, DC, DrawStruct, g_XorMode ); + } /* Unlink the structure */ DrawStruct->Pnext = DrawStruct->Pback = NULL; // Only one struct -> no link diff --git a/eeschema/cmpclass.cpp b/eeschema/cmpclass.cpp index 5dfc0cc4e6..6e9f0f3200 100644 --- a/eeschema/cmpclass.cpp +++ b/eeschema/cmpclass.cpp @@ -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; @@ -257,7 +257,49 @@ EDA_Rect EDA_DrawLineStruct::GetBoundingBox() const 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 */ diff --git a/eeschema/component_class.cpp b/eeschema/component_class.cpp index ced31b7d97..5cbc080c5d 100644 --- a/eeschema/component_class.cpp +++ b/eeschema/component_class.cpp @@ -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 ); @@ -733,7 +733,7 @@ bool PartTextStruct::IsVoid() /********************************************/ -EDA_Rect PartTextStruct::GetBoundaryBox() +EDA_Rect PartTextStruct::GetBoundaryBox() const /********************************************/ /* return diff --git a/eeschema/component_class.h b/eeschema/component_class.h index 8b20c7ca4b..b563866d65 100644 --- a/eeschema/component_class.h +++ b/eeschema/component_class.h @@ -59,7 +59,7 @@ public: void PartTextCopy( PartTextStruct* target ); void Place( WinEDA_DrawFrame* frame, wxDC* DC ); - EDA_Rect GetBoundaryBox(); + EDA_Rect GetBoundaryBox() const; bool IsVoid(); void SwapData( PartTextStruct* copyitem ); }; @@ -123,7 +123,8 @@ public: wxPoint GetScreenCoord( const wxPoint& coord ); void Display_Infos( WinEDA_DrawFrame* frame ); void ClearAnnotation(); - EDA_Rect GetBoundaryBox(); + EDA_Rect GetBoundaryBox() const; + EDA_Rect GetBoundingBox(); const wxString& ReturnFieldName( int aFieldNdx ) const; diff --git a/eeschema/program.h b/eeschema/program.h index 956dd6aa03..ad89f428a1 100644 --- a/eeschema/program.h +++ b/eeschema/program.h @@ -91,12 +91,7 @@ public: return m_Start == m_End; } - - /** - * Function GetBoundingBox - * returns the bounding box of this TRACK - */ - EDA_Rect GetBoundingBox() const; + EDA_Rect GetBoundingBox(); virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, int Color = -1 ); @@ -234,6 +229,7 @@ public: return wxT( "DrawJunction" ); } + EDA_Rect GetBoundingBox(); DrawJunctionStruct* GenCopy(); virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, diff --git a/include/base_struct.h b/include/base_struct.h index dd0b1fb403..9a5fef6185 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -1,5 +1,5 @@ /*********************************************************************/ -/* base_struct.h : Basic classes for most kicad item descriptions */ +/* base_struct.h : Basic classes for most kicad item descriptions */ /*********************************************************************/ #ifndef BASE_STRUCT_H @@ -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 */ /********************************************************************/ @@ -268,6 +340,19 @@ public: 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 @@ -414,7 +499,7 @@ public: virtual ~EDA_TextStruct(); void CreateDrawData(); - int GetLength() { return m_Text.Length(); }; + int GetLength() const { return m_Text.Length(); }; /** Function Pitch() * @return distance between 2 caracteres @@ -600,74 +685,4 @@ public: 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 */ diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 496e27456c..9fbc8bf801 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -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 int radius = ( m_Width+1 )/2; diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index da1476f342..239a3f0772 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -67,12 +67,7 @@ public: return m_Start; // it had to be start or end. } - - /** - * Function GetBoundingBox - * returns the bounding box of this TRACK - */ - EDA_Rect GetBoundingBox() const; + EDA_Rect GetBoundingBox(); /* supprime du chainage la structure Struct */