Commit edf64afc authored by charras's avatar charras
Browse files

Eeschema: Added patch from Torsten Huter addeing hotkeys and enhancements in libeditor

Some fixes.
parent ac97a574
Loading
Loading
Loading
Loading
+1486 −1451
Original line number Original line Diff line number Diff line
@@ -388,6 +388,41 @@ void RotatePoint( double* pX, double* pY, int angle )
}
}




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


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


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


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

    return distance < threshold;
}


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


double fsinus[3600] =
double fsinus[3600] =
{
{
    0.0000000000,  0.0017453284,  0.0034906514,  0.0052359638,
    0.0000000000,  0.0017453284,  0.0034906514,  0.0052359638,
+4 −0
Original line number Original line Diff line number Diff line
@@ -514,6 +514,10 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )


    /* save the new list: */
    /* save the new list: */
    ITEM_PICKER item;
    ITEM_PICKER item;
    // In list the wrapper is owner of the shematic item, we can use the UR_DELETED
    // status for the picker because pickers with this status are owner of the picked item
    // (or TODO ?: create a new status like UR_DUPLICATE)
    item.m_UndoRedoStatus = UR_DELETED;
    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    {
    {
        /* Make a copy of the original picked item. */
        /* Make a copy of the original picked item. */
+47 −38
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
#include "protos.h"
#include "protos.h"
#include "classes_body_items.h"
#include "classes_body_items.h"



static int fill_tab[3] = { 'N', 'F', 'f' };
static int fill_tab[3] = { 'N', 'F', 'f' };


//#define DRAW_ARC_WITH_ANGLE       // Used to draw arcs
//#define DRAW_ARC_WITH_ANGLE       // Used to draw arcs
@@ -231,13 +230,12 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;


    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if( mindist < 3 )
    if( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;


    return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
    return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
}
}



/** Function HitTest
/** Function HitTest
 * @return true if the point aPosRef is near this object
 * @return true if the point aPosRef is near this object
 * @param aRefPoint = a wxPoint to test
 * @param aRefPoint = a wxPoint to test
@@ -245,38 +243,45 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
 *                     of a line)
 *                     of a line)
 * @param aTransMat = the transform matrix
 * @param aTransMat = the transform matrix
 */
 */
bool LIB_ARC::HitTest( wxPoint aRefPoint, int aThreshold,
bool LIB_ARC::HitTest( wxPoint aReferencePoint, int aThreshold,
                       const int aTransMat[2][2] )
                       const int aTransformationMatrix[2][2] )
{
{

    // TODO: use aTransMat to calculmates parameters
    // TODO: use aTransMat to calculmates parameters
    wxPoint relpos = aRefPoint;
    wxPoint relativePosition = aReferencePoint;


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


    relpos -= m_Pos;
    int distance = wxRound( EuclideanNorm(TwoPointVector(m_Pos, relativePosition) ) );
    int dist = wxRound( sqrt( ( (double) relpos.x * (double) relpos.x ) +
                              ( (double) relpos.y * (double) relpos.y ) ) );


    if( abs( dist - m_Radius ) > aThreshold )
    if( abs( distance - m_Radius ) > aThreshold )
        return false;
        return false;


    // 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
    int astart = m_t1;    // arc starting point ( in 0.1 degree)
    int aend   = m_t2;    // arc ending point ( in 0.1 degree)
    int atest  = wxRound( atan2( (double) relpos.y,
                                 (double) relpos.x ) * 1800.0 / M_PI );
    NORMALIZE_ANGLE_180( atest );
    NORMALIZE_ANGLE_180( astart );
    NORMALIZE_ANGLE_180( aend );

    if( astart > aend )
        EXCHG( astart, aend );

    if( atest >= astart && atest <= aend )
        return true;


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

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

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

    // The cross products need to be exchanged, depending on which side the center point
    // relative to the start point to end point vector lies
    if (CrossProduct(startEndVector, startRelativePositionVector) < 0 ){
    	EXCHG(crossProductStart, crossProductEnd);
    }

    // When the cross products have a different sign, the point lies in sector
    // also check, if the reference is near start or end point
    return 	HitTestPoints(m_ArcStart, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
    		HitTestPoints(m_ArcEnd, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
    		(crossProductStart <= 0 && crossProductEnd >= 0);
}
}




@@ -603,8 +608,8 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;


    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if( mindist < 3 )
    if( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;


    return HitTest( aPosRef, mindist, DefaultTransformMatrix );
    return HitTest( aPosRef, mindist, DefaultTransformMatrix );
}
}
@@ -811,6 +816,9 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) :
    m_Fill       = NO_FILL;
    m_Fill       = NO_FILL;
    m_isFillable = true;
    m_isFillable = true;
    m_typeName   = _( "Rectangle" );
    m_typeName   = _( "Rectangle" );
    m_isHeightLocked = false;
    m_isWidthLocked = false;
    m_isStartPointSelected = false;
}
}




