Commit 44d96074 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Pcbnew: Fix incorrect bounding box calculation of texts. Only noticeable with...

Pcbnew: Fix incorrect bounding box calculation of texts. Only noticeable with boards conveted from Eagle, which are using other text justification than center.
Eagle plugin: filter and replace not allowed chars in FPID(-':' and '/')  by _ or -, if they are used in Eagle footprint names (otherwise, boards converted and saved under kicad_pcb format are not readable by Pcbnew).
parent db5409df
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -532,3 +532,40 @@ double EDA_RECT::GetArea() const
{
    return (double) GetWidth() * (double) GetHeight();
}

/* Calculate the bounding box of this, when rotated
 */
EDA_RECT EDA_RECT::GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle )
{
    wxPoint corners[4];

    // Build the corners list
    corners[0]   = GetOrigin();
    corners[2]   = GetEnd();
    corners[1].x = corners[0].x;
    corners[1].y = corners[2].y;
    corners[3].x = corners[2].x;
    corners[3].y = corners[0].y;

    // Rotate all corners, to find the bounding box
    for( int ii = 0; ii < 4; ii ++ )
        RotatePoint( &corners[ii], aRotCenter, aAngle );

    // Find the corners bounding box
    wxPoint start = corners[0];
    wxPoint end = corners[0];

    for( int ii = 1; ii < 4; ii ++ )
    {
        start.x = std::min( start.x, corners[ii].x);
        start.y = std::min( start.y, corners[ii].y);
        end.x = std::max( end.x, corners[ii].x);
        end.y = std::max( end.y, corners[ii].y);
    }

    EDA_RECT bbox;
    bbox.SetOrigin( start );
    bbox.SetEnd( end );

    return bbox;
}
+1 −1
Original line number Diff line number Diff line
@@ -363,7 +363,7 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
        DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );

    // Enable these line to draw the bounding box (debug tests purposes only)
#if 0
#if 1
    {
        EDA_RECT BoundaryBox = GetBoundingBox();
        GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
+10 −0
Original line number Diff line number Diff line
@@ -274,6 +274,16 @@ public:
     * @return The area of the rectangle.
     */
    double GetArea() const;

    /**
     * Function GetBoundingBoxRotated
     * @return the bounding box of this, after rotation
     * @param aAngle = the rotation angle in 0.1 deg.
     * @param aRotCenter = the rotation point.
     * useful to calculate bounding box of rotated items, when
     * rotation if not k*90 degrees
     */
    EDA_RECT GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle );
};


+2 −1
Original line number Diff line number Diff line
@@ -229,7 +229,8 @@ public:
     * useful in multiline texts to calculate the full text or a line area (for
     * zones filling, locate functions....)
     * @return the rect containing the line of text (i.e. the position and the
     *         size of one line) this rectangle is calculated for 0 orient text.
     *         size of one line)
     *         this rectangle is calculated for 0 orient text.
     *         If orientation is not 0 the rect must be rotated to match the
     *         physical area
     * @param aLine The line of text to consider.
+18 −0
Original line number Diff line number Diff line
@@ -106,6 +106,14 @@ void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
    EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
    EDA_TEXT::Draw( clipbox, DC, offset, color,
                    DrawMode, fillmode, anchor_color );

    // Enable these line to draw the bounding box (debug tests purposes only)
#if 0
    {
        EDA_RECT BoundaryBox = GetBoundingBox();
        GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
    }
#endif
}


@@ -150,6 +158,16 @@ void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
    aList.push_back( MSG_PANEL_ITEM( _( "Size Y" ), msg, RED ) );
}

EDA_RECT TEXTE_PCB::GetBoundingBox() const
{
    EDA_RECT rect = GetTextBox( -1, -1 );

    if( m_Orient )
        rect = rect.GetBoundingBoxRotated( m_Pos, m_Orient );

    return rect;
}


void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
{
Loading