/* Widgetklasse: XwHistspectrWidgetClass WHistspectr.c $Revision: 2.1 $ $Log: Whistspectr.c,v $ Revision 2.1 2003/12/27 13:41:22 keidel Whistspectr added This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /****************************************************************** Widgetclass: XwHistspectrWidgetClass written by: WizAnt Software Jürgen Keidel Bergstrasse 15 D 85080 Gaimersheim Tel: D 08406 379 E-mail: wizant.keidel@freenet.de 2003 ******************************************************************/ /* History: initial: Tue Dec 9 08:14:39 CET 2003 */ /* include */ #include #include #ifdef LINUX #define __USE_BSD #endif #include #include #include #include #include #include #ifdef __cplusplus extern "C"{ #endif #define offset(field) XtOffsetOf(XwHistspectrRec, field) #ifndef strdup char *strdup(const char *s); #endif /****** private Funktions Deklaration ******/ #ifdef _NO_PROTO /* Deklaration der Methoden */ static void Initialize(); static Boolean SetValues (); static void Redisplay(); static void Resize(); static void Destroy( ); /* Deklaration der privaten Funktionen */ static void get_proportion(); static void Gethistspectr_gc(); static void clear_histspectr(); static void scale(); static void drawgrid(); static void drawspectr(); static void drawannot(); static void copyannot(); static void copypix(); static void dancevals(); #else /* Deklaration der Methoden */ static void Initialize ( Widget , Widget , ArgList , Cardinal *); static Boolean SetValues ( Widget curr, Widget requ, Widget new , ArgList args , Cardinal *numargs); static void Redisplay (Widget w, XEvent *event, Region region); static void Resize ( Widget ); static void Destroy ( Widget ); /* Deklaration der privaten Funktionen */ static void get_proportion ( XwHistspectrWidget ); static void Gethistspectr_gc ( XwHistspectrWidget ); static void clear_histspectr (XwHistspectrWidget ); static void scale (XwHistspectrWidget); static void drawgrid (XwHistspectrWidget ); static void drawspectr (XwHistspectrWidget , w3dPoint *val , float time , int npoints); static void drawannot (XwHistspectrWidget cw); static void copyannot (XwHistspectrWidget cw ,Drawable target , double yoffset); static void copypix (XwHistspectrWidget cw ); static void dancevals (XwHistspectrWidget cw ); #endif /* _NO_PROTO */ /* Definition der Resourcen-Liste */ static XtResource resources[] = { /* * { * XmNinputCallback, * NULL, * XtRCallback, * sizeof(XtPointer), * offset(histspectr.input_callback), * XtRCallback, * NULL * * }, */ { XmNexposeCallback, XmCExposeCallback, XtRCallback, sizeof(XtPointer), offset(histspectr.expose_callback), XtRCallback, NULL }, { XmNresizeCallback, XmCResizeCallback, XtRCallback, sizeof(XtPointer), offset(histspectr.resize_callback), XtRCallback, NULL }, { XwNhistspectrAutoscale , XwCHistspectrAutoscale, XtRInt , sizeof(short int), offset(histspectr.autoscale), XtRImmediate, NoAuto }, { XwNhistspectrGridScale , XwCHistspectrGridScale, XtRFloat , sizeof(float *), offset(histspectr.gr), XtRImmediate, NULL }, { XwNhistspectrScale, XwCHistspectrScale, XtRFloat , sizeof(float *), offset(histspectr.vis), XtRImmediate, NULL }, { XwNhistspectrAnnotColor, /* annotation foreground */ XwCHistspectrAnnotColor, XtRPixel , sizeof(Pixel), offset(histspectr.anncolor), XtRImmediate, (XtPointer) 1 }, { XwNhistspectrBackground , /* background of curve window */ XwCHistspectrBackground , XtRPixel , sizeof(Pixel), offset(histspectr.background), XtRImmediate, (XtPointer) 1 }, { XwNhistspectrAnnotTNdec, XwCHistspectrAnnotTNdec, XtRInt , sizeof(int), offset(histspectr.tndecimals), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotYNdec, XwCHistspectrAnnotYNdec, XtRInt , sizeof(int), offset(histspectr.yndecimals), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotXNdec, XwCHistspectrAnnotXNdec, XtRInt , sizeof(int), offset(histspectr.xndecimals), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotXNgrid, XwCHistspectrAnnotXNgrid, XtRInt , sizeof(int), offset(histspectr.xnthgridanno), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotTNgrid, XwCHistspectrAnnotTNgrid, XtRInt , sizeof(int), offset(histspectr.tnthgridanno), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotYNgrid, XwCHistspectrAnnotYNgrid, XtRInt , sizeof(int), offset(histspectr.ynthgridanno), XtRImmediate, (XtPointer) 0 }, { XwNhistspectrAnnotation, XwCHistspectrAnnotation, XtRBool , sizeof(short int), offset(histspectr.anflag), XtRImmediate, (XtPointer) TRUE }, { XwNhistspectrLines, XwCHistspectrLines, XtRBool , sizeof(short int), offset(histspectr.lines), XtRImmediate, (XtPointer) TRUE }, { XwNhistspectrAddtext, XwCHistspectrAddtext, XtRString, sizeof(char *), offset(histspectr.fixtext), XtRImmediate, (XtPointer) NULL }, { XwNhistspectrFill, /* fill area under curve */ XwCHistspectrFill, XtRPixel , sizeof(Pixel), offset(histspectr.fillcolor), XtRImmediate, (XtPointer) 1 }, { XwNhistspectrCurveColor, /* curve color (line)*/ XwCHistspectrCurveColor, XtRPixel , sizeof(Pixel), offset(histspectr.linecolor), XtRImmediate, (XtPointer) 1 }, { XwNhistspectrAngle, XwCHistspectrAngle, XtRInt, sizeof(int), offset(histspectr.Angle), XtRImmediate, (XtPointer) XwHistspectrDefaultAngle }, { XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), offset(histspectr.font_list), XtRImmediate, NULL }, }; /*Definition der Translation Tabelle */ /* Definition der Aktionen für die Translation-Tabelle */ /* Klasseninitialisierung für die XwHistspectrClass */ XwHistspectrClassRec xwHistspectrClassRec = { { /* core_Class Felder */ /* Superklasse */ (WidgetClass) & xmPrimitiveClassRec, /* Klassenname */ "XwHistspectr", /* Widget groesse */ sizeof(XwHistspectrRec), /* Class_initialize */ NULL, /* Class_part_initialize */ NULL, /* class_inited intern */ FALSE, /* initialize */ Initialize, /* initialize_hook (dynami)*/ NULL, /* realize (XCreateWindow) */ XtInheritRealize, /* actions */ NULL, /* Anzahl der Action */ 0, /* Resourcen */ resources, /* Resourcen anzahl */ XtNumber(resources), /* xrm_class intern */ NULLQUARK, /* compressmotion */ TRUE, /* compress_exposure */ XtExposeCompressMaximal, /* compress_enterleave */ TRUE, /* VisibilityNotify */ FALSE, /* destroy */ Destroy, /* resize */ Resize, /* expose */ Redisplay, /* set_values */ SetValues, /* set_values_hook */ NULL, /* set_values_almost */ XtInheritSetValuesAlmost, /* get_values_hook */ NULL, /* accept_focus */ NULL, /* version */ XtVersion, /* callback_private */ NULL, /* tm_table */NULL, /* query_geometry */ NULL, /* display_accelerator */ XtInheritDisplayAccelerator, /* extension */ NULL }, { /* Primitive_Class felder */ /* border_highlight */ NULL, /* border_unhighlight */ NULL, /* translations */ XtInheritTranslations, /* arm_and_activate */ NULL, /* syn resources */ NULL, /* num_syn_resources */ 0, /* extension */ NULL, }, { /* Whistspectr_Class felder */ /* extensions */ NULL, }, }; WidgetClass XwHistspectrWidgetClass = (WidgetClass) &xwHistspectrClassRec; static float defaultscal[6] = {0.0,100.0,0.0,100.0,0,100.0}; static float defaultgrid[6] = {0.0,10.0,0.0,10.0,0.0,20.0}; /*************************************************************************** *************************************************************************** * * Functionname: Initialize * * * Prototype: static void Initialize (Widget treq, Widget tnew, ArgList args, * Cardinal *num_args); * * Input: Widget treq, Widget tnew, ArgList args, * Cardinal *num_args * * Output: * * Return: * * Documentation: Method, called from X, creating the Widget. * The Instances are checked, dependent parameters * calculated from resources, pixmaps and GC's created * initial clearing of pixmaps, and setting the grid * * * History: Sun Jan 18 08:57:43 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args) { XwHistspectrWidget new = (XwHistspectrWidget) tnew; /* Convert pointer type to Instancerecord */ float *interm; Dimension width,height; /* for safety, cannot be smaller */ if(new->core.width < minsize) new->core.width = minsize; if(new->core.height < minsize) new->core.height = minsize; if(new->histspectr.fixtext && new->histspectr.fixtext[0] ){ new->histspectr.fixtext = strdup(new->histspectr.fixtext); new->histspectr.dofixtext = TRUE; }else{ new->histspectr.fixtext = NULL; new->histspectr.dofixtext = FALSE; } new->histspectr.mark = 0; new->primitive.highlight_thickness = 0; /* copy scaling and grid definition over to internal storage, as application might free the array */ interm = (float *)XtMalloc(sizeof(float)*6); if(!interm ) XtWarning("WHistspectr create cannot XtMalloc"); if(new->histspectr.vis) memcpy(interm, new->histspectr.vis , 6*sizeof(float)); else memcpy(interm, defaultscal , 6*sizeof(float)); new->histspectr.vis = interm; interm = (float *)XtMalloc(sizeof(float)*6); if(!interm ) XtWarning("WHistspectr create cannot XtMalloc"); if(new->histspectr.gr ) memcpy(interm, new->histspectr.gr , 6*sizeof(float)); else memcpy(interm, defaultgrid , 6*sizeof(float)); new->histspectr.angle = (M_PI * new->histspectr.Angle) / 180.0; new->histspectr.gr = interm; new->histspectr.sc.at = new->histspectr.gr[0]; new->histspectr.exposed = 0; /* count to get first exposure */ new->histspectr.lastanncnt = 1; new->histspectr.curve = NULL; new->histspectr.curvepoint = 0; /* Wenn keine Fontliste durch Resourcen gesetzt ist,laden die Default-Fontliste */ if (new->histspectr.font_list == NULL){ new->histspectr.font_list = _XmGetDefaultFontList((Widget) new, XmLABEL_FONTLIST); } /* set all colours , is not explicitely set, inherit from parent */ if (new->histspectr.background == 1) new->histspectr.background = new->core.background_pixel; if(new->histspectr.anncolor == 1) new->histspectr.anncolor = new->primitive.foreground; if(new->histspectr.fillcolor == 1) new->histspectr.fillcolor = new->histspectr.background; if(new->histspectr.linecolor == 1) new->histspectr.linecolor = new->primitive.foreground; /* Die Fonts für die Fontliste laden */ if (new->histspectr.font_list ){ new->histspectr.font_list = XmFontListCopy(new->histspectr.font_list); _XmFontListGetDefaultFont( new->histspectr.font_list, &new->histspectr.font_struct); } else{ new->histspectr.font_struct = XLoadQueryFont(XtDisplay(new), "fixed"); } new->histspectr.panno = (Pixmap)NULL; get_proportion(new); /* calculate sizes and starting */ new->histspectr.pix = XCreatePixmap(XtDisplay(new), RootWindow(XtDisplay(new), DefaultScreen(XtDisplay(new))), new->histspectr.pixwidth, new->histspectr.pixheight, new->core.depth); if(new->histspectr.anflag ){ height = new->histspectr.pixheight; width = new->histspectr.annsiz; if(width > 0 && height > 0) new->histspectr.panno = XCreatePixmap(XtDisplay(new), RootWindow(XtDisplay(new), DefaultScreen(XtDisplay(new))), width, height,new->core.depth); else{ new->histspectr.anflag = FALSE; XtWarning("Bad size, Annotation set to FALSE"); } } new->histspectr.lasttim = new->histspectr.vis[0] ; new->histspectr.foldx = new->histspectr.pixwidth - new->histspectr.width; new->histspectr.foldy = new->histspectr.height; new->histspectr.Xpos = new->histspectr.width; Gethistspectr_gc(new); scale(new); /* scale the widget */ drawgrid(new ); new->histspectr.lasttim = 0.0; } /*************************************************************************** *************************************************************************** * * Functionname: SetValues * * Input: Widget curr,Widget requ, Widget new, ArgList args, Cardinal *numargs * * Return: * * Documentation: Die Funktion wird von Xt als Methode aufgerufen wenn die Applikation * XtSetValue() oder XtSetValues() aufruft. In dieser Funktion wird über- * prüft ob sich eine Wert der Ressourcen Variablen für die Widgetklasse * geändert hat. Ist dies der Fall werden die davon abhängigen privaten * Instanzvariablen neu berechnet. Wenn sich die Skalierung, der Grid oder * Annotation, bzw. Histspectr-Richtung geaendert hat, wird das Widget komplett * neu gezeichnet. * * * * History: wizant Sun Jan 18 08:58:14 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ /* ARGSUSED */ static Boolean SetValues ( Widget curr, Widget requ, Widget new, ArgList args, Cardinal *numargs){ XwHistspectrWidget current = (XwHistspectrWidget) curr; XwHistspectrWidget newon = (XwHistspectrWidget) new; int i; Boolean rescale = FALSE , reset = FALSE; XGCValues values; XtGCMask valuemask = GCFont ; float *interm , *oldinterm; Dimension width,height; unsigned long colorpix[4]; if(!XwIsHistspectr(curr)){ XtWarning("BAD widget id in XwHistspectr SetValues"); return FALSE; } /* for safety, cannot be smaller */ if(newon->core.width < minsize) newon->core.width = minsize; if(newon->core.height < minsize) newon->core.height = minsize; i=0; if(newon->histspectr.background != current->histspectr.background) colorpix[i++] = current->histspectr.background; if(newon->histspectr.anncolor != current->histspectr.anncolor) colorpix[i++] = current->histspectr.anncolor; if(newon->histspectr.fillcolor != current->histspectr.fillcolor) colorpix[i++] = current->histspectr.fillcolor; if(newon->histspectr.linecolor != current->histspectr.linecolor) colorpix[i++] = current->histspectr.linecolor; if(i) XFreeColors(XtDisplay(current), DefaultColormap(XtDisplay(current) ,DefaultScreen(XtDisplay(current))),colorpix,i,0); if(newon->histspectr.xndecimals != current->histspectr.xndecimals){ get_proportion(newon); /* recalculate sizes and starting */ rescale = TRUE; } if(newon->histspectr.yndecimals != current->histspectr.yndecimals){ get_proportion(newon); /* recalculate sizes and starting */ rescale = TRUE; } if(newon->histspectr.fixtext != current->histspectr.fixtext){ if(current->histspectr.fixtext ){ free(current->histspectr.fixtext); current->histspectr.fixtext = NULL; } if(newon->histspectr.fixtext && newon->histspectr.fixtext[0]){ newon->histspectr.fixtext = strdup(newon->histspectr.fixtext); newon->histspectr.dofixtext = TRUE; }else{ newon->histspectr.fixtext = NULL; newon->histspectr.dofixtext = FALSE; } } if(newon->histspectr.autoscale & AutoAbs) newon->histspectr.lasttim = 0; /* Prüfen ob sich die Fontliste geändert hat */ if(newon->histspectr.font_list != current->histspectr.font_list){ if((current->histspectr.font_list == NULL) && (current->histspectr.font_struct != NULL)) XFreeFont(XtDisplay(current), current->histspectr.font_struct); if( current->histspectr.font_list) XmFontListFree(current->histspectr.font_list); if( newon->histspectr.font_list == NULL) newon->histspectr.font_list = _XmGetDefaultFontList((Widget) newon, XmLABEL_FONTLIST); if( newon->histspectr.font_list != NULL){ newon->histspectr.font_list = XmFontListCopy(newon->histspectr.font_list); _XmFontListGetDefaultFont(newon->histspectr.font_list, &newon->histspectr.font_struct); } else newon->histspectr.font_struct = XLoadQueryFont(XtDisplay(newon),"fixed"); /* now push font to GC's */ values.font = newon->histspectr.font_struct->fid; XChangeGC(XtDisplay(newon), newon->histspectr.gc, valuemask, &values); XChangeGC(XtDisplay(newon), newon->histspectr.anngc, valuemask, &values); } if(newon->histspectr.Angle != current->histspectr.Angle){ newon->histspectr.angle = (M_PI * newon->histspectr.Angle) / 180.0; rescale = TRUE; reset = TRUE; } /* check and recalculate display relative parameters, recreate pixmaps */ if( newon->histspectr.anflag != current->histspectr.anflag || newon->histspectr.dofixtext != current->histspectr.dofixtext){ if(newon->histspectr.pix) XFreePixmap(XtDisplay(newon),newon->histspectr.pix); if(newon->histspectr.panno) XFreePixmap(XtDisplay(newon),newon->histspectr.panno); newon->histspectr.panno = (Pixmap)NULL; /* put NULL in, there is no pixmap */ get_proportion(newon); /* recalculate sizes and starting */ newon->histspectr.pix = XCreatePixmap(XtDisplay(newon), RootWindow(XtDisplay(newon), DefaultScreen(XtDisplay(newon))), newon->histspectr.pixwidth, newon->histspectr.pixheight, newon->core.depth); if(newon->histspectr.anflag ){ height = newon->histspectr.pixheight; width = newon->histspectr.annsiz; if(width > 0 && height > 0) newon->histspectr.panno = XCreatePixmap(XtDisplay(newon), RootWindow(XtDisplay(newon), DefaultScreen(XtDisplay(newon))), width, height,newon->core.depth); } rescale = TRUE; } /* set all colors if changed or not into GC */ XSetForeground(XtDisplay(newon) , newon->histspectr.gc,newon->histspectr.linecolor); XSetForeground(XtDisplay(newon) , newon->histspectr.anngc,newon->histspectr.anncolor); XSetBackground(XtDisplay(newon) , newon->histspectr.gc,newon->histspectr.background); XSetBackground(XtDisplay(newon) , newon->histspectr.anngc,newon->core.background_pixel); /* copy scaling and grid definition over to internal storage, as application might free the array */ if(newon->histspectr.vis != current->histspectr.vis ){ reset = TRUE; oldinterm = current->histspectr.vis; interm = newon->histspectr.vis; newon->histspectr.vis = (float *)XtMalloc(sizeof(float)*6); if(!newon->histspectr.vis ) { XtWarning("WHistspectr SetValues cannot XtMalloc"); newon->histspectr.vis = oldinterm; }else{ memcpy(newon->histspectr.vis , interm , 6*sizeof(float)); if(current->histspectr.vis) XtFree((char *)current->histspectr.vis); } rescale = TRUE ; } if(newon->histspectr.gr != current->histspectr.gr ){ reset = TRUE; interm = newon->histspectr.gr; oldinterm = current->histspectr.gr; newon->histspectr.gr = (float *)XtMalloc(sizeof(float)*6); if(!newon->histspectr.gr ) { XtWarning("WHistspectr SetValues cannot XtMalloc"); newon->histspectr.gr = oldinterm; }else{ memcpy(newon->histspectr.gr, interm , 6*sizeof(float)); if(current->histspectr.gr) XtFree((char *)current->histspectr.gr); } rescale = TRUE ; newon->histspectr.sc.at = newon->histspectr.gr[0]; } if(newon->histspectr.tndecimals != current->histspectr.tndecimals) current->histspectr.tndecimals =newon->histspectr.tndecimals; if(newon->histspectr.xndecimals != current->histspectr.xndecimals) current->histspectr.xndecimals = newon->histspectr.xndecimals , rescale=TRUE; /** now redisplay etc */ if(rescale){ /* rescale all and clear pixmap, create grid and copy it into visible */ newon->histspectr.mark = 0; scale (newon); /* new scaling */ clear_histspectr(newon); /******************* re-offset */ /* for(i=0;ihistspectr.nactc;i++){ */ /* first rescale all oldpoints in bars */ if(reset){ newon->histspectr.Xoffset = newon->histspectr.pixwidth - newon->histspectr.width; newon->histspectr.Yoffset = 0; /* newon->histspectr.init = 0; */ newon->histspectr.oldx = newon->histspectr.pixwidth - newon->histspectr.width; newon->histspectr.oldy = newon->histspectr.foldy = 0; newon->histspectr.foldx = newon->histspectr.oldx ; }else { newon->histspectr.foldx = (newon->histspectr.pixwidth - newon->histspectr.width) - (newon->histspectr.lasttim- newon->histspectr.sc.at ) * newon->histspectr.sc.bt * cos(newon->histspectr.angle); newon->histspectr.oldx = newon->histspectr.foldx; newon->histspectr.foldy = (newon->histspectr.lasttim - newon->histspectr.sc.at ) * newon->histspectr.sc.bt * sin(newon->histspectr.angle); newon->histspectr.oldy = newon->histspectr.foldy; } /* } */ /* need a clear */ drawgrid(newon); if(newon->histspectr.exposed){ XClearArea(XtDisplay(newon), XtWindow(newon), newon->histspectr.xv, 0, newon->histspectr.width, XtHeight(newon), FALSE); drawannot(newon); } } return TRUE; } /*************************************************************************** *************************************************************************** * * Functionname: get_proportion * * * Prototype: static void get_proportion(XwHistspectrWidget cw); * * Input: XwHistspectrWidget cw * * Output: * * Return: * * Documentation: calculates all sizedependent parameters inside the * widget. Visible part size and position, pixmap sizes * * * History: Sun Jan 18 08:58:33 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void get_proportion(XwHistspectrWidget cw){ int len , cheight = (cw->histspectr.font_struct->ascent - cw->histspectr.font_struct->descent); char annot[40]; cw->histspectr.width = XtWidth(cw) ; cw->histspectr.height = XtHeight(cw) ; cw->histspectr.xv = cw->histspectr.yv = 0; /* correct illegal annotation-flag combinations */ if(cw->histspectr.anflag){ cw->histspectr.yv += (cheight+2)*2; if(cw->histspectr.dofixtext) cw->histspectr.yv += cheight+2; cw->histspectr.height -= cw->histspectr.yv ; sprintf(annot,"% .*f", cw->histspectr.yndecimals,(cw->histspectr.vis[2] +cw->histspectr.vis[3])*10.); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) +8; /* grid space 6 pixels */ cw->histspectr.width -= len; cw->histspectr.xv = len ; sprintf(annot,"% .*f", cw->histspectr.tndecimals,cw->histspectr.vis[1]*100.); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) +8; cw->histspectr.width -= len; cw->histspectr.annsiz = len; /* width of annotation pixmap */ } if((signed short)cw->histspectr.width < 0) cw->histspectr.width = XtWidth(cw) ; if((signed short )cw->histspectr.height < 0) cw->histspectr.height = XtHeight(cw) ; cw->histspectr.pixwidth = cw->histspectr.width * 3; /* 3 times bigger pixmap */ cw->histspectr.pixheight = cw->histspectr.height * 3; cw->histspectr.Xoffset = cw->histspectr.pixwidth - cw->histspectr.width; cw->histspectr.Yoffset = 0; } /*************************************************************************** *************************************************************************** * * Functionname: Gethistspectr_gc * * * Prototype: static void Gethistspectr_gc(XwHistspectrWidget cw); * * Input: XwHistspectrWidget cw * * Output: * * Return: * * Documentation: Creates all needed GC's setting the font to all of them * setting background/foreground colours from resources * * * History: Sun Jan 18 08:58:51 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void Gethistspectr_gc(XwHistspectrWidget cw){ XGCValues values; XtGCMask mask = GCForeground | GCBackground | GCFont ; /* Erzeugendes diagram GCs */ values.foreground = cw->primitive.foreground; values.background = cw->histspectr.background; values.font = cw->histspectr.font_struct->fid; cw->histspectr.gc = XCreateGC(XtDisplay(cw),cw->histspectr.pix, mask, &values); /* Erzeugen des annotation GCs */ values.foreground = cw->histspectr.anncolor; values.background = cw->core.background_pixel; cw->histspectr.anngc = XCreateGC(XtDisplay(cw),cw->histspectr.pix, mask, &values); /* Create the GC for dancevals etc */ values.foreground = cw->primitive.foreground; values.background = cw->histspectr.background; values.font = cw->histspectr.font_struct->fid; clear_histspectr(cw ); } /*************************************************************************** *************************************************************************** * * Functionname: Redisplay * * * Prototype: static void Redisplay(Widget w, XEvent *event, Region region); * * Input: Widget w, XEvent *event, Region region * * Output: * * Return: * * Documentation: This is the Expose method for X * The region and event parameter are ignored. * actually the active pixmap parts are replotted and the * annotation redrawed * * * History: Sun Jan 18 08:59:13 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void Redisplay(Widget w, XEvent *event, Region region){ XwHistspectrWidget cw = (XwHistspectrWidget) w; XwHistspectrCallbackStruct call_value; XExposeEvent *xexpose =(XExposeEvent *)event; /* Prüfen ob die Widgetinstanz schon realisiert ist */ if ( !XtIsRealized((Widget)cw) ) return; if(xexpose->count) return; /* Fenster aktualisieren */ if(cw->histspectr.exposed) copypix(cw ); drawannot(cw); cw->histspectr.exposed++; if(cw->histspectr.expose_callback){ call_value.reason = XmCR_EXPOSE; call_value.event = event; call_value.fd = -1; call_value.width = cw->histspectr.width; call_value.height = cw->histspectr.height; /* Aufrufen der Callbackliste für den Exposeevent */ XtCallCallbackList((Widget)cw,cw->histspectr.expose_callback,&call_value); } } /* ======================================================================= */ /*************************************************************************** *************************************************************************** * * Functionname: Resize * * * Prototype: static void Resize ( Widget w ); * * Input: Widget w * * Output: * * Return: * * Documentation: This is a method, called by X whenever the size * of widget was changed. it recreates the pixmaps for * the new size. * * * History: Sun Jan 18 08:51:44 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void Resize ( Widget w ){ XwHistspectrWidget cw = (XwHistspectrWidget) w; Dimension width,height; XwHistspectrCallbackStruct call_value; XFreePixmap(XtDisplay(cw), cw->histspectr.pix); if(cw->histspectr.panno) XFreePixmap(XtDisplay(cw),cw->histspectr.panno); /* for safety, cannot be smaller */ if(cw->core.width < minsize) cw->core.width = minsize; if(cw->core.height < minsize) cw->core.height = minsize; cw->histspectr.panno = (Pixmap)NULL; /* preclear */ get_proportion( cw ); /* recalculate sizes and starting */ cw->histspectr.pix =XCreatePixmap(XtDisplay(cw), RootWindow(XtDisplay(cw), DefaultScreen(XtDisplay(cw))), cw->histspectr.pixwidth, cw->histspectr.pixheight, cw->core.depth); /* pixmap for external annotation */ if(cw->histspectr.anflag ){ height = cw->histspectr.pixheight; width = cw->histspectr.annsiz; if(width > 0 && height > 0) cw->histspectr.panno = XCreatePixmap(XtDisplay(cw), RootWindow(XtDisplay(cw), DefaultScreen(XtDisplay(cw))), width, height,cw->core.depth); } clear_histspectr(cw ); cw->histspectr.Xpos =cw->histspectr.width; cw->histspectr.oldy = cw->histspectr.height; cw->histspectr.foldx = cw->histspectr.pixwidth - cw->histspectr.width; scale(cw); drawgrid(cw ); cw->histspectr.gr[0] = cw->histspectr.prevgrid; if(cw->histspectr.resize_callback){ call_value.reason =XmCR_RESIZE ; call_value.event =NULL; call_value.fd = -1; call_value.width = cw->histspectr.width; call_value.height = cw->histspectr.height; /* Aufrufen der Callbackliste für den Exposeevent */ XtCallCallbackList((Widget)cw,cw->histspectr.resize_callback,&call_value); } } /*************************************************************************** *************************************************************************** * * Functionname: Destroy * * Input: Widget w * * Return: * * Documentation: Method, called when the widget is destroyed * (not called during termination and quitting * must clearly free all allocated storage * * History: Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void Destroy(Widget w ){ XwHistspectrWidget cw = (XwHistspectrWidget) w; int i=0; unsigned long colorpix[4]; XFreeGC(XtDisplay( cw), cw->histspectr.gc); XFreeGC(XtDisplay( cw), cw->histspectr.anngc); if(cw->histspectr.background) colorpix[i++] = cw->histspectr.background; if(cw->histspectr.anncolor) colorpix[i++] = cw->histspectr.anncolor; if(cw->histspectr.fillcolor) colorpix[i++] = cw->histspectr.fillcolor; if(cw->histspectr.linecolor) colorpix[i++] = cw->histspectr.linecolor; if(i) XFreeColors(XtDisplay(cw), DefaultColormap(XtDisplay(cw) ,DefaultScreen(XtDisplay(cw))),colorpix,i,0); /* XmFontListFree(cw->histspectr.font_list); */ XFreePixmap(XtDisplay(cw), cw->histspectr.pix); if(cw->histspectr.panno) XFreePixmap(XtDisplay(cw), cw->histspectr.panno); if(cw->histspectr.curve) XtFree((char *)cw->histspectr.curve); XtFree((char *)cw->histspectr.vis); XtFree((char *)cw->histspectr.gr); cw->histspectr.pix = 0; cw->histspectr.panno = 0; cw->histspectr.gc = NULL; cw->histspectr.anngc = NULL; /* cw->histspectr.font_list = NULL; */ } /*************************************************************************** *************************************************************************** * * Functionname: clear_histspectr * * * Prototype: static void clear_histspectr(XwHistspectrWidget cw ); * * Input: XwHistspectrWidget cw , int notall * * Output: * * Return: * * Documentation: actual clearing the total pixmap * to background colour, should be followed by recreating grid * (and scale) * * * History: Sun Jan 18 08:52:05 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void clear_histspectr(XwHistspectrWidget cw ){ XSetForeground(XtDisplay(cw),cw->histspectr.gc,cw->histspectr.background); XFillRectangle(XtDisplay(cw),cw->histspectr.pix,cw->histspectr.gc, 0,0,cw->histspectr.pixwidth,cw->histspectr.pixheight); if(cw->histspectr.panno){ XSetForeground(XtDisplay(cw),cw->histspectr.anngc,cw->core.background_pixel); XFillRectangle(XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc, 0,0,cw->histspectr.annsiz,cw->histspectr.pixheight); XSetForeground(XtDisplay(cw),cw->histspectr.anngc,cw->histspectr.anncolor); } } /*************************************************************************** *************************************************************************** * * Functionname: scale * * * Prototype: static void scale(XwHistspectrWidget cw); * * Input: XwHistspectrWidget cw * * Output: * * Return: * * Documentation: does all scaling,construct parameters to calculate from users values * into pixmap. * * given vis[6] vis[0] xoffset starting value of time * vis[1] displayable x-range * vis[2] lowest y value * vis[3] range of y * vis[4] min value of x-axis * vis[5] range of x-axis * History: Tue Dec 16 13:21:24 CET 2003 * * *************************************************************************** ***************************************************************************/ static void scale(XwHistspectrWidget cw){ double width,height; /* assumed, that pixel coords begin with 0 */ /* basically we use a square as diaplay area, so the height will be used */ width = (cw->histspectr.height / 2.0) / sin(cw->histspectr.angle); height = cw->histspectr.height /2.0 ; cw->histspectr.sc.bt = width / cw->histspectr.vis[1] ; cw->histspectr.sc.by = height / cw->histspectr.vis[3] ; cw->histspectr.sc.ay = - cw->histspectr.sc.by * cw->histspectr.vis[2]; cw->histspectr.sc.bx = width / cw->histspectr.vis[5] ; cw->histspectr.sc.ax = cw->histspectr.sc.bx * cw->histspectr.vis[4]; } /*************************************************************************** *************************************************************************** * * Functionname: drawannot * * * Prototype: static void drawannot(XwHistspectrWidget cw); * * Input: XwHistspectrWidget cw * * Output: * * Return: * * Documentation: draws the ordinate annotation(if needed) to window * * * History: Mon Jan 5 10:15:22 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void drawannot(XwHistspectrWidget cw){ int ypix , cnt = cw->histspectr.ynthgridanno+1; int len,cheight = (cw->histspectr.font_struct->ascent - cw->histspectr.font_struct->descent); int cnt1 = cw->histspectr.xnthgridanno+1; int pos=0 ; float base = cw->histspectr.gr[2] ; char annot[40]; if(!cw->histspectr.anflag) return; XSetForeground(XtDisplay(cw),cw->histspectr.anngc ,cw->histspectr.anncolor); while((ypix= cw->histspectr.height - (cw->histspectr.sc.ay + cw->histspectr.sc.by * base)) >= cw->histspectr.height/2 ) { /* ordinate annot */ /* ypix = cw->histspectr.height - (cw->histspectr.sc.ay + cw->histspectr.sc.by * base); */ if(ypix <= (cw->histspectr.height - cheight/2) ){ if(!--cnt ){ cnt = cw->histspectr.ynthgridanno+1; sprintf(annot,"%.*f",cw->histspectr.yndecimals,base); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) ; pos = cw->histspectr.xv - len -8 ; XDrawString (XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc ,pos , ypix+cheight/2 ,annot,strlen(annot)); } } XDrawLine(XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc , cw->histspectr.xv , ypix,cw->histspectr.xv -8 ,ypix); base += cw->histspectr.gr[3]; } /* do annotation of X-axis */ base = cw->histspectr.gr[4]; while((pos = cw->histspectr.xv + cw->histspectr.sc.ax + cw->histspectr.sc.bx *base) < (cw->histspectr.width )){ if(pos < 0) break; XDrawLine(XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc , pos , cw->histspectr.height,pos ,cw->histspectr.height+ cheight); if(!--cnt1 ){ cnt1 = cw->histspectr.xnthgridanno+1; sprintf(annot,"%.*f",cw->histspectr.xndecimals,base); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) ; XDrawString (XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc ,pos-len/2 , cw->histspectr.height + 2*cheight ,annot,strlen(annot)); } base += cw->histspectr.gr[5]; } if(!cw->histspectr.dofixtext) return; /* now add the fixtext per bar */ ypix = (cw->histspectr.height + 2 ) +( 3 * cheight ); if(cw->histspectr.fixtext){ XSetForeground(XtDisplay(cw),cw->histspectr.anngc ,cw->histspectr.anncolor); pos = cw->histspectr.xv /* + cw->histspectr.Xpos - cw->histspectr.width */; XDrawString (XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc ,pos , ypix ,cw->histspectr.fixtext ,strlen(cw->histspectr.fixtext)); } } /*************************************************************************** *************************************************************************** * * Functionname: drawgrid * * * Prototype: static void drawgrid(XwHistspectrWidget cw ); * * Input: XwHistspectrWidget cw , int doit * * Output: * * Return: * * Documentation: * Draws the grid into pixmap and draws the time * annotation into annotation pixmap * * * History: Mon Jan 5 11:19:36 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void drawgrid(XwHistspectrWidget cw){ int ypix , cnt = cw->histspectr.lastanncnt , len; float base = cw->histspectr.gr[0] ; char annot[40]; int cheight = (cw->histspectr.font_struct->ascent - cw->histspectr.font_struct->descent); if(!cw->histspectr.panno) return; /* grid forground colour is fixed set to cw->primitive.foreground */ XSetForeground(XtDisplay(cw),cw->histspectr.anngc,cw->core.background_pixel); XFillRectangle(XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc, 0,0,cw->histspectr.annsiz,cw->histspectr.pixheight); XSetForeground(XtDisplay(cw),cw->histspectr.anngc,cw->histspectr.anncolor); /* do y- rastering */ cw->histspectr.prevgrid = cw->histspectr.gr[0]; /* save for repeat gridding */ while((ypix= cw->histspectr.height + (base - cw->histspectr.sc.at ) * cw->histspectr.sc.bt * sin(cw->histspectr.angle)) >= 0) { /* time grid first up*/ if(ypix+cheight/2 <= cw->histspectr.height ){ if(!--cnt ){ cnt = cw->histspectr.tnthgridanno+1; sprintf(annot,"%.*f",cw->histspectr.tndecimals,base); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) ; XDrawString (XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc ,cw->histspectr.annsiz - len , ypix+cheight/2 ,annot,strlen(annot)); } } XDrawLine(XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc ,0,ypix,8,ypix); base -= cw->histspectr.gr[1]; } base = cw->histspectr.gr[0] ; while((ypix = cw->histspectr.height + (base - cw->histspectr.sc.at ) * cw->histspectr.sc.bt * sin(cw->histspectr.angle)) <= (cw->histspectr.pixheight - cheight/2)) { /* time grid second down*/ if( ypix >= 0){ if(!--cnt ){ cnt = cw->histspectr.tnthgridanno+1; sprintf(annot,"%.*f",cw->histspectr.tndecimals,base); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot)) ; XDrawString (XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc ,cw->histspectr.annsiz - len , ypix+cheight/2 ,annot,strlen(annot)); } } XDrawLine(XtDisplay(cw),cw->histspectr.panno,cw->histspectr.anngc ,0,ypix,8,ypix); base += cw->histspectr.gr[1]; } cw->histspectr.lastanncnt = cnt; } /*************************************************************************** *************************************************************************** * * Functionname: copyannot * * Input: XwHistspectrWidget cw , Drawable target,double yoffset * * Return: * * Documentation: if external annotation set, copies the annotation pixmap * in place for annotation, wher given might be x or y coordinate * corresponding to direction * * * History: Wed Mar 12 17:45:42 CET 1997 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void copyannot(XwHistspectrWidget cw , Drawable target , double yoffset){ if(!cw->histspectr.panno) return; /* no copy needed */ XCopyArea(XtDisplay(cw),cw->histspectr.panno,target, cw->histspectr.anngc, 0 ,(int)yoffset , cw->histspectr.annsiz, cw->histspectr.height ,cw->histspectr.xv+cw->histspectr.width,0); } /*************************************************************************** *************************************************************************** * * Functionname: copypix * * Input: XwHistspectrWidget cw * * Return: * * Documentation: copies the actual pixmapwindow into visible * if external annotation set, copies the annotation pixmap * in place for annotation. * * History: Sat Jan 3 09:26:31 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void copypix(XwHistspectrWidget cw ){ double lsttim = 0; if(cw->histspectr.foldy > 0 || cw->histspectr.foldx < cw->histspectr.pixwidth - cw->histspectr.width){ if(cw->histspectr.foldy > cw->histspectr.Yoffset) cw->histspectr.Yoffset = cw->histspectr.foldy; if(cw->histspectr.foldx < cw->histspectr.Xoffset) cw->histspectr.Xoffset = cw->histspectr.foldx; if(lsttim < cw->histspectr.lasttim) lsttim = cw->histspectr.lasttim; } XCopyArea(XtDisplay(cw),cw->histspectr.pix,XtWindow(cw), cw->histspectr.gc, (int)cw->histspectr.Xoffset , (int)cw->histspectr.Yoffset , cw->histspectr.width, cw->histspectr.height,cw->histspectr.xv,0); copyannot(cw ,XtWindow(cw),cw->histspectr.Yoffset ); dancevals(cw); if(cw->histspectr.Xoffset <= 10 || cw->histspectr.Yoffset >= (cw->histspectr.pixheight -cw->histspectr.height -10)){ /* now refresh pixmap */ XCopyArea(XtDisplay(cw),cw->histspectr.pix,cw->histspectr.pix , cw->histspectr.gc, (int)cw->histspectr.Xoffset , (int)cw->histspectr.Yoffset ,cw->histspectr.width, cw->histspectr.height ,cw->histspectr.pixwidth - cw->histspectr.width,0); cw->histspectr.Xoffset = cw->histspectr.pixwidth - cw->histspectr.width; cw->histspectr.Yoffset = 0;/* cw->histspectr.height; */ cw->histspectr.oldx = cw->histspectr.pixwidth - cw->histspectr.width; cw->histspectr.oldy = cw->histspectr.foldy = 0 ; cw->histspectr.foldx = cw->histspectr.oldx ; XSetForeground(XtDisplay(cw),cw->histspectr.gc,cw->histspectr.background); XFillRectangle(XtDisplay(cw),cw->histspectr.pix , cw->histspectr.gc, 0,0, cw->histspectr.pixwidth - cw->histspectr.width , cw->histspectr.pixheight); XFillRectangle(XtDisplay(cw),cw->histspectr.pix , cw->histspectr.gc, cw->histspectr.pixwidth - cw->histspectr.width , cw->histspectr.height ,cw->histspectr.width, cw->histspectr.pixheight - cw->histspectr.height); cw->histspectr.sc.at = lsttim; drawgrid(cw); } } /*************************************************************************** *************************************************************************** * * Functionname: drawspectr * * Input: XwHistspectrWidget cw * long int id id of actual bar * float val , float time values of bar * * Output: * * Return: * * Documentation: draws a bar into pixmap, saving the actual values for next * draw. The deepness of bar is calculated from previous time * * On host: wizant by: WizAnt Software * History: Sat Jan 3 09:26:15 CET 1998 * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ static void drawspectr (XwHistspectrWidget cw, w3dPoint *val , float time , int npoints){ /* XPoint curve[540]; */ int i ; char annot[20]; int cheight = (cw->histspectr.font_struct->ascent - cw->histspectr.font_struct->descent); cw->histspectr.mark = 0; if(time < cw->histspectr.lasttim) return; /* x-axis must increase */ if(!cw->histspectr.curve){ cw->histspectr.curve = (XPoint *)XtMalloc(sizeof(XPoint)*(npoints+2)); if(!cw->histspectr.curve ){ XtWarning("WHistspectr drawspectr cannot XtMalloc"); return; } cw->histspectr.curvepoint = npoints+2; } if(cw->histspectr.curvepoint < npoints+2 ){ XtFree((char *)cw->histspectr.curve); cw->histspectr.curve = (XPoint *)XtMalloc(sizeof(XPoint)*(npoints+2)); if(!cw->histspectr.curve ){ XtWarning("WHistspectr drawspectr cannot XtMalloc"); return; } } if((time - cw->histspectr.lasttim ) > (cw->histspectr.vis[0] + cw->histspectr.vis[1])){ fprintf(stderr," time is out of scale: prevtime / time %f %f %f\n" ,cw->histspectr.lasttim,time , cw->histspectr.vis[1]); /* ignoring is not the best, think about something intelligent */ } cw->histspectr.foldx = (cw->histspectr.pixwidth - cw->histspectr.width) - (time - cw->histspectr.sc.at ) * cw->histspectr.sc.bt * cos(cw->histspectr.angle); cw->histspectr.foldy = (time - cw->histspectr.sc.at ) * cw->histspectr.sc.bt * sin(cw->histspectr.angle); if(cw->histspectr.foldx > cw->histspectr.pixwidth || cw->histspectr.foldx < 0 || cw->histspectr.height +cw->histspectr.foldy < 0 || cw->histspectr.height +cw->histspectr.foldy > cw->histspectr.pixheight){ } cw->histspectr.oldx = cw->histspectr.foldx; cw->histspectr.oldy = cw->histspectr.foldy; for(i=1;i <= npoints;i++){ cw->histspectr.curve[i].y = cw->histspectr.height +cw->histspectr.foldy- (cw->histspectr.sc.ay + cw->histspectr.sc.by * val[i-1].y); cw->histspectr.curve[i].x = cw->histspectr.Xpos + cw->histspectr.foldx - cw->histspectr.width +(cw->histspectr.sc.ax + cw->histspectr.sc.bx *val[i-1].x) ; if(cw->histspectr.marker && i > 1 && val[i-2].x <= cw->histspectr.marker && val[i].x >= cw->histspectr.marker) cw->histspectr.mark = i; } cw->histspectr.curve[npoints+1].y = cw->histspectr.curve[0].y = cw->histspectr.height +cw->histspectr.foldy; cw->histspectr.curve[0].x = cw->histspectr.curve[1].x; cw->histspectr.curve[npoints+1].x = cw->histspectr.curve[i-1].x; XSetForeground(XtDisplay(cw), cw->histspectr.gc,cw->histspectr.fillcolor); XFillPolygon(XtDisplay(cw),cw->histspectr.pix , cw->histspectr.gc, cw->histspectr.curve , npoints+2, Nonconvex, CoordModeOrigin); XSetForeground(XtDisplay(cw), cw->histspectr.gc,cw->histspectr.linecolor); /* Lines or Points the Question */ if(cw->histspectr.lines) XDrawLines(XtDisplay(cw), cw->histspectr.pix, cw->histspectr.gc , &cw->histspectr.curve[1],npoints,CoordModeOrigin); else XDrawPoints(XtDisplay(cw), cw->histspectr.pix, cw->histspectr.gc , &cw->histspectr.curve[1],npoints,CoordModeOrigin); cw->histspectr.lasttim = time; if(cw->histspectr.mark ) /* draw a marker line at given x-pos */ XDrawLine (XtDisplay(cw), cw->histspectr.pix, cw->histspectr.anngc , cw->histspectr.curve[cw->histspectr.mark].x , cw->histspectr.height+cw->histspectr.Yoffset-cheight , cw->histspectr.curve[cw->histspectr.mark].x , cw->histspectr.curve[cw->histspectr.mark].y-10); } /*************************************************************************** *************************************************************************** * * Functionname: dancevals * * Input: XwHistspectrWidget cw * * Return: * * Documentation: plots marker x-value above copied pixmap * * * History: Mon Dec 15 14:20:46 CET 2003 * * *************************************************************************** ***************************************************************************/ static void dancevals(XwHistspectrWidget cw ){ int i , xpix,ypix ; int len , pos; char annot[20]; if(cw->histspectr.mark ){ sprintf(annot,"%.*f",cw->histspectr.xndecimals,cw->histspectr.marker); len = XTextWidth(cw->histspectr.font_struct,annot,strlen(annot))/2 ; pos = cw->histspectr.curve[cw->histspectr.mark].x - cw->histspectr.Xoffset+cw->histspectr.xv-len; if(pos < cw->histspectr.xv) /* avoid plotting outside */ pos = cw->histspectr.xv; XDrawString (XtDisplay(cw), XtWindow(cw),cw->histspectr.anngc ,pos,cw->histspectr.height-3 ,annot,strlen(annot)); } } /* ================================================================================ */ /* Public directly accessible Functions */ /* ================================================================================ */ /*************************************************************************** *************************************************************************** * * Functionname: XwCreateHistspectr * * Input: Widget parent, * char *name, * ArgList arglist, * Cardinal argcount * * Return: Widget * * Documentation: Standeard X- creating routine * * * History: Sun Jan 18 08:55:04 CET 1998 on host:wizant * Tue Dec 16 13:27:10 CET 2003 * * *************************************************************************** ***************************************************************************/ Widget XwCreateHistspectr( Widget parent, char *name, ArgList arglist , Cardinal argcount) { return( (Widget) XtCreateWidget(name, XwHistspectrWidgetClass, parent, arglist, argcount)); } /*************************************************************************** *************************************************************************** * * Functionname: XwHistspectrSettext * * Input: Widget w * char *text set text to display (empty or NULL to rest) * * Return: * * Documentation: sets the per bar text display. * CAUTION: There is no limit check for number of characters * so check if the text fits with fontsize into one line * * * History: Sun Jan 25 08:05:44 CET 1998 * Tue Dec 16 13:27:10 CET 2003 *************************************************************************** ***************************************************************************/ void XwHistspectrSettext(Widget w, char *text){ XwHistspectrWidget cw = (XwHistspectrWidget) w; if(!XwIsHistspectr(w)){ XtWarning("BAD widget id in XwHistspectrSettext"); return; } if(cw->histspectr.fixtext) free(cw->histspectr.fixtext); if(!text || !strlen(text) ){ cw->histspectr.fixtext = NULL; cw->histspectr.dofixtext = FALSE; return; } cw->histspectr.fixtext = strdup(text); cw->histspectr.dofixtext = TRUE; if(cw->histspectr.dofixtext && cw->histspectr.exposed) drawannot(cw); } /*************************************************************************** *************************************************************************** * * Functionname: XwHistdoscan * * Input: Widget w target histspectring widget * * w3dPoint xy[] value pair (x , y ) * int npoints * float time t-axis value * Return: * * Documentation: adds a scan to the actual display * * * History: Sun Jan 18 08:56:47 CET 1998 on host: wizant * Tue Dec 16 13:27:10 CET 2003 * *************************************************************************** ***************************************************************************/ void XwHistdoscan (Widget w , w3dPoint xy[] ,int npoints , float time){ XwHistspectrWidget cw = (XwHistspectrWidget) w; float min = 900000000.0, max = -900000000.0 ; int i , rescale =0; if(!XwIsHistspectr(w)){ XtWarning("BAD widget id in XwHistdoscan"); return; } /* if autoscale is set do the scaling and gridding */ if(cw->histspectr.autoscale & AutoTime ){ /*autotiming */ if(!cw->histspectr.lasttim){ cw->histspectr.lasttim = time; return; /* delay it now for next sample */ } cw->histspectr.vis[1] = (time - cw->histspectr.lasttim)*100.0; cw->histspectr.gr[0] = cw->histspectr.lasttim; cw->histspectr.gr[1] = cw->histspectr.vis[1] / 5; rescale++; } if(cw->histspectr.autoscale & AutoAbs){ /* abscissa */ for(i=0;i xy[i].x) min = xy[i].x; if(max < xy[i].x) max = xy[i].x; } cw->histspectr.vis[4]=min; cw->histspectr.vis[5]= max-min; if(!cw->histspectr.vis[5]) return; /* unusable, scale later */ cw->histspectr.gr[4] = min; cw->histspectr.gr[5] = cw->histspectr.vis[5] / 5.0; rescale++; } if(cw->histspectr.autoscale & AutoAmpl){ /* Aplitude */ min = 900000000.0; max = -900000000.0; for(i=0;i xy[i].y) min = xy[i].y; if(max < xy[i].y) max = xy[i].y; } cw->histspectr.vis[3] = max-min; if(!cw->histspectr.vis[3]) return; /* unusable, scale later */ cw->histspectr.vis[2] = min - cw->histspectr.vis[3] *2 ; cw->histspectr.vis[3] *= 4.0; cw->histspectr.gr[2] = cw->histspectr.vis[2]; cw->histspectr.gr[3] = cw->histspectr.vis[3] / 5.0; rescale++; } if(rescale){ scale(cw); /* scale the widget */ drawgrid(cw ); XSetForeground(XtDisplay(cw),cw->histspectr.anngc ,cw->core.background_pixel); XFillRectangle(XtDisplay(cw),XtWindow(cw),cw->histspectr.anngc, 0,0,cw->core.width,cw->core.height); drawannot(cw ); cw->histspectr.autoscale &= ~(AutoAbs|AutoAmpl|AutoTime); } /* first check if pixmap overrun will occur, than refresh pixmap */ drawspectr (cw, xy , time , npoints); cw->histspectr.lasttim = time; copypix(cw ); } /*************************************************************************** *************************************************************************** * * Functionname: XwHistspectrSetMarker * * Input: Widget w target histspectring widget * * float x abscissa value to mark monitoring * Return: * * Documentation: adds a scan to the actual display * * * History: Tue Dec 16 13:27:10 CET 2003 * * *************************************************************************** ***************************************************************************/ void XwHistspectrSetMarker (Widget w ,float x){ if(!XwIsHistspectr(w)){ XtWarning("BAD widget id in XwHistspectrSetMarker"); return; } ((XwHistspectrWidget) w)->histspectr.marker = x; } #ifdef __cplusplus } #endif