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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/*
* $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/dease.c,v 1.3 2008-03-06 19:35:08 m_fischer Exp $
*
* Easement Button Hdlrs
*
*/
/* 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 "track.h"
#include "ccurve.h"
#include "cstraigh.h"
#include "cjoin.h"
#include "i18n.h"
static wButton_p easementB;
static DIST_T easeX = 0.0;
static DIST_T Rvalues[3];
static DIST_T Lvalues[3];
static DIST_T oldEasementVal;
static wIcon_p enone_bm;
static wIcon_p esharp_bm;
static wIcon_p egtsharp_bm;
static wIcon_p enormal_bm;
static wIcon_p eltbroad_bm;
static wIcon_p ebroad_bm;
static wIcon_p egtbroad_bm;
/****************************************
*
* EASEMENTW
*
*/
static wWin_p easementW;
static void EasementSel( long );
static void SetEasement( DIST_T, void * );
static void EasementOk( void );
static void EasementCancel( void );
static char *easementChoiceLabels[] = { N_("None"), N_("Sharp"), N_("Normal"), N_("Broad"), NULL };
static paramFloatRange_t r0o5_2 = { 0.5, 2.0, 60 };
static paramFloatRange_t r0_100 = { 0.0, 100.0, 60 };
static paramFloatRange_t r0_10 = { 0.0, 10.0, 60 };
static long easeM;
static paramData_t easementPLs[] = {
#define I_EASEVAL (0)
{ PD_FLOAT, &easementVal, "val", PDO_NOPSHUPD, &r0o5_2, N_("Value") },
{ PD_FLOAT, &easeR, "r", PDO_DIM|PDO_DLGRESETMARGIN, &r0_100, N_("R"), BO_READONLY },
{ PD_FLOAT, &easeX, "x", PDO_DIM|PDO_DLGHORZ, &r0_10, N_("X"), BO_READONLY },
{ PD_FLOAT, &easeL, "l", PDO_DIM|PDO_DLGHORZ, &r0_100, N_("L"), BO_READONLY },
#define I_EASESEL (4)
{ PD_RADIO, &easeM, "radio", PDO_DIM|PDO_NORECORD|PDO_NOPREF|PDO_DLGRESETMARGIN, easementChoiceLabels, NULL, BC_HORZ|BC_NONE } };
static paramGroup_t easementPG = { "easement", PGO_RECORD, easementPLs, sizeof easementPLs/sizeof easementPLs[0] };
static void SetEasement(
DIST_T val,
void * update )
/*
* Set transition-curve parameters (R and L).
*/
{
DIST_T z;
long selVal = -1;
wIcon_p bm;
if (val == 0.0) {
easeX = easeR = easeL = 0.0;
selVal = 0;
bm = enone_bm;
} else if (val <= 1.0) {
z = 1.0/val - 1.0;
easeR = Rvalues[1] - z * (Rvalues[1] - Rvalues[0]);
easeL = Lvalues[1] - z * (Lvalues[1] - Lvalues[0]);
if (easeR != 0.0)
easeX = easeL*easeL/(24*easeR);
else
easeX = 0.0;
if (val == 1.0) {
selVal = 2;
bm = enormal_bm;
} else if (val == 0.5) {
selVal = 1;
bm = esharp_bm;
} else {
bm = egtsharp_bm;
}
} else {
z = val - 1.0;
easeR = Rvalues[1] + z * (Rvalues[2] - Rvalues[1]);
easeL = Lvalues[1] + z * (Lvalues[2] - Lvalues[1]);
if (easeR != 0.0)
easeX = easeL*easeL/(24*easeR);
else
easeX = 0.0;
if (val == 2.0) {
selVal = 3;
bm = ebroad_bm;
} else if (val < 2.0) {
bm = eltbroad_bm;
} else {
bm = egtbroad_bm;
}
}
easeR = (floor(easeR*100.0))/100.0;
easementVal = val;
if (easementW && wWinIsVisible(easementW)) {
ParamLoadControls( &easementPG );
if (update) {
easeM = selVal;
ParamLoadControl( &easementPG, I_EASESEL );
}
}
/*ParamChange( &easeValPD );*/
if (easementB)
wButtonSetLabel( easementB, (char*)bm );
}
static void EasementOk( void )
{
ParamLoadData( &easementPG );
SetEasement( easementVal, (void*)FALSE );
wHide( easementW );
}
static void EasementCancel( void )
{
SetEasement( easementVal = oldEasementVal, (void*)FALSE );
wHide( easementW );
}
static void EasementSel(
long arg )
/*
* Handle transition-curve parameter selection.
*/
{
DIST_T val;
switch (arg) {
case 0:
val = 0;
break;
case 1:
val = 0.5;
break;
case 2:
val = 1.0;
break;
case 3:
val = 2.0;
break;
default:
AbortProg( "easementSel: bad value %ld", arg);
val = 0.0;
break;
}
SetEasement( val, (void*)FALSE );
}
static void EasementDlgUpdate(
paramGroup_p pg,
int inx,
void * valueP )
{
switch (inx) {
case I_EASEVAL:
SetEasement( *(FLOAT_T*)valueP, (void*)1 );
break;
case I_EASESEL:
EasementSel( *(long*)valueP );
break;
}
}
static void LayoutEasementW(
paramData_t * pd,
int inx,
wPos_t colX,
wPos_t * x,
wPos_t * y )
{
if ( inx == 2 )
wControlSetPos( easementPLs[0].control, *x, wControlGetPosY(easementPLs[0].control) );
}
static void DoEasement( void * junk )
{
if (easementW == NULL) {
easementW = ParamCreateDialog( &easementPG, MakeWindowTitle(_("Easement")), _("Ok"), (paramActionOkProc)EasementOk, (paramActionCancelProc)EasementCancel, TRUE, LayoutEasementW, 0, EasementDlgUpdate );
SetEasement( easementVal, (void*)TRUE );
}
oldEasementVal = easementVal;
wShow( easementW );
SetEasement( easementVal, (void*)TRUE );
}
static void EasementChange( long changes )
/*
* Handle change of scale. Load new parameters.
*/
{
if (changes&(CHANGE_SCALE|CHANGE_UNITS)) {
GetScaleEasementValues( Rvalues, Lvalues );
SetEasement( easementVal, (void*)TRUE );
}
}
#include "bitmaps/enone.xpm"
#include "bitmaps/esharp.xpm"
#include "bitmaps/egtsharp.xpm"
#include "bitmaps/enormal.xpm"
#include "bitmaps/eltbroad.xpm"
#include "bitmaps/ebroad.xpm"
#include "bitmaps/egtbroad.xpm"
EXPORT addButtonCallBack_t EasementInit( void )
{
ParamRegister( &easementPG );
enone_bm = wIconCreatePixMap( enone_xpm );
esharp_bm = wIconCreatePixMap( esharp_xpm );
egtsharp_bm = wIconCreatePixMap( egtsharp_xpm );
enormal_bm = wIconCreatePixMap( enormal_xpm );
eltbroad_bm = wIconCreatePixMap( eltbroad_xpm );
ebroad_bm = wIconCreatePixMap( ebroad_xpm );
egtbroad_bm = wIconCreatePixMap( egtbroad_xpm );
easementB = AddToolbarButton( "cmdEasement", enone_bm, 0, (addButtonCallBack_t)DoEasementRedir, NULL );
RegisterChangeNotification( EasementChange );
return &DoEasement;
}
|