1 /*
2  * tclgeomap.h --
3  *
4  *	This header file describes the externally visible facilities of
5  *	the tclgeomap extension to Tcl.  See the tclgeomap (n) man page for
6  *	information on the commands this package adds to Tcl.
7  *
8  * Copyright (c) 2004 Gordon D. Carrie.  All rights reserved.
9  *
10  * Licensed under the Open Software License version 2.1
11  *
12  * Please address questions and feedback to user0@tkgeomap.org
13  *
14  * @(#) $Id: tclgeomap.h,v 1.33 2009/10/23 20:37:25 tkgeomap Exp $
15  *
16  ********************************************
17  *
18  */
19 
20 #ifndef _TCLGEOMAP
21 #define _TCLGEOMAP
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <math.h>
27 #include <assert.h>
28 #include <limits.h>
29 #include <float.h>
30 #ifdef __WIN32__
31 #include <rpc.h>
32 #include <xdr.h>
33 #else
34 #include <rpc/rpc.h>
35 #endif
36 
37 #include <tcl.h>
38 
39 #include "geography.h"
40 #include "geoProj.h"
41 #include "geoLines.h"
42 #include "mapLines.h"
43 
44 #define TCLGEOMAP_MAJOR_VERSION 2
45 #define TCLGEOMAP_MINOR_VERSION 11
46 #define TCLGEOMAP_PATCH_LEVEL 5
47 #define TCLGEOMAP_VERSION "2.11.6"
48 
49 /*
50  * The following declarations export generic geography functions in Tcl.
51  */
52 
53 EXTERN Tcl_Obj *	Tclgeomap_NewGeoPtObj _ANSI_ARGS_((GeoPt geoPt));
54 EXTERN void		Tclgeomap_SetGeoPtObj _ANSI_ARGS_((Tcl_Obj *ptr,
55 				GeoPt geoPt));
56 EXTERN int		Tclgeomap_GetGeoPtFromObj _ANSI_ARGS_((
57 				Tcl_Interp *interp, Tcl_Obj *objPtr,
58 				GeoPt *geoPtPtr));
59 EXTERN Tcl_Obj *	Tclgeomap_NewMapPtObj _ANSI_ARGS_((MapPt mapPt));
60 EXTERN void		Tclgeomap_SetMapPtObj _ANSI_ARGS_((Tcl_Obj *ptr,
61 				MapPt mapPt));
62 EXTERN int		Tclgeomap_GetMapPtFromObj _ANSI_ARGS_((
63 				Tcl_Interp *interp, Tcl_Obj *objPtr,
64 				MapPt *mapPtPtr));
65 EXTERN Tcl_Obj *	Tclgeomap_NewGeoTimeObj _ANSI_ARGS_((
66 				struct GeoTime_Jul jul));
67 EXTERN void		Tclgeomap_SetGeoTimeObj _ANSI_ARGS_((Tcl_Obj *ptr,
68 				struct GeoTime_Jul jul));
69 EXTERN int		Tclgeomap_GetGeoTimeFromObj _ANSI_ARGS_((
70 				Tcl_Interp *interp, Tcl_Obj *objPtr,
71 				struct GeoTime_Jul *julPtr));
72 
73 /*
74  * The following structure manages geographic projections in Tcl.  It is
75  * derived from the GeoProj structure declared in geoProj.h, so functions
76  * that take pointers to GeoProj structures can also accept pointers to
77  * Tclgeomap_Proj structures.
78  */
79 
80 struct Tclgeomap_Proj {
81     struct GeoProj proj;	/* Geographic projection */
82     Tcl_Interp *interp;		/* Interpreter in which the command
83 				 * corresponding to the projection resides */
84     Tcl_Command cmd;		/* Tcl command for the projection */
85     Tcl_HashTable updateTasks;	/* Procedures to call when the projection
86 				 * changes.  ONE_WORD_KEYS are clientData's.
87 				 * Values are procedures of form
88 				 * void (*updateProc)(ClientData clientData).
89 				 * The update procedures are called with their
90 				 * clientData values as arguments when the
91 				 * projection changes. */
92     Tcl_HashTable deleteTasks;	/* Procedures to call when the projection is
93 				 * deleted.  Entries are added with calls to
94 				 * Tclgeomap_AddProjDeleteTask.  ONE_WORD_KEYS
95 				 * are clientData's.  Values are
96 				 * Tclgeomap_ProjDeleteProcs. */
97 };
98 typedef struct Tclgeomap_Proj *Tclgeomap_Proj;
99 
100 typedef void (Tclgeomap_ProjUpdateProc)(ClientData clientData);
101 typedef void (Tclgeomap_ProjDeleteProc)(ClientData clientData);
102 
103 EXTERN Tclgeomap_Proj	Tclgeomap_GetProj _ANSI_ARGS_((Tcl_Interp *interp,
104 				char *name));
105 EXTERN CONST char *	Tclgeomap_ProjName _ANSI_ARGS_((Tclgeomap_Proj proj));
106 EXTERN void		Tclgeomap_AddProjUpdateTask _ANSI_ARGS_((
107 				Tclgeomap_Proj proj,
108 				Tclgeomap_ProjUpdateProc updateProc,
109 				ClientData clientData));
110 EXTERN void		Tclgeomap_CnxProjUpdateTask _ANSI_ARGS_((Tclgeomap_Proj,
111 				ClientData clientData));
112 EXTERN void		Tclgeomap_AddProjDeleteTask _ANSI_ARGS_((
113 				Tclgeomap_Proj, Tclgeomap_ProjDeleteProc,
114 				ClientData));
115 EXTERN void		Tclgeomap_CnxProjDeleteTask _ANSI_ARGS_((
116 				Tclgeomap_Proj, ClientData));
117 
118 /*
119  * This structures stores a GeoLnArr structure with information needed to
120  * manage a GeoLnArr struct  in Tcl.  Pointers to Tclgeomap_LnArr structures
121  * can be used as parameters in the procedures declared in this file, and also
122  * in * procedures declared in geoLines.h that take pointers to GeoLnArr
123  * structures.  Clients should not access members directly.  The structure
124  * declaration is visible for to enable inheritance and to ease debugging.
125  */
126 
127 struct Tclgeomap_LnArr {
128     struct GeoLnArr geoLnArr;	/* The geolinearray.  See geoLines.h
129 				 * for contents */
130     Tcl_Interp *interp;		/* Interpreter in which the command
131 				 * corresponding to the geolinearray resides */
132     Tcl_Command cmd;		/* Tcl command for the array */
133     Tcl_HashTable mapLnArrs;	/* This table stores mapline arrays derived
134 				 * from geoLnArr. Keys are projections.
135 				 * Values are MapLnArr's obtained from the
136 				 * geolinearray with the projection. */
137     Tcl_HashTable deleteTasks;	/* Table of deletion procs to call when the
138 				 * tclgeolinearray is deleted.  Entries to this
139 				 * table are added with calls to
140 				 * Tclgeomap_AddLnArrDeleteTask.
141 				 * ONE_WORD_KEYS are clientData's and values
142 				 * are Tclgeomap_LnArrDeleteProc's given as
143 				 * arguments Tclgeomap_AddLnArrDeleteTask.
144 				 */
145 };
146 typedef struct Tclgeomap_LnArr *Tclgeomap_LnArr;
147 
148 /*
149  * Procedure type:
150  */
151 
152 typedef void (Tclgeomap_LnArrDeleteProc)(ClientData clientData);
153 
154 /*
155  * Procedure declarations:
156  */
157 
158 EXTERN Tclgeomap_LnArr	Tclgeomap_AddLnArr _ANSI_ARGS_((Tcl_Interp *, char *,
159 			    GeoLnArr));
160 EXTERN void		Tclgeomap_AddLnArrDeleteTask _ANSI_ARGS_((
161 			    Tclgeomap_LnArr, Tclgeomap_LnArrDeleteProc,
162 			    ClientData));
163 EXTERN void		Tclgeomap_CnxLnArrDeleteTask _ANSI_ARGS_((
164 			    Tclgeomap_LnArr, ClientData));
165 EXTERN Tclgeomap_LnArr	Tclgeomap_GetLnArr _ANSI_ARGS_((Tcl_Interp *, char *));
166 EXTERN CONST char *	Tclgeomap_LnArrName _ANSI_ARGS_((Tclgeomap_LnArr));
167 EXTERN MapLnArr 	Tclgeomap_LnArrToMap _ANSI_ARGS_((Tclgeomap_LnArr,
168 			    Tclgeomap_Proj));
169 
170 /*
171  * This structure stores information about a named place.  Client
172  * applications should not make direct references to fields in this
173  * structure.  It is made visible to help with debugging.
174  */
175 
176 struct Tclgeomap_Place
177 {
178     GeoPt geoPt;		/* Latitude and longitude of a place */
179     Tcl_Interp *interp;		/* Interpreter in which the command resides */
180     Tcl_Command cmd;		/* Tcl command for the place */
181     Tcl_HashTable updateTasks;	/* Procedures to call when the place moves.
182 				 * Entries are added with calls to
183 				 * Tclgeomap_AddPlaceUpdateTask.  ONE_WORD_KEYS
184 				 * are clientData's.  Values are
185 				 * Tclgeomap_PlaceUpdateProc's. */
186     Tcl_HashTable deleteTasks;	/* Procedures to call when the place is deleted.
187 				 * Entries are added with calls to
188 				 * Tclgeomap_AddPlaceDeleteTask.  ONE_WORD_KEYS
189 				 * are clientData's.  Values are
190 				 * Tclgeomap_PlaceDeleteProc's. */
191 };
192 typedef struct Tclgeomap_Place *Tclgeomap_Place;
193 
194 /*
195  * Procedure types:
196  */
197 
198 typedef void (Tclgeomap_PlaceUpdateProc)	_ANSI_ARGS_((ClientData));
199 typedef void (Tclgeomap_PlaceDeleteProc)	_ANSI_ARGS_((ClientData));
200 
201 /*
202  * Global functions:
203  */
204 
205 EXTERN void		Tclgeomap_AddPlaceUpdateTask _ANSI_ARGS_((
206 				Tclgeomap_Place, Tclgeomap_PlaceUpdateProc,
207 				ClientData));
208 EXTERN void		Tclgeomap_CnxPlaceUpdateTask _ANSI_ARGS_((
209 				Tclgeomap_Place, ClientData));
210 EXTERN void		Tclgeomap_AddPlaceDeleteTask _ANSI_ARGS_((
211 				Tclgeomap_Place, Tclgeomap_PlaceDeleteProc,
212 				ClientData));
213 EXTERN void		Tclgeomap_CnxPlaceDeleteTask _ANSI_ARGS_((
214 				Tclgeomap_Place, ClientData));
215 EXTERN Tclgeomap_Place	Tclgeomap_GetPlace _ANSI_ARGS_((Tcl_Interp *,
216 				CONST char *));
217 EXTERN GeoPt		Tclgeomap_PlaceLoc _ANSI_ARGS_((Tclgeomap_Place));
218 EXTERN CONST char *	Tclgeomap_PlaceName _ANSI_ARGS_((Tclgeomap_Place));
219 
220 /*
221  * The following declaration exports the Tclgeomap interface.
222  */
223 
224 EXTERN int	Tclgeomap_Init _ANSI_ARGS_((Tcl_Interp *));
225 EXTERN Tcl_Obj *Tclgeomap_JulDayToList _ANSI_ARGS_((struct GeoTime_Jul jul));
226 EXTERN void	Tclgeomap_AppendTime _ANSI_ARGS_((Tcl_Obj *list,
227 	    struct GeoTime_Jul jul));
228 
229 #endif
230