summaryrefslogtreecommitdiff
path: root/app/bin/cturntbl.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:55:58 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:55:58 +0100
commitd1a8285f818eb7e5c3d6a05709ea21a808490b8c (patch)
tree326578f0505cbed07cfe60de530022822dc237ac /app/bin/cturntbl.c
parent16e9630b79f0a7a90c6cedb6781175bb8b337dc1 (diff)
New upstream version 5.1.0upstream/5.1.0
Diffstat (limited to 'app/bin/cturntbl.c')
-rw-r--r--app/bin/cturntbl.c64
1 files changed, 56 insertions, 8 deletions
diff --git a/app/bin/cturntbl.c b/app/bin/cturntbl.c
index 31f33ed..9264572 100644
--- a/app/bin/cturntbl.c
+++ b/app/bin/cturntbl.c
@@ -1,8 +1,5 @@
-/*
- * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/cturntbl.c,v 1.4 2008-03-06 19:35:06 m_fischer Exp $
- *
+/** \file cturntbl.c
* TURNTABLE
- *
*/
/* XTrkCad - Model Railroad CAD
@@ -23,9 +20,17 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "track.h"
+#include <math.h>
+#include <string.h>
+
#include "cstraigh.h"
+#include "cundo.h"
+#include "fileio.h"
#include "i18n.h"
+#include "messages.h"
+#include "param.h"
+#include "track.h"
+#include "utility.h"
static TRKTYP_T T_TURNTABLE = -1;
@@ -233,7 +238,7 @@ static struct {
coOrd orig;
DIST_T diameter;
long epCnt;
- LAYER_T layerNumber;
+ unsigned int layerNumber;
} trntblData;
typedef enum { OR, RA, EC, LY } trntblDesc_e;
static descData_t trntblDesc[] = {
@@ -584,6 +589,26 @@ static STATUS_T ModifyTurntable( track_p trk, wAction_t action, coOrd pos )
return C_ERROR;
}
+EXPORT BOOL_T ConnectTurntableTracks(
+ track_p trk1,
+ EPINX_T ep1,
+ track_p trk2,
+ EPINX_T ep2 ) {
+ coOrd center, pos;
+ DIST_T radius;
+ TurntableGetCenter( trk1, &center, &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) {
+ EPINX_T ep = NewTurntableEndPt(trk1,angle);
+ ConnectTracks( trk1, ep, trk2, ep2 );
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
static BOOL_T GetParamsTurntable( int inx, track_p trk, coOrd pos, trackParams_t * params )
{
@@ -604,6 +629,8 @@ static BOOL_T GetParamsTurntable( int inx, track_p trk, coOrd pos, trackParams_t
params->lineEnd = params->lineOrig;
params->len = 0.0;
params->arcR = 0.0;
+ params->ttcenter = center; //Turntable
+ params->ttradius = radius; //Turntable
return TRUE;
}
@@ -623,11 +650,27 @@ static BOOL_T MoveEndPtTurntable( track_p *trk, EPINX_T *ep, coOrd pos, DIST_T d
d -= d0;
Translate( &pos, pos, angle0+180, d0 );
}
- if (d < r) {
+ if (small((r-d)/2)) {
+ Translate( &pos, posCen, angle0+180, r); //Make radius equal if close
+ } else if (d < r) {
ErrorMessage( MSG_POINT_INSIDE_TURNTABLE );
return FALSE;
}
- *ep = NewTurntableEndPt( *trk, angle0 );
+ //Look for empty slot
+ BOOL_T found = FALSE;
+ for (*ep=0; *ep<GetTrkEndPtCnt(*trk); *ep=*ep+1) {
+ if ( (GetTrkEndTrk(*trk,*ep)) == NULL )
+ found = TRUE;
+ break;
+ }
+ if (!found)
+ *ep = NewTurntableEndPt(*trk,angle0);
+ else {
+ struct extraData *xx = GetTrkExtraData(*trk);
+ coOrd pos1;
+ PointOnCircle( &pos1, xx->pos, xx->radius, angle0 );
+ SetTrkEndPoint(*trk, *ep, pos1, angle0); //Reuse
+ }
if ((d-r) > connectDistance) {
trk1 = NewStraightTrack( GetTrkEndPos(*trk,*ep), pos );
CopyAttributes( *trk, trk1 );
@@ -650,7 +693,12 @@ static BOOL_T QueryTurntable( track_p trk, int query )
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:
+ return FALSE;
default:
return FALSE;
}