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

« back to all changes in this revision

Viewing changes to lib/display/setup.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
 
/* D_setup (clear)
2
 
 *
3
 
 * This is a high level D call.
4
 
 * It does a full setup for the current graphics frame.
5
 
 *
6
 
 *   1. Makes sure there is a current graphics frame
7
 
 *      (will create a full-screen one, if not
8
 
 *   2. Sets the region coordinates so that the graphics frame
9
 
 *      and the active program region agree
10
 
 *      (may change active program region to do this).
11
 
 *   3. Performs graphic frame/region coordinate conversion intialization
12
 
 *
13
 
 * Returns: 0 if ok. Exits with error message if failure.
14
 
 *
15
 
 * Note: Connection to driver must already be made.
16
 
 *
17
 
 * clear values:
18
 
 *   1: clear frame (visually and coordinates)
19
 
 *   0: do not clear frame
20
 
 */
 
1
/*!
 
2
  \file lib/display/setup.c
 
3
 
 
4
  \brief Display Driver - setup
 
5
 
 
6
  (C) 2006-2011 by the GRASS Development Team
 
7
 
 
8
  This program is free software under the GNU General Public License
 
9
  (>=v2). Read the file COPYING that comes with GRASS for details.
 
10
 
 
11
  \author Glynn Clements <glynn gclements.plus.com> (original contributor)
 
12
  \author Huidae Cho <grass4u gmail.com>
 
13
*/
 
14
 
21
15
#include <string.h>
22
16
#include <grass/gis.h>
 
17
#include <grass/raster.h>
23
18
#include <grass/display.h>
24
 
#include <grass/raster.h>
25
 
 
26
 
 
27
 
/*!
28
 
 * \brief initialize/create a frame
29
 
 *
30
 
 * This routine
31
 
 * performs a series of initialization steps for the current frame. It also
32
 
 * creates a full screen frame if there is no current frame. The <b>clear</b>
33
 
 * flag, if set to 1, tells this routine to clear any information associated with
34
 
 * the frame: graphics as well as region information.
35
 
 * This routine relieves the programmer of having to perform the following
36
 
 * idiomatic function call sequence
37
 
 *
38
 
 *  \param clear
39
 
 *  \return int
40
 
 */
41
 
 
42
 
 
43
 
/*!
44
 
 * \brief graphics frame setup
45
 
 *
46
 
 * Performs a full setup
47
 
 * for the current graphics frame: 1) Makes sure there is a current graphics
48
 
 * frame (will create a full-screen one, if not); 2) Sets the region coordinates
49
 
 * so that the graphics frame and the active module region agree (may change
50
 
 * active module region to do this); and 3) performs graphic frame/region
51
 
 * coordinate conversion initialization.
52
 
 * If <b>clear</b> is true, the frame is cleared (same as running
53
 
 * <i>d.erase.</i>) Otherwise, it is not cleared.
54
 
 *
55
 
 *  \param clear
56
 
 *  \return int
57
 
 */
58
 
 
59
 
int D_setup(int clear)
 
19
 
 
20
#include "driver.h"
 
21
 
 
22
/*!
 
23
  \brief Graphics frame setup
 
24
 
 
25
  This is a high level D call. It does a full setup for the current
 
26
  graphics frame.
 
27
 
 
28
  Note: Connection to driver must already be made.
 
29
  
 
30
  Sets the source coordinate system to the current region, and
 
31
  adjusts the destination coordinate system to preserve the aspect
 
32
  ratio.
 
33
  
 
34
  Performs a full setup for the current graphics frame:
 
35
  - Makes sure there is a current graphics frame (will create a full-screen
 
36
  one, if not);
 
37
  - Sets the region coordinates so that the graphics frame and the active
 
38
  module region agree (may change active module region to do this); and  
 
39
  - Performs graphic frame/region coordinate conversion initialization.
 
40
 
 
41
  If <b>clear</b> is true, the frame is cleared (same as running
 
42
  <i>d.erase</i>.) Otherwise, it is not cleared.
 
43
 
 
44
  \param clear 1 to clear frame (visually and coordinates)
 
45
*/
 
