~ubuntu-branches/ubuntu/karmic/grace/karmic

« back to all changes in this revision

Viewing changes to src/regionwin.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-19 14:19:58 UTC
  • Revision ID: james.westby@ubuntu.com-20020319141958-5gxna6vo1ek3zjml
Tags: upstream-5.1.7
ImportĀ upstreamĀ versionĀ 5.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Grace - GRaphing, Advanced Computation and Exploration of data
 
3
 * 
 
4
 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
 
5
 * 
 
6
 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
 
7
 * Copyright (c) 1996-2000 Grace Development Team
 
8
 * 
 
9
 * Maintained by Evgeny Stambulchik <fnevgeny@plasma-gate.weizmann.ac.il>
 
10
 * 
 
11
 * 
 
12
 *                           All Rights Reserved
 
13
 * 
 
14
 *    This program is free software; you can redistribute it and/or modify
 
15
 *    it under the terms of the GNU General Public License as published by
 
16
 *    the Free Software Foundation; either version 2 of the License, or
 
17
 *    (at your option) any later version.
 
18
 * 
 
19
 *    This program is distributed in the hope that it will be useful,
 
20
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 *    GNU General Public License for more details.
 
23
 * 
 
24
 *    You should have received a copy of the GNU General Public License
 
25
 *    along with this program; if not, write to the Free Software
 
26
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
27
 */
 
28
 
 
29
/*
 
30
 * define regions and operate on regions
 
31
 */
 
32
 
 
33
#include <config.h>
 
34
 
 
35
#include <stdio.h>
 
36
 
 
37
#include <Xm/Xm.h>
 
38
#include <Xm/Form.h>
 
39
#include <Xm/DialogS.h>
 
40
#include <Xm/Label.h>
 
41
#include <Xm/PushB.h>
 
42
#include <Xm/RowColumn.h>
 
43
#include <Xm/ScrolledW.h>
 
44
#include <Xm/Text.h>
 
45
 
 
46
#include "globals.h"
 
47
#include "graphs.h"
 
48
#include "utils.h"
 
49
#include "events.h"
 
50
#include "motifinc.h"
 
51
#include "protos.h"
 
52
 
 
53
static Widget but1[2];
 
54
static Widget but2[2];
 
55
static Widget but3[3];
 
56
 
 
57
extern int regiontype;  /* in regionutils.c */
 
58
 
 
59
static void do_define_region(Widget w, XtPointer client_data, XtPointer call_data);
 
60
static void do_clear_region(Widget w, XtPointer client_data, XtPointer call_data);
 
61
 
 
62
 
 
63
static Widget *define_region_item;
 
64
static Widget *define_type_item;
 
65
 
 
66
static char buf[256];
 
67
 
 
68
static Widget status_frame;
 
69
static Widget status_panel;
 
70
static Widget status_sw;
 
71
 
 
72
static Widget header_w;
 
73
static Widget *labx;
 
74
 
 
75
static void do_define_region(Widget w, XtPointer client_data, XtPointer call_data)
 
76
{
 
77
    int rtype = GetChoice(define_type_item);
 
78
 
 
79
    nr = GetChoice(define_region_item);
 
80
    define_region(nr, rtype);
 
81
}
 
82
 
 
83
void create_define_frame(void *data)
 
84
{
 
85
    static Widget top, dialog;
 
86
 
 
87
    set_wait_cursor();
 
88
    if (top == NULL) {
 
89
        char *label2[2];
 
90
        label2[0] = "Define";
 
91
        label2[1] = "Close";
 
92
        top = XmCreateDialogShell(app_shell, "Define region", NULL, 0);
 
93
        handle_close(top);
 
94
        dialog = XmCreateRowColumn(top, "dialog_rc", NULL, 0);
 
95
 
 
96
        define_region_item = CreatePanelChoice(dialog,
 
97
                                               "Define region:",
 
98
                                               6,
 
99
                                               "0", "1", "2", "3", "4",
 
100
                                               NULL, 0);
 
101
 
 
102
        define_type_item = CreatePanelChoice(dialog,
 
103
                                             "Region type:",
 
104
                                             11,
 
105
                                             "Inside polygon",
 
106
                                             "Outside polygon",
 
107
                                             "Above line",
 
108
                                             "Below line",
 
109
                                             "Left of line",
 
110
                                             "Right of line",
 
111
                                             "In Horiz. Range",
 
112
                                             "In Vert. Range",
 
113
                                             "Out of Horiz. Range",
 
114
                                             "Out of Vert. Range",
 
115
                                             NULL, 0);
 
116
 
 
117
        CreateSeparator(dialog);
 
118
 
 
119
        CreateCommandButtons(dialog, 2, but2, label2);
 
120
        XtAddCallback(but2[0], XmNactivateCallback, (XtCallbackProc) do_define_region, (XtPointer) NULL);
 
121
        XtAddCallback(but2[1], XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) top);
 
122
 
 
123
        ManageChild(dialog);
 
124
    }
 
