1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/** \file csplit.c
* SPLIT
*/
/* XTrkCad - Model Railroad CAD
* Copyright (C) 2005 Dave Bullis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
#include "cundo.h"
#include "i18n.h"
#include "messages.h"
#include "track.h"
#include "utility.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 void ChangeSplitEPMode( wBool_t set, void * mode )
{
long imode = (long)mode;
long option;
int inx0, inx;
UndoStart( _("Set Block Gaps"), "Set Block Gaps" );
DrawEndPt( &mainD, splitTrkTrk[0], splitTrkEP[0], wDrawColorWhite );
DrawEndPt( &mainD, splitTrkTrk[1], splitTrkEP[1], wDrawColorWhite );
for ( inx0=0; inx0<2; inx0++ ) {
inx = splitTrkFlip?1-inx0:inx0;
UndoModify( splitTrkTrk[inx] );
option = GetTrkEndOption( splitTrkTrk[inx], splitTrkEP[inx] );
option &= ~EPOPT_GAPPED;
if ( (imode&1) != 0 )
option |= EPOPT_GAPPED;
SetTrkEndOption( splitTrkTrk[inx], splitTrkEP[inx], option );
imode >>= 1;
}
DrawEndPt( &mainD, splitTrkTrk[0], splitTrkEP[0], wDrawColorBlack );
DrawEndPt( &mainD, splitTrkTrk[1], splitTrkEP[1], wDrawColorBlack );
}
static STATUS_T CmdSplitTrack( wAction_t action, coOrd pos )
{
track_p trk0, trk1;
EPINX_T ep0;
int oldTrackCount;
int inx, mode, quad;
ANGLE_T angle;
switch (action) {
case C_START:
InfoMessage( _("Select track to split") );
/* no break */
case C_DOWN:
case C_MOVE:
return C_CONTINUE;
break;
case C_UP:
onTrackInSplit = TRUE;
trk0 = OnTrack( &pos, TRUE, TRUE );
if ( trk0 != NULL) {
if (!CheckTrackLayer( trk0 ) ) {
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 );
onTrackInSplit = FALSE;
if (ep0 < 0) {
return C_CONTINUE;
}
UndoStart( _("Split Track"), "SplitTrack( T%d[%d] )", GetTrkIndex(trk0), ep0 );
oldTrackCount = trackCount;
SplitTrack( trk0, pos, ep0, &trk1, FALSE );
UndoEnd();
return C_TERMINATE;
}
onTrackInSplit = FALSE;
return C_TERMINATE;
break;
case C_CMDMENU:
splitTrkTrk[0] = OnTrack( &pos, TRUE, TRUE );
if ( splitTrkTrk[0] == NULL )
return C_CONTINUE;
if ( splitPopupM[0] == NULL ) {
splitPopupM[0] = MenuRegister( "End Point Mode R-L" );
splitPopupMI[0][0] = wMenuToggleCreate( splitPopupM[0], "", _("None"), 0, TRUE, ChangeSplitEPMode, (void*)0 );
splitPopupMI[0][1] = wMenuToggleCreate( splitPopupM[0], "", _("Left"), 0, FALSE, ChangeSplitEPMode, (void*)1 );
splitPopupMI[0][2] = wMenuToggleCreate( splitPopupM[0], "", _("Right"), 0, FALSE, ChangeSplitEPMode, (void*)2 );
splitPopupMI[0][3] = wMenuToggleCreate( splitPopupM[0], "", _("Both"), 0, FALSE, ChangeSplitEPMode, (void*)3 );
splitPopupM[1] = MenuRegister( "End Point Mode T-B" );
splitPopupMI[1][0] = wMenuToggleCreate( splitPopupM[1], "", _("None"), 0, TRUE, ChangeSplitEPMode, (void*)0 );
splitPopupMI[1][1] = wMenuToggleCreate( splitPopupM[1], "", _("Top"), 0, FALSE, ChangeSplitEPMode, (void*)1 );
splitPopupMI[1][2] = wMenuToggleCreate( splitPopupM[1], "", _("Bottom"), 0, FALSE, ChangeSplitEPMode, (void*)2 );
splitPopupMI[1][3] = wMenuToggleCreate( splitPopupM[1], "", _("Both"), 0, FALSE, ChangeSplitEPMode, (void*)3 );
}
splitTrkEP[0] = PickEndPoint( pos, splitTrkTrk[0] );
angle = NormalizeAngle(GetTrkEndAngle( splitTrkTrk[0], splitTrkEP[0] ));
if ( angle <= 45.0 )
quad = 0;
else if ( angle <= 135.0 )
quad = 1;
else if ( angle <= 225.0 )
quad = 2;
else if ( angle <= 315.0 )
quad = 3;
else
quad = 0;
splitTrkFlip = (quad<2);
if ( (splitTrkTrk[1] = GetTrkEndTrk( splitTrkTrk[0], splitTrkEP[0] ) ) == NULL ) {
ErrorMessage( MSG_BAD_BLOCKGAP );
return C_CONTINUE;
}
splitTrkEP[1] = GetEndPtConnectedToMe( splitTrkTrk[1], splitTrkTrk[0] );
mode = 0;
if ( GetTrkEndOption( splitTrkTrk[1-splitTrkFlip], splitTrkEP[1-splitTrkFlip] ) & EPOPT_GAPPED )
mode |= 2;
if ( GetTrkEndOption( splitTrkTrk[splitTrkFlip], splitTrkEP[splitTrkFlip] ) & EPOPT_GAPPED )
mode |= 1;
for ( inx=0; inx<4; inx++ )
wMenuToggleSet( splitPopupMI[quad&1][inx], mode == inx );
wMenuPopupShow( splitPopupM[quad&1] );
break;
}
return C_CONTINUE;
}
#include "bitmaps/splittrk.xpm"
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 );
}
|