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
|
/* ***************************************************************
* *
* * 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.
* *
* **************************************************************/
#define MAIN
#include <stdio.h>
#include <stdlib.h>
#include <tcl.h>
#include <tk.h>
#include "gis.h"
#include "display.h"
#include "raster.h"
#include "Vect.h"
#include "global.h"
#include "proto.h"
int Tcl_AppInit(Tcl_Interp* interp)
{
int ret;
char buf[1024];
ret = Tcl_Init(interp);
if (ret != TCL_OK) { return TCL_ERROR; }
ret = Tk_Init(interp);
if (ret != TCL_OK) { return TCL_ERROR; }
Toolbox = interp;
Tcl_CreateCommand(interp, "c_tool_centre", (Tcl_CmdProc*) c_tool_centre, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_next_tool", (Tcl_CmdProc*) c_next_tool, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_cancel", (Tcl_CmdProc*) c_cancel, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_set_color", (Tcl_CmdProc*) c_set_color, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_set_on", (Tcl_CmdProc*) c_set_on, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_create_table", (Tcl_CmdProc*) c_create_table, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_table_definition", (Tcl_CmdProc*) c_table_definition, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_var_set", (Tcl_CmdProc*) c_var_set, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_create_bgcmd", (Tcl_CmdProc*) c_create_bgcmd, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_set_bgcmd", (Tcl_CmdProc*) c_set_bgcmd, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_add_blank_bgcmd", (Tcl_CmdProc*) c_add_blank_bgcmd, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_del_cat", (Tcl_CmdProc*) c_del_cat, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
Tcl_CreateCommand(interp, "c_add_cat", (Tcl_CmdProc*) c_add_cat, (ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
/* Init variables */
var_init ();
/* Init snap */
var_seti ( VAR_SNAP, 1 );
var_seti ( VAR_SNAP_MODE, SNAP_SCREEN );
var_seti ( VAR_SNAP_SCREEN, 10 );
var_setd ( VAR_SNAP_MAP, 10 );
sprintf(buf,"%s/etc/v.digit/toolbox.tcl", G_gisbase());
ret = Tcl_EvalFile(interp, buf);
if ( ret == TCL_ERROR) {
if (interp->result != NULL)
sprintf(buf,"Cannot open toolbox: %s\n", interp->result);
else
sprintf(buf,"Cannot open toolbox.\n");
G_fatal_error(buf) ;
}
return TCL_OK;
}
int
main (int argc, char *argv[])
{
int i;
struct GModule *module;
struct Option *map_opt, *bgcmd_opt;
struct Flag *new_f;
char *mapset;
char **tokens;
G_gisinit(argv[0]);
map_opt = G_define_standard_option(G_OPT_V_MAP);
bgcmd_opt = G_define_option();
bgcmd_opt->key = "bgcmd";
bgcmd_opt->type = TYPE_STRING;
bgcmd_opt->required = NO;
bgcmd_opt->multiple = NO;
bgcmd_opt->answer = "";
bgcmd_opt->description = "d.* commands to be used for background separated by ';'";
new_f = G_define_flag ();
new_f->key = 'n';
new_f->description = "Create new file if it does not exist.";
if (G_parser (argc, argv)) exit(-1);
module = G_define_module();
module->description = "Edit GRASS vector.";
G_debug (2, "Variable = %p", Variable );
/* Read background commands */
if ( bgcmd_opt->answer ) {
tokens = G_tokenize (bgcmd_opt->answer, ";");
for (i = 0; tokens[i] != NULL ; i++) {
G_debug (2, "cmd %d : %s", i, tokens[i]);
bg_add ( tokens[i] );
}
G_free_tokens (tokens);
}
for ( i = 0; i < nbgcmd; i++ ) G_debug (2, "cmd %d : %s", i, Bgcmd[i]);
Tool_next = TOOL_NOTHING;
G_get_window(&Region);
G_debug (1, "Region: N = %f S = %f E = %f W = %f", Region.north, Region.south, Region.east, Region.west);
/* Check driver */
if (R_open_driver() != 0) G_fatal_error ("No graphics device selected");
R_close_driver();
G_debug (1, "Driver opened");
/* Open map */
mapset = G_find_vector2 (map_opt->answer, G_mapset());
if ( mapset == NULL ) {
fprintf (stderr, "Map does not exist.\n");
if ( new_f->answer ) {
fprintf (stderr, "New empty map created.\n");
Vect_open_new (&Map, map_opt->answer, 0 );
Vect_build ( &Map, NULL );
Vect_close (&Map);
Vect_open_update (&Map, map_opt->answer, G_mapset());
} else {
exit ( 1 );
}
} else {
Vect_set_open_level(2);
Vect_open_update (&Map, map_opt->answer, mapset);
}
Vect_set_category_index_update ( &Map );
Vect_hist_command ( &Map );
G_debug (1, "Map opened");
/* Init maximum categories */
cat_init ();
/* Init symbology for lines and nodes */
symb_lines_init ();
symb_nodes_init ();
/* Display the map */
symb_init ();
G_get_window(&window);
driver_open ();
display_erase ();
display_bg ();
display_map ();
driver_close ();
G_get_window(&window);
/* Open toolbox */
Tk_Main(0, argv, Tcl_AppInit);
/* Not reached */
exit(0) ;
}
int
end ( void )
{
G_debug (1, "end()");
Vect_build_partial (&Map, GV_BUILD_NONE, NULL);
Vect_build ( &Map, stdout );
Vect_close (&Map);
return 1;
}
|