125
    RaiseWindow(top);
 
126
    unset_wait_cursor();
 
127
}
 
128
 
 
129
static Widget *clear_region_item;
 
130
 
 
131
static void do_clear_region(Widget w, XtPointer client_data, XtPointer call_data)
 
132
{
 
133
    int i;
 
134
 
 
135
    set_wait_cursor();
 
136
    if (GetChoice(clear_region_item) == MAXREGION) {
 
137
        for (i = 0; i < MAXREGION; i++) {
 
138
            kill_region(i);
 
139
        }
 
140
    } else {
 
141
        kill_region(GetChoice(clear_region_item));
 
142
    }
 
143
    unset_wait_cursor();
 
144
    xdrawgraph();
 
145
}
 
146
 
 
147
void create_clear_frame(void *data)
 
148
{
 
149
    static Widget top, dialog;
 
150
 
 
151
    set_wait_cursor();
 
152
    if (top == NULL) {
 
153
        char *label1[2];
 
154
        label1[0] = "Accept";
 
155
        label1[1] = "Close";
 
156
        top = XmCreateDialogShell(app_shell, "Clear region", NULL, 0);
 
157
        handle_close(top);
 
158
        dialog = XmCreateRowColumn(top, "dialog_rc", NULL, 0);
 
159
 
 
160
        clear_region_item = CreatePanelChoice(dialog,
 
161
                                              "Clear region:",
 
162
                                              7,
 
163
                                              "0", "1", "2", "3", "4", "All",
 
164
                                              NULL, 0);
 
165
 
 
166
        CreateSeparator(dialog);
 
167
 
 
168
        CreateCommandButtons(dialog, 2, but1, label1);
 
169
        XtAddCallback(but1[0], XmNactivateCallback, (XtCallbackProc) do_clear_region, (XtPointer) NULL);
 
170
        XtAddCallback(but1[1], XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) top);
 
171
 
 
172
        ManageChild(dialog);
 
173
    }
 
174
    RaiseWindow(top);
 
175
    unset_wait_cursor();
 
176
}
 
177
 
 
178
Widget arealab, perimlab;
 
179
 
 
180
void create_area_frame(void *data)
 
181
{
 
182
    static Widget top, dialog;
 
183
    XmString str;
 
184
 
 
185
    set_wait_cursor();
 
186
    if (top == NULL) {
 
187
        char *label3[3];
 
188
        label3[0] = "Area";
 
189
        label3[1] = "Perimeter";
 
190
        label3[2] = "Close";
 
191
        top = XmCreateDialogShell(app_shell, "Area/perimeter", NULL, 0);
 
192
        handle_close(top);
 
193
        dialog = XmCreateRowColumn(top, "dialog_rc", NULL, 0);
 
194
 
 
195
        str = XmStringCreateLocalized("[    Area    ]");
 
196
        arealab = XtVaCreateManagedWidget("label Area", xmLabelWidgetClass, dialog,
 
197
                                          XmNlabelString, str,
 
198
                                          NULL);
 
199
        XmStringFree(str);
 
200
        str = XmStringCreateLocalized("[    Perim    ]");
 
201
        perimlab = XtVaCreateManagedWidget("label Perim", xmLabelWidgetClass, dialog,
 
202
                                           XmNlabelString, str,
 
203
                                           NULL);
 
204
        XmStringFree(str);
 
205
 
 
206
        CreateSeparator(dialog);
 
207
 
 
208
        CreateCommandButtons(dialog, 3, but3, label3);
 
209
        XtAddCallback(but3[0], XmNactivateCallback, (XtCallbackProc) do_select_area, (XtPointer) NULL);
 
210
        XtAddCallback(but3[1], XmNactivateCallback, (XtCallbackProc) do_select_peri, (XtPointer) NULL);
 
211
        XtAddCallback(but3[2], XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) top);
 
212
 
 
213
        ManageChild(dialog);
 
214
    }
 
215
    RaiseWindow(top);
 
216
    unset_wait_cursor();
 
217
}
 
218
 
 
219
static Widget *reporton_region_item;
 
