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 222 223 224 225 226 227 228 229 230
|
/* ***************************************************************
* *
* * MODULE: v.digit
* *
* * AUTHOR(S): Radim Blazek
* *
* * PURPOSE: Edit vector
* *
* * COPYRIGHT: (C) 2001 by the GRASS Development Team
* *
* * This program is free software under the
* * GNU General Public License (>=v2).
* * Read the file COPYING that comes with GRASS
* * for details.
* *
* **************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gis.h"
#include "colors.h"
#include "raster.h"
#include "display.h"
#include "global.h"
#include "proto.h"
/* init variables
*/
void
var_init ( void )
{
G_debug (2, "var_init" );
G_debug (2, "Variable = %p", Variable );
/* Note: important is that VAR_CMODE is set last, because if it is CAT_MODE_NEXT
* previously set VAR_CAT is automaticaly reset to 'next not used' for current field */
var_seti ( VAR_CAT, 1 );
var_seti ( VAR_FIELD, 1 );
var_seti ( VAR_CAT_MODE, CAT_MODE_NEXT );
var_seti ( VAR_INSERT, 1 );
}
/* set variable value by code
* return 0 ok
* -1 error
*/
int
var_seti ( int code, int iv )
{
int i, cat;
G_debug (5, "var_seti(): code = %d val = %d", code, iv );
i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) {
Variable[i].i = iv;
/* Some variables requires extra actions */
if ( (code == VAR_FIELD && var_geti(VAR_CAT_MODE) == CAT_MODE_NEXT) ) {
cat = cat_max_get ( var_geti(VAR_FIELD) ) + 1;
var_seti ( VAR_CAT, cat );
}
if ( code == VAR_CAT_MODE ) {
if ( var_geti(VAR_CAT_MODE) == CAT_MODE_NEXT ) {
cat = cat_max_get ( var_geti(VAR_FIELD) ) + 1;
var_seti ( VAR_CAT, cat );
}
i_set_cat_mode();
}
i_var_seti ( code, iv); /* if called from C GUI is reset, */
/* if originaly called from GUI it is reset in GUI second time */
return 0;
}
i++;
}
G_warning ("Cannot set variable code = %d", code );
return -1;
}
/* set variable value by code
* return 0 ok
* -1 error
*/
int
var_setd ( int code, double d )
{
int i;
i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) {
Variable[i].d = d;
i_var_setd ( code, d);
return 0;
}
i++;
}
G_warning ("Cannot set variable code = %d", code );
return -1;
}
/* set variable value by code
* return 0 ok
* -1 error
*/
int
var_setc ( int code, char *c )
{
int i;
i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) {
Variable[i].c = G_store ( c );
i_var_setc ( code, c);
return 0;
}
i++;
}
G_warning ("Cannot set variable code = %d", code );
return -1;
}
/* get variable type
* return type
* -1 not found
*/
int
var_get_type_by_name ( char *name )
{
int i;
G_debug (5, "var_get_type_by_name()" );
i = 0;
while ( Variable[i].name ) {
if ( strcmp ( name, Variable[i].name) == 0 ) { return (Variable[i].type); }
i++;
}
G_warning ("Cannot get type of variable %s", name );
return -1;
}
/* get variable type
* return type
* -1 not found
*/
int
var_get_code_by_name ( char *name )
{
int i;
G_debug (5, "var_get_code_by_name()" );
i = 0;
while ( Variable[i].name ) {
if ( strcmp ( name, Variable[i].name) == 0 ) { return (Variable[i].code); }
i++;
}
G_warning ("Cannot get code of variable %s", name );
return -1;
}
/* get pointer to variable name
* return pointer to name or NULL
*/
char *
var_get_name_by_code ( int code )
{
int i;
G_debug (5, "var_get_name_by_code()" );
i = 0;
while ( Variable[i].name ) {
if ( Variable[i].code == code ) { return ( Variable[i].name ) ; }
i++;
}
G_warning ("Cannot get name of variable %d", code );
return NULL;
}
/* get variable value */
int
var_geti ( int code )
{
int i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) { return ( Variable[i].i ); }
i++;
}
G_warning ("Cannot get value of variable code = %d", code );
return 0;
}
/* get variable value */
double
var_getd ( int code )
{
int i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) { return ( Variable[i].d ); }
i++;
}
G_warning ("Cannot get value of variable code = %d", code );
return 0;
}
/* get variable value */
char *
var_getc ( int code )
{
int i = 0;
while ( Variable[i].name ) {
if ( code == Variable[i].code ) { return ( Variable[i].c ); }
i++;
}
G_warning ("Cannot get value of variable code = %d", code );
return NULL;
}
|