1 /******************************************************************************
2 * $Id: fgisInit.c,v 1.3 2003-01-08 09:50:05 dron Exp $
4 * Project: fGIS core engine
5 * Purpose: initialization procedure for Fgis package
7 ******************************************************************************
9 * Copyright (C) 1997, Victor Wagner <vitus@ice.ru>
10 * Copyright (C) 2003, Andrey Kiselev <dron@remotesensing.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 *****************************************************************************
38 int check_for_rc(Tcl_Interp *interp,char *home,char *path);
39 /* Global variables */
42 * Initialization procedure for Environmental Planning Tcl extension
43 * Return value TCL_OK if success
45 * defines commands raster vector palette fgisPlanchet_mapx fgisPlanchet_mapy
46 * fgisPlanchet_scrx fgisPlanchet_scry fgisPlanchet_fit defaultpalette
47 * defines default (1:1) reclass table
48 * defines fGIS_HOME variable to directory, containing fgis.rc
49 * Directories are searched in following order
50 * FGIS_CONFDIR as defined in Makefile
54 EXPORT(int, Fgis_Init)(Tcl_Interp *interp)
58 /* Defining commands */
61 if (!Tcl_CreateCommand(interp,"palette",Fgis_Palette,NULL,
64 if (!Tcl_CreateCommand(interp,"defaultpalette",Fgis_PaletteObj,
65 (ClientData)default_palette,Fgis_DeletePalette))
68 if (!Tcl_CreateCommand(interp,"patterns",Fgis_CreatePatterns,
69 NULL,Fgis_DefDeleteProc))
72 if (!Tcl_CreateCommand(interp,"raster",Fgis_Raster,
73 NULL,Fgis_DeleteRaster))
76 if (!Tcl_CreateCommand(interp,"vector",Fgis_Vector,NULL,Fgis_DefDeleteProc))
78 /* Tk dependent fgis commands. Should eventually go into separate package*/
80 if (!Tcl_CreateCommand(interp,"fgisRasterColorImage",Fgis_RasterImage,
81 (ClientData)1,Fgis_DefDeleteProc)) return TCL_ERROR;
82 if (!Tcl_CreateCommand(interp,"fgisRasterBWImage",Fgis_RasterImage,
83 NULL,Fgis_DefDeleteProc)) return TCL_ERROR;
84 /* planchet widget subcommands, written on C */
85 if (!Tcl_CreateCommand(interp,"fgisPlanchet_mapx",Fgis_MapX,NULL,
88 if (!Tcl_CreateCommand(interp,"fgisPlanchet_mapy",Fgis_MapY,NULL,
92 if (!Tcl_CreateCommand(interp,"fgisPlanchet_scrx",Fgis_ScrX,NULL,
95 if (!Tcl_CreateCommand(interp,"fgisPlanchet_scry",Fgis_ScrY,NULL,
98 if (!Tcl_CreateCommand(interp,"fgisPlanchet_fit",Fgis_Fit,NULL,
101 if (!Tcl_CreateCommand(interp,"projection",Fgis_Projection,NULL,
105 /* Searching for fgis.rc and executing it */
106 /* First, check if fGIS_HOME already set */
107 if ((fGIS_HOME=Tcl_GetVar(interp,"fGIS_HOME",TCL_GLOBAL_ONLY))==NULL) {
109 /* Check if compilied in default is valid */
110 if (!check_for_rc(interp,fGIS_HOME,FGIS_CONFDIR)&&
112 !check_for_rc(interp,fGIS_HOME,"/usr/local/lib/fgis")&&
113 !check_for_rc(interp,fGIS_HOME,"/usr/lib/fgis")&&
114 !check_for_rc(interp,fGIS_HOME,"~/fgis")
116 !check_for_rc(interp,fGIS_HOME,"C:/FGIS") &&
117 !check_for_rc(interp,fGIS_HOME,"C:/Program Files/fGIS") &&
118 !check_for_rc(interp,fGIS_HOME,"C:/TCL/LIB/fGIS")
121 Tcl_SetResult(interp,"Cannot determine fGIS home directory",
125 Tcl_SetVar(interp,"fGIS_HOME",fGIS_HOME,TCL_GLOBAL_ONLY);
128 if (Tcl_EvalFile(interp,FGIS_CONFDIR "/fgis.rc")!=TCL_OK) {
129 Tcl_SetResult(interp,"Error in initialization file",TCL_STATIC);
132 /* Providing package for Tcl versions, which supports it */
133 #if (TCL_MAJOR_VERSION>7)||((TCL_MAJOR_VERSION==7)&&(TCL_MINOR_VERSION>=5))
134 Tcl_PkgProvide(interp,"Fgis","0.1");
139 int check_for_rc (Tcl_Interp *interp,char *home,char *path)
142 sprintf(buffer,"file readable [file join {%s} fgis.rc]",path);
143 Tcl_Eval(interp,buffer);
144 if (Tcl_GetInt(interp,interp->result,&result)==TCL_OK&& result) {