summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-04-10 15:40:21 (GMT)
committerjoye <joye>2014-04-10 15:40:21 (GMT)
commit33b9fdcd95135396aac6f56494a9602fe9ca196e (patch)
treec24c33dcc4acc7a77f0d24b85e3a932f3971e6d7 /src
parent78ef82bd0194ac88cd48b670d4dbe72838d0d2d0 (diff)
downloadblt-33b9fdcd95135396aac6f56494a9602fe9ca196e.zip
blt-33b9fdcd95135396aac6f56494a9602fe9ca196e.tar.gz
blt-33b9fdcd95135396aac6f56494a9602fe9ca196e.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltGrAxis.C283
-rw-r--r--src/bltGrAxis.h23
-rw-r--r--src/bltGrAxisOp.C32
-rw-r--r--src/bltGrAxisOp.h33
-rw-r--r--src/bltGrAxisOption.C280
-rw-r--r--src/bltGrAxisOption.h39
-rw-r--r--src/bltGrElemBar.C1
-rw-r--r--src/bltGrElemLine.C1
-rw-r--r--src/bltGrMarker.C1
-rw-r--r--src/bltGraph.C1
-rw-r--r--src/bltGraph.h7
11 files changed, 410 insertions, 291 deletions
diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C
index c66e264..08c238c 100644
--- a/src/bltGrAxis.C
+++ b/src/bltGrAxis.C
@@ -38,6 +38,7 @@ extern "C" {
#include "bltGrElemBar.h"
#include "bltGrElemLine.h"
#include "bltGrAxis.h"
+#include "bltGrAxisOption.h"
#include "bltGrLegd.h"
#define AXIS_PAD_TITLE 2
@@ -68,230 +69,19 @@ AxisName axisNames[] = {
// Defs
+extern void DestroyAxis(Axis *axisPtr);
extern int ConfigureAxis(Axis *axisPtr);
extern int AxisObjConfigure(Tcl_Interp* interp, Axis* axisPtr,
int objc, Tcl_Obj* const objv[]);
-extern int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
- Axis **axisPtrPtr);
-extern Tcl_FreeProc FreeAxis;
-
static void FreeTickLabels(Blt_Chain chain);
-static void ReleaseAxis(Axis* axisPtr);
static Axis *NewAxis(Graph* graphPtr, const char *name, int margin);
-static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
- ClassId classId, Axis **axisPtrPtr);
-static void DestroyAxis(Axis *axisPtr);
static int Round(double x)
{
return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}
-
-// OptionSpecs
-
-static Tk_CustomOptionSetProc AxisSetProc;
-static Tk_CustomOptionGetProc AxisGetProc;
-static Tk_CustomOptionFreeProc AxisFreeProc;
-Tk_ObjCustomOption xAxisObjOption =
- {
- "xaxis", AxisSetProc, AxisGetProc, RestoreProc, AxisFreeProc,
- (ClientData)CID_AXIS_X
- };
-Tk_ObjCustomOption yAxisObjOption =
- {
- "yaxis", AxisSetProc, AxisGetProc, RestoreProc, AxisFreeProc,
- (ClientData)CID_AXIS_Y
- };
-
-static int AxisSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* savePtr, int flags)
-{
- Axis** axisPtrPtr = (Axis**)(widgRec + offset);
- *(double*)savePtr = *(double*)axisPtrPtr;
-
- if (!axisPtrPtr)
- return TCL_OK;
-
- Graph* graphPtr = Blt_GetGraphFromWindowData(tkwin);
- ClassId classId = (ClassId)(long(clientData));
- Axis* axisPtr;
- if (GetAxisByClass(interp, graphPtr, *objPtr, classId, &axisPtr) != TCL_OK)
- return TCL_ERROR;
-
- *axisPtrPtr = axisPtr;
-
- return TCL_OK;
-};
-
-static Tcl_Obj* AxisGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- Axis* axisPtr = *(Axis**)(widgRec + offset);
- if (!axisPtr)
- return Tcl_NewStringObj("", -1);
-
- return Tcl_NewStringObj(axisPtr->obj.name, -1);
-};
-
-static void AxisFreeProc(ClientData clientData, Tk_Window tkwin, char *ptr)
-{
- Axis* axisPtr = *(Axis**)ptr;
- if (axisPtr)
- ReleaseAxis(axisPtr);
-}
-
-static Tk_CustomOptionSetProc LimitSetProc;
-static Tk_CustomOptionGetProc LimitGetProc;
-Tk_ObjCustomOption limitObjOption =
- {
- "limit", LimitSetProc, LimitGetProc, NULL, NULL, NULL
- };
-
-static int LimitSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* save, int flags)
-{
- double* limitPtr = (double*)(widgRec + offset);
- const char* string = Tcl_GetString(*objPtr);
- if (!string || !string[0]) {
- *limitPtr = NAN;
- return TCL_OK;
- }
-
- if (Blt_ExprDoubleFromObj(interp, *objPtr, limitPtr) != TCL_OK)
- return TCL_ERROR;
-
- return TCL_OK;
-}
-
-static Tcl_Obj* LimitGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- double limit = *(double*)(widgRec + offset);
- Tcl_Obj* objPtr;
-
- if (!isnan(limit))
- objPtr = Tcl_NewDoubleObj(limit);
- else
- objPtr = Tcl_NewStringObj("", -1);
-
- return objPtr;
-}
-
-static Tk_CustomOptionSetProc TicksSetProc;
-static Tk_CustomOptionGetProc TicksGetProc;
-static Tk_CustomOptionFreeProc TicksFreeProc;
-Tk_ObjCustomOption ticksObjOption =
- {
- "ticks", TicksSetProc, TicksGetProc, RestoreProc, TicksFreeProc, NULL
- };
-
-static int TicksSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* savePtr, int flags)
-{
- Ticks** ticksPtrPtr = (Ticks**)(widgRec + offset);
- *(double*)savePtr = *(double*)ticksPtrPtr;
-
- if (!ticksPtrPtr)
- return TCL_OK;
-
- int objc;
- Tcl_Obj** objv;
- if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK)
- return TCL_ERROR;
-
- Ticks* ticksPtr = NULL;
- if (objc > 0) {
- ticksPtr = (Ticks*)malloc(sizeof(Ticks) + (objc*sizeof(double)));
- for (int ii = 0; ii<objc; ii++) {
- double value;
- if (Blt_ExprDoubleFromObj(interp, objv[ii], &value) != TCL_OK) {
- free(ticksPtr);
- return TCL_ERROR;
- }
- ticksPtr->values[ii] = value;
- }
- ticksPtr->nTicks = objc;
- }
-
- *ticksPtrPtr = ticksPtr;
-
- return TCL_OK;
-}
-
-static Tcl_Obj* TicksGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- Ticks* ticksPtr = *(Ticks**)(widgRec + offset);
-
- if (!ticksPtr)
- return Tcl_NewListObj(0, NULL);
-
- int cnt = ticksPtr->nTicks;
- Tcl_Obj** ll = (Tcl_Obj**)calloc(cnt, sizeof(Tcl_Obj*));
- for (int ii = 0; ii<cnt; ii++)
- ll[ii] = Tcl_NewDoubleObj(ticksPtr->values[ii]);
-
- Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll);
- free(ll);
- return listObjPtr;
-}
-
-static void TicksFreeProc(ClientData clientData, Tk_Window tkwin,
- char *ptr)
-{
- Ticks* ticksPtr = *(Ticks**)ptr;
- if (ticksPtr)
- free(ticksPtr);
-}
-
-static Tk_CustomOptionSetProc ObjectSetProc;
-static Tk_CustomOptionGetProc ObjectGetProc;
-static Tk_CustomOptionFreeProc ObjectFreeProc;
-Tk_ObjCustomOption objectObjOption =
- {
- "object", ObjectSetProc, ObjectGetProc, RestoreProc, ObjectFreeProc, NULL,
- };
-
-static int ObjectSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* savePtr, int flags)
-{
- Tcl_Obj** objectPtrPtr = (Tcl_Obj**)(widgRec + offset);
- *(double*)savePtr = *(double*)objectPtrPtr;
-
- if (!objectPtrPtr)
- return TCL_OK;
-
- Tcl_IncrRefCount(*objPtr);
- *objectPtrPtr = *objPtr;
-
- return TCL_OK;
-}
-
-static Tcl_Obj* ObjectGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- Tcl_Obj** objectPtrPtr = (Tcl_Obj**)(widgRec + offset);
-
- if (!objectPtrPtr)
- return Tcl_NewObj();
-
- return *objectPtrPtr;
-}
-
-static void ObjectFreeProc(ClientData clientData, Tk_Window tkwin,
- char *ptr)
-{
- Tcl_Obj* objectPtr = *(Tcl_Obj**)ptr;
- if (objectPtr)
- Tcl_DecrRefCount(objectPtr);
-}
-
static Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_COLOR, "-activeforeground", "activeForeground", "ActiveForeground",
STD_ACTIVE_FOREGROUND, -1, Tk_Offset(Axis, activeFgColor), 0, NULL, 0},
@@ -503,7 +293,7 @@ static Axis *NewAxis(Graph* graphPtr, const char *name, int margin)
return axisPtr;
}
-static void DestroyAxis(Axis *axisPtr)
+void DestroyAxis(Axis *axisPtr)
{
Graph* graphPtr = axisPtr->obj.graphPtr;
@@ -585,17 +375,6 @@ int AxisIsHorizontal(Axis *axisPtr)
return ((axisPtr->obj.classId == CID_AXIS_Y) == graphPtr->inverted);
}
-static void ReleaseAxis(Axis *axisPtr)
-{
- if (axisPtr) {
- axisPtr->refCount--;
- if (axisPtr->refCount == 0) {
- axisPtr->flags |= DELETE_PENDING;
- Tcl_EventuallyFree(axisPtr, FreeAxis);
- }
- }
-}
-
static void FreeTickLabels(Blt_Chain chain)
{
Blt_ChainLink link;
@@ -1205,12 +984,6 @@ static void ResetTextStyles(Axis *axisPtr)
axisPtr->minor.gc = newGC;
}
-void FreeAxis(char* data)
-{
- Axis* axisPtr = (Axis*)data;
- DestroyAxis(axisPtr);
-}
-
static float titleAngle[4] = /* Rotation for each axis title */
{
0.0, 90.0, 0.0, 270.0
@@ -2645,56 +2418,6 @@ int ConfigureAxis(Axis *axisPtr)
return TCL_OK;
}
-int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
- Axis **axisPtrPtr)
-{
- Tcl_HashEntry *hPtr;
- const char *name;
-
- *axisPtrPtr = NULL;
- name = Tcl_GetString(objPtr);
- hPtr = Tcl_FindHashEntry(&graphPtr->axes.table, name);
- if (hPtr) {
- Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
- if ((axisPtr->flags & DELETE_PENDING) == 0) {
- *axisPtrPtr = axisPtr;
- return TCL_OK;
- }
- }
- if (interp)
- Tcl_AppendResult(interp, "can't find axis \"", name, "\" in \"",
- Tk_PathName(graphPtr->tkwin), "\"", NULL);
-
- return TCL_ERROR;
-}
-
-static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
- ClassId classId, Axis **axisPtrPtr)
-{
- Axis *axisPtr;
-
- if (GetAxisFromObj(interp, graphPtr, objPtr, &axisPtr) != TCL_OK)
- return TCL_ERROR;
-
- if (classId != CID_NONE) {
- // Set the axis type on the first use of it.
- if ((axisPtr->refCount == 0) || (axisPtr->obj.classId == CID_NONE))
- Blt_GraphSetObjectClass(&axisPtr->obj, classId);
-
- else if (axisPtr->obj.classId != classId) {
- Tcl_AppendResult(interp, "axis \"", Tcl_GetString(objPtr),
- "\" is already in use on an opposite ",
- axisPtr->obj.className, "-axis",
- NULL);
- return TCL_ERROR;
- }
- axisPtr->refCount++;
- }
-
- *axisPtrPtr = axisPtr;
- return TCL_OK;
-}
-
void Blt_DestroyAxes(Graph* graphPtr)
{
Tcl_HashSearch cursor;
diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h
index 4c93deb..9489329 100644
--- a/src/bltGrAxis.h
+++ b/src/bltGrAxis.h
@@ -33,6 +33,15 @@
#ifndef _BLT_GR_AXIS_H
#define _BLT_GR_AXIS_H
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+extern "C" {
+#include "bltGraph.h"
+}
+
#include "bltList.h"
#include "bltConfig.h"
@@ -79,7 +88,7 @@ typedef struct {
int nSteps; /* Number of intervals. */
} TickSweep;
-typedef struct {
+typedef struct _Axis {
GraphObj obj; /* Must be first field in axis. */
int use;
@@ -243,8 +252,7 @@ typedef struct {
Tk_Anchor tickAnchor;
Tk_Anchor reqTickAnchor;
XColor* tickColor;
- GC tickGC; /* Graphics context for axis and tick
- * labels */
+ GC tickGC;
GC activeTickGC;
double titleAngle;
@@ -253,15 +261,12 @@ typedef struct {
Tk_Justify titleJustify;
XColor* titleColor;
- Grid major, minor; /* Axis grid information. */
+ Grid major;
+ Grid minor;
double screenScale;
int screenMin, screenRange;
} Axis;
-typedef struct {
- Axis *x, *y;
-} Axis2d;
-
-#endif /* _BLT_GR_AXIS_H */
+#endif
diff --git a/src/bltGrAxisOp.C b/src/bltGrAxisOp.C
index 1c31b00..a415ce3 100644
--- a/src/bltGrAxisOp.C
+++ b/src/bltGrAxisOp.C
@@ -41,6 +41,7 @@ typedef int (GraphDefAxisProc)(Tcl_Interp* interp, Axis *axisPtr,
typedef int (GraphAxisProc)(Tcl_Interp* interp, Graph* graphPtr,
int objc, Tcl_Obj* const objv[]);
+extern void DestroyAxis(Axis *axisPtr);
extern Tcl_FreeProc FreeAxis;
extern int ConfigureAxis(Axis *axisPtr);
extern int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
@@ -716,3 +717,34 @@ int Blt_AxisOp(Graph* graphPtr, Tcl_Interp* interp,
return (*proc)(interp, graphPtr, objc, objv);
}
+// Support
+
+int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
+ Axis **axisPtrPtr)
+{
+ Tcl_HashEntry *hPtr;
+ const char *name;
+
+ *axisPtrPtr = NULL;
+ name = Tcl_GetString(objPtr);
+ hPtr = Tcl_FindHashEntry(&graphPtr->axes.table, name);
+ if (hPtr) {
+ Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr);
+ if ((axisPtr->flags & DELETE_PENDING) == 0) {
+ *axisPtrPtr = axisPtr;
+ return TCL_OK;
+ }
+ }
+ if (interp)
+ Tcl_AppendResult(interp, "can't find axis \"", name, "\" in \"",
+ Tk_PathName(graphPtr->tkwin), "\"", NULL);
+
+ return TCL_ERROR;
+}
+
+void FreeAxis(char* data)
+{
+ Axis* axisPtr = (Axis*)data;
+ DestroyAxis(axisPtr);
+}
+
diff --git a/src/bltGrAxisOp.h b/src/bltGrAxisOp.h
new file mode 100644
index 0000000..7a0117e
--- /dev/null
+++ b/src/bltGrAxisOp.h
@@ -0,0 +1,33 @@
+/*
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * This code has been modified under the terms listed below and is made
+ * available under the same terms.
+ */
+
+/*
+ * Copyright 1993-2004 George A Howlett.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BltGrAxisOp_h__
+#define __BltGrAxisOp_h__
+
+#endif
diff --git a/src/bltGrAxisOption.C b/src/bltGrAxisOption.C
new file mode 100644
index 0000000..454e169
--- /dev/null
+++ b/src/bltGrAxisOption.C
@@ -0,0 +1,280 @@
+/*
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * This code has been modified under the terms listed below and is made
+ * available under the same terms.
+ */
+
+/*
+ * Copyright 1993-2004 George A Howlett.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "bltGrAxis.h"
+#include "bltGrAxisOption.h"
+
+extern Tcl_FreeProc FreeAxis;
+extern int GetAxisFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
+ Axis **axisPtrPtr);
+static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
+ ClassId classId, Axis **axisPtrPtr);
+static void ReleaseAxis(Axis* axisPtr);
+
+static Tk_CustomOptionSetProc AxisSetProc;
+static Tk_CustomOptionGetProc AxisGetProc;
+static Tk_CustomOptionFreeProc AxisFreeProc;
+Tk_ObjCustomOption xAxisObjOption =
+ {
+ "xaxis", AxisSetProc, AxisGetProc, RestoreProc, AxisFreeProc,
+ (ClientData)CID_AXIS_X
+ };
+Tk_ObjCustomOption yAxisObjOption =
+ {
+ "yaxis", AxisSetProc, AxisGetProc, RestoreProc, AxisFreeProc,
+ (ClientData)CID_AXIS_Y
+ };
+
+static int AxisSetProc(ClientData clientData, Tcl_Interp* interp,
+ Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
+ int offset, char* savePtr, int flags)
+{
+ Axis** axisPtrPtr = (Axis**)(widgRec + offset);
+ *(double*)savePtr = *(double*)axisPtrPtr;
+
+ if (!axisPtrPtr)
+ return TCL_OK;
+
+ Graph* graphPtr = Blt_GetGraphFromWindowData(tkwin);
+ ClassId classId = (ClassId)(long(clientData));
+ Axis* axisPtr;
+ if (GetAxisByClass(interp, graphPtr, *objPtr, classId, &axisPtr) != TCL_OK)
+ return TCL_ERROR;
+
+ *axisPtrPtr = axisPtr;
+
+ return TCL_OK;
+};
+
+static Tcl_Obj* AxisGetProc(ClientData clientData, Tk_Window tkwin,
+ char *widgRec, int offset)
+{
+ Axis* axisPtr = *(Axis**)(widgRec + offset);
+ if (!axisPtr)
+ return Tcl_NewStringObj("", -1);
+
+ return Tcl_NewStringObj(axisPtr->obj.name, -1);
+};
+
+static void AxisFreeProc(ClientData clientData, Tk_Window tkwin, char *ptr)
+{
+ Axis* axisPtr = *(Axis**)ptr;
+ if (axisPtr)
+ ReleaseAxis(axisPtr);
+}
+
+static Tk_CustomOptionSetProc LimitSetProc;
+static Tk_CustomOptionGetProc LimitGetProc;
+Tk_ObjCustomOption limitObjOption =
+ {
+ "limit", LimitSetProc, LimitGetProc, NULL, NULL, NULL
+ };
+
+static int LimitSetProc(ClientData clientData, Tcl_Interp* interp,
+ Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
+ int offset, char* save, int flags)
+{
+ double* limitPtr = (double*)(widgRec + offset);
+ const char* string = Tcl_GetString(*objPtr);
+ if (!string || !string[0]) {
+ *limitPtr = NAN;
+ return TCL_OK;
+ }
+
+ if (Blt_ExprDoubleFromObj(interp, *objPtr, limitPtr) != TCL_OK)
+ return TCL_ERROR;
+
+ return TCL_OK;
+}
+
+static Tcl_Obj* LimitGetProc(ClientData clientData, Tk_Window tkwin,
+ char *widgRec, int offset)
+{
+ double limit = *(double*)(widgRec + offset);
+ Tcl_Obj* objPtr;
+
+ if (!isnan(limit))
+ objPtr = Tcl_NewDoubleObj(limit);
+ else
+ objPtr = Tcl_NewStringObj("", -1);
+
+ return objPtr;
+}
+
+static Tk_CustomOptionSetProc TicksSetProc;
+static Tk_CustomOptionGetProc TicksGetProc;
+static Tk_CustomOptionFreeProc TicksFreeProc;
+Tk_ObjCustomOption ticksObjOption =
+ {
+ "ticks", TicksSetProc, TicksGetProc, RestoreProc, TicksFreeProc, NULL
+ };
+
+static int TicksSetProc(ClientData clientData, Tcl_Interp* interp,
+ Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
+ int offset, char* savePtr, int flags)
+{
+ Ticks** ticksPtrPtr = (Ticks**)(widgRec + offset);
+ *(double*)savePtr = *(double*)ticksPtrPtr;
+
+ if (!ticksPtrPtr)
+ return TCL_OK;
+
+ int objc;
+ Tcl_Obj** objv;
+ if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK)
+ return TCL_ERROR;
+
+ Ticks* ticksPtr = NULL;
+ if (objc > 0) {
+ ticksPtr = (Ticks*)malloc(sizeof(Ticks) + (objc*sizeof(double)));
+ for (int ii = 0; ii<objc; ii++) {
+ double value;
+ if (Blt_ExprDoubleFromObj(interp, objv[ii], &value) != TCL_OK) {
+ free(ticksPtr);
+ return TCL_ERROR;
+ }
+ ticksPtr->values[ii] = value;
+ }
+ ticksPtr->nTicks = objc;
+ }
+
+ *ticksPtrPtr = ticksPtr;
+
+ return TCL_OK;
+}
+
+static Tcl_Obj* TicksGetProc(ClientData clientData, Tk_Window tkwin,
+ char *widgRec, int offset)
+{
+ Ticks* ticksPtr = *(Ticks**)(widgRec + offset);
+
+ if (!ticksPtr)
+ return Tcl_NewListObj(0, NULL);
+
+ int cnt = ticksPtr->nTicks;
+ Tcl_Obj** ll = (Tcl_Obj**)calloc(cnt, sizeof(Tcl_Obj*));
+ for (int ii = 0; ii<cnt; ii++)
+ ll[ii] = Tcl_NewDoubleObj(ticksPtr->values[ii]);
+
+ Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll);
+ free(ll);
+ return listObjPtr;
+}
+
+static void TicksFreeProc(ClientData clientData, Tk_Window tkwin,
+ char *ptr)
+{
+ Ticks* ticksPtr = *(Ticks**)ptr;
+ if (ticksPtr)
+ free(ticksPtr);
+}
+
+static Tk_CustomOptionSetProc ObjectSetProc;
+static Tk_CustomOptionGetProc ObjectGetProc;
+static Tk_CustomOptionFreeProc ObjectFreeProc;
+Tk_ObjCustomOption objectObjOption =
+ {
+ "object", ObjectSetProc, ObjectGetProc, RestoreProc, ObjectFreeProc, NULL,
+ };
+
+static int ObjectSetProc(ClientData clientData, Tcl_Interp* interp,
+ Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
+ int offset, char* savePtr, int flags)
+{
+ Tcl_Obj** objectPtrPtr = (Tcl_Obj**)(widgRec + offset);
+ *(double*)savePtr = *(double*)objectPtrPtr;
+
+ if (!objectPtrPtr)
+ return TCL_OK;
+
+ Tcl_IncrRefCount(*objPtr);
+ *objectPtrPtr = *objPtr;
+
+ return TCL_OK;
+}
+
+static Tcl_Obj* ObjectGetProc(ClientData clientData, Tk_Window tkwin,
+ char *widgRec, int offset)
+{
+ Tcl_Obj** objectPtrPtr = (Tcl_Obj**)(widgRec + offset);
+
+ if (!objectPtrPtr)
+ return Tcl_NewObj();
+
+ return *objectPtrPtr;
+}
+
+static void ObjectFreeProc(ClientData clientData, Tk_Window tkwin,
+ char *ptr)
+{
+ Tcl_Obj* objectPtr = *(Tcl_Obj**)ptr;
+ if (objectPtr)
+ Tcl_DecrRefCount(objectPtr);
+}
+
+// Support
+
+static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr,
+ ClassId classId, Axis **axisPtrPtr)
+{
+ Axis *axisPtr;
+
+ if (GetAxisFromObj(interp, graphPtr, objPtr, &axisPtr) != TCL_OK)
+ return TCL_ERROR;
+
+ if (classId != CID_NONE) {
+ // Set the axis type on the first use of it.
+ if ((axisPtr->refCount == 0) || (axisPtr->obj.classId == CID_NONE))
+ Blt_GraphSetObjectClass(&axisPtr->obj, classId);
+
+ else if (axisPtr->obj.classId != classId) {
+ Tcl_AppendResult(interp, "axis \"", Tcl_GetString(objPtr),
+ "\" is already in use on an opposite ",
+ axisPtr->obj.className, "-axis",
+ NULL);
+ return TCL_ERROR;
+ }
+ axisPtr->refCount++;
+ }
+
+ *axisPtrPtr = axisPtr;
+ return TCL_OK;
+}
+
+static void ReleaseAxis(Axis *axisPtr)
+{
+ if (axisPtr) {
+ axisPtr->refCount--;
+ if (axisPtr->refCount == 0) {
+ axisPtr->flags |= DELETE_PENDING;
+ Tcl_EventuallyFree(axisPtr, FreeAxis);
+ }
+ }
+}
+
diff --git a/src/bltGrAxisOption.h b/src/bltGrAxisOption.h
new file mode 100644
index 0000000..f5f1fa6
--- /dev/null
+++ b/src/bltGrAxisOption.h
@@ -0,0 +1,39 @@
+/*
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * This code has been modified under the terms listed below and is made
+ * available under the same terms.
+ */
+
+/*
+ * Copyright 1993-2004 George A Howlett.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BltGrAxisOption_h__
+#define __BltGrAxisOption_h__
+
+extern Tk_ObjCustomOption xAxisObjOption;
+extern Tk_ObjCustomOption yAxisObjOption;
+extern Tk_ObjCustomOption limitObjOption;
+extern Tk_ObjCustomOption ticksObjOption;
+extern Tk_ObjCustomOption objectObjOption;
+
+#endif
diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C
index e1b898a..897ee72 100644
--- a/src/bltGrElemBar.C
+++ b/src/bltGrElemBar.C
@@ -32,6 +32,7 @@
#include "bltGrElemBar.h"
#include "bltGrElemOption.h"
#include "bltGrPenOp.h"
+#include "bltGrAxis.h"
#define CLAMP(x,l,h) ((x) = (((x)<(l))? (l) : ((x)>(h)) ? (h) : (x)))
diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C
index cea00d7..57cfce7 100644
--- a/src/bltGrElemLine.C
+++ b/src/bltGrElemLine.C
@@ -36,6 +36,7 @@ extern "C" {
#include "bltGrElemLine.h"
#include "bltGrElemOption.h"
#include "bltGrPenOp.h"
+#include "bltGrAxis.h"
#define SEARCH_X 0
#define SEARCH_Y 1
diff --git a/src/bltGrMarker.C b/src/bltGrMarker.C
index 34a7f72..72eea84 100644
--- a/src/bltGrMarker.C
+++ b/src/bltGrMarker.C
@@ -28,6 +28,7 @@
*/
#include "bltGrMarker.h"
+#include "bltGrAxis.h"
using namespace Blt;
diff --git a/src/bltGraph.C b/src/bltGraph.C
index b3cb89e..28247a0 100644
--- a/src/bltGraph.C
+++ b/src/bltGraph.C
@@ -37,6 +37,7 @@ extern "C" {
#include "bltOp.h"
}
+#include "bltGrAxis.h"
#include "bltGrPen.h"
#include "bltGrPenOp.h"
#include "bltGrElem.h"
diff --git a/src/bltGraph.h b/src/bltGraph.h
index 84d483e..ecde240 100644
--- a/src/bltGraph.h
+++ b/src/bltGraph.h
@@ -48,9 +48,14 @@
typedef struct _Graph Graph;
typedef struct _Crosshairs Crosshairs;
+typedef struct _Axis Axis;
class Element;
class Legend;
+typedef struct {
+ Axis *x, *y;
+} Axis2d;
+
typedef enum {
CID_NONE, CID_AXIS_X, CID_AXIS_Y, CID_ELEM_BAR, CID_ELEM_LINE,
CID_MARKER_BITMAP, CID_MARKER_IMAGE, CID_MARKER_LINE, CID_MARKER_POLYGON,
@@ -94,8 +99,6 @@ typedef struct {
const char **tags; /* Binding tags for the object. */
} GraphObj;
-#include "bltGrAxis.h"
-
typedef struct {
Segment2d *segments;
int length;