/ATF2/control-software/epics-3.14.10/extensions/src/medm3_1_4/medm/SciPlot.c
C | 2367 lines | 2009 code | 254 blank | 104 comment | 263 complexity | 3feafe23b91cab39f429457029134f13 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /*----------------------------------------------------------------------------
- * SciPlot A generalized plotting widget
- *
- * Copyright (c) 1996 Robert W. McMullen
- *
- * This library 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 library 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 library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * Author: Rob McMullen <rwmcm@mail.ae.utexas.edu>
- * http://www.ae.utexas.edu/~rwmcm
- */
- #define DEBUG_SCIPLOT 0
- #define DEBUG_SCIPLOT_VTEXT 0
- #define DEBUG_SCIPLOT_TEXT 0
- #define DEBUG_SCIPLOT_LINE 0
- #define DEBUG_SCIPLOT_AXIS 0
- #define DEBUG_SCIPLOT_ALLOC 0
- #define DEBUG_SCIPLOT_MLK 0
- /* KE: Use SCIPLOT_EPS to avoid roundoff in floor and ceil */
- #define SCIPLOT_EPS .0001
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <X11/IntrinsicP.h>
- #include <X11/StringDefs.h>
- #ifdef MOTIF
- #include <Xm/Xm.h>
- #endif
- #ifdef _MSC_VER
- /* Eliminate Microsoft C++ warnings about converting to float */
- #pragma warning (disable: 4244 4305)
- #endif
- #ifdef WIN32
- /* Hummingbird extra functions including lprintf
- * Needs to be included after Intrinsic.h for Exceed 5 */
- # include <X11/XlibXtra.h>
- /* The following is done in Exceed 6 but not in Exceed 5
- * Need it to define printf as lprintf for Windows
- * (as opposed to Console) apps */
- # ifdef _WINDOWS
- # ifndef printf
- # define printf lprintf
- # endif
- # endif
- #endif /* #ifdef WIN32 */
- #include "SciPlotP.h"
- enum sci_drag_states {NOT_DRAGGING,
- DRAGGING_NOTHING,
- DRAGGING_TOP, DRAGGING_BOTTOM,
- DRAGGING_BOTTOM_AND_LEFT,
- DRAGGING_LEFT, DRAGGING_RIGHT, DRAGGING_DATA
- };
- enum sci_draw_axis_type {DRAW_ALL,
- DRAW_AXIS_ONLY,
- DRAW_NO_LABELS
- };
- #define SCIPLOT_ZOOM_FACTOR 0.25
- #define offset(field) XtOffsetOf(SciPlotRec, plot.field)
- static XtResource resources[] =
- {
- {XtNchartType, XtCMargin, XtRInt, sizeof(int),
- offset(ChartType), XtRImmediate, (XtPointer) XtCARTESIAN},
- {XtNdegrees, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(Degrees), XtRImmediate, (XtPointer) True},
- {XtNdrawMajor, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMajor), XtRImmediate, (XtPointer) True},
- {XtNdrawMajorTics, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMajorTics), XtRImmediate, (XtPointer) True},
- {XtNdrawMinor, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMinor), XtRImmediate, (XtPointer) True},
- {XtNdrawMinorTics, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMinorTics), XtRImmediate, (XtPointer) True},
- {XtNmonochrome, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(Monochrome), XtRImmediate, (XtPointer) False},
- {XtNshowLegend, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowLegend), XtRImmediate, (XtPointer) True},
- {XtNshowTitle, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowTitle), XtRImmediate, (XtPointer) True},
- {XtNshowXLabel, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowXLabel), XtRImmediate, (XtPointer) True},
- {XtNshowYLabel, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowYLabel), XtRImmediate, (XtPointer) True},
- {XtNxLabel, XtCString, XtRString, sizeof(String),
- offset(TransientXLabel), XtRString, "X Axis"},
- {XtNyLabel, XtCString, XtRString, sizeof(String),
- offset(TransientYLabel), XtRString, "Y Axis"},
- {XtNplotTitle, XtCString, XtRString, sizeof(String),
- offset(TransientPlotTitle), XtRString, "Plot"},
- {XtNmargin, XtCMargin, XtRInt, sizeof(int),
- offset(Margin), XtRImmediate, (XtPointer) 5},
- {XtNtitleMargin, XtCMargin, XtRInt, sizeof(int),
- offset(TitleMargin), XtRImmediate, (XtPointer) 16},
- {XtNlegendLineSize, XtCMargin, XtRInt, sizeof(int),
- offset(LegendLineSize), XtRImmediate, (XtPointer) 16},
- {XtNdefaultMarkerSize, XtCMargin, XtRInt, sizeof(int),
- offset(DefaultMarkerSize), XtRImmediate, (XtPointer) 3},
- {XtNlegendMargin, XtCMargin, XtRInt, sizeof(int),
- offset(LegendMargin), XtRImmediate, (XtPointer) 3},
- {XtNlegendThroughPlot, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(LegendThroughPlot), XtRImmediate, (XtPointer) False},
- {XtNtitleFont, XtCMargin, XtRInt, sizeof(int),
- offset(TitleFont), XtRImmediate, (XtPointer) (XtFONT_HELVETICA | 24)},
- {XtNlabelFont, XtCMargin, XtRInt, sizeof(int),
- offset(LabelFont), XtRImmediate, (XtPointer) (XtFONT_TIMES | 18)},
- {XtNaxisFont, XtCMargin, XtRInt, sizeof(int),
- offset(AxisFont), XtRImmediate, (XtPointer) (XtFONT_TIMES | 10)},
- {XtNxAutoScale, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XAutoScale), XtRImmediate, (XtPointer) True},
- {XtNyAutoScale, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YAutoScale), XtRImmediate, (XtPointer) True},
- {XtNxAxisNumbers, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XAxisNumbers), XtRImmediate, (XtPointer) True},
- {XtNyAxisNumbers, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YAxisNumbers), XtRImmediate, (XtPointer) True},
- {XtNxLog, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XLog), XtRImmediate, (XtPointer) False},
- {XtNyLog, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YLog), XtRImmediate, (XtPointer) False},
- {XtNxOrigin, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XOrigin), XtRImmediate, (XtPointer) False},
- {XtNyOrigin, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YOrigin), XtRImmediate, (XtPointer) False},
- {XtNyNumbersHorizontal, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YNumHorz), XtRImmediate, (XtPointer) True},
- {XtNdragX, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DragX), XtRImmediate, (XtPointer) True},
- {XtNdragY, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DragY), XtRImmediate, (XtPointer) False},
- {XtNtrackPointer, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(TrackPointer), XtRImmediate, (XtPointer) False},
- {XtNxNoCompMinMax, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XNoCompMinMax), XtRImmediate, (XtPointer) False},
- {XtNdragXCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- offset(drag_x_callback), XtRCallback, NULL},
- {XtNdragYCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- offset(drag_y_callback), XtRCallback, NULL},
- {XtNpointerValCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- offset(pointer_val_callback), XtRCallback, NULL},
- {XtNbtn1ClickCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- offset(btn1_callback), XtRCallback, NULL},
- {XtNxFixedLeftRight, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XFixedLR), XtRImmediate, (XtPointer) False},
- {XtNxLeftSpace, XtCMargin, XtRInt, sizeof(int),
- offset(XLeftSpace), XtRImmediate, (XtPointer) (100)},
- {XtNxRightSpace, XtCMargin, XtRInt, sizeof(int),
- offset(XRightSpace), XtRImmediate, (XtPointer) (100)},
- /* KE: (From XmFrame.c) */
- #ifdef MOTIF
- {XmNshadowType, XmCShadowType, XmRShadowType, sizeof(unsigned char),
- offset(ShadowType), XmRImmediate, (XtPointer)XmINVALID_DIMENSION},
- #endif
- };
- static SciPlotFontDesc font_desc_table[] =
- {
- {XtFONT_TIMES, "Times", "times", False, True},
- {XtFONT_COURIER, "Courier", "courier", True, False},
- {XtFONT_HELVETICA, "Helvetica", "helvetica", True, False},
- {XtFONT_LUCIDA, "Lucida", "lucidabright", False, False},
- {XtFONT_LUCIDASANS, "LucidaSans", "lucida", False, False},
- {XtFONT_NCSCHOOLBOOK, "NewCenturySchlbk",
- "new century schoolbook", False, True},
- {-1, NULL, NULL, False, False},
- };
- /*
- * Private function declarations
- */
- static void Redisplay (Widget w, XEvent *event, Region region);
- static void Resize (Widget w);
- static Boolean SetValues (Widget current,
- Widget request, Widget new,
- ArgList args, Cardinal *nargs);
- static void GetValuesHook (Widget w, ArgList args,
- Cardinal *num_args);
- static void Initialize (Widget treq, Widget tnew,
- ArgList args, Cardinal *num);
- static void Realize (Widget aw, XtValueMask * value_mask,
- XSetWindowAttributes * attributes);
- static void Destroy (Widget w);
- static void ComputeAll (SciPlotWidget w, int type);
- static void ComputeAllDimensions (SciPlotWidget w, int type);
- static void DrawAll (SciPlotWidget w);
- static void ItemDrawAll (SciPlotWidget w);
- static void ItemDraw (SciPlotWidget w, SciPlotItem *item);
- static void EraseAll (SciPlotWidget w);
- static void FontInit (SciPlotWidget w, SciPlotFont *pf);
- static int ColorStore (SciPlotWidget w, Pixel color);
- static int FontStore (SciPlotWidget w, int flag);
- static int FontnumReplace (SciPlotWidget w, int fontnum, int flag);
- static void SciPlotPrintf(const char *fmt, ...);
- /* translation manager routines */
- static void sciPlotMotionAP (SciPlotWidget w,
- XEvent *event, char *args, int n_args);
- static void sciPlotBtnUpAP (SciPlotWidget w,
- XEvent *event, char *args, int n_args);
- static void sciPlotClick (SciPlotWidget w,
- XEvent *event, char *args, int n_args);
- static void sciPlotTrackPointer (SciPlotWidget w,
- XEvent *event, char *args, int n_args);
- /* KE: */
- #ifdef MOTIF
- static void DrawShadow (SciPlotWidget w, Boolean raised, real x, real y,
- real width, real height);
- #endif
- static char sciPlotTranslations[] =
- #ifndef _MEDM
- "<Btn2Motion>: Motion()\n\
- <Btn2Down>: Motion()\n\
- <Btn2Up>: BtnUp()\n\
- <Btn1Up>: Btn1Up()\n\
- <Motion>: TrackPointer()";
- #else
- "Shift<Btn1Motion>: Motion()\n\
- Shift<Btn2Motion>: Motion()\n\
- Shift<Btn1Down>: Motion()\n\
- Shift<Btn1Up>: BtnUp()\n\
- Shift<Btn2Down>: Motion()\n\
- Shift<Btn2Up>: BtnUp()\n\
- <Btn1Up>: Btn1Up()\n\
- <Motion>: TrackPointer()";
- #endif
- static XtActionsRec sciPlotActionsList[] = {
- {"Motion", (XtActionProc)sciPlotMotionAP},
- {"BtnUp", (XtActionProc)sciPlotBtnUpAP},
- {"Btn1Up", (XtActionProc)sciPlotClick},
- {"TrackPointer", (XtActionProc)sciPlotTrackPointer}
- };
- SciPlotClassRec sciplotClassRec =
- {
- {
- /* core_class fields */
- #ifdef MOTIF
- /* superclass */ (WidgetClass) & xmPrimitiveClassRec,
- #else
- /* superclass */ (WidgetClass) & widgetClassRec,
- #endif
- /* class_name */ "SciPlot",
- /* widget_size */ sizeof(SciPlotRec),
- /* class_initialize */ NULL,
- /* class_part_initialize */ NULL,
- /* class_inited */ False,
- /* initialize */ Initialize,
- /* initialize_hook */ NULL,
- /* realize */ Realize,
- /* actions */ sciPlotActionsList,
- /* num_actions */ XtNumber (sciPlotActionsList),
- /* resources */ resources,
- /* num_resources */ XtNumber(resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ True,
- /* compress_exposure */ XtExposeCompressMultiple,
- /* compress_enterleave */ True,
- /* visible_interest */ True,
- /* destroy */ Destroy,
- /* resize */ Resize,
- /* expose */ Redisplay,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ GetValuesHook,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback_private */ NULL,
- /* tm_table */ sciPlotTranslations,
- /* query_geometry */ NULL,
- /* display_accelerator */ XtInheritDisplayAccelerator,
- /* extension */ NULL
- },
- #ifdef MOTIF
- {
- /* primitive_class fields */
- /* border_highlight */ (XtWidgetProc)_XtInherit,
- /* border_unhighligh */ (XtWidgetProc)_XtInherit,
- /* translations */ XtInheritTranslations,
- /* arm_and_activate */ (XtActionProc)_XtInherit,
- /* syn_resources */ NULL,
- /* num_syn_resources */ 0,
- /* extension */ NULL
- },
- #endif
- {
- /* plot_class fields */
- /* dummy */ 0
- /* (some stupid compilers barf on empty structures) */
- }
- };
- WidgetClass sciplotWidgetClass = (WidgetClass) & sciplotClassRec;
- static void
- Initialize(Widget treq, Widget tnew, ArgList args, Cardinal *num)
- {
- SciPlotWidget new;
- new = (SciPlotWidget) tnew;
- new->plot.plotlist = NULL;
- new->plot.alloc_plotlist = 0;
- new->plot.num_plotlist = 0;
- new->plot.alloc_drawlist = NUMPLOTITEMALLOC;
- new->plot.drawlist = (SciPlotItem *) XtCalloc(new->plot.alloc_drawlist,
- sizeof(SciPlotItem));
- new->plot.num_drawlist = 0;
- new->plot.cmap = DefaultColormap(XtDisplay(new),
- DefaultScreen(XtDisplay(new)));
- new->plot.xlabel = (char *) XtMalloc(strlen(new->plot.TransientXLabel) + 1);
- strcpy(new->plot.xlabel, new->plot.TransientXLabel);
- new->plot.ylabel = (char *) XtMalloc(strlen(new->plot.TransientYLabel) + 1);
- strcpy(new->plot.ylabel, new->plot.TransientYLabel);
- new->plot.plotTitle = (char *) XtMalloc(strlen(new->plot.TransientPlotTitle) + 1);
- strcpy(new->plot.plotTitle, new->plot.TransientPlotTitle);
- new->plot.TransientXLabel=NULL;
- new->plot.TransientYLabel=NULL;
- new->plot.TransientPlotTitle=NULL;
- new->plot.colors = NULL;
- new->plot.num_colors = 0;
- new->plot.fonts = NULL;
- new->plot.num_fonts = 0;
- new->plot.update = FALSE;
- new->plot.UserMin.x = new->plot.UserMin.y = 0.0;
- new->plot.UserMax.x = new->plot.UserMax.y = 10.0;
- new->plot.titleFont = FontStore(new, new->plot.TitleFont);
- new->plot.labelFont = FontStore(new, new->plot.LabelFont);
- new->plot.axisFont = FontStore(new, new->plot.AxisFont);
- /* set initial drag state to drag_none */
- new->plot.drag_state = NOT_DRAGGING;
- new->plot.drag_start.x = 0.0;
- new->plot.drag_start.y = 0.0;
- new->plot.startx = 0.0;
- new->plot.endx = 0.0;
- new->plot.starty = 0.0;
- new->plot.endy = 0.0;
- new->plot.reach_limit = 0;
- }
- static void
- GCInitialize(SciPlotWidget new)
- {
- XGCValues values;
- XtGCMask mask;
- long colorsave;
- values.line_style = LineSolid;
- values.line_width = 0;
- values.fill_style = FillSolid;
- values.background = WhitePixelOfScreen(XtScreen(new));
- values.background = new->core.background_pixel;
- new->plot.BackgroundColor = ColorStore(new, values.background);
- /* KE: Moved this up here 1-11-01 so 1 would be the foreground color
- as in the documentation */
- values.foreground = colorsave = BlackPixelOfScreen(XtScreen(new));
- new->plot.ForegroundColor = ColorStore(new, values.foreground);
- #ifdef MOTIF
- /* KE: Primitive should keep track of colors and GC. We don't need to
- * do that. */
- new->core.background_pixel = values.background;
- {
- Pixel fg, select, shade1, shade2;
- XmGetColors(XtScreen(new), new->core.colormap,
- new->core.background_pixel, &fg, &shade1, &shade2, &select);
- new->plot.ShadowColor1 = ColorStore(new, shade1);
- new->plot.ShadowColor2 = ColorStore(new, shade2);
- new->primitive.top_shadow_color = shade1;
- new->primitive.bottom_shadow_color = shade2;
- }
- #endif
- mask = GCLineStyle | GCLineWidth | GCFillStyle | GCForeground | GCBackground;
- new->plot.defaultGC = XCreateGC(XtDisplay(new),XtWindow(new), mask, &values);
- /* Eliminate events that we do not handle anyway */
- XSetGraphicsExposures(XtDisplay(new), new->plot.defaultGC, False);
- values.foreground = colorsave;
- values.line_style = LineOnOffDash;
- new->plot.dashGC = XCreateGC(XtDisplay(new),XtWindow(new), mask, &values);
- /* Eliminate events that we do not handle anyway */
- XSetGraphicsExposures(XtDisplay(new), new->plot.dashGC, False);
- }
- static void
- Realize(Widget aw, XtValueMask * value_mask, XSetWindowAttributes * attributes)
- {
- SciPlotWidget w = (SciPlotWidget) aw;
- #define superclass (&widgetClassRec)
- (*superclass->core_class.realize) (aw, value_mask, attributes);
- #undef superclass
- GCInitialize(w);
- }
- static void
- Destroy(Widget ws)
- {
- SciPlotWidget w = (SciPlotWidget)ws;
- int i, j;
- SciPlotFont *pf;
- SciPlotList *p;
- XFreeGC(XtDisplay(w), w->plot.defaultGC);
- XFreeGC(XtDisplay(w), w->plot.dashGC);
- XtFree((char *) w->plot.xlabel);
- XtFree((char *) w->plot.ylabel);
- XtFree((char *) w->plot.plotTitle);
- for (i = 0; i < w->plot.num_fonts; i++) {
- pf = &w->plot.fonts[i];
- XFreeFont(XtDisplay((Widget) w), pf->font);
- }
- XtFree((char *) w->plot.fonts);
- XtFree((char *) w->plot.colors);
- #if DEBUG_SCIPLOT_ALLOC
- SciPlotPrintf("Destroy: alloc_plotlist=%d num_plotlist=%d\n",
- w->plot.alloc_plotlist,w->plot.num_plotlist);
- for (i = 0; i < w->plot.alloc_plotlist; i++) {
- p = w->plot.plotlist + i;
- SciPlotPrintf(" List %d: allocated=%d legend=%x markertext=%x\n",
- i, p->allocated, p->legend, p->markertext);
- }
- #endif
- for (i = 0; i < w->plot.alloc_plotlist; i++) {
- p = w->plot.plotlist + i;
- if (p->allocated > 0)
- XtFree((char *) p->data);
- if (p->legend)
- XtFree(p->legend);
- if (p->markertext) {
- for (j = 0; j < p->number; j++) {
- if (p->markertext[j])
- XtFree (p->markertext[j]);
- }
- }
- }
- if (w->plot.alloc_plotlist > 0)
- XtFree((char *) w->plot.plotlist);
- EraseAll(w);
- XtFree((char *) w->plot.drawlist);
- }
- static Boolean
- SetValues(Widget currents, Widget requests, Widget news,
- ArgList args, Cardinal *nargs)
- /* KE: requests, args, nargs are not used */
- {
- SciPlotWidget current = (SciPlotWidget)currents;
- SciPlotWidget new = (SciPlotWidget)news;
- Boolean redisplay = FALSE;
- if (current->plot.XLog != new->plot.XLog)
- redisplay = TRUE;
- else if (current->plot.YLog != new->plot.YLog)
- redisplay = TRUE;
- else if (current->plot.XOrigin != new->plot.XOrigin)
- redisplay = TRUE;
- else if (current->plot.YOrigin != new->plot.YOrigin)
- redisplay = TRUE;
- else if (current->plot.XAxisNumbers != new->plot.XAxisNumbers)
- redisplay = TRUE;
- else if (current->plot.YAxisNumbers != new->plot.YAxisNumbers)
- redisplay = TRUE;
- else if (current->plot.DrawMajor != new->plot.DrawMajor)
- redisplay = TRUE;
- else if (current->plot.DrawMajorTics != new->plot.DrawMajorTics)
- redisplay = TRUE;
- else if (current->plot.DrawMinor != new->plot.DrawMinor)
- redisplay = TRUE;
- else if (current->plot.DrawMinorTics != new->plot.DrawMinorTics)
- redisplay = TRUE;
- else if (current->plot.ChartType != new->plot.ChartType)
- redisplay = TRUE;
- else if (current->plot.Degrees != new->plot.Degrees)
- redisplay = TRUE;
- else if (current->plot.ShowLegend != new->plot.ShowLegend)
- redisplay = TRUE;
- else if (current->plot.ShowTitle != new->plot.ShowTitle)
- redisplay = TRUE;
- else if (current->plot.ShowXLabel != new->plot.ShowXLabel)
- redisplay = TRUE;
- else if (current->plot.ShowYLabel != new->plot.ShowYLabel)
- redisplay = TRUE;
- else if (current->plot.ShowTitle != new->plot.ShowTitle)
- redisplay = TRUE;
- else if (current->plot.Monochrome != new->plot.Monochrome)
- redisplay = TRUE;
- else if (current->plot.XFixedLR != new->plot.XFixedLR)
- redisplay = TRUE;
- else if ((current->plot.XLeftSpace != new->plot.XLeftSpace ||
- current->plot.XRightSpace != new->plot.XRightSpace) &&
- new->plot.XFixedLR)
- redisplay = TRUE;
- if (new->plot.TransientXLabel) {
- if (current->plot.TransientXLabel != new->plot.TransientXLabel ||
- strcmp(new->plot.TransientXLabel,current->plot.xlabel)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.xlabel);
- new->plot.xlabel = (char *) XtMalloc(strlen(new->plot.TransientXLabel) + 1);
- strcpy(new->plot.xlabel, new->plot.TransientXLabel);
- new->plot.TransientXLabel=NULL;
- }
- }
- if (new->plot.TransientYLabel) {
- if (current->plot.TransientYLabel != new->plot.TransientYLabel ||
- strcmp(new->plot.TransientYLabel,current->plot.ylabel)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.ylabel);
- new->plot.ylabel = (char *) XtMalloc(strlen(new->plot.TransientYLabel) + 1);
- strcpy(new->plot.ylabel, new->plot.TransientYLabel);
- new->plot.TransientYLabel=NULL;
- }
- }
- if (new->plot.TransientPlotTitle) {
- if (current->plot.TransientPlotTitle != new->plot.TransientPlotTitle ||
- strcmp(new->plot.TransientPlotTitle,current->plot.plotTitle)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.plotTitle);
- new->plot.plotTitle = (char *) XtMalloc(strlen(new->plot.TransientPlotTitle) + 1);
- strcpy(new->plot.plotTitle, new->plot.TransientPlotTitle);
- new->plot.TransientPlotTitle=NULL;
- }
- }
- if (current->plot.AxisFont != new->plot.AxisFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.axisFont, new->plot.AxisFont);
- }
- if (current->plot.TitleFont != new->plot.TitleFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.titleFont, new->plot.TitleFont);
- }
- if (current->plot.LabelFont != new->plot.LabelFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.labelFont, new->plot.LabelFont);
- }
- new->plot.update = redisplay;
- return redisplay;
- }
- static void
- GetValuesHook(Widget ws, ArgList args, Cardinal *num_args)
- {
- SciPlotWidget w = (SciPlotWidget)ws;
- int i;
- char **loc;
- for (i=0; i < (int)*num_args; i++) {
- loc=(char **)args[i].value;
- if (strcmp(args[i].name,XtNplotTitle)==0)
- *loc=w->plot.plotTitle;
- else if (strcmp(args[i].name,XtNxLabel)==0)
- *loc=w->plot.xlabel;
- else if (strcmp(args[i].name,XtNyLabel)==0)
- *loc=w->plot.ylabel;
- }
- }
- static void
- Redisplay(Widget ws, XEvent *event, Region region)
- /* KE: event, region not used */
- {
- SciPlotWidget w = (SciPlotWidget)ws;
- if (!XtIsRealized((Widget)w))
- return;
- if (w->plot.update) {
- Resize(ws);
- w->plot.update = FALSE;
- }
- else {
- ItemDrawAll(w);
- }
- }
- static void
- Resize(Widget ws)
- {
- SciPlotWidget w = (SciPlotWidget)ws;
- if (!XtIsRealized((Widget)w))
- return;
- EraseAll(w);
- if (w->plot.XNoCompMinMax)
- ComputeAll(w, NO_COMPUTE_MIN_MAX_X);
- else
- ComputeAll(w, COMPUTE_MIN_MAX);
- DrawAll(w);
- }
- /*
- * Private SciPlot utility functions
- */
- static int
- ColorStore (SciPlotWidget w, Pixel color)
- {
- int i;
- /* Check if it is there */
- for(i=0; i < w->plot.num_colors; i++) {
- if(w->plot.colors[i] == color) return i;
- }
- /* Not found, add it */
- w->plot.num_colors++;
- w->plot.colors = (Pixel *) XtRealloc((char *) w->plot.colors,
- sizeof(Pixel) * w->plot.num_colors);
- w->plot.colors[w->plot.num_colors - 1] = color;
- return w->plot.num_colors - 1;
- }
- static void
- FontnumStore (SciPlotWidget w, int fontnum, int flag)
- {
- SciPlotFont *pf;
- int fontflag, sizeflag, attrflag;
- pf = &w->plot.fonts[fontnum];
- fontflag = flag & XtFONT_NAME_MASK;
- sizeflag = flag & XtFONT_SIZE_MASK;
- attrflag = flag & XtFONT_ATTRIBUTE_MASK;
- switch (fontflag) {
- case XtFONT_TIMES:
- case XtFONT_COURIER:
- case XtFONT_HELVETICA:
- case XtFONT_LUCIDA:
- case XtFONT_LUCIDASANS:
- case XtFONT_NCSCHOOLBOOK:
- break;
- default:
- fontflag = XtFONT_NAME_DEFAULT;
- break;
- }
- if (sizeflag < 1)
- sizeflag = XtFONT_SIZE_DEFAULT;
- switch (attrflag) {
- case XtFONT_BOLD:
- case XtFONT_ITALIC:
- case XtFONT_BOLD_ITALIC:
- break;
- default:
- attrflag = XtFONT_ATTRIBUTE_DEFAULT;
- break;
- }
- pf->id = flag;
- FontInit(w, pf);
- }
- static int
- FontnumReplace (SciPlotWidget w, int fontnum, int flag)
- {
- SciPlotFont *pf;
- pf = &w->plot.fonts[fontnum];
- XFreeFont(XtDisplay(w), pf->font);
- FontnumStore(w, fontnum, flag);
- return fontnum;
- }
- static int
- FontStore (SciPlotWidget w, int flag)
- {
- int fontnum;
- w->plot.num_fonts++;
- w->plot.fonts = (SciPlotFont *) XtRealloc((char *) w->plot.fonts,
- sizeof(SciPlotFont) * w->plot.num_fonts);
- fontnum = w->plot.num_fonts - 1;
- FontnumStore(w, fontnum, flag);
- return fontnum;
- }
- static SciPlotFontDesc *
- FontDescLookup (int flag)
- {
- SciPlotFontDesc *pfd;
- pfd = font_desc_table;
- while (pfd->flag >= 0) {
- #if DEBUG_SCIPLOT
- SciPlotPrintf("FontDescLookup: checking if %d == %d (font %s)\n",
- flag & XtFONT_NAME_MASK, pfd->flag, pfd->PostScript);
- #endif
- if ((flag & XtFONT_NAME_MASK) == pfd->flag)
- return pfd;
- pfd++;
- }
- return NULL;
- }
- static void
- FontnumPostScriptString (SciPlotWidget w, int fontnum, char *str)
- {
- char temp[128];
- int flag, bold, italic;
- SciPlotFontDesc *pfd;
- flag = w->plot.fonts[fontnum].id;
- pfd = FontDescLookup(flag);
- if (pfd) {
- strcpy(temp, pfd->PostScript);
- bold = False;
- italic = False;
- if (flag & XtFONT_BOLD) {
- bold = True;
- strcat(temp, "-Bold");
- }
- if (flag & XtFONT_ITALIC) {
- italic = True;
- if (!bold)
- strcat(temp, "-");
- if (pfd->PSUsesOblique)
- strcat(temp, "Oblique");
- else
- strcat(temp, "Italic");
- }
- if (!bold && !italic && pfd->PSUsesRoman) {
- strcat(temp, "-Roman");
- }
- sprintf(str, "/%s findfont %d scalefont",
- temp,
- (flag & XtFONT_SIZE_MASK));
- }
- else
- sprintf(str, "/Courier findfont 10 scalefont");
- }
- static void
- FontX11String (int flag, char *str)
- {
- SciPlotFontDesc *pfd;
- pfd = FontDescLookup(flag);
- if (pfd) {
- sprintf(str, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-*-*",
- pfd->X11,
- (flag & XtFONT_BOLD ? "bold" : "medium"),
- (flag & XtFONT_ITALIC ? (pfd->PSUsesOblique ? "o" : "i") : "r"),
- (flag & XtFONT_SIZE_MASK));
- }
- else
- sprintf(str, "fixed");
- #if DEBUG_SCIPLOT
- SciPlotPrintf("FontX11String: font string=%s\n", str);
- #endif
- }
- static void
- FontInit (SciPlotWidget w, SciPlotFont *pf)
- {
- char str[256], **list;
- int num;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #if DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- SciPlotPrintf("FontInit: Found font: %s\n", list[i]);
- i++;
- }
- }
- #endif
- if (num <= 0) {
- pf->id &= ~XtFONT_ATTRIBUTE_MASK;
- pf->id |= XtFONT_ATTRIBUTE_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #if DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- SciPlotPrintf("FontInit: Attr reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- if (num <= 0) {
- pf->id &= ~XtFONT_NAME_MASK;
- pf->id |= XtFONT_NAME_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #if DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- SciPlotPrintf("FontInit: Name reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- if (num <= 0) {
- pf->id &= ~XtFONT_SIZE_MASK;
- pf->id |= XtFONT_SIZE_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #if DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- SciPlotPrintf("FontInit: Size reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- #if DEBUG_SCIPLOT
- if (1) {
- XFontStruct *f;
- int i;
- i = 0;
- while (i < num) {
- SciPlotPrintf("FontInit: Properties for: %s\n", list[i]);
- f = XLoadQueryFont(XtDisplay(w), list[i]);
- SciPlotPrintf(" Height: %3d Ascent: %d Descent: %d\n",
- f->max_bounds.ascent + f->max_bounds.descent,
- f->max_bounds.ascent, f->max_bounds.descent);
- XFreeFont(XtDisplay(w), f);
- i++;
- }
- }
- #endif
- if (num > 0) {
- /* Use the first one in the list */
- /* KE: Used to use str instead of list[0] but this failed on Linux
- * Enterprise for some unknown reason */
- pf->font = XLoadQueryFont(XtDisplay(w), list[0]);
- XFreeFontNames(list);
- } else {
- /* Use fixed */
- pf->font = XLoadQueryFont(XtDisplay(w), "fixed");
- }
- #if DEBUG_SCIPLOT
- SciPlotPrintf("FontInit: Finally ran XLoadQueryFont using: %s\n", str);
- SciPlotPrintf(" Height: %3d Ascent: %d Descent: %d\n",
- pf->font->max_bounds.ascent + pf->font->max_bounds.descent,
- pf->font->max_bounds.ascent, pf->font->max_bounds.descent);
- #endif
- }
- static XFontStruct *
- FontFromFontnum (SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- if (fontnum >= w->plot.num_fonts)
- fontnum = 0;
- f = w->plot.fonts[fontnum].font;
- return f;
- }
- static real
- FontHeight(XFontStruct *f)
- {
- return (real) (f->max_bounds.ascent + f->max_bounds.descent);
- }
- static real
- FontnumHeight(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontHeight(f);
- }
- static real
- FontDescent(XFontStruct *f)
- {
- return (real) (f->max_bounds.descent);
- }
- static real
- FontnumDescent(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontDescent(f);
- }
- static real
- FontAscent(XFontStruct *f)
- {
- return (real) (f->max_bounds.ascent);
- }
- static real
- FontnumAscent(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontAscent(f);
- }
- static real
- FontTextWidth(XFontStruct *f, char *c)
- {
- return (real) XTextWidth(f, c, strlen(c));
- }
- static real
- FontnumTextWidth(SciPlotWidget w, int fontnum, char *c)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontTextWidth(f, c);
- }
- /*
- * Private List functions
- */
- static int
- _ListNew (SciPlotWidget w)
- {
- int index;
- SciPlotList *p;
- Boolean found;
- /* First check to see if there is any free space in the index */
- found = FALSE;
- for (index = 0; index < w->plot.num_plotlist; index++) {
- p = w->plot.plotlist + index;
- if (!p->used) {
- found = TRUE;
- break;
- }
- }
- /* If no space is found, increase the size of the index */
- if (!found) {
- w->plot.num_plotlist++;
- if (w->plot.alloc_plotlist == 0) {
- w->plot.alloc_plotlist = NUMPLOTLINEALLOC;
- w->plot.plotlist = (SciPlotList *) XtCalloc(w->plot.alloc_plotlist, sizeof(SciPlotList));
- if (!w->plot.plotlist) {
- SciPlotPrintf("Can't calloc memory for SciPlotList\n");
- exit(1);
- }
- w->plot.alloc_plotlist = NUMPLOTLINEALLOC;
- }
- else if (w->plot.num_plotlist > w->plot.alloc_plotlist) {
- w->plot.alloc_plotlist += NUMPLOTLINEALLOC;
- w->plot.plotlist = (SciPlotList *) XtRealloc((char *) w->plot.plotlist,
- w->plot.alloc_plotlist * sizeof(SciPlotList));
- if (!w->plot.plotlist) {
- SciPlotPrintf("Can't realloc memory for SciPlotList\n");
- exit(1);
- }
- /* KE: XtRealloc does not zero memory as does the original XtCalloc
- * This will cause problems in Destroy for data, legend, markertest, etc.*/
- p = w->plot.plotlist + w->plot.alloc_plotlist - NUMPLOTLINEALLOC;
- memset(p, '\0', NUMPLOTLINEALLOC * sizeof(SciPlotList));
- }
- index = w->plot.num_plotlist - 1;
- p = w->plot.plotlist + index;
- }
- /* KE: Since the lists have been zeroed, only the non-zero ones
- * really need to be set */
- p->LineStyle = p->LineColor = p->PointStyle = p->PointColor = 0;
- p->number = p->allocated = 0;
- p->data = NULL;
- p->legend = NULL;
- p->draw = p->used = TRUE;
- p->markersize = (real) w->plot.DefaultMarkerSize;
- p->markertext = NULL;
- #if DEBUG_SCIPLOT_ALLOC
- SciPlotPrintf("_ListNew: alloc_plotlist=%d num_plotlist=%d\n",
- w->plot.alloc_plotlist,w->plot.num_plotlist);
- #endif
- return index;
- }
- static void
- _ListDelete (SciPlotList *p)
- {
- int i;
- if (p->markertext) {
- for (i = 0; i < p->number; i++) {
- if (p->markertext[i]) {
- XtFree (p->markertext[i]);
- p->markertext[i] = NULL;
- }
- }
- XtFree ((char *)p->markertext);
- p->markertext = NULL;
- }
- p->draw = p->used = FALSE;
- p->number = p->allocated = 0;
- if (p->data)
- XtFree((char *) p->data);
- p->data = NULL;
- if (p->legend)
- XtFree((char *) p->legend);
- p->legend = NULL;
- #if DEBUG_SCIPLOT_ALLOC
- SciPlotPrintf("_ListDelete:\n");
- #endif
- }
- static SciPlotList *
- _ListFind (SciPlotWidget w, int id)
- {
- SciPlotList *p;
- if ((id >= 0) && (id < w->plot.num_plotlist)) {
- p = w->plot.plotlist + id;
- if (p->used)
- return p;
- }
- return NULL;
- }
- static void
- _ListSetStyle (SciPlotList *p, int pcolor, int pstyle, int lcolor, int lstyle)
- {
- /* Note! Do checks in here later on... */
- if (lstyle >= 0)
- p->LineStyle = lstyle;
- if (lcolor >= 0)
- p->LineColor = lcolor;
- if (pstyle >= 0)
- p->PointStyle = pstyle;
- if (pcolor >= 0)
- p->PointColor = pcolor;
- }
- static void
- _ListSetLegend (SciPlotList *p, char *legend)
- {
- /* Note! Do checks in here later on... */
- p->legend = (char *) XtMalloc(strlen(legend) + 1);
- strcpy(p->legend, legend);
- }
- static void
- _ListAllocData (SciPlotList *p, int num)
- {
- if (p->data) {
- XtFree((char *) p->data);
- p->allocated = 0;
- }
- p->allocated = num + NUMPLOTDATAEXTRA;
- p->data = (realpair *) XtCalloc(p->allocated, sizeof(realpair));
- if (!p->data) {
- p->number = p->allocated = 0;
- }
- }
- static void
- _ListReallocData (SciPlotList *p, int more)
- {
- if (!p->data) {
- _ListAllocData(p, more);
- }
- else if (p->number + more > p->allocated) {
- p->allocated += more + NUMPLOTDATAEXTRA;
- p->data = (realpair *) XtRealloc((char *) p->data, p->allocated * sizeof(realpair));
- if (!p->data) {
- p->number = p->allocated = 0;
- }
- }
- }
- static void
- _ListAddReal (SciPlotList *p, int num, real *xlist, real *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListAddFloat (SciPlotList *p, int num, float *xlist, float *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListAddDouble (SciPlotList *p, int num, double *xlist, double *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListSetReal(SciPlotList *p, int num, real *xlist, real *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddReal(p, num, xlist, ylist);
- }
- static void
- _ListSetFloat (SciPlotList *p, int num, float *xlist, float *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddFloat(p, num, xlist, ylist);
- }
- static void
- _ListSetDouble (SciPlotList *p, int num, double *xlist, double *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddDouble(p, num, xlist, ylist);
- }
- /*
- * Private SciPlot functions
- */
- /*
- * The following vertical text drawing routine uses the "Fill Stippled" idea
- * found in xvertext-5.0, by Alan Richardson (mppa3@syma.sussex.ac.uk).
- *
- * The following code is my interpretation of his idea, including some
- * hacked together excerpts from his source. The credit for the clever bits
- * belongs to him.
- *
- * To be complete, portions of the subroutine XDrawVString are
- * Copyright (c) 1993 Alan Richardson (mppa3@syma.sussex.ac.uk)
- */
- static void
- XDrawVString (Display *display, Window win, GC gc, int x, int y, char *str, int len, XFontStruct *f)
- {
- XImage *before, *after;
- char *dest, *source, *source0, *source1;
- int xloop, yloop, xdest, ydest;
- Pixmap pix, rotpix;
- int width, height;
- GC drawGC;
- width = (int) FontTextWidth(f, str);
- height = (int) FontHeight(f);
- pix = XCreatePixmap(display, win, width, height, 1);
- rotpix = XCreatePixmap(display, win, height, width, 1);
- drawGC = XCreateGC(display, pix, 0L, NULL);
- XSetBackground(display, drawGC, 0);
- XSetFont(display, drawGC, f->fid);
- XSetForeground(display, drawGC, 0);
- XFillRectangle(display, pix, drawGC, 0, 0, width, height);
- XFillRectangle(display, rotpix, drawGC, 0, 0, height, width);
- XSetForeground(display, drawGC, 1);
- /* Eliminate events that we do not handle anyway */
- XSetGraphicsExposures(display, drawGC, False);
- XDrawImageString(display, pix, drawGC, 0, (int) FontAscent(f),
- str, strlen(str));
- source0 = (char *) calloc((((width + 7) / 8) * height), 1);
- before = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)),
- 1, XYPixmap, 0, source0, width, height, 8, 0);
- before->byte_order = before->bitmap_bit_order = MSBFirst;
- XGetSubImage(display, pix, 0, 0, width, height, 1L, XYPixmap, before, 0, 0);
- source1 = (char *) calloc((((height + 7) / 8) * width), 1);
- after = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)),
- 1, XYPixmap, 0, source1, height, width, 8, 0);
- after->byte_order = after->bitmap_bit_order = MSBFirst;
- for (yloop = 0; yloop < height; yloop++) {
- for (xloop = 0; xloop < width; xloop++) {
- source = before->data + (xloop / 8) +
- (yloop * before->bytes_per_line);
- if (*source & (128 >> (xloop % 8))) {
- dest = after->data + (yloop / 8) +
- ((width - 1 - xloop) * after->bytes_per_line);
- *dest |= (128 >> (yloop % 8));
- }
- }
- }
- #if DEBUG_SCIPLOT_VTEXT
- if (1) {
- char sourcebit;
- for (yloop = 0; yloop < before->height; yloop++) {
- for (xloop = 0; xloop < before->width; xloop++) {
- source = before->data + (xloop / 8) +
- (yloop * before->bytes_per_line);
- sourcebit = *source & (128 >> (xloop % 8));
- if (sourcebit)
- putchar('X');
- else
- putchar('.');
- }
- putchar('\n');
- }
- for (yloop = 0; yloop < after->height; yloop++) {
- for (xloop = 0; xloop < after->width; xloop++) {
- source = after->data + (xloop / 8) +
- (yloop * after->bytes_per_line);
- sourcebit = *source & (128 >> (xloop % 8));
- if (sourcebit)
- putchar('X');
- else
- putchar('.');
- }
- putchar('\n');
- }
- }
- #endif
- xdest = x - (int) FontAscent(f);
- if (xdest < 0)
- xdest = 0;
- ydest = y - width;
- XPutImage(display, rotpix, drawGC, after, 0, 0, 0, 0,
- after->width, after->height);
- XSetFillStyle(display, gc, FillStippled);
- XSetStipple(display, gc, rotpix);
- XSetTSOrigin(display, gc, xdest, ydest);
- XFillRectangle(display, win, gc, xdest, ydest, after->width, after->height);
- XSetFillStyle(display, gc, FillSolid);
- XFreeGC(display, drawGC);
- /* Free image data ourselves and mark it as null in the XImage */
- free(source0);
- free(source1);
- before->data = 0;
- after->data = 0;
- XDestroyImage(before);
- XDestroyImage(after);
- XFreePixmap(display, pix);
- XFreePixmap(display, rotpix);
- }
- static char dots[] =
- {2, 1, 1};
- static char widedots[] =
- {2, 1, 4};
- static GC
- ItemGetGC (SciPlotWidget w, SciPlotItem *item)
- {
- GC gc;
- short color;
- switch (item->kind.any.style) {
- case XtLINE_SOLID:
- gc = w->plot.defaultGC;
- break;
- case XtLINE_DOTTED:
- XSetDashes(XtDisplay(w), w->plot.dashGC, 0, &dots[1],
- (int) dots[0]);
- gc = w->plot.dashGC;
- break;
- case XtLINE_WIDEDOT:
- XSetDashes(XtDisplay(w), w->plot.dashGC, 0, &widedots[1],
- (int) widedots[0]);
- gc = w->plot.dashGC;
- break;
- default:
- return NULL;
- }
- if (w->plot.Monochrome)
- if (item->kind.any.color > 0)
- color = w->plot.ForegroundColor;
- else
- color = w->plot.BackgroundColor;
- else if (item->kind.any.color >= w->plot.num_colors)
- color = w->plot.ForegroundColor;
- else if (item->kind.any.color <= 0)
- color = w->plot.BackgroundColor;
- else
- color = item->kind.any.color;
- XSetForeground(XtDisplay(w), gc, w->plot.colors[color]);
- return gc;
- }
- static GC
- ItemGetFontGC (SciPlotWidget w, SciPlotItem *item)
- {
- GC gc;
- short color, fontnum;
- gc = w->plot.dashGC;
- if (w->plot.Monochrome)
- if (item->kind.any.color > 0)
- color = w->plot.ForegroundColor;
- else
- color = w->plot.BackgroundColor;
- else if (item->kind.any.color >= w->plot.num_colors)
- color = w->plot.ForegroundColor;
- else if (item->kind.any.color <= 0)
- color = w->plot.BackgroundColor;
- else
- color = item->kind.any.color;
- XSetForeground(XtDisplay(w), gc, w->plot.colors[color]);
- if (item->kind.text.font >= w->plot.num_fonts)
- fontnum = 0;
- else
- fontnum = item->kind.text.font;
- /*
- * fontnum==0 hack: 0 is supposed to be the default font, but the program
- * can't seem to get the default font ID from the GC for some reason. So,
- * use a different GC where the default font still exists.
- */
- XSetFont(XtDisplay(w), gc, w->plot.fonts[fontnum].font->fid);
- return gc;
- }
- static void
- ItemDraw (SciPlotWidget w, SciPlotItem *item)
- {
- XPoint point[8];
- XSegment seg;
- XRectangle rect;
- int i;
- GC gc;
- if (!XtIsRealized((Widget) w))
- return;
- if ((item->type > SciPlotStartTextTypes) && (item->type < SciPlotEndTextTypes))
- gc = ItemGetFontGC(w, item);
- else
- gc = ItemGetGC(w, item);
- if (!gc)
- return;
- #if DEBUG_SCIPLOT_LINE
- SciPlotPrintf("ItemDraw: item->type=%d\n"
- " SciPlotFALSE=%d SciPlotPoint=%d SciPlotLine=%d \n",
- item->type,SciPlotFALSE,SciPlotPoint,SciPlotLine);
- #endif
- switch (item->type) {
- case SciPlotLine:
- seg.x1 = (short) item->kind.line.x1;
- seg.y1 = (short) item->kind.line.y1;
- seg.x2 = (short) item->kind.line.x2;
- seg.y2 = (short) item->kind.line.y2;
- XDrawSegments(XtDisplay(w), XtWindow(w), gc,
- &seg, 1);
- break;
- case SciPlotRect:
- XDrawRectangle(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- break;
- case SciPlotFRect:
- XFillRectangle(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- XDrawRectangle(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- break;
- case SciPlotPoly:
- i = 0;
- while (i < item->kind.poly.count) {
- point[i].x = (int) item->kind.poly.x[i];
- point[i].y = (int) item->kind.poly.y[i];
- i++;
- }
- point[i].x = (int) item->kind.poly.x[0];
- point[i].y = (int) item->kind.poly.y[0];
- XDrawLines(XtDisplay(w), XtWindow(w), gc,
- point, i + 1, CoordModeOrigin);
- break;
- case SciPlotFPoly:
- i = 0;
- while (i < item->kind.poly.count) {
- point[i].x = (int) item->kind.poly.x[i];
- point[i].y = (int) item->kind.poly.y[i];
- i++;
- }
- point[i].x = (int) item->kind.poly.x[0];
- point[i].y = (int) item->kind.poly.y[0];
- XFillPolygon(XtDisplay(w), XtWindow(w), gc,
- point, i + 1, Complex, CoordModeOrigin);
- XDrawLines(XtDisplay(w), XtWindow(w), gc,
- point, i + 1, CoordModeOrigin);
- break;
- case SciPlotCircle:
- XDrawArc(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.circ.x - item->kind.circ.r),
- (int) (item->kind.circ.y - item->kind.circ.r),
- (unsigned int) (item->kind.circ.r * 2),
- (unsigned int) (item->kind.circ.r * 2),
- 0 * 64, 360 * 64);
- break;
- case SciPlotFCircle:
- XFillArc(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.circ.x - item->kind.circ.r),
- (int) (item->kind.circ.y - item->kind.circ.r),
- (unsigned int) (item->kind.circ.r * 2),
- (unsigned int) (item->kind.circ.r * 2),
- 0 * 64, 360 * 64);
- break;
- case SciPlotText:
- XDrawString(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.text.x), (int) (item->kind.text.y),
- item->kind.text.text,
- (int) item->kind.text.length);
- break;
- case SciPlotVText:
- XDrawVString(XtDisplay(w), XtWindow(w), gc,
- (int) (item->kind.text.x), (int) (item->kind.text.y),
- item->kind.text.text,
- (int) item->kind.text.length,
- FontFromFontnum(w, item->kind.text.font));
- break;
- case SciPlotClipRegion:
- rect.x = (short) item->kind.line.x1;
- rect.y = (short) item->kind.line.y1;
- rect.width = (short) item->kind.line.x2;
- rect.height = (short) item->kind.line.y2;
- XSetClipRectangles(XtDisplay(w), w->plot.dashGC, 0, 0, &rect, 1, Unsorted);
- XSetClipRectangles(XtDisplay(w), w->plot.defaultGC, 0, 0, &rect, 1, Unsorted);
- break;
- case SciPlotClipClear:
- XSetClipMask(XtDisplay(w), w->plot.dashGC, None);
- XSetClipMask(XtDisplay(w), w->plot.defaultGC, None);
- break;
- default:
- #if DEBUG_SCIPLOT_LINE
- SciPlotPrintf("ItemDraw: default case\n");
- #endif
- break;
- }
- }
- static void
- ItemDrawAll (SciPlotWidget w)
- {
- SciPlotItem *item;
- int i;
- if (!XtIsRealized((Widget) w))
- return;
- item = w->plot.drawlist;
- i = 0;
- while (i < w->plot.num_drawlist) {
- ItemDraw(w, item);
- i++;
- item++;
- }
- }
- /*
- * PostScript (r) functions ------------------------------------------------
- *
- */
- typedef struct {
- char *command;
- char *prolog;
- } PScommands;
- static PScommands psc[] =
- {
- {"ma", "moveto"},
- {"da", "lineto stroke newpath"},
- {"la", "lineto"},
- {"poly", "closepath stroke newpath"},
- {"fpoly", "closepath fill newpath"},
- {"box", "1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath stroke newpath"},
- {"fbox", "1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill newpath"},
- {"clipbox", "gsave 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath clip newpath"},
- {"unclip", "grestore newpath"},
- {"cr", "0 360 arc stroke newpath"},
- {"fcr", "0 360 arc fill newpath"},
- {"vma", "gsave moveto 90 rotate"},
- {"norm", "grestore"},
- {"solid", "[] 0 setdash"},
- {"dot", "[.25 2] 0 setdash"},
- {"widedot", "[.25 8] 0 setdash"},
- {"rgb", "setrgbcolor"},
- {NULL, NULL}
- };
- enum PSenums {
- PSmoveto, PSlineto,
- PSpolyline, PSendpoly, PSendfill,
- PSbox, PSfbox,
- PSclipbox, PSunclip,
- PScircle, PSfcircle,
- PSvmoveto, PSnormal,
- PSsolid, PSdot, PSwidedot,
- PSrgb
- };
- static void
- ItemPSDrawAll (SciPlotWidget w, FILE *fd, float yflip, int usecolor)
- {
- int i, loopcount;
- SciPlotItem *item;
- XcmsColor currentcolor;
- int previousfont, previousline, currentfont, currentline, previouscolor;
- item = w->plot.drawlist;
- loopcount = 0;
- previousfont = 0;
- previouscolor = -1;
- previousline = XtLINE_SOLID;
- while (loopcount < w->plot.num_drawlist) {
- /* 2 switch blocks: 1st sets up defaults, 2nd actually draws things. */
- currentline = previousline;
- currentfont = previousfont;
- switch (item->type) {
- case SciPlotLine:
- case SciPlotCircle:
- currentline = item->kind.any.style;
- break;
- default:
- break;
- }
- if (currentline != XtLINE_NONE) {
- if (currentline != previousline) {
- switch (item->kind.any.style) {
- case XtLINE_SOLID:
- fprintf(fd, "%s ", psc[PSsolid].command);
- break;
- case XtLINE_DOTTED:
- fprintf(fd, "%s ", psc[PSdot].command);
- break;
- case XtLINE_WIDEDOT:
- fprintf(fd, "%s ", psc[PSwidedot].command);
- break;
- }
- previousline = currentline;
- }
- if (usecolor && item->kind.any.color != previouscolor) {
- /* Get Pixel index */
- currentcolor.pixel = w->plot.colors[item->kind.any.color];
- #ifdef WIN32
- /* Exceed 5 does not have Xcms routines
- * Only want to get colors as XcmsFloat=double in range [0.0,1.0]
- * So use XQueryColors and convert */
- {
- XColor xcolor;
- XQueryColor( XtDisplay(w), w->plot.cmap, &xcolor);
- currentcolor.spec.RGBi.red = (double)xcolor.red/65535.;
- currentcolor.spec.RGBi.green = (double)xcolor.green/65535.;
- currentcolor.spec.RGBi.blue = (double)xcolor.blue/65535.;
- currentcolor.format = XcmsRGBiFormat;
- }
- #else
- /* Get RGBi components [0.0,1.0] */
- XcmsQueryColor( XtDisplay(w), w->plot.cmap, ¤tcolor,
- XcmsRGBiFormat );
- #endif
- /* output PostScript command */
- fprintf(fd, "%f %f %f %s ", currentcolor.spec.RGBi.red,
- currentcolor.spec.RGBi.green, currentcolor.spec.RGBi.blue,
- psc[PSrgb].command);
- previouscolor=item->kind.any.color;
- }
- switch (item->type) {
- case SciPlotLine:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.line.x1, yflip - item->kind.line.y1,
- psc[PSmoveto].command,
- item->kind.line.x2, yflip - item->kind.line.y2,
- psc[PSlineto].command);
- break;
- case SciPlotRect:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.rect.x,
- yflip - item->kind.rect.y - (item->kind.rect.h - 1.0),
- psc[PSmoveto].command,
- item->kind.rect.w - 1.0, item->kind.rect.h - 1.0,
- psc[PSbox].command);
- break;
- case SciPlotFRect:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.rect.x,
- yflip - item->kind.rect.y - (item->kind.rect.h - 1.0),
- psc[PSmoveto].command,
- item->kind.rect.w - 1.0, item->kind.rect.h - 1.0,
- psc[PSfbox].command);
- break;
- case SciPlotPoly:
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[0], yflip - item->kind.poly.y[0],
- psc[PSmoveto].command);
- for (i = 1; i < item->kind.poly.count; i++) {
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[i],
- yflip - item->kind.poly.y[i],
- psc[PSpolyline].command);
- }
- fprintf(fd, "%s\n", psc[PSendpoly].command);
- break;
- case SciPlotFPoly:
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[0], yflip - item->kind.poly.y[0],
- psc[PSmoveto].command);
- for (i = 1; i < item->kind.poly.count; i++) {
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[i],
- yflip - item->kind.poly.y[i],
- psc[PSpolyline].command);
- }
- fprintf(fd, "%s\n", psc[PSendfill].command);
- break;
- case SciPlotCircle:
- fprintf(fd, "%.2f %.2f %.2f %s\n",
- item->kind.circ.x, yflip - item->kind.circ.y,
- item->kind.circ.r,
- psc[PScircle].command);
- break;
- case SciPlotFCircle:
- fprintf(fd, "%.2f %.2f %.2f %s\n",
- item->kind.circ.x, yflip - item->kind.circ.y,
- item->kind.circ.r,
- psc[PSfcircle].command);
- break;
- case Sci…
Large files files are truncated, but you can click here to view the full file