46
void D_setup(int clear)
60
47
{
61
48
    struct Cell_head region;
62
 
    char name[128];
63
 
    int t, b, l, r;
64
 
 
65
 
    if (D_get_cur_wind(name)) {
66
 
        t = R_screen_top();
67
 
        b = R_screen_bot();
68
 
        l = R_screen_left();
69
 
        r = R_screen_rite();
70
 
        strcpy(name, "full_screen");
71
 
        D_new_window(name, t, b, l, r);
72
 
    }
73
 
 
74
 
    if (D_set_cur_wind(name))
75
 
        G_fatal_error("Current graphics frame not available");
76
 
    if (D_get_screen_window(&t, &b, &l, &r))
77
 
        G_fatal_error("Getting graphics coordinates");
78
 
 
79
 
    /* clear the frame, if requested to do so */
80
 
    if (clear) {
81
 
        D_clear_window();
82
 
        R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
83
 
        R_box_abs(l, t, r, b);
84
 
    }
85
 
 
86
 
    /* Set the map region associated with graphics frame */
 
49
    double dt, db, dl, dr;
 
50
 
 
51
    D_get_frame(&dt, &db, &dl, &dr);
 
52
 
87
53
    G_get_set_window(&region);
88
 
    if (D_check_map_window(&region))
89
 
        G_fatal_error("Setting graphics coordinates");
90
 
    if (G_set_window(&region) < 0)
91
 
        G_fatal_error("Invalid graphics coordinates");
92
 
 
93
 
    /* Determine conversion factors */
94
 
    if (D_do_conversions(&region, t, b, l, r))
95
 
        G_fatal_error("Error calculating graphics-region conversions");
96
 
 
97
 
    /* set text clipping, for good measure */
98
 
    R_set_window(t, b, l, r);
99
 
    R_move_abs(0, 0);
100
 
    D_move_abs(0, 0);
101
 
    return 0;
 
54
    Rast_set_window(&region);
 
55
 
 
56
    D_do_conversions(&region, dt, db, dl, dr);
 
57
 
 
58
    D_set_clip_window_to_screen_window();
 
59
 
 
60
    if (clear)
 
61
        D_erase(DEFAULT_BG_COLOR);
 
62
 
 
63
    D_set_clip_window_to_map_window();
 
64
}
 
65
 
 
66
/*!
 
67
  \brief Graphics frame setup
 
68
 
 
69
  Sets the source coordinate system to match the
 
70
  destination coordinate system, so that D_* functions use the same
 
71
  coordinate system as R_* functions.
 
72
 
 
73
  If <b>clear</b> is true, the frame is cleared (same as running
 
74
  <i>d.erase</i>). Otherwise, it is not cleared.
 
75
  
 
76
  \param clear non-zero code to clear the frame
 
77
*/
 
78
void D_setup_unity(int clear)
 
79
{
 
80
    double dt, db, dl, dr;
 
81
 
 
82
    D_get_frame(&dt, &db, &dl, &dr);
 
83
 
 
84
    D_set_src(dt, db, dl, dr);
 
85
    D_set_dst(dt, db, dl, dr);
 
86
 
 
87
    D_update_conversions();
 
88
 
 
89
    D_set_clip_window_to_screen_window();
 
90
 
 
91
    if (clear)
 
92
        D_erase(DEFAULT_BG_COLOR);
 
93
 
 
94
    D_set_clip_window_to_map_window();
 
95
}
 
96
 
 
97
/*!
 
98
  \brief Sets source coordinate system
 
99
  
 
100
  Sets the source coordinate system to its arguments, and if
 
101
  the <b>fit</b> argument is non-zero, adjusts the destination coordinate
 
102
  system to preserve the aspect ratio.
 
103
  
 
104
  If <b>clear</b> is true, the frame is cleared (same as running
 
105
  <i>d.erase</i>). Otherwise, it is not cleared.
 
106
  
 
107
  \param clear non-zero code to clear the frame
 
108
  \param fit non-zero code to adjust destination coordinate system
 
109
  \param s_top
 
110
  \param s_bottom
 
111
  \param s_left
 
112
  \param s_right
 
113
*/
 
114
void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
 
115
{
 
116
    double dt, db, dl, dr;
 
117
 
 
118
    D_get_frame(&dt, &db, &dl, &dr);
 
119
 
 
120
    D_set_src(st, sb, sl, sr);
 
121
    D_set_dst(dt, db, dl, dr);
 
122
 
 
123
    if (fit)
 
124
        D_fit_d_to_u();
 
125
 
 
126
    D_update_conversions();
 
127
 
 
128
    D_set_clip_window_to_screen_window();
 
129
 
 
130
    if (clear)
 
131
        D_erase(DEFAULT_BG_COLOR);
 
132
 
 
133
    D_set_clip_window_to_map_window();
 
134
}
 
135
 
 
136
/*!
 
137
  \brief Get driver output file
 
138
 
 
139
  \return file name or NULL if not defined
 
140
*/
 
141
const char *D_get_file(void)
 
142
{
 
143
    return COM_Graph_get_file();
102
144
}