5 * $Log: tableVisiTcl.C,v $
6 * Revision 1.2 1995/11/08 21:56:05 tamches
7 * when-idle routine does a tryFirst()
8 * fold, invalidmetrics, phasename callbacks gone since unused
9 * sigFigChangeCommand reads from tcl vrble SignificantDigits instead
11 * removed unInstallTableVisiCommands, since not useful
13 * Revision 1.1 1995/11/04 00:48:25 tamches
14 * First version of new table visi
24 #include "tableVisi.h"
25 #include "visi/h/visualization.h"
27 #include "tableVisiTcl.h"
29 /* ************************************************************* */
31 extern tableVisi *theTableVisi; // our main data structure
32 extern bool xsynch_flag;
33 unsigned currFormat=0; // 0 --> current; 1 --> averages; 2 --> totals
35 /* ************************************************************* */
37 void tableWhenIdleDrawRoutine(ClientData) {
38 if (theTableVisi->tryFirst())
39 theTableVisi->draw(xsynch_flag);
41 tkInstallIdle tableDrawWhenIdle(&tableWhenIdleDrawRoutine);
43 /* ************************************************************* */
45 int Dg2NewDataCallback(int lastBucket) {
46 // cout << "Dg2NewDataCallback (c++)" << endl;
47 if (theTableVisi == NULL) {
48 cout << "Dg2NewDataCallback tableVisi: missed an early sample since not yet initialized" << endl;
52 const unsigned numMetrics = theTableVisi->getNumMetrics();
53 const unsigned numFoci = theTableVisi->getNumFoci();
55 for (unsigned metriclcv=0; metriclcv < numMetrics; metriclcv++) {
56 visi_GridHistoArray &metricValues = dataGrid[metriclcv];
58 for (unsigned focuslcv=0; focuslcv < numFoci; focuslcv++) {
59 visi_GridCellHisto &theCell = metricValues[focuslcv];
62 theTableVisi->invalidateCell(metriclcv, focuslcv);
63 else if (currFormat==0) // current values
64 theTableVisi->setCellValidData(metriclcv, focuslcv,
65 theCell.Value(lastBucket));
66 else if (currFormat==1) // average values
67 theTableVisi->setCellValidData(metriclcv, focuslcv,
68 dataGrid.AggregateValue(metriclcv,
70 else if (currFormat==2) // total values
71 theTableVisi->setCellValidData(metriclcv, focuslcv,
72 dataGrid.SumValue(metriclcv, focuslcv));
76 tableDrawWhenIdle.install(NULL);
80 int Dg2AddMetricsCallback(int) {
81 // completely rethink metrics and resources
82 // very ugly; necessary because the visilib interface
83 // is rather crude in this area.
84 // Nevertheless, an improved version of this routine can avoid
85 // rethinking everything, by making a pass over the dataGrid to
86 // _manually_ compute what has actually changed.
88 extern Tcl_Interp *mainInterp;
89 theTableVisi->clearMetrics(mainInterp);
90 unsigned newNumMetrics = dataGrid.NumMetrics();
91 for (unsigned metriclcv=0; metriclcv < newNumMetrics; metriclcv++)
92 theTableVisi->addMetric(dataGrid.MetricName(metriclcv),
93 dataGrid.MetricUnits(metriclcv));
95 theTableVisi->clearFoci(mainInterp);
96 unsigned newNumFoci = dataGrid.NumResources();
97 for (unsigned focuslcv=0; focuslcv < newNumFoci; focuslcv++)
98 theTableVisi->addFocus(dataGrid.ResourceName(focuslcv));
100 // now update the sorting, as applicable
101 char *sortMetricsStr = Tcl_GetVar(mainInterp, "sortMetrics", TCL_GLOBAL_ONLY);
102 bool sortMetricsFlag = atoi(sortMetricsStr);
104 theTableVisi->sortMetrics();
106 theTableVisi->unsortMetrics();
108 char *sortFociStr = Tcl_GetVar(mainInterp, "sortFoci", TCL_GLOBAL_ONLY);
109 bool sortFociFlag = atoi(sortFociStr);
111 theTableVisi->sortFoci();
113 theTableVisi->unsortFoci();
115 theTableVisi->resize(mainInterp);
116 tableDrawWhenIdle.install(NULL);
122 // cout << "welcome to Dg2Fold" << endl;
123 // tableDrawWhenIdle.install(NULL);
128 //int Dg2InvalidMetricsOrResources(int) {
129 // cout << "welcome to Dg2InvalidMetricsOrResources" << endl;
130 //// myTclEval(MainInterp, "DgInvalidCallback");
131 // tableDrawWhenIdle.install(NULL);
136 //int Dg2PhaseNameCallback(int) {
137 // cout << "welcome to Dg2PhaseNameCallback" << endl;
138 //// myTclEval(MainInterp, "DgPhaseCallback");
139 // tableDrawWhenIdle.install(NULL);
144 /* ************************************************************* */
146 void dummyDeleteProc(ClientData) {}
148 int tableVisiNewVertScrollPositionCommand(ClientData, Tcl_Interp *interp,
149 int argc, char **argv) {
150 // The arguments will be one of:
151 // 1) moveto [fraction]
152 // 2) scroll [num-units] unit (num-units is always either -1 or 1)
153 // 3) scroll [num-pages] page (num-pages is always either -1 or 1)
154 // we let processScrollCallback handle 'em
157 bool anyChanges = processScrollCallback(interp, argc, argv,
159 theTableVisi->get_offset_y(),
160 theTableVisi->get_total_cell_y_pix(),
161 theTableVisi->get_visible_y_pix(),
165 anyChanges = theTableVisi->adjustVertSBOffset(interp, newFirst);
168 tableDrawWhenIdle.install(NULL);
173 int tableVisiNewHorizScrollPositionCommand(ClientData, Tcl_Interp *interp,
174 int argc, char **argv) {
175 // The arguments will be one of:
176 // 1) moveto [fraction]
177 // 2) scroll [num-units] unit (num-units is always either -1 or 1)
178 // 3) scroll [num-pages] page (num-pages is always either -1 or 1)
179 // we let processScrollCallback handle 'em
182 bool anyChanges = processScrollCallback(interp, argc, argv,
184 theTableVisi->get_offset_x(),
185 theTableVisi->get_total_cell_x_pix(),
186 theTableVisi->get_visible_x_pix(),
190 anyChanges = theTableVisi->adjustHorizSBOffset(interp, newFirst);
193 tableDrawWhenIdle.install(NULL);
198 int tableVisiConfigureCommand(ClientData, Tcl_Interp *interp,
200 assert(theTableVisi->tryFirst());
201 theTableVisi->resize(interp); // adjusts scrollbar
202 tableDrawWhenIdle.install(NULL);
207 int tableVisiExposeCommand(ClientData, Tcl_Interp *,
209 assert(theTableVisi->tryFirst());
210 tableDrawWhenIdle.install(NULL);
215 int updateNamesCommand(ClientData, Tcl_Interp *interp,
216 int argc, char **argv) {
218 // cout << "welcome to updateNamesCommand: arg is " << argv[1] << endl;
220 assert(theTableVisi->tryFirst());
222 if (theTableVisi->setFocusNameMode(interp, (bool)atoi(argv[1])))
223 tableDrawWhenIdle.install(NULL);
228 int sigFigChangeCommand(ClientData, Tcl_Interp *interp,
232 char *sigFigStr = Tcl_GetVar(interp, "SignificantDigits", TCL_GLOBAL_ONLY);
233 if (sigFigStr == NULL)
234 tclpanic(interp, "could not find vrble SignificantDigits");
236 int newNumSigFigs = atoi(sigFigStr);
238 assert(theTableVisi->tryFirst());
240 if (theTableVisi->setSigFigs(newNumSigFigs))
241 tableDrawWhenIdle.install(NULL);
246 int sortMetricsCommand(ClientData, Tcl_Interp *,
248 theTableVisi->sortMetrics();
249 if (theTableVisi->tryFirst())
250 tableDrawWhenIdle.install(NULL);
254 int unsortMetricsCommand(ClientData, Tcl_Interp *,
256 theTableVisi->unsortMetrics();
257 if (theTableVisi->tryFirst())
258 tableDrawWhenIdle.install(NULL);
262 int sortFociCommand(ClientData, Tcl_Interp *,
264 theTableVisi->sortFoci();
265 if (theTableVisi->tryFirst())
266 tableDrawWhenIdle.install(NULL);
270 int unsortFociCommand(ClientData, Tcl_Interp *,
272 theTableVisi->unsortFoci();
273 if (theTableVisi->tryFirst())
274 tableDrawWhenIdle.install(NULL);
278 int formatChangedCommand(ClientData, Tcl_Interp *interp,
280 char *dataFormatStr = Tcl_GetVar(interp, "DataFormat", TCL_GLOBAL_ONLY);
281 if (dataFormatStr == NULL)
282 tclpanic(interp, "could not find DataFormat tcl vrble");
284 int dataFormat = atoi(dataFormatStr);
285 currFormat = dataFormat;
287 if (theTableVisi->tryFirst())
288 tableDrawWhenIdle.install(NULL);
293 void installTableVisiCommands(Tcl_Interp *interp) {
294 Tcl_CreateCommand(interp, "horizScrollbarNewScrollPosition",
295 tableVisiNewHorizScrollPositionCommand,
296 NULL, dummyDeleteProc);
297 Tcl_CreateCommand(interp, "vertScrollbarNewScrollPosition",
298 tableVisiNewVertScrollPositionCommand,
299 NULL, dummyDeleteProc);
301 Tcl_CreateCommand(interp, "tableVisiConfigure",
302 tableVisiConfigureCommand,
303 NULL, dummyDeleteProc);
304 Tcl_CreateCommand(interp, "tableVisiExpose",
305 tableVisiExposeCommand,
306 NULL, dummyDeleteProc);
308 Tcl_CreateCommand(interp, "updateNames",
310 NULL, dummyDeleteProc);
312 Tcl_CreateCommand(interp, "sigFigChange",
314 NULL, dummyDeleteProc);
316 Tcl_CreateCommand(interp, "sortMetrics",
318 NULL, dummyDeleteProc);
319 Tcl_CreateCommand(interp, "unsortMetrics",
320 unsortMetricsCommand,
321 NULL, dummyDeleteProc);
323 Tcl_CreateCommand(interp, "sortFoci",
325 NULL, dummyDeleteProc);
326 Tcl_CreateCommand(interp, "unsortFoci",
328 NULL, dummyDeleteProc);
330 Tcl_CreateCommand(interp, "formatChanged",
331 formatChangedCommand,
332 NULL, dummyDeleteProc);