file: multi_select.c
/* * multi_select.c - This file contains all routines associated with * the multiple selection of points. */ #include "XmdvTool.h" #include "multi_select.h" #include "cursor.h" #include "util.h" /* external variables */ extern int dims; extern double *br_pos, *br_size; extern double dim_min[MAXDIM], dim_max[MAXDIM]; /* global multi_select variables */ static int multi_select = FALSE; static int multi_sel_pts[MAX_MULTI_SEL]; static int num_multi_sel; /* * MultiSelectACT() - Action that toggles the multi_select flag * when a shift key is pressed or released. */ void MultiSelectACT(Widget w, XEvent *event, String *params, Cardinal *num_params) { int state; /* check the parameters */ if(*num_params != 1) { fprintf(stderr, "Error in MultiSelect() - Invalid # of parameters passed\n"); return; } if(!strcmp(params[0], "On")) { multi_select = TRUE; /* initialize data structures */ num_multi_sel = 0; state = GetState(); /* change the cursor */ if(state == STATE_GLYPH) CrosshairCursor(w); else if(state == STATE_SCATTERPLOT || state == STATE_PARCOORD) CircleCursor(w); } else if(!strcmp(params[0], "Off")) { multi_select = FALSE; /* create the brush from the points */ if(num_multi_sel != 0) MultiSelectDefineBrush(); /* restore the cursor */ ArrowCursor(w); } else { fprintf(stderr, "Error in MultiSelect() - Incorrect parameter passed: %s\n", params[0]); return; } } /* * MultiSelectDefineBrush() - Define a new brush from the multiple * selected points */ void MultiSelectDefineBrush(void) { int i,j; double *brush_mins, *brush_maxes; double data[MAXDIM]; if(!(brush_mins = (double *)malloc(dims * sizeof(double)))) { fprintf(stderr, "Error allocating brush_mins in MultiSelectDefineBrush()\n"); return; } if(!(brush_maxes = (double *)malloc(dims * sizeof(double)))) { fprintf(stderr, "Error allocating brush_maxes in MultiSelectDefineBrush()\n"); return; } /* set starting value for mins/maxes */ for(i=0; i<dims; i++) { get_data(data, multi_sel_pts[0]); brush_mins[i] = brush_maxes[i] = data[i]; } /* define the brush min/max values */ for(i=1; i<num_multi_sel; i++) { get_data(data, multi_sel_pts[i]); for(j=0; j<dims; j++) { brush_mins[j] = MIN(brush_mins[j], data[j]); brush_maxes[j] = MAX(brush_maxes[j], data[j]); } } /* create the new brush from min/max values and redraw */ for(i=0; i<dims; i++) { br_pos[i] = (brush_mins[i] + brush_maxes[i]) / 2.; br_size[i] = brush_maxes[i] - brush_mins[i]; /* add on 1% of the min/max range for roundoff error */ br_size[i] += .01*(dim_max[i] - dim_min[i]); } do_redraw(); free(brush_mins); free(brush_maxes); } /* * MultiSelectAddPoint() - Add a point to the list of points in the * multi-select list. If point already exists, * will not add it. Returns 0 on success and 1 * on error. */ int MultiSelectAddPoint(int point) { int i; /* check if full */ if(num_multi_sel == MAX_MULTI_SEL) return 1; /* check if point is already there */ for(i=0; i<num_multi_sel; i++) if(multi_sel_pts[i] == point) return 1; /* add the point */ multi_sel_pts[num_multi_sel++] = point; return 0; } /* * MultiSelectDeletePoint() - Delete a point from the multi-select list. * No operation performed if point is not in * the list. Returns 0 on success or 1 on error. */ int MultiSelectDeletePoint(int point) { int i,j; /* check if point is already there */ for(i=0; i<num_multi_sel; i++) if(multi_sel_pts[i] == point) break; if(i == num_multi_sel) /* if it wasn't there */ return 1; /* delete the point */ for(j=i+1; j<num_multi_sel; j++) multi_sel_pts[j-1] = multi_sel_pts[j]; num_multi_sel--; return 0; } /* * MultiSelectCovered() - Given a point, return TRUE if the point is * in the multi-select list. */ int MultiSelectCovered(int point) { int i; for(i=0; i<num_multi_sel; i++) if(multi_sel_pts[i] == point) return TRUE; /* didn't find it */ return FALSE; } /* * CheckMultiSelect() - Returns TRUE if multi_select is on, FALSE if * not. */ int CheckMultiSelect(void) { return(multi_select); }
Back to Source File Index
C++ to HTML Conversion by ctoohtml