/* * Track.c -- Implementation of Track and WayPoint items. * * Authors : Patrick Lecoanet. * Creation date : * * $Id$ */ /* * Copyright (c) 1993 - 1999 CENA, Patrick Lecoanet -- * * This code is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this code; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "Track.h" #include "Draw.h" #include "Geo.h" #include "Item.h" #include "Types.h" #include "WidgetInfo.h" #include "tkZinc.h" #include #include static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; #define SPEED_VECTOR_PICKING_THRESHOLD 5 /* In pixels */ #define MARKER_FILLED_BIT 1 << 0 #define FILLED_HISTORY_BIT 1 << 1 #define DOT_MIXED_HISTORY_BIT 1 << 2 #define CIRCLE_HISTORY_BIT 1 << 3 #define POLAR_BIT 1 << 5 #define FROZEN_LABEL_BIT 1 << 6 #define LAST_AS_FIRST_BIT 1 << 7 #define CURRENT_POSITION -2 #define LEADER -3 #define CONNECTION -4 #define SPEED_VECTOR -5 /* ********************************************************************************** * * Specific Track item record * ********************************************************************************** */ typedef struct { ZnPoint world; /* world coord of pos */ ZnPoint dev; /* dev coord of pos */ ZnBool visible; } HistoryStruct, *History; typedef struct _TrackItemStruct { ItemStruct header; /* Public data */ unsigned char flags; Pixmap symbol; /* item symbol */ ZnColor symbol_color; int label_angle; /* Label angle from track. */ int label_distance; /* Label distance from track. */ int label_dx; /* Label dx/dy from track. */ int label_dy; ZnAnchor label_anchor; LeaderAnchors leader_anchors; /* Spec of the leader attachment */ ZnColor leader_color; /* leader color */ LineStyle leader_style; LineShape leader_shape; ZnLineEnd leader_first_end; ZnLineEnd leader_last_end; int leader_width; int marker_size; /* world size of error circle */ ZnColor marker_color; /* error circle color */ LineStyle marker_style; /* error circle style */ Pixmap marker_fill_pattern; /* error circle fill pattern */ ZnColor connection_color; /* connection color */ LineStyle connection_style; int connection_width; ZnColor speed_vector_color; /* s. v. color */ int visible_history_size; /* Number of visible positions */ ZnPoint pos; /* item world coordinates */ ZnPoint speed_vector; /* s. v. slope in world coord */ ZnColor history_color; /* Private data */ FieldSetStruct field_set; ZnPoint dev; /* device coords of current pos */ ZnPoint speed_vector_dev; /* s. v. end in device coord */ ZnDim marker_size_dev; /* dev size of error circle */ ZnList history; /* pos list */ ZnList leader_points; } TrackItemStruct, *TrackItem; static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_BOOL, "-circlehistory", NULL, Tk_Offset(TrackItemStruct, flags), CIRCLE_HISTORY_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, Tk_Offset(TrackItemStruct, header.flags), COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TrackItemStruct, header.connected_item), 0, ZN_COORDS_FLAG|ZN_ITEM_FLAG, False }, { ZN_CONFIG_COLOR, "-connectioncolor", NULL, Tk_Offset(TrackItemStruct, connection_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-connectionsensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CONNECTION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-connectionstyle", NULL, Tk_Offset(TrackItemStruct, connection_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-connectionwidth", NULL, Tk_Offset(TrackItemStruct, connection_width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-filledhistory", NULL, Tk_Offset(TrackItemStruct, flags), FILLED_HISTORY_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-filledmarker", NULL, Tk_Offset(TrackItemStruct, flags), MARKER_FILLED_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-frozenlabel", NULL, Tk_Offset(TrackItemStruct, flags), FROZEN_LABEL_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-historycolor", NULL, Tk_Offset(TrackItemStruct, history_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_ANCHOR, "-labelanchor", NULL, Tk_Offset(TrackItemStruct, label_anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ANGLE, "-labelangle", NULL, Tk_Offset(TrackItemStruct, label_angle), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, { ZN_CONFIG_DIM, "-labeldistance", NULL, Tk_Offset(TrackItemStruct, label_distance), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, { ZN_CONFIG_DIM, "-labeldx", NULL, Tk_Offset(TrackItemStruct, label_dx), 0, ZN_COORDS_FLAG|ZN_CARTESIAN_FLAG, False }, { ZN_CONFIG_DIM, "-labeldy", NULL, Tk_Offset(TrackItemStruct, label_dy), 0, ZN_COORDS_FLAG|ZN_CARTESIAN_FLAG, False }, { ZN_CONFIG_LABEL_FORMAT, "-labelformat", NULL, Tk_Offset(TrackItemStruct, field_set.label_format), 0, ZN_COORDS_FLAG|ZN_CLFC_FLAG, False }, { ZN_CONFIG_BOOL, "-lastasfirst", NULL, Tk_Offset(TrackItemStruct, flags), LAST_AS_FIRST_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LEADER_ANCHORS, "-leaderanchors", NULL, Tk_Offset(TrackItemStruct, leader_anchors), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-leadercolor", NULL, Tk_Offset(TrackItemStruct, leader_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_END, "-leaderfirstend", NULL, Tk_Offset(TrackItemStruct, leader_first_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_LINE_END, "-leaderlastend", NULL, Tk_Offset(TrackItemStruct, leader_last_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-leadersensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(LEADER), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-leaderstyle", NULL, Tk_Offset(TrackItemStruct, leader_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_SHAPE, "-leadershape", NULL, Tk_Offset(TrackItemStruct, leader_shape), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_DIM, "-leaderwidth", NULL, Tk_Offset(TrackItemStruct, leader_width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-markercolor", NULL, Tk_Offset(TrackItemStruct, marker_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_PATTERN, "-markerfillpattern", NULL, Tk_Offset(TrackItemStruct, marker_fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-markersize", NULL, Tk_Offset(TrackItemStruct, marker_size), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-markerstyle", NULL, Tk_Offset(TrackItemStruct, marker_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-mixedhistory", NULL, Tk_Offset(TrackItemStruct, flags), DOT_MIXED_HISTORY_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_UINT, "-numfields", NULL, Tk_Offset(TrackItemStruct, field_set.num_fields), 0, 0, True }, { ZN_CONFIG_POINT, "-position", NULL, Tk_Offset(TrackItemStruct, pos), 0, ZN_COORDS_FLAG|ZN_MOVED_FLAG, False}, { ZN_CONFIG_PRI, "-priority", NULL, Tk_Offset(TrackItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(TrackItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_POINT, "-speedvector", NULL, Tk_Offset(TrackItemStruct, speed_vector), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-speedvectorcolor", NULL, Tk_Offset(TrackItemStruct, speed_vector_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-speedvectorsensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(SPEED_VECTOR), ZN_REPICK_FLAG, False }, { ZN_CONFIG_PATTERN, "-symbol", NULL, Tk_Offset(TrackItemStruct, symbol), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-symbolcolor", NULL, Tk_Offset(TrackItemStruct, symbol_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-symbolsensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CURRENT_POSITION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAGS, "-tags", NULL, Tk_Offset(TrackItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(TrackItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, { ZN_CONFIG_UINT, "-visiblehistorysize", NULL, Tk_Offset(TrackItemStruct, visible_history_size), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } }; static ZnAttrConfig wp_attrs[] = { { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, Tk_Offset(TrackItemStruct, header.flags), COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TrackItemStruct, header.connected_item), 0, ZN_COORDS_FLAG|ZN_ITEM_FLAG, False }, { ZN_CONFIG_COLOR, "-connectioncolor", NULL, Tk_Offset(TrackItemStruct, connection_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-connectionsensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CONNECTION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-connectionstyle", NULL, Tk_Offset(TrackItemStruct, connection_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-connectionwidth", NULL, Tk_Offset(TrackItemStruct, connection_width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-filledmarker", NULL, Tk_Offset(TrackItemStruct, flags), MARKER_FILLED_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_ANCHOR, "-labelanchor", NULL, Tk_Offset(TrackItemStruct, label_anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ANGLE, "-labelangle", NULL, Tk_Offset(TrackItemStruct, label_angle), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, { ZN_CONFIG_DIM, "-labeldistance", NULL, Tk_Offset(TrackItemStruct, label_distance), 0, ZN_COORDS_FLAG|ZN_POLAR_FLAG, False }, { ZN_CONFIG_DIM, "-labeldx", NULL, Tk_Offset(TrackItemStruct, label_dx), 0, ZN_COORDS_FLAG|ZN_CARTESIAN_FLAG, False }, { ZN_CONFIG_DIM, "-labeldy", NULL, Tk_Offset(TrackItemStruct, label_dy), 0, ZN_COORDS_FLAG|ZN_CARTESIAN_FLAG, False }, { ZN_CONFIG_LABEL_FORMAT, "-labelformat", NULL, Tk_Offset(TrackItemStruct, field_set.label_format), 0, ZN_COORDS_FLAG|ZN_CLFC_FLAG, False }, { ZN_CONFIG_LEADER_ANCHORS, "-leaderanchors", NULL, Tk_Offset(TrackItemStruct, leader_anchors), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-leadercolor", NULL, Tk_Offset(TrackItemStruct, leader_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_END, "-leaderfirstend", NULL, Tk_Offset(TrackItemStruct, leader_first_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_LINE_END, "-leaderlastend", NULL, Tk_Offset(TrackItemStruct, leader_last_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-leadersensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(LEADER), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_SHAPE, "-leadershape", NULL, Tk_Offset(TrackItemStruct, leader_shape), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-leaderstyle", NULL, Tk_Offset(TrackItemStruct, leader_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-leaderwidth", NULL, Tk_Offset(TrackItemStruct, leader_width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-markercolor", NULL, Tk_Offset(TrackItemStruct, marker_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_PATTERN, "-markerfillpattern", NULL, Tk_Offset(TrackItemStruct, marker_fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-markersize", NULL, Tk_Offset(TrackItemStruct, marker_size), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-markerstyle", NULL, Tk_Offset(TrackItemStruct, marker_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_UINT, "-numfields", NULL, Tk_Offset(TrackItemStruct, field_set.num_fields), 0, 0, True }, { ZN_CONFIG_POINT, "-position", NULL, Tk_Offset(TrackItemStruct, pos), 0, ZN_COORDS_FLAG, False}, { ZN_CONFIG_PRI, "-priority", NULL, Tk_Offset(TrackItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(TrackItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_PATTERN, "-symbol", NULL, Tk_Offset(TrackItemStruct, symbol), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_COLOR, "-symbolcolor", NULL, Tk_Offset(TrackItemStruct, symbol_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-symbolsensitive", NULL, Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CURRENT_POSITION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAGS, "-tags", NULL, Tk_Offset(TrackItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(TrackItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } }; /* ********************************************************************************** * * Init -- * ********************************************************************************** */ static int Init(Item item, int *argc, Tcl_Obj *CONST *args[]) { TrackItem track = (TrackItem) item; FieldSet field_set = &track->field_set; WidgetInfo *wi = item->wi; /*printf("size of a track = %d\n", sizeof(TrackItemStruct));*/ SET(item->flags, VISIBLE_BIT); SET(item->flags, SENSITIVE_BIT); SET(item->flags, COMPOSE_ROTATION_BIT); SET(item->flags, COMPOSE_SCALE_BIT); SET(item->part_sensitive, PART_NUMBER_TO_BIT(CURRENT_POSITION)); SET(item->part_sensitive, PART_NUMBER_TO_BIT(LEADER)); SET(item->part_sensitive, PART_NUMBER_TO_BIT(CONNECTION)); SET(item->part_sensitive, PART_NUMBER_TO_BIT(SPEED_VECTOR)); track->symbol_color = ZnGetColorByValue(wi->win, wi->fore_color); track->symbol = Tk_GetBitmap(wi->interp, wi->win, Tk_GetUid("AtcSymbol15")); track->label_anchor = ZnAnchorCenter; track->label_angle = DEFAULT_LABEL_ANGLE; track->label_distance = DEFAULT_LABEL_DISTANCE; SET(track->flags, POLAR_BIT); CLEAR(track->flags, FROZEN_LABEL_BIT); track->leader_anchors = NULL; track->leader_color = ZnGetColorByValue(wi->win, wi->fore_color); track->leader_style = LINE_SIMPLE; track->leader_shape = LINE_STRAIGHT; track->leader_width = DEFAULT_LINE_WIDTH; track->connection_color = ZnGetColorByValue(wi->win, wi->fore_color); track->connection_style = LINE_SIMPLE; track->connection_width = DEFAULT_LINE_WIDTH; track->marker_color = ZnGetColorByValue(wi->win, wi->fore_color); track->marker_style = LINE_SIMPLE; track->marker_fill_pattern = ZnUnspecifiedPattern; track->speed_vector_color = ZnGetColorByValue(wi->win, wi->fore_color); track->history_color = ZnGetColorByValue(wi->win, wi->fore_color); CLEAR(track->flags, MARKER_FILLED_BIT); SET(track->flags, FILLED_HISTORY_BIT); CLEAR(track->flags, DOT_MIXED_HISTORY_BIT); CLEAR(track->flags, CIRCLE_HISTORY_BIT); CLEAR(track->flags, LAST_AS_FIRST_BIT); if (item->class == ZnTrack) { item->priority = DEFAULT_TRACK_PRIORITY; track->visible_history_size = DEFAULT_VISIBLE_HISTORY_SIZE; track->marker_size = DEFAULT_MARKER_SIZE; track->speed_vector.x = 0; track->speed_vector.y = 0; } else { item->priority = DEFAULT_WAY_POINT_PRIORITY; track->visible_history_size = 0; track->marker_size = 0; track->speed_vector.x = 0.0; track->speed_vector.y = 10.0; } field_set->wi = wi; field_set->label_format = NULL; /* * Then try to see if some fields are needed. */ if ((*argc > 0) && (Tcl_GetString((*args)[0])[0] != '-') && (Tcl_GetIntFromObj(wi->interp, (*args)[0], &field_set->num_fields) != ZN_ERROR)) { *args += 1; *argc -= 1; ITEM_P.InitFields(field_set); } else { Tcl_AppendResult(wi->interp, " number of fields expected", NULL); return ZN_ERROR; } track->pos.x = 0; track->pos.y = 0; track->field_set.label_pos.x = 0; track->field_set.label_pos.y = 0; track->leader_first_end = NULL; track->leader_last_end = NULL; track->history = NULL; track->dev.x = 0; track->dev.y = 0; track->speed_vector_dev.x = 0; track->speed_vector_dev.y = 0; track->marker_size_dev = 0; track->leader_points = NULL; return ZN_OK; } /* ********************************************************************************** * * Clone -- * ********************************************************************************** */ static void Clone(Item item) { TrackItem track = (TrackItem) item; WidgetInfo *wi = item->wi; if (track->history) { track->history = ZnListDuplicate(track->history); } track->dev.x = 0; track->dev.y = 0; track->speed_vector_dev.x = 0; track->speed_vector_dev.y = 0; track->marker_size_dev = 0; if (track->leader_points) { track->leader_points = ZnListDuplicate(track->leader_points); } if (track->leader_first_end) { LineEndDuplicate(track->leader_first_end); } if (track->leader_last_end) { LineEndDuplicate(track->leader_last_end); } ITEM_P.CloneFields(&track->field_set); /* * We get all shared resources, colors bitmaps. */ track->symbol_color = ZnGetColorByValue(wi->win, track->symbol_color); track->leader_color = ZnGetColorByValue(wi->win, track->leader_color); track->connection_color = ZnGetColorByValue(wi->win, track->connection_color); track->marker_color = ZnGetColorByValue(wi->win, track->marker_color); track->speed_vector_color = ZnGetColorByValue(wi->win, track->speed_vector_color); track->history_color = ZnGetColorByValue(wi->win, track->history_color); if (track->symbol != ZnUnspecifiedPattern) { track->symbol = Tk_GetBitmap(wi->interp, wi->win, Tk_NameOfBitmap(wi->dpy, track->symbol)); } if (track->marker_fill_pattern != ZnUnspecifiedPattern) { track->marker_fill_pattern = Tk_GetBitmap(wi->interp, wi->win, Tk_NameOfBitmap(wi->dpy, track->marker_fill_pattern)); } } /* ********************************************************************************** * * Destroy -- * ********************************************************************************** */ static void Destroy(Item item) { TrackItem track = (TrackItem) item; WidgetInfo *wi = item->wi; if (track->leader_points) { ZnListFree(track->leader_points); } if (track->leader_first_end) { LineEndDelete(track->leader_first_end); } if (track->leader_last_end) { LineEndDelete(track->leader_last_end); } if (track->history) { ZnListFree(track->history); } /* * Release shared resources. */ ZnFreeColor(track->symbol_color); ZnFreeColor(track->leader_color); ZnFreeColor(track->connection_color); ZnFreeColor(track->marker_color); ZnFreeColor(track->speed_vector_color); ZnFreeColor(track->history_color); if (track->symbol != ZnUnspecifiedPattern) { Tk_FreeBitmap(wi->dpy, track->symbol); } if (track->marker_fill_pattern != ZnUnspecifiedPattern) { Tk_FreeBitmap(wi->dpy, track->marker_fill_pattern); } ITEM_P.FreeFields(&track->field_set); } /* ********************************************************************************** * * Configure -- * ********************************************************************************** */ static void AddToHistory(TrackItem track, ZnPoint old_pos) { WidgetInfo *wi = ((Item) track)->wi; /*printf("Track moved, manage history: %d\n", wi->track_manage_history);*/ if (track->history) { if (wi->track_manage_history) { HistoryStruct hist; hist.world = old_pos; hist.dev = track->dev; hist.visible = True; ZnListAdd(track->history, &hist, ZnListHead); ZnListTruncate(track->history, wi->track_managed_history_size); } } else { /* We do not shift the first time we move as the preceding position * is not valid. */ /*printf("creating history\n");*/ track->history = ZnListNew(wi->track_managed_history_size+1, sizeof(HistoryStruct)); } } static int Configure(Item item, int argc, Tcl_Obj *CONST argv[], int *flags) { TrackItem track = (TrackItem) item; WidgetInfo *wi = item->wi; Item old_connected; ZnPoint old_pos; old_pos = track->pos; old_connected = item->connected_item; if (ITEM_P.ConfigureAttributes((char *) item, -1, argc, argv, flags) == ZN_ERROR) { return ZN_ERROR; } /* * Trunc the visible history to the managed size. */ track->visible_history_size = MIN(track->visible_history_size, wi->track_managed_history_size); /* * Adapt to the new label locating system. */ if (ISSET(*flags, ZN_POLAR_FLAG)) { SET(track->flags, POLAR_BIT); } else if (ISSET(*flags, ZN_CARTESIAN_FLAG)) { CLEAR(track->flags, POLAR_BIT); } if (ISSET(*flags, ZN_ITEM_FLAG)) { /* * If the new connected item is not appropriate back up * to the old one. */ if ((item->connected_item == ZN_NO_ITEM) || (((item->connected_item->class == ZnTrack) || (item->connected_item->class == ZnWayPoint)) && (item->parent == item->connected_item->parent))) { ITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } #ifdef OM if (ISSET(*flags, ZN_VIS_FLAG)) { /* Record the change to trigger the overlap manager latter */ if ((item->class == ZnTrack) && ISSET(item->flags, VISIBLE_BIT)) { ((GroupItem) item->parent)->call_om = True; } } #endif /* If the current position has changed, shift the past pos. */ if (ISSET(*flags, ZN_MOVED_FLAG)) { if (item->class == ZnTrack) { AddToHistory(track, old_pos); } } return ZN_OK; } /* ********************************************************************************** * * Query -- * ********************************************************************************** */ static int Query(Item item, int argc, Tcl_Obj *CONST argv[]) { if (ITEM_P.QueryAttribute((char *) item, -1, argv[0]) == ZN_ERROR) { return ZN_ERROR; } return ZN_OK; } /* ********************************************************************************** * * ComputeCoordinates -- * ********************************************************************************** */ static void ComputeCoordinates(Item item, ZnBool force) { WidgetInfo *wi = item->wi; TrackItem track = (TrackItem) item; FieldSet field_set = &track->field_set; Item c_item; History hist; ZnPoint old_label_pos, old_pos, p, xp; ZnDim old_label_width, old_label_height; ZnReal rotation; ZnBBox bbox; ZnPoint *points; int num_acc_pos, i; int num_points, alignment; int w2=0, h2=0, w=0, h=0; ResetBBox(&item->item_bounding_box); old_label_pos = field_set->label_pos; old_label_width = field_set->label_width; old_label_height = field_set->label_height; /* * Suppress history if history management was turned off. */ if ((item->class == ZnTrack) && !wi->track_manage_history) { ZnListEmpty(track->history); } old_pos = track->dev; ZnTransformPoint(wi->current_transfo, &track->pos, &track->dev); /*printf("track pos %g %g --> %g %g\n", track->pos.x, track->pos.y, track->dev.x, track->dev.y);*/ if (track->symbol != ZnUnspecifiedPattern) { Tk_SizeOfBitmap(wi->dpy, track->symbol, &w, &h); /*printf("taille symbole %d %d\n", w, h);*/ w2 = (w+1)/2; h2 = (h+1)/2; bbox.orig.x = track->dev.x - w2; bbox.orig.y = track->dev.y - h2; bbox.corner.x = bbox.orig.x + w; bbox.corner.y = bbox.orig.y + h; AddBBoxToBBox(&item->item_bounding_box, &bbox); } /* Here we approximate the past position sizes to the size of the current position. They are actually smaller but who care :-). In fact it is even worse as we use the overall information from the symbol font. */ if ((item->class == ZnTrack) && track->history) { ResetBBox(&bbox); num_acc_pos = ZnListSize(track->history); hist = ZnListArray(track->history); for (i = 0; i < num_acc_pos; i++) { ZnTransformPoint(wi->current_transfo, &hist[i].world, &hist[i].dev); if ((i < track->visible_history_size) && (hist[i].visible)) { bbox.orig.x = hist[i].dev.x - w2; bbox.orig.y = hist[i].dev.y - h2; bbox.corner.x = bbox.orig.x + w; bbox.corner.y = bbox.orig.y + h; AddBBoxToBBox(&item->item_bounding_box, &bbox); } } } /* * Compute the speed vector end. */ if (item->class == ZnTrack) { p.x = track->pos.x + track->speed_vector.x * wi->speed_vector_length; p.y = track->pos.y + track->speed_vector.y * wi->speed_vector_length; ZnTransformPoint(wi->current_transfo, &p, &track->speed_vector_dev); AddPointToBBox(&item->item_bounding_box, track->speed_vector_dev.x, track->speed_vector_dev.y); } /* * Take care of the connection between items. */ c_item = item->connected_item; if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { ResetBBox(&bbox); w2 = track->connection_width/2; AddPointToBBox(&item->item_bounding_box, track->dev.x-w2, track->dev.y-w2); AddPointToBBox(&item->item_bounding_box, ((TrackItem)c_item)->dev.x+w2, ((TrackItem)c_item)->dev.y+w2); } /* * Compute the size of the circular marker. */ p.x = track->pos.x + track->marker_size; p.y = track->pos.y; ZnTransformPoint(wi->current_transfo, &p, &xp); xp.x = xp.x - track->dev.x; xp.y = xp.y - track->dev.y; track->marker_size_dev = sqrt(xp.x*xp.x + xp.y*xp.y); if (track->marker_size_dev > PRECISION_LIMIT) { AddPointToBBox(&item->item_bounding_box, track->dev.x - (ZnPos) track->marker_size_dev, track->dev.y - (ZnPos) track->marker_size_dev); AddPointToBBox(&item->item_bounding_box, track->dev.x + (ZnPos) track->marker_size_dev, track->dev.y + (ZnPos) track->marker_size_dev); } /* Compute the new label bounding box. */ if (field_set->label_format) { ZnDim bb_width, bb_height, dist; ZnPoint leader_end; ITEM_P.GetLabelBBox(field_set, &bb_width, &bb_height); /* * Compute the label position. */ if (ISCLEAR(track->flags, FROZEN_LABEL_BIT)) { if (ISSET(track->flags, POLAR_BIT)) { /* * Adjust the min dist spec given in label_distance by * the size of the label. */ if ((track->label_anchor == ZnAnchorN) || (track->label_anchor == ZnAnchorCenter) || (track->label_anchor == ZnAnchorS)) { dist = sqrt(bb_width*bb_width/4+bb_height*bb_height/4); } else { dist = sqrt(bb_width*bb_width+bb_height*bb_height); } dist += track->label_distance; /* * Compute heading after applying the transform. */ ZnTransfoDecompose(wi->current_transfo, NULL, NULL, &rotation, NULL); /*printf("rotation=%g, heading=%g, angle=%d\n", rotation, ProjectionToAngle(track->speed_vector.x, track->speed_vector.y), track->label_angle);*/ rotation = ProjectionToAngle(track->speed_vector.x, track->speed_vector.y)-rotation; PointPolarToCartesian(rotation, dist, track->label_angle, &track->label_dx, &track->label_dy); } field_set->label_pos.x = track->dev.x + track->label_dx; field_set->label_pos.y = track->dev.y - track->label_dy; Anchor2Origin(&field_set->label_pos, bb_width, bb_height, track->label_anchor, &field_set->label_pos); } AddPointToBBox(&item->item_bounding_box, field_set->label_pos.x, field_set->label_pos.y); AddPointToBBox(&item->item_bounding_box, field_set->label_pos.x + (ZnPos) bb_width, field_set->label_pos.y + (ZnPos) bb_height); /* * Process the leader. */ if (track->leader_width > 0) { int left_x, left_y, right_x, right_y; ZnPoint end_points[LINE_END_POINTS]; /* * Compute the actual leader end in the label. */ if (track->leader_anchors) { left_x = track->leader_anchors->left_x; right_x = track->leader_anchors->right_x; left_y = track->leader_anchors->left_y; right_y = track->leader_anchors->right_y; } else { left_x = right_x = left_y = right_y = 50; } if (track->label_angle >= 270 || track->label_angle < 90) { if (track->leader_anchors && (left_y < 0)) { ITEM_P.GetFieldBBox(field_set, left_x, &bbox); leader_end.x = bbox.orig.x; leader_end.y = bbox.corner.y; } else { leader_end.x = field_set->label_pos.x + left_x*bb_width/100; leader_end.y = field_set->label_pos.y + left_y*bb_height/100; } alignment = AA_LEFT; } else { if (track->leader_anchors && (right_y < 0)) { ITEM_P.GetFieldBBox(field_set, right_x, &bbox); leader_end.x = bbox.corner.x; leader_end.y = bbox.corner.y; } else { leader_end.x = field_set->label_pos.x + right_x*bb_width/100; leader_end.y = field_set->label_pos.y + right_y*bb_height/100; } alignment = AA_RIGHT; } ITEM.SetFieldsAutoAlign(item, alignment); /* Clip the leader on the label's fields */ ITEM_P.LeaderToLabel(field_set, &track->dev, &leader_end); /* Setup leader shape points */ if (!track->leader_points) { track->leader_points = ZnListNew(LINE_SHAPE_POINTS, sizeof(ZnPoint)); } GetLineShape(&track->dev, &leader_end, track->leader_width, track->leader_shape, &bbox, track->leader_points); AddBBoxToBBox(&item->item_bounding_box, &bbox); points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); /* Setup leader ends */ if (track->leader_first_end != NULL) { GetLineEnd(&points[0], &points[1], track->leader_width, CapRound, track->leader_first_end, end_points); AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); } if (track->leader_last_end != NULL) { GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, CapRound, track->leader_last_end, end_points); AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); } } } /* Update connected items. */ if ((old_label_pos.x != field_set->label_pos.x) || (old_label_pos.y != field_set->label_pos.y) || (old_label_width != field_set->label_width) || (old_label_height != field_set->label_height) || (old_pos.x != track->dev.x) || (old_pos.y != track->dev.y)) { /* Update connected items */ SET(item->flags, UPDATE_DEPENDENT_BIT); #ifdef OM /* Record the move to trigger the overlap manager latter */ if (item->class == ZnTrack) { ((GroupItem) item->parent)->call_om = True; } #endif } } /* ********************************************************************************** * * ToArea -- * Tell if the object is entirely outside (-1), * entirely inside (1) or in between (0). * ********************************************************************************** */ static int ToArea(Item item, ZnBBox *area, Tk_Uid tag_uid, int enclosed, ZnBool report) { WidgetInfo *wi = item->wi; TrackItem track = (TrackItem) item; int inside; int width, height; ZnDim lwidth, lheight; ZnBBox bbox; /* * Try the current position. */ ResetBBox(&bbox); if (track->symbol != ZnUnspecifiedPattern) { Tk_SizeOfBitmap(wi->dpy, track->symbol, &width, &height); bbox.orig.x = track->dev.x-(width+1)/2; bbox.orig.y = track->dev.y-(height+1)/2; bbox.corner.x = bbox.orig.x + width; bbox.corner.y = bbox.orig.y + height; } inside = BBoxInBBox(&bbox, area); if (inside == 0) { /*printf("track pos\n");*/ return 0; } /* * Try the fields. */ ITEM_P.GetLabelBBox(&track->field_set, &lwidth, &lheight); if ((lwidth > 0.0) && (lheight > 0.0)) { if (ITEM_P.FieldsToArea(&track->field_set, area) != inside) { return 0; } } /* * Try the leader. */ if (track->field_set.label_format && (track->leader_width > 0)) { ZnPoint end_points[LINE_END_POINTS]; ZnPoint *points; int num_points; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); width = track->leader_width > 1 ? track->leader_width : 0; if (PolylineInBBox(points, num_points, width, CapRound, JoinRound, area) != inside) { /*printf("track leader\n");*/ return 0; } if (track->leader_first_end != NULL) { GetLineEnd(&points[0], &points[1], track->leader_width, CapRound, track->leader_first_end, end_points); if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != inside) { /*printf("track leader\n");*/ return 0; } } if (track->leader_last_end != NULL) { GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, CapRound, track->leader_last_end, end_points); if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != inside) { /*printf("track leader\n");*/ return 0; } } } /* * Try the speed vector. */ if (item->class == ZnTrack) { if (LineInBBox(&track->dev, &track->speed_vector_dev, area) != inside) { /*printf("track speed vector\n");*/ return 0; } } /* * Try the connection. */ if ((item->connected_item != ZN_NO_ITEM) && (track->connection_width > 0)) { ZnPoint pts[2]; pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; width = track->connection_width > 1 ? track->connection_width : 0; if (PolylineInBBox(pts, 2, width, CapRound, JoinRound, area) != inside) { /*printf("track connection\n");*/ return 0; } } return inside; } /* ********************************************************************************** * * Draw -- * ********************************************************************************** */ static void Draw(Item item) { WidgetInfo *wi = item->wi; TrackItem track = (TrackItem) item; Item c_item; char tmp_str[] = "."; XGCValues values; History hist; int h_side_size, side_size, width=0, height=0; int i, nb_hist, num_acc_pos; /* Draw the marker */ if (track->marker_size_dev != 0) { SetLineStyle(wi->dpy, wi->gc, track->marker_style); values.foreground = ZnPixel(track->marker_color); values.line_width = 0; if (ISSET(track->flags, MARKER_FILLED_BIT)) { if (track->marker_fill_pattern == ZnUnspecifiedPattern) { /* Fill solid */ values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); } else { /* Fill stippled */ values.fill_style = FillStippled; values.stipple = track->marker_fill_pattern; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCStipple | GCLineWidth | GCForeground, &values); } XFillArc(wi->dpy, wi->draw_buffer, wi->gc, track->dev.x - (ZnPos) track->marker_size_dev, track->dev.y - (ZnPos) track->marker_size_dev, track->marker_size_dev * 2, track->marker_size_dev * 2, 0, 360 * 64); } else { XChangeGC(wi->dpy, wi->gc, GCLineWidth | GCForeground, &values); XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, track->dev.x - (ZnPos) track->marker_size_dev, track->dev.y - (ZnPos) track->marker_size_dev, track->marker_size_dev * 2, track->marker_size_dev * 2, 0, 360 * 64); } } /* * Draw the connection. */ c_item = item->connected_item; if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { ZnPoint pts[2]; pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; DrawLineShape(wi, pts, 2, track->connection_style, track->connection_color, track->connection_width, LINE_STRAIGHT); } /* * Draw the speed vector. */ if (item->class == ZnTrack) { values.foreground = ZnPixel(track->speed_vector_color); values.line_width = 0; values.line_style = LineSolid; values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, &values); XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, track->dev.x, track->dev.y, track->speed_vector_dev.x, track->speed_vector_dev.y); } /* * Draw the leader. */ if (track->field_set.label_format && track->leader_width > 0) { ZnPoint end_points[LINE_END_POINTS]; XPoint xpoints[LINE_END_POINTS]; ZnPoint *points; int num_points; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); DrawLineShape(wi, points, num_points, track->leader_style, track->leader_color, track->leader_width, track->leader_shape); if (track->leader_first_end != NULL) { GetLineEnd(&points[0], &points[1], track->leader_width, CapRound, track->leader_first_end, end_points); for (i = 0; i < LINE_END_POINTS; i++) { xpoints[i].x = end_points[i].x; xpoints[i].y = end_points[i].y; } XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, LINE_END_POINTS, Nonconvex, CoordModeOrigin); } if (track->leader_last_end != NULL) { GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, CapRound, track->leader_last_end, end_points); for (i = 0; i < LINE_END_POINTS; i++) { xpoints[i].x = end_points[i].x; xpoints[i].y = end_points[i].y; } XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, LINE_END_POINTS, Nonconvex, CoordModeOrigin); } } tmp_str[0] = track->symbol; if (track->symbol != ZnUnspecifiedPattern) { Tk_SizeOfBitmap(wi->dpy, track->symbol, &width, &height); } /* * Draw the history, current pos excepted. */ if ((item->class == ZnTrack) && track->history) { values.foreground = ZnPixel(track->history_color); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle, &values); if (ISCLEAR(track->flags, FILLED_HISTORY_BIT)) { values.line_width = 0; values.line_style = LineSolid; XChangeGC(wi->dpy, wi->gc, GCLineWidth | GCLineStyle, &values); } num_acc_pos = MIN(track->visible_history_size, ZnListSize(track->history)); hist = ZnListArray(track->history); side_size = MAX(width, height); for (i = 0, nb_hist = 0; i < num_acc_pos; i++) { if (ISSET(track->flags, LAST_AS_FIRST_BIT) && (i == num_acc_pos-1)) { values.foreground = ZnPixel(track->symbol_color); XChangeGC(wi->dpy, wi->gc, GCForeground, &values); } side_size--; side_size = MAX(1, side_size); h_side_size = (side_size+1)/2; if (hist[i].visible) { if (ISSET(track->flags, DOT_MIXED_HISTORY_BIT) && !(nb_hist++ % 2)) { XDrawPoint(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x, hist[i].dev.y); } else { if (ISSET(track->flags, CIRCLE_HISTORY_BIT)) { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { XFillArc(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, side_size, side_size, 0, 360*64); } else { XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, side_size - 1, side_size - 1, 0, 360*64); } } else { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, side_size, side_size); } else { XDrawRectangle(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, side_size - 1, side_size - 1); } } } } } } /* * Draw the current position using a pattern for Tk. */ if (track->symbol != ZnUnspecifiedPattern) { int x = track->dev.x - (width+1)/2; int y = track->dev.y - (height+1)/2; values.foreground = ZnPixel(track->symbol_color); values.fill_style = FillStippled; values.stipple = track->symbol; values.ts_x_origin = x; values.ts_y_origin = y; XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle|GCStipple|GCTileStipXOrigin|GCTileStipYOrigin, &values); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, x, y, width, height); } /* * Draw the label. */ ITEM_P.DrawFields(&track->field_set); } /* ********************************************************************************** * * Render -- * ********************************************************************************** */ static void Render(Item item) { /* WidgetInfo *wi = item->wi; TrackItem track = (TrackItem) item;*/ } /* ********************************************************************************** * * IsSensitive -- * ********************************************************************************** */ static ZnBool IsSensitive(Item item, int item_part) { if (ISCLEAR(item->flags, SENSITIVE_BIT) || !item->parent->class->IsSensitive(item->parent, ZN_NO_PART)) { return False; } if (item_part < ZN_NO_PART) { return ISSET(item->part_sensitive, PART_NUMBER_TO_BIT(item_part)); } else if (item_part >= 0) { return ITEM_P.IsFieldSensitive(&((TrackItem) item)->field_set, item_part); } return True; } /* ********************************************************************************** * * Pick -- * ********************************************************************************** */ static double Pick(Item item, ZnPoint *p, Item start_item, int aperture, Item *a_item, int *part) { WidgetInfo *wi= item->wi; TrackItem track = (TrackItem) item; Item c_item; ZnBBox bbox; double dist=0, new_dist; ZnPoint *points; int num_points, i; int width=0, height=0; double width_2; int best_part; /* * Try one of the fields. */ dist = ITEM_P.FieldsPick(&track->field_set, p, &best_part); if (dist <= 0.0) { goto report0; } /* * Try the current position symbol. */ ResetBBox(&bbox); if (track->symbol != ZnUnspecifiedPattern) { Tk_SizeOfBitmap(wi->dpy, track->symbol, &width, &height); bbox.orig.x = track->dev.x-(width+1)/2; bbox.orig.y = track->dev.y-(height+1)/2; bbox.corner.x = bbox.orig.x + width; bbox.corner.y = bbox.orig.y + height; } new_dist = RectangleToPointDist(&bbox, p); if (new_dist < dist) { best_part = CURRENT_POSITION; dist = new_dist; } if (dist <= 0.0) { goto report0; } /* * Try the leader. */ if (track->field_set.label_format && (track->leader_width > 0) && track->leader_points) { ZnPoint end_points[LINE_END_POINTS]; width_2 = (track->leader_width>1) ? ((double) track->leader_width)/2.0 : 0; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points)-1; for (i = 0; i < num_points; i++) { new_dist = LineToPointDist(&points[i], &points[i+1], p); new_dist -= width_2; if (new_dist < dist) { best_part = LEADER; dist = new_dist; } if (dist <= 0.0) { goto report0; } } if (track->leader_first_end != NULL) { GetLineEnd(&points[0], &points[1], track->leader_width, CapRound, track->leader_first_end, end_points); new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); if (new_dist < dist) { best_part = LEADER; dist = new_dist; } if (dist <= 0.0) { goto report0; } } if (track->leader_last_end != NULL) { GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, CapRound, track->leader_last_end, end_points); new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); if (new_dist < dist) { best_part = LEADER; dist = new_dist; } if (dist <= 0.0) { goto report0; } } } /* * Try the speed vector. */ if (item->class == ZnTrack) { new_dist = LineToPointDist(&track->dev, &track->speed_vector_dev, p); if (new_dist < dist) { best_part = SPEED_VECTOR; dist = new_dist; } if (dist <= 0.0) { goto report0; } } /* * Try the connection. */ c_item = item->connected_item; if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { ZnPoint pts[2]; pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; new_dist = PolylineToPointDist(pts, 2, track->connection_width, CapRound, JoinRound, p); if (new_dist < dist) { dist = new_dist; best_part = CONNECTION; } if (dist <= 0.0) { report0: dist = 0.0; } } /* printf("track %d reporting part %d, distance %lf\n", item->id, best_part, dist); */ *part = best_part; return dist; } /* ********************************************************************************** * * PostScript -- * ********************************************************************************** */ static void PostScript(Item item, PostScriptInfo ps_info) { } /* ********************************************************************************** * * SendTrackToOm -- * ********************************************************************************** */ /* * TODO: * * The tracks should be identified by their ids not their * structure pointer. This would enable an easy interface * between the overlap manager and the applications when * dealing with tracks. */ void * SendTrackToOm(void *ptr, void *item, int *x, int *y, int *sv_dx, int *sv_dy, /* int *label_x, int *label_y, int *label_width, int *label_height,*/ int *rho, int *theta, int *visibility) { WidgetInfo *wi = (WidgetInfo *) ptr; Item current_item = (Item) item; TrackItem track; ZnBBox zn_bbox, bbox; ZnBool to_be_sent; zn_bbox.orig.x = zn_bbox.orig.y = 0; zn_bbox.corner.x = wi->width; zn_bbox.corner.y = wi->height; if (current_item == ZN_NO_ITEM) { current_item = ((GroupItem) wi->om_group)->head; } else { current_item = current_item->next; } while (current_item != ZN_NO_ITEM) { to_be_sent = current_item->class == ZnTrack; /* We send invisibles items because the current algorithm take care of the age of the tracks. to_be_sent &= ISSET(current_item->flags, VISIBLE_BIT);*/ IntersectBBox(&zn_bbox, ¤t_item->item_bounding_box, &bbox); to_be_sent &= !IsEmptyBBox(&bbox); if (to_be_sent) { track = (TrackItem) current_item; *x = track->dev.x; *y = wi->height - track->dev.y; /* * We must send world values for speed vector deltas as device * equivalents can be null. But then if the image is rotated this * is nonsense. */ *sv_dx = track->speed_vector.x; *sv_dy = track->speed_vector.y; /* Fri Oct 13 15:16:38 2000 *label_x = track->field_set.label_pos.x; *label_y = wi->height - track->field_set.label_pos.y; if (track->field_set.label_format) { ZnDim bb_width, bb_height; ITEM_P.GetLabelBBox(&track->field_set, &bb_width, &bb_height); *label_width = bb_width; *label_height = bb_height; } else { *label_width = 0; *label_height = 0; } */ *rho = sqrt(track->label_dx*track->label_dx + track->label_dy*track->label_dy); *theta = track->label_angle; *visibility = ISSET(current_item->flags, VISIBLE_BIT); break; } current_item = current_item->next; } return (void *) current_item; } /* ********************************************************************************** * * SetLabelAngleFromOm -- * ********************************************************************************** */ void SetLabelAngleFromOm(void *ptr, /* No longer in use. */ void *item, int theta) { TrackItem track = (TrackItem) item; theta %= 360; if ((theta >= 0) && (track->label_angle != theta)) { track->label_angle = theta; SET(track->flags, POLAR_BIT); ITEM.Invalidate((Item) item, ZN_COORDS_FLAG); } } /* ********************************************************************************** * * QueryLabelPosition -- OverlapMan query the widget about what would be the * label position if label_angle is theta * ********************************************************************************** */ void QueryLabelPosition(void *ptr, /* No longer in use. */ void *item, int theta, int *x, int *y, int *w, int *h) { Item it = (Item) item; WidgetInfo *wi = it->wi; TrackItem track = (TrackItem) it; if (track->field_set.label_format) { ZnDim bb_width, bb_height; int delta_x, delta_y; ZnReal heading; /* * !! BUG !! This doesn't work if the current transform has some rotation. */ heading = ProjectionToAngle(track->speed_vector.x, track->speed_vector.y); PointPolarToCartesian(heading, track->label_distance, theta, &delta_x, &delta_y); ITEM_P.GetLabelBBox(&track->field_set, &bb_width, &bb_height); /* * !! BUG !! This assume a label placing relative to the center anchor. * We must fix this by taking into account the label anchor. */ *x = track->dev.x + (ZnPos) (delta_x - bb_width/2); *y = track->dev.y - (ZnPos) (delta_y + bb_height/2); *y = wi->height - *y; *w = bb_width; *h = bb_height; } else { *x = *y = *w = *h = 0; } } /* ********************************************************************************** * * SetHistoryVisibility -- PLC - not yet implemented * ********************************************************************************** */ void SetHistoryVisibility(Item item, int index, ZnBool visible) { } /* ********************************************************************************** * * TruncHistory -- PLC - not yet interfaced * ********************************************************************************** */ void TruncHistory(Item item) { TrackItem track = (TrackItem) item; if (track->history) { int size = ZnListSize (track->history); History hist_tbl = ZnListArray (track->history); while (size--) { hist_tbl[size].visible = False; } ITEM.Invalidate(item, ZN_COORDS_FLAG); } } /* ********************************************************************************** * * GetFieldSet -- * ********************************************************************************** */ static FieldSet GetFieldSet(Item item) { return &((TrackItem) item)->field_set; } /* ********************************************************************************** * * GetAnchor -- * ********************************************************************************** */ static void GetAnchor(Item item, ZnAnchor anchor, ZnPoint *p) { FieldSet field_set = &((TrackItem) item)->field_set; ZnDim width, height; if (field_set->label_format) { ITEM_P.GetLabelBBox(field_set, &width, &height); Origin2Anchor(&field_set->label_pos, width, height, anchor, p); } else { p->x = p->y = 0.0; } } /* ********************************************************************************** * * Coords -- * Return or edit the item position. * ********************************************************************************** */ static int Coords(Item item, int contour, int index, int cmd, ZnPoint **pts, int *num_pts) { TrackItem track = (TrackItem) item; if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " ", item->class->name, "s can't add or remove vertices", NULL); return ZN_ERROR; } else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on ", item->class->name, "s", NULL); return ZN_ERROR; } if (item->class == ZnTrack) { AddToHistory(track, track->pos); } track->pos = (*pts)[0]; ITEM.Invalidate(item, ZN_COORDS_FLAG); } else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { *num_pts = 1; *pts = &track->pos; } return ZN_OK; } /* ********************************************************************************** * * Part -- * Convert a private part from/to symbolic representation. * ********************************************************************************** */ static int Part(Item item, Tcl_Obj **part_spec, int *part) { char *part_str=""; int c; char *end; if (*part_spec) { part_str = Tcl_GetString(*part_spec); if (strlen(part_str) == 0) { *part = ZN_NO_PART; } else if (isdigit(part_str[0])) { *part = strtol(part_str, &end, 0); if ((*end != 0) || (*part < 0) || (*part >= ((TrackItem) item)->field_set.num_fields)) { goto part_error; } } else { c = part_str[0]; if ((c == 'c') && (strcmp(part_str, "connection") == 0)) { *part = CONNECTION; } else if ((c == 'l') && (strcmp(part_str, "leader") == 0)) { *part = LEADER; } else if ((c == 'p') && (strcmp(part_str, "position") == 0)) { *part = CURRENT_POSITION; } else if ((c == 's') && (strcmp(part_str, "speedvector") == 0)) { if (item->class != ZnTrack) { goto part_error; } *part = SPEED_VECTOR; } else { part_error: Tcl_AppendResult(item->wi->interp, " invalid item part specification", NULL); return ZN_ERROR; } } } else { if (*part >= 0) { *part_spec = Tcl_NewIntObj(*part); } else { switch (*part) { default: case ZN_NO_PART: part_str = ""; break; case CURRENT_POSITION: part_str = "position"; break; case LEADER: part_str = "leader"; break; case CONNECTION: part_str = "connection"; break; case SPEED_VECTOR: if (item->class == ZnTrack) { part_str = "speedvector"; break; } } *part_spec = NewStringObj(part_str); } } return ZN_OK; } /* ********************************************************************************** * * Exported functions struct -- * ********************************************************************************** */ static ItemClassStruct TRACK_ITEM_CLASS = { sizeof(TrackItemStruct), True, /* has_fields */ 4, /* num_parts */ True, /* has_anchors */ "track", track_attrs, Init, Clone, Destroy, Configure, Query, GetFieldSet, GetAnchor, NULL, /* GetClipVertices */ Coords, NULL, /* InsertChars */ NULL, /* DeleteChars */ NULL, /* Cursor */ NULL, /* Index */ Part, NULL, /* Selection */ NULL, /* Contour */ ComputeCoordinates, ToArea, Draw, Render, IsSensitive, Pick, NULL, /* PickVertex */ PostScript }; static ItemClassStruct WAY_POINT_ITEM_CLASS = { sizeof(TrackItemStruct), True, /* has_fields */ 3, /* num_parts */ True, /* has_anchors */ "waypoint", wp_attrs, Init, Clone, Destroy, Configure, Query, GetFieldSet, GetAnchor, NULL, /* GetClipVertices */ Coords, NULL, /* InsertChars */ NULL, /* DeleteChars */ NULL, /* Cursor */ NULL, /* Index */ Part, NULL, /* Selection */ NULL, /* Contour */ ComputeCoordinates, ToArea, Draw, Render, IsSensitive, Pick, NULL, /* PickVertex */ PostScript }; ZnItemClassId ZnTrack = (ZnItemClassId) &TRACK_ITEM_CLASS; ZnItemClassId ZnWayPoint = (ZnItemClassId) &WAY_POINT_ITEM_CLASS;