220
static Widget *reporton_type_item;
 
221
 
 
222
static void do_reporton_region(Widget w, XtPointer client_data, XtPointer call_data)
 
223
{
 
224
    int regno = (int) GetChoice(reporton_region_item);
 
225
    int type = (int) GetChoice(reporton_type_item);
 
226
    set_wait_cursor();
 
227
    reporton_region(get_cg(), regno, type);
 
228
    unset_wait_cursor();
 
229
}
 
230
 
 
231
void create_reporton_frame(void *data)
 
232
{
 
233
    static Widget top, dialog;
 
234
 
 
235
    set_wait_cursor();
 
236
    if (top == NULL) {
 
237
        char *label1[2];
 
238
        label1[0] = "Accept";
 
239
        label1[1] = "Close";
 
240
        top = XmCreateDialogShell(app_shell, "Report on sets in region", NULL, 0);
 
241
        handle_close(top);
 
242
        dialog = XmCreateRowColumn(top, "dialog_rc", NULL, 0);
 
243
 
 
244
        reporton_region_item = CreatePanelChoice(dialog,
 
245
                                                   "Report on sets in region:",
 
246
                                                   8,
 
247
                   "0", "1", "2", "3", "4", "Inside world", "Outside world",
 
248
                                                   NULL, 0);
 
249
 
 
250
        reporton_type_item = CreatePanelChoice(dialog,
 
251
                                                   "Report type:",
 
252
                                                   3,
 
253
                                                "Sets", "Points",
 
254
                                                   NULL, 0);
 
255
 
 
256
        CreateSeparator(dialog);
 
257
 
 
258
        CreateCommandButtons(dialog, 2, but1, label1);
 
259
        XtAddCallback(but1[0], XmNactivateCallback, (XtCallbackProc) do_reporton_region, (XtPointer) NULL);
 
260
        XtAddCallback(but1[1], XmNactivateCallback, (XtCallbackProc) destroy_dialog, (XtPointer) top);
 
261
 
 
262
        ManageChild(dialog);
 
263
    }
 
264
    RaiseWindow(top);
 
265
    unset_wait_cursor();
 
266
}
 
267
 
 
268
static void set_status_label(Widget w, char *buf)
 
269
{
 
270
    Arg al;
 
271
    XmString ls;
 
272
    ls = XmStringCreateLocalized(buf);
 
273
    XtSetArg(al, XmNlabelString, ls);
 
274
    XtSetValues(w, &al, 1);
 
275
    XmStringFree(ls);
 
276
}
 
277
 
 
278
 
 
279
void clear_status(void)
 
280
{
 
281
    int i;
 
282
    for (i = 0; i < MAXREGION; i++) {
 
283
        set_status_label(labx[i], " ");
 
284
    }
 
285
}
 
286
 
 
287
void update_status_popup(Widget w, XtPointer client_data, XtPointer call_data)
 
288
{
 
289
    int rno;
 
290
    if (status_frame) {
 
291
        clear_status();
 
292
        sprintf(buf, " Region # Active  Type");
 
293
        set_status_label(header_w, buf);
 
294
 
 
295
        for (rno = 0; rno < MAXREGION; rno++) {
 
296
            sprintf(buf, "  %2d    %3s   %6s", rno, on_or_off(rg[rno].active),
 
297
                    region_types(rg[rno].type, 0));
 
298
            set_status_label(labx[rno], buf);
 
299
        }
 
300
 
 
301
    }
 
302
}
 
303
 
 
304
 
 
305
void define_status_popup(void *data)
 
