-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobeAdjust.c
355 lines (321 loc) · 9.32 KB
/
probeAdjust.c
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/Separator.h>
#include <Xm/BulletinB.h>
/*
* System includes for CA
*/
#include <caerr.h>
#include <cadef.h>
#include <db_access.h>
#include <stdio.h>
#include <string.h>
#include <alarm.h>
#include "probe.h"
/*
* X's stuff
*/
extern XmFontList fontList;
extern XFontStruct *font;
extern XmFontList fontList1;
extern XFontStruct *font1;
void updateLabelDisplay();
void updateTextDisplay();
void adjustOptionCallback();
void adjustCancelCallback(Widget w, XtPointer clientData,
XtPointer callbackStruct)
{
atom *channel = (atom *) clientData;
XtUnmanageChild(channel->adjust.dialog);
XtDestroyWidget(channel->adjust.dialog);
channel->adjust.upMask = ALL_DOWN;
channel->upMask &= ~ADJUST_UP;
channel->updateMask &= ~UPDATE_ADJUST;
channel->adjust.dialog = NULL;
channel->adjust.panel = NULL;
clearButtons(&(channel->adjust.buttons));
clearSlider(&(channel->adjust.slider));
channel->d[TEXT1].w = NULL;
channel->d[TEXT1].proc = NULL;
channel->d[LABEL2].w = NULL;
channel->d[LABEL2].proc = NULL;
}
void updateAdjustPanel(atom *ch)
{
if ((ch->upMask & ADJUST_UP) == 0) return;
if (ch->connected == FALSE) {
if (ch->adjust.dialog != NULL) {
adjustCancelCallback(NULL,(XtPointer)ch,NULL);
return;
}
} else {
switch(ca_field_type(ch->chId)) {
case DBF_STRING :
if (XtIsManaged(ch->adjust.panel))
XtUnmanageChild(ch->adjust.panel);
if (ch->adjust.upMask != ALL_DOWN) {
if (ch->adjust.upMask & ADJUST_SLIDER_UP)
destroySlider(ch);
if (ch->adjust.upMask & ADJUST_BUTTONS_UP)
destroyButtons(ch);
}
break;
case DBF_ENUM :
if (XtIsManaged(ch->adjust.panel))
XtUnmanageChild(ch->adjust.panel);
if (ch->adjust.upMask != ALL_DOWN) {
if (ch->adjust.upMask & ADJUST_SLIDER_UP)
destroySlider(ch);
if (ch->adjust.upMask & ADJUST_BUTTONS_UP)
destroyButtons(ch);
}
createButtons(ch);
XtManageChild(ch->adjust.panel);
break;
case DBF_CHAR :
case DBF_INT :
case DBF_LONG :
case DBF_FLOAT :
case DBF_DOUBLE :
if (XtIsManaged(ch->adjust.panel))
XtUnmanageChild(ch->adjust.panel);
if (ch->adjust.upMask != ALL_DOWN) {
if (ch->adjust.upMask & ADJUST_SLIDER_UP)
destroySlider(ch);
if (ch->adjust.upMask & ADJUST_BUTTONS_UP)
destroyButtons(ch);
}
createSlider(ch);
XtManageChild(ch->adjust.panel);
break;
default :
xerrmsg("updateAdjustPanel: Unknown channel type.\n");
break;
}
}
ch->updateMask &= ~UPDATE_ADJUST;
}
void textAdjustCallback(Widget w, XtPointer clientData,
XtPointer callbackData)
{
int n;
long outputL;
double outputD;
int stringFound;
#ifdef ALLOW_ARBITRARY_ENUMS
int ans;
char message[1024];
#endif
atom *channel = (atom *)clientData;
if (channel->monitored == FALSE) return;
switch(ca_field_type(channel->chId)) {
case DBF_STRING :
strcpy(channel->data.S.value,XmTextGetString(channel->d[TEXT1].w));
break;
case DBF_ENUM :
n = 0;
/* See if it matches a menu string */
stringFound=0;
for (n=0; n < channel->info.data.E.no_str; n++) {
if (strcmp(XmTextGetString(channel->d[TEXT1].w),
channel->info.data.E.strs[n]) == 0) {
stringFound=1;
break;
}
}
if (stringFound) {
channel->data.E.value = (short)n;
break;
}
/* Not found, see if it is a number */
if (sscanf(XmTextGetString(channel->d[TEXT1].w),
"%d", &n)) {
/* See if it is in range */
if (n < channel->info.data.E.no_str) {
channel->data.E.value = (short)n;
break;
}
#ifdef ALLOW_ARBITRARY_ENUMS
sprintf(message,"Are your sure?\n"
"Value=%d is out of range\n"
"for the number of strings [%d]",
n,channel->info.data.E.no_str);
ans=questionDialog(message,"Continue","Abort",NULL);
if(ans == 1) {
channel->data.E.value = (short)n;
break;
} else {
return;
}
#endif
}
/* Failed. Check if it is because it is out of range */
if (n < 0 || n >= channel->info.data.E.no_str) {
xerrmsg("textAdjustCallback: "
"Value [%d]\nis invalid for the number of strings [%d]\n",
n,channel->info.data.E.no_str);
} else {
xerrmsg("textAdjustCallback: Bad value\n");
}
return;
case DBF_CHAR :
if (sscanf(XmTextGetString(channel->d[TEXT1].w),"%ld", &outputL) &&
outputL >=0 && outputL < 256) {
channel->data.L.value = outputL;
} else {
xerrmsg("textAdjustCallback : Must be integer in range 0-255.\n");
return;
}
break;
case DBF_INT :
case DBF_LONG :
if (sscanf(XmTextGetString(channel->d[TEXT1].w),"%ld", &outputL)) {
channel->data.L.value = outputL;
} else {
xerrmsg("textAdjustCallback : Must be an integer.\n");
return;
}
break;
case DBF_FLOAT :
case DBF_DOUBLE :
if (sscanf(XmTextGetString(channel->d[TEXT1].w),"%lf",&outputD)) {
channel->data.D.value = outputD;
} else {
xerrmsg("textAdjustCallback : Must be a number.\n");
return;
}
break;
default :
return;
}
probeCASetValue(channel);
updateDisplay(channel);
}
void adjustCallback(Widget w, XtPointer clientData,
XtPointer callbackStruct)
{
atom *channel = (atom *) clientData;
int n;
Arg wargs[5];
Widget formatPanel;
Widget separator1;
Widget separator2;
Widget okButton, cancel;
Widget buttonsHolder;
if (channel->upMask & ADJUST_UP) return;
if (channel->connected == FALSE) return;
if (channel->monitored == FALSE)
startMonitor(NULL,(XtPointer)channel,NULL);
channel->upMask |= ADJUST_UP;
/*
* Create the XmbulletinBoardDialogBox.
*/
n = 0;
if (font)
XtSetArg(wargs[n], XmNtextFontList, fontList); n++;
XtSetArg(wargs[n], XmNautoUnmanage, FALSE); n++;
channel->adjust.dialog =
(Widget) XmCreateBulletinBoardDialog(w, "Adjust", wargs, n);
/*
* Create a XmRowColumn widget to hold everything.
*/
formatPanel = XtCreateManagedWidget("panel",
xmRowColumnWidgetClass,
channel->adjust.dialog, NULL, 0);
/*
* Create a label for the panel.
*/
n = 0;
if (font) {
XtSetArg(wargs[n], XmNfontList, fontList); n++;
}
channel->d[LABEL2].w = XtCreateManagedWidget("Channel name",
xmLabelWidgetClass,
formatPanel, wargs, n);
channel->d[LABEL2].proc = updateLabelDisplay;
channel->updateMask |= UPDATE_LABEL2;
/*
* Create a text input.
*/
n = 0;
if (font) {
XtSetArg(wargs[n], XmNfontList, fontList); n++;
}
channel->d[TEXT1].w = XtCreateManagedWidget("textAdjust",
xmTextWidgetClass,
formatPanel, wargs, n);
channel->d[TEXT1].proc = updateTextDisplay;
channel->updateMask |= UPDATE_TEXT1;
/*
* Create a separator for the extra control function region.
*/
n = 0;
separator1 = XtCreateManagedWidget("separator1",
xmSeparatorWidgetClass, formatPanel, wargs, n);
/*
* Create a rowColumn widget to hold the
* slider , toggle switch or other special controls.
*/
n = 0;
channel->adjust.panel = XmCreateRowColumn(formatPanel,
"adjust", wargs, n);
XtManageChild(channel->adjust.panel);
n = 0;
separator2 = XtCreateManagedWidget("separator1",
xmSeparatorWidgetClass, formatPanel, wargs, n);
/*
* Create a XmRowColumn widget to hold the name and value of
* the process variable.
*/
n = 0;
XtSetArg(wargs[n], XmNorientation, XmVERTICAL); n++;
XtSetArg(wargs[n], XmNnumColumns, 3); n++;
XtSetArg(wargs[n], XmNpacking, XmPACK_COLUMN);n++;
XtSetArg(wargs[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
buttonsHolder = XtCreateManagedWidget("holder",
xmRowColumnWidgetClass,
formatPanel, wargs, n);
/*
* Create 'OK' button
*/
n = 0;
if (font) {
XtSetArg(wargs[n], XmNfontList, fontList); n++;
}
okButton = XtCreateManagedWidget("Ok",
xmPushButtonWidgetClass,
buttonsHolder, wargs, n);
XtAddCallback(okButton, XmNactivateCallback, textAdjustCallback, channel);
/*
* Create 'cancel' button
*/
n = 0;
if (font) {
XtSetArg(wargs[n], XmNfontList, fontList); n++;
}
cancel = XtCreateManagedWidget("Cancel",
xmPushButtonWidgetClass,
buttonsHolder, wargs, n);
XtAddCallback(cancel, XmNactivateCallback,adjustCancelCallback,channel);
n = 0;
XtSetArg(wargs[n], XmNdefaultButton, okButton); n++;
XtSetValues(channel->adjust.dialog,wargs,n);
channel->d[ADJUST].w = channel->adjust.dialog;
channel->d[ADJUST].proc = updateAdjustPanel;
updateAdjustPanel(channel);
updateDisplay(channel);
XtManageChild(channel->adjust.dialog);
}