@@ -1037,8 +1045,8 @@ bool LIB_RECTANGLE::HitTest( const wxPoint& aRefPoint )
    int mindist = (m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2) + 1;
    int mindist = (m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2) + 1;


    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if( mindist < 3 )
    if( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;


    return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
    return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
}
}
@@ -1079,8 +1087,9 @@ bool LIB_RECTANGLE::HitTest( wxPoint aRefPoint, int aThreshold,
        return true;
        return true;


    // locate left segment
    // locate left segment
    start.x = actualStart.x;
    start = actualStart;
    end.x   = actualStart.y;
    end.x = actualStart.x;
    end.y = actualEnd.y;
    if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
    if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
        return true;
        return true;


@@ -1282,8 +1291,8 @@ bool LIB_SEGMENT::HitTest( const wxPoint& aPosRef )
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;


    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if( mindist < 3 )
    if( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;


    return HitTest( aPosRef, mindist, DefaultTransformMatrix );
    return HitTest( aPosRef, mindist, DefaultTransformMatrix );
}
}
@@ -1613,8 +1622,8 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aRefPos )
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
    int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;


    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if( mindist < 3 )
    if( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;
    return HitTest( aRefPos, mindist, DefaultTransformMatrix );
    return HitTest( aRefPos, mindist, DefaultTransformMatrix );
}
}


@@ -1980,8 +1989,8 @@ bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
{
{
    int mindist = m_Width ? m_Width /2 : g_DrawDefaultLineThickness / 2;
    int mindist = m_Width ? m_Width /2 : g_DrawDefaultLineThickness / 2;
    // Have a minimal tolerance for hit test
    // Have a minimal tolerance for hit test
    if ( mindist < 3 )
    if ( mindist < MINIMUM_SELECTION_DISTANCE )
        mindist = 3;        // = 3 mils
        mindist = MINIMUM_SELECTION_DISTANCE;
    return HitTest( aRefPos, mindist, DefaultTransformMatrix );
    return HitTest( aRefPos, mindist, DefaultTransformMatrix );
}
}


+5 −1
Original line number Original line Diff line number Diff line
@@ -32,7 +32,7 @@ class LIB_PIN;
#define CLOCK_PIN_DIM       40  /* Dim of clock pin symbol. */
#define CLOCK_PIN_DIM       40  /* Dim of clock pin symbol. */
#define IEEE_SYMBOL_PIN_DIM 40  /* Dim of special pin symbol. */
#define IEEE_SYMBOL_PIN_DIM 40  /* Dim of special pin symbol. */



#define MINIMUM_SELECTION_DISTANCE 15 // Minimum selection distance in mils


/**
/**
 * The component library pin object electrical types used in ERC tests.
 * The component library pin object electrical types used in ERC tests.
@@ -978,6 +978,9 @@ public:
    wxPoint m_End;     /* Rectangle end point. */
    wxPoint m_End;     /* Rectangle end point. */
    wxPoint m_Pos;     /* Rectangle start point. */
    wxPoint m_Pos;     /* Rectangle start point. */
    int     m_Width;   /* Line width */
    int     m_Width;   /* Line width */
    bool	m_isWidthLocked; /* Flag: Keep width locked */
    bool	m_isHeightLocked; /* Flag: Keep height locked */
    bool	m_isStartPointSelected; /* Flag: is the upper left edge selected ? */


public:
public:
    LIB_RECTANGLE(LIB_COMPONENT * aParent);
    LIB_RECTANGLE(LIB_COMPONENT * aParent);
@@ -1146,6 +1149,7 @@ class LIB_POLYLINE : public LIB_DRAW_ITEM
public:
public:
    int m_Width;                            /* Line width */
    int m_Width;                            /* Line width */
    std::vector<wxPoint> m_PolyPoints;      // list of points (>= 2)
    std::vector<wxPoint> m_PolyPoints;      // list of points (>= 2)
    int m_ModifyIndex;						// Index of the polyline point to modify


public:
public:
    LIB_POLYLINE(LIB_COMPONENT * aParent);
    LIB_POLYLINE(LIB_COMPONENT * aParent);
+196 −195
Original line number Original line Diff line number Diff line
@@ -166,6 +166,7 @@ enum id_eeschema_frm
	ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
	ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
	ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
	ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
	ID_POPUP_LIBEDIT_DELETE_ITEM,
	ID_POPUP_LIBEDIT_DELETE_ITEM,
	ID_POPUP_LIBEDIT_MODIFY_ITEM,
	ID_POPUP_LIBEDIT_END_CREATE_ITEM,
	ID_POPUP_LIBEDIT_END_CREATE_ITEM,
	ID_POPUP_LIBEDIT_CANCEL_EDITING,
	ID_POPUP_LIBEDIT_CANCEL_EDITING,
	ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
	ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
Loading