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

DRC code cleaning, and added DRC tests for trapezoidal pads. Needs more tests.

parents e149951b f1df65c5
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -96,6 +96,7 @@ set(PCBNEW_SRCS
    dist.cpp
    dist.cpp
    dragsegm.cpp
    dragsegm.cpp
    drc.cpp
    drc.cpp
    drc_clearance_test_functions.cpp
    drc_marker_functions.cpp
    drc_marker_functions.cpp
    edgemod.cpp
    edgemod.cpp
    edit.cpp
    edit.cpp
+7 −18
Original line number Original line Diff line number Diff line
@@ -764,17 +764,15 @@ bool D_PAD::IsOnLayer( int aLayer ) const
 */
 */
bool D_PAD::HitTest( const wxPoint& ref_pos )
bool D_PAD::HitTest( const wxPoint& ref_pos )
{
{
    int     deltaX, deltaY;
    int     dx, dy;
    int     dx, dy;
    double  dist;
    double  dist;


    wxPoint shape_pos = ReturnShapePos();
    wxPoint shape_pos = ReturnShapePos();


    deltaX = ref_pos.x - shape_pos.x;
    wxPoint delta = ref_pos - shape_pos;
    deltaY = ref_pos.y - shape_pos.y;


    /* Quick test: a test point must be inside the circle. */
    /* Quick test: a test point must be inside the circle. */
    if( ( abs( deltaX ) > m_ShapeMaxRadius ) || ( abs( deltaY ) > m_ShapeMaxRadius ) )
    if( ( abs( delta.x ) > m_ShapeMaxRadius ) || ( abs( delta.y ) > m_ShapeMaxRadius ) )
        return false;
        return false;


    dx = m_Size.x >> 1; // dx also is the radius for rounded pads
    dx = m_Size.x >> 1; // dx also is the radius for rounded pads
@@ -783,7 +781,7 @@ bool D_PAD::HitTest( const wxPoint& ref_pos )
    switch( m_PadShape & 0x7F )
    switch( m_PadShape & 0x7F )
    {
    {
    case PAD_CIRCLE:
    case PAD_CIRCLE:
        dist = hypot( deltaX, deltaY );
        dist = hypot( delta.x, delta.y );
        if( wxRound( dist ) <= dx )
        if( wxRound( dist ) <= dx )
            return true;
            return true;
        break;
        break;
@@ -792,22 +790,13 @@ bool D_PAD::HitTest( const wxPoint& ref_pos )
    {
    {
        wxPoint poly[4];
        wxPoint poly[4];
        BuildPadPolygon( poly, wxSize(0,0), 0 );
        BuildPadPolygon( poly, wxSize(0,0), 0 );
        // Build the same polygon with CPolyPt corners,
        RotatePoint( &delta, -m_Orient );
        // to use TestPointInsidePolygon
        return TestPointInsidePolygon( poly, 4, delta );
        static std::vector <CPolyPt> polysList;     // Is static to avoid memory reallocation
        polysList.clear();
        for(int ii= 0; ii < 4; ii++ )
        {
            CPolyPt corner(poly[ii].x, poly[ii].y);
            polysList.push_back(corner);
        }
        RotatePoint( &deltaX, &deltaY, -m_Orient );
        return TestPointInsidePolygon( polysList, 0, 3, deltaX, deltaY );
    }
    }


    default:
    default:
        RotatePoint( &deltaX, &deltaY, -m_Orient );
        RotatePoint( &delta, -m_Orient );
        if( (abs( deltaX ) <= dx ) && (abs( deltaY ) <= dy) )
        if( (abs( delta.x ) <= dx ) && (abs( delta.y ) <= dy) )
            return true;
            return true;
        break;
        break;
    }
    }
+15 −3
Original line number Original line Diff line number Diff line
@@ -148,7 +148,7 @@ public:
     * Function GetShape
     * Function GetShape
     * @return the shape of this pad.
     * @return the shape of this pad.
     */
     */
    int GetShape() { return m_PadShape & 0xFF;  }
    int GetShape() const { return m_PadShape & 0xFF;  }


    /**
    /**
     * Function GetPosition
     * Function GetPosition
@@ -239,14 +239,26 @@ public:
    void          DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo );
    void          DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo );


    /** function BuildPadPolygon
    /** function BuildPadPolygon
     * Has meaning only for polygonal pads (trapeziod and rectangular)
     * Has meaning only for polygonal pads (trapezoid and rectangular)
     * Build the Corner list of the polygonal shape,
     * Build the Corner list of the polygonal shape,
     * depending on shape, extra size (clearance ...) and orientation
     * depending on shape, extra size (clearance ...) and orientation
     * @param aCoord[4] = a buffer to fill.
     * @param aCoord[4] = a buffer to fill.
     * @param aInflateValue = wxSize: the clearance or margin value. value > 0: inflate, < 0 deflate
     * @param aInflateValue = wxSize: the clearance or margin value. value > 0: inflate, < 0 deflate
     * @param aRotation = full rotation of the polygon
     * @param aRotation = full rotation of the polygon
     */
     */
    void          BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation );
    void          BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const;

    /** function BuildSegmentFromOvalShape
     * Has meaning only for OVAL (and ROUND) pads
     * Build an equivalent segment having the same shape as the OVAL shape,
     * Useful in draw function and in DRC and HitTest functions,
     *  because segments are already well handled by track tests
     * @param aSegStart = the starting point of the equivalent segment, relative to the shape position.
     * @param aSegEnd = the ending point of the equivalent segment, relative to the shape position
     * @param aRotation = full rotation of the segment
     * @return the width of the segment
     */
    int          BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation) const;


    // others
    // others
    void          SetPadName( const wxString& name );       // Change pad name
    void          SetPadName( const wxString& name );       // Change pad name
+55 −36
Original line number Original line Diff line number Diff line
@@ -357,9 +357,9 @@ void D_PAD::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDraw_mode,
void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
{
{
    wxPoint coord[4];
    wxPoint coord[4];
    int     rotdx,
    int     delta_cx, delta_cy;
            delta_cx, delta_cy;
    int     angle = m_Orient;
    int     angle = m_Orient;
    int     seg_width;


    GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
    GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );


@@ -392,43 +392,29 @@ void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
        break;
        break;


    case PAD_OVAL:
    case PAD_OVAL:
        if( halfsize.x > halfsize.y )       /* horizontal */
    {
    {
            delta_cx = halfsize.x - halfsize.y;
        wxPoint segStart, segEnd;
            delta_cy = 0;
        seg_width = BuildSegmentFromOvalShape(segStart, segEnd, angle);
            rotdx    = m_Size.y + ( aDrawInfo.m_Mask_margin.y * 2 );
        segStart += shape_pos;
        }
        segEnd += shape_pos;
        else                /* vertical */
        {
            delta_cx = 0;
            delta_cy = halfsize.y - halfsize.x;
            rotdx    = m_Size.x + ( aDrawInfo.m_Mask_margin.x * 2 );
        }
        RotatePoint( &delta_cx, &delta_cy, angle );

        if( aDrawInfo.m_ShowPadFilled )
        if( aDrawInfo.m_ShowPadFilled )
        {
        {
            GRFillCSegm( aClipBox, aDC,
            GRFillCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
                         shape_pos.x + delta_cx, shape_pos.y + delta_cy,
                         seg_width, aDrawInfo.m_Color );
                         shape_pos.x - delta_cx, shape_pos.y - delta_cy,
                         rotdx, aDrawInfo.m_Color );
        }
        }
        else
        else
        {
        {
            GRCSegm( aClipBox, aDC,
            GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
                     shape_pos.x + delta_cx, shape_pos.y + delta_cy,
                     seg_width, m_PadSketchModePenSize, aDrawInfo.m_Color );
                     shape_pos.x - delta_cx, shape_pos.y - delta_cy,
                     rotdx, m_PadSketchModePenSize, aDrawInfo.m_Color );
        }
        }


        /* Draw the isolation line. */
        /* Draw the isolation line. */
        if( aDrawInfo.m_PadClearance )
        if( aDrawInfo.m_PadClearance )
        {
        {
            rotdx = rotdx + 2 * aDrawInfo.m_PadClearance;
            seg_width += 2 * aDrawInfo.m_PadClearance;

            GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
            GRCSegm( aClipBox, aDC, shape_pos.x + delta_cx, shape_pos.y + delta_cy,
                     seg_width, aDrawInfo.m_Color );
                     shape_pos.x - delta_cx, shape_pos.y - delta_cy,
        }
                     rotdx, aDrawInfo.m_Color );
    }
    }
        break;
        break;


