diff options
Diffstat (limited to 'app/bin/cturntbl.c')
-rw-r--r-- | app/bin/cturntbl.c | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/app/bin/cturntbl.c b/app/bin/cturntbl.c index 9264572..f15aeff 100644 --- a/app/bin/cturntbl.c +++ b/app/bin/cturntbl.c @@ -162,9 +162,19 @@ static ANGLE_T ConstrainTurntableAngle( track_p trk, coOrd pos ) static EPINX_T NewTurntableEndPt( track_p trk, ANGLE_T angle ) { struct extraData *xx = GetTrkExtraData(trk); - EPINX_T ep = GetTrkEndPtCnt(trk); + EPINX_T ep = -1; + /* Reuse an old empty ep if it exists */ + for (int i =0;i< GetTrkEndPtCnt(trk)-1;i++) { + if (GetTrkEndTrk(trk,i) == NULL) { + ep = i; + break; + } + } + if (ep == -1) { + ep = GetTrkEndPtCnt(trk); + SetTrkEndPtCnt( trk, ep+1 ); + } coOrd pos; - SetTrkEndPtCnt( trk, ep+1 ); PointOnCircle( &pos, xx->pos, xx->radius, angle ); SetTrkEndPoint( trk, ep, pos, angle ); return ep; @@ -182,7 +192,8 @@ static void DrawTurntable( track_p t, drawCmd_p d, wDrawColor color ) struct extraData *xx = GetTrkExtraData(t); coOrd p0, p1; EPINX_T ep; - long widthOptions = DTS_TIES; + long widthOptions = DTS_LEFT|DTS_RIGHT; + if ( !ValidateTurntablePosition(t) ) { p0.y = p1.y = xx->pos.y; @@ -194,17 +205,13 @@ static void DrawTurntable( track_p t, drawCmd_p d, wDrawColor color ) } if (color == wDrawColorBlack) color = normalColor; - DrawArc( d, xx->pos, xx->radius, 0.0, 360.0, 0, 0, color ); - if ( programMode != MODE_DESIGN ) - return; - if ( (d->options&DC_QUICK) == 0 ) { - DrawStraightTrack( d, p0, p1, FindAngle(p0,p1), t, GetTrkGauge(t), color, widthOptions ); - for ( ep=0; ep<GetTrkEndPtCnt(t); ep++ ) { - if (GetTrkEndTrk(t,ep) != NULL ) - DrawEndPt( d, t, ep, color ); - } + DrawArc( d, xx->pos, xx->radius, 0.0, 360.0, 0, (color == wDrawColorPreviewSelected || color == wDrawColorPreviewUnselected)?3:0, color ); + DrawStraightTrack( d, p0, p1, FindAngle(p0,p1), t, color, widthOptions ); + for ( ep=0; ep<GetTrkEndPtCnt(t); ep++ ) { + if (GetTrkEndTrk(t,ep) != NULL ) + DrawEndPt( d, t, ep, color ); } - if ( ((d->funcs->options&wDrawOptTemp)==0) && + if ( ((d->options&DC_SIMPLE)==0) && (labelWhen == 2 || (labelWhen == 1 && (d->options&DC_PRINT))) && labelScale >= d->scale ) { LabelLengths( d, t, color ); @@ -218,9 +225,7 @@ static DIST_T DistanceTurntable( track_p trk, coOrd * p ) ANGLE_T a; coOrd pos0, pos1; - d = FindDistance( xx->pos, *p ) - xx->radius; - if (d < 0.0) - d = 0.0; + d = FindDistance( xx->pos, *p ) - xx->radius; //OK to be negative if ( programMode == MODE_DESIGN ) { a = FindAngle( xx->pos, *p ); Translate( p, xx->pos, a, d+xx->radius ); @@ -310,11 +315,11 @@ static BOOL_T WriteTurntable( track_p t, FILE * f ) xx->pos.x, xx->pos.y, xx->radius, xx->currEp )>0; for (ep=0; ep<GetTrkEndPtCnt(t); ep++) rc &= WriteEndPt( f, t, ep ); - rc &= fprintf(f, "\tEND\n")>0; + rc &= fprintf(f, "\t%s\n", END_SEGS)>0; return rc; } -static void ReadTurntable( char * line ) +static BOOL_T ReadTurntable( char * line ) { track_p trk; struct extraData *xx; @@ -333,12 +338,17 @@ static void ReadTurntable( char * line ) paramVersion<10?"dL000sdpffX": "dL000sdpffd", &index, &layer, scale, &visible, &p, &elev, &r, &currEp )) - return; + return FALSE; + if ( !ReadSegs() ) + return FALSE; trk = NewTrack( index, T_TURNTABLE, 0, sizeof *xx ); - ReadSegs(); SetEndPts( trk, 0 ); xx = GetTrkExtraData(trk); - SetTrkVisible(trk, visible); + if ( paramVersion < 3 ) { + SetTrkVisible(trk, visible!=0); + } else { + SetTrkVisible(trk, visible&2); + } SetTrkScale(trk, LookupScale( scale ) ); SetTrkLayer(trk, layer); xx->pos = p; @@ -346,6 +356,7 @@ static void ReadTurntable( char * line ) xx->currEp = currEp; xx->reverse = 0; ComputeTurntableBoundingBox( trk ); + return TRUE; } static void MoveTurntable( track_p trk, coOrd orig ) @@ -590,22 +601,32 @@ static STATUS_T ModifyTurntable( track_p trk, wAction_t action, coOrd pos ) } EXPORT BOOL_T ConnectTurntableTracks( - track_p trk1, - EPINX_T ep1, + track_p trk1, /*The turntable */ + EPINX_T ep1, /*Ignored */ track_p trk2, EPINX_T ep2 ) { coOrd center, pos; DIST_T radius; + DIST_T dist; + if (!QueryTrack(trk1,Q_CAN_ADD_ENDPOINTS)) return FALSE; TurntableGetCenter( trk1, ¢er, &radius ); pos = GetTrkEndPos(trk2,ep2); ANGLE_T angle = FindAngle(center, GetTrkEndPos(trk2,ep2)); - if (NormalizeAngle(GetTrkEndAngle(trk2,ep2) + 180 - angle) < connectAngle) { - if (FindDistance(center,pos)-radius < connectDistance) { + if (fabs(DifferenceBetweenAngles(GetTrkEndAngle(trk2,ep2),angle+180)) <= connectAngle) { + dist = FindDistance(center,pos)-radius; + if (dist < connectDistance) { + UndoStart( _("Connect Turntable Tracks"), "TurnTracks(T%d[%d] T%d[%d] D%0.3f A%0.3F )", + GetTrkIndex(trk1), ep1, GetTrkIndex(trk2), ep2, dist, angle ); + UndoModify(trk1); EPINX_T ep = NewTurntableEndPt(trk1,angle); - ConnectTracks( trk1, ep, trk2, ep2 ); + if (ConnectTracks( trk1, ep, trk2, ep2 )) { + UndoUndo(); + return FALSE; + } return TRUE; } } + ErrorMessage( MSG_TOO_FAR_APART_DIVERGE ); return FALSE; } @@ -688,13 +709,12 @@ static BOOL_T QueryTurntable( track_p trk, int query ) switch ( query ) { case Q_REFRESH_JOIN_PARAMS_ON_MOVE: case Q_CANNOT_PLACE_TURNOUT: - case Q_DONT_DRAW_ENDPOINT: + case Q_NODRAWENDPT: case Q_CAN_NEXT_POSITION: case Q_ISTRACK: case Q_NOT_PLACE_FROGPOINTS: case Q_MODIFY_REDRAW_DONT_UNDRAW_TRACK: case Q_CAN_ADD_ENDPOINTS: - case Q_CAN_EXTEND: return TRUE; case Q_MODIFY_CAN_SPLIT: case Q_CORNU_CAN_MODIFY: @@ -727,7 +747,19 @@ static void DrawTurntablePositionIndicator( track_p trk, wDrawColor color ) pos0 = GetTrkEndPos(trk,xx->currEp); angle = FindAngle( xx->pos, pos0 ); PointOnCircle( &pos1, xx->pos, xx->radius, angle+180.0 ); - DrawLine( &mainD, pos0, pos1, 3, color ); + DrawLine( &tempD, pos0, pos1, 3, color ); +} + +static wBool_t CompareTurntable( track_cp trk1, track_cp trk2 ) +{ + struct extraData *xx1 = GetTrkExtraData( trk1 ); + struct extraData *xx2 = GetTrkExtraData( trk2 ); + char * cp = message + strlen(message); + REGRESS_CHECK_POS( "Pos", xx1, xx2, pos ) + REGRESS_CHECK_DIST( "Radius", xx1, xx2, radius ) + REGRESS_CHECK_INT( "CurrEp", xx1, xx2, currEp ) + REGRESS_CHECK_INT( "Reverse", xx1, xx2, reverse ) + return TRUE; } static void AdvanceTurntablePositionIndicator( @@ -744,7 +776,6 @@ static void AdvanceTurntablePositionIndicator( angle1 = FindAngle( xx->pos, pos ); if ( !FindTurntableEndPt( trk, &angle1, &ep, &reverse ) ) return; - DrawTurntablePositionIndicator( trk, wDrawColorWhite ); angle0 = GetTrkEndAngle(trk,xx->currEp); if ( ep == xx->currEp ) { Rotate( posR, xx->pos, 180.0 ); @@ -762,7 +793,6 @@ static void AdvanceTurntablePositionIndicator( } *angleR = angle1; xx->currEp = ep; - DrawTurntablePositionIndicator( trk, selectedColor ); } @@ -794,13 +824,21 @@ static trackCmd_t turntableCmds = { FlipTurntable, DrawTurntablePositionIndicator, AdvanceTurntablePositionIndicator, - CheckTraverseTurntable }; + CheckTraverseTurntable, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + CompareTurntable }; static STATUS_T CmdTurntable( wAction_t action, coOrd pos ) { track_p t; static coOrd pos0; + static int state = 0; wControl_p controls[2]; char * labels[1]; @@ -819,6 +857,7 @@ static STATUS_T CmdTurntable( wAction_t action, coOrd pos ) labels[0] = N_("Diameter"); InfoSubstituteControls( controls, labels ); /*InfoMessage( "Place Turntable");*/ + state = 0; return C_CONTINUE; case C_DOWN: @@ -833,18 +872,15 @@ static STATUS_T CmdTurntable( wAction_t action, coOrd pos ) InfoSubstituteControls( controls, labels ); ParamLoadData( &turntablePG ); pos0 = pos; - DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); + state = 1; return C_CONTINUE; case C_MOVE: - DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); SnapPos( &pos ); pos0 = pos; - DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); return C_CONTINUE; case C_UP: - DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); SnapPos( &pos ); UndoStart( _("Create Turntable"), "NewTurntable" ); t = NewTurntable( pos, turntableDiameter/2.0 ); @@ -853,10 +889,13 @@ static STATUS_T CmdTurntable( wAction_t action, coOrd pos ) InfoSubstituteControls( NULL, NULL ); sprintf( message, "turntable-diameter-%s", curScaleName ); wPrefSetFloat( "misc", message, turntableDiameter ); + state = 0; return C_TERMINATE; case C_REDRAW: - DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); + if ( state > 0 ) { + DrawArc( &tempD, pos0, turntableDiameter/2.0, 0.0, 360.0, 0, 0, wDrawColorBlack ); + } return C_CONTINUE; case C_CANCEL: @@ -874,7 +913,7 @@ static STATUS_T CmdTurntable( wAction_t action, coOrd pos ) EXPORT void InitCmdTurntable( wMenu_p menu ) { - AddMenuButton( menu, CmdTurntable, "cmdTurntable", _("Turntable"), wIconCreatePixMap(turntbl_xpm), LEVEL0_50, IC_STICKY, ACCL_TURNTABLE, NULL ); + AddMenuButton( menu, CmdTurntable, "cmdTurntable", _("Custom Turntable"), wIconCreatePixMap(turntbl_xpm), LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY, ACCL_TURNTABLE, NULL ); } |