diff options
author | joye <joye> | 2014-03-26 19:38:01 (GMT) |
---|---|---|
committer | joye <joye> | 2014-03-26 19:38:01 (GMT) |
commit | a78a78c2c45694657e8aa2fa78cbae1b6c78e808 (patch) | |
tree | 6c96d0777d027b75fa2d52bbf78de41744806b40 | |
parent | 89a6725b0b1fd8edef4978bd2203dc86ddb6ebdc (diff) | |
download | blt-a78a78c2c45694657e8aa2fa78cbae1b6c78e808.zip blt-a78a78c2c45694657e8aa2fa78cbae1b6c78e808.tar.gz blt-a78a78c2c45694657e8aa2fa78cbae1b6c78e808.tar.bz2 |
*** empty log message ***
-rw-r--r-- | src/bltGrElemBar.C | 96 | ||||
-rw-r--r-- | src/bltGrElemLine.C | 2 | ||||
-rw-r--r-- | src/bltGrElemOp.C | 378 | ||||
-rw-r--r-- | src/bltGrElemOp.h | 8 | ||||
-rw-r--r-- | tests/all.tcl | 15 | ||||
-rw-r--r-- | tests/axis.tcl | 2 | ||||
-rw-r--r-- | tests/bargraph.tcl | 2 | ||||
-rw-r--r-- | tests/bitmapmarker.tcl | 2 | ||||
-rw-r--r-- | tests/crosshairs.tcl | 2 | ||||
-rw-r--r-- | tests/legend.tcl | 4 | ||||
-rw-r--r-- | tests/linegraph.tcl | 2 | ||||
-rw-r--r-- | tests/linemarker.tcl | 2 | ||||
-rw-r--r-- | tests/marker.tcl | 2 | ||||
-rw-r--r-- | tests/polygonmarker.tcl | 2 | ||||
-rw-r--r-- | tests/textmarker.tcl | 2 |
15 files changed, 253 insertions, 268 deletions
diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index 7487450..302242e 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -185,9 +185,8 @@ static ElementProcs barProcs = { static Tk_ObjCustomOption styleObjOption = { - "style", StyleSetProc, StyleGetProc, NULL, NULL, + "style", StyleSetProc, StyleGetProc, StyleRestoreProc, StyleFreeProc, (ClientData)sizeof(BarStyle) - }; extern Tk_ObjCustomOption barPenObjOption; @@ -429,9 +428,8 @@ static int ConfigureBarProc(Graph* graphPtr, Element *basePtr) Blt_ChainLink link; BarStyle *stylePtr; - if (ConfigurePenProc(graphPtr, (Pen*)&elemPtr->builtinPen)!= TCL_OK) { + if (ConfigurePenProc(graphPtr, (Pen*)&elemPtr->builtinPen)!= TCL_OK) return TCL_ERROR; - } // Point to the static normal pen if no external pens have been selected. link = Blt_Chain_FirstLink(elemPtr->stylePalette); @@ -505,12 +503,11 @@ static int ConfigurePenProc(Graph* graphPtr, Pen *basePtr) static void ResetStylePalette(Blt_Chain stylePalette) { - Blt_ChainLink link; - - for (link = Blt_Chain_FirstLink(stylePalette); link; + for (Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); link; link = Blt_Chain_NextLink(link)) { BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); - stylePtr->xeb.length = stylePtr->yeb.length = 0; + stylePtr->xeb.length = 0; + stylePtr->yeb.length = 0; stylePtr->nBars = 0; } } @@ -744,12 +741,8 @@ static void ClosestBarProc(Graph* graphPtr, Element *basePtr) static void MergePens(BarElement* elemPtr, BarStyle **dataToStyle) { if (Blt_Chain_GetLength(elemPtr->stylePalette) < 2) { - Blt_ChainLink link; - BarStyle *stylePtr; - - link = Blt_Chain_FirstLink(elemPtr->stylePalette); - - stylePtr = (BarStyle*)Blt_Chain_GetValue(link); + Blt_ChainLink link = Blt_Chain_FirstLink(elemPtr->stylePalette); + BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); stylePtr->nBars = elemPtr->nBars; stylePtr->bars = elemPtr->bars; stylePtr->symbolSize = elemPtr->bars->width / 2; @@ -759,9 +752,9 @@ static void MergePens(BarElement* elemPtr, BarStyle **dataToStyle) stylePtr->yeb.segments = elemPtr->yeb.segments; return; } - /* We have more than one style. Group bar segments of like pen styles - * together. */ + // We have more than one style. Group bar segments of like pen styles + // together if (elemPtr->nBars > 0) { Blt_ChainLink link; XRectangle *bars, *bp; @@ -899,8 +892,8 @@ static void MapActiveBars(BarElement* elemPtr) static void ResetBar(BarElement* elemPtr) { - /* Release any storage associated with the display of the bar */ ResetStylePalette(elemPtr->stylePalette); + if (elemPtr->activeRects) free(elemPtr->activeRects); @@ -1284,20 +1277,18 @@ static void MapBarProc(Graph* graphPtr, Element *basePtr) if (count > 0) { size = bars->width; } - { - Blt_ChainLink link; - /* Set the symbol size of all the pen styles. */ - for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; - link = Blt_Chain_NextLink(link)) { - BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); - stylePtr->symbolSize = size; - stylePtr->errorBarCapWidth = - (stylePtr->penPtr->errorBarCapWidth > 0) - ? stylePtr->penPtr->errorBarCapWidth : (size * 66666) / 100000; - stylePtr->errorBarCapWidth /= 2; - } + // Set the symbol size of all the pen styles + for (Blt_ChainLink link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; + link = Blt_Chain_NextLink(link)) { + BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); + stylePtr->symbolSize = size; + stylePtr->errorBarCapWidth = + (stylePtr->penPtr->errorBarCapWidth > 0) + ? stylePtr->penPtr->errorBarCapWidth : (size * 66666) / 100000; + stylePtr->errorBarCapWidth /= 2; } + dataToStyle = (BarStyle**)Blt_StyleMap((Element *)elemPtr); if (((elemPtr->yHigh && elemPtr->yHigh->nValues > 0) && (elemPtr->yLow && elemPtr->yLow->nValues > 0)) || @@ -1307,6 +1298,7 @@ static void MapBarProc(Graph* graphPtr, Element *basePtr) (elemPtr->yError && elemPtr->yError->nValues > 0)) { MapErrorBars(graphPtr, elemPtr, dataToStyle); } + MergePens(elemPtr, dataToStyle); free(dataToStyle); } @@ -1488,32 +1480,30 @@ static void DrawNormalBarProc(Graph* graphPtr, Drawable drawable, Element *basePtr) { BarElement* elemPtr = (BarElement *)basePtr; - int count; - Blt_ChainLink link; - count = 0; - for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; + int count = 0; + for (Blt_ChainLink link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; link = Blt_Chain_NextLink(link)) { BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); BarPen* penPtr = (BarPen*)stylePtr->penPtr; - if (stylePtr->nBars > 0) { + if (stylePtr->nBars > 0) DrawBarSegments(graphPtr, drawable, penPtr, stylePtr->bars, stylePtr->nBars); - } - if ((stylePtr->xeb.length > 0) && (penPtr->errorBarShow & SHOW_X)) { + + if ((stylePtr->xeb.length > 0) && (penPtr->errorBarShow & SHOW_X)) Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC, stylePtr->xeb.segments, stylePtr->xeb.length); - } - if ((stylePtr->yeb.length > 0) && (penPtr->errorBarShow & SHOW_Y)) { + + if ((stylePtr->yeb.length > 0) && (penPtr->errorBarShow & SHOW_Y)) Blt_Draw2DSegments(graphPtr->display, drawable, penPtr->errorBarGC, stylePtr->yeb.segments, stylePtr->yeb.length); - } - if (penPtr->valueShow != SHOW_NONE) { + + if (penPtr->valueShow != SHOW_NONE) DrawBarValues(graphPtr, drawable, elemPtr, penPtr, stylePtr->bars, stylePtr->nBars, elemPtr->barToData + count); - } + count += stylePtr->nBars; } } @@ -1537,7 +1527,8 @@ static void DrawActiveBarProc(Graph* graphPtr, Drawable drawable, elemPtr->activeRects, elemPtr->nActive, elemPtr->activeToData); } - } else if (elemPtr->nActiveIndices < 0) { + } + else if (elemPtr->nActiveIndices < 0) { DrawBarSegments(graphPtr, drawable, penPtr, elemPtr->bars, elemPtr->nBars); if (penPtr->valueShow != SHOW_NONE) { @@ -1704,21 +1695,18 @@ static void NormalBarToPostScriptProc(Graph* graphPtr, Blt_Ps ps, Element *basePtr) { BarElement* elemPtr = (BarElement *)basePtr; - Blt_ChainLink link; - int count; - - count = 0; - for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; + + int count = 0; + for (Blt_ChainLink link = Blt_Chain_FirstLink(elemPtr->stylePalette); link; link = Blt_Chain_NextLink(link)) { - XColor* colorPtr; BarStyle *stylePtr = (BarStyle*)Blt_Chain_GetValue(link); BarPen* penPtr = (BarPen*)stylePtr->penPtr; - if (stylePtr->nBars > 0) { + if (stylePtr->nBars > 0) SegmentsToPostScript(graphPtr, ps, penPtr, stylePtr->bars, stylePtr->nBars); - } - colorPtr = penPtr->errorBarColor; + + XColor* colorPtr = penPtr->errorBarColor; if (!colorPtr) colorPtr = penPtr->outlineColor; @@ -1728,17 +1716,19 @@ static void NormalBarToPostScriptProc(Graph* graphPtr, Blt_Ps ps, Blt_Ps_Draw2DSegments(ps, stylePtr->xeb.segments, stylePtr->xeb.length); } + if ((stylePtr->yeb.length > 0) && (penPtr->errorBarShow & SHOW_Y)) { Blt_Ps_XSetLineAttributes(ps, colorPtr, penPtr->errorBarLineWidth, NULL, CapButt, JoinMiter); Blt_Ps_Draw2DSegments(ps, stylePtr->yeb.segments, stylePtr->yeb.length); } - if (penPtr->valueShow != SHOW_NONE) { + + if (penPtr->valueShow != SHOW_NONE) BarValuesToPostScript(graphPtr, ps, elemPtr, penPtr, stylePtr->bars, stylePtr->nBars, elemPtr->barToData + count); - } + count += stylePtr->nBars; } } diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index 94838b0..ac06d6c 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -273,7 +273,7 @@ static const char* penDirObjOption[] = static Tk_ObjCustomOption styleObjOption = { - "styles", StyleSetProc, StyleGetProc, NULL, NULL, + "styles", StyleSetProc, StyleGetProc, StyleRestoreProc, StyleFreeProc, (ClientData)sizeof(LineStyle) }; diff --git a/src/bltGrElemOp.C b/src/bltGrElemOp.C index b1d2155..118d95b 100644 --- a/src/bltGrElemOp.C +++ b/src/bltGrElemOp.C @@ -44,6 +44,7 @@ extern "C" { // Defs +static Tcl_Obj *DisplayListObj(Graph* graphPtr); static void DestroyElement(Element* elemPtr); static int ElementObjConfigure(Tcl_Interp* interp, Graph* graphPtr, Element* elemPtr, @@ -275,19 +276,19 @@ int StyleSetProc(ClientData clientData, Tcl_Interp* interp, Element* elemPtr = (Element*)(widgRec); size_t size = (size_t)clientData; - Tcl_Obj** objv; int objc; + Tcl_Obj** objv; if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK) return TCL_ERROR; - /* Reserve the first entry for the "normal" pen. We'll set the - * style later */ + // Reserve the first entry for the "normal" pen. We'll set the style later Blt_FreeStylePalette(stylePalette); Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); - if (link == NULL) { + if (!link) { link = Blt_Chain_AllocLink(size); Blt_Chain_LinkAfter(stylePalette, link, NULL); } + PenStyle* stylePtr = (PenStyle*)Blt_Chain_GetValue(link); stylePtr->penPtr = NORMALPEN(elemPtr); for (int ii = 0; ii<objc; ii++) { @@ -298,10 +299,11 @@ int StyleSetProc(ClientData clientData, Tcl_Interp* interp, stylePtr->weight.range = 1.0; if (GetPenStyleFromObj(interp, elemPtr->obj.graphPtr, objv[ii], elemPtr->obj.classId, - (PenStyle *)stylePtr) != TCL_OK) { + (PenStyle*)stylePtr) != TCL_OK) { Blt_FreeStylePalette(stylePalette); return TCL_ERROR; } + Blt_Chain_LinkAfter(stylePalette, link, NULL); } @@ -335,6 +337,17 @@ Tcl_Obj* StyleGetProc(ClientData clientData, Tk_Window tkwin, return listObjPtr; } +void StyleRestoreProc(ClientData clientData, Tk_Window tkwin, + char *ptr, char *savePtr) +{ + // do nothing +} + +void StyleFreeProc(ClientData clientData, Tk_Window tkwin, char *ptr) +{ + // do nothing +} + // Create static int CreateElement(Graph* graphPtr, Tcl_Interp* interp, int objc, @@ -402,13 +415,8 @@ static void DestroyElement(Element* elemPtr) Blt_DeleteBindings(graphPtr->bindTable, elemPtr); Blt_Legend_RemoveElement(graphPtr, elemPtr); - if (elemPtr->link) { + if (elemPtr->link) Blt_Chain_DeleteLink(graphPtr->elements.displayList, elemPtr->link); - if (!(elemPtr->flags & DELETE_PENDING)) { - graphPtr->flags |= RESET_WORLD; - Blt_EventuallyRedrawGraph(graphPtr); - } - } if (elemPtr->hashPtr) Tcl_DeleteHashEntry(elemPtr->hashPtr); @@ -516,54 +524,48 @@ static int ElementObjConfigure(Tcl_Interp* interp, Graph* graphPtr, static int ActivateOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - Element* elemPtr; - int i; - int *indices; - int nIndices; - + // List all the currently active elements if (objc == 3) { - Tcl_HashEntry *hPtr; + Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); + Tcl_HashSearch iter; - Tcl_Obj *listObjPtr; - - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - /* List all the currently active elements */ - for (hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { - elemPtr = (Element*)Tcl_GetHashValue(hPtr); - if (elemPtr->flags & ACTIVE) { - Tcl_ListObjAppendElement(interp, listObjPtr, + for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { + Element* elemPtr = (Element*)Tcl_GetHashValue(hPtr); + if (elemPtr->flags & ACTIVE) + Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(elemPtr->obj.name, -1)); - } } + Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } - if (Blt_GetElement(interp, graphPtr, objv[3], &elemPtr) != TCL_OK) { - return TCL_ERROR; /* Can't find named element */ - } - elemPtr->flags |= ACTIVE | ACTIVE_PENDING; - indices = NULL; - nIndices = -1; - if (objc > 4) { - int *activePtr; + Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, objv[3], &elemPtr) != TCL_OK) + return TCL_ERROR; + int* indices = NULL; + int nIndices = -1; + if (objc > 4) { nIndices = objc - 4; - activePtr = indices = (int*)malloc(sizeof(int) * nIndices); - for (i = 4; i < objc; i++) { - if (GetIndex(interp, elemPtr, objv[i], activePtr) != TCL_OK) { + indices = (int*)malloc(sizeof(int) * nIndices); + + int *activePtr = indices; + for (int ii=4; ii<objc; ii++) { + if (GetIndex(interp, elemPtr, objv[ii], activePtr) != TCL_OK) return TCL_ERROR; - } activePtr++; } } - if (elemPtr->activeIndices) { + + if (elemPtr->activeIndices) free(elemPtr->activeIndices); - } elemPtr->nActiveIndices = nIndices; elemPtr->activeIndices = indices; + + elemPtr->flags |= ACTIVE | ACTIVE_PENDING; Blt_EventuallyRedrawGraph(graphPtr); + return TCL_OK; } @@ -571,13 +573,10 @@ static int BindOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { if (objc == 3) { - Tcl_HashEntry *hPtr; - Tcl_HashSearch iter; - Tcl_Obj *listObjPtr; + Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - for (hPtr = Tcl_FirstHashEntry(&graphPtr->elements.tagTable, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { + Tcl_HashSearch iter; + for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->elements.tagTable, &iter); hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { char *tagName = (char*)Tcl_GetHashKey(&graphPtr->elements.tagTable, hPtr); Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(tagName, -1)); @@ -614,13 +613,15 @@ static int ClosestOp(Graph* graphPtr, Tcl_Interp* interp, searchPtr->dist = (double)(searchPtr->halo + 1); if (objc>5) { - Element* elemPtr; - if (Blt_GetElement(interp, graphPtr, objv[5], &elemPtr) != TCL_OK) - return TCL_ERROR; + for (int ii=5; ii<objc; ii++) { + Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, objv[ii], &elemPtr) != TCL_OK) + return TCL_ERROR; - if (elemPtr && !elemPtr->hide && - !(elemPtr->flags & (MAP_ITEM|DELETE_PENDING))) - (*elemPtr->procsPtr->closestProc) (graphPtr, elemPtr); + if (elemPtr && !elemPtr->hide && + !(elemPtr->flags & (MAP_ITEM|DELETE_PENDING))) + (*elemPtr->procsPtr->closestProc) (graphPtr, elemPtr); + } } else { // Find the closest point from the set of displayed elements, @@ -655,30 +656,33 @@ static int ClosestOp(Graph* graphPtr, Tcl_Interp* interp, return TCL_OK; } -static int DeactivateOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) +static int CreateOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[], ClassId classId) { - Element* elemPtr; - if (Blt_GetElement(interp, graphPtr, objv[3], &elemPtr) != TCL_OK) + if (CreateElement(graphPtr, interp, objc, objv, classId) != TCL_OK) return TCL_ERROR; - - elemPtr->flags &= ~(ACTIVE | ACTIVE_PENDING); - if (elemPtr->activeIndices) { - free(elemPtr->activeIndices); - elemPtr->activeIndices = NULL; - } - elemPtr->nActiveIndices = 0; - Blt_EventuallyRedrawGraph(graphPtr); + Tcl_SetObjResult(interp, objv[3]); return TCL_OK; } -static int CreateOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[], ClassId classId) +static int DeactivateOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) { - if (CreateElement(graphPtr, interp, objc, objv, classId) != TCL_OK) - return TCL_ERROR; - Tcl_SetObjResult(interp, objv[3]); + for (int ii=3; ii<objc; ii++) { + Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, objv[ii], &elemPtr) != TCL_OK) + return TCL_ERROR; + + if (elemPtr->activeIndices) { + free(elemPtr->activeIndices); + elemPtr->activeIndices = NULL; + } + elemPtr->nActiveIndices = 0; + elemPtr->flags &= ~(ACTIVE | ACTIVE_PENDING); + } + + Blt_EventuallyRedrawGraph(graphPtr); return TCL_OK; } @@ -686,19 +690,19 @@ static int CreateOp(Graph* graphPtr, Tcl_Interp* interp, static int DeleteOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - if (objc<4) - return TCL_ERROR; - - Element* elemPtr; - if (Blt_GetElement(interp, graphPtr, objv[3], &elemPtr) != TCL_OK) { - Tcl_AppendResult(interp, "can't find element \"", - Tcl_GetString(objv[3]), "\" in \"", - Tk_PathName(graphPtr->tkwin), "\"", NULL); + for (int ii=3; ii<objc; ii++) { + Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, objv[ii], &elemPtr) != TCL_OK) { + Tcl_AppendResult(interp, "can't find element \"", + Tcl_GetString(objv[ii]), "\" in \"", + Tk_PathName(graphPtr->tkwin), "\"", NULL); return TCL_ERROR; + } + elemPtr->flags |= DELETE_PENDING; + Tcl_EventuallyFree(elemPtr, FreeElement); } - elemPtr->flags |= DELETE_PENDING; - Tcl_EventuallyFree(elemPtr, FreeElement); + graphPtr->flags |= RESET_WORLD; Blt_EventuallyRedrawGraph(graphPtr); return TCL_OK; @@ -707,9 +711,8 @@ static int DeleteOp(Graph* graphPtr, Tcl_Interp* interp, static int ExistsOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - Tcl_HashEntry *hPtr; - - hPtr = Tcl_FindHashEntry(&graphPtr->elements.table, Tcl_GetString(objv[3])); + Tcl_HashEntry *hPtr = + Tcl_FindHashEntry(&graphPtr->elements.table, Tcl_GetString(objv[3])); Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (hPtr != NULL)); return TCL_OK; } @@ -717,9 +720,7 @@ static int ExistsOp(Graph* graphPtr, Tcl_Interp* interp, static int GetOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - char *string; - - string = Tcl_GetString(objv[3]); + char *string = Tcl_GetString(objv[3]); if ((string[0] == 'c') && (strcmp(string, "current") == 0)) { Element* elemPtr = (Element*)Blt_GetCurrentItem(graphPtr->bindTable); /* Report only on elements. */ @@ -732,90 +733,65 @@ static int GetOp(Graph* graphPtr, Tcl_Interp* interp, return TCL_OK; } -static Tcl_Obj *DisplayListObj(Graph* graphPtr) -{ - Tcl_Obj *listObjPtr; - Blt_ChainLink link; - - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - for (link = Blt_Chain_FirstLink(graphPtr->elements.displayList); - link != NULL; link = Blt_Chain_NextLink(link)) { - Element* elemPtr = (Element*)Blt_Chain_GetValue(link); - Tcl_Obj *objPtr = Tcl_NewStringObj(elemPtr->obj.name, -1); - Tcl_ListObjAppendElement(graphPtr->interp, listObjPtr, objPtr); - } - return listObjPtr; -} - static int LowerOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - Blt_Chain chain; - Blt_ChainLink link, next; - // Move the links of lowered elements out of the display list into // a temporary list - chain = Blt_Chain_Create(); + Blt_Chain chain = Blt_Chain_Create(); + for (int ii=3; ii<objc; ii++) { Element* elemPtr; - if (Blt_GetElement(interp, graphPtr, objv[ii], &elemPtr) != TCL_OK) return TCL_ERROR; - Blt_Chain_UnlinkLink(graphPtr->elements.displayList, elemPtr->link); Blt_Chain_LinkAfter(chain, elemPtr->link, NULL); } // Append the links to end of the display list + Blt_ChainLink link, next; for (link = Blt_Chain_FirstLink(chain); link != NULL; link = next) { next = Blt_Chain_NextLink(link); Blt_Chain_UnlinkLink(chain, link); Blt_Chain_LinkAfter(graphPtr->elements.displayList, link, NULL); } Blt_Chain_Destroy(chain); - Tcl_SetObjResult(interp, DisplayListObj(graphPtr)); + graphPtr->flags |= RESET_WORLD; Blt_EventuallyRedrawGraph(graphPtr); + + Tcl_SetObjResult(interp, DisplayListObj(graphPtr)); return TCL_OK; } static int NamesOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - Tcl_Obj *listObjPtr; + Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); if (objc == 3) { - Tcl_HashEntry *hPtr; Tcl_HashSearch iter; - - for (hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { + for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { Element* elemPtr = (Element*)Tcl_GetHashValue(hPtr); Tcl_Obj *objPtr = Tcl_NewStringObj(elemPtr->obj.name, -1); Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); } } else { - Tcl_HashEntry *hPtr; Tcl_HashSearch iter; - - for (hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { - int i; - + for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->elements.table, &iter); hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { Element* elemPtr = (Element*)Tcl_GetHashValue(hPtr); - for (i = 3; i < objc; i++) { - if (Tcl_StringMatch(elemPtr->obj.name,Tcl_GetString(objv[i]))) { - Tcl_Obj *objPtr; - objPtr = Tcl_NewStringObj(elemPtr->obj.name, -1); + for (int ii=3; ii<objc; ii++) { + if (Tcl_StringMatch(elemPtr->obj.name,Tcl_GetString(objv[ii]))) { + Tcl_Obj *objPtr = Tcl_NewStringObj(elemPtr->obj.name, -1); Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); break; } } } } + Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } @@ -823,73 +799,70 @@ static int NamesOp(Graph* graphPtr, Tcl_Interp* interp, static int RaiseOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - Blt_Chain chain; - Blt_ChainLink link, prev; - int i; + Blt_Chain chain = Blt_Chain_Create(); - /* Move the links of lowered elements out of the display list into - * a temporary list. */ - chain = Blt_Chain_Create(); - for (i = 3; i < objc; i++) { + for (int ii=3; ii<objc; ii++) { Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, objv[ii], &elemPtr) != TCL_OK) + return TCL_ERROR; - if (Blt_GetElement(interp, graphPtr, objv[i], &elemPtr) != TCL_OK) { - return TCL_ERROR; /* Can't find named element */ - } Blt_Chain_UnlinkLink(graphPtr->elements.displayList, elemPtr->link); Blt_Chain_LinkAfter(chain, elemPtr->link, NULL); } - /* Prepend the links to beginning of the display list in reverse order. */ + + // Prepend the links to beginning of the display list in reverse order + Blt_ChainLink link, prev; for (link = Blt_Chain_LastLink(chain); link != NULL; link = prev) { prev = Blt_Chain_PrevLink(link); Blt_Chain_UnlinkLink(chain, link); Blt_Chain_LinkBefore(graphPtr->elements.displayList, link, NULL); } Blt_Chain_Destroy(chain); - Tcl_SetObjResult(interp, DisplayListObj(graphPtr)); + graphPtr->flags |= RESET_WORLD; Blt_EventuallyRedrawGraph(graphPtr); + + Tcl_SetObjResult(interp, DisplayListObj(graphPtr)); return TCL_OK; } static int ShowOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - if (objc == 4) { - Tcl_Obj **elem; - int n; - if (Tcl_ListObjGetElements(interp, objv[3], &n, &elem) != TCL_OK) - return TCL_ERROR; + int n; + Tcl_Obj **elem; + if (Tcl_ListObjGetElements(interp, objv[3], &n, &elem) != TCL_OK) + return TCL_ERROR; - // Collect the named elements into a list - Blt_Chain chain = Blt_Chain_Create(); - for (int ii = 0; ii<n; ii++) { - Element* elemPtr; - if (Blt_GetElement(interp, graphPtr, elem[ii], &elemPtr) != TCL_OK) { - Blt_Chain_Destroy(chain); - return TCL_ERROR; - } - Blt_Chain_Append(chain, elemPtr); + // Collect the named elements into a list + Blt_Chain chain = Blt_Chain_Create(); + for (int ii=0; ii<n; ii++) { + Element* elemPtr; + if (Blt_GetElement(interp, graphPtr, elem[ii], &elemPtr) != TCL_OK) { + Blt_Chain_Destroy(chain); + return TCL_ERROR; } + Blt_Chain_Append(chain, elemPtr); + } - // Clear the links from the currently displayed elements - for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->elements.displayList); link != NULL; link = Blt_Chain_NextLink(link)) { - Element* elemPtr = (Element*)Blt_Chain_GetValue(link); - elemPtr->link = NULL; - } - Blt_Chain_Destroy(graphPtr->elements.displayList); - graphPtr->elements.displayList = chain; + // Clear the links from the currently displayed elements + for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->elements.displayList); link != NULL; link = Blt_Chain_NextLink(link)) { + Element* elemPtr = (Element*)Blt_Chain_GetValue(link); + elemPtr->link = NULL; + } + Blt_Chain_Destroy(graphPtr->elements.displayList); + graphPtr->elements.displayList = chain; - // Set links on all the displayed elements - for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link != NULL; - link = Blt_Chain_NextLink(link)) { - Element* elemPtr = (Element*)Blt_Chain_GetValue(link); - elemPtr->link = link; - } - graphPtr->flags |= RESET_WORLD; - Blt_EventuallyRedrawGraph(graphPtr); + // Set links on all the displayed elements + for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link != NULL; + link = Blt_Chain_NextLink(link)) { + Element* elemPtr = (Element*)Blt_Chain_GetValue(link); + elemPtr->link = link; } + graphPtr->flags |= RESET_WORLD; + Blt_EventuallyRedrawGraph(graphPtr); + Tcl_SetObjResult(interp, DisplayListObj(graphPtr)); return TCL_OK; } @@ -917,19 +890,17 @@ static Blt_OpSpec elemOps[] = { {"activate", 1, (void*)ActivateOp, 3, 0, "?elemName? ?index...?",}, {"bind", 1, (void*)BindOp, 3, 6, "elemName sequence command",}, {"cget", 2, (void*)CgetOp, 5, 5, "elemName option",}, - {"closest", 2, (void*)ClosestOp, 5, 0, - "x y ?option value?... ?elemName?...",}, - {"configure", 2, (void*)ConfigureOp, 4, 0, - "elemName ?elemName?... ?option value?...",}, + {"closest", 2, (void*)ClosestOp, 5, 0, "x y ?elemName?...",}, + {"configure", 2, (void*)ConfigureOp, 4, 0, "elemName ?option value?...",}, {"create", 2, (void*)CreateOp, 4, 0, "elemName ?option value?...",}, - {"deactivate", 3, (void*)DeactivateOp, 3, 0, "?elemName?...",}, - {"delete", 3, (void*)DeleteOp, 3, 0, "?elemName?...",}, + {"deactivate", 3, (void*)DeactivateOp, 4, 0, "?elemName?...",}, + {"delete", 3, (void*)DeleteOp, 4, 0, "?elemName?...",}, {"exists", 1, (void*)ExistsOp, 4, 4, "elemName",}, {"get", 1, (void*)GetOp, 4, 4, "name",}, - {"lower", 1, (void*)LowerOp, 3, 0, "?elemName?...",}, + {"lower", 1, (void*)LowerOp, 4, 0, "?elemName?...",}, {"names", 1, (void*)NamesOp, 3, 0, "?pattern?...",}, - {"raise", 1, (void*)RaiseOp, 3, 0, "?elemName?...",}, - {"show", 1, (void*)ShowOp, 3, 4, "?elemList?",}, + {"raise", 1, (void*)RaiseOp, 4, 0, "?elemName?...",}, + {"show", 1, (void*)ShowOp, 4, 4, "?elemList?",}, {"type", 1, (void*)TypeOp, 4, 4, "elemName",}, }; static int numElemOps = sizeof(elemOps) / sizeof(Blt_OpSpec); @@ -952,6 +923,19 @@ int Blt_ElementOp(Graph* graphPtr, Tcl_Interp* interp, // Support +static Tcl_Obj *DisplayListObj(Graph* graphPtr) +{ + Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); + + for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->elements.displayList); link != NULL; link = Blt_Chain_NextLink(link)) { + Element* elemPtr = (Element*)Blt_Chain_GetValue(link); + Tcl_Obj *objPtr = Tcl_NewStringObj(elemPtr->obj.name, -1); + Tcl_ListObjAppendElement(graphPtr->interp, listObjPtr, objPtr); + } + + return listObjPtr; +} + static void FreeElement(char* data) { Element* elemPtr = (Element *)data; @@ -962,34 +946,32 @@ static int GetPenStyleFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr, ClassId classId, PenStyle *stylePtr) { - Pen* penPtr; - Tcl_Obj **objv; int objc; - - if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) { + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) return TCL_ERROR; - } + if ((objc != 1) && (objc != 3)) { - if (interp) { - Tcl_AppendResult(interp, "bad style entry \"", - Tcl_GetString(objPtr), - "\": should be \"penName\" or \"penName min max\"", - NULL); - } + Tcl_AppendResult(interp, "bad style entry \"", + Tcl_GetString(objPtr), + "\": should be \"penName\" or \"penName min max\"", + NULL); return TCL_ERROR; } + + Pen* penPtr; if (Blt_GetPenFromObj(interp, graphPtr, objv[0], classId, &penPtr) != TCL_OK) return TCL_ERROR; if (objc == 3) { double min, max; - if ((Tcl_GetDoubleFromObj(interp, objv[1], &min) != TCL_OK) || - (Tcl_GetDoubleFromObj(interp, objv[2], &max) != TCL_OK)) { + (Tcl_GetDoubleFromObj(interp, objv[2], &max) != TCL_OK)) return TCL_ERROR; - } + SetWeight(stylePtr->weight, min, max); } + stylePtr->penPtr = penPtr; return TCL_OK; } @@ -1012,15 +994,12 @@ static int FetchVectorValues(Tcl_Interp* interp, ElemValues* valuesPtr, if (!valuesPtr) return TCL_ERROR; - double *array; - if (!valuesPtr->values) - array = (double*)malloc(Blt_VecLength(vector) * sizeof(double)); - else - array = (double*)realloc(valuesPtr->values, Blt_VecLength(vector) * sizeof(double)); + double *array = !valuesPtr->values ? + (double*)malloc(Blt_VecLength(vector) * sizeof(double)) : + (double*)realloc(valuesPtr->values, Blt_VecLength(vector)*sizeof(double)); if (!array) { - if (interp) - Tcl_AppendResult(interp, "can't allocate new vector", NULL); + Tcl_AppendResult(interp, "can't allocate new vector", NULL); return TCL_ERROR; } @@ -1182,16 +1161,11 @@ double Blt_FindElemValuesMinimum(ElemValues* valuesPtr, double minLimit) void Blt_FreeStylePalette(Blt_Chain stylePalette) { - Blt_ChainLink link; - - /* Skip the first slot. It contains the built-in "normal" pen of - * the element. */ - link = Blt_Chain_FirstLink(stylePalette); + // Skip the first slot. It contains the built-in "normal" pen of the element + Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); if (link) { Blt_ChainLink next; - for (link = Blt_Chain_NextLink(link); link != NULL; link = next) { - next = Blt_Chain_NextLink(link); PenStyle *stylePtr = (PenStyle*)Blt_Chain_GetValue(link); Blt_FreePen(stylePtr->penPtr); diff --git a/src/bltGrElemOp.h b/src/bltGrElemOp.h index 9dea9d5..359c1d4 100644 --- a/src/bltGrElemOp.h +++ b/src/bltGrElemOp.h @@ -68,7 +68,9 @@ extern "C" { #define NORMALPEN(e) ((((e)->normalPenPtr == NULL) ? (e)->builtinPenPtr : (e)->normalPenPtr)) typedef struct { - double min, max, range; + double min; + double max; + double range; } Weight; #define SetRange(l) \ @@ -189,13 +191,15 @@ struct _Element { extern const char* fillObjOption[]; extern Tk_CustomOptionSetProc StyleSetProc; extern Tk_CustomOptionGetProc StyleGetProc; +extern Tk_CustomOptionRestoreProc StyleRestoreProc; +extern Tk_CustomOptionFreeProc StyleFreeProc; extern double Blt_FindElemValuesMinimum(ElemValues *vecPtr, double minLimit); extern void Blt_ResizeStatusArray(Element* elemPtr, int nPoints); extern int Blt_GetPenStyle(Graph *graphPtr, char *name, size_t classId, PenStyle *stylePtr); extern void Blt_FreeStylePalette (Blt_Chain stylePalette); -extern PenStyle **Blt_StyleMap (Element* elemPtr); +extern PenStyle** Blt_StyleMap (Element* elemPtr); extern void Blt_MapErrorBars(Graph *graphPtr, Element* elemPtr, PenStyle **dataToStyle); extern void Blt_FreeDataValues(ElemValues *evPtr); diff --git a/tests/all.tcl b/tests/all.tcl index 4318d49..55df317 100644 --- a/tests/all.tcl +++ b/tests/all.tcl @@ -1,14 +1,11 @@ source graph.tcl -source xaxis.tcl -source axis.tcl source line.tcl source bar.tcl -source element.tcl -source pen.tcl source crosshairs.tcl source legend.tcl -source marker.tcl -source bitmapmarker.tcl -source linemarker.tcl -source polygonmarker.tcl -source textmarker.tcl +source xaxis.tcl +source axis.tcl +source element.tcl +source pen.tcl +source markerall.tcl + diff --git a/tests/axis.tcl b/tests/axis.tcl index c5d21f1..e7f08bb 100644 --- a/tests/axis.tcl +++ b/tests/axis.tcl @@ -5,6 +5,8 @@ set graph [bltLineGraph $w] $graph xaxis configure -title "X Axis" -limitsformat "%g" +echo "Testing Axis..." + #bltCmd $graph axis activate #bltCmd $graph axis bind #bltCmd $graph axis cget diff --git a/tests/bargraph.tcl b/tests/bargraph.tcl index db3fd7f..18f37ec 100644 --- a/tests/bargraph.tcl +++ b/tests/bargraph.tcl @@ -3,6 +3,8 @@ source base.tcl set w .bar set graph [bltBarGraph $w] +echo "Testing BarGraph..." + # Graph bltTest $graph -aspect 2 bltTest $graph -background red diff --git a/tests/bitmapmarker.tcl b/tests/bitmapmarker.tcl index 1c780dc..02fe772 100644 --- a/tests/bitmapmarker.tcl +++ b/tests/bitmapmarker.tcl @@ -6,6 +6,8 @@ set graph [bltLineGraph $w] set mm [$graph marker create bitmap tt -element data1 \ -coords {1.5 100} -bitmap error] +echo "Testing Bitmap Marker..." + bltTest3 $graph marker $mm -anchor nw bltTest3 $graph marker $mm -background yellow bltTest3 $graph marker $mm -bg red diff --git a/tests/crosshairs.tcl b/tests/crosshairs.tcl index c3cf2ad..cb3a93e 100644 --- a/tests/crosshairs.tcl +++ b/tests/crosshairs.tcl @@ -3,6 +3,8 @@ source base.tcl set w .line set graph [bltLineGraph $w] +echo "Testing Crosshairs..." + $graph crosshairs configure -hide no $graph crosshairs configure -position "@200,200" diff --git a/tests/legend.tcl b/tests/legend.tcl index 2959df0..3222d8d 100644 --- a/tests/legend.tcl +++ b/tests/legend.tcl @@ -3,7 +3,9 @@ source base.tcl set w .line set graph [bltLineGraph $w] -#bltTest2 $graph legend -activebackground +echo "Testing Legend..." + +bltTest2 $graph legend -activebackground #bltTest2 $graph legend -activeborderwidth #bltTest2 $graph legend -activeforeground #bltTest2 $graph legend -activerelief diff --git a/tests/linegraph.tcl b/tests/linegraph.tcl index 7b43526..0ba5b52 100644 --- a/tests/linegraph.tcl +++ b/tests/linegraph.tcl @@ -3,6 +3,8 @@ source base.tcl set w .line set graph [bltLineGraph $w] +echo "Testing LineGraph..." + bltTest $graph -aspect 2 bltTest $graph -background red bltTest $graph -barmode overlap diff --git a/tests/linemarker.tcl b/tests/linemarker.tcl index 41f7a34..a02a33c 100644 --- a/tests/linemarker.tcl +++ b/tests/linemarker.tcl @@ -9,6 +9,8 @@ set nn [$graph marker create line ss -element data1 \ -coords {1 150 .5 100 1 50} -linewidth 1 \ -outline green -dashes 4] +echo "Testing Line Marker..." + bltTest3 $graph marker $mm -bindtags {aa} bltTest3 $graph marker $mm -cap round bltTest3 $graph marker $mm -coords {1 50 1.5 100 2 150} diff --git a/tests/marker.tcl b/tests/marker.tcl index f72029c..bc034df 100644 --- a/tests/marker.tcl +++ b/tests/marker.tcl @@ -9,6 +9,8 @@ set nn [$graph marker create line ss -element data1 \ -coords {1 150 .5 100 1 50} -linewidth 1 \ -outline green -dashes 4] +echo "Testing Marker..." + bltCmd $graph marker bind aa <Button-1> [list puts "%x %y"] bltCmd $graph marker cget $mm -cap bltCmd $graph marker configure $mm diff --git a/tests/polygonmarker.tcl b/tests/polygonmarker.tcl index 4efe987..d71ab8d 100644 --- a/tests/polygonmarker.tcl +++ b/tests/polygonmarker.tcl @@ -6,6 +6,8 @@ set graph [bltLineGraph $w] set mm [$graph marker create polygon tt -element data1 \ -coords {1 50 1.5 100 1 150} -linewidth 5] +echo "Testing Polygon Marker..." + bltTest3 $graph marker $mm -bindtags {aa} bltTest3 $graph marker $mm -cap round bltTest3 $graph marker $mm -coords {1 50 1.5 100 2 150} diff --git a/tests/textmarker.tcl b/tests/textmarker.tcl index ad885c5..c5787f2 100644 --- a/tests/textmarker.tcl +++ b/tests/textmarker.tcl @@ -6,6 +6,8 @@ set graph [bltLineGraph $w] set mm [$graph marker create text tt -element data1 \ -coords {1.5 100} -text {Text Marker} -font {24}] +echo "Testing Text Marker..." + bltTest3 $graph marker $mm -anchor nw bltTest3 $graph marker $mm -background blue bltTest3 $graph marker $mm -bg red |