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

Pcbnew: board editor: allows pad edition by hotkey 'E' (was accessible only by...

Pcbnew: board editor: allows pad edition by hotkey 'E' (was accessible only by mouse button right click)
All: minor code cleaning and very minor bug fixes.
parent c39ca125
Loading
Loading
Loading
Loading
+11 −18
Original line number Original line Diff line number Diff line
@@ -8,12 +8,12 @@
#include <trigo.h>
#include <trigo.h>
#include <common.h>
#include <common.h>


static bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );

bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist )
bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist )
{
{
    // make coordinates relatives to aStart:
    return DistanceTest( aDist, aEnd.x - aStart.x, aEnd.y - aStart.y,
    aEnd -= aStart;
                         aRefPoint.x - aStart.x, aRefPoint.y - aStart.y );
    aRefPoint -= aStart;
    return DistanceTest( aDist, aEnd.x, aEnd.y, aRefPoint.x, aRefPoint.y );
}
}




@@ -347,41 +347,34 @@ void RotatePoint( double* pX, double* pY, double angle )


double EuclideanNorm( wxPoint vector )
double EuclideanNorm( wxPoint vector )
{
{
    return sqrt( (double) vector.x * (double) vector.x + (double) vector.y * (double) vector.y );
    return hypot( (double) vector.x, (double) vector.y );
}


wxPoint TwoPointVector( wxPoint startPoint, wxPoint endPoint )
{
    return endPoint - startPoint;
}
}



double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint )
double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint )
{
{
    return fabs( (double) ( (linePointB.x - linePointA.x) * (linePointA.y - referencePoint.y) -
    return fabs( (double) ( (linePointB.x - linePointA.x) * (linePointA.y - referencePoint.y) -
                 (linePointA.x - referencePoint.x ) * (linePointB.y - linePointA.y) )
                 (linePointA.x - referencePoint.x ) * (linePointB.y - linePointA.y) )
                  / EuclideanNorm( TwoPointVector( linePointA, linePointB ) ) );
                  / EuclideanNorm( linePointB - linePointA ) );
}
}




bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold )
bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold )
{
{
    wxPoint vectorAB = TwoPointVector( pointA, pointB );
    wxPoint vectorAB = pointB - pointA;
    double  distance = EuclideanNorm( vectorAB );
    double  distance = EuclideanNorm( vectorAB );


    return distance < threshold;
    return distance < threshold;
}
}




int CrossProduct( wxPoint vectorA, wxPoint vectorB )
double CrossProduct( wxPoint vectorA, wxPoint vectorB )
{
{
    return vectorA.x * vectorB.y - vectorA.y * vectorB.x;
    return (double)vectorA.x * vectorB.y - (double)vectorA.y * vectorB.x;
}
}




double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB )
double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB )
{
{
    return sqrt( pow( (double) aPointA.x - (double) aPointB.x, 2 ) +
    return hypot( (double) aPointA.x - (double) aPointB.x,
                 pow( (double) aPointA.y - (double) aPointB.y, 2 ) );
                  (double) aPointA.y - (double) aPointB.y );
}
}
+22 −16
Original line number Original line Diff line number Diff line
@@ -41,6 +41,12 @@
#include <lib_arc.h>
#include <lib_arc.h>
#include <transform.h>
#include <transform.h>


// Helper function
static inline wxPoint twoPointVector( wxPoint startPoint, wxPoint endPoint )
{
    return endPoint - startPoint;
}



//! @brief Given three points A B C, compute the circumcenter of the resulting triangle
//! @brief Given three points A B C, compute the circumcenter of the resulting triangle
//! reference: http://en.wikipedia.org/wiki/Circumscribed_circle
//! reference: http://en.wikipedia.org/wiki/Circumscribed_circle
@@ -188,7 +194,7 @@ bool LIB_ARC::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTran


    NEGATE( relativePosition.y );       // reverse Y axis
    NEGATE( relativePosition.y );       // reverse Y axis


    int distance = KiROUND( EuclideanNorm( TwoPointVector( m_Pos, relativePosition ) ) );
    int distance = KiROUND( EuclideanNorm( twoPointVector( m_Pos, relativePosition ) ) );


    if( abs( distance - m_Radius ) > aThreshold )
    if( abs( distance - m_Radius ) > aThreshold )
        return false;
        return false;
