summaryrefslogtreecommitdiff
path: root/app/bin/tstraigh.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/tstraigh.c')
-rw-r--r--app/bin/tstraigh.c108
1 files changed, 71 insertions, 37 deletions
diff --git a/app/bin/tstraigh.c b/app/bin/tstraigh.c
index 5cf1cda..f9b666f 100644
--- a/app/bin/tstraigh.c
+++ b/app/bin/tstraigh.c
@@ -163,7 +163,7 @@ static void UpdateStraight( track_p trk, int inx, descData_p descUpd, BOOL_T fin
case Z1:
ep = (inx==Z0?0:1);
UpdateTrkEndElev( trk, ep, GetTrkEndElevUnmaskedMode(trk,ep), strData.elev[ep], NULL );
- ComputeElev( trk, 1-ep, FALSE, &strData.elev[1-ep], NULL );
+ ComputeElev( trk, 1-ep, FALSE, &strData.elev[1-ep], NULL, TRUE );
if ( strData.length > minLength )
strData.grade = fabs( (strData.elev[0]-strData.elev[1])/strData.length )*100.0;
else
@@ -242,8 +242,8 @@ static void DescribeStraight( track_p trk, char * str, CSIZE_T len )
fix1 = GetTrkEndTrk(trk,1)!=NULL;
strData.endPt[0] = GetTrkEndPos(trk,0);
strData.endPt[1] = GetTrkEndPos(trk,1);
- ComputeElev( trk, 0, FALSE, &strData.elev[0], NULL );
- ComputeElev( trk, 1, FALSE, &strData.elev[1], NULL );
+ ComputeElev( trk, 0, FALSE, &strData.elev[0], NULL, FALSE );
+ ComputeElev( trk, 1, FALSE, &strData.elev[1], NULL, FALSE );
strData.length = FindDistance( strData.endPt[0], strData.endPt[1] );
strData.layerNumber = GetTrkLayer(trk);
if ( strData.length > minLength )
@@ -274,18 +274,12 @@ static DIST_T DistanceStraight( track_p t, coOrd * p )
static void DrawStraight( track_p t, drawCmd_p d, wDrawColor color )
{
- long widthOptions = DTS_LEFT|DTS_RIGHT|DTS_TIES;
- if (GetTrkWidth(t) == 2)
- widthOptions |= DTS_THICK2;
- if (GetTrkWidth(t) == 3)
- widthOptions |= DTS_THICK3;
+ long widthOptions = DTS_LEFT|DTS_RIGHT;
DrawStraightTrack( d, GetTrkEndPos(t,0), GetTrkEndPos(t,1),
GetTrkEndAngle(t,0),
- t, GetTrkGauge(t), color, widthOptions );
- if ( (d->funcs->options & wDrawOptTemp) == 0 && (d->options & DC_QUICK) == 0 ) {
- DrawEndPt( d, t, 0, color );
- DrawEndPt( d, t, 1, color );
- }
+ t, color, widthOptions );
+ DrawEndPt( d, t, 0, color );
+ DrawEndPt( d, t, 1, color );
}
static void DeleteStraight( track_p t )
@@ -297,14 +291,14 @@ static BOOL_T WriteStraight( track_p t, FILE * f )
BOOL_T rc = TRUE;
rc &= fprintf(f, "STRAIGHT %d %d %ld 0 0 %s %d\n",
GetTrkIndex(t), GetTrkLayer(t), (long)GetTrkWidth(t),
- GetTrkScaleName(t), GetTrkVisible(t) )>0;
+ GetTrkScaleName(t), GetTrkVisible(t)|(GetTrkNoTies(t)?1<<2:0)|(GetTrkBridge(t)?1<<3:0) )>0;
rc &= WriteEndPt( f, t, 0 );
rc &= WriteEndPt( f, t, 1 );
- rc &= fprintf(f, "\tEND\n" )>0;
+ rc &= fprintf(f, "\t%s\n", END_SEGS)>0;
return rc;
}
-static void ReadStraight( char * line )
+static BOOL_T ReadStraight( char * line )
{
track_p trk;
wIndex_t index;
@@ -314,15 +308,25 @@ static void ReadStraight( char * line )
long options;
if ( !GetArgs( line+8, paramVersion<3?"dXZsd":"dLl00sd", &index, &layer, &options, scale, &visible ) )
- return;
+ return FALSE;
+ if ( !ReadSegs() )
+ return FALSE;
trk = NewTrack( index, T_STRAIGHT, 0, 0 );
SetTrkScale( trk, LookupScale(scale) );
- SetTrkVisible(trk, visible);
+ if ( paramVersion < 3 ) {
+ SetTrkVisible(trk, visible!=0);
+ SetTrkNoTies(trk, FALSE);
+ SetTrkBridge(trk, FALSE);
+ } else {
+ SetTrkVisible(trk, visible&2);
+ SetTrkNoTies(trk, visible&4);
+ SetTrkBridge(trk, visible&8);
+ }
SetTrkLayer(trk, layer);
SetTrkWidth( trk, (int)(options&3) );
- ReadSegs();
SetEndPts( trk, 2 );
ComputeBoundingBox( trk );
+ return TRUE;
}
static void MoveStraight( track_p trk, coOrd orig )
@@ -362,11 +366,16 @@ static BOOL_T SplitStraight( track_p trk, coOrd pos, EPINX_T ep, track_p *leftov
{
track_p trk1;
- trk1 = NewStraightTrack( GetTrkEndPos(trk,ep), pos );
+ trk1 = NewStraightTrack( 1-ep?GetTrkEndPos(trk,ep):pos, 1-ep?pos:GetTrkEndPos(trk,ep) );
+ DIST_T height;
+ int opt;
+ GetTrkEndElev(trk,ep,&opt,&height);
+ UpdateTrkEndElev( trk1, ep, opt, height, (opt==ELEV_STATION)?GetTrkEndElevStation(trk,ep):NULL );
AdjustStraightEndPt( trk, ep, pos );
+ UpdateTrkEndElev( trk, ep, ELEV_NONE, 0, NULL);
*leftover = trk1;
- *ep0 = 1;
- *ep1 = 0;
+ *ep0 = 1-ep;
+ *ep1 = ep;
return TRUE;
}
@@ -413,7 +422,7 @@ static BOOL_T EnumerateStraight( track_p trk )
return TRUE;
}
-static BOOL_T TrimStraight( track_p trk, EPINX_T ep, DIST_T dist )
+static BOOL_T TrimStraight( track_p trk, EPINX_T ep, DIST_T dist, coOrd endpos, ANGLE_T angle, DIST_T radius, coOrd center )
{
DIST_T d;
ANGLE_T a;
@@ -427,8 +436,10 @@ static BOOL_T TrimStraight( track_p trk, EPINX_T ep, DIST_T dist )
UndrawNewTrack( trk );
AdjustStraightEndPt( trk, ep, pos );
DrawNewTrack( trk );
- } else
+ } else {
+ UndrawNewTrack( trk );
DeleteTrack( trk, TRUE );
+ }
return TRUE;
}
@@ -493,6 +504,7 @@ BOOL_T ExtendStraightToJoin(
DisconnectTracks( trk1, 1-ep1, trk1x, ep1x );
}
if (trk2) {
+ UndrawNewTrack( trk1 );
DeleteTrack( trk1, TRUE );
} else {
trk2 = trk1;
@@ -555,17 +567,13 @@ static STATUS_T ModifyStraight( track_p trk, wAction_t action, coOrd pos )
if (action == C_MOVE)
InfoMessage( _("Straight: Length=%s Angle=%0.3f"),
FormatDistance( d ), PutAngle( GetTrkEndAngle( trk, ep ) ) );
- MainRedraw();
- MapRedraw();
return C_CONTINUE;
case C_UP:
if (valid)
AdjustStraightEndPt( trk, ep, tempSegs(0).u.l.pos[1] );
tempSegs_da.cnt = 0;
- DrawNewTrack( trk );
- MainRedraw();
- MapRedraw();
+ DrawNewTrack( trk );
return C_TERMINATE;
default:
@@ -584,9 +592,8 @@ static DIST_T GetLengthStraight( track_p trk )
static BOOL_T GetParamsStraight( int inx, track_p trk, coOrd pos, trackParams_t * params )
{
params->type = curveTypeStraight;
- if ( inx == PARAMS_PARALLEL ) {
- params->ep = 0;
- } else if (inx == PARAMS_CORNU ){
+ if ( inx == PARAMS_NODES ) return FALSE;
+ if ((inx == PARAMS_CORNU) || (inx == PARAMS_1ST_JOIN) || (inx == PARAMS_2ND_JOIN) ){
params->ep = PickEndPoint( pos, trk);
params->arcP = zero;
params->arcR = 0.0;
@@ -627,6 +634,7 @@ static BOOL_T QueryStraight( track_p trk, int query )
case Q_ISTRACK:
case Q_CORNU_CAN_MODIFY:
case Q_MODIFY_CAN_SPLIT:
+ case Q_CAN_EXTEND:
return TRUE;
default:
return FALSE;
@@ -647,9 +655,11 @@ static BOOL_T MakeParallelStraight(
track_p trk,
coOrd pos,
DIST_T sep,
+ DIST_T factor,
track_p * newTrkR,
coOrd * p0R,
- coOrd * p1R )
+ coOrd * p1R,
+ BOOL_T track)
{
ANGLE_T angle = GetTrkEndAngle(trk,1);
coOrd p0, p1;
@@ -660,12 +670,23 @@ static BOOL_T MakeParallelStraight(
Translate( &p0, GetTrkEndPos(trk,0), angle, sep );
Translate( &p1, GetTrkEndPos(trk,1), angle, sep );
if ( newTrkR ) {
- *newTrkR = NewStraightTrack( p0, p1 );
+ if (track)
+ *newTrkR = NewStraightTrack( p0, p1 );
+ else {
+ tempSegs(0).color = wDrawColorBlack;
+ tempSegs(0).width = 0;
+ tempSegs_da.cnt = 1;
+ tempSegs(0).type = SEG_STRLIN;
+ tempSegs(0).u.l.pos[0] = p0;
+ tempSegs(0).u.l.pos[1] = p1;
+ *newTrkR = MakeDrawFromSeg( zero, 0.0, &tempSegs(0) );
+ }
+
} else {
tempSegs(0).color = wDrawColorBlack;
tempSegs(0).width = 0;
tempSegs_da.cnt = 1;
- tempSegs(0).type = SEG_STRTRK;
+ tempSegs(0).type = track?SEG_STRTRK:SEG_STRLIN;
tempSegs(0).u.l.pos[0] = p0;
tempSegs(0).u.l.pos[1] = p1;
}
@@ -675,6 +696,12 @@ static BOOL_T MakeParallelStraight(
}
+static wBool_t CompareStraight( track_cp trk1, track_cp trk2 )
+{
+ return TRUE;
+}
+
+
static trackCmd_t straightCmds = {
"STRAIGHT",
DrawStraight,
@@ -704,8 +731,13 @@ static trackCmd_t straightCmds = {
NULL,
NULL,
NULL,
- MakeParallelStraight };
-
+ MakeParallelStraight,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ CompareStraight };
EXPORT void StraightSegProc(
segProc_e cmd,
@@ -810,6 +842,8 @@ EXPORT void StraightSegProc(
*/
+
+
track_p NewStraightTrack( coOrd p0, coOrd p1 )
{
track_p t;