Commit 4b04d6c2 authored by dickelbeck's avatar dickelbeck
Browse files

fix for magnetic tracks for parallel case, cleanup of original patches

parent 5cb57e3b
Loading
Loading
Loading
Loading
+23 −20
Original line number Original line Diff line number Diff line
@@ -5,6 +5,12 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
Please add newer entries at the top, list the date and your name with
email address.
email address.


2008-Feb-29 UPDATE   Dick Hollenbeck <dick@softplc.com>
================================================================================
+pcbnew
    controle.cpp: fixed the magnetic track if tracks are parallel.


2008-Feb-29 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
2008-Feb-29 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
================================================================================
+eeschema
+eeschema
@@ -12,7 +18,6 @@ email address.
    Use carefully because this can change the whole schematic structure.
    Use carefully because this can change the whole schematic structure.
    Gen Bom List now works in unicode build version
    Gen Bom List now works in unicode build version
    (label list generation crashed eeschema in unicode build version)
    (label list generation crashed eeschema in unicode build version)

+all
+all
    Display filename and full sheet name ("sheet path") in sheet reference
    Display filename and full sheet name ("sheet path") in sheet reference
    the full sheet name has no meanning in pcbnew.
    the full sheet name has no meanning in pcbnew.
@@ -52,8 +57,6 @@ email address.
    Need work to solve this problem and keep the undo/redo feature.
    Need work to solve this problem and keep the undo/redo feature.






2008-Feb-25 UPDATE   Wayne Stambaugh <stambaughw{at}verizon{dot}net>
2008-Feb-25 UPDATE   Wayne Stambaugh <stambaughw{at}verizon{dot}net>
================================================================================
================================================================================
+eeschema
+eeschema
+31 −30
Original line number Original line Diff line number Diff line
@@ -294,6 +294,7 @@ void WinEDA_DrawFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels


    case WXK_NUMPAD2:       /* Deplacement curseur vers le bas */
    case WXK_NUMPAD2:       /* Deplacement curseur vers le bas */
    case WXK_DOWN:
    case WXK_DOWN:
        D(printf("DOWN\n");)
        MousePositionInPixels.y += delta.y;
        MousePositionInPixels.y += delta.y;
        DrawPanel->MouseTo( MousePositionInPixels );
        DrawPanel->MouseTo( MousePositionInPixels );
        break;
        break;
+90 −38
Original line number Original line Diff line number Diff line
@@ -219,14 +219,20 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
}
}




/*
/**
 * "Join" finds the point where b0+x*(b1-b0) intersects with a0+y*(a1-a0).
 * Function Join
 * finds the point where b0+x*(b1-b0) intersects with a0+y*(a1-a0).
 * If that point would be outside of a0-a1, the respective endpoint is used.
 * If that point would be outside of a0-a1, the respective endpoint is used.
 * Join returns the point in "res" and "true" if a suitable point was found,
 * Join returns the point in "res" and "true" if a suitable point was found,
 * "false" if both lines are parallel.
 * "false" if both lines are parallel.
 */
 */
static bool Join( wxPoint& res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 )
static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 )
{
{
    /* References:
        http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
        http://www.gekkou.co.uk/blogs/monologues/2007/12/13/1197586800000.html
    */

    int64_t denom;
    int64_t denom;
    double  t;
    double  t;


@@ -236,14 +242,16 @@ static bool Join( wxPoint& res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 )


    denom = (int64_t) b1.y * a1.x - (int64_t) b1.x * a1.y;
    denom = (int64_t) b1.y * a1.x - (int64_t) b1.x * a1.y;
    if( !denom )
    if( !denom )
    {
        return false;       // parallel
        return false;       // parallel
    }


    t = ((int64_t) b1.y * b0.x - (int64_t) b1.x * b0.y ) / (double) denom;
    t = ((int64_t) b1.y * b0.x - (int64_t) b1.x * b0.y ) / (double) denom;


    t = min( max( t, 0.0 ), 1.0 );
    t = min( max( t, 0.0 ), 1.0 );


    res.x = (int) round(a0.x+t*a1.x);
    res->x = (int) round( a0.x + t * a1.x );
    res.y = (int) round(a0.y+t*a1.y);
    res->y = (int) round( a0.y + t * a1.y );


    return true;
    return true;
}
}
@@ -253,7 +261,7 @@ static bool Join( wxPoint& res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 )
 * "Project" finds the projection of a grid point on a track. This is the point
 * "Project" finds the projection of a grid point on a track. This is the point
 * from where we want to draw new orthogonal tracks when starting on a track.
 * from where we want to draw new orthogonal tracks when starting on a track.
 */
 */