@@ -196,16 +202,16 @@ bool LIB_ARC::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTran
    // We are on the circle, ensure we are only on the arc, i.e. between
    // We are on the circle, ensure we are only on the arc, i.e. between
    //  m_ArcStart and m_ArcEnd
    //  m_ArcStart and m_ArcEnd


    wxPoint startEndVector = TwoPointVector( m_ArcStart, m_ArcEnd);
    wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd);
    wxPoint startRelativePositionVector = TwoPointVector( m_ArcStart, relativePosition );
    wxPoint startRelativePositionVector = twoPointVector( m_ArcStart, relativePosition );


    wxPoint centerStartVector = TwoPointVector( m_Pos, m_ArcStart );
    wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart );
    wxPoint centerEndVector = TwoPointVector( m_Pos, m_ArcEnd );
    wxPoint centerEndVector = twoPointVector( m_Pos, m_ArcEnd );
    wxPoint centerRelativePositionVector = TwoPointVector( m_Pos, relativePosition );
    wxPoint centerRelativePositionVector = twoPointVector( m_Pos, relativePosition );


    // Compute the cross product to check if the point is in the sector
    // Compute the cross product to check if the point is in the sector
    int crossProductStart = CrossProduct( centerStartVector, centerRelativePositionVector );
    double crossProductStart = CrossProduct( centerStartVector, centerRelativePositionVector );
    int crossProductEnd = CrossProduct( centerEndVector, centerRelativePositionVector );
    double crossProductEnd = CrossProduct( centerEndVector, centerRelativePositionVector );


    // The cross products need to be exchanged, depending on which side the center point
    // The cross products need to be exchanged, depending on which side the center point
    // relative to the start point to end point vector lies
    // relative to the start point to end point vector lies
@@ -553,7 +559,7 @@ void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition )
        wxPoint middlePoint = wxPoint( (m_ArcStart.x + m_ArcEnd.x) / 2,
        wxPoint middlePoint = wxPoint( (m_ArcStart.x + m_ArcEnd.x) / 2,
                                       (m_ArcStart.y + m_ArcEnd.y) / 2 );
                                       (m_ArcStart.y + m_ArcEnd.y) / 2 );
        wxPoint centerVector   = m_Pos - middlePoint;
        wxPoint centerVector   = m_Pos - middlePoint;
        wxPoint startEndVector = TwoPointVector( m_ArcStart, m_ArcEnd );
        wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd );
        m_editCenterDistance = EuclideanNorm( centerVector );
        m_editCenterDistance = EuclideanNorm( centerVector );


        // Determine on which side is the center point
        // Determine on which side is the center point
@@ -650,10 +656,10 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
            // Determine if the arc angle is larger than 180 degrees -> this happens if both
            // Determine if the arc angle is larger than 180 degrees -> this happens if both
            // points (cursor position, center point) lie on the same side of the vector
            // points (cursor position, center point) lie on the same side of the vector
            // start-end
            // start-end
            int  crossA = CrossProduct( TwoPointVector( startPos, endPos ),
            double  crossA = CrossProduct( twoPointVector( startPos, endPos ),
                                        TwoPointVector( endPos, aPosition ) );
                                        twoPointVector( endPos, aPosition ) );
            int  crossB = CrossProduct( TwoPointVector( startPos, endPos ),
            double  crossB = CrossProduct( twoPointVector( startPos, endPos ),
                                        TwoPointVector( endPos, newCenterPoint ) );
                                        twoPointVector( endPos, newCenterPoint ) );


            if( ( crossA < 0 && crossB < 0 ) || ( crossA >= 0 && crossB >= 0 ) )
            if( ( crossA < 0 && crossB < 0 ) || ( crossA >= 0 && crossB >= 0 ) )
                newCenterPoint = m_Pos;
                newCenterPoint = m_Pos;