@@ -486,9 +472,6 @@ void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
#else
#else
            if( aDrawInfo.m_Scale * hole > 1 ) /* draw hole if its size is enough */
            if( aDrawInfo.m_Scale * hole > 1 ) /* draw hole if its size is enough */
#endif
#endif



                GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
                GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
                                aDrawInfo.m_Color, aDrawInfo.m_HoleColor );
                                aDrawInfo.m_Color, aDrawInfo.m_HoleColor );
            break;
            break;
@@ -501,18 +484,18 @@ void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
            {
            {
                delta_cx = halfsize.x - halfsize.y;
                delta_cx = halfsize.x - halfsize.y;
                delta_cy = 0;
                delta_cy = 0;
                rotdx    = m_Drill.y;
                seg_width    = m_Drill.y;
            }
            }
            else                         /* vertical */
            else                         /* vertical */
            {
            {
                delta_cx = 0;
                delta_cx = 0;
                delta_cy = halfsize.y - halfsize.x;
                delta_cy = halfsize.y - halfsize.x;
                rotdx    = m_Drill.x;
                seg_width    = m_Drill.x;
            }
            }
            RotatePoint( &delta_cx, &delta_cy, angle );
            RotatePoint( &delta_cx, &delta_cy, angle );


            GRFillCSegm( aClipBox, aDC, holepos.x + delta_cx, holepos.y + delta_cy,
            GRFillCSegm( aClipBox, aDC, holepos.x + delta_cx, holepos.y + delta_cy,
                         holepos.x - delta_cx, holepos.y - delta_cy, rotdx,
                         holepos.x - delta_cx, holepos.y - delta_cy, seg_width,
                         aDrawInfo.m_HoleColor );
                         aDrawInfo.m_HoleColor );
            break;
            break;


