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

« back to all changes in this revision

Viewing changes to display/d.info/main.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:
4
4
 * MODULE:       d.info
5
5
 * AUTHOR(S):    Glynn Clements
6
6
 * PURPOSE:      Display information about the active display monitor
7
 
 * COPYRIGHT:    (C) 2004 by the GRASS Development Team
 
7
 * COPYRIGHT:    (C) 2004, 2012 by the GRASS Development Team
8
8
 *
9
9
 *               This program is free software under the GNU General Public
10
10
 *               License (>=v2). Read the file COPYING that comes with GRASS
15
15
#include <stdlib.h>
16
16
#include <stdio.h>
17
17
#include <grass/gis.h>
18
 
#include <grass/raster.h>
19
18
#include <grass/display.h>
20
19
#include <grass/glocale.h>
21
20
 
22
21
int main(int argc, char *argv[])
23
22
{
24
23
    struct GModule *module;
25
 
    struct Flag *rflag, *dflag, *cflag, *fflag, *bflag, *gflag;
26
 
    int l, r, t, b;
27
 
    double n, s, e, w;
28
 
    char window_name[128];
29
 
    struct Cell_head window;
 
24
    struct Flag *rflag, *dflag, *fflag, *eflag, *bflag, *gflag;
 
25
    double st, sb, sl, sr;
 
26
    double ft, fb, fl, fr;
30
27
 
31
28
    G_gisinit(argv[0]);
32
29
 
33
30
    module = G_define_module();
34
 
    module->keywords = _("display, metadata");
 
31
    G_add_keyword(_("display"));
 
32
    G_add_keyword(_("graphics"));
 
33
    G_add_keyword(_("monitors"));
 
34
    module->label =
 
35
        _("Displays information about the active display monitor.");
35
36
    module->description =
36
 
        _("Display information about the active display monitor");
 
37
        _("Display monitors are maintained by d.mon.");
37
38
 
38
39
    rflag = G_define_flag();
39
40
    rflag->key = 'r';
48
49
    fflag->key = 'f';
49
50
    fflag->description = _("Display active frame rectangle");
50
51
 
 
52
    eflag = G_define_flag();
 
53
    eflag->key = 'e';
 
54
    eflag->description = _("Display frame dimensions (width, height)");
 
55
 
51
56
    bflag = G_define_flag();
52
57
    bflag->key = 'b';
53
58
    bflag->description = _("Display screen rectangle of current region");
55
60
    gflag = G_define_flag();
56
61
    gflag->key = 'g';
57
62
    gflag->description =
58
 
        _("Display geographic coordinates and resolution of entire screen");
59
 
 
60
 
    cflag = G_define_flag();
61
 
    cflag->key = 'c';
62
 
    cflag->description = _("Display number of colors");
63
 
 
64
 
    if (argc > 1 && G_parser(argc, argv))
65
 
        exit(EXIT_FAILURE);
66
 
 
67
 
    if (!rflag->answer && !dflag->answer && !cflag->answer &&
68
 
        !fflag->answer && !bflag->answer && !gflag->answer) {
69
 
        G_usage();
70
 
        exit(EXIT_FAILURE);
71
 
    }
72
 
 
73
 
    if (R_open_driver() != 0)
74
 
        G_fatal_error(_("No graphics device selected"));
75
 
 
76
 
    if (rflag->answer || dflag->answer) {
77
 
        l = R_screen_left();
78
 
        r = R_screen_rite();
79
 
        t = R_screen_top();
80
 
        b = R_screen_bot();
81
 
    }
 
63
        _("Display geographic coordinates and resolution of entire frame");
 
64
 
 
65
    G_option_required(rflag, dflag, fflag, eflag, bflag, gflag, NULL); 
 
66
 
 
67
    if (G_parser(argc, argv))
 
68
        exit(EXIT_FAILURE);
 
69
 
 
70
    D_open_driver();
 
71
    
 
72
    if (rflag->answer || dflag->answer)
 
73
        D_get_screen(&st, &sb, &sl, &sr);
 
74
    
 
75
    if (fflag->answer || eflag->answer || gflag->answer)
 
76
        D_get_frame(&ft, &fb, &fl, &fr);
 
77
 
82
78
 
83
79
    if (rflag->answer)
84
 
        fprintf(stdout, "rectangle: %d %d %d %d\n", l, r, t, b);
 
80
        fprintf(stdout, "screen rectangle: %f %f %f %f\n", sl, sr, st, sb);
85
81
 
86
82
    if (dflag->answer)
87
 
        fprintf(stdout, "dimensions: %d %d\n", r - l, b - t);
88
 
 
89
 
    if (cflag->answer) {
90
 
        int colors;
91
 
 
92
 
        R_get_num_colors(&colors);
93
 
        fprintf(stdout, "colors: %d\n", colors);
94
 
    }
95
 
 
96
 
    if (fflag->answer) {
97
 
        D_get_screen_window(&t, &b, &l, &r);
98
 
        fprintf(stdout, "frame: %d %d %d %d\n", l, r, t, b);
99
 
    }
 
83
        fprintf(stdout, "screen dimensions: %f %f\n", sr - sl, sb - st);
 
84
 
 
85
    if (fflag->answer)
 
86
        fprintf(stdout, "frame rectangle: %f %f %f %f\n", fl, fr, ft, fb);
 
87
 
 
88
    if (eflag->answer)
 
89
        fprintf(stdout, "frame dimensions: %f %f\n", fr - fl, fb - ft);
100
90
 
101
91
    if (bflag->answer) {
102
 
        if (D_get_cur_wind(window_name))
103
 
            G_fatal_error(_("No current window"));
104
 
        if (D_set_cur_wind(window_name))
105
 
            G_fatal_error(_("Current window not available"));
106
 
 
107
 
        /* Read in the map window associated with window */
108
 
        G_get_window(&window);
109
 
 
110
 
        if (D_check_map_window(&window))
111
 
            G_fatal_error(_("Setting map window"));
112
 
        if (D_get_screen_window(&t, &b, &l, &r))
113
 
            G_fatal_error(_("Getting screen window"));
114
 
        if (D_do_conversions(&window, t, b, l, r))
115
 
            G_fatal_error(_("Error in calculating conversions"));
 
92
        double t, b, l, r;
 
93
        D_setup(0);
116
94
 
117
95
        l = D_get_d_west();
118
96
        r = D_get_d_east();
119
97
        t = D_get_d_north();
120
98
        b = D_get_d_south();
121
99
 
122
 
        fprintf(stdout, "region: %d %d %d %d\n", l, r, t, b);
 
100
        fprintf(stdout, "region: %f %f %f %f\n", l, r, t, b);
123
101
    }
124
102
 
125
103
    if (gflag->answer) {
126
 
        /* outer bounds of the screen (including white bands) */
127
 
 
128
 
        if (D_get_cur_wind(window_name))
129
 
            G_fatal_error(_("No current window"));
130
 
        if (D_set_cur_wind(window_name))
131
 
            G_fatal_error(_("Current window not available"));
132
 
 
133
 
        G_get_window(&window);
134
 
 
135
 
        if (D_check_map_window(&window))
136
 
            G_fatal_error(_("Setting map window"));
137
 
        if (D_get_screen_window(&t, &b, &l, &r))
138
 
            G_fatal_error(_("Getting screen window"));
139
 
        if (D_do_conversions(&window, t, b, l, r))
140
 
            G_fatal_error(_("Error in calculating conversions"));
141
 
 
142
 
        n = D_d_to_u_row((double)t);
143
 
        s = D_d_to_u_row((double)b);
144
 
        w = D_d_to_u_col((double)l);
145
 
        e = D_d_to_u_col((double)r);
 
104
        /* outer bounds of the screen (including margins) */
 
105
        double n, s, e, w;
 
106
        D_setup(0);
 
107
 
 
108
        n = D_d_to_u_row(ft);
 
109
        s = D_d_to_u_row(fb);
 
110
        w = D_d_to_u_col(fl);
 
111
        e = D_d_to_u_col(fr);
146
112
 
147
113
        fprintf(stdout, "n=%f\n", n );
148
114
        fprintf(stdout, "s=%f\n", s );
149
115
        fprintf(stdout, "w=%f\n", w );
150
116
        fprintf(stdout, "e=%f\n", e );
151
 
        fprintf(stdout, "ewres=%.15g\n", (e-w)/(r-l) );
152
 
        fprintf(stdout, "nsres=%.15g\n", (n-s)/(b-t) );
 
117
        fprintf(stdout, "ewres=%.15g\n",  D_get_d_to_u_xconv() );
 
118
        fprintf(stdout, "nsres=%.15g\n", -D_get_d_to_u_yconv() );
153
119
    }
154
120
 
155
 
    R_close_driver();
 
121
    
 
122
    D_close_driver();
156
123
 
157
 
    return EXIT_SUCCESS;
 
124
    exit(EXIT_SUCCESS);
158
125
}