@@ -665,7 +671,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
            wxPoint middlePoint = wxPoint( (startPos.x + endPos.x) / 2,
            wxPoint middlePoint = wxPoint( (startPos.x + endPos.x) / 2,
                                           (startPos.y + endPos.y) / 2 );
                                           (startPos.y + endPos.y) / 2 );


            wxPoint startEndVector = TwoPointVector( startPos, endPos );
            wxPoint startEndVector = twoPointVector( startPos, endPos );
            wxPoint perpendicularVector = wxPoint( -startEndVector.y, startEndVector.x );
            wxPoint perpendicularVector = wxPoint( -startEndVector.y, startEndVector.x );
            double  lengthPerpendicularVector = EuclideanNorm( perpendicularVector );
            double  lengthPerpendicularVector = EuclideanNorm( perpendicularVector );


@@ -736,8 +742,8 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )


void LIB_ARC::calcRadiusAngles()
void LIB_ARC::calcRadiusAngles()
{
{
    wxPoint centerStartVector = TwoPointVector( m_Pos, m_ArcStart );
    wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart );
    wxPoint centerEndVector   = TwoPointVector( m_Pos, m_ArcEnd );
    wxPoint centerEndVector   = twoPointVector( m_Pos, m_ArcEnd );


    m_Radius = KiROUND( EuclideanNorm( centerStartVector ) );
    m_Radius = KiROUND( EuclideanNorm( centerStartVector ) );


+2 −15
Original line number Original line Diff line number Diff line
@@ -587,23 +587,10 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos )
    // TODO: a better analyze of the shape (perhaps create a D_CODE::HitTest for flashed items)
    // TODO: a better analyze of the shape (perhaps create a D_CODE::HitTest for flashed items)
    int     radius = std::min( m_Size.x, m_Size.y ) >> 1;
    int     radius = std::min( m_Size.x, m_Size.y ) >> 1;


    // delta is a vector from m_Start to m_End (an origin of m_Start)
    wxPoint delta = m_End - m_Start;

    // dist is a vector from m_Start to ref_pos (an origin of m_Start)
    wxPoint dist = ref_pos - m_Start;

    if( m_Flashed )
    if( m_Flashed )
    {
        return HitTestPoints( m_Start, ref_pos, radius );
        return (double) dist.x * dist.x + (double) dist.y * dist.y <= (double) radius * radius;
    }
    else
    else
    {
        return TestSegmentHit( ref_pos, m_Start, m_End, radius );
        if( DistanceTest( radius, delta.x, delta.y, dist.x, dist.y ) )
            return true;
    }

    return false;
}
}




+1 −38
Original line number Original line Diff line number Diff line
@@ -44,13 +44,6 @@ void RotatePoint( double *pX, double *pY, double cx, double cy, double angle );
 */
 */
int ArcTangente( int dy, int dx );
int ArcTangente( int dy, int dx );


/**
 * Function DistanceTest
 * Calculate the distance from mouse cursor to a line segment.
 * @return  False if distance > threshold or true if distance <= threshold.
 */
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );

//! @brief Compute the distance between a line and a reference point
//! @brief Compute the distance between a line and a reference point
//! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
//! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
//! @param linePointA Point on line
//! @param linePointA Point on line
@@ -63,12 +56,6 @@ double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint refere
//! @return Euclidean norm of the vector
//! @return Euclidean norm of the vector
double EuclideanNorm( wxPoint vector );
double EuclideanNorm( wxPoint vector );


//! @brief Vector between two points
//! @param startPoint The start point
//! @param endPoint The end point
//! @return Vector between the points
wxPoint TwoPointVector( wxPoint startPoint, wxPoint endPoint );

//! @brief Test, if two points are near each other
//! @brief Test, if two points are near each other
//! @param pointA First point
//! @param pointA First point
//! @param pointB Second point
//! @param pointB Second point
@@ -79,7 +66,7 @@ bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold );
//! @brief Determine the cross product
//! @brief Determine the cross product
//! @param vectorA Two-dimensional vector
//! @param vectorA Two-dimensional vector
//! @param vectorB Two-dimensional vector
//! @param vectorB Two-dimensional vector
int CrossProduct( wxPoint vectorA, wxPoint vectorB );
double CrossProduct( wxPoint vectorA, wxPoint vectorB );




