summaryrefslogtreecommitdiff
path: root/app/bin/track.h
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/track.h
parent16e9630b79f0a7a90c6cedb6781175bb8b337dc1 (diff)
New upstream version 5.1.0upstream/5.1.0
Diffstat (limited to 'app/bin/track.h')
-rw-r--r--app/bin/track.h161
1 files changed, 99 insertions, 62 deletions
diff --git a/app/bin/track.h b/app/bin/track.h
index e26a47a..e39a98f 100644
--- a/app/bin/track.h
+++ b/app/bin/track.h
@@ -1,5 +1,5 @@
-/*
- * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/track.h,v 1.3 2009-05-25 18:11:03 m_fischer Exp $
+/** \file track.h
+ *
*/
/* XTrkCad - Model Railroad CAD
@@ -23,24 +23,9 @@
#ifndef TRACK_H
#define TRACK_H
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef WINDOWS
-#include <unistd.h>
-#endif
-#include <math.h>
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-#include <string.h>
-
-#include "wlib.h"
#include "common.h"
-#include "utility.h"
#include "draw.h"
-#include "misc.h"
-
+#include "misc2.h"
extern TRKTYP_T T_NOTRACK;
@@ -51,19 +36,19 @@ extern track_p tempTrack;
extern wIndex_t trackCount;
extern long drawTunnel;
extern long drawEndPtV;
+extern long drawUnconnectedEndPt;
extern long centerDrawMode;
extern wDrawColor selectedColor;
extern wDrawColor normalColor;
extern BOOL_T useCurrentLayer;
-extern LAYER_T curTrackLayer;
+extern unsigned int curTrackLayer;
extern coOrd descriptionOff;
extern DIST_T roadbedWidth;
extern DIST_T roadbedLineWidth;
+extern long printCenterLines;
extern long drawElevations;
extern wDrawColor elevColorIgnore;
extern wDrawColor elevColorDefined;
-extern DIST_T minTrackRadius;
-extern DIST_T maxTrackGrade;
extern wDrawColor exceptionColor;
#define TIEDRAWMODE_NONE (0)
#define TIEDRAWMODE_OUTLINE (1)
@@ -81,24 +66,36 @@ extern int pathMax;
extern BOOL_T onTrackInSplit;
-typedef enum { curveTypeNone, curveTypeCurve, curveTypeStraight } curveType_e;
+typedef enum { curveTypeNone, curveTypeCurve, curveTypeStraight, curveTypeBezier, curveTypeCornu } curveType_e;
#define PARAMS_1ST_JOIN (0)
#define PARAMS_2ND_JOIN (1)
#define PARAMS_EXTEND (2)
#define PARAMS_PARALLEL (3)
+#define PARAMS_BEZIER (4) //Not used (yet)
+#define PARAMS_CORNU (5) //Called to get end characteristics
typedef struct {
- curveType_e type;
- EPINX_T ep;
- DIST_T len;
- ANGLE_T angle;
- coOrd lineOrig;
- coOrd lineEnd;
- coOrd arcP;
- DIST_T arcR;
- ANGLE_T arcA0, arcA1;
+ curveType_e type; //Straight, Curve, Bezier, Cornu
+ EPINX_T ep; //End point that is nearby pos
+ DIST_T len; //Length of track
+ ANGLE_T angle; //Angle at end of track
+ coOrd lineOrig; //Start of straight
+ coOrd lineEnd; //End of Straight (or zero for Turnout)
+ coOrd arcP; //center or zero
+ DIST_T arcR; //radius or zero
+ ANGLE_T arcA0, arcA1; //Start angle and angular length (clockwise)
long helixTurns;
+ ANGLE_T track_angle;
+ BOOL_T circleOrHelix; //Track is circle or Helix
+ coOrd bezierPoints[4]; //Bezier Ends and CPs
+ coOrd cornuEnd[2]; //Cornu Ends
+ ANGLE_T cornuAngle[2]; //Angle at Cornu Ends
+ DIST_T cornuRadius[2]; //Radius at Cornu Ends
+ coOrd cornuCenter[2]; //Center at Cornu Ends
+ coOrd ttcenter; //Turntable
+ DIST_T ttradius; //Turntable
+
} trackParams_t;
#define Q_CANNOT_BE_ON_END (1)
@@ -118,13 +115,20 @@ typedef struct {
#define Q_NOT_PLACE_FROGPOINTS (15)
#define Q_HAS_DESC (16)
#define Q_MODIFY_REDRAW_DONT_UNDRAW_TRACK (17)
+#define Q_CAN_MODIFY_CONTROL_POINTS (18) // Is T_BEZIER or T_BEZLIN
+#define Q_IS_CORNU (19) // Is T_CORNU
+#define Q_MODIFY_CAN_SPLIT (20) // Is able to be Split
+#define Q_CAN_EXTEND (21) // Add extra curve or straight in CORNU MODIFY
+#define Q_CAN_ADD_ENDPOINTS (22) // Is T_TURNTABLE
+#define Q_HAS_VARIABLE_ENDPOINTS (23) // Is Helix or Circle
+#define Q_CORNU_CAN_MODIFY (24) // can be modified by CORNU MODIFY
typedef struct {
- track_p trk;
- DIST_T length;
- DIST_T dist;
- coOrd pos;
- ANGLE_T angle;
+ track_p trk; // IN Current Track OUT Next Track
+ DIST_T length; // IN How far to go
+ DIST_T dist; // OUT how far left = 0 if found
+ coOrd pos; // IN/OUT - where we are, where we will be // IN/OUT - where we are now
+ ANGLE_T angle; // IN/OUT - angle now
} traverseTrack_t, *traverseTrack_p;
@@ -159,6 +163,7 @@ typedef struct {
BOOL_T (*checkTraverse)( track_p, coOrd );
BOOL_T (*makeParallel)( track_p, coOrd, DIST_T, track_p *, coOrd *, coOrd * );
void (*drawDesc)( track_p, drawCmd_p, wDrawColor );
+ BOOL_T (*rebuildSegs)(track_p);
} trackCmd_t;
@@ -187,18 +192,30 @@ typedef struct {
dynArr_t tempEndPts_da;
#define tempEndPts(N) DYNARR_N( trkEndPt_t, tempEndPts_da, N )
+typedef enum { FREEFORM, RECTANGLE
+} PolyType_e;
typedef struct {
char type;
wDrawColor color;
DIST_T width;
+ dynArr_t bezSegs; //placed here to avoid overwrites
union {
struct {
- coOrd pos[2];
+ coOrd pos[4];
ANGLE_T angle;
long option;
} l;
struct {
+ coOrd pos[4];
+ ANGLE_T angle0;
+ ANGLE_T angle3;
+ DIST_T minRadius;
+ DIST_T radius0;
+ DIST_T radius3;
+ DIST_T length;
+ } b;
+ struct {
coOrd center;
ANGLE_T a0, a1;
DIST_T radius;
@@ -224,14 +241,17 @@ typedef struct {
coOrd * pts;
coOrd orig;
ANGLE_T angle;
+ PolyType_e polyType;
} p;
} u;
} trkSeg_t, * trkSeg_p;
#define SEG_STRTRK ('S')
#define SEG_CRVTRK ('C')
+#define SEG_BEZTRK ('W')
#define SEG_STRLIN ('L')
#define SEG_CRVLIN ('A')
+#define SEG_BEZLIN ('H')
#define SEG_JNTTRK ('J')
#define SEG_FILCRCL ('G')
#define SEG_POLY ('Y')
@@ -247,7 +267,7 @@ typedef struct {
#define SEG_DIMLIN ('M')
#define SEG_TBLEDGE ('Q')
-#define IsSegTrack( S ) ( (S)->type == SEG_STRTRK || (S)->type == SEG_CRVTRK || (S)->type == SEG_JNTTRK )
+#define IsSegTrack( S ) ( (S)->type == SEG_STRTRK || (S)->type == SEG_CRVTRK || (S)->type == SEG_JNTTRK || (S)->type == SEG_BEZTRK)
dynArr_t tempSegs_da;
#define tempSegs(N) DYNARR_N( trkSeg_t, tempSegs_da, N )
@@ -295,24 +315,31 @@ void DrawSegsO(
DIST_T trackGauge,
wDrawColor color,
long options );
-ANGLE_T GetAngleSegs( wIndex_t, trkSeg_p, coOrd, wIndex_t * );
+ANGLE_T GetAngleSegs( wIndex_t, trkSeg_p, coOrd *, wIndex_t *, DIST_T *, BOOL_T *, wIndex_t *, BOOL_T * );
void RecolorSegs( wIndex_t, trkSeg_p, wDrawColor );
BOOL_T ReadSegs( void );
BOOL_T WriteSegs( FILE * f, wIndex_t segCnt, trkSeg_p segs );
+BOOL_T WriteSegsEnd(FILE * f, wIndex_t segCnt, trkSeg_p segs, BOOL_T writeEnd);
typedef union {
struct {
- coOrd pos; /* IN */
- ANGLE_T angle;
- DIST_T dist; /* OUT */
- BOOL_T backwards;
- } traverse1;
+ coOrd pos; /* IN the point to get to */
+ ANGLE_T angle; /* IN is the angle that the object starts at (-ve for forwards) */
+ DIST_T dist; /* OUT is how far it is along the track to get to pos*/
+ BOOL_T backwards; /* OUT which way are we going? */
+ BOOL_T reverse_seg; /* OUT the seg is backwards curve */
+ BOOL_T negative; /* OUT the curve is negative */
+ int BezSegInx; /* OUT for Bezier Seg - the segment we are on in Bezier */
+ BOOL_T segs_backwards; /* OUT for Bezier Seg - the direction of the overall Bezier */
+ } traverse1; // Find dist between pos and end of track that starts with angle set backwards
struct {
- EPINX_T segDir; /* IN */
- DIST_T dist; /* IN/OUT */
- coOrd pos; /* OUT */
- ANGLE_T angle;
- } traverse2;
+ BOOL_T segDir; /* IN Direction to go in this seg*/
+ int BezSegInx; /* IN for Bezier Seg which element to start with*/
+ BOOL_T segs_backwards; /* IN for Bezier Seg which way to go down the array*/
+ DIST_T dist; /* IN/OUT In = distance to go, Out = distance left */
+ coOrd pos; /* OUT = point reached if dist = 0 */
+ ANGLE_T angle; /* OUT = angle at point */
+ } traverse2; //Return distance left (or 0) and angle and pos when going dist from segDir end
struct {
int first, last; /* IN */
ANGLE_T side;
@@ -324,15 +351,15 @@ typedef union {
drawCmd_p d;
} drawRoadbedSide;
struct {
- coOrd pos1; /* IN/OUT */
- DIST_T dd; /* OUT */
+ coOrd pos1; /* IN pos to find */
+ DIST_T dd; /* OUT distance from nearest point in seg to input pos */
} distance;
struct {
track_p trk; /* OUT */
EPINX_T ep[2];
} newTrack;
struct {
- DIST_T length;
+ DIST_T length; /* OUT */
} length;
struct {
coOrd pos; /* IN */
@@ -340,9 +367,14 @@ typedef union {
trkSeg_t newSeg[2];
} split;
struct {
- coOrd pos; /* IN */
- ANGLE_T angle; /* OUT */
- } getAngle;
+ coOrd pos; /* IN Pos to find nearest to - OUT found pos on curve*/
+ ANGLE_T angle; /* OUT angle at pos - (-ve if backwards)*/
+ BOOL_T negative_radius; /* OUT Radius <0? */
+ BOOL_T backwards; /* OUT Seg is backwards */
+ DIST_T radius; /* OUT radius at pos */
+ coOrd center; /* OUT center of curvature at pos (0 = straight)*/
+ int bezSegInx; /* OUT if a bezier proc, the index of the sub segment */
+ } getAngle; // Get pos on seg nearest, angle at that (-ve for forwards)
} segProcData_t, *segProcData_p;
typedef enum {
SEGPROC_TRAVERSE1,
@@ -359,6 +391,8 @@ void SegProc( segProc_e, trkSeg_p, segProcData_p );
void StraightSegProc( segProc_e, trkSeg_p, segProcData_p );
void CurveSegProc( segProc_e, trkSeg_p, segProcData_p );
void JointSegProc( segProc_e, trkSeg_p, segProcData_p );
+void BezierSegProc( segProc_e, trkSeg_p, segProcData_p ); //Used in Cornu join
+void CleanSegs( dynArr_t *);
@@ -416,7 +450,7 @@ void SetTrkScale( track_p, SCALEINX_T );
BOOL_T GetTrkSelected( track_p );
BOOL_T GetTrkVisible( track_p );
void SetTrkVisible( track_p, BOOL_T );
-LAYER_T GetTrkLayer( track_p );
+unsigned int GetTrkLayer( track_p );
void SetBoundingBox( track_p, coOrd, coOrd );
void GetBoundingBox( track_p, coOrd*, coOrd* );
EPINX_T GetTrkEndPtCnt( track_p );
@@ -465,6 +499,7 @@ void SetTrkEndPtCnt( track_p, EPINX_T );
BOOL_T WriteEndPt( FILE *, track_cp, EPINX_T );
EPINX_T PickEndPoint( coOrd, track_cp );
EPINX_T PickUnconnectedEndPoint( coOrd, track_cp );
+EPINX_T PickUnconnectedEndPointSilent( coOrd, track_cp );
void AuditTracks( char *, ... );
void CheckTrackLength( track_cp );
@@ -501,9 +536,10 @@ void DrawStraightTies( drawCmd_p, track_p, coOrd, coOrd, wDrawColor );
void DrawStraightTrack( drawCmd_p, coOrd, coOrd, ANGLE_T, track_p, DIST_T, wDrawColor, long );
ANGLE_T GetAngleAtPoint( track_p, coOrd, EPINX_T *, EPINX_T * );
-DIST_T GetTrkDistance( track_cp, coOrd );
+DIST_T GetTrkDistance( track_cp, coOrd *);
track_p OnTrack( coOrd *, INT_T, BOOL_T );
-track_p OnTrack2( coOrd *, INT_T, BOOL_T, BOOL_T );
+track_p OnTrackIgnore(coOrd *, INT_T, BOOL_T , track_p );
+track_p OnTrack2( coOrd *, INT_T, BOOL_T, BOOL_T, track_p );
void ComputeRectBoundingBox( track_p, coOrd, coOrd );
void ComputeBoundingBox( track_p );
@@ -513,7 +549,7 @@ void DrawEndElev( drawCmd_p, track_p, EPINX_T, wDrawColor );
wDrawColor GetTrkColor( track_p, drawCmd_p );
void DrawTrack( track_cp, drawCmd_p, wDrawColor );
void DrawTracks( drawCmd_p, DIST_T, coOrd, coOrd );
-void RedrawLayer( LAYER_T, BOOL_T );
+void RedrawLayer( unsigned int, BOOL_T );
void DrawNewTrack( track_cp );
void DrawOneTrack( track_cp, drawCmd_p );
void UndrawNewTrack( track_cp );
@@ -547,6 +583,7 @@ void ConnectTracks( track_p, EPINX_T, track_p, EPINX_T );
BOOL_T ReconnectTrack( track_p, EPINX_T, track_p, EPINX_T );
void DisconnectTracks( track_p, EPINX_T, track_p, EPINX_T );
BOOL_T ConnectAbuttingTracks( track_p, EPINX_T, track_p, EPINX_T );
+BOOL_T ConnectTurntableTracks(track_p, EPINX_T, track_p, EPINX_T );
BOOL_T SplitTrack( track_p, coOrd, EPINX_T, track_p *leftover, BOOL_T );
BOOL_T TraverseTrack( traverseTrack_p, DIST_T * );
BOOL_T RemoveTrack( track_p*, EPINX_T*, DIST_T* );
@@ -560,6 +597,7 @@ BOOL_T QueryTrack( track_p, int );
void UngroupTrack( track_p );
BOOL_T IsTrack( track_p );
char * GetTrkTypeName( track_p );
+BOOL_T RebuildTrackSegs(track_p);
DIST_T GetFlexLength( track_p, EPINX_T, coOrd * );
void LabelLengths( drawCmd_p, track_p, wDrawColor );
@@ -576,8 +614,6 @@ void AdvancePositionIndicator( track_p, coOrd, coOrd *, ANGLE_T * );
BOOL_T MakeParallelTrack( track_p, coOrd, DIST_T, track_p *, coOrd *, coOrd * );
-#include "cundo.h"
-#include "cselect.h"
/* cmisc.c */
wIndex_t describeCmdInx;
@@ -600,7 +636,7 @@ typedef struct {
wControl_p control0;
wControl_p control1;
wPos_t posy;
- } descData_t, * descData_p;
+ } descData_t, * descData_p;
typedef void (*descUpdate_t)( track_p, int, descData_p, BOOL_T );
void DoDescribe( char *, track_p, descData_p, descUpdate_t );
void DescribeCancel( void );
@@ -632,6 +668,7 @@ void DrawTrackElev( track_p, drawCmd_p, BOOL_T );
/* cdraw.c */
track_p MakeDrawFromSeg( coOrd, ANGLE_T, trkSeg_p );
BOOL_T OnTableEdgeEndPt( track_p, coOrd * );
+BOOL_T GetClosestEndPt( track_p, coOrd * );
BOOL_T ReadTableEdge( char * );
BOOL_T ReadText( char * );