bool Project( wxPoint& res, wxPoint on_grid, const TRACK* track )
bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track )
{
{
    wxPoint vec;
    wxPoint vec;
    double  t;
    double  t;
@@ -269,31 +277,40 @@ bool Project( wxPoint& res, wxPoint on_grid, const TRACK* track )
    t /= (int64_t) vec.x*vec.x + (int64_t) vec.y*vec.y;
    t /= (int64_t) vec.x*vec.x + (int64_t) vec.y*vec.y;
    t = min( max( t, 0.0 ), 1.0 );
    t = min( max( t, 0.0 ), 1.0 );


    res.x = (int) round( track->m_Start.x + t*vec.x );
    res->x = (int) round( track->m_Start.x + t*vec.x );
    res.y = (int) round( track->m_Start.y + t*vec.y );
    res->y = (int) round( track->m_Start.y + t*vec.y );


    return true;
    return true;
}
}




/**
 * Function Magnetize
 * tests to see if there are any magnetic items within near reach of the given
 * "curpos".  If yes, then curpos is adjusted appropriately according to that
 * near magnetic item and true is returned.
 * @param curpos The initial position, and what to adjust if a change is needed.
 */
static bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame,
static bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame,
                       int m_ID_current_state, wxSize grid, wxPoint on_grid, wxPoint& curpos )
                       int aCurrentTool, wxSize grid, wxPoint on_grid, wxPoint* curpos )
{
{
    const D_PAD* pad;
    D_PAD*  pad;
    const TRACK* curr = NULL;
    TRACK*  curr = g_CurrentTrackSegment;
    const TRACK* via, * track;
    TRACK*  via;
    TRACK*  track;
    int     layer, layer_mask;
    int     layer, layer_mask;


    bool         sometimes = g_MagneticPadOption != capture_always && Drc_On;
    bool    doCheckNet = g_MagneticPadOption != capture_always && Drc_On;


    curr = g_CurrentTrackSegment;
    if( frame->GetCurItem() != curr )
    if( frame->GetCurItem() != curr )
    {
        curr = NULL;
        curr = NULL;
    }


    switch( g_MagneticPadOption )
    switch( g_MagneticPadOption )
    {
    {
    case capture_cursor_in_track_tool:
    case capture_cursor_in_track_tool:
        if( m_ID_current_state != ID_TRACK_BUTT )
        if( aCurrentTool != ID_TRACK_BUTT )
            return false;
            return false;
        break;
        break;


@@ -308,20 +325,22 @@ static bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame,
    pad = Locate_Any_Pad( m_Pcb, CURSEUR_OFF_GRILLE, TRUE );
    pad = Locate_Any_Pad( m_Pcb, CURSEUR_OFF_GRILLE, TRUE );
    if( pad )
    if( pad )
    {
    {
        if( curr && curr->GetNet() != pad->GetNet() && sometimes )
        if( doCheckNet && curr && curr->GetNet() != pad->GetNet() )
            return false;
            return false;
        curpos = pad->m_Pos;

        *curpos = pad->m_Pos;
        return true;
        return true;
    }
    }


    layer = ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer;
    layer = ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer;


    via = Locate_Via_Area( m_Pcb, curpos, layer );
    via = Locate_Via_Area( m_Pcb, *curpos, layer );
    if( via )
    if( via )
    {
    {
        if( curr && curr->GetNet() != via->GetNet() && sometimes )
        if( doCheckNet && curr && curr->GetNet() != via->GetNet() )
            return false;
            return false;
        curpos = via->m_Start;

        *curpos = via->m_Start;
        return true;
        return true;
    }
    }


@@ -340,26 +359,58 @@ static bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame,
     * In two segment mode, ignore the final segment if it's inside a grid
     * In two segment mode, ignore the final segment if it's inside a grid
     * square.
     * square.
     */
     */
    if( g_TwoSegmentTrackBuild && curr->Pback
    if( g_TwoSegmentTrackBuild && curr->Back()
        && curr->m_Start.x - grid.x < curr->m_End.x
        && curr->m_Start.x - grid.x < curr->m_End.x
        && curr->m_Start.x + grid.x > curr->m_End.x
        && curr->m_Start.x + grid.x > curr->m_End.x
        && curr->m_Start.y - grid.y < curr->m_End.y
        && curr->m_Start.y - grid.y < curr->m_End.y
        && curr->m_Start.y + grid.y > curr->m_End.y )
        && curr->m_Start.y + grid.y > curr->m_End.y )
    {
        curr = curr->Back();
        curr = curr->Back();
    }


    track = Locate_Pistes( m_Pcb->m_Track, layer_mask, CURSEUR_OFF_GRILLE );
    for( track = m_Pcb->m_Track;  track;  track = track->Next() )
    for( ; track; track = track->Next() )
    {
    {
        if( track->Type() != TYPETRACK )
        if( track->Type() != TYPETRACK )
            continue;
            continue;


        if( curr->GetNet() != track->GetNet() && sometimes )
        if( doCheckNet && curr->GetNet() != track->GetNet() )
            continue;

        if( (g_DesignSettings.m_LayerColor[track->GetLayer()] & ITEM_NOT_SHOW) )
            continue;

        if( !track->IsOnLayer( layer ) )
            continue;

        // @todo, this should be a track overlap test, not a mouse on track test.
        // The former would consider the new track's width.
        if( !track->HitTest( *curpos ) )
            continue;
            continue;


        if( Join( curpos, track->m_Start, track->m_End,
        if( Join( curpos, track->m_Start, track->m_End, curr->m_Start, curr->m_End ) )
               curr->m_Start, curr->m_End ) )
        {
            return true;
        }

        if( aCurrentTool == ID_TRACK_BUTT )
        {
            // At this point we have a drawing mouse on a track, we are drawing
            // a new track and that new track is parallel to the track the
            // mouse is on. Find the nearest end point of the track under mouse
            // to the mouse and return that.
            double distStart = hypot( double( curpos->x - track->m_Start.x ),
                                      double( curpos->y - track->m_Start.y ));

            double distEnd   = hypot( double( curpos->x - track->m_End.x ),
                                      double( curpos->y - track->m_End.y ));

            if( distStart < distEnd )
                *curpos = track->m_Start;
            else
                *curpos = track->m_End;
            return true;
            return true;
        }
        }
    }


    return false;
    return false;
}
}
@@ -505,22 +556,23 @@ void WinEDA_BasePcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )


        PutOnGrid( &on_grid );
        PutOnGrid( &on_grid );
        if( Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state,
        if( Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state,
                        GetScreen()->GetGrid(), on_grid, curpos) )
                        GetScreen()->GetGrid(), on_grid, &curpos) )
        {
            GetScreen()->m_Curseur = curpos;
            GetScreen()->m_Curseur = curpos;
        }
        else
        else
        {
        {
            /*
            // If there's no intrusion and DRC is active, we pass the cursor
             * If there's an intrusion and DRC is active, we pass the cursor
            // "as is", and let ShowNewTrackWhenMovingCursor figure out what to do.
             * "as is", and let ShowNewTrackWhenMovingCursor figure our what to
             * do.
             */
            if(  !Drc_On || !g_CurrentTrackSegment
            if(  !Drc_On || !g_CurrentTrackSegment
              || g_CurrentTrackSegment != this->GetCurItem()
              || g_CurrentTrackSegment != this->GetCurItem()
              || !LocateIntrusion( m_Pcb->m_Track, g_CurrentTrackSegment->GetNet(),
              || !LocateIntrusion( m_Pcb->m_Track, g_CurrentTrackSegment->GetNet(),
                        g_CurrentTrackSegment->m_Width ) )
                        g_CurrentTrackSegment->m_Width ) )
            {
                GetScreen()->m_Curseur = on_grid;
                GetScreen()->m_Curseur = on_grid;
            }
            }
        }
        }
    }


    if( oldpos != GetScreen()->m_Curseur )
    if( oldpos != GetScreen()->m_Curseur )
    {
    {
+27 −30
Original line number Original line Diff line number Diff line
@@ -501,33 +501,29 @@ void WinEDA_PcbFrame::End_Route( TRACK* track, wxDC* DC )
TRACK* LocateIntrusion( TRACK* start, int net, int width )
TRACK* LocateIntrusion( TRACK* start, int net, int width )
{
{
    int     layer = ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer;
    int     layer = ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer;
    int     layer_mask = g_TabOneLayerMask[layer];
    wxPoint ref = ActiveScreen->RefPos( 1 );
    TRACK*  track, * found = NULL;


    for( track = start; track; track = track->Next() )
    wxPoint ref = ActiveScreen->RefPos( true );
    {

        int     dist;
    TRACK*  found = NULL;
        wxPoint pos, vec;
        int64_t tmp;


        /* Locate_Pistes */
    for( TRACK* track = start;  track;  track = track->Next() )
    {
        if( track->Type() == TYPETRACK )    // skip vias
        {
            if( track->GetState( BUSY | DELETED ) )
            if( track->GetState( BUSY | DELETED ) )
                continue;
                continue;


        if( !(g_TabOneLayerMask[track->GetLayer()] & layer_mask) )
            if( layer != track->GetLayer() )
                continue;
                continue;


            if( track->GetNet() == net )
            if( track->GetNet() == net )
                continue;
                continue;


        if( track->Type() == TYPEVIA )
            continue;

            /* TRACK::HitTest */
            /* TRACK::HitTest */
        dist = width / 2 + track->m_Width / 2 + g_DesignSettings.m_TrackClearence;
            int dist = width / 2 + track->m_Width / 2 + g_DesignSettings.m_TrackClearence;
        pos  = ref - track->m_Start;

        vec  = track->m_End - track->m_Start;
            wxPoint pos  = ref - track->m_Start;
            wxPoint vec  = track->m_End - track->m_Start;


            if( !DistanceTest( dist, vec.x, vec.y, pos.x, pos.y ) )
            if( !DistanceTest( dist, vec.x, vec.y, pos.x, pos.y ) )
                continue;
                continue;
@@ -535,10 +531,11 @@ TRACK* LocateIntrusion( TRACK* start, int net, int width )
            found = track;
            found = track;


            /* prefer intrusions from the side, not the end */
            /* prefer intrusions from the side, not the end */
        tmp = (int64_t) pos.x * vec.x + (int64_t) pos.y * vec.y;
            int64_t tmp = (int64_t) pos.x * vec.x + (int64_t) pos.y * vec.y;
            if( tmp >= 0 && tmp <= (int64_t) vec.x * vec.x + (int64_t) vec.y * vec.y )
            if( tmp >= 0 && tmp <= (int64_t) vec.x * vec.x + (int64_t) vec.y * vec.y )
                break;
                break;
        }
        }
    }


    return found;
    return found;
}
}
@@ -612,7 +609,7 @@ static void PushTrack( WinEDA_DrawPanel* panel )
    n.x = (int) round( f * n.x );
    n.x = (int) round( f * n.x );
    n.y = (int) round( f * n.y );
    n.y = (int) round( f * n.y );


    Project( track->m_End, cursor, other );
    Project( &track->m_End, cursor, other );
    track->m_End += n;
    track->m_End += n;
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -387,7 +387,7 @@ TRACK* CreateLockPoint( int* pX, int* pY, TRACK* ptsegm, TRACK* refsegm
/* CONTROLE.CPP */
/* CONTROLE.CPP */
/****************/
/****************/
void RemoteCommand( const char* cmdline );
void RemoteCommand( const char* cmdline );
bool Project( wxPoint& res, wxPoint on_grid, const TRACK* track );
bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track );




/***************/
/***************/