/**
/**
@@ -100,28 +87,4 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
 */
 */
double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB );
double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB );



/*******************/
/* Macro NEW_COORD */
/*******************/

/* Calculate coordinates to rotate around an axis
 *           coord:  xrot = y + x * sin * cos
 *                   yrot = y * cos - sin * x
 *           either: xrot = (y + x * tg) * cos
 *                   yrot = (y - x * tg) * cos
 *
 * Cosine coefficients are loaded from a trigonometric table by 16 bit values.
 */
#define NEW_COORD( x0, y0 )                       \
    do {                                          \
        int itmp;                                 \
        itmp = x0;                                \
        x0 = x0 + (int)( y0 * tg );               \
        y0 = y0 - (int)( itmp * tg );             \
        x0 = ( x0 * cosinus ) >> 8;               \
        y0 = ( y0 * cosinus ) >> 8;               \
    } while( 0 );


#endif
#endif
+9 −73
Original line number Original line Diff line number Diff line
@@ -398,96 +398,32 @@ void DIMENSION::DisplayInfo( EDA_DRAW_FRAME* frame )


bool DIMENSION::HitTest( const wxPoint& aPosition )
bool DIMENSION::HitTest( const wxPoint& aPosition )
{
{
    int ux0, uy0;
    int dx, dy, spot_cX, spot_cY;

    if( m_Text.TextHitTest( aPosition ) )
    if( m_Text.TextHitTest( aPosition ) )
        return true;
        return true;


    // Locate SEGMENTS?
    int dist_max = m_Width / 2;
    ux0 = m_crossBarO.x;
    uy0 = m_crossBarO.y;

    // Recalculate coordinates with ux0, uy0 = origin.
    dx  = m_crossBarF.x - ux0;
    dy  = m_crossBarF.y - uy0;


    spot_cX = aPosition.x - ux0;
    // Locate SEGMENTS
    spot_cY = aPosition.y - uy0;


    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
    if( TestSegmentHit( aPosition, m_crossBarO, m_crossBarF, dist_max ) )
        return true;
        return true;


    ux0 = m_featureLineGO.x;
    if( TestSegmentHit( aPosition, m_featureLineGO, m_featureLineGF, dist_max ) )
    uy0 = m_featureLineGO.y;

    dx  = m_featureLineGF.x - ux0;
    dy  = m_featureLineGF.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    ux0 = m_featureLineDO.x;
    if( TestSegmentHit( aPosition, m_featureLineDO, m_featureLineDF, dist_max ) )
    uy0 = m_featureLineDO.y;

    dx  = m_featureLineDF.x - ux0;
    dy  = m_featureLineDF.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    ux0 = m_arrowD1O.x;
    if( TestSegmentHit( aPosition, m_arrowD1O, m_arrowD1F, dist_max ) )
    uy0 = m_arrowD1O.y;

    dx  = m_arrowD1F.x - ux0;
    dy  = m_arrowD1F.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    ux0 = m_arrowD2O.x;
    if( TestSegmentHit( aPosition, m_arrowD2O, m_arrowD2F, dist_max ) )
    uy0 = m_arrowD2O.y;

    dx  = m_arrowD2F.x - ux0;
    dy  = m_arrowD2F.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    ux0 = m_arrowG1O.x;
    if( TestSegmentHit( aPosition, m_arrowG1O, m_arrowG1F, dist_max ) )
    uy0 = m_arrowG1O.y;

    dx  = m_arrowG1F.x - ux0;
    dy  = m_arrowG1F.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    ux0 = m_arrowG2O.x;
    if( TestSegmentHit( aPosition, m_arrowG2O, m_arrowG2F, dist_max ) )
    uy0 = m_arrowG2O.y;

    dx  = m_arrowG2F.x - ux0;
    dy  = m_arrowG2F.y - uy0;

    spot_cX = aPosition.x - ux0;
    spot_cY = aPosition.y - uy0;

    if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
        return true;
        return true;


    return false;
    return false;
Loading