From 5d2c2b27a6323e2666378b986129b2a7c2c39e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 6 Feb 2022 16:04:24 +0100 Subject: New upstream version 5.2.2GA --- app/bin/chndldto.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'app/bin/chndldto.c') diff --git a/app/bin/chndldto.c b/app/bin/chndldto.c index a0f2d6b..abb6e32 100644 --- a/app/bin/chndldto.c +++ b/app/bin/chndldto.c @@ -21,17 +21,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include - #include "ccurve.h" #include "cjoin.h" #include "compound.h" #include "cstraigh.h" #include "cundo.h" -#include "i18n.h" -#include "messages.h" #include "track.h" -#include "utility.h" +#include "draw.h" +#include "common-ui.h" #define PTRACE(X) @@ -351,9 +348,9 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) } -#include "bitmaps/hndldto.xpm" +#include "bitmaps/turnout-designer.xpm" EXPORT void InitCmdHandLaidTurnout( wMenu_p menu ) { - AddMenuButton( menu, CmdHandLaidTurnout, "cmdHandLaidTurnout", _("HandLaidTurnout"), wIconCreatePixMap(hndldto_xpm), LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY|IC_POPUP2, ACCL_HNDLDTO, NULL ); + AddMenuButton( menu, CmdHandLaidTurnout, "cmdHandLaidTurnout", _("HandLaidTurnout"), wIconCreatePixMap(turnout_designer_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY|IC_POPUP2, ACCL_HNDLDTO, NULL ); } -- cgit v1.2.3 From a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 3 Jul 2024 10:19:30 +0200 Subject: New upstream version 5.3.0GA --- app/bin/chndldto.c | 155 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 64 deletions(-) (limited to 'app/bin/chndldto.c') diff --git a/app/bin/chndldto.c b/app/bin/chndldto.c index abb6e32..fb7c05f 100644 --- a/app/bin/chndldto.c +++ b/app/bin/chndldto.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "ccurve.h" @@ -36,17 +36,17 @@ * STATE INFO */ static struct { - STATE_T state; - coOrd normalP; - ANGLE_T normalA; - track_p normalT; - coOrd reverseP; - coOrd reverseP1; - ANGLE_T reverseA; - DIST_T frogNo; - ANGLE_T frogA; - curveData_t curveData; - } Dhlt; + STATE_T state; + coOrd normalP; + ANGLE_T normalA; + track_p normalT; + coOrd reverseP; + coOrd reverseP1; + ANGLE_T reverseA; + DIST_T frogNo; + ANGLE_T frogA; + curveData_t curveData; +} Dhlt; static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) @@ -55,7 +55,8 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) EPINX_T ep, ep1, ep2, ep2a=-1, ep2b=-1, pointEp0, pointEp1; DIST_T dist, reverseD, pointD; coOrd off, intersectP; - coOrd pointP, pointC, pointP1, reverseC, point0; + coOrd pointP, pointP1, reverseC, point0; +// coOrd pointC; track_p trk, trk1, trk2, trk2a=NULL, trk2b=NULL, pointT; trkSeg_p segP; BOOL_T right; @@ -68,18 +69,18 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) DYNARR_SET( trkSeg_t, tempSegs_da, 1 ); Dhlt.state = 0; Dhlt.normalT = NULL; - tempSegs_da.cnt = 0; DYNARR_SET( trkSeg_t, tempSegs_da, 2 ); tempSegs(0).color = drawColorBlack; - tempSegs(0).width = 0; + tempSegs(0).lineWidth = 0; tempSegs(1).color = drawColorBlack; - tempSegs(1).width = 0; + tempSegs(1).lineWidth = 0; return C_CONTINUE; case C_DOWN: if (Dhlt.state == 0) { - if ((Dhlt.normalT = OnTrack( &pos, TRUE, TRUE )) == NULL) + if ((Dhlt.normalT = OnTrack( &pos, TRUE, TRUE )) == NULL) { break; + } if ( QueryTrack( Dhlt.normalT, Q_NOT_PLACE_FROGPOINTS ) ) { ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("frog") ); Dhlt.normalT = NULL; @@ -89,19 +90,20 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) Dhlt.normalA = GetAngleAtPoint( Dhlt.normalT, Dhlt.normalP, NULL, NULL ); InfoMessage( _("Drag to set angle") ); Dhlt.state = 1; - pointC = pointP = pointP1 = reverseC = zero; +// pointC = pointP = pointP1 = reverseC = zero; return C_CONTINUE; } case C_MOVE: case C_UP: - if (Dhlt.normalT == NULL) + if (Dhlt.normalT == NULL) { break; + } if (Dhlt.state == 1) { Dhlt.reverseP1 = pos; Dhlt.reverseA = FindAngle( Dhlt.reverseP, Dhlt.reverseP1 ); Dhlt.frogA = NormalizeAngle( Dhlt.reverseA - Dhlt.normalA ); -/*printf( "RA=%0.3f FA=%0.3f ", Dhlt.reverseA, Dhlt.frogA );*/ + /*printf( "RA=%0.3f FA=%0.3f ", Dhlt.reverseA, Dhlt.frogA );*/ if (Dhlt.frogA > 270.0) { Dhlt.frogA = 360.0-Dhlt.frogA; right = FALSE; @@ -118,12 +120,13 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) } else { right = TRUE; } -/*printf( "NA=%0.3f FA=%0.3f R=%d\n", Dhlt.normalA, Dhlt.frogA, right );*/ + /*printf( "NA=%0.3f FA=%0.3f R=%d\n", Dhlt.normalA, Dhlt.frogA, right );*/ Dhlt.frogNo = tan(D2R(Dhlt.frogA)); - if (Dhlt.frogNo > 0.01) + if (Dhlt.frogNo > 0.01) { Dhlt.frogNo = 1.0/Dhlt.frogNo; - else + } else { Dhlt.frogNo = 0.0; + } if (action == C_MOVE) { if (Dhlt.frogNo != 0) { InfoMessage( _("Angle = %0.2f Frog# = %0.2f"), Dhlt.frogA, Dhlt.frogNo ); @@ -133,15 +136,18 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) } else { InfoMessage( _("Select point position") ); Dhlt.state = 2; - Translate( &Dhlt.reverseP, Dhlt.reverseP, Dhlt.normalA+(right?+90:-90), trackGauge ); - Translate( &Dhlt.reverseP1, Dhlt.reverseP1, Dhlt.normalA+(right?+90:-90), trackGauge ); + Translate( &Dhlt.reverseP, Dhlt.reverseP, Dhlt.normalA+(right?+90:-90), + trackGauge ); + Translate( &Dhlt.reverseP1, Dhlt.reverseP1, Dhlt.normalA+(right?+90:-90), + trackGauge ); } return C_CONTINUE; } else if ( Dhlt.state == 2 ) { - tempSegs_da.cnt = 0; + DYNARR_RESET( trkSeg_t, tempSegs_da ); pointP = pos; - if ((pointT = OnTrack( &pointP, TRUE, TRUE )) == NULL) + if ((pointT = OnTrack( &pointP, TRUE, TRUE )) == NULL) { break; + } if ( QueryTrack( pointT, Q_NOT_PLACE_FROGPOINTS ) ) { ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("points") ); break; @@ -149,11 +155,11 @@ static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) dist = FindDistance( Dhlt.normalP, pointP ); pointA = GetAngleAtPoint( pointT, pointP, &pointEp0, &pointEp1 ); angle = NormalizeAngle( pointA + 180.0 - Dhlt.reverseA ); -PTRACE(( "rA=%0.1f pA=%0.1f a=%0.1f ", Dhlt.reverseA, pointA, angle )) + PTRACE(( "rA=%0.1f pA=%0.1f a=%0.1f ", Dhlt.reverseA, pointA, angle )) if ( angle > 90.0 && angle < 270.0 ) { pointA = NormalizeAngle( pointA + 180.0 ); angle = NormalizeAngle( angle + 180.0 ); -PTRACE(( " {pA=%0.1f a=%0.1f} ", pointA, angle )) + PTRACE(( " {pA=%0.1f a=%0.1f} ", pointA, angle )) } else { ep = pointEp0; pointEp0 = pointEp1; pointEp1 = ep; } @@ -163,10 +169,11 @@ PTRACE(( " {pA=%0.1f a=%0.1f} ", pointA, angle )) } else { right = FALSE; } -PTRACE(( "r=%c a=%0.1f ", right?'T':'F', angle )) + PTRACE(( "r=%c a=%0.1f ", right?'T':'F', angle )) Translate( &off, pointP, pointA+180.0, trackGauge*2.0 ); - if ((trk = OnTrack( &off, TRUE, TRUE )) == NULL) + if ((trk = OnTrack( &off, TRUE, TRUE )) == NULL) { break; + } if ( QueryTrack( trk, Q_NOT_PLACE_FROGPOINTS ) ) { ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("points") ); break; @@ -175,23 +182,25 @@ PTRACE(( "r=%c a=%0.1f ", right?'T':'F', angle )) Rotate( &off, Dhlt.reverseP, 180-Dhlt.reverseA ); off.x -= Dhlt.reverseP.x; off.y -= Dhlt.reverseP.y; - if (right) + if (right) { off.x = -off.x; -PTRACE(( "off=[%0.3f %0.3f] ", off.x, off.y )) + } + PTRACE(( "off=[%0.3f %0.3f] ", off.x, off.y )) if (off.y < 0) { ErrorMessage( MSG_MOVE_POINTS_OTHER_SIDE ); -PTRACE(("\n")) + PTRACE(("\n")) break; } if (off.x < 0) { ErrorMessage( MSG_MOVE_POINTS_AWAY_CLOSE ); -PTRACE(("\n")) + PTRACE(("\n")) break; } angle2 = FindAngle( zero, off ); -PTRACE(( "a2=%0.1f\n", angle2 )) + PTRACE(( "a2=%0.1f\n", angle2 )) if (angle < 0.5) { if ( off.x < connectDistance ) { + DYNARR_SET( trkSeg_t, tempSegs_da, 2 ); tempSegs(0).type = SEG_STRTRK; tempSegs(0).color = wDrawColorBlack; tempSegs(0).u.l.pos[0] = pointP; @@ -200,23 +209,25 @@ PTRACE(( "a2=%0.1f\n", angle2 )) tempSegs(1).color = wDrawColorBlack; tempSegs(1).u.l.pos[0] = Dhlt.reverseP; Translate( &tempSegs(1).u.l.pos[1], Dhlt.reverseP, Dhlt.reverseA, trackGauge ); - tempSegs_da.cnt = 2; } else { - ErrorMessage( MSG_MOVE_POINTS_AWAY_NO_INTERSECTION ); - break; + ErrorMessage( MSG_MOVE_POINTS_AWAY_NO_INTERSECTION ); + break; } } else if (angle < angle2) { ErrorMessage( MSG_MOVE_POINTS_AWAY_NO_INTERSECTION ); break; } else { - if (!FindIntersection( &intersectP, Dhlt.reverseP, Dhlt.reverseA+180.0, pointP, pointA+180.0 )) + if (!FindIntersection( &intersectP, Dhlt.reverseP, Dhlt.reverseA+180.0, pointP, + pointA+180.0 )) { break; + } reverseD = FindDistance( Dhlt.reverseP, intersectP ); pointD = FindDistance( pointP, intersectP ); if (reverseD > pointD) { reverseR = pointD/tan(D2R(angle/2.0)); Translate( &reverseC, pointP, pointA+(right?-90:+90), reverseR ); -PTRACE(( "rR=%0.3f rC=[%0.3f %0.3f]\n", reverseR, reverseC.x, reverseC.y )) + PTRACE(( "rR=%0.3f rC=[%0.3f %0.3f]\n", reverseR, reverseC.x, reverseC.y )) + DYNARR_SET( trkSeg_t, tempSegs_da, 3 ); tempSegs(0).type = SEG_CRVTRK; tempSegs(0).color = wDrawColorBlack; tempSegs(0).u.c.center = reverseC; @@ -225,13 +236,13 @@ PTRACE(( "rR=%0.3f rC=[%0.3f %0.3f]\n", reverseR, reverseC.x, reverseC.y )) tempSegs(0).u.c.a1 = angle; tempSegs(1).type = SEG_STRTRK; tempSegs(1).color = wDrawColorBlack; - PointOnCircle( &tempSegs(1).u.l.pos[0], reverseC, reverseR, tempSegs(0).u.c.a0 + (right?angle:0.0) ); + PointOnCircle( &tempSegs(1).u.l.pos[0], reverseC, reverseR, + tempSegs(0).u.c.a0 + (right?angle:0.0) ); tempSegs(1).u.l.pos[1] = Dhlt.reverseP; tempSegs(2).type = SEG_STRTRK; tempSegs(2).color = wDrawColorBlack; tempSegs(2).u.l.pos[0] = Dhlt.reverseP; Translate( &tempSegs(2).u.l.pos[1], Dhlt.reverseP, Dhlt.reverseA, trackGauge ); - tempSegs_da.cnt = 3; } else { reverseR = reverseD/tan(D2R(angle/2.0)); reverseR *= sqrt(reverseD/pointD); @@ -240,17 +251,21 @@ PTRACE(( "rR=%0.3f rC=[%0.3f %0.3f]\n", reverseR, reverseC.x, reverseC.y )) dist = FindDistance( reverseC, pointP ); angle2 = R2D( asin( reverseR/dist ) ); angle3 = FindAngle( pointP, reverseC ); - if (right) + if (right) { angle2 = NormalizeAngle(angle3 - pointA+180) - angle2; - else + } else { angle2 = NormalizeAngle(pointA+180 - angle3) - angle2; + } reverseA1 = angle-angle2; -PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) + PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) + DYNARR_SET( trkSeg_t, tempSegs_da, 3 ); tempSegs(0).type = SEG_STRTRK; tempSegs(0).color = wDrawColorBlack; tempSegs(0).u.l.pos[0] = pointP; - tempSegs(1).u.c.a0 = NormalizeAngle(Dhlt.reverseA + (right?(-90.0-reverseA1):+90.0)); - PointOnCircle( &tempSegs(0).u.l.pos[1], reverseC, reverseR, tempSegs(1).u.c.a0 + (right?0.0:reverseA1) ); + tempSegs(1).u.c.a0 = NormalizeAngle(Dhlt.reverseA + (right? + (-90.0-reverseA1):+90.0)); + PointOnCircle( &tempSegs(0).u.l.pos[1], reverseC, reverseR, + tempSegs(1).u.c.a0 + (right?0.0:reverseA1) ); tempSegs(1).type = SEG_CRVTRK; tempSegs(1).color = wDrawColorBlack; tempSegs(1).u.c.center = reverseC; @@ -260,26 +275,29 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) tempSegs(2).color = wDrawColorBlack; tempSegs(2).u.l.pos[0] = Dhlt.reverseP; Translate( &tempSegs(2).u.l.pos[1], Dhlt.reverseP, Dhlt.reverseA, trackGauge ); - tempSegs_da.cnt = 3; } } if (action != C_UP) { dist = FindDistance( pointP, Dhlt.normalP ); - InfoMessage( _("Length = %0.2f Angle = %0.2f Frog# = %0.2f"), dist, Dhlt.frogA, Dhlt.frogNo ); + InfoMessage( _("Length = %0.2f Angle = %0.2f Frog# = %0.2f"), dist, Dhlt.frogA, + Dhlt.frogNo ); return C_CONTINUE; } - UndoStart( _("Create Hand Laid Turnout"), "Hndldto( T%d[%d] )", GetTrkIndex(pointT), pointEp0 ); + UndoStart( _("Create Hand Laid Turnout"), "Hndldto( T%d[%d] )", + GetTrkIndex(pointT), pointEp0 ); UndoModify( pointT ); - if (!SplitTrack( pointT, pointP, pointEp0, &trk1, TRUE )) + if (!SplitTrack( pointT, pointP, pointEp0, &trk1, TRUE )) { break; + } dist = trackGauge*2.0; if ( !trk1 ) { trk1 = pointT; pointT = NULL; } ep1 = PickEndPoint( pointP, trk1 ); - if (!RemoveTrack( &trk1, &ep1, &dist )) + if (!RemoveTrack( &trk1, &ep1, &dist )) { break; + } point0 = GetTrkEndPos( trk1, ep1 ); angle0 = NormalizeAngle(GetTrkEndAngle(trk1,ep1)+180.0); trk2 = NULL; @@ -291,7 +309,8 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) ep2b = 0; break; case SEG_CRVTRK: - trk2b = NewCurvedTrack( segP->u.c.center, fabs(segP->u.c.radius), segP->u.c.a0, segP->u.c.a1, 0 ); + trk2b = NewCurvedTrack( segP->u.c.center, fabs(segP->u.c.radius), segP->u.c.a0, + segP->u.c.a1, 0 ); ep2b = (right?0:1); } if (trk2 == NULL) { @@ -305,11 +324,13 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) } *trkpp = NULL; dist = trackGauge*2.0; - if (!RemoveTrack( &trk2, &ep2, &dist )) + if (!RemoveTrack( &trk2, &ep2, &dist )) { break; + } trk = NewHandLaidTurnout( pointP, pointA, - point0, angle0, - GetTrkEndPos(trk2,ep2), NormalizeAngle(GetTrkEndAngle(trk2,ep2)+180.0), Dhlt.frogA ); + point0, angle0, + GetTrkEndPos(trk2,ep2), NormalizeAngle(GetTrkEndAngle(trk2,ep2)+180.0), + Dhlt.frogA ); DrawEndPt( &mainD, trk1, ep1, wDrawColorWhite ); if ( pointT ) { DrawEndPt( &mainD, pointT, pointEp0, wDrawColorWhite ); @@ -324,18 +345,22 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) DrawTrack( pointT, &mainD, wDrawColorBlack ); } DrawTrack( trk, &mainD, wDrawColorBlack ); - for (trkpp=trks; *trkpp; trkpp++) + for (trkpp=trks; *trkpp; trkpp++) { DrawTrack( *trkpp, &mainD, wDrawColorBlack ); - + } + Dhlt.state = 0; return C_TERMINATE; } case C_REDRAW: - if (Dhlt.state >= 1) + if (Dhlt.state >= 1) { DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack ); - if (Dhlt.state >= 2) - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); + } + if (Dhlt.state >= 2) { + DrawSegsDA( &tempD, NULL, zero, 0.0, &tempSegs_da, trackGauge, wDrawColorBlack, + 0 ); + } return C_CONTINUE; case C_CANCEL: @@ -348,9 +373,11 @@ PTRACE(( " a2=%0.1f rA1=%0.1f\n", angle2, reverseA1 )) } -#include "bitmaps/turnout-designer.xpm" +#include "bitmaps/turnout-design.xpm3" EXPORT void InitCmdHandLaidTurnout( wMenu_p menu ) { - AddMenuButton( menu, CmdHandLaidTurnout, "cmdHandLaidTurnout", _("HandLaidTurnout"), wIconCreatePixMap(turnout_designer_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY|IC_POPUP2, ACCL_HNDLDTO, NULL ); + AddMenuButton( menu, CmdHandLaidTurnout, "cmdHandLaidTurnout", + _("HandLaidTurnout"), wIconCreatePixMap(turnout_design_xpm3[iconSize]), + LEVEL0_50, IC_STICKY|IC_INITNOTSTICKY|IC_POPUP2, ACCL_HNDLDTO, NULL ); } -- cgit v1.2.3