~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.frame/frame.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       d.frame
5
 
 * AUTHOR(S):    James Westervelt, U.S. Army CERL (original contributor)
6
 
 *               Michael Shapiro, U.S. Army CERL (original contributor)
7
 
 *               Markus Neteler <neteler itc.it>
8
 
 *               Bernhard Reiter <bernhard intevation.de>, Eric G. Miller <egm2 jps.net>, 
9
 
 *               Glynn Clements <glynn gclements.plus.com>, Hamish Bowman <hamish_b yahoo.com>, 
10
 
 *               Jan-Oliver Wagner <jan intevation.de>
11
 
 * PURPOSE:      
12
 
 * COPYRIGHT:    (C) 1999-2007 by the GRASS Development Team
13
 
 *
14
 
 *               This program is free software under the GNU General Public
15
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
16
 
 *               for details.
17
 
 *
18
 
 *****************************************************************************/
19
 
/*
20
 
 *   d.frame [-cps] [frame=name] [at=bottom,top,left,right]
21
 
 *
22
 
 *   at=...       create frame here (implies -c)
23
 
 *       top, bottom, left, and right are % coordinates of window;
24
 
 *       0,0 is lower left; 100,100 is upper right
25
 
 */
26
 
 
27
 
#include <string.h>
28
 
#include <stdlib.h>
29
 
#include <grass/gis.h>
30
 
#include <grass/display.h>
31
 
#include <grass/raster.h>
32
 
#include <grass/glocale.h>
33
 
 
34
 
int check_at(char *);
35
 
int list_all(void);
36
 
 
37
 
int main(int argc, char *argv[])
38
 
