diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
commit | 5d2c2b27a6323e2666378b986129b2a7c2c39e5c (patch) | |
tree | ce8982b6c0111f79791068de2c2d4c6ce3138a49 /app/bin/ctodesgn.c | |
parent | b623f5953691b2a0614e6f1f4def86bdbb9a4113 (diff) |
New upstream version 5.2.2GAupstream/5.2.2GA
Diffstat (limited to 'app/bin/ctodesgn.c')
-rw-r--r-- | app/bin/ctodesgn.c | 496 |
1 files changed, 265 insertions, 231 deletions
diff --git a/app/bin/ctodesgn.c b/app/bin/ctodesgn.c index dc118a1..ea124cf 100644 --- a/app/bin/ctodesgn.c +++ b/app/bin/ctodesgn.c @@ -21,29 +21,18 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef WINDOWS -#include <stdlib.h> -#endif - -#include <stdint.h> -#include <ctype.h> -#include <math.h> -#include <string.h> -#include "messages.h" - #include "ccurve.h" #include "compound.h" #include "cstraigh.h" #include "custom.h" #include "fileio.h" -#include "i18n.h" #include "param.h" #include "track.h" -#include "utility.h" #include "ccornu.h" #include "cbezier.h" #include "misc.h" +#include "common-ui.h" dynArr_t tempSegs_da; dynArr_t tempEndPts_da; @@ -53,6 +42,8 @@ char tempCustom[4096]; dynArr_t tempSegs_da; +// Minimum Track Segment length +#define MIN_TRACK_LENGTH (0.20) /***************************************** * @@ -84,7 +75,7 @@ dynArr_t tempSegs_da; typedef struct { struct { - wPos_t x, y; + wWinPix_t x, y; } pos; int index; char * winLabel; @@ -148,13 +139,16 @@ static long newTurnRoadbedLineWidth = 0; static wDrawColor roadbedColor; static DIST_T newTurnTrackGauge; static char * newTurnScaleName; +static paramFloatRange_t r0d001_10000 = { 0.001, 10000, 80 }; +static paramFloatRange_t r0d300_10000 = { 0.300, 10000, 80 }; static paramFloatRange_t r0_10000 = { 0, 10000, 80 }; -static paramFloatRange_t r_10000_10000 = {-10000, 10000, 80 }; -static paramFloatRange_t r0_360 = { 0, 360, 80 }; +static paramFloatRange_t r_10000_10000 = { -1000, 10000, 80 }; +static paramFloatRange_t r0d001_90 = { 0.001, 90, 80 }; +static paramFloatRange_t r_90_90 = { -90, 90, 80 }; static paramFloatRange_t r0_100 = { 0, 100, 80 }; static paramIntegerRange_t i0_100 = { 0, 100, 40 }; -static void NewTurnOk( void * ); -static void ShowTurnoutDesigner( void * ); +static void NewTurnOk( void * context ); +static void ShowTurnoutDesigner( void * context ); static coOrd points[20]; @@ -166,48 +160,48 @@ static DIST_T radii[10]; static double angles[10]; -#define POSX(X) ((wPos_t)((X)*newTurnout_d.dpi)) -#define POSY(Y) ((wPos_t)((Y)*newTurnout_d.dpi)) +#define POSX(X) ((wWinPix_t)((X)*newTurnout_d.dpi)) +#define POSY(Y) ((wWinPix_t)((Y)*newTurnout_d.dpi)) static paramData_t turnDesignPLs[] = { #define I_TOLENGTH (0) #define I_TO_FIRST_FLOAT (0) - { PD_FLOAT, &newTurnLen0, "len0", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, - { PD_FLOAT, &newTurnLen1, "len1", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, - { PD_FLOAT, &newTurnLen2, "len2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, - { PD_FLOAT, &newTurnLen3, "len3", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, + { PD_FLOAT, &newTurnLen0, "len0", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Length") }, + { PD_FLOAT, &newTurnLen1, "len1", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Length") }, + { PD_FLOAT, &newTurnLen2, "len2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Length") }, + { PD_FLOAT, &newTurnLen3, "len3", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Length") }, #define I_TOOFFSET (4) - { PD_FLOAT, &newTurnOff0, "off0", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Offset") }, - { PD_FLOAT, &newTurnOff1, "off1", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Offset") }, - { PD_FLOAT, &newTurnOff2, "off2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Offset") }, - { PD_FLOAT, &newTurnOff3, "off3", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Offset") }, + { PD_FLOAT, &newTurnOff0, "off0", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Offset") }, + { PD_FLOAT, &newTurnOff1, "off1", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Offset") }, + { PD_FLOAT, &newTurnOff2, "off2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Offset") }, + { PD_FLOAT, &newTurnOff3, "off3", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d001_10000, N_("Offset") }, #define I_TORAD (8) { PD_FLOAT, &newTurnRad0, "rad0", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Radius") }, { PD_FLOAT, &newTurnRad1, "rad1", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Radius") }, - { PD_FLOAT, &newTurnRad2, "rad2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Radius") }, + { PD_FLOAT, &newTurnRad2, "rad2", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Radius") }, { PD_FLOAT, &newTurnRad3, "rad3", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r_10000_10000, N_("Radius") }, #define I_TOTOELENGTH (12) - { PD_FLOAT, &newTurnToeL, "toeL", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, - { PD_FLOAT, &newTurnToeR, "toeR", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0_10000, N_("Length") }, + { PD_FLOAT, &newTurnToeL, "toeL", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d300_10000, N_("Length") }, + { PD_FLOAT, &newTurnToeR, "toeR", PDO_DIM|PDO_DLGIGNORELABELWIDTH, &r0d300_10000, N_("Length") }, #define I_TOANGLE (14) - { PD_FLOAT, &newTurnAngle0, "angle0", PDO_DLGIGNORELABELWIDTH, &r0_360, N_("Angle") }, - { PD_FLOAT, &newTurnAngle1, "angle1", PDO_DLGIGNORELABELWIDTH, &r0_360, N_("Angle") }, - { PD_FLOAT, &newTurnAngle2, "angle2", PDO_DLGIGNORELABELWIDTH, &r0_360, N_("Angle") }, + { PD_FLOAT, &newTurnAngle0, "angle0", PDO_DLGIGNORELABELWIDTH, &r0d001_90, N_("Angle") }, + { PD_FLOAT, &newTurnAngle1, "angle1", PDO_DLGIGNORELABELWIDTH, &r0d001_90, N_("Angle") }, + { PD_FLOAT, &newTurnAngle2, "angle2", PDO_DLGIGNORELABELWIDTH, &r0d001_90, N_("Angle") }, #define I_TO_LAST_FLOAT (17) - { PD_FLOAT, &newTurnAngle3, "angle3", PDO_DLGIGNORELABELWIDTH, &r0_360, N_("Angle") }, + { PD_FLOAT, &newTurnAngle3, "angle3", PDO_DLGIGNORELABELWIDTH, &r0d001_90, N_("Angle") }, #define I_TOMANUF (18) - { PD_STRING, &newTurnManufacturer, "manuf", PDO_STRINGLIMITLENGTH, NULL, N_("Manufacturer"), 0, 0, sizeof(newTurnManufacturer)}, + { PD_STRING, &newTurnManufacturer, "manuf", PDO_NOTBLANK, NULL, N_("Manufacturer"), 0, 0, sizeof(newTurnManufacturer)}, #define I_TOLDESC (19) - { PD_STRING, &newTurnLeftDesc, "desc1", PDO_STRINGLIMITLENGTH, NULL, N_("Left Description"), 0, 0, sizeof(newTurnLeftDesc)}, - { PD_STRING, &newTurnLeftPartno, "partno1", PDO_DLGHORZ | PDO_STRINGLIMITLENGTH, NULL, N_(" #"), 0, 0, sizeof(newTurnLeftPartno)}, + { PD_STRING, &newTurnLeftDesc, "desc1", PDO_NOTBLANK, NULL, N_("Left Description"), 0, 0, sizeof(newTurnLeftDesc)}, + { PD_STRING, &newTurnLeftPartno, "partno1", PDO_DLGHORZ | PDO_NOTBLANK, NULL, N_(" #"), 0, 0, sizeof(newTurnLeftPartno)}, #define I_TORDESC (21) - { PD_STRING, &newTurnRightDesc, "desc2", PDO_STRINGLIMITLENGTH, NULL, N_("Right Description"),0, 0, sizeof(newTurnRightDesc)}, - { PD_STRING, &newTurnRightPartno, "partno2", PDO_DLGHORZ | PDO_STRINGLIMITLENGTH, NULL, N_(" #"),0, 0, sizeof(newTurnRightPartno)}, + { PD_STRING, &newTurnRightDesc, "desc2", PDO_NOTBLANK, NULL, N_("Right Description"),0, 0, sizeof(newTurnRightDesc)}, + { PD_STRING, &newTurnRightPartno, "partno2", PDO_DLGHORZ | PDO_NOTBLANK, NULL, N_(" #"),0, 0, sizeof(newTurnRightPartno)}, { PD_FLOAT, &newTurnRoadbedWidth, "roadbedWidth", PDO_DIM, &r0_100, N_("Roadbed Width") }, { PD_LONG, &newTurnRoadbedLineWidth, "roadbedLineWidth", PDO_DLGHORZ, &i0_100, N_("Line Width") }, { PD_COLORLIST, &roadbedColor, "color", PDO_DLGHORZ|PDO_DLGBOXEND, NULL, N_("Color") }, - { PD_BUTTON, (void*)NewTurnOk, "done", PDO_DLGCMDBUTTON, NULL, N_("Ok") }, - { PD_BUTTON, (void*)wPrintSetup, "printsetup", 0, NULL, N_("Print Setup") }, + { PD_BUTTON, NewTurnOk, "done", PDO_DLGCMDBUTTON, NULL, N_("Ok") }, + { PD_BUTTON, wPrintSetup, "printsetup", 0, NULL, N_("Print Setup") }, #define I_TOANGMODE (28) { PD_RADIO, &newTurnAngleMode, "angleMode", 0, newTurnAngleModeLabels }, #define I_TOSLIPMODE (29) @@ -215,7 +209,7 @@ static paramData_t turnDesignPLs[] = { }; #ifndef MKTURNOUT -static paramGroup_t turnDesignPG = { "turnoutNew", 0, turnDesignPLs, sizeof turnDesignPLs/sizeof turnDesignPLs[0] }; +static paramGroup_t turnDesignPG = { "turnoutNew", 0, turnDesignPLs, COUNT( turnDesignPLs ) }; static turnoutInfo_t * customTurnout1, * customTurnout2; static BOOL_T includeNontrackSegments; @@ -253,8 +247,8 @@ static toDesignDesc_t RegDesc = { NTO_REGULAR, N_("Regular Turnout"), 2, - sizeof RegLines/sizeof RegLines[0], RegLines, - sizeof RegFloats/sizeof RegFloats[0], RegFloats, + COUNT( RegLines ), RegLines, + COUNT( RegFloats ), RegFloats, &RegSchema, 1 }; static wLines_t CrvLines[] = { @@ -290,8 +284,8 @@ static toDesignDesc_t CrvDesc = { NTO_CURVED, N_("Curved Turnout"), 2, - sizeof CrvLines/sizeof CrvLines[0], CrvLines, - sizeof CrvFloats/sizeof CrvFloats[0], CrvFloats, + COUNT( CrvLines ), CrvLines, + COUNT( CrvFloats ), CrvFloats, &Crv1Schema, 1 }; static wLines_t CornuLines[] = { @@ -319,8 +313,8 @@ static toDesignDesc_t CornuDesc = { NTO_CORNU, N_("Cornu Curved Turnout"), 2, - sizeof CornuLines/sizeof CornuLines[0], CornuLines, - sizeof CornuFloats/sizeof CornuFloats[0], CornuFloats, + COUNT( CornuLines ), CornuLines, + COUNT( CornuFloats ), CornuFloats, &CornuSchema, 1 }; static wLines_t WyeLines[] = { @@ -356,8 +350,8 @@ static toDesignDesc_t WyeDesc = { NTO_WYE, N_("Wye Turnout"), 1, - sizeof WyeLines/sizeof WyeLines[0], WyeLines, - sizeof WyeFloats/sizeof WyeFloats[0], WyeFloats, + COUNT( WyeLines ), WyeLines, + COUNT( WyeFloats ), WyeFloats, NULL, 1 }; static wLines_t CornuWyeLines[] = { @@ -385,8 +379,8 @@ static toDesignDesc_t CornuWyeDesc = { NTO_CORNUWYE, N_("Cornu Wye Turnout"), 1, - sizeof CornuWyeLines/sizeof CornuWyeLines[0], CornuWyeLines, - sizeof CornuWyeFloats/sizeof CornuWyeFloats[0], CornuWyeFloats, + COUNT( CornuWyeLines ), CornuWyeLines, + COUNT( CornuWyeFloats ), CornuWyeFloats, NULL, 1 }; static wLines_t ThreewayLines[] = { @@ -426,8 +420,8 @@ static toDesignDesc_t ThreewayDesc = { NTO_3WAY, N_("3-way Turnout"), 1, - sizeof ThreewayLines/sizeof ThreewayLines[0], ThreewayLines, - sizeof ThreewayFloats/sizeof ThreewayFloats[0], ThreewayFloats, + COUNT( ThreewayLines ), ThreewayLines, + COUNT( ThreewayFloats ), ThreewayFloats, NULL, 1 }; static wLines_t CornuThreewayLines[] = { @@ -461,8 +455,8 @@ static toDesignDesc_t CornuThreewayDesc = { NTO_CORNU3WAY, N_("Cornu 3-way Turnout"), 1, - sizeof CornuThreewayLines/sizeof CornuThreewayLines[0], CornuThreewayLines, - sizeof CornuThreewayFloats/sizeof CornuThreewayFloats[0], CornuThreewayFloats, + COUNT( CornuThreewayLines ), CornuThreewayLines, + COUNT( CornuThreewayFloats ), CornuThreewayFloats, NULL, 1 }; static wLines_t CrossingLines[] = { @@ -481,8 +475,8 @@ static toDesignDesc_t CrossingDesc = { NTO_CROSSING, N_("Crossing"), 1, - sizeof CrossingLines/sizeof CrossingLines[0], CrossingLines, - sizeof CrossingFloats/sizeof CrossingFloats[0], CrossingFloats, + COUNT( CrossingLines ), CrossingLines, + COUNT( CrossingFloats ), CrossingFloats, &CrossingSchema, 1 }; static wLines_t SingleSlipLines[] = { @@ -502,8 +496,8 @@ static toDesignDesc_t SingleSlipDesc = { NTO_S_SLIP, N_("Single Slipswitch"), 1, - sizeof SingleSlipLines/sizeof SingleSlipLines[0], SingleSlipLines, - sizeof SingleSlipFloats/sizeof SingleSlipFloats[0], SingleSlipFloats, + COUNT( SingleSlipLines ), SingleSlipLines, + COUNT( SingleSlipFloats ), SingleSlipFloats, &SingleSlipSchema, 1 }; static wLines_t DoubleSlipLines[] = { @@ -531,8 +525,8 @@ static toDesignDesc_t DoubleSlipDesc = { NTO_D_SLIP, N_("Double Slipswitch"), 1, - sizeof DoubleSlipLines/sizeof DoubleSlipLines[0], DoubleSlipLines, - sizeof DoubleSlipFloats/sizeof DoubleSlipFloats[0], DoubleSlipFloats, + COUNT( DoubleSlipLines ), DoubleSlipLines, + COUNT( DoubleSlipFloats ), DoubleSlipFloats, &DoubleSlipSchema, 1 }; static wLines_t RightCrossoverLines[] = { @@ -551,8 +545,8 @@ static toDesignDesc_t RightCrossoverDesc = { NTO_R_CROSSOVER, N_("Right Crossover"), 1, - sizeof RightCrossoverLines/sizeof RightCrossoverLines[0], RightCrossoverLines, - sizeof RightCrossoverFloats/sizeof RightCrossoverFloats[0], RightCrossoverFloats, + COUNT( RightCrossoverLines ), RightCrossoverLines, + COUNT( RightCrossoverFloats ), RightCrossoverFloats, &RightCrossoverSchema, 0 }; static wLines_t LeftCrossoverLines[] = { @@ -571,8 +565,8 @@ static toDesignDesc_t LeftCrossoverDesc = { NTO_L_CROSSOVER, N_("Left Crossover"), 1, - sizeof LeftCrossoverLines/sizeof LeftCrossoverLines[0], LeftCrossoverLines, - sizeof LeftCrossoverFloats/sizeof LeftCrossoverFloats[0], LeftCrossoverFloats, + COUNT( LeftCrossoverLines ), LeftCrossoverLines, + COUNT( LeftCrossoverFloats ), LeftCrossoverFloats, &LeftCrossoverSchema, 0 }; static wLines_t DoubleCrossoverLines[] = { @@ -591,8 +585,8 @@ static toDesignDesc_t DoubleCrossoverDesc = { NTO_D_CROSSOVER, N_("Double Crossover"), 1, - sizeof DoubleCrossoverLines/sizeof DoubleCrossoverLines[0], DoubleCrossoverLines, - sizeof DoubleCrossoverFloats/sizeof DoubleCrossoverFloats[0], DoubleCrossoverFloats, + COUNT( DoubleCrossoverLines ), DoubleCrossoverLines, + COUNT( DoubleCrossoverFloats ), DoubleCrossoverFloats, &DoubleCrossoverSchema, 0 }; static wLines_t StrSectionLines[] = { @@ -609,8 +603,8 @@ static toDesignDesc_t StrSectionDesc = { NTO_STR_SECTION, N_("Straight Section"), 1, - sizeof StrSectionLines/sizeof StrSectionLines[0], StrSectionLines, - sizeof StrSectionFloats/sizeof StrSectionFloats[0], StrSectionFloats, + COUNT( StrSectionLines ), StrSectionLines, + COUNT( StrSectionFloats ), StrSectionFloats, &StrSectionSchema, 0 }; static wLines_t CrvSectionLines[] = { @@ -628,8 +622,8 @@ static toDesignDesc_t CrvSectionDesc = { NTO_CRV_SECTION, N_("Curved Section"), 1, - sizeof CrvSectionLines/sizeof CrvSectionLines[0], CrvSectionLines, - sizeof CrvSectionFloats/sizeof CrvSectionFloats[0], CrvSectionFloats, + COUNT( CrvSectionLines ), CrvSectionLines, + COUNT( CrvSectionFloats ), CrvSectionFloats, &CrvSectionSchema, 0 }; #ifdef LATER @@ -647,8 +641,8 @@ static toDesignDesc_t BumperDesc = { NTO_BUMPER, N_("Bumper Section"), 1, - sizeof StrSectionLines/sizeof StrSectionLines[0], StrSectionLines, - sizeof BumperFloats/sizeof BumperFloats[0], BumperFloats, + COUNT( BumberLines ), BumperLines, + COUNT( BumperFloats ), BumperFloats, &BumperSchema, 0 }; static wLines_t TurntableLines[] = { @@ -739,8 +733,8 @@ static toDesignDesc_t TurntableDesc = { NTO_TURNTABLE, N_("Turntable Section"), 1, - sizeof StrSectionLines/sizeof StrSectionLines[0], StrSectionLines, - sizeof TurntableFloats/sizeof TurntableFloats[0], TurntableFloats, + COUNT( TurntableLines ), TurntableLines, + COUNT( TurntableFloats ), TurntableFLoats, &TurntableSchema, 0 }; #endif @@ -900,7 +894,7 @@ BOOL_T HittestTurnoutRoadbed( d -= roadbedWidth/2.0; PointOnCircle( &p0, sp->u.c.center, d, a ); } - dd = 100000.0; + dd = DIST_INF; closest = -1; for (inx=0; inx<segCnt; inx++) { sp = &segPtr[inx]; @@ -953,7 +947,7 @@ EXPORT long ComputeTurnoutRoadbedSide( rbw = (int)(roadbedWidth/length*32/2); /*printf( "L=%0.3f G=%0.3f [%0.3f %0.3f] RBW=%d\n", length, gapWidth, first, last, rbw );*/ res = 0xFF0000FF; - for ( p=searchTable; p<&searchTable[sizeof searchTable/sizeof searchTable[0]]; p++) { + for ( p=searchTable; p<&searchTable[COUNT( searchTable )]; p++) { if ( (p->width < rbw && res==0xFFFFFFFF) || res==0 ) break; res1 = (p->mask & res); @@ -1043,7 +1037,7 @@ if ( debugComputeRoadbed>=3 ) printf( " res=%lx\n", res ); hit0 = hit1; } if ( debugComputeRoadbed>=2 ) printf( "S%d %c res=%lx\n", segInx, side>0?'+':'-', res ); - return res; + return (0xFFFFFFFF)&res; } @@ -1286,11 +1280,10 @@ BOOL_T CallCornuNoBez(coOrd pos[2], coOrd center[2], ANGLE_T angle[2], DIST_T ra static toDesignSchema_t * LoadSegs( toDesignDesc_t * dp, - wBool_t loadPoints, - wIndex_t * pathLenP ) + wBool_t loadPoints ) { wIndex_t s; - int i, p, p0, p1; + int p, p0, p1; DIST_T d; #ifndef MKTURNOUT wIndex_t pathLen; @@ -1332,15 +1325,15 @@ static toDesignSchema_t * LoadSegs( pp = dp->paths; if (loadPoints) { DYNARR_RESET( trkEndPt_t, tempEndPts_da ); - for ( i=0; i<dp->floatCnt; i++ ) - if ( *(FLOAT_T*)(turnDesignPLs[dp->floats[i].index].valueP) == 0.0 ) - if (dp->type != NTO_CORNU && - dp->type != NTO_CORNUWYE && - dp->type != NTO_CORNU3WAY - ) { - NoticeMessage( MSG_TODSGN_VALUES_GTR_0, _("Ok"), NULL ); - return NULL; - } +// for ( i=0; i<dp->floatCnt; i++ ) +// if ( *(FLOAT_T*)(turnDesignPLs[dp->floats[i].index].valueP) == 0.0 ) +// if (dp->type != NTO_CORNU && +// dp->type != NTO_CORNUWYE && +// dp->type != NTO_CORNU3WAY +// ) { +// NoticeMessage( MSG_TODSGN_VALUES_GTR_0, _("Ok"), NULL ); +// return NULL; +// } switch (dp->type) { case NTO_REGULAR: @@ -1367,9 +1360,9 @@ static toDesignSchema_t * LoadSegs( (newTurnLen1), fabs(newTurnOff1), angle1 ) ) return NULL; d = points[3].x - points[5].x; - if ( d < -0.10 ) + if ( d < -MIN_TRACK_LENGTH ) pp = &Crv3Schema; - else if ( d > 0.10 ) + else if ( d > MIN_TRACK_LENGTH ) pp = &Crv2Schema; else pp = &Crv1Schema; @@ -1422,9 +1415,9 @@ static toDesignSchema_t * LoadSegs( points[7].y = 0; points[7].x = (newTurnLen2); d = points[3].x - points[5].x; - if ( d < -0.10 ) { + if ( d < -MIN_TRACK_LENGTH ) { pp = (dp->type==NTO_3WAY ? &Tri3Schema : &Wye3Schema ); - } else if ( d > 0.10 ) { + } else if ( d > MIN_TRACK_LENGTH ) { pp = (dp->type==NTO_3WAY ? &Tri2Schema : &Wye2Schema ); } else { pp = (dp->type==NTO_3WAY ? &Tri1Schema : &Wye1Schema ); @@ -1499,21 +1492,32 @@ static toDesignSchema_t * LoadSegs( } } - DIST_T end_length = minLength/2; + DIST_T end_length = MIN_TRACK_LENGTH; for (int i=0;i<((dp->type==NTO_CORNU3WAY)?4:3);i++) { if (radii[i] == 0.0) { - Translate(&end_points[i], points[i], 90-angles[i]+(i==0?0:180), end_length); + if (i==2) + Translate(&end_points[i], points[i], NormalizeAngle(90.0+angles[i]+180), end_length); + else + Translate(&end_points[i], points[i], NormalizeAngle(90.0-angles[i]+(i==0?0.0:180.0)), end_length); end_angles[i] = angles[i]; } else { - if (((i==0) && radii[0]>0.0) || ((i==1 || i==3) && radii[i]>0.0)|| ((i==2) && radii[i]<0.0)) - Translate(&end_centers[i], points[i], -angles[i], fabs(radii[i])); - else - Translate(&end_centers[i], points[i], angles[i], fabs(radii[i])); - end_arcs[i] = (radii[i]>=0?1:-1)*R2D(end_length/fabs(radii[i])); + if (i!=2) { + if (((i==0) && radii[0]>0.0) || ((i==1 || i==3) && radii[i]>0.0)) + Translate(&end_centers[i], points[i], -angles[i], fabs(radii[i])); + else + Translate(&end_centers[i], points[i], angles[i]+180, fabs(radii[i])); + end_arcs[i] = (radii[i]>=0?1:-1)*R2D(end_length/fabs(radii[i])); + } else { + if (radii[2]>0.0) + Translate(&end_centers[i], points[i], angles[i]+180, fabs(radii[i])); + else + Translate(&end_centers[i], points[i], -angles[i], fabs(radii[i])); + end_arcs[i] = (radii[i]>=0?-1:1)*R2D(end_length/fabs(radii[i])); + } end_points[i] = points[i]; - Rotate(&end_points[i],end_centers[i],((i==0||i==3)?-1:1)*end_arcs[i]); - end_angles[i] = angles[i]-((i==0||i==3)?-1:1)*end_arcs[i]; + Rotate(&end_points[i],end_centers[i],end_arcs[i]); + end_angles[i] = angles[i]+end_arcs[i]; } LogPrintf( "ctoDes0-%d: EP(%f,%f) NEP(%f,%f) EA(%f) NEA(%f) R(%f) ARC(%f) EC(%f,%f) \n", i+1,points[i].x,points[i].y,end_points[i].x,end_points[i].y,angles[i],end_angles[i],radii[i],end_arcs[i], @@ -1620,20 +1624,18 @@ LogPrintf( "ctoDes0-%d: EP(%f,%f) NEP(%f,%f) EA(%f) NEA(%f) R(%f) ARC(%f) EC(%f, int inx,subSeg; wBool_t back, neg; - CallCornu0(&cornuData.pos[0],&cornuData.center[0],&cornuData.angle[0],&cornuData.radius[0],&tempSegs_da, FALSE); - /* Override if a "Y" has zero radius at base to be a straight until the Toe * We set the start of the curve to be at the Toe position */ if (cornuData.radius[0] == 0.0) { - pos.x = end_points[0].x+(LH_first?newTurnToeL:newTurnToeR); - pos.y = 0.0; + pos.x = end_points[0].x+(LH_first?newTurnToeL:newTurnToeR)-MIN_TRACK_LENGTH; + pos.y = end_points[0].y; angle = 90.0; radius = 0.0; center = zero; } else { - /*Find Toe 1 from curve */ + CallCornu0(&cornuData.pos[0],&cornuData.center[0],&cornuData.angle[0],&cornuData.radius[0],&tempSegs_da, FALSE); /*Get ToeAngle/Radius/Center for first toe */ pos.x = end_points[0].x+(LH_first?newTurnToeL:newTurnToeR); @@ -1692,22 +1694,30 @@ LogPrintf( "ctoDes0-%d: EP(%f,%f) NEP(%f,%f) EA(%f) NEA(%f) R(%f) ARC(%f) EC(%f, if (dp->type == NTO_CORNU3WAY) { if (newTurnToeR!=newTurnToeL) { /* Second Toe */ - pos.x = end_points[0].x+(LH_first?newTurnToeR:newTurnToeL); - pos.y = end_points[0].y; /* This will be close to but not on the curve */ - angle = GetAngleSegs(tempSegs_da.cnt,(trkSeg_t *)(tempSegs_da.ptr),&pos,&inx,NULL,&back,&subSeg,&neg); - segPtr = &DYNARR_N(trkSeg_t, tempSegs_da, inx); - - if (segPtr->type == SEG_BEZTRK) { - segPtr = &DYNARR_N(trkSeg_t,segPtr->bezSegs,subSeg); - } - - if (segPtr->type == SEG_STRTRK) { + if (cornuData.radius[0] == 0.0) { + pos.x = end_points[0].x+(LH_first?newTurnToeR:newTurnToeL)-MIN_TRACK_LENGTH; + pos.y = 0.0; + angle = 90.0; radius = 0.0; center = zero; - } else if (segPtr->type == SEG_CRVTRK) { - center = segPtr->u.c.center; - radius = fabs(segPtr->u.c.radius); - } + } else { + pos.x = end_points[0].x+(LH_first?newTurnToeR:newTurnToeL); + pos.y = end_points[0].y; /* This will be close to but not on the curve */ + angle = GetAngleSegs(tempSegs_da.cnt,(trkSeg_t *)(tempSegs_da.ptr),&pos,&inx,NULL,&back,&subSeg,&neg); + segPtr = &DYNARR_N(trkSeg_t, tempSegs_da, inx); + + if (segPtr->type == SEG_BEZTRK) { + segPtr = &DYNARR_N(trkSeg_t,segPtr->bezSegs,subSeg); + } + + if (segPtr->type == SEG_STRTRK) { + radius = 0.0; + center = zero; + } else if (segPtr->type == SEG_CRVTRK) { + center = segPtr->u.c.center; + radius = fabs(segPtr->u.c.radius); + } + } cornuData.pos[3] = pos; cornuData.center[3] = center; cornuData.angle[3] = angle; @@ -1786,16 +1796,36 @@ LogPrintf( "ctoDes1: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f), EP(%f,%f) RP0(%f,%f) points[0].x,points[0].y,end_points[0].x,end_points[0].y, rp0.x,rp0.y,rp1.x,rp1.y); } - - if ((cornuData.pos[0].x != cornuData.pos[1].x) || - (cornuData.pos[0].y != cornuData.pos[1].y) ) + //If Radius zero, just a straight to the First Toe if offset + if (cornuData.radius[0] == 0.0) { + if ((cornuData.pos[0].x != cornuData.pos[1].x) || + (cornuData.pos[0].y != cornuData.pos[1].y)) { + DYNARR_APPEND(trkSeg_t,tempSegs_da,1); + temp_p = &DYNARR_LAST(trkSeg_t,tempSegs_da); + temp_p->type = SEG_STRTRK; + temp_p->color = wDrawColorBlack; + temp_p->width = 0.0; + temp_p->u.l.pos[0] = cornuData.pos[0]; + temp_p->u.l.pos[1] = cornuData.pos[1]; + } + } else if ((cornuData.pos[0].x != cornuData.pos[1].x) || + (cornuData.pos[0].y != cornuData.pos[1].y) ) CallCornuNoBez(&cornuData.pos[0],&cornuData.center[0],&cornuData.angle[0],&cornuData.radius[0],&tempSegs_da); + Toe1Seg = tempSegs_da.cnt; if (dp->type == NTO_CORNU3WAY) { if (newTurnToeR!=newTurnToeL) { /* Toe1 to Toe2 in tempSegs array */ - if ((cornuData.pos[2].x != cornuData.pos[3].x) || + if (cornuData.radius[0] == 0.0) { + DYNARR_APPEND(trkSeg_t,cornuSegs_da,1); + temp_p = &DYNARR_LAST(trkSeg_t,cornuSegs_da); + temp_p->type = SEG_STRTRK; + temp_p->color = wDrawColorBlack; + temp_p->width = 0.0; + temp_p->u.l.pos[0] = cornuData.pos[2]; + temp_p->u.l.pos[1] = cornuData.pos[3]; + } else if ((cornuData.pos[2].x != cornuData.pos[3].x) || (cornuData.pos[2].y != cornuData.pos[3].y) ) CallCornuNoBez(&cornuData.pos[2],&cornuData.center[2],&cornuData.angle[2],&cornuData.radius[2],&cornuSegs_da); @@ -1817,7 +1847,7 @@ LogPrintf( "ctoDes1: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f), EP(%f,%f) RP0(%f,%f) temp_p->color = wDrawColorBlack; temp_p->width = 0.0; temp_p->u.l.pos[0] = cornuData.pos[5]; - temp_p->u.l.pos[1] = end_points[3]; + temp_p->u.l.pos[1] = points[3]; LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->u.l.pos[0].x,temp_p->u.l.pos[0].y,temp_p->u.l.pos[1].x,temp_p->u.l.pos[1].y ); } else { @@ -1826,7 +1856,7 @@ LogPrintf( "ctoDes1: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f), EP(%f,%f) RP0(%f,%f) temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[3]); + temp_p->u.c.radius = -radii[3]; //Assumed Left if (radii[3]>0) temp_p->u.c.a0 = FindAngle(end_centers[3],points[3]); else @@ -1861,7 +1891,7 @@ LogPrintf( "ctoDes1: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f), EP(%f,%f) RP0(%f,%f) temp_p->color = wDrawColorBlack; temp_p->width = 0.0; temp_p->u.l.pos[0] = cornuData.pos[7]; - temp_p->u.l.pos[1] = end_points[1]; + temp_p->u.l.pos[1] = points[1]; LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->u.l.pos[0].x,temp_p->u.l.pos[0].y,temp_p->u.l.pos[1].x,temp_p->u.l.pos[1].y ); } else { @@ -1870,7 +1900,7 @@ LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[1]); + temp_p->u.c.radius = -radii[1]; //Negative relative to left if (radii[1]>0) temp_p->u.c.a0 = FindAngle(end_centers[1],points[1]); else @@ -1903,7 +1933,7 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) temp_p->color = wDrawColorBlack; temp_p->width = 0.0; temp_p->u.l.pos[0] = cornuData.pos[9]; - temp_p->u.l.pos[1] = end_points[2]; + temp_p->u.l.pos[1] = points[2]; LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->u.l.pos[0].x,temp_p->u.l.pos[0].y,temp_p->u.l.pos[1].x,temp_p->u.l.pos[1].y ); } else { @@ -1912,9 +1942,9 @@ LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[2]); - if (radii[2]<0) - temp_p->u.c.a0 = FindAngle(end_centers[2],points[2]); + temp_p->u.c.radius = radii[2]; + if (radii[2]>0) + temp_p->u.c.a0 = FindAngle(end_centers[2],cornuData.pos[9]); else temp_p->u.c.a0 = FindAngle(end_centers[2],end_points[2]); temp_p->u.c.a1 = fabs(end_arcs[2]); @@ -1945,7 +1975,7 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) static char pathChar[512]; if (dp->type == NTO_CORNU3WAY) { strcpy(pathChar,"Normal"); /* Also resets array */ - pathLen = strlen(pathChar)+1; + pathLen = (wIndex_t)strlen(pathChar)+1; for (uint8_t i=0;i<CenterEndSeg;i++) { pathChar[pathLen] = i+1; pathLen++; @@ -1955,10 +1985,10 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) pathChar[pathLen] = 0; pathLen++; sprintf(&pathChar[pathLen],"%s","Left"); - pathLen += strlen(&pathChar[pathLen])+1; + pathLen += (wIndex_t)strlen(&pathChar[pathLen])+1; } else { strcpy(pathChar,"Left"); - pathLen = strlen(pathChar)+1; + pathLen = (wIndex_t)strlen(pathChar)+1; } for (uint8_t i=0;i<Toe1Seg;i++) { pathChar[pathLen] = i+1; @@ -1982,7 +2012,7 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) pathLen++; sprintf(&pathChar[pathLen],"%s","Right"); - pathLen += strlen(&pathChar[pathLen])+1; + pathLen += (wIndex_t)strlen(&pathChar[pathLen])+1; for (uint8_t i=0;i<Toe1Seg;i++) { pathChar[pathLen] = i+1; @@ -2107,9 +2137,9 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) switch (dp->type) { case NTO_CURVED: d = points[3].x - points[5].x; - if ( d < -0.10 ) + if ( d < -MIN_TRACK_LENGTH ) pp = &Crv3Schema; - else if ( d > 0.10 ) + else if ( d > MIN_TRACK_LENGTH ) pp = &Crv2Schema; else pp = &Crv1Schema; @@ -2121,7 +2151,7 @@ LogPrintf( "ctoDes2: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) if(dp->type == NTO_CORNU) { DYNARR_SET( trkEndPt_t, tempEndPts_da, 3 ); - DIST_T end_length = minLength/2; + DIST_T end_length = MIN_TRACK_LENGTH; // Adjust end_points to impose small fixed end segments @@ -2173,7 +2203,7 @@ LogPrintf( "ctoDes0-%d: EP(%f,%f) NEP(%f,%f) EA(%f) NEA(%f) R(%f) ARC(%f) EC(%f, cornuData.radius[0] = fabs(radii[0]); cornuData.radius[1] = fabs(radii[2]); cornuData.radius[3] = fabs(radii[2]); - cornuData.radius[5] = fabs(radii[1]); /*Inner*/ + cornuData.radius[5] = fabs(radii[1]); /*Inner*/ DYNARR_RESET( trkSeg_t, tempSegs_da ); trkSeg_t * temp_p, * cornu_p; @@ -2188,7 +2218,7 @@ LogPrintf( "ctoDes0-%d: EP(%f,%f) NEP(%f,%f) EA(%f) NEA(%f) R(%f) ARC(%f) EC(%f, wBool_t back, neg; DIST_T radius; coOrd center; - pos.x = end_points[0].x+newTurnToeL; + pos.x = end_points[0].x+newTurnToeL-MIN_TRACK_LENGTH; pos.y = end_points[0].y; /* This will be close to but not on the curve */ ANGLE_T angle = GetAngleSegs(tempSegs_da.cnt,(trkSeg_t *)(tempSegs_da.ptr),&pos,&inx,NULL,&back,&subSeg,&neg); segPtr = &DYNARR_N(trkSeg_t, tempSegs_da, inx); @@ -2239,7 +2269,7 @@ LogPrintf( "ctoDes1: P0(%f,%f) P1(%f,%f) \n", temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[0]);; + temp_p->u.c.radius = -radii[0]; if (radii[0]>0.0) temp_p->u.c.a0 = FindAngle(end_centers[0],end_points[0]); else @@ -2281,7 +2311,7 @@ LogPrintf( "ctoDes2: P0(%f,%f) P1(%f,%f) \n", temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[2]); + temp_p->u.c.radius = -radii[2]; if (radii[2]>0) temp_p->u.c.a0 = FindAngle(end_centers[2],points[2]); else @@ -2324,7 +2354,7 @@ LogPrintf( "ctoDes3: P0(%f,%f) P1(%f,%f) \n", temp_p->type = SEG_CRVTRK; temp_p->color = wDrawColorBlack; temp_p->width = 0.0; - temp_p->u.c.radius = fabs(radii[1]); + temp_p->u.c.radius = -radii[1]; if (radii[1]>0) temp_p->u.c.a0 = FindAngle(end_centers[1],points[1]); else @@ -2357,7 +2387,7 @@ LogPrintf( "ctoDes3: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) static char pathChar[512]; strcpy(pathChar,"Normal"); /* Also resets array */ - pathLen = strlen(pathChar)+1; + pathLen = (wIndex_t)strlen(pathChar)+1; for (uint8_t i=0;i<OuterEndSeg;i++) { pathChar[pathLen] = i+1; @@ -2370,7 +2400,7 @@ LogPrintf( "ctoDes3: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) sprintf(&pathChar[pathLen],"%s","Reverse"); - pathLen += strlen(&pathChar[pathLen])+1; + pathLen += (wIndex_t)strlen(&pathChar[pathLen])+1; for (uint8_t i=0;i<ToeSeg;i++) { pathChar[pathLen] = i+1; pathLen++; @@ -2393,7 +2423,7 @@ LogPrintf( "ctoDes3: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) if (!( (dp->type== NTO_CORNU) || (dp->type == NTO_CORNUWYE) || (dp->type == NTO_CORNU3WAY))) { segOrder = pp->segOrder; - segCnt = strlen( segOrder ); + segCnt = (wIndex_t)strlen( segOrder ); if (segCnt%3 != 0) AbortProg( dp->label ); segCnt /= 3; @@ -2429,11 +2459,8 @@ LogPrintf( "ctoDes3: R(%f) A0(%f) A1(%f) C(%f,%f) P(%f,%f) EP(%f,%f) RP0(%f,%f) AddRoadbed(); #ifndef MKTURNOUT - if ( (pathLen=CheckPaths( segCnt, &tempSegs(0), pp->paths )) < 0 ) + if ( CheckPaths( segCnt, &tempSegs(0), pp->paths ) < 0 ) return NULL; - - if (pathLenP) - *pathLenP = pathLen; #endif return pp; } @@ -2474,7 +2501,7 @@ static void NewTurnPrint( { 0.0, 0.0 }, Pix2CoOrd, CoOrd2Pix }; - if ((pp=LoadSegs( curDesign, TRUE, NULL )) == NULL) + if ((pp=LoadSegs( curDesign, TRUE )) == NULL) return; if (includeNontrackSegments && customTurnout1) CopyNonTracks( customTurnout1 ); @@ -2529,26 +2556,25 @@ static void NewTurnPrint( #endif orig.x = - ( size.y + orig.x + newTurnTrackGauge/2.0 + 0.5 ); orig.y -= (0.5); + coOrd strPos; for ( i=0, newTurnout_d.orig.x=orig.x; i<ii; i++, newTurnout_d.orig.x+=newTurnout_d.size.x ) { for ( j=0, newTurnout_d.orig.y=orig.y; j<jj; j++, newTurnout_d.orig.y+=newTurnout_d.size.y ) { newTurnout_d.d = wPrintPageStart(); newTurnout_d.dpi = wDrawGetDPI(newTurnout_d.d); + strPos.x = newTurnout_d.orig.x + 3.0; sprintf( message, "%s", sProdName ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(6.75), 0.0, message, fp, 40, - wDrawColorBlack, 0 ); + strPos.y = newTurnout_d.orig.y + 6.75; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 40, wDrawColorBlack ); sprintf( message, _("%s Designer"), _(curDesign->label) ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(6.25), 0.0, message, fp, 30, - wDrawColorBlack, 0 ); + strPos.y -= 0.5; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 20, wDrawColorBlack ); sprintf( message, _("%s %d x %d (of %d x %d)"), _("Page"), i+1, j+1, ii, jj ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(5.75), 0.0, message, fp, 20, - wDrawColorBlack, 0 ); - + strPos.y -= 0.5; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 20, wDrawColorBlack ); + strPos.y -= 0.10; for ( p=0; p<curDesign->floatCnt; p++ ) { tmpR = *(FLOAT_T*)(turnDesignPLs[curDesign->floats[p].index].valueP); sprintf( message, "%s: %s", @@ -2556,34 +2582,21 @@ static void NewTurnPrint( curDesign->floats[p].mode==Dim_e? FormatDistance(tmpR): FormatFloat(tmpR) ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(5.50-p*0.25), 0.0, - message, fp, 20, wDrawColorBlack, 0 ); + strPos.y -= 0.25; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 16, wDrawColorBlack ); } if (newTurnLeftDesc[0] || newTurnLeftPartno[0]) { sprintf( message, "%s %s %s", newTurnManufacturer, newTurnLeftPartno, newTurnLeftDesc ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(5.50-curDesign->floatCnt*0.25), 0.0, - message, fp, 20, wDrawColorBlack, 0 ); + strPos.y -= 0.25; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 16, wDrawColorBlack ); } if (newTurnRightDesc[0] || newTurnRightPartno[0]) { sprintf( message, "%s %s %s", newTurnManufacturer, newTurnRightPartno, newTurnRightDesc ); - wDrawString( newTurnout_d.d, POSX(3.0), - POSY(5.50-curDesign->floatCnt*0.25-0.25), 0.0, - message, fp, 20, wDrawColorBlack, 0 ); + strPos.y -= 0.25; + DrawString( &newTurnout_d, strPos, 0.0, message, fp, 16, wDrawColorBlack ); } - wDrawLine( newTurnout_d.d, POSX(0), POSY(0), - POSX(newTurnout_d.size.x), POSY(0), 0, wDrawLineSolid, - wDrawColorBlack, 0 ); - wDrawLine( newTurnout_d.d, POSX(newTurnout_d.size.x), POSY(0.0), - POSX(newTurnout_d.size.x), POSY(newTurnout_d.size.y), 0, - wDrawLineSolid, wDrawColorBlack, 0 ); - wDrawLine( newTurnout_d.d, POSX(newTurnout_d.size.x), POSY(newTurnout_d.size.y), - POSX(0.0), POSY(newTurnout_d.size.y), 0, wDrawLineSolid, - wDrawColorBlack, 0 ); - wDrawLine( newTurnout_d.d, POSX(0.0), POSY(newTurnout_d.size.y), - POSX(0.0), POSX(0.0), 0, wDrawLineSolid, wDrawColorBlack, 0 ); + DrawRectangle( &newTurnout_d, newTurnout_d.orig, newTurnout_d.size, wDrawColorBlack, DRAW_CLOSED ); DrawSegs( &newTurnout_d, zero, 270.0, &tempSegs(0), tempSegs_da.cnt, newTurnTrackGauge, wDrawColorBlack ); @@ -2615,7 +2628,6 @@ static void NewTurnOk( void * context ) { FILE * f; toDesignSchema_t * pp; - wIndex_t pathLen; int i; BOOL_T foundR=FALSE; char * cp; @@ -2625,16 +2637,20 @@ static void NewTurnOk( void * context ) FLOAT_T flt; wIndex_t segCnt; char * customInfoP; - char *oldLocale = NULL; - if ((pp=LoadSegs( curDesign, TRUE, &pathLen )) == NULL) +#ifndef MKTURNOUT + if ( ! ParamCheckInputs( &turnDesignPG, (wControl_p)turnDesignPG.okB ) ) return; +#endif - if ( (curDesign->strCnt >= 1 && newTurnLeftDesc[0] == 0) || - (curDesign->strCnt >= 2 && newTurnRightDesc[0] == 0) ) { - NoticeMessage( MSG_TODSGN_DESC_NONBLANK, _("Ok"), NULL ); + if ((pp=LoadSegs( curDesign, TRUE )) == NULL) return; - } + +// if ( (curDesign->strCnt >= 1 && newTurnLeftDesc[0] == 0) || +// (curDesign->strCnt >= 2 && newTurnRightDesc[0] == 0) ) { +// NoticeMessage( MSG_TODSGN_DESC_NONBLANK, _("Ok"), NULL ); +// return; +// } BuildTrimedTitle( message, "\t", newTurnManufacturer, newTurnLeftDesc, newTurnLeftPartno ); #ifndef MKTURNOUT @@ -2643,7 +2659,7 @@ static void NewTurnOk( void * context ) if ( !NoticeMessage( MSG_TODSGN_REPLACE, _("Yes"), _("No") ) ) return; } - oldLocale = SaveLocale("C"); + SetCLocale(); #endif f = OpenCustom("a"); @@ -2695,6 +2711,9 @@ static void NewTurnOk( void * context ) strcpy( tempCustom, message ); segCnt = tempSegs_da.cnt; + long options = 0; + if ( curDesign->type == NTO_D_SLIP && newTurnSlipMode == 1) + options |= COMPOUND_OPTION_PATH_NOCOMBINE; #ifndef MKTURNOUT if (includeNontrackSegments && customTurnout1) CopyNonTracks( customTurnout1 ); @@ -2708,13 +2727,12 @@ static void NewTurnOk( void * context ) (curDesign->type == NTO_CORNU3WAY)) { radii_ends = &radii[0]; } - to = CreateNewTurnout( newTurnScaleName, tempCustom, tempSegs_da.cnt, &tempSegs(0), - pathLen, pp->paths, tempEndPts_da.cnt, &tempEndPts(0), radii, FALSE ); + pp->paths, tempEndPts_da.cnt, &tempEndPts(0), FALSE, options ); to->customInfo = customInfoP; #endif if (f) { - fprintf( f, "TURNOUT %s \"%s\"\n", newTurnScaleName, PutTitle(tempCustom) ); + fprintf( f, "TURNOUT %s \"%s\" %ld\n", newTurnScaleName, PutTitle(tempCustom), options ); #ifdef MKTURNOUT if (doCustomInfoLine) #endif @@ -2729,7 +2747,7 @@ static void NewTurnOk( void * context ) points[3].y = - points[3].y; points[4].y = - points[4].y; radii[0] = - radii[0]; - LoadSegs( curDesign, FALSE, &pathLen ); + LoadSegs( curDesign, FALSE ); tempEndPts(2).pos.y = - tempEndPts(2).pos.y; tempEndPts(2).angle = 180.0 - tempEndPts(2).angle; BuildTrimedTitle( tempCustom, "\t", newTurnManufacturer, newTurnRightDesc, newTurnRightPartno ); @@ -2740,11 +2758,11 @@ static void NewTurnOk( void * context ) if ( customTurnout2 ) customTurnout2->segCnt = 0; to = CreateNewTurnout( newTurnScaleName, tempCustom, tempSegs_da.cnt, &tempSegs(0), - pathLen, pp->paths, tempEndPts_da.cnt, &tempEndPts(0), NULL, FALSE ); + pp->paths, tempEndPts_da.cnt, &tempEndPts(0), FALSE, options ); to->customInfo = customInfoP; #endif if (f) { - fprintf( f, "TURNOUT %s \"%s\"\n", newTurnScaleName, PutTitle(tempCustom) ); + fprintf( f, "TURNOUT %s \"%s\" %ld\n", newTurnScaleName, PutTitle(tempCustom), options ); #ifdef MKTURNOUT if (doCustomInfoLine) #endif @@ -2774,7 +2792,7 @@ static void NewTurnOk( void * context ) angles[4] = -angles[4]; angles[5] = -angles[5]; angles[6] = -angles[6]; - LoadSegs( curDesign, FALSE, &pathLen ); + LoadSegs( curDesign, FALSE ); tempEndPts(1).pos.y = - tempEndPts(1).pos.y; tempEndPts(1).angle = 180.0 - tempEndPts(1).angle; tempEndPts(2).pos.y = - tempEndPts(2).pos.y; @@ -2787,11 +2805,11 @@ static void NewTurnOk( void * context ) if ( customTurnout2 ) customTurnout2->segCnt = 0; to = CreateNewTurnout( newTurnScaleName, tempCustom, tempSegs_da.cnt, &tempSegs(0), - pathLen, pp->paths, tempEndPts_da.cnt, &tempEndPts(0), NULL, FALSE ); + pp->paths, tempEndPts_da.cnt, &tempEndPts(0), FALSE, options ); to->customInfo = customInfoP; #endif if (f) { - fprintf( f, "TURNOUT %s \"%s\"\n", newTurnScaleName, PutTitle(tempCustom) ); + fprintf( f, "TURNOUT %s \"%s\" %ld\n", newTurnScaleName, PutTitle(tempCustom), options ); #ifdef MKTURNOUT if (doCustomInfoLine) #endif @@ -2807,7 +2825,7 @@ static void NewTurnOk( void * context ) #ifndef MKTURNOUT if (f) fclose(f); - RestoreLocale(oldLocale); + SetUserLocale(); includeNontrackSegments = TRUE; wHide( newTurnW ); DoChangeNotification( CHANGE_PARAMS ); @@ -2826,17 +2844,17 @@ static void NewTurnCancel( wWin_p win ) -static wPos_t turnDesignWidth; -static wPos_t turnDesignHeight; +static wWinPix_t turnDesignWidth; +static wWinPix_t turnDesignHeight; static void TurnDesignLayout( paramData_t * pd, int index, - wPos_t colX, - wPos_t * w, - wPos_t * h ) + wWinPix_t colX, + wWinPix_t * w, + wWinPix_t * h ) { - wPos_t inx; + wIndex_t inx; if ( curDesign == NULL ) return; if ( index >= I_TO_FIRST_FLOAT && index <= I_TO_LAST_FLOAT ) { @@ -2856,18 +2874,18 @@ static void TurnDesignLayout( static void SetupTurnoutDesignerW( toDesignDesc_t * newDesign ) { - static wPos_t partnoWidth; + static wWinPix_t partnoWidth; int inx; - wPos_t w, h, ctlH; + wWinPix_t w, h, ctlH; if ( newTurnW == NULL ) { partnoWidth = wLabelWidth( "999-99999-9999" ); turnDesignPLs[I_TOLDESC+1].winData = turnDesignPLs[I_TORDESC+1].winData = - (void*)(intptr_t)partnoWidth; + I2VP(partnoWidth); partnoWidth += wLabelWidth( " # " ); newTurnW = ParamCreateDialog( &turnDesignPG, _("Turnout Designer"), _("Print"), NewTurnPrint, NewTurnCancel, TRUE, TurnDesignLayout, F_BLOCK, NULL ); - for ( inx=0; inx<(sizeof designDescs/sizeof designDescs[0]); inx++ ) { + for ( inx=0; inx<COUNT( designDescs ); inx++ ) { designDescs[inx]->lineC = wLineCreate( turnDesignPG.win, NULL, designDescs[inx]->lineCnt, designDescs[inx]->lines ); wControlShow( (wControl_p)designDescs[inx]->lineC, FALSE ); } @@ -2944,6 +2962,27 @@ static void SetupTurnoutDesignerW( toDesignDesc_t * newDesign ) w -= partnoWidth; wStringSetWidth( (wString_p)turnDesignPLs[I_TOLDESC].control, w ); wStringSetWidth( (wString_p)turnDesignPLs[I_TORDESC].control, w ); + if ( curDesign->type == NTO_CORNU || + curDesign->type == NTO_CORNUWYE || + curDesign->type == NTO_CORNU3WAY ) { + turnDesignPLs[I_TOOFFSET+0].winData = + turnDesignPLs[I_TOOFFSET+1].winData = + turnDesignPLs[I_TOOFFSET+2].winData = + turnDesignPLs[I_TOOFFSET+3].winData = &r_10000_10000; + turnDesignPLs[I_TOANGLE+0].winData = + turnDesignPLs[I_TOANGLE+1].winData = + turnDesignPLs[I_TOANGLE+2].winData = + turnDesignPLs[I_TOANGLE+3].winData = &r_90_90; + } else { + turnDesignPLs[I_TOOFFSET+0].winData = + turnDesignPLs[I_TOOFFSET+1].winData = + turnDesignPLs[I_TOOFFSET+2].winData = + turnDesignPLs[I_TOOFFSET+3].winData = &r0d001_10000; + turnDesignPLs[I_TOANGLE+0].winData = + turnDesignPLs[I_TOANGLE+1].winData = + turnDesignPLs[I_TOANGLE+2].winData = + turnDesignPLs[I_TOANGLE+3].winData = &r0d001_90; + } ParamLayoutDialog( &turnDesignPG ); } } @@ -2989,7 +3028,6 @@ EXPORT void EditCustomTurnout( turnoutInfo_t * to, turnoutInfo_t * to1 ) int i; toDesignDesc_t * dp; char * type, * name, *cp, *mfg, *descL, *partL, *descR, *partR; - wIndex_t pathLen; long rgb; trkSeg_p sp0, sp1; BOOL_T segsDiff; @@ -2997,13 +3035,13 @@ EXPORT void EditCustomTurnout( turnoutInfo_t * to, turnoutInfo_t * to1 ) if ( ! GetArgs( to->customInfo, "qqqqqc", &type, &name, &mfg, &descL, &partL, &cp ) ) return; - for ( i=0; i<(sizeof designDescs/sizeof designDescs[0]); i++ ) { + for ( i=0; i<COUNT( designDescs ); i++ ) { dp = designDescs[i]; if ( strcmp( type, dp->label ) == 0 ) { break; } } - if ( i >= (sizeof designDescs/sizeof designDescs[0]) ) + if ( i >= COUNT( designDescs ) ) return; SetupTurnoutDesignerW(dp); @@ -3054,7 +3092,7 @@ EXPORT void EditCustomTurnout( turnoutInfo_t * to, turnoutInfo_t * to1 ) segsDiff = FALSE; if ( to ) { - LoadSegs( dp, TRUE, &pathLen ); + LoadSegs( dp, TRUE ); segsDiff = FALSE; if ( to->segCnt == tempSegs_da.cnt ) { for ( sp0=to->segs,sp1=&tempSegs(0); (!segsDiff) && sp0<&to->segs[to->segCnt]; sp0++,sp1++ ) { @@ -3112,7 +3150,7 @@ EXPORT void EditCustomTurnout( turnoutInfo_t * to, turnoutInfo_t * to1 ) radii[0] = - radii[0]; radii[1] = - radii[1]; } - LoadSegs( dp, FALSE, &pathLen ); + LoadSegs( dp, FALSE ); if ( dp->type==NTO_REGULAR ) { points[2].y = - points[2].y; radii[0] = - radii[0]; @@ -3190,9 +3228,9 @@ EXPORT void InitNewTurn( wMenu_p m ) { int i; ParamRegister( &turnDesignPG ); - for ( i=0; i<(sizeof designDescs/sizeof designDescs[0]); i++ ) { + for ( i=0; i<COUNT( designDescs ); i++ ) { wMenuPushCreate( m, NULL, _(designDescs[i]->label), 0, - ShowTurnoutDesigner, (void*)designDescs[i] ); + ShowTurnoutDesigner, designDescs[i] ); sprintf( message, "%s SHOW %s", TURNOUTDESIGNER, designDescs[i]->label ); AddPlaybackProc( message, (playbackProc_p)ShowTurnoutDesigner, designDescs[i] ); } @@ -3204,10 +3242,6 @@ EXPORT void InitNewTurn( wMenu_p m ) #ifdef MKTURNOUT -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> - char message[STR_HUGE_SIZE]; char * curScaleName; double trackGauge; @@ -3216,7 +3250,7 @@ wDrawColor drawColorBlack; long roadbedColorRGB = 0; EXPORT void AbortProg( - char * msg, + const char * msg, ... ) { static BOOL_T abort2 = FALSE; @@ -3229,7 +3263,7 @@ EXPORT void AbortProg( abort(); } -void * MyRealloc( void * ptr, long size ) +void * MyRealloc( void * ptr, size_t size ) { return realloc( ptr, size ); } @@ -3243,7 +3277,7 @@ EXPORT char * MyStrdup( const char * str ) } -int NoticeMessage( char * msg, char * yes, char * no, ... ) +int NoticeMessage( const char * msg, const char * yes, const char * no, ... ) { /*fprintf( stderr, "%s\n", msg );*/ return 0; @@ -3284,9 +3318,9 @@ EXPORT void ComputeCurvedSeg( } } -EXPORT char * Strcpytrimed( char * dst, char * src, BOOL_T double_quotes ) +EXPORT char * Strcpytrimed( char * dst, const char * src, BOOL_T double_quotes ) { - char * cp; + const char * cp; while (*src && isspace((unsigned char)*src) ) src++; if (!*src) return dst; @@ -3302,7 +3336,7 @@ EXPORT char * Strcpytrimed( char * dst, char * src, BOOL_T double_quotes ) } -EXPORT char * BuildTrimedTitle( char * cp, char * sep, char * mfg, char * desc, char * partno ) +EXPORT char * BuildTrimedTitle( char * cp, const char * sep, const char * mfg, const char * desc, const char * partno ) { cp = Strcpytrimed( cp, mfg, FALSE ); strcpy( cp, sep ); @@ -3502,7 +3536,7 @@ int main ( int argc, char * argv[] ) newTurnScaleName = curScaleName = *argv++; trackGauge = 0.0; - for ( inx=0; inx<sizeof scaleMap/sizeof scaleMap[0]; inx++ ) { + for ( inx=0; inx<COUNT( scaleMap ); inx++ ) { if (strcmp( curScaleName, scaleMap[inx].scale ) == 0 ) { newTurnTrackGauge = trackGauge = scaleMap[inx].trackGauge; break; |