summaryrefslogtreecommitdiff
path: root/app/bin/csplit.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
commitb55285a77da0e0b829e4ce8d7e09debaabc68e15 (patch)
treef622559ef65bbdd3e1c5bdb06098a8f89eec0563 /app/bin/csplit.c
parentd3897ce090dbeb220ed2c782f095597e417cf3cc (diff)
parentd1ae75703e1ed81d65ea16946dcdb77e7a13adc9 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'app/bin/csplit.c')
-rw-r--r--app/bin/csplit.c89
1 files changed, 83 insertions, 6 deletions
diff --git a/app/bin/csplit.c b/app/bin/csplit.c
index 6cfdcc8..c2b516a 100644
--- a/app/bin/csplit.c
+++ b/app/bin/csplit.c
@@ -21,16 +21,20 @@
*/
#include "cundo.h"
+#include "compound.h"
#include "i18n.h"
#include "messages.h"
#include "track.h"
#include "utility.h"
+#include "fileio.h"
static wMenu_p splitPopupM[2];
static wMenuToggle_p splitPopupMI[2][4];
static track_p splitTrkTrk[2];
static EPINX_T splitTrkEP[2];
static BOOL_T splitTrkFlip;
+static dynArr_t anchors_da;
+#define anchors(N) DYNARR_N(trkSeg_t,anchors_da,N)
static void ChangeSplitEPMode( wBool_t set, void * mode )
{
@@ -55,6 +59,45 @@ static void ChangeSplitEPMode( wBool_t set, void * mode )
DrawEndPt( &mainD, splitTrkTrk[1], splitTrkEP[1], wDrawColorBlack );
}
+static void CreateSplitAnchorAngle(coOrd pos, track_p t, BOOL_T end, ANGLE_T a) {
+ DIST_T d = tempD.scale*0.1;
+ DIST_T w = tempD.scale/tempD.dpi*4;
+ int i;
+ if (!end) {
+ DYNARR_APPEND(trkSeg_t,anchors_da,1);
+ i = anchors_da.cnt-1;
+ anchors(i).type = SEG_STRLIN;
+ anchors(i).color = wDrawColorBlue;
+ Translate(&anchors(i).u.l.pos[0],pos,a,GetTrkGauge(t));
+ Translate(&anchors(i).u.l.pos[1],pos,a,-GetTrkGauge(t));
+ anchors(i).width = w;
+ } else {
+ DYNARR_APPEND(trkSeg_t,anchors_da,1);
+ i = anchors_da.cnt-1;
+ anchors(i).type = SEG_STRLIN;
+ anchors(i).color = wDrawColorBlue;
+ Translate(&anchors(i).u.l.pos[0],pos,a,GetTrkGauge(t));
+ Translate(&anchors(i).u.l.pos[0],anchors(i).u.l.pos[0],a+90,d);
+ Translate(&anchors(i).u.l.pos[1],pos,a,-GetTrkGauge(t));
+ Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a+90,-d);
+ anchors(i).width = w;
+ DYNARR_APPEND(trkSeg_t,anchors_da,1);
+ i = anchors_da.cnt-1;
+ anchors(i).type = SEG_STRLIN;
+ anchors(i).color = wDrawColorBlue;
+ Translate(&anchors(i).u.l.pos[0],pos,a,GetTrkGauge(t));
+ Translate(&anchors(i).u.l.pos[0],anchors(i).u.l.pos[0],a+90,-d);
+ Translate(&anchors(i).u.l.pos[1],pos,a,-GetTrkGauge(t));
+ Translate(&anchors(i).u.l.pos[1],anchors(i).u.l.pos[1],a+90,d);
+ anchors(i).width = w;
+ }
+}
+
+static void CreateSplitAnchor(coOrd pos, track_p t, BOOL_T end) {
+ ANGLE_T a = NormalizeAngle(GetAngleAtPoint(t,pos,NULL,NULL)+90.0);
+ CreateSplitAnchorAngle(pos,t,end,a);
+}
+
static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
{
track_p trk0, trk1;
@@ -66,6 +109,7 @@ static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
switch (action) {
case C_START:
InfoMessage( _("Select track to split") );
+ DYNARR_RESET(trkSeg_t,anchors_da);
/* no break */
case C_DOWN:
case C_MOVE:
@@ -79,12 +123,16 @@ static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
onTrackInSplit = FALSE;
return C_TERMINATE;
}
- if (!QueryTrack(trk0,Q_MODIFY_CAN_SPLIT)) {
- onTrackInSplit = FALSE;
- InfoMessage(_("Can't Split that Track"));
- return C_CONTINUE;
- }
ep0 = PickEndPoint( pos, trk0 );
+ if (IsClose(FindDistance(GetTrkEndPos(trk0,ep0),pos)) && (GetTrkEndTrk(trk0,ep0)!=NULL)) {
+ pos = GetTrkEndPos(trk0,ep0);
+ } else {
+ if (!QueryTrack(trk0,Q_MODIFY_CAN_SPLIT)) {
+ onTrackInSplit = FALSE;
+ InfoMessage(_("Can't Split that Track"));
+ return C_CONTINUE;
+ }
+ }
onTrackInSplit = FALSE;
if (ep0 < 0) {
return C_CONTINUE;
@@ -139,9 +187,38 @@ static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
mode |= 1;
for ( inx=0; inx<4; inx++ )
wMenuToggleSet( splitPopupMI[quad&1][inx], mode == inx );
+ menuPos = pos;
wMenuPopupShow( splitPopupM[quad&1] );
break;
+ case wActionMove:
+ DYNARR_RESET(trkSeg_t,anchors_da);
+ onTrackInSplit = TRUE;
+ if ((trk0 = OnTrack( &pos, FALSE, TRUE ))!=NULL && CheckTrackLayerSilent( trk0 )) {
+ ep0 = PickEndPoint( pos, trk0 );
+ if (IsClose(FindDistance(GetTrkEndPos(trk0,ep0),pos)) && (GetTrkEndTrk(trk0,ep0)!=NULL)) {
+ CreateSplitAnchor(GetTrkEndPos(trk0,ep0),trk0,TRUE);
+ } else if (QueryTrack(trk0,Q_IS_TURNOUT)) {
+ if ((MyGetKeyState()&WKEY_SHIFT) != 0 ) {
+ if (SplitTurnoutCheck(trk0,pos,ep0,NULL,NULL,NULL,TRUE,&pos,&angle)) {
+ angle = NormalizeAngle(angle+90);
+ CreateSplitAnchorAngle(pos,trk0,FALSE,angle);
+ }
+ } else {
+ CreateSplitAnchor(GetTrkEndPos(trk0,ep0),trk0,TRUE);
+ }
+ break;
+ } else if (QueryTrack(trk0,Q_MODIFY_CAN_SPLIT)) {
+ CreateSplitAnchor(pos,trk0,FALSE);
+ }
+ }
+ onTrackInSplit = FALSE;
+ break;
+ case C_REDRAW:
+ if (anchors_da.cnt)
+ DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack );
+ break;
}
+
return C_CONTINUE;
}
@@ -152,6 +229,6 @@ static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
void InitCmdSplit( wMenu_p menu )
{
- AddMenuButton( menu, CmdSplitTrack, "cmdSplitTrack", _("Split Track"), wIconCreatePixMap(splittrk_xpm), LEVEL0_50, IC_STICKY|IC_POPUP|IC_CMDMENU, ACCL_SPLIT, NULL );
+ AddMenuButton( menu, CmdSplitTrack, "cmdSplitTrack", _("Split Track"), wIconCreatePixMap(splittrk_xpm), LEVEL0_50, IC_STICKY|IC_POPUP|IC_CMDMENU|IC_WANT_MOVE, ACCL_SPLIT, NULL );
}