From 26c1a2f52c92f44ee99132a343ad76d0014ae348 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 8 Apr 2002 13:51:11 +0000 Subject: Int�gration du code des commandes externes qui se trouvaient dans tkZinc.c --- generic/MapInfo.c | 911 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 889 insertions(+), 22 deletions(-) (limited to 'generic/MapInfo.c') diff --git a/generic/MapInfo.c b/generic/MapInfo.c index 60d2ce8..c9eb779 100644 --- a/generic/MapInfo.c +++ b/generic/MapInfo.c @@ -34,6 +34,7 @@ #include #include "MapInfo.h" +#include "tkZinc.h" #include #include @@ -158,7 +159,7 @@ ComputeLineMarks(MapInfoLine marked_line) } -MapInfoId +static MapInfoId MapInfoCreate(char *name) { MapInfo new_map; @@ -175,7 +176,7 @@ MapInfoCreate(char *name) } -char * +static char * MapInfoName(MapInfoId map_info) { if (!map_info) { @@ -185,7 +186,7 @@ MapInfoName(MapInfoId map_info) } -MapInfoId +static MapInfoId MapInfoDuplicate(MapInfoId map_info) { MapInfo cur_map = (MapInfo) map_info; @@ -240,7 +241,7 @@ MapInfoDuplicate(MapInfoId map_info) } -void +static void MapInfoDelete(MapInfoId map_info) { MapInfo cur_map = (MapInfo) map_info; @@ -286,7 +287,7 @@ MapInfoDelete(MapInfoId map_info) } } -void +static void MapInfoEmpty(MapInfoId map_info) { MapInfo cur_map = (MapInfo) map_info; @@ -308,7 +309,7 @@ MapInfoEmpty(MapInfoId map_info) } -void +static void MapInfoAddLine(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -349,7 +350,7 @@ MapInfoAddLine(MapInfoId map_info, } -void +static void MapInfoReplaceLine(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -391,7 +392,7 @@ MapInfoReplaceLine(MapInfoId map_info, } -void +static void MapInfoRemoveLine(MapInfoId map_info, unsigned int index) { @@ -496,7 +497,7 @@ MapInfoNumLines(MapInfoId map_info) } -void +static void MapInfoAddSymbol(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -523,7 +524,7 @@ MapInfoAddSymbol(MapInfoId map_info, } -void +static void MapInfoReplaceSymbol(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -546,7 +547,7 @@ MapInfoReplaceSymbol(MapInfoId map_info, } -void +static void MapInfoRemoveSymbol(MapInfoId map_info, unsigned int index) { @@ -603,7 +604,7 @@ MapInfoNumSymbols(MapInfoId map_info) } -void +static void MapInfoAddText(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -634,7 +635,7 @@ MapInfoAddText(MapInfoId map_info, } -void +static void MapInfoReplaceText(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -664,7 +665,7 @@ MapInfoReplaceText(MapInfoId map_info, } -void +static void MapInfoRemoveText(MapInfoId map_info, unsigned int index) { @@ -735,7 +736,7 @@ MapInfoNumTexts(MapInfoId map_info) } -void +static void MapInfoAddArc(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -774,7 +775,7 @@ MapInfoAddArc(MapInfoId map_info, } -void +static void MapInfoReplaceArc(MapInfoId map_info, unsigned int index, ZnPtr tag, @@ -810,7 +811,7 @@ MapInfoReplaceArc(MapInfoId map_info, } -void +static void MapInfoRemoveArc(MapInfoId map_info, unsigned int index) { @@ -890,7 +891,7 @@ MapInfoNumArcs(MapInfoId map_info) } } -void +static void MapInfoScale(MapInfoId map_info, double factor) { @@ -938,7 +939,7 @@ MapInfoScale(MapInfoId map_info, } } -void +static void MapInfoTranslate(MapInfoId map_info, int x, int y) @@ -1049,7 +1050,8 @@ ReorderVidomap(VideoMap *vm) *----------------------------------------------------------------------- */ -static void FillMap(MapInfoId map, VideoMap *vm) +static void +FillMap(MapInfoId map, VideoMap *vm) { unsigned int i; ZnBool has_start_pos = False; @@ -1183,7 +1185,7 @@ static void FillMap(MapInfoId map, VideoMap *vm) * *----------------------------------------------------------------------- */ -int +static int MapInfoGetVideomap(MapInfoId map, char *filename, int index) @@ -1245,7 +1247,7 @@ error: *----------------------------------------------------------------------- */ -ZnList +static ZnList MapInfoVideomapIds(char *filename) { FILE *file; @@ -1287,3 +1289,868 @@ error: ZnListFree(ids); return NULL; } + + +/* + *-------------------------------------------------------------------------- + * + * MapInfo and Videomapstuff that should go eventually in its own file. + * + *-------------------------------------------------------------------------- + */ + +static Tcl_HashTable mapInfoTable; +static ZnBool map_info_inited = False; + +typedef struct { + ClientData client_data; + MapInfoChangeProc proc; +} MapInfoClient; + +typedef struct { + MapInfoId map_info; + ZnBool deleted; + ZnList clients; +} MapInfoMaster; + +static void +MapInfoInit() +{ + Tcl_InitHashTable(&mapInfoTable, TCL_ONE_WORD_KEYS); + + map_info_inited = True; +} + +static void +UpdateMapInfoClients(MapInfoMaster *master) +{ + int i, num; + MapInfoClient *client; + + num = ZnListSize(master->clients); + client = (MapInfoClient *) ZnListArray(master->clients); + for (i = 0; i < num; i++, client++) { + (*client->proc)(client->client_data, master->map_info); + } +} + +static int +ZnCreateMapInfo(Tcl_Interp *interp, + char *name, + MapInfoId *map_info) +{ + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + int new; + MapInfoMaster *master; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_CreateHashEntry(&mapInfoTable, uid, &new); + if (!new) { + /* + * Empty the map info if it is not. + */ + master = (MapInfoMaster *) Tcl_GetHashValue(entry); + if (master->deleted) { + master->deleted = False; + } + else { + MapInfoEmpty(master->map_info); + UpdateMapInfoClients(master); + } + } + else { + master = (MapInfoMaster *) ZnMalloc(sizeof(MapInfoMaster)); + master->map_info = MapInfoCreate(name); + master->deleted = False; + master->clients = ZnListNew(1, sizeof(MapInfoClient)); + Tcl_SetHashValue(entry, master); + } + if (map_info) { + *map_info = master->map_info; + } + return TCL_OK; +} + +static int +ZnDuplicateMapInfo(Tcl_Interp *interp, + char *name, + MapInfoId map_info) +{ + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + int new; + MapInfoMaster *master; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_CreateHashEntry(&mapInfoTable, uid, &new); + if (!new) { + Tcl_AppendResult(interp, "duplicate mapinfo \"", name, "\" already exists", NULL); + return ZN_ERROR; + } + master = (MapInfoMaster *) ZnMalloc(sizeof(MapInfoMaster)); + master->map_info = MapInfoDuplicate(map_info); + master->deleted = False; + master->clients = ZnListNew(1, sizeof(MapInfoClient)); + Tcl_SetHashValue(entry, master); + + return TCL_OK; +} + +static MapInfoMaster * +LookupMapInfoMaster(Tcl_Interp *interp, + char *name) +{ + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + MapInfoMaster *master; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_FindHashEntry(&mapInfoTable, uid); + if (entry == NULL) { + mp_error: + Tcl_AppendResult(interp, "mapinfo \"", name, "\" doesn't exist", NULL); + return NULL; + } + master = (MapInfoMaster *) Tcl_GetHashValue(entry); + if (master->deleted) { + goto mp_error; + } + return master; +} + +static int +ZnDeleteMapInfo(Tcl_Interp *interp, + char *name) +{ + MapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_FindHashEntry(&mapInfoTable, uid); + if (entry == NULL) { + return ZN_ERROR; + } + + master = (MapInfoMaster *) Tcl_GetHashValue(entry); + if (ZnListSize(master->clients) != 0) { + master->deleted = True; + MapInfoEmpty(master->map_info); + UpdateMapInfoClients(master); + } + else { + MapInfoDelete(master->map_info); + ZnListFree(master->clients); + Tcl_DeleteHashEntry(entry); + ZnFree(master); + } + + return TCL_OK; +} + +MapInfoId +ZnGetMapInfo(Tcl_Interp *interp, + char *name, + MapInfoChangeProc proc, + ClientData client_data) +{ + MapInfoMaster *master; + MapInfoClient client; + + master = LookupMapInfoMaster(interp, name); + if (master == NULL) { + return NULL; + } + client.proc = proc; + client.client_data = client_data; + ZnListAdd(master->clients, &client, ZnListTail); + + return master->map_info; +} + +void +ZnFreeMapInfo(MapInfoId map_info, + MapInfoChangeProc proc, + ClientData client_data) +{ + Tk_Uid uid = Tk_GetUid(MapInfoName(map_info)); + Tcl_HashEntry *entry; + MapInfoMaster *master; + MapInfoClient *client; + int num, i; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_FindHashEntry(&mapInfoTable, uid); + if (entry == NULL) { + return; + } + master = (MapInfoMaster *) Tcl_GetHashValue(entry); + client = (MapInfoClient *) ZnListArray(master->clients); + num = ZnListSize(master->clients); + for (i = 0; i < num; i++, client++) { + if ((client->client_data == client_data) && + (client->proc == proc)) { + ZnListDelete(master->clients, i); + return; + } + } +} + +static void +ZnUpdateMapInfoClients(MapInfoId map_info) +{ + Tk_Uid uid = Tk_GetUid(MapInfoName(map_info)); + Tcl_HashEntry *entry; + MapInfoMaster *master; + + if (!map_info_inited) { + MapInfoInit(); + } + + entry = Tcl_FindHashEntry(&mapInfoTable, uid); + if (entry == NULL) { + return; + } + master = (MapInfoMaster *) Tcl_GetHashValue(entry); + UpdateMapInfoClients(master); +} + + +/* + * These arrays must be kept in sync with the MapInfoLineStyle + * and MapInfoTextStyle enums. + */ +static char *line_style_strings[] = { + "simple", + "dashed", + "dotted", + "mixed", + "marked", +}; + +static char *text_style_strings[] = { + "normal", + "underlined" +}; + +static char * +MapInfoLineStyleToString(MapInfoLineStyle line_style) +{ + return line_style_strings[line_style]; +} + +static int +MapInfoLineStyleFromString(Tcl_Interp *interp, + char *str, + MapInfoLineStyle *line_style) +{ + int i, num = sizeof(line_style_strings)/sizeof(char *); + + for (i = 0; i < num; i++) { + if (strcmp(str, line_style_strings[i]) == 0) { + *line_style = i; + return TCL_OK; + } + } + Tcl_AppendResult(interp, " incorrect mapinfo line style \"", + str,"\"", NULL); + return ZN_ERROR; +} + +static char * +MapInfoTextStyleToString(MapInfoTextStyle text_style) +{ + return text_style_strings[text_style]; +} + +static int +MapInfoTextStyleFromString(Tcl_Interp *interp, + char *str, + MapInfoTextStyle *text_style) +{ + int i, num = sizeof(text_style_strings)/sizeof(char *); + + for (i = 0; i < num; i++) { + if (strcmp(str, text_style_strings[i]) == 0) { + *text_style = i; + return TCL_OK; + } + } + Tcl_AppendResult(interp, " incorrect mapinfo text style \"", + str,"\"", NULL); + return ZN_ERROR; +} + +int +MapInfoObjCmd(ClientData client_data, + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + Tcl_Obj *CONST args[]) +{ + int index, index2, result; + MapInfoMaster *master; + Tcl_Obj *l; + static char *sub_cmd_strings[] = { + "add", "count", "create", "delete", "duplicate", + "get", "remove", "replace", "scale", "translate", NULL + }; + static char *e_type_strings[] = { + "arc", "line", "symbol", "text", NULL + }; + enum sub_cmds { + ZN_MI_ADD, ZN_MI_COUNT, ZN_MI_CREATE, ZN_MI_DELETE, ZN_MI_DUPLICATE, + ZN_MI_GET, ZN_MI_REMOVE, ZN_MI_REPLACE, ZN_MI_SCALE, ZN_MI_TRANSLATE + }; + enum e_types { + ZN_E_ARC, ZN_E_LINE, ZN_E_SYMBOL, ZN_E_TEXT + }; + + + if (argc < 3) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo/name subCmd ?args?"); + return ZN_ERROR; + } + + if (Tcl_GetIndexFromObj(interp, args[2], sub_cmd_strings, + "subCmd", 0, &index) != ZN_OK) { + return ZN_ERROR; + } + result = TCL_OK; + /*printf("mapinfo command \"%s\", argc=%d\n", + Tcl_GetString(args[2]), argc);*/ + + switch((enum sub_cmds) index) { + /* + * create + */ + case ZN_MI_CREATE: + { + if (argc != 3) { + Tcl_WrongNumArgs(interp, 1, args, "name create"); + return ZN_ERROR; + } + if (ZnCreateMapInfo(interp, Tcl_GetString(args[1]), NULL) == ZN_ERROR) { + return ZN_ERROR; + } + } + break; + /* + * delete + */ + case ZN_MI_DELETE: + { + if (argc != 3) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo delete"); + return ZN_ERROR; + } + if (ZnDeleteMapInfo(interp, Tcl_GetString(args[1])) == ZN_ERROR) { + return ZN_ERROR; + } + } + break; + /* + * duplicate + */ + case ZN_MI_DUPLICATE: + { + if (argc != 4) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo duplicate name"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (ZnDuplicateMapInfo(interp, Tcl_GetString(args[3]), + master->map_info) == ZN_ERROR) { + return ZN_ERROR; + } + } + break; + /* + * add/replace + */ + case ZN_MI_ADD: + case ZN_MI_REPLACE: + { + MapInfoLineStyle line_style; + MapInfoTextStyle text_style; + int i, insert; + int coords[6]; + ZnBool add_cmd = (enum sub_cmds) index == ZN_MI_ADD; + int num_param = add_cmd ? 4 : 5; + + if (argc < num_param) { + Tcl_WrongNumArgs(interp, 3, args, + add_cmd ? "elementType ?args?" : "elementType index ?args?"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (!add_cmd) { + if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { + return ZN_ERROR; + } + if (insert < 0) { + insert = 0; + } + } + if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, + "elementType", 0, &index2) != ZN_OK) { + return ZN_ERROR; + } + switch ((enum e_types) index2) { + case ZN_E_LINE: + { + if (argc != (num_param+6)) { + Tcl_WrongNumArgs(interp, 4, args, + add_cmd ? "style width x1 y1 x2 y2" : "index style width x1 y1 x2 y2"); + return ZN_ERROR; + } + if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), + &line_style) == ZN_ERROR) { + return ZN_ERROR; + } + for (i = 0; i < 5; i++) { + if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == ZN_ERROR) { + return ZN_ERROR; + } + } + if (coords[0] < 0) { + coords[0] = 0; + } + if (add_cmd) { + MapInfoAddLine(master->map_info, ZnListTail, NULL, line_style, + coords[0], coords[1], coords[2], coords[3], coords[4]); + } + else { + MapInfoReplaceLine(master->map_info, insert, NULL, line_style, + coords[0], coords[1], coords[2], coords[3], coords[4]); + } + } + break; + case ZN_E_SYMBOL: + { + if (argc != (num_param+3)) { + Tcl_WrongNumArgs(interp, 4, args, + add_cmd ? "x y intVal" : "index x y intVal"); + return ZN_ERROR; + } + for (i = 0; i < 3; i++) { + if (Tcl_GetIntFromObj(interp, args[num_param+i], &coords[i]) == ZN_ERROR) { + return ZN_ERROR; + } + } + if (coords[2] < 0) { + coords[2] = 0; + } + if (add_cmd) { + MapInfoAddSymbol(master->map_info, ZnListTail, NULL, coords[0], + coords[1], coords[2]); + } + else { + MapInfoReplaceSymbol(master->map_info, insert, NULL, coords[0], + coords[1], coords[2]); + } + } + break; + case ZN_E_TEXT: + { + if (argc != (num_param+5)) { + Tcl_WrongNumArgs(interp, 4, args, + add_cmd ? "textStyle lineStyle x y string" : "index textStyle lineStyle x y string"); + return ZN_ERROR; + } + if (MapInfoTextStyleFromString(interp, Tcl_GetString(args[num_param]), + &text_style) == ZN_ERROR) { + return ZN_ERROR; + } + if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param+1]), + &line_style) == ZN_ERROR) { + return ZN_ERROR; + } + for (i = 0; i < 2; i++) { + if (Tcl_GetIntFromObj(interp, args[num_param+i+2], &coords[i]) == ZN_ERROR) { + return ZN_ERROR; + } + } + if (add_cmd) { + MapInfoAddText(master->map_info, ZnListTail, NULL, text_style, + line_style, coords[0], coords[1], + Tcl_GetString(args[num_param+4])); + } + else { + /*printf("replace text ts %d ls %d %d %d %s\n", text_style, + line_style, coords[0], coords[1], Tcl_GetString(args[num_param+4]));*/ + MapInfoReplaceText(master->map_info, insert, NULL, text_style, + line_style, coords[0], coords[1], + Tcl_GetString(args[num_param+4])); + } + } + break; + case ZN_E_ARC: + { + if (argc != (num_param+7)) { + Tcl_WrongNumArgs(interp, 4, args, + add_cmd ? "style width cx cy radius start extent" : "index style width cx cy radius start extent"); + return ZN_ERROR; + } + if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), + &line_style) == ZN_ERROR) { + return ZN_ERROR; + } + for (i = 0; i < 6; i++) { + if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == ZN_ERROR) { + return ZN_ERROR; + } + } + if (coords[0] < 0) { + coords[0] = 0; + } + if (add_cmd) { + MapInfoAddArc(master->map_info, ZnListTail, NULL, line_style, + coords[0], coords[1], coords[2], coords[3], coords[4], + coords[5]); + } + else { + MapInfoReplaceArc(master->map_info, insert, NULL, line_style, coords[0], + coords[1], coords[2], coords[3], coords[4], coords[5]); + } + } + break; + } + UpdateMapInfoClients(master); + } + break; + /* + * count + */ + case ZN_MI_COUNT: + { + int count = 0; + if (argc != 4) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo count type"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, + "elementType", 0, &index2) != ZN_OK) { + return ZN_ERROR; + } + switch ((enum e_types) index2) { + case ZN_E_LINE: + count = MapInfoNumLines(master->map_info); + break; + case ZN_E_SYMBOL: + count = MapInfoNumSymbols(master->map_info); + break; + case ZN_E_TEXT: + count = MapInfoNumTexts(master->map_info); + break; + case ZN_E_ARC: + count = MapInfoNumArcs(master->map_info); + break; + } + l = Tcl_NewIntObj(count); + Tcl_SetObjResult(interp, l); + } + break; + /* + * get + */ + case ZN_MI_GET: + { + int insert; + if (argc != 5) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo get type index"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { + return ZN_ERROR; + } + if (insert < 0) { + insert = 0; + } + if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, + "elementType", 0, &index2) != ZN_OK) { + return ZN_ERROR; + } + switch ((enum e_types) index2) { + case ZN_E_LINE: + { + MapInfoLineStyle line_style; + int line_width; + int x_from, y_from, x_to, y_to; + MapInfoGetLine(master->map_info, insert, NULL, &line_style, + &line_width, &x_from, &y_from, &x_to, &y_to); + l = Tcl_GetObjResult(interp); + Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(line_width)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x_from)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y_from)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x_to)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y_to)); + } + break; + case ZN_E_SYMBOL: + { + int x, y; + char symbol; + MapInfoGetSymbol(master->map_info, insert, NULL, &x, &y, &symbol); + l = Tcl_GetObjResult(interp); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(symbol)); + } + break; + case ZN_E_TEXT: + { + int x, y; + char *text; + MapInfoTextStyle text_style; + MapInfoLineStyle line_style; + MapInfoGetText(master->map_info, insert, NULL, &text_style, &line_style, + &x, &y, &text); + l = Tcl_GetObjResult(interp); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y)); + Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoTextStyleToString(text_style))); + Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); + Tcl_ListObjAppendElement(interp, l, NewStringObj(text)); + } + break; + case ZN_E_ARC: + { + MapInfoLineStyle line_style; + int line_width; + int center_x, center_y, start, extent; + unsigned int radius; + MapInfoGetArc(master->map_info, insert, NULL, &line_style, &line_width, + ¢er_x, ¢er_y, &radius, &start, &extent); + l = Tcl_GetObjResult(interp); + Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(line_width)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(center_x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(center_y)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(radius)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(start)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(extent)); + } + break; + } + } + break; + /* + * remove + */ + case ZN_MI_REMOVE: + { + int insert; + if (argc != 5) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo remove type index"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { + return ZN_ERROR; + } + if (insert < 0) { + insert = 0; + } + if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, + "elementType", 0, &index2) != ZN_OK) { + return ZN_ERROR; + } + switch ((enum e_types) index2) { + case ZN_E_LINE: + MapInfoRemoveLine(master->map_info, insert); + break; + case ZN_E_SYMBOL: + MapInfoRemoveSymbol(master->map_info, insert); + break; + case ZN_E_TEXT: + MapInfoRemoveText(master->map_info, insert); + break; + case ZN_E_ARC: + MapInfoRemoveArc(master->map_info, insert); + break; + } + UpdateMapInfoClients(master); + } + break; + /* + * scale + */ + case ZN_MI_SCALE: + { + double factor; + + if (argc != 4) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo scale factor"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (Tcl_GetDoubleFromObj(interp, args[3], &factor) == ZN_ERROR) { + return ZN_ERROR; + } + MapInfoScale(master->map_info, factor); + UpdateMapInfoClients(master); + } + break; + /* + * translate + */ + case ZN_MI_TRANSLATE: + { + int x, y; + + if (argc != 5) { + Tcl_WrongNumArgs(interp, 1, args, "mapInfo translate xAmount yAmount"); + return ZN_ERROR; + } + master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); + if (master == NULL) { + return ZN_ERROR; + } + if (Tcl_GetIntFromObj(interp, args[3], &x) == ZN_ERROR) { + return ZN_ERROR; + } + if (Tcl_GetIntFromObj(interp, args[4], &y) == ZN_ERROR) { + return ZN_ERROR; + } + MapInfoTranslate(master->map_info, x, y); + UpdateMapInfoClients(master); + } + break; + } + + return TCL_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * VideomapObjCmd -- + * + * + *---------------------------------------------------------------------- + */ +int +VideomapObjCmd(ClientData client_data, + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + Tcl_Obj *CONST args[]) +{ + ZnList ids; + int index; + int *id_array, id_num, i; + Tcl_Obj *l; + static char *sub_cmd_strings[] = { + "ids", "load", NULL + }; + enum sub_cmds { + ZN_V_IDS, ZN_V_LOAD + }; + + + if (argc < 2) { + Tcl_WrongNumArgs(interp, 1, args, "?subCmd? filename $args?"); + return ZN_ERROR; + } + + if (Tcl_GetIndexFromObj(interp, args[1], sub_cmd_strings, + "subCmd", 0, &index) != ZN_OK) { + return ZN_ERROR; + } + + switch((enum sub_cmds) index) { + /* + * ids + */ + case ZN_V_IDS: + { + if (argc != 3) { + Tcl_WrongNumArgs(interp, 1, args,"ids filename"); + return ZN_ERROR; + } + ids = MapInfoVideomapIds(Tcl_GetString(args[2])); + if (ids == NULL) { + Tcl_AppendResult(interp, "unable to look at videomap file \"", + Tcl_GetString(args[2]), "\"", NULL); + return ZN_ERROR; + } + id_array = (int *) ZnListArray(ids); + id_num = ZnListSize(ids); + l = Tcl_GetObjResult(interp); + for (i = 0; i < id_num; i++) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(id_array[i])); + } + ZnListFree(ids); + } + break; + /* + * load + */ + case ZN_V_LOAD: + { + MapInfoId map_info; + int insert; + + if (argc != 5) { + Tcl_WrongNumArgs(interp, 1, args, "load filename index mapInfo"); + return ZN_ERROR; + } + if (Tcl_GetIntFromObj(interp, args[3], &insert) == ZN_ERROR) { + return ZN_ERROR; + } + if (insert < 0) { + insert = 0; + } + if (ZnCreateMapInfo(interp, Tcl_GetString(args[4]), &map_info) == ZN_ERROR) { + return ZN_ERROR; + } + if (MapInfoGetVideomap(map_info, Tcl_GetString(args[2]), insert) == ZN_ERROR) { + Tcl_AppendResult(interp, "unable to load videomap file \"", + Tcl_GetString(args[2]), ":", + Tcl_GetString(args[3]), "\"", NULL); + return ZN_ERROR; + } + ZnUpdateMapInfoClients(map_info); + } + break; + } + + return TCL_OK; +} -- cgit v1.1