@@ -637,6 +620,42 @@ void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
    }
    }
}
}


/** function BuildSegmentFromOvalShape
 * Has meaning only for OVAL (and ROUND) pads.
 * Build an equivalent segment having the same shape as the OVAL shape,
 * aSegStart and aSegEnd are the ending points of the equivalent segment of the shape
 * aRotation is the asked rotation of the segment (usually m_Orient)
 */
int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation) const
{
    int width;
    if( m_Size.y < m_Size.x )     // Build an horizontal equiv segment
    {
        int delta   = ( m_Size.x - m_Size.y ) / 2;
        aSegStart.x = -delta;
        aSegStart.y = 0;
        aSegEnd.x = delta;
        aSegEnd.y = 0;
        width = m_Size.y;
    }
    else        // Vertical oval: build a vertical equiv segment
    {
        int delta   = ( m_Size.y -m_Size.x ) / 2;
        aSegStart.x = 0;
        aSegStart.y = -delta;
        aSegEnd.x = 0;
        aSegEnd.y = delta;
        width = m_Size.x;
    }

    if( aRotation )
    {
        RotatePoint( &aSegStart, aRotation);
        RotatePoint( &aSegEnd, aRotation);
    }

    return width;
}


/** function BuildPadPolygon
/** function BuildPadPolygon
 * Has meaning only for polygonal pads (trapeziod and rectangular)
 * Has meaning only for polygonal pads (trapeziod and rectangular)
@@ -646,7 +665,7 @@ void D_PAD::DrawShape( EDA_Rect* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
 * @param aInflateValue = wxSize: the clearance or margin value. value > 0: inflate, < 0 deflate
 * @param aInflateValue = wxSize: the clearance or margin value. value > 0: inflate, < 0 deflate
 * @param aRotation = full rotation of the polygon, usually m_Orient
 * @param aRotation = full rotation of the polygon, usually m_Orient
 */
 */
void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation )
void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const
{
{
    if( (GetShape() != PAD_RECT) && (GetShape() != PAD_TRAPEZOID) )
    if( (GetShape() != PAD_RECT) && (GetShape() != PAD_TRAPEZOID) )
        return;
        return;
+1 −8
Original line number Original line Diff line number Diff line
@@ -44,21 +44,17 @@ bool DIALOG_DRC_CONTROL::Show( bool show )
{
{
    bool ret;
    bool ret;


    D(printf("%s %d\n", __func__, show );)

    if( show )
    if( show )
    {
    {
        ret = DIALOG_DRC_CONTROL_BASE::Show( show );
        ret = DIALOG_DRC_CONTROL_BASE::Show( show );


        if( s_LastPos.x != -1 )
        if( s_LastPos.x != -1 )
        {
        {
            D(printf("setting window pos to (%d,%d)\n", s_LastPos.x, s_LastPos.y );)
            //SetPosition( s_LastPos );
            SetSize( s_LastPos.x, s_LastPos.y, s_LastSize.x, s_LastSize.y, 0 );
            SetSize( s_LastPos.x, s_LastPos.y, s_LastSize.x, s_LastSize.y, 0 );
        }
        }
        else
        else
        {
        {
            D(printf("not setting window pos (%d,%d)\n", s_LastPos.x, s_LastPos.y );)
            // Do nothing: last position not yet saved.
        }
        }
    }
    }
    else
    else
@@ -66,9 +62,6 @@ bool DIALOG_DRC_CONTROL::Show( bool show )
        // Save the dialog's position before hiding
        // Save the dialog's position before hiding
        s_LastPos  = GetPosition();
        s_LastPos  = GetPosition();
        s_LastSize = GetSize();
        s_LastSize = GetSize();

        D(printf("saving window pos as (%d,%d)\n", s_LastPos.x, s_LastPos.y );)

        ret = DIALOG_DRC_CONTROL_BASE::Show( show );
        ret = DIALOG_DRC_CONTROL_BASE::Show( show );
    }
    }


Loading