-
Notifications
You must be signed in to change notification settings - Fork 1
/
titles.c
226 lines (169 loc) · 6.01 KB
/
titles.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
/*
-------------------------------------------------------------------------
OBJECT NAME: titles.c
FULL NAME: netCDF Titles/Category Window & callbacks
ENTRY POINTS: ViewTitles()
STATIC FNS: CreateTitleWindow()
SetTitles()
DismissTitles()
PrintTitles()
DESCRIPTION: Currently hardwired to only use the Category list from
file[0].
COPYRIGHT: University Corporation for Atmospheric Research, 1998-05
-------------------------------------------------------------------------
*/
#include "define.h"
#include "ps.h"
#include <netcdf.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
static Widget TitleShell, TitleWindow = NULL, titleText;
static int currentCategory;
static void
CreateTitleWindow(), SetTitles(),
PrintTitles(Widget w, XtPointer client, XtPointer call),
DismissTitles(Widget w, XtPointer client, XtPointer call);
extern Widget AppShell;
/* -------------------------------------------------------------------- */
void ViewTitles(Widget w, XtPointer client, XtPointer call)
{
if (NumberDataFiles == 0)
return;
if (!TitleWindow)
CreateTitleWindow();
SetTitles();
if (TitleWindow) {
XtManageChild(TitleWindow);
XtPopup(XtParent(TitleWindow), XtGrabNone);
}
} /* END VIEWTITLES */
/* -------------------------------------------------------------------- */
static void DismissTitles(Widget w, XtPointer client, XtPointer call)
{
if (TitleWindow)
{
XtUnmanageChild(TitleWindow);
XtPopdown(XtParent(TitleWindow));
XmTextSetString(titleText, (char *)"");
}
} /* END DISMISSHEADER */
/* -------------------------------------------------------------------- */
static void SetCategory(Widget w, XtPointer client, XtPointer call)
{
currentCategory = (long)client;
SetTitles();
} /* END SETCATEGORY */
/* -------------------------------------------------------------------- */
static void SetTitles()
{
DATAFILE_INFO *curFile = &dataFile[CurrentDataFile];
XmTextSetString(titleText, const_cast<char *>(curFile->fileName.c_str()));
XmTextInsert(titleText, XmTextGetLastPosition(titleText), (char *)"\n\n");
for (size_t i = 0; i < curFile->Variable.size(); ++i)
{
VARTBL *vp = curFile->Variable[i];
bool ok = false;
if (currentCategory == 0)
ok = true;
else
{
std::set<std::string>::iterator it = curFile->categories.begin();
std::advance (it, currentCategory - 1);
if (find(vp->categories.begin(), vp->categories.end(), *it) != vp->categories.end())
ok = true;
}
if (ok)
{
snprintf(buffer, BUFFSIZE, "%-20s %-10s %s\n",
curFile->Variable[i]->name.c_str(),
curFile->Variable[i]->units.c_str(),
curFile->Variable[i]->long_name.c_str());
XmTextInsert(titleText, XmTextGetLastPosition(titleText), buffer);
}
}
} /* END SETTITLES */
/* -------------------------------------------------------------------- */
static void CreateTitleWindow()
{
Arg args[8];
size_t i, n;
Widget drFrame, drRC, b[3], catPD, catOpMenu, catButts[32];
XmString name;
n = 0;
TitleShell = XtCreatePopupShell("headerShell",
topLevelShellWidgetClass, AppShell, args, n);
n = 0;
TitleWindow = XmCreateForm(TitleShell, (char *)"headerForm", args, n);
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
drFrame = XmCreateFrame(TitleWindow, (char *)"buttonFrame", args, n);
XtManageChild(drFrame);
n = 0;
drRC = XmCreateRowColumn(drFrame, (char *)"buttonRC", args, n);
XtManageChild(drRC);
n = 0;
b[0] = XmCreatePushButton(drRC, (char *)"dismissButton", args, n);
XtAddCallback(b[0], XmNactivateCallback, DismissTitles, TitleWindow);
n = 0;
b[1] = XmCreatePushButton(drRC, (char *)"printButton", args, n);
XtAddCallback(b[1], XmNactivateCallback, PrintTitles, NULL);
XtManageChildren(b, 2);
/* Category Op Menu.
*/
n = 0;
catPD = XmCreatePulldownMenu(drRC, (char *)"catPullDown", args, n);
n = 0;
XtSetArg(args[n], XmNsubMenuId, catPD); ++n;
catOpMenu = XmCreateOptionMenu(drRC, (char *)"catOpMenu", args, n);
XtManageChild(catOpMenu);
name = XmStringCreateLocalized((char *)"All Variables");
n = 0;
XtSetArg(args[n], XmNlabelString, name); ++n;
catButts[0] = XmCreatePushButton(catPD, (char *)"opMenB", args, n);
XtAddCallback(catButts[0], XmNactivateCallback, SetCategory, (XtPointer)0);
XmStringFree(name);
std::set<std::string>::iterator it = dataFile[0].categories.begin();
for (i = 1; it != dataFile[0].categories.end(); ++it, ++i)
{
name = XmStringCreateLocalized(const_cast<char *>((*it).c_str()));
n = 0;
XtSetArg(args[n], XmNlabelString, name); ++n;
catButts[i] = XmCreatePushButton(catPD, (char *)"opMenB", args, n);
XtAddCallback(catButts[i], XmNactivateCallback, SetCategory, (XtPointer)i);
XmStringFree(name);
}
XtManageChildren(catButts, i);
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, drFrame); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
titleText = XmCreateScrolledText(TitleWindow, (char *)"headerText", args, n);
XtManageChild(titleText);
} /* END CREATETITLEWINDOW */
/* -------------------------------------------------------------------- */
static void PrintTitles(Widget w, XtPointer client, XtPointer call)
{
FILE *fp;
char *p;
if ((p = getenv("LPDEST")) != NULL)
printf("Output being sent to %s.\n", p);
if ((fp = popen(const_cast<char *>(printerSetup.lpCommand.c_str()), "w")) == NULL)
{
ShowError("PrintTitles: can't open pipe to 'lp'");
return;
}
fprintf(fp, "%s, %s\n\n",
mainPlot[0].title.c_str(), mainPlot[0].subTitle.c_str());
p = XmTextGetString(titleText);
fprintf(fp, "%s\n", p);
XtFree(p);
pclose(fp);
} /* END PRINTTITLES */
/* END TITLES.C */