306
{
 
307
    set_wait_cursor();
 
308
    
 
309
    if (status_frame == NULL) {
 
310
        int i;
 
311
        Widget wbut, rc, rc3, fr2;
 
312
 
 
313
        status_frame = XmCreateDialogShell(app_shell, "Status", NULL, 0);
 
314
        handle_close(status_frame);
 
315
 
 
316
        status_panel = XmCreateForm(status_frame, "form", NULL, 0);
 
317
 
 
318
        status_sw = XtVaCreateManagedWidget("sw",
 
319
            xmScrolledWindowWidgetClass, status_panel,
 
320
            XmNscrollingPolicy, XmAUTOMATIC,
 
321
            XmNheight, 200,
 
322
            XmNwidth, 200,
 
323
            NULL);
 
324
        rc3 = XmCreateRowColumn(status_sw, "rc3", NULL, 0);
 
325
        header_w = XtVaCreateManagedWidget("header", xmLabelWidgetClass, rc3,
 
326
            XmNalignment, XmALIGNMENT_BEGINNING,
 
327
            XmNrecomputeSize, True,
 
328
            NULL);
 
329
        SetFixedFont(header_w);
 
330
        labx = (Widget *)xmalloc( MAXREGION*sizeof(Widget) );
 
331
        for (i = 0; i < MAXREGION; i++) {
 
332
            labx[i] = XtVaCreateManagedWidget("labx", xmLabelWidgetClass, rc3,
 
333
                XmNalignment, XmALIGNMENT_BEGINNING,
 
334
                XmNrecomputeSize, True,
 
335
                NULL);
 
336
            SetFixedFont(labx[i]);
 
337
        }
 
338
        ManageChild(rc3);
 
339
        XtVaSetValues(status_sw, XmNworkWindow, rc3, NULL);
 
340
 
 
341
        fr2 = CreateFrame(status_panel, NULL);
 
342
        rc = XmCreateRowColumn(fr2, "rc", NULL, 0);
 
343
        XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL);
 
344
 
 
345
        wbut = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, rc,
 
346
                                       NULL);
 
347
        XtAddCallback(wbut, XmNactivateCallback, (XtCallbackProc) destroy_dialog, status_frame);
 
348
 
 
349
        wbut = XtVaCreateManagedWidget("Update", xmPushButtonWidgetClass, rc,
 
350
                                       NULL);
 
351
        XtAddCallback(wbut, XmNactivateCallback, (XtCallbackProc) update_status_popup, NULL);
 
352
 
 
353
        ManageChild(rc);
 
354
 
 
355
        XtVaSetValues(status_sw,
 
356
                      XmNtopAttachment, XmATTACH_FORM,
 
357
                      XmNleftAttachment, XmATTACH_FORM,
 
358
                      XmNrightAttachment, XmATTACH_FORM,
 
359
                      XmNbottomAttachment, XmATTACH_WIDGET,
 
360
                      XmNbottomWidget, fr2,
 
361
                      NULL);
 
362
        XtVaSetValues(fr2,
 
363
                      XmNleftAttachment, XmATTACH_FORM,
 
364
                      XmNrightAttachment, XmATTACH_FORM,
 
365
                      XmNbottomAttachment, XmATTACH_FORM,
 
366
                      NULL);
 
367
        ManageChild(status_panel);
 
368
 
 
369
    }
 
370
    RaiseWindow(status_frame);
 
371
    update_status_popup(NULL, NULL, NULL);
 
372
    unset_wait_cursor();
 
373
}
 
374
 
 
375
void define_region(int nr, int rtype)
 
376
{
 
377
    kill_region(nr);
 
378
    switch (rtype) {
 
379
    case 0:
 
380
        regiontype = REGION_POLYI;
 
381
        do_select_region();
 
382
        break;
 
383
    case 1:
 
384
        regiontype = REGION_POLYO;
 
385
        do_select_region();
 
386
        break;
 
387
    case 2:
 
388
        regiontype = REGION_ABOVE;
 
389
        set_action(DO_NOTHING);
 
390
        set_action(DEF_REGION1ST);
 
391
        break;
 
392
    case 3:
 
393
        regiontype = REGION_BELOW;
 
394
        set_action(DO_NOTHING);
 
395
        set_action(DEF_REGION1ST);
 
396
        break;
 
397
    case 4:
 
398
        regiontype = REGION_TOLEFT;
 
399
        set_action(DO_NOTHING);
 
400
        set_action(DEF_REGION1ST);
 
401
        break;
 
402
    case 5:
 
403
        regiontype = REGION_TORIGHT;
 
404
        set_action(DO_NOTHING);
 
405
        set_action(DEF_REGION1ST);
 
406
        break;
 
407
    case 6:
 
408
        regiontype= REGION_HORIZI;
 
409
        set_action(DO_NOTHING);
 
410
        set_action(DEF_REGION1ST);
 
411
        break;
 
412
    case 7:
 
413
        regiontype= REGION_VERTI;
 
414
        set_action(DO_NOTHING);
 
415
        set_action(DEF_REGION1ST);
 
416
        break;
 
417
    case 8:
 
418
        regiontype= REGION_HORIZO;
 
419
        set_action(DO_NOTHING);
 
420
        set_action(DEF_REGION1ST);
 
421
        break;
 
422
    case 9:
 
423
        regiontype= REGION_VERTO;
 
424
        set_action(DO_NOTHING);
 
425
        set_action(DEF_REGION1ST);
 
426
        break;
 
427
    }
 
428
}