diff options
Diffstat (limited to 'app/bin/cpull.c')
-rw-r--r-- | app/bin/cpull.c | 344 |
1 files changed, 197 insertions, 147 deletions
diff --git a/app/bin/cpull.c b/app/bin/cpull.c index 7f27864..af6642e 100644 --- a/app/bin/cpull.c +++ b/app/bin/cpull.c @@ -17,19 +17,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <math.h> - #include "cselect.h" #include "compound.h" #include "cundo.h" #include "fileio.h" -#include "i18n.h" -#include "messages.h" #include "track.h" -#include "utility.h" +#include "draw.h" +#include "common-ui.h" int debugPull = 0; @@ -40,22 +37,22 @@ DIST_T littleD = 0.1; static double factorX=10, factorY=100, factorA=0.2; typedef struct { - double X, Y, A, T; - } cost_t; + double X, Y, A, T; +} cost_t; static cost_t sumCosts; static cost_t maxCosts; static int maxCostsInx; typedef struct { - coOrd p[2]; - ANGLE_T a[2]; - ANGLE_T angle; - DIST_T dist; - track_p trk; - EPINX_T ep[2]; - cost_t costs[2]; - double contrib; - coOrd pp; - } section_t, *section_p; + coOrd p[2]; + ANGLE_T a[2]; + ANGLE_T angle; + DIST_T dist; + track_p trk; + EPINX_T ep[2]; + cost_t costs[2]; + double contrib; + coOrd pp; +} section_t, *section_p; static dynArr_t section_da; #define section(N) DYNARR_N( section_t, section_da, N ) static double contribL, contribR; @@ -70,10 +67,10 @@ typedef enum { freeEnd, connectedEnd, loopEnd } ending_e; * Utilities */ static ending_e GetConnectedTracks( - track_p trk, - EPINX_T ep, - track_p endTrk, - EPINX_T endEp ) + track_p trk, + EPINX_T ep, + track_p endTrk, + EPINX_T endEp ) { track_p trk1; EPINX_T ep1, ep2; @@ -84,15 +81,15 @@ static ending_e GetConnectedTracks( trk1 = NULL; } else { ep2 = GetNextTrk( trk, ep, &trk1, &ep1, 0 ); - if (trk1 == NULL) + if (trk1 == NULL) { return freeEnd; + } } if ( ep2 >= 0 ) { int inx; - for (inx=0;inx<section_da.cnt;inx++) { - if ( section(inx).trk == trk ) { - AbortProg("GetConnectedTracks(T%d already selected)", GetTrkIndex(trk)); - } + for (inx=0; inx<section_da.cnt; inx++) { + CHECKMSG( section(inx).trk != trk, ("GetConnectedTracks(T%d already selected)", + GetTrkIndex(trk)) ); } } DYNARR_APPEND( section_t, section_da, 10 ); @@ -102,17 +99,19 @@ static ending_e GetConnectedTracks( sp->ep[1] = ep2; sp->p[0] = GetTrkEndPos(trk,ep); sp->costs[0].X = sp->costs[0].Y = sp->costs[0].A = sp->costs[0].T = - sp->costs[1].X = sp->costs[1].Y = sp->costs[1].A = sp->costs[1].T =0.0; + sp->costs[1].X = sp->costs[1].Y = sp->costs[1].A = sp->costs[1].T =0.0; sp->a[0] = GetTrkEndAngle(trk,ep); sp->a[1] = 0; - if (ep2 < 0) + if (ep2 < 0) { return connectedEnd; + } sp->p[1] = GetTrkEndPos(trk,ep2); sp->dist = FindDistance( GetTrkEndPos(trk,ep), GetTrkEndPos(trk,ep2) ); sp->angle = NormalizeAngle( GetTrkEndAngle(trk,ep2)-GetTrkEndAngle(trk,ep) ); sp->a[1] = GetTrkEndAngle(trk,ep2); - if (trk == endTrk) + if (trk == endTrk) { return loopEnd; + } trk = trk1; ep = ep1; } @@ -122,10 +121,10 @@ static ending_e GetConnectedTracks( * Simple move to connect */ static void MoveConnectedTracks( - track_p trk1, - EPINX_T ep1, - coOrd pos, - ANGLE_T angle ) + track_p trk1, + EPINX_T ep1, + coOrd pos, + ANGLE_T angle ) { EPINX_T ep, ep2; track_p trk; @@ -143,10 +142,10 @@ static void MoveConnectedTracks( RotateTrack( trk1, pos, a ); DrawNewTrack( trk1 ); ep2 = GetNextTrk( trk1, ep1, &trk, &ep, 0 ); - if (trk==NULL) + if (trk==NULL) { return; - if (ep2 < 0) - AbortProg("MoveConnectedTracks(T%d rooted)", GetTrkIndex(trk1)); + } + CHECKMSG( ep2 >= 0, ("MoveConnectedTracks(T%d rooted)", GetTrkIndex(trk1)) );; angle = NormalizeAngle(GetTrkEndAngle( trk1, ep2 )+180.0); pos = GetTrkEndPos( trk1, ep2 ); trk1 = trk; @@ -159,7 +158,7 @@ static void MoveConnectedTracks( * Helpers for complex case */ static void ReverseSectionList( - int start, int end ) + int start, int end ) { int up, down; section_t tmpUp, tmpDown; @@ -203,25 +202,28 @@ static int CheckConnections( void ) sp = §ion(inx); dist = FindDistance( sp[0].p[0], sp[-1].p[1] ); angle = NormalizeAngle( sp[0].a[0] - sp[-1].a[1] + 180.0 + connectAngle/2 ); - if (dist > connectDistance) + if (dist > connectDistance) { rc |= DIST_FAULT; - if (angle > connectAngle) + } + if (angle > connectAngle) { rc |= ANGLE_FAULT; + } } return rc; } static void ComputeCost( - coOrd p, - ANGLE_T a, - section_p sp ) + coOrd p, + ANGLE_T a, + section_p sp ) { ANGLE_T da; coOrd pp; da = NormalizeAngle( sp->a[0]+180.0-a ); - if (da>180) + if (da>180) { da = 360.0-a; + } sp->costs[0].A = da*factorA; pp = sp->p[0]; Rotate( &pp, p, -a ); @@ -229,8 +231,9 @@ static void ComputeCost( pp.y -= p.y; sp->costs[0].X = fabs(pp.y*factorX); sp->costs[0].Y = fabs(pp.x*factorY); - if ( pp.x < -0.010 ) + if ( pp.x < -0.010 ) { sp->costs[0].X *= 100; + } sp->costs[0].T = sp->costs[0].X+sp->costs[0].Y; } @@ -245,9 +248,9 @@ static void ComputeCosts( void ) for (inx=1; inx<section_da.cnt; inx++) { sp = §ion(inx); ComputeCost( sp[-1].p[1], sp[-1].a[1], sp ); -if (debugPull) { -/*printf("%2d: X=%0.3f Y=%0.3f A=%0.3f T=%0.3f\n", inx, sp->costs[0].X, sp->costs[0].Y, sp->costs[0].A, sp->costs[0].T );*/ -} + if (debugPull) { + /*printf("%2d: X=%0.3f Y=%0.3f A=%0.3f T=%0.3f\n", inx, sp->costs[0].X, sp->costs[0].Y, sp->costs[0].A, sp->costs[0].T );*/ + } sumCosts.A += sp->costs[0].A; sumCosts.X += sp->costs[0].X; sumCosts.Y += sp->costs[0].Y; @@ -264,11 +267,11 @@ if (debugPull) { static double ComputeContrib( - DIST_T dist, - ANGLE_T angle, - int start, - int end, - EPINX_T ep ) + DIST_T dist, + ANGLE_T angle, + int start, + int end, + EPINX_T ep ) { int inx; section_p sp; @@ -295,27 +298,30 @@ static void ComputeContribs( coOrd *rp1 ) Rotate( &p1, p0, -sp[0].a[0] ); p1.x -= p0.x; p1.y -= p0.y; - if (sp->costs[0].X > 0.000001 && sp->costs[0].X > aveX) + if (sp->costs[0].X > 0.000001 && sp->costs[0].X > aveX) { p1.y *= 1-aveX/sp->costs[0].X; - else + } else { p1.y = 0.0; - if (sp->costs[0].Y > 0.000001 && sp->costs[0].Y > aveY) + } + if (sp->costs[0].Y > 0.000001 && sp->costs[0].Y > aveY) { p1.x *= 1-aveY/sp->costs[0].Y; - else + } else { p1.x = 0.0; + } Rotate( &p1, zero, sp[0].a[0] ); dist = FindDistance( zero, p1 ); angle = FindAngle( zero, p1 ); - contribL = ComputeContrib( dist, NormalizeAngle(angle+180.0), 1, maxCostsInx-1, 0 ); + contribL = ComputeContrib( dist, NormalizeAngle(angle+180.0), 1, maxCostsInx-1, + 0 ); contribR = ComputeContrib( dist, angle, maxCostsInx, section_da.cnt-2, 1 ); if (debugPull) { printf( "Minx=%d D=%0.3f A=%0.3f X=%0.3f Y=%0.3f L=%0.3f R=%0.3f\n", - maxCostsInx, dist, angle, p1.x, p1.y, contribL, contribR ); + maxCostsInx, dist, angle, p1.x, p1.y, contribL, contribR ); sp = §ion(0); printf( " 0[%d] [%0.3f %0.3f] [%0.3f %0.3f]\n", - GetTrkIndex(sp->trk), - sp[0].p[0].x, sp[0].p[0].y, sp[0].p[1].x, sp[0].p[1].y ); + GetTrkIndex(sp->trk), + sp[0].p[0].x, sp[0].p[0].y, sp[0].p[1].x, sp[0].p[1].y ); } *rp1 = p1; } @@ -325,8 +331,8 @@ static void ComputeContribs( coOrd *rp1 ) * Shufflers */ static void AdjustSection( - section_p sp, - coOrd amount ) + section_p sp, + coOrd amount ) { sp->p[0].x += amount.x; sp->p[0].y += amount.y; @@ -371,13 +377,16 @@ static void DumpSections( void ) sp = §ion(inx); dist = FindDistance( sp[0].p[0], sp[-1].p[1] ); printf( "%2d[%d] X%0.3f Y%0.3f A%0.3f T%0.3f C%0.3f x%0.3f y%0.3f [%0.3f %0.3f] [%0.3f %0.3f] dd%0.3f da%0.3f\n", - inx, GetTrkIndex(sp->trk), sp->costs[0].X, sp->costs[0].Y, sp->costs[0].A, sp->costs[0].T, - sp->contrib, sp->pp.x, sp->pp.y, - sp[0].p[0].x, sp[0].p[0].y, sp[0].p[1].x, sp[0].p[1].y, - dist, - (dist>0.001)?NormalizeAngle( FindAngle( sp[0].p[0], sp[-1].p[1] ) - sp[0].a[0] ):0.0 ); + inx, GetTrkIndex(sp->trk), sp->costs[0].X, sp->costs[0].Y, sp->costs[0].A, + sp->costs[0].T, + sp->contrib, sp->pp.x, sp->pp.y, + sp[0].p[0].x, sp[0].p[0].y, sp[0].p[1].x, sp[0].p[1].y, + dist, + (dist>0.001)?NormalizeAngle( FindAngle( sp[0].p[0], + sp[-1].p[1] ) - sp[0].a[0] ):0.0 ); } - printf("== X%0.3f Y%0.3f A%0.3f T%0.3f\n", sumCosts.X, sumCosts.Y, sumCosts.A, sumCosts.T ); + printf("== X%0.3f Y%0.3f A%0.3f T%0.3f\n", sumCosts.X, sumCosts.Y, sumCosts.A, + sumCosts.T ); } @@ -390,22 +399,28 @@ static int MinimizeCosts( void ) int inx; int rc = 0; coOrd p1; - if (section_da.cnt <= 0) + if (section_da.cnt <= 0) { return FALSE; + } for (inx=0; inx<iterCnt; inx++) { rc = CheckConnections(); ComputeCosts(); - if (maxCostsInx<0) + if (maxCostsInx<0) { return TRUE; + } ComputeContribs( &p1 ); - if (contribR+contribL <= 0.001) + if (contribR+contribL <= 0.001) { return rc; + } if (maxCosts.T*1.1 < sumCosts.T/(contribR+contribL) && rc) /* our work is done */ + { return rc; + } AdjustSections( p1 ); - if (debugPull) + if (debugPull) { DumpSections(); + } } return rc; } @@ -425,9 +440,9 @@ static void MoveSectionTracks( void ) oldPos = GetTrkEndPos( sp->trk, sp->ep[0] ); amount.x = sp->p[0].x-oldPos.x; amount.y = sp->p[0].y-oldPos.y; -if (debugPull) { -printf("%2d: X%0.3f Y%0.3f\n", inx, amount.x, amount.y ); -} + if (debugPull) { + printf("%2d: X%0.3f Y%0.3f\n", inx, amount.x, amount.y ); + } if (fabs(amount.x)>0.001 || fabs(amount.y)>0.001) { UndrawNewTrack( sp->trk ); UndoModify( sp->trk ); @@ -441,10 +456,10 @@ printf("%2d: X%0.3f Y%0.3f\n", inx, amount.x, amount.y ); static void PullTracks( - track_p trk1, - EPINX_T ep1, - track_p trk2, - EPINX_T ep2 ) + track_p trk1, + EPINX_T ep1, + track_p trk2, + EPINX_T ep2 ) { ending_e e1, e2; DIST_T d; @@ -452,7 +467,8 @@ static void PullTracks( coOrd p1, p2; ANGLE_T a1, a2; coOrd p; - int cnt1, cnt2; + int cnt1; +// int cnt2; int rc; if (QueryTrack(trk1,Q_CAN_ADD_ENDPOINTS)) { @@ -463,13 +479,15 @@ static void PullTracks( return; } - if (ep1<0 || ep2<0 ) return; + if (ep1<0 || ep2<0 ) { return; } - if (ConnectAbuttingTracks( trk1, ep1, trk2, ep2 )) + if (ConnectAbuttingTracks( trk1, ep1, trk2, ep2 )) { return; + } - if (ConnectAdjustableTracks( trk1, ep1, trk2, ep2 )) + if (ConnectAdjustableTracks( trk1, ep1, trk2, ep2 )) { return; + } p1 = GetTrkEndPos( trk1, ep1 ); @@ -482,23 +500,25 @@ static void PullTracks( ErrorMessage( MSG_TOO_FAR_APART_DIVERGE ); return; } - UndoStart( _("Pull Tracks"), "PullTracks(T%d[%d] T%d[%d] D%0.3f A%0.3F )", GetTrkIndex(trk1), ep1, GetTrkIndex(trk2), ep2, d, a ); - + UndoStart( _("Pull Tracks"), "PullTracks(T%d[%d] T%d[%d] D%0.3f A%0.3F )", + GetTrkIndex(trk1), ep1, GetTrkIndex(trk2), ep2, d, a ); + DYNARR_RESET( section_t, section_da ); e1 = e2 = GetConnectedTracks( trk1, ep1, trk2, ep2 ); cnt1 = section_da.cnt; if ( e1 != loopEnd ) { e2 = GetConnectedTracks( trk2, ep2, trk1, ep1 ); - } - cnt2 = section_da.cnt - cnt1; + } +// cnt2 = section_da.cnt - cnt1; if ( e1 == freeEnd && e2 == freeEnd ) { p.x = (p1.x+p2.x)/2.0; p.y = (p1.y+p2.y)/2.0; a = NormalizeAngle( (a1-(a2+180.0)) ); - if ( a < 180.0 ) + if ( a < 180.0 ) { a = NormalizeAngle(a1 + a/2.0); - else + } else { a = NormalizeAngle(a1 - (360-a)/2.0); + } MoveConnectedTracks( trk1, ep1, p, a ); MoveConnectedTracks( trk2, ep2, p, a+180.0 ); } else if ( e1 == freeEnd ) { @@ -548,8 +568,8 @@ static void PullTracks( */ static void TightenTracks( - track_p trk, - EPINX_T ep ) + track_p trk, + EPINX_T ep ) { track_p trk1; EPINX_T ep1, ep2; @@ -562,8 +582,9 @@ static void TightenTracks( ep = ep1; } trk1 = GetTrkEndTrk( trk, ep ); - if (trk1 == NULL) + if (trk1 == NULL) { return; + } ep1 = GetEndPtConnectedToMe( trk1, trk ); cnt = 0; while(1) { @@ -574,9 +595,9 @@ static void TightenTracks( p1.x = p0.x - p1.x; p1.y = p0.y - p1.y; a1 = NormalizeAngle( a0-a1 ); -if (debugPull) { -printf("T%d [%0.3f %0.3f %0.3f]\n", GetTrkIndex(trk1), p1.x, p1.y, a1 ); -} + if (debugPull) { + printf("T%d [%0.3f %0.3f %0.3f]\n", GetTrkIndex(trk1), p1.x, p1.y, a1 ); + } if ( FindDistance( zero, p1 ) > 0.001 || ( a1 > 0.05 && a1 < 365.95 ) ) { UndrawNewTrack( trk1 ); UndoModify( trk1 ); @@ -587,15 +608,16 @@ printf("T%d [%0.3f %0.3f %0.3f]\n", GetTrkIndex(trk1), p1.x, p1.y, a1 ); } trk = trk1; ep = GetNextTrk( trk, ep1, &trk1, &ep1, 0 ); - if (trk1 == NULL) + if (trk1 == NULL) { break; - if (ep<0) - AbortProg( "tightenTracks: can't happen" ); + } + CHECK(ep>=0); } InfoMessage( _("%d tracks moved"), cnt ); } -static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) { +static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) +{ coOrd pos = GetTrkEndPos(t,ep); DIST_T d = tempD.scale*0.15; DIST_T w = tempD.scale/tempD.dpi*4; @@ -609,7 +631,7 @@ static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) { anchors(i).u.l.pos[0] = pos; Translate(&anchors(i).u.l.pos[1],pos,a+90,-GetTrkGauge(t)); Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a,-d); - anchors(i).width = w; + anchors(i).lineWidth = w; DYNARR_APPEND(trkSeg_t,anchors_da,1); i = anchors_da.cnt-1; anchors(i).type = SEG_STRLIN; @@ -617,7 +639,7 @@ static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) { anchors(i).u.l.pos[0] = pos; Translate(&anchors(i).u.l.pos[1],pos,a+90,GetTrkGauge(t)); Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a,-d); - anchors(i).width = w; + anchors(i).lineWidth = w; } else { DYNARR_APPEND(trkSeg_t,anchors_da,1); i = anchors_da.cnt-1; @@ -627,7 +649,7 @@ static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) { Translate(&anchors(i).u.l.pos[0],anchors(i).u.l.pos[0],a,d); Translate(&anchors(i).u.l.pos[1],pos,a+90,-GetTrkGauge(t)); Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a,-d); - anchors(i).width = w; + anchors(i).lineWidth = w; DYNARR_APPEND(trkSeg_t,anchors_da,1); i = anchors_da.cnt-1; anchors(i).type = SEG_STRLIN; @@ -636,24 +658,28 @@ static void CreateConnectAnchor(EPINX_T ep, track_p t, BOOL_T shift) { Translate(&anchors(i).u.l.pos[0],anchors(i).u.l.pos[0],a,-d); Translate(&anchors(i).u.l.pos[1],pos,a+90,-GetTrkGauge(t)); Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a,d); - anchors(i).width = w; + anchors(i).lineWidth = w; } } -STATUS_T ConnectMultiple() { +STATUS_T ConnectMultiple() +{ int countTracksR0 =0,countTracksR1 =0, possibleEndPoints =0; if (selectedTrackCount==0) { - ErrorMessage(_("Connect Multiple Tracks - Select multiple tracks to join first")); + ErrorMessage( + _("Connect Multiple Tracks - Select multiple tracks to join first")); return C_CONTINUE; } - if (NoticeMessage(_("Try to Connect all Selected Tracks?"), _("Yes"), _("No"))<=0) return C_CONTINUE; + if (NoticeMessage(_("Try to Connect all Selected Tracks?"), _("Yes"), + _("No"))<=0) { return C_CONTINUE; } track_p trk1 = NULL; track_p trk2 = NULL; EPINX_T ep1,ep2; ANGLE_T a; DIST_T d; UndoStart( _("ReConnect"),"Try to reconnect all selected tracks"); - for (int i=0;i<2;i++) { // Try twice - in case later joins help earlier ones and to try close ones first + for (int i=0; i<2; + i++) { // Try twice - in case later joins help earlier ones and to try close ones first while ( TrackIterate( &trk1 ) ) { BOOL_T found = FALSE; if ( GetTrkSelected( trk1 ) ) { @@ -661,42 +687,46 @@ STATUS_T ConnectMultiple() { if (!GetTrkEndTrk( trk1, ep1 )) { trk2 = NULL; while (!found && TrackIterate(&trk2) ) { - if (trk1 == trk2) continue; + if (trk1 == trk2) { continue; } for (ep2=0; ep2<GetTrkEndPtCnt(trk2); ep2++) { - if (GetTrkEndTrk( trk2, ep2 )) continue; + if (GetTrkEndTrk( trk2, ep2 )) { continue; } d = FindDistance(GetTrkEndPos(trk1,ep1),GetTrkEndPos(trk2,ep2)); - a = NormalizeAngle( 180+GetTrkEndAngle( trk1, ep1 ) - GetTrkEndAngle( trk2, ep2 )+(connectAngle/2.0)); + a = NormalizeAngle( 180+GetTrkEndAngle( trk1, ep1 ) - GetTrkEndAngle( trk2, + ep2 )+(connectAngle/2.0)); // Take two passes. In round one favor closer connections. In round two try anything. if ( (i==0 && (d < connectDistance) && (a < connectAngle)) || - (i>0 && (d<3.0 && a<7.5))) { // Match PullTracks criteria in round 2 + (i>0 && (d<3.0 && a<7.5))) { // Match PullTracks criteria in round 2 PullTracks(trk1,ep1,trk2,ep2); if (GetTrkEndTrk( trk2, ep2 )) { found = TRUE; - if (i==0) + if (i==0) { countTracksR0++; - else + } else { countTracksR1++; + } break; //Stop looking - } else if (i==1) possibleEndPoints++; + } else if (i==1) { possibleEndPoints++; } } } } - if (found) break; //Next EndPoint + if (found) { break; } //Next EndPoint } } } } } UndoEnd(); - NoticeMessage(_("Round 1 %d and Round 2 %d tracks connected, %d close pairs of end Points were not connected"), _("Ok"), NULL, countTracksR0, countTracksR1, possibleEndPoints); + NoticeMessage( + _("Round 1 %d and Round 2 %d tracks connected, %d close pairs of end Points were not connected"), + _("Ok"), NULL, countTracksR0, countTracksR1, possibleEndPoints); return C_TERMINATE; } static wMenu_p pullPopupM; static STATUS_T CmdPull( - wAction_t action, - coOrd pos ) + wAction_t action, + coOrd pos ) { static track_p trk1, t1, t2; @@ -706,16 +736,19 @@ static STATUS_T CmdPull( EPINX_T ep2; static BOOL_T turntable; - int countTracksR0 = 0, countTracksR1 = 0, possibleEndPoints = 0; - BOOL_T found = FALSE; +// int countTracksR0 = 0, countTracksR1 = 0, possibleEndPoints = 0; +// BOOL_T found = FALSE; switch (action&0xFF) { case C_START: - if (selectedTrackCount==0) - InfoMessage( _("Select first endpoint or turntable to connect, +Shift to tighten") ); - else - InfoMessage( _("Select first endpoint to connect, or Right-Click for connecting selected tracks (not turntable)") ); + if (selectedTrackCount==0) { + InfoMessage( + _("Select first endpoint or turntable to connect, +Shift to tighten") ); + } else { + InfoMessage( + _("Select first endpoint to connect, or Right-Click for connecting selected tracks (not turntable)") ); + } trk1 = NULL; turntable = FALSE; t1 = t2 = NULL; @@ -731,35 +764,39 @@ static STATUS_T CmdPull( if (QueryTrack(t1, Q_CAN_ADD_ENDPOINTS)) { DrawTrack(t1,&mainD,wDrawColorBlue); t_turn1 = TRUE; - } else t1 = NULL; + } else { t1 = NULL; } } - if (t1 && t_ep1 >=0) + if (t1 && t_ep1 >=0) { CreateConnectAnchor(t_ep1,t1,FALSE); + } } } else { if (t1 != NULL) { - if (t_turn1) DrawTrack(t1,&mainD,wDrawColorBlue); - else CreateConnectAnchor(t_ep1,t1,FALSE); + if (t_turn1) { DrawTrack(t1,&mainD,wDrawColorBlue); } + else { CreateConnectAnchor(t_ep1,t1,FALSE); } } if ((t2= OnTrackIgnore( &pos, FALSE, TRUE, t1 )) != NULL) { if ((t_ep2 = PickUnconnectedEndPointSilent( pos, t2 )) < 0) { if (QueryTrack(t2, Q_CAN_ADD_ENDPOINTS)) { DrawTrack(t2,&mainD,wDrawColorBlue); t_turn2 = TRUE; - } else t2 = NULL; + } else { t2 = NULL; } } - if (t2 && t_ep2 >=0) + if (t2 && t_ep2 >=0) { CreateConnectAnchor(t_ep2,t2,FALSE); + } } } } else { //Shift, tighten t1 = OnTrack( &pos, FALSE, TRUE ); - if (t1 == NULL) + if (t1 == NULL) { return C_CONTINUE; + } t_ep1 = PickUnconnectedEndPointSilent( pos, t1 ); - if ( t_ep1 < 0 ) + if ( t_ep1 < 0 ) { return C_CONTINUE; + } CreateConnectAnchor(t_ep1,t1,TRUE); } break; @@ -772,7 +809,7 @@ static STATUS_T CmdPull( if (QueryTrack(trk1, Q_CAN_ADD_ENDPOINTS)) { turntable = TRUE; ep1 = -1; - } else trk1 = NULL; + } else { trk1 = NULL; } } else { InfoMessage( _("Select second endpoint or turntable to connect") ); } @@ -790,7 +827,8 @@ static STATUS_T CmdPull( inError = TRUE; return C_TERMINATE; } - if (!turntable && QueryTrack(trk2, Q_CAN_ADD_ENDPOINTS)) { /*Second end a turntable */ + if (!turntable + && QueryTrack(trk2, Q_CAN_ADD_ENDPOINTS)) { /*Second end a turntable */ ep2 = -1; turntable = TRUE; PullTracks( trk2, ep2, trk1, ep1); @@ -803,11 +841,13 @@ static STATUS_T CmdPull( } } else { trk1 = OnTrack( &pos, TRUE, TRUE ); - if (trk1 == NULL) + if (trk1 == NULL) { return C_CONTINUE; + } ep1 = PickUnconnectedEndPoint( pos, trk1 ); - if ( ep1 < 0 ) + if ( ep1 < 0 ) { return C_CONTINUE; + } TightenTracks( trk1, ep1 ); trk1 = NULL; inError = TRUE; @@ -816,12 +856,16 @@ static STATUS_T CmdPull( return C_CONTINUE; case C_REDRAW: - if (anchors_da.cnt) - DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); - if (t1 && t_turn1) - DrawTrack(t1,&tempD,wDrawColorBlue); - if (t2 && t_turn2) - DrawTrack(t2,&tempD,wDrawColorBlue); + DrawHighlightBoxes(FALSE,FALSE,NULL); + HighlightSelectedTracks(NULL, TRUE, TRUE); + DrawSegsDA( &tempD, NULL, zero, 0.0, &anchors_da, trackGauge, wDrawColorBlack, + 0 ); + if (t1 && t_turn1) { + DrawTrack(t1,&tempD,wDrawColorBlue); + } + if (t2 && t_turn2) { + DrawTrack(t2,&tempD,wDrawColorBlue); + } return C_CONTINUE; case C_TEXT: @@ -856,11 +900,13 @@ static STATUS_T CmdPull( -#include "bitmaps/pull.xpm" +#include "bitmaps/connect.xpm3" wMenuPush_p pullConnectMultiple; -void pullMenuEnter(int key) { +void pullMenuEnter( void * keyVP ) +{ + int key = (int)VP2L(keyVP); int action; action = C_TEXT; action |= key<<8; @@ -869,7 +915,11 @@ void pullMenuEnter(int key) { void InitCmdPull( wMenu_p menu ) { - AddMenuButton( menu, CmdPull, "cmdConnect", _("Connect Two Tracks"), wIconCreatePixMap(pull_xpm), LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY|IC_LCLICK|IC_POPUP3|IC_CMDMENU|IC_WANT_MOVE, ACCL_CONNECT, NULL ); + AddMenuButton( menu, CmdPull, "cmdConnect", _("Connect Two Tracks"), + wIconCreatePixMap(connect_xpm3[iconSize]), LEVEL0_50, + IC_STICKY|IC_INITNOTSTICKY|IC_LCLICK|IC_POPUP3|IC_CMDMENU|IC_WANT_MOVE, + ACCL_CONNECT, NULL ); pullPopupM = MenuRegister( "Connect Options" ); - pullConnectMultiple = wMenuPushCreate( pullPopupM, "", _("Connect All Selected - 'S'"), 0, (wMenuCallBack_p)pullMenuEnter, (void*) 'S'); + pullConnectMultiple = wMenuPushCreate( pullPopupM, "", + _("Connect All Selected - 'S'"), 0, pullMenuEnter, I2VP('S') ); } |