{
39
 
    char buf[1024];
40
 
    int create, select, print, debug, list;
41
 
    struct GModule *module;
42
 
    struct
43
 
    {
44
 
        struct Option *frame, *at;
45
 
    } parm;
46
 
    struct
47
 
    {
48
 
        struct Flag *debug;
49
 
        struct Flag *list;
50
 
        struct Flag *select;
51
 
        struct Flag *print;
52
 
        struct Flag *printall;
53
 
        struct Flag *create;
54
 
        struct Flag *erase;
55
 
    } flag;
56
 
 
57
 
    G_gisinit(argv[0]);
58
 
 
59
 
    module = G_define_module();
60
 
    module->keywords = _("display, setup");
61
 
    module->description =
62
 
        _("Manages display frames on the user's graphics monitor.");
63
 
 
64
 
    flag.create = G_define_flag();
65
 
    flag.create->key = 'c';
66
 
    flag.create->description = _("Create a new frame");
67
 
 
68
 
    flag.select = G_define_flag();
69
 
    flag.select->key = 's';
70
 
    flag.select->description = _("Select a frame");
71
 
 
72
 
    flag.erase = G_define_flag();
73
 
    flag.erase->key = 'e';
74
 
    flag.erase->description = _("Remove all frames and erase the screen");
75
 
 
76
 
    flag.print = G_define_flag();
77
 
    flag.print->key = 'p';
78
 
    flag.print->description = _("Print name of current frame");
79
 
 
80
 
    flag.printall = G_define_flag();
81
 
    flag.printall->key = 'a';
82
 
    flag.printall->description = _("Print names of all frames");
83
 
 
84
 
    flag.list = G_define_flag();
85
 
    flag.list->key = 'l';
86
 
    flag.list->description = _("List map names displayed in GRASS monitor");
87
 
 
88
 
    flag.debug = G_define_flag();
89
 
    flag.debug->key = 'D';
90
 
    flag.debug->description = _("Debugging output");
91
 
 
92
 
    parm.frame = G_define_option();
93
 
    parm.frame->key = "frame";
94
 
    parm.frame->type = TYPE_STRING;
95
 
    parm.frame->key_desc = _("name");
96
 
    parm.frame->required = NO;
97
 
    parm.frame->multiple = NO;
98
 
    parm.frame->description = _("Frame to be created/selected");
99
 
 
100
 
    parm.at = G_define_option();
101
 
    parm.at->key = "at";
102
 
    parm.at->key_desc = _("bottom,top,left,right");
103
 
    parm.at->type = TYPE_DOUBLE;
104
 
    parm.at->required = NO;
105
 
    parm.at->multiple = NO;
106
 
    parm.at->description =
107
 
        _("Where to place the frame, values in percent (implies -c)");
108
 
    parm.at->checker = check_at;
109
 
 
110
 
    if (G_parser(argc, argv))
111
 
        exit(EXIT_FAILURE);
112
 
 
113
 
    create = flag.create->answer;
114
 
    print = flag.print->answer;
115
 
    select = flag.select->answer;
116
 
    debug = flag.debug->answer;
117
 
    list = flag.list->answer;
118
 
 
119
 
    /* if frame name is given without a control option, treat it as select */
120
 
    if (parm.frame->answer && (!create && !print && !select && !list))
121
 
        select = TRUE;
122
 
 
123
 
    /* at= placement implies creation */
124
 
    if (parm.at->answer)
125
 
        create = TRUE;
126
 
 
127
 
    if (flag.erase->answer) {
128
 
        if (R_open_driver() != 0)
129
 
            G_fatal_error(_("No graphics device selected"));
130
 
 
131
 
        if (!create)
132
 
            D_full_screen();
133
 
        else {
134
 
            D_remove_windows();
135
 
            R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
136
 
            R_erase();
137
 
        }
138
 
 
139
 
        R_close_driver();
140
 
    }
141
 
 
142
 
    if (create) {
143
 
        select = FALSE;
144
 
        sprintf(buf, "%s/etc/frame.create", G_gisbase());
145
 
        if (parm.frame->answer) {
146
 
            strcat(buf, " frame='");
147
 
            strcat(buf, parm.frame->answer);
148
 
            strcat(buf, "'");
149
 
        }
150
 
        if (parm.at->answer) {
151
 
            strcat(buf, " at='");
152
 
            strcat(buf, parm.at->answer);
153
 
            strcat(buf, "'");
154
 
        }
155
 
        if (system(buf))
156
 
            exit(EXIT_FAILURE);
157
 
    }
158
 
    if (select) {
159
 
        sprintf(buf, "%s/etc/frame.select", G_gisbase());
160
 
        if (parm.frame->answer) {
161
 
            strcat(buf, " frame='");
162
 
            strcat(buf, parm.frame->answer);
163
 
            strcat(buf, "'");
164
 
        }
165
 
        if (system(buf))
166
 
            exit(EXIT_FAILURE);
167
 
    }
168
 
 
169
 
    if (debug) {
170
 
        sprintf(buf, "%s/etc/frame.dumper", G_gisbase());
171
 
        if (system(buf))
172
 
            exit(EXIT_FAILURE);
173
 
    }
174
 
 
175
 
    if (list) {
176
 
        sprintf(buf, "%s/etc/frame.list", G_gisbase());
177
 
        if (system(buf))
178
 
            exit(EXIT_FAILURE);
179
 
    }
180
 
 
181
 
    if (print) {
182
 
        if (R_open_driver() != 0)
183
 
            G_fatal_error(_("No graphics device selected"));
184
 
        D_get_cur_wind(buf);
185
 
        D_set_cur_wind(buf);
186
 
        R_close_driver();
187
 
        fprintf(stdout, "%s\n", buf);
188
 
    }
189
 
 
190
 
    if (flag.printall->answer)
191
 
        list_all();
192
 
 
193
 
 
194
 
    exit(EXIT_SUCCESS);
195
 
}
196
 
 
197
 
 
198
 
int check_at(char *s)
199
 
{
200
 
    float top, bottom, left, right;
201
 
 
202
 
 
203
 
    if (s == NULL)
204
 
        return 0;
205
 
 
206
 
    if (4 != sscanf(s, "%f,%f,%f,%f", &bottom, &top, &left, &right)
207
 
        || bottom < 0.0 || top > 100.0 || bottom >= top
208
 
        || left < 0.0 || right > 100.0 || left >= right) {
209
 
        fprintf(stderr, "<at=%s> invalid request\n", s);
210
 
        return 1;
211
 
    }
212
 
    return 0;
213
 
}
214
 
 
215
 
 
216
 
int list_all(void)
217
 
{
218
 
    char **pads;
219
 
    int npads;
220
 
    int p;
221
 
 
222
 
    if (R_open_driver() != 0)
223
 
        G_fatal_error(_("No graphics device selected"));
224
 
 
225
 
    R_pad_list(&pads, &npads);
226
 
 
227
 
    for (p = npads - 1; p >= 0; p--)
228
 
        fprintf(stdout, "%s\n", pads[p]);
229
 
 
230
 
    R_close_driver();
231
 
 
232
 
    return 0;
233
 
}