aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Tabular.c52
-rw-r--r--generic/Track.c133
2 files changed, 165 insertions, 20 deletions
diff --git a/generic/Tabular.c b/generic/Tabular.c
index 00bd019..8f179e0 100644
--- a/generic/Tabular.c
+++ b/generic/Tabular.c
@@ -33,6 +33,9 @@
#include "Geo.h"
#include "tkZinc.h"
+#include <ctype.h>
+#include <stdlib.h>
+
static const char rcsid[] = "$Id$";
static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $";
@@ -495,6 +498,52 @@ Coords(Item item,
/*
**********************************************************************************
*
+ * Part --
+ * Convert a private part from/to symbolic representation.
+ *
+ **********************************************************************************
+ */
+static int
+Part(Item item,
+ Tcl_Obj **part_spec,
+ int *part)
+{
+ char *part_str;
+ 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 >= ((TabularItem) item)->field_set.num_fields)) {
+ goto part_error;
+ }
+ }
+ 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 {
+ *part_spec = NewStringObj("");
+ }
+ }
+ return ZN_OK;
+}
+
+
+/*
+ **********************************************************************************
+ *
* Exported functions structs --
*
**********************************************************************************
@@ -502,7 +551,7 @@ Coords(Item item,
static ItemClassStruct TABULAR_ITEM_CLASS = {
sizeof(TabularItemStruct),
True, /* has_fields */
- False, /* has_parts */
+ 0, /* num_parts */
True, /* has_anchors */
"tabular",
tabular_attrs,
@@ -519,6 +568,7 @@ static ItemClassStruct TABULAR_ITEM_CLASS = {
NULL, /* DeleteChars */
NULL, /* Cursor */
NULL, /* Index */
+ Part,
NULL, /* Selection */
NULL, /* Contour */
ComputeCoordinates,
diff --git a/generic/Track.c b/generic/Track.c
index 586b5b9..33dbdeb 100644
--- a/generic/Track.c
+++ b/generic/Track.c
@@ -35,6 +35,9 @@
#include "WidgetInfo.h"
#include "tkZinc.h"
+#include <ctype.h>
+#include <stdlib.h>
+
static const char rcsid[] = "$Id$";
static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $";
@@ -49,6 +52,11 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
#define POLAR_BIT 1 << 5
#define FROZEN_LABEL_BIT 1 << 6
+#define CURRENT_POSITION -2
+#define LEADER -3
+#define CONNECTION -4
+#define SPEED_VECTOR -5
+
/*
**********************************************************************************
@@ -120,7 +128,7 @@ static ZnAttrConfig track_attrs[] = {
{ 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(ZN_CONNECTION),
+ 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 },
@@ -158,7 +166,7 @@ static ZnAttrConfig track_attrs[] = {
{ 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(ZN_LEADER),
+ 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 },
@@ -190,14 +198,14 @@ static ZnAttrConfig track_attrs[] = {
{ 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(ZN_SPEED_VECTOR),
+ 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(ZN_CURRENT_POSITION),
+ 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 },
@@ -223,7 +231,7 @@ static ZnAttrConfig wp_attrs[] = {
{ 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(ZN_CONNECTION),
+ 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 },
@@ -257,7 +265,7 @@ static ZnAttrConfig wp_attrs[] = {
{ 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(ZN_LEADER),
+ 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 },
@@ -287,7 +295,7 @@ static ZnAttrConfig wp_attrs[] = {
{ 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(ZN_CURRENT_POSITION),
+ 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 },
@@ -322,10 +330,10 @@ Init(Item item,
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(ZN_CURRENT_POSITION));
- SET(item->part_sensitive, PART_NUMBER_TO_BIT(ZN_LEADER));
- SET(item->part_sensitive, PART_NUMBER_TO_BIT(ZN_CONNECTION));
- SET(item->part_sensitive, PART_NUMBER_TO_BIT(ZN_SPEED_VECTOR));
+ 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;
@@ -1263,7 +1271,7 @@ Pick(Item item,
new_dist = RectangleToPointDist(&bbox, p);
if (new_dist < dist) {
- best_part = ZN_CURRENT_POSITION;
+ best_part = CURRENT_POSITION;
dist = new_dist;
}
if (dist <= 0.0) {
@@ -1283,7 +1291,7 @@ Pick(Item item,
new_dist = LineToPointDist(&points[i], &points[i+1], p);
new_dist -= width_2;
if (new_dist < dist) {
- best_part = ZN_LEADER;
+ best_part = LEADER;
dist = new_dist;
}
if (dist <= 0.0) {
@@ -1295,7 +1303,7 @@ Pick(Item item,
CapRound, track->leader_first_end, end_points);
new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p);
if (new_dist < dist) {
- best_part = ZN_LEADER;
+ best_part = LEADER;
dist = new_dist;
}
if (dist <= 0.0) {
@@ -1307,7 +1315,7 @@ Pick(Item item,
CapRound, track->leader_last_end, end_points);
new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p);
if (new_dist < dist) {
- best_part = ZN_LEADER;
+ best_part = LEADER;
dist = new_dist;
}
if (dist <= 0.0) {
@@ -1322,7 +1330,7 @@ Pick(Item item,
if (item->class == ZnTrack) {
new_dist = LineToPointDist(&track->dev, &track->speed_vector_dev, p);
if (new_dist < dist) {
- best_part = ZN_SPEED_VECTOR;
+ best_part = SPEED_VECTOR;
dist = new_dist;
}
if (dist <= 0.0) {
@@ -1343,7 +1351,7 @@ Pick(Item item,
CapRound, JoinRound, p);
if (new_dist < dist) {
dist = new_dist;
- best_part = ZN_CONNECTION;
+ best_part = CONNECTION;
}
if (dist <= 0.0) {
report0:
@@ -1663,6 +1671,91 @@ Coords(Item item,
/*
**********************************************************************************
*
+ * 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 --
*
**********************************************************************************
@@ -1670,7 +1763,7 @@ Coords(Item item,
static ItemClassStruct TRACK_ITEM_CLASS = {
sizeof(TrackItemStruct),
True, /* has_fields */
- True, /* has_parts */
+ 4, /* num_parts */
True, /* has_anchors */
"track",
track_attrs,
@@ -1687,6 +1780,7 @@ static ItemClassStruct TRACK_ITEM_CLASS = {
NULL, /* DeleteChars */
NULL, /* Cursor */
NULL, /* Index */
+ Part,
NULL, /* Selection */
NULL, /* Contour */
ComputeCoordinates,
@@ -1701,7 +1795,7 @@ static ItemClassStruct TRACK_ITEM_CLASS = {
static ItemClassStruct WAY_POINT_ITEM_CLASS = {
sizeof(TrackItemStruct),
True, /* has_fields */
- True, /* has_parts */
+ 3, /* num_parts */
True, /* has_anchors */
"waypoint",
wp_attrs,
@@ -1718,6 +1812,7 @@ static ItemClassStruct WAY_POINT_ITEM_CLASS = {
NULL, /* DeleteChars */
NULL, /* Cursor */
NULL, /* Index */
+ Part,
NULL, /* Selection */
NULL, /* Contour */
ComputeCoordinates,