From 1dbf5e21f7e8dbaedeefa2f46f8cc894aa1d37e6 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Wed, 27 Feb 2008 15:26:16 +0000 Subject: [PATCH] beautify --- pcbnew/controle.cpp | 40 +++++----- pcbnew/editrack.cpp | 183 +++++++++++++++++++++++--------------------- pcbnew/protos.h | 3 + 3 files changed, 119 insertions(+), 107 deletions(-) diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index 8b3b0a3ea5..04bb3d5a8a 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -499,27 +499,27 @@ void WinEDA_BasePcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse ) if( DrawStruct && DrawStruct->m_Flags ) keep_on_grid = TRUE; - if (keep_on_grid) { - wxPoint on_grid = curpos; + if( keep_on_grid ) + { + wxPoint on_grid = curpos; - PutOnGrid(&on_grid); - if (Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state, - GetScreen()->GetGrid(), on_grid, curpos)) - GetScreen()->m_Curseur = curpos; - else { - extern TRACK *LocateIntrusion(TRACK *start, int net, int width); - - /* - * If there's an intrusion and DRC is active, we pass the cursor - * "as is", and let ShowNewTrackWhenMovingCursor figure our what to - * do. - */ - if (!Drc_On || !g_CurrentTrackSegment || - g_CurrentTrackSegment != this->GetCurItem() || - !LocateIntrusion(m_Pcb->m_Track, g_CurrentTrackSegment->GetNet(), - g_CurrentTrackSegment->m_Width)) - GetScreen()->m_Curseur = on_grid; - } + PutOnGrid( &on_grid ); + if( Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state, + GetScreen()->GetGrid(), on_grid, curpos) ) + GetScreen()->m_Curseur = curpos; + else + { + /* + * If there's an intrusion and DRC is active, we pass the cursor + * "as is", and let ShowNewTrackWhenMovingCursor figure our what to + * do. + */ + if( !Drc_On || !g_CurrentTrackSegment + || g_CurrentTrackSegment != this->GetCurItem() + || !LocateIntrusion(m_Pcb->m_Track, g_CurrentTrackSegment->GetNet(), + g_CurrentTrackSegment->m_Width ) ) + GetScreen()->m_Curseur = on_grid; + } } if( oldpos != GetScreen()->m_Curseur ) diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 2cabd2843e..dfc5fe9f1f 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -12,6 +12,8 @@ #include "protos.h" #include "drc_stuff.h" +#include "trigo.h" + /* Routines Locales */ @@ -281,6 +283,7 @@ int WinEDA_PcbFrame::Add_45_degrees_Segment( wxDC* DC, TRACK* pt_segm ) pas_45 = GetScreen()->GetGrid().x / 2; if( pas_45 < pt_segm->m_Width ) pas_45 = GetScreen()->GetGrid().x; + while( pas_45 < pt_segm->m_Width ) pas_45 *= 2; @@ -436,6 +439,7 @@ void WinEDA_PcbFrame::End_Route( TRACK* track, wxDC* DC ) { adr_buf = (TRACK*) LockPoint; g_HightLigth_NetCode = adr_buf->GetNet(); + /* creation eventuelle d'un point d'accrochage */ LockPoint = CreateLockPoint( &g_CurrentTrackSegment->m_End.x, &g_CurrentTrackSegment->m_End.y, @@ -493,8 +497,56 @@ void WinEDA_PcbFrame::End_Route( TRACK* track, wxDC* DC ) SetCurItem( NULL ); } -/* - * PushTrack detecs if the mouse is pointing into a conflicting track. + +TRACK* LocateIntrusion( TRACK* start, int net, int width ) +{ + 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() ) + { + int dist; + wxPoint pos, vec; + int64_t tmp; + + /* Locate_Pistes */ + if( track->GetState( BUSY | DELETED ) ) + continue; + + if( !(g_TabOneLayerMask[track->GetLayer()] & layer_mask) ) + continue; + + if( track->GetNet() == net ) + continue; + + if( track->Type() == TYPEVIA ) + continue; + + /* TRACK::HitTest */ + dist = width / 2 + track->m_Width / 2 + g_DesignSettings.m_TrackClearence; + pos = ref - track->m_Start; + vec = track->m_End - track->m_Start; + + if( !DistanceTest( dist, vec.x, vec.y, pos.x, pos.y ) ) + continue; + + found = track; + + /* prefer intrusions from the side, not the end */ + 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 ) + break; + } + + return found; +} + + +/** + * Function PushTrack + * detects if the mouse is pointing into a conflicting track. * In this case, it tries to push the new track out of the conflicting track's * clearance zone. This gives us a cheap mechanism for drawing tracks that * tightly follow others, independent of grid settings. @@ -507,107 +559,64 @@ void WinEDA_PcbFrame::End_Route( TRACK* track, wxDC* DC ) * - if we have a magnetic hit and a DRC violation at the same time, we choose * the magnetic hit instead of solving the violation * - should locate conflicting tracks also when we're crossing over them - * - we obviously shouldn't access functions through "extern" or have #includes - * in the middle of the file */ - -#include "trigo.h" - -extern bool Project(wxPoint &res, wxPoint on_grid, const TRACK *track); - - -TRACK *LocateIntrusion(TRACK *start, int net, int width) +static void PushTrack( WinEDA_DrawPanel* panel ) { - 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()) { - int dist; - wxPoint pos, vec; - int64_t tmp; - - /* Locate_Pistes */ - if (track->GetState(BUSY | DELETED)) - continue; - if (!(g_TabOneLayerMask[track->GetLayer()] & layer_mask)) - continue; - if (track->GetNet() == net) - continue; - if (track->Type() == TYPEVIA) - continue; - - /* TRACK::HitTest */ - dist = width/2 + track->m_Width/2 + g_DesignSettings.m_TrackClearence; - pos = ref-track->m_Start; - vec = track->m_End-track->m_Start; - if (!DistanceTest(dist, vec.x, vec.y, pos.x, pos.y)) - continue; - found = track; - - /* prefer intrusions from the side, not the end */ - 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) - break; - } - return found; -} - - - -static void PushTrack(WinEDA_DrawPanel *panel) -{ - BOARD *pcb = ((WinEDA_BasePcbFrame *) (panel->m_Parent))->m_Pcb; + BOARD* pcb = ( (WinEDA_BasePcbFrame*) (panel->m_Parent) )->m_Pcb; wxPoint cursor = ActiveScreen->m_Curseur; wxPoint cv, vec, n; - TRACK *track = g_CurrentTrackSegment; - TRACK *other; + TRACK* track = g_CurrentTrackSegment; + TRACK* other; int64_t det; - int dist; - double f; + int dist; + double f; - other = LocateIntrusion(pcb->m_Track, track->GetNet(), track->m_Width); + other = LocateIntrusion( pcb->m_Track, track->GetNet(), track->m_Width ); /* are we currently pointing into a conflicting trace ? */ - if (!other) - return; - if (other->GetNet() == track->GetNet()) - return; + if( !other ) + return; - cv = cursor-other->m_Start; - vec = other->m_End-other->m_Start; + if( other->GetNet() == track->GetNet() ) + return; - det = (int64_t) cv.x*vec.y - (int64_t) cv.y*vec.x; + cv = cursor - other->m_Start; + vec = other->m_End - other->m_Start; + + det = (int64_t) cv.x * vec.y - (int64_t) cv.y * vec.x; /* cursor is right at the center of the old track */ - if (!det) - return; + if( !det ) + return; - dist = (track->m_Width+1)/2 + (other->m_Width+1)/2 + - g_DesignSettings.m_TrackClearence+2; - /* - * DRC wants >, so +1. - * We may have a quantization error of 1/sqrt(2), so +1 again. - */ + dist = (track->m_Width + 1) / 2 + (other->m_Width + 1) / 2 + + g_DesignSettings.m_TrackClearence + 2; + + /* + * DRC wants >, so +1. + * We may have a quantization error of 1/sqrt(2), so +1 again. + */ /* Vector "n" is perpendicular to "other", pointing towards the cursor. */ - if (det > 0) { - n.x = vec.y; - n.y = -vec.x; + if( det > 0 ) + { + n.x = vec.y; + n.y = -vec.x; } - else { - n.x = -vec.y; - n.y = vec.x; + else + { + n.x = -vec.y; + n.y = vec.x; } - f = dist/hypot(n.x, n.y); - n.x = (int) round(f*n.x); - n.y = (int) round(f*n.y); + f = dist / hypot( n.x, n.y ); + n.x = (int) round( f * n.x ); + n.y = (int) round( f * n.y ); - Project(track->m_End, cursor, other); + Project( track->m_End, cursor, other ); track->m_End += n; } + /****************************************************************************/ void ShowNewTrackWhenMovingCursor( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) /****************************************************************************/ @@ -653,12 +662,12 @@ void ShowNewTrackWhenMovingCursor( WinEDA_DrawPanel* panel, wxDC* DC, bool erase if( Track_45_Only ) { if( g_TwoSegmentTrackBuild ) { - g_CurrentTrackSegment->m_End = ActiveScreen->m_Curseur; - if (Drc_On) - PushTrack(panel); + g_CurrentTrackSegment->m_End = ActiveScreen->m_Curseur; + if (Drc_On) + PushTrack(panel); ComputeBreakPoint( g_CurrentTrackSegment, g_TrackSegmentCount, - g_CurrentTrackSegment->m_End); - } + g_CurrentTrackSegment->m_End); + } else { /* Calcul de l'extremite de la piste pour orientations permises: diff --git a/pcbnew/protos.h b/pcbnew/protos.h index 880f38795d..19c5d8440b 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -224,6 +224,8 @@ MODULE* Load_Module_From_Library( WinEDA_DrawFrame* frame, wxDC* DC ); /* EDITRACK.C : */ /****************/ +TRACK* LocateIntrusion( TRACK* start, int net, int width ); + void ShowNewTrackWhenMovingCursor( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); @@ -385,6 +387,7 @@ TRACK* CreateLockPoint( int* pX, int* pY, TRACK* ptsegm, TRACK* refsegm /* CONTROLE.CPP */ /****************/ void RemoteCommand( const char* cmdline ); +bool Project( wxPoint& res, wxPoint on_grid, const TRACK* track ); /***************/