1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/* $Id: display.c,v 1.9 2004/02/09 03:51:04 hamish Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include "gis.h"
#include "Vect.h"
#include "raster.h"
#include "display.h"
#include "D.h"
#include "colors.h"
#include "global.h"
#include "proto.h"
/* --- DISLAY ---
* For all display functions the display driver must be opened first.
* Because some functions like erase() call other grass commands, driver is closed
* and reopened within these functions
*/
/* Display points */
void display_points ( struct line_pnts *Points, int flsh )
{
int i;
G_debug (2, "display_points()");
for(i=1; i < Points->n_points; i++) {
G_plot_line ( Points->x[i-1], Points->y[i-1], Points->x[i], Points->y[i]);
}
if ( flsh ) R_flush();
}
/* Display icon */
void display_icon ( double x, double y, int icon, double angle, int size , int flsh )
{
G_debug (2, "display_icon()");
G_plot_icon(x, y, icon, angle, Scale * size);
if ( flsh ) R_flush();
}
/* Display vector line
* color : code from SymbNumber
*
* ! This function doesn't check Symb[symb].on so that new digitized line is displayed even
* if its symbology is switched off (that means incorrect and user friendly)
*/
void display_line ( int line, int color, int flsh )
{
int type, symb;
static struct line_pnts *Points;
static struct line_cats *Cats;
static int first = 1;
G_debug (2, "display_line(): line = %d color = %d", line, color );
if ( first ) {
Points = Vect_new_line_struct ();
Cats = Vect_new_cats_struct ();
first = 0;
}
if ( !Vect_line_alive ( &Map, line ) ) return;
type = Vect_read_line ( &Map, Points, Cats, line);
if ( color == SYMB_DEFAULT ) symb = LineSymb[line];
else symb = color;
symb_set_driver_color ( symb );
if ( type & GV_POINTS ) display_icon ( Points->x[0], Points->y[0], G_ICON_CROSS, 0, 6, flsh);
else display_points ( Points, flsh );
}
/* Redraw updated lines */
void
display_updated_lines ( int symb )
{
int i, line;
for ( i = 0; i < Vect_get_num_updated_lines(&Map); i++ ) {
line = Vect_get_updated_line( &Map, i );
if ( !Vect_line_alive ( &Map, line ) ) continue;
display_line ( line, symb, 0 );
}
R_flush();
}
/* Display node, color may be given but shape and size is read from symbology table,
* this is useful to delete (redraw by background) existing node
*
* color : code from SymbNumber
*/
void display_node ( int node, int color, int flsh )
{
int symb;
double x, y;
G_debug (2, "display_node(): node = %d color = %d", node, color );
if ( !Vect_node_alive ( &Map, node ) ) return;
if ( color == SYMB_DEFAULT ) symb = NodeSymb[node];
else symb = color;
symb_set_driver_color ( symb );
Vect_get_node_coor ( &Map, node, &x, &y, NULL);
display_icon ( x, y, G_ICON_CROSS, 0.785, 6, flsh);
}
/* Redraw updated nodes */
void
display_updated_nodes ( int symb )
{
int i, node;
if ( symb != SYMB_DEFAULT ) symb_set_driver_color ( symb );
for ( i = 0; i < Vect_get_num_updated_nodes(&Map); i++ ) {
node = Vect_get_updated_node( &Map, i );
if ( !Vect_node_alive ( &Map, node ) ) continue;
if ( NodeSymb[node] == SYMB_NODE_0 ) continue;
display_node ( node, symb, 0);
}
R_flush();
}
/* Display vector map */
void display_map ( void )
{
int i, n, symb;
G_debug (2, "display_map()");
/* Because after resize of monitor we expect manual call to display_map()
* it is good to refresh D_* here */
driver_refresh ();
/* Lines */
n = Vect_get_num_lines ( &Map );
symb_set_driver_color ( SYMB_HIGHLIGHT );
for(i=1; i <= n; i++) {
symb = LineSymb[i];
G_debug (2, "symb = %d", symb);
if ( !Symb[symb].on ) continue;
display_line ( i , SYMB_DEFAULT, 0 );
}
R_flush();
/* Nodes: first nodes with more than 1 line, then nodes with only 1 line,
* so that dangles are not hidden, and nodes without lines (points,
* centroids, are displayed) */
n = Vect_get_num_nodes ( &Map );
if ( Symb[SYMB_NODE_2].on ) {
symb_set_driver_color ( SYMB_NODE_2 );
for(i=1; i <= n; i++) {
if ( !Vect_node_alive ( &Map, i) ) continue;
if ( NodeSymb[i] != SYMB_NODE_2 ) continue;
display_node(i, NodeSymb[i], 0);
}
R_flush();
}
if ( Symb[SYMB_NODE_1].on ) {
symb_set_driver_color ( SYMB_NODE_1 );
for(i=1; i <= n; i++) {
G_debug ( 2, "node = %d NodeSymb = %d", i, NodeSymb[i]);
if ( !Vect_node_alive ( &Map, i) ) continue;
if ( NodeSymb[i] != SYMB_NODE_1 ) continue;
display_node(i, NodeSymb[i], 0);
}
R_flush();
}
}
/* Display bacground */
void display_bg ( void )
{
int i;
G_debug (2, "display_bg()");
driver_close();
for(i=0; i < nbgcmd; i++) {
if ( Bgcmd[i].on )
system ( Bgcmd[i].cmd );
}
driver_open();
}
/* Erase */
void display_erase ( void )
{
char command[128];
driver_close();
sprintf(command, "d.erase color=white");
system( command ); /* It does everything and command is registered */
driver_open();
/* As erase must be run after each zoom by v.digit, here is good place to reset plot.
* Other such place is display_map() */
driver_refresh ();
}
/* Redraw */
void display_redraw ( void )
{
display_erase ();
display_bg();
display_map();
}
|