From d1a8285f818eb7e5c3d6a05709ea21a808490b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 19 Mar 2018 19:55:58 +0100 Subject: New upstream version 5.1.0 --- app/bin/cstraigh.c | 80 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 13 deletions(-) (limited to 'app/bin/cstraigh.c') diff --git a/app/bin/cstraigh.c b/app/bin/cstraigh.c index 6038c9a..7be25ee 100644 --- a/app/bin/cstraigh.c +++ b/app/bin/cstraigh.c @@ -1,5 +1,5 @@ -/* - * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/cstraigh.c,v 1.4 2008-03-06 19:35:06 m_fischer Exp $ +/** \file cstraigh.c + * STRAIGHT */ /* XTrkCad - Model Railroad CAD @@ -19,22 +19,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include -#include "track.h" #include "cstraigh.h" +#include "cundo.h" +#include "fileio.h" #include "i18n.h" - -/******************************************************************************* - * - * STRAIGHT - * - */ +#include "messages.h" +#include "param.h" +#include "track.h" +#include "utility.h" /* * STATE INFO */ static struct { coOrd pos0, pos1; + track_p trk; + EPINX_T ep; + BOOL_T down; } Dl; @@ -42,15 +45,46 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) { track_p t; DIST_T dist; + coOrd p; switch (action) { case C_START: - InfoMessage( _("Place 1st end point of Straight track") ); + Dl.pos0=pos; + Dl.pos1=pos; + Dl.trk = NULL; + Dl.ep=-1; + Dl.down = FALSE; + InfoMessage( _("Place 1st end point of straight track + Shift -> snap to unconnected endpoint") ); return C_CONTINUE; case C_DOWN: - SnapPos( &pos ); + p = pos; + BOOL_T found = FALSE; + Dl.trk = NULL; + if ((MyGetKeyState() & WKEY_SHIFT) != 0) { + if ((t = OnTrack(&p, FALSE, TRUE)) != NULL) { + EPINX_T ep = PickUnconnectedEndPointSilent(p, t); + if (ep != -1) { + Dl.trk = t; + Dl.ep = ep; + pos = GetTrkEndPos(t, ep); + found = TRUE; + } else { + InfoMessage(_("No unconnected end-point on track - Try again or release Shift and click")); + Dl.pos0=pos; + Dl.pos1=pos; + return C_CONTINUE; + } + } else { + InfoMessage(_("Not on a track - Try again or release Shift and click")); + Dl.pos0=pos; + Dl.pos1=pos; + return C_CONTINUE; + } + } + Dl.down = TRUE; + if (!found) SnapPos( &pos ); Dl.pos0 = pos; InfoMessage( _("Drag to place 2nd end point") ); DYNARR_SET( trkSeg_t, tempSegs_da, 1 ); @@ -62,8 +96,17 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) return C_CONTINUE; case C_MOVE: + if (!Dl.down) return C_CONTINUE; DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); - SnapPos( &pos ); + ANGLE_T angle, angle2; + if (Dl.trk) { + angle = NormalizeAngle(GetTrkEndAngle( Dl.trk, Dl.ep)); + angle2 = NormalizeAngle(FindAngle(pos, Dl.pos0)-angle); + if (angle2 > 90.0 && angle2 < 270.0) + Translate( &pos, Dl.pos0, angle, FindDistance( Dl.pos0, pos ) ); + else pos = Dl.pos0; + } else SnapPos( &pos ); + InfoMessage( _("Straight Track Length=%s Angle=%0.3f"), FormatDistance(FindDistance( Dl.pos0, pos )), PutAngle(FindAngle( Dl.pos0, pos )) ); @@ -73,15 +116,25 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) return C_CONTINUE; case C_UP: + if (!Dl.down) return C_CONTINUE; DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); tempSegs_da.cnt = 0; - SnapPos( &pos ); + if (Dl.trk) { + angle = NormalizeAngle(GetTrkEndAngle( Dl.trk, Dl.ep)); + angle2 = NormalizeAngle(FindAngle(pos, Dl.pos0)-angle); + if (angle2 > 90.0 && angle2 < 270.0) + Translate( &pos, Dl.pos0, angle, FindDistance( Dl.pos0, pos )); + else pos = Dl.pos0; + } else SnapPos( &pos ); if ((dist=FindDistance( Dl.pos0, pos )) <= minLength) { ErrorMessage( MSG_TRK_TOO_SHORT, "Straight ", PutDim(fabs(minLength-dist)) ); return C_TERMINATE; } UndoStart( _("Create Straight Track"), "newStraight" ); t = NewStraightTrack( Dl.pos0, pos ); + if (Dl.trk) { + ConnectTracks(Dl.trk, Dl.ep, t, 0); + } UndoEnd(); DrawNewTrack(t); return C_TERMINATE; @@ -89,6 +142,7 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) case C_REDRAW: case C_CANCEL: DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); + Dl.down = FALSE; return C_CONTINUE; default: -- cgit v1.2.3