/***********************************************************************/ /* Open Visualization Data Explorer */ /* (C) Copyright IBM Corp. 1989,1999 */ /* ALL RIGHTS RESERVED */ /* This code licensed under the */ /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ /***********************************************************************/ #include #include #include static RGBColor DEFAULTTICSCOLOR = {1.0, 1.0, 0.0}; static RGBColor DEFAULTLABELCOLOR = {1.0, 1.0, 1.0}; static RGBColor DEFAULTGRIDCOLOR = {0.3, 0.3, 0.3}; static RGBColor DEFAULTBACKGROUNDCOLOR = {0.05, 0.05, 0.05}; extern Pointer _dxfNewAxesObject(void); extern Error _dxfSetAxesCharacteristic(Pointer, char *, Pointer); static Error GetAnnotationColors(Object, Object, RGBColor, RGBColor, RGBColor, RGBColor, int *, RGBColor *, RGBColor *, RGBColor *, RGBColor *); extern Error _dxfHowManyStrings(Object, int *); extern Error _dxfLowerCase(char *, char **); static Error _dxfCopyMostAttributes(Object, Object); extern Object _dxfAutoAxes(Pointer); int m_AutoAxes(Object *in, Object *out) { Pointer axeshandle=NULL; Object object, labels, corners; Camera camera; int n = -9999, ns[3], adjust = 1, i; char *xlabel = NULL, *ylabel = NULL, *zlabel = NULL, *extra = NULL; char *axestype = NULL, *fontname; Point cursor, box[8], min, max, delta; int frame; float labelscale=1.0, fuzzattfloat; Matrix m1, m3, m; int cursor_specified = 0; int grid, fuzzattint; Class class; RGBColor labelcolor, ticcolor, gridcolor, backgroundcolor; Array xticklocations=NULL, yticklocations=NULL, zticklocations=NULL; int numlist; float *list_ptr; ns[0] = ns[1] = ns[2] = 0; /* the object */ if (!in[0]) { /* object must be specified */ DXSetError(ERROR_BAD_PARAMETER, "#10000", "object"); return ERROR; } if (DXGetObjectClass(in[0])==CLASS_FIELD && DXEmptyField((Field)in[0])) { out[0] = in[0]; return OK; } class = DXGetObjectClass(in[0]); if ((class != CLASS_FIELD)&&(class != CLASS_GROUP)&& (class != CLASS_XFORM)&&(class != CLASS_CLIPPED)) { /* object must be a field or a group */ DXSetError(ERROR_BAD_PARAMETER,"#10190", "object"); return ERROR; } object = in[0]; /* camera */ if (!in[1]) { DXSetError(ERROR_BAD_PARAMETER, "#10000", "camera"); return ERROR; } class = DXGetObjectClass(in[1]); if (class != CLASS_CAMERA) { /* camera must be a camera */ DXSetError(ERROR_BAD_PARAMETER,"#10660", "camera"); return ERROR; } camera = (Camera)in[1]; /* labels */ labels = in[2]? in[2] : DXGetAttribute(object, "axis labels"); if (labels) { if (!DXExtractNthString(labels, 0, &xlabel)) { /* must be a string list */ DXSetError(ERROR_BAD_PARAMETER, "#10201", "labels"); return ERROR; } DXExtractNthString(labels, 1, &ylabel); DXExtractNthString(labels, 2, &zlabel); if (DXExtractNthString(labels, 3, &extra)) DXWarning("extra axis label(s) ignored"); } /* number of tick marks */ n = -9999; if (in[3]) { if (DXExtractParameter(in[3], TYPE_INT, 1, 3, (Pointer)ns)) { n = 0; } else if (DXExtractParameter(in[3], TYPE_INT, 1, 2, (Pointer)ns)) { ns[2] = 0; n = 0; } else if (!DXExtractInteger(in[3], &n)) { /* ticks must be an integer or integer list */ DXSetError(ERROR_BAD_PARAMETER, "#10050", "ticks"); return ERROR; } } /* corners is in[4] */ corners = in[4]; /* show frame? */ frame = 0; if (in[5] && !DXExtractInteger(in[5], &frame)) { /* frame parameter must be either 0 or 1 */ DXSetError(ERROR_BAD_PARAMETER, "#10070", "frame"); return ERROR; } if ((frame<0) || (frame>1)) { DXSetError(ERROR_BAD_PARAMETER, "#10070", "frame"); return ERROR; } /* adjust? */ adjust = 1; if (in[6] && !DXExtractInteger(in[6], &adjust)) { DXSetError(ERROR_BAD_PARAMETER, "#10070", "adjust"); return ERROR; } if (adjust!=0 && adjust!=1) { DXSetError(ERROR_BAD_PARAMETER, "#10070", "adjust"); return ERROR; } /* cursor? */ cursor_specified = 0; if (in[7]) { if (!DXExtractParameter(in[7], TYPE_FLOAT, 3, 1, (Pointer)&cursor)) { /* "cursor must be a three vector" */ DXSetError(ERROR_BAD_PARAMETER, "#10230","cursor", 3); return ERROR; } cursor_specified = 1; } if (in[8]) { if (!DXExtractInteger(in[8], &grid)) { /* grid must be 0 or 1 */ DXSetError(ERROR_BAD_PARAMETER,"#10070", "grid"); return ERROR; } if ((grid < 0)||(grid > 1)) { DXSetError(ERROR_BAD_PARAMETER,"#10070", "grid"); return ERROR; } } else { grid=0; } /* in[9] and in[10] are the colors for the annotation objects */ if (!(GetAnnotationColors(in[9], in[10], DEFAULTTICSCOLOR, DEFAULTLABELCOLOR, DEFAULTGRIDCOLOR, DEFAULTBACKGROUNDCOLOR, &frame, &ticcolor, &labelcolor, &gridcolor, &backgroundcolor))) return ERROR; /* labelscale */ if (in[11]) { if (!DXExtractFloat(in[11],&labelscale)) { DXSetError(ERROR_BAD_PARAMETER, "#10090","labelscale"); return ERROR; } if (labelscale < 0) { DXSetError(ERROR_BAD_PARAMETER, "#10090","labelscale"); return ERROR; } } /* font */ if (in[12]) { if (!DXExtractString(in[12],&fontname)) { DXSetError(ERROR_BAD_PARAMETER, "#10200","font"); return ERROR; } } else { fontname = "standard"; } /* If specified, these should override the corners and the tics params */ /* user-forced xtic locations */ if (in[13]) { if (!(DXGetObjectClass(in[13])==CLASS_ARRAY)) { DXSetError(ERROR_BAD_PARAMETER,"xlocations must be a scalar list"); return ERROR; } xticklocations = in[13]; } /* user-forced ytic locations */ if (in[14]) { if (!(DXGetObjectClass(in[14])==CLASS_ARRAY)) { DXSetError(ERROR_BAD_PARAMETER,"ylocations must be a scalar list"); return ERROR; } yticklocations = in[14]; } /* user-forced ztic locations */ if (in[15]) { if (!(DXGetObjectClass(in[15])==CLASS_ARRAY)) { DXSetError(ERROR_BAD_PARAMETER,"zlocations must be a scalar list"); return ERROR; } zticklocations = in[15]; } /* user-forced xtic labels; need to set in[13] */ if (in[16]) { if (!(DXGetObjectClass(in[16])==CLASS_ARRAY)) { DXSetError(ERROR_BAD_PARAMETER,"xlabels must be a string list"); return ERROR; } if (!DXGetArrayInfo(in[16], &numlist, NULL,NULL,NULL,NULL)) return ERROR; if (!in[13]) { /* need to make an array to use. It will go from 0 to n-1 */ xticklocations = DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 0); if (!xticklocations) return ERROR; list_ptr = DXAllocate(numlist*sizeof(float)); if (!list_ptr) return ERROR; for (i=0; i max.x) max.x = box[i].x; if (box[i].y > max.y) max.y = box[i].y; if (box[i].z > max.z) max.z = box[i].z; } delta.x = max.x - min.x; delta.y = max.y - min.y; delta.z = max.z - min.z; DXFree((Pointer)axeshandle); DXSetIntegerAttribute(out[0], "autoaxes", 1); /* copy all the top level attributes. However, we don't want to copy the color multiplier and opacity multiplier attributes, because then they'll be there twice and will get concatenated together. */ _dxfCopyMostAttributes(out[0],in[0]); if (!in[13]) DXDelete((Object)xticklocations); if (!in[14]) DXDelete((Object)yticklocations); if (!in[15]) DXDelete((Object)zticklocations); return OK; } else if (!in[13]) DXDelete((Object)xticklocations); if (!in[14]) DXDelete((Object)yticklocations); if (!in[15]) DXDelete((Object)zticklocations); DXFree((Pointer)axeshandle); return ERROR; } static Error GetAnnotationColors(Object colors, Object which, RGBColor defaultticcolor, RGBColor defaultlabelcolor, RGBColor defaultgridcolor, RGBColor defaultbackgroundcolor, int *frame, RGBColor *ticcolor, RGBColor *labelcolor, RGBColor *gridcolor, RGBColor *backgroundcolor) { RGBColor *colorlist =NULL; int i, numcolors, numcolorobjects; char *colorstring, *newcolorstring; /* in[9] is the colors list */ /* first set up the default colors */ *ticcolor = defaultticcolor; *labelcolor = defaultlabelcolor; *gridcolor = defaultgridcolor; *backgroundcolor = defaultbackgroundcolor; if (colors) { if (DXExtractNthString(colors,0,&colorstring)) { /* it's a list of strings */ /* first figure out how many there are */ if (!_dxfHowManyStrings(colors, &numcolors)) goto error; /* allocate space for the 3-vectors */ colorlist = DXAllocateLocal(numcolors*sizeof(RGBColor)); if (!colorlist) goto error; for (i=0; i