~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/photo.2image/zoom_box.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <grass/gis.h>
2
 
#include <grass/raster.h>
3
 
#include "globals.h"
4
 
 
5
 
 
6
 
static int x1, y1, x2, y2;
7
 
static View *pick_view, *zoom_view, *main_view;
8
 
static int target_flag;
9
 
static int cancel(void);
10
 
static int zoom1(int, int);
11
 
static int zoom2(int, int);
12
 
 
13
 
 
14
 
int zoom_box(void)
15
 
{
16
 
    static int use = 1;
17
 
 
18
 
    static Objects objects[] = {
19
 
        MENU("CANCEL", cancel, &use),
20
 
        INFO(" Mark first corner of window ", &use),
21
 
        OTHER(zoom1, &use),
22
 
        {0}
23
 
    };
24
 
 
25
 
    Input_pointer(objects);
26
 
    return 1;
27
 
}
28
 
 
29
 
static int zoom1(               /* called by Input_pointer */
30
 
                    int x, int y)
31
 
{                               /* called by Input_pointer */
32
 
    static int use = 1;
33
 
    static Objects objects[] = {
34
 
        MENU("CANCEL", cancel, &use),
35
 
        INFO(" Define the window ", &use),
36
 
        OTHER(zoom2, &use),
37
 
        {0}
38
 
    };
39
 
 
40
 
    /* 
41
 
     * user has marked first corner 
42
 
     * this determines which view is being zoomed
43
 
     */
44
 
    x1 = x;
45
 
    y1 = y;
46
 
 
47
 
    if (In_view(pick_view = VIEW_MAP1, x1, y1)) {
48
 
        main_view = VIEW_MAP1;
49
 
        zoom_view = VIEW_MAP1_ZOOM;
50
 
        target_flag = 0;
51
 
    }
52
 
    /*
53
 
       else if (In_view (pick_view = VIEW_MAP2, x1, y1))
54
 
       {
55
 
       if (!pick_view->cell.configured)
56
 
       return 0;    *//* ignore the mouse event *//*
57
 
       main_view = VIEW_MAP2;
58
 
       zoom_view = VIEW_MAP2_ZOOM;
59
 
       target_flag = 1;
60
 
       }
61
 
     */
62
 
    else if (In_view(pick_view = VIEW_MAP1_ZOOM, x1, y1)) {
63
 
        if (!pick_view->cell.configured)
64
 
            return 0;           /* ignore the mouse event */
65
 
        main_view = VIEW_MAP1;
66
 
        zoom_view = VIEW_MAP1_ZOOM;
67
 
        target_flag = 0;
68
 
    }
69
 
    /*
70
 
       else if (In_view (pick_view = VIEW_MAP2_ZOOM, x1, y1))
71
 
       {
72
 
       if (!pick_view->cell.configured)
73
 
       return 0;    *//* ignore the mouse event *//*
74
 
       main_view = VIEW_MAP2;
75
 
       zoom_view = VIEW_MAP2_ZOOM;
76
 
       target_flag = 1;
77
 
       }
78
 
     */
79
 
    else
80
 
        return 0;               /* ignore the mouse event */
81
 
    if (!pick_view->cell.configured)
82
 
        return 0;               /* just to be sure */
83
 
 
84
 
    return Input_box(objects, x, y);
85
 
}
86
 
 
87
 
static int zoom2(int x, int y)
88
 
{
89
 
    int top, bottom, left, right;
90
 
    int row, col;
91
 
    struct Cell_head cellhd;
92
 
 
93
 
    x2 = x;
94
 
    y2 = y;
95
 
    /* 
96
 
     * user has completed the zoom window.
97
 
     * must be in same view as first corner
98
 
     */
99
 
    if (x1 == x2 || y1 == y2)
100
 
        return 0;               /* ignore event */
101
 
    if (!In_view(pick_view, x2, y2))
102
 
        return 0;
103
 
    /*
104
 
     * ok, erase menu messages
105
 
     */
106
 
    Menu_msg("");
107
 
 
108
 
    /*
109
 
     * assign window coordinates to top,bottom,left,right
110
 
     */
111
 
    if (x1 < x2) {
112
 
        left = x1;
113
 
        right = x2;
114
 
    }
115
 
    else {
116
 
        left = x2;
117
 
        right = x1;
118
 
    }
119
 
    if (y1 < y2) {
120
 
        top = y1;
121
 
        bottom = y2;
122
 
    }
123
 
    else {
124
 
        top = y2;
125
 
        bottom = y1;
126
 
    }
127
 
 
128
 
    /* 
129
 
     * Determine the the zoom window (ie, cellhd)
130
 
     * must copy the current view cellhd first, to preserve header info
131
 
     * (such as projection, zone, and other items.)
132
 
     * compute zoom window northings,eastings, rows, cols, and resolution
133
 
     */
134
 
 
135
 
    G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));
136
 
 
137
 
    /* convert top to northing at top edge of cell
138
 
     * left to easting at left edge
139
 
     */
140
 
    col = view_to_col(pick_view, left);
141
 
    row = view_to_row(pick_view, top);
142
 
    cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
143
 
    cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);
144
 
 
145
 
    /* convert bottom to northing at bottom edge of cell
146
 
     * right to easting at right edge
147
 
     */
148
 
    col = view_to_col(pick_view, right);
149
 
    row = view_to_row(pick_view, bottom);
150
 
    cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
151
 
    cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);
152
 
 
153
 
 
154
 
    cellhd.rows = bottom - top + 1;
155
 
    cellhd.cols = right - left + 1;
156
 
    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
157
 
    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
158
 
 
159
 
    /*
160
 
     * Outline the zoom window on the main map
161
 
     * Turn previous one to grey.
162
 
     */
163
 
    if (zoom_view->cell.configured) {
164
 
        R_standard_color(GREY);
165
 
        Outline_cellhd(main_view, &zoom_view->cell.head);
166
 
    }
167
 
    R_standard_color(RED);
168
 
    Outline_cellhd(main_view, &cellhd);
169
 
 
170
 
 
171
 
    /*
172
 
     * zoom
173
 
     */
174
 
    if (target_flag)
175
 
        select_target_env();
176
 
    G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
177
 
                           zoom_view->ncols);
178
 
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
179
 
                   pick_view->cell.ns_res, pick_view->cell.ew_res);
180
 
    drawcell(zoom_view);
181
 
    select_current_env();
182
 
    display_ref_points(1);
183
 
    return 1;                   /* pop back */
184
 
}
185
 
 
186
 
 
187
 
static int cancel(void)
188
 
{
189
 
    return -1;
190
 
}