00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "aclvis/Interact.h"
00027 #include "aclvis/aclvis.h"
00028 #include "aclvis/MainWindow.h"
00029 #include "aclvis/UIWindow.h"
00030 #include "Profile/Profiler.h"
00031
00032 #ifdef IPPL_USE_STANDARD_HEADERS
00033 #include <iostream>
00034 using namespace std;
00035 #else
00036 #include <iostream.h>
00037 #endif
00038
00039 #include <vtk.h>
00040 #include <vtkXRenderWindow.h>
00041
00042 extern MainWindow *mainWindow;
00043
00044 VizTool *current_viztool;
00045
00047 VizRecord::VizRecord() {
00048 TAU_PROFILE("VizRecord::VizRecord()", "void ()", TAU_VIZ);
00049
00050 caller = NULL;
00051 strcpy(name,"");
00052 id = 0;
00053 tool = NULL;
00054 tooltype = Empty;
00055 }
00056
00057 void
00058 VizRecord::Print() {
00059 TAU_PROFILE("VizRecord::Print()", "void ()", TAU_VIZ | TAU_IO);
00060
00061 cerr << "Caller: " << caller << "\n";
00062 cerr << "Name: " << name << "\n";
00063 cerr << "Id: " << id << "\n";
00064 cerr << "Tool: " << tool << "\n";
00065 cerr << "ToolType: " << tooltype << "\n\n";
00066 }
00067
00069 int
00070 VizCollection::MatchTest(VizRecord *current, VizRecord *data) {
00071 TAU_PROFILE("VizCollection::MatchTest()", "int (VizRecord *, VizRecord *)", TAU_VIZ);
00072
00073 Boolean flag;
00074
00075 flag = 1;
00076
00077 if (data->caller != NULL) {
00078 flag = flag && (current->caller == data->caller);
00079 }
00080 if (strcmp(data->name,"") != 0) {
00081 flag = flag && (strcmp(current->name, data->name) == 0);
00082 }
00083 if (data->tool != NULL) {
00084 flag = flag && (current->tool == data->tool);
00085 }
00086 if (data->id != 0) {
00087 flag = flag && (current->id == data->id);
00088 }
00089 if (data->tooltype != Empty) {
00090 flag = flag && (current->tooltype == data->tooltype);
00091 }
00092 return flag;
00093 }
00094
00095 VizRecord*
00096 VizCollection::FindItem(VizRecord *data) {
00097 TAU_PROFILE("VizCollection::FindItem()", "VizRecord * (VizRecord *)", TAU_VIZ);
00098
00099 VizRecord *current;
00100
00101
00102
00103 this->InitTraversal();
00104
00105 while ((current = (VizRecord *)this->GetNextItemAsObject()) != NULL) {
00106
00107 if (MatchTest(current,data) == 1) {
00108
00109
00110 return current;
00111 }
00112 }
00113
00114 return NULL;
00115 }
00116
00117 VizRecord*
00118 VizCollection::FindNextItem(VizRecord *data) {
00119 TAU_PROFILE("VizCollection::FindNextItem()", "VizRecord * (VizRecord *)", TAU_VIZ);
00120
00121 VizRecord *current;
00122
00123
00124 while ((current = (VizRecord *)this->GetNextItemAsObject()) != NULL) {
00125 if (MatchTest(current,data) == 1) {
00126
00127
00128 return current;
00129 }
00130 }
00131
00132 return NULL;
00133 }
00134
00135
00137 extern vtkXRenderWindow *renWin;
00138 extern vtkRenderer *ren1;
00139
00140 VizTool::VizTool() : interpreter("vizard> ")
00141 {
00142 TAU_PROFILE("VizTool::VizTool()", "void ()", TAU_VIZ);
00143
00144
00145
00146
00147 RenderTool *rendertool;
00148 VizRecord *viz_data;
00149
00150 image_file_base = 0;
00151 image_file_ext = 0;
00152 image_next_num = 0;
00153
00154 InitToolIds();
00155
00156 rendertool = new RenderTool;
00157 rendertool->SetRenderWindow(renWin);
00158 rendertool->SetRenderer(ren1);
00159 SetSelectedTool(Render, rendertool);
00160
00161 viz_db = new VizCollection();
00162
00163 viz_data = new VizRecord();
00164 viz_data->caller = rendertool;
00165 strcpy(viz_data->name, "Render Tool");
00166 viz_data->tool = rendertool;
00167 viz_data->id = GetUniqueToolId(Render);
00168 viz_data->tooltype = Render;
00169
00170 viz_db->AddItem(viz_data);
00171
00172 current_viztool = this;
00173
00174 interactIter = 0;
00175 goFlag = 0;
00176 InteractFlag = 1;
00177
00178
00179 toolcmd = new InterpCmdTool(this);
00180 interpreter.addCommand(*toolcmd);
00181 }
00182
00183 void
00184 VizTool::InterpretCommand(const char *str) {
00185 TAU_PROFILE("VizTool::InterpretCommand()", "void", TAU_VIZ);
00186 interpreter.evalCommand(str);
00187 }
00188
00189 void
00190 VizTool::InterpretInteract(int timeoutseconds) {
00191 TAU_PROFILE("VizTool::InterpretInteract()", "void", TAU_VIZ);
00192 interpreter.interact(timeoutseconds);
00193 }
00194
00195 VizCollection*
00196 VizTool::GetVizDB() {
00197 TAU_PROFILE("VizTool::GetVizDB()", "VizCollection * ()", TAU_VIZ);
00198 return viz_db;
00199 }
00200
00201 int
00202 VizTool::GetUniqueToolId(ToolType tooltype) {
00203 TAU_PROFILE("VizTool::GetUniqueToolId()", "int (ToolType)", TAU_VIZ);
00204 ToolId[tooltype]++;
00205 return ToolId[tooltype];
00206 };
00207
00208 void
00209 VizTool::InitToolIds() {
00210 TAU_PROFILE("VizTool::InitToolIds()", "void ()", TAU_VIZ);
00211 int i;
00212 for (i = 0; i < NUM_OF_TOOL_TYPES; i++) {
00213 ToolId[i]=0;
00214 }
00215 };
00216
00217 void
00218 VizTool::SetSelectedTool(ToolType tooltype, Tool *tool) {
00219 TAU_PROFILE("VizTool::SetSelectedTool()", "void (ToolType, Tool *)", TAU_VIZ);
00220 SelectedTool[tooltype] = tool;
00221 };
00222
00223 Tool*
00224 VizTool::GetSelectedTool(ToolType tooltype) {
00225 TAU_PROFILE("VizTool::GetSelectedTool()", "Tool * (ToolType)", TAU_VIZ);
00226 return SelectedTool[tooltype];
00227 };
00228
00229 void
00230 VizTool::Interact(int flag) {
00231 TAU_PROFILE("VizTool::Interact()", "void (int)", TAU_VIZ);
00232
00233
00234
00235
00236
00237
00238 XEvent event_return;
00239 Boolean test;
00240
00241
00242 RenderTool *rendertool;
00243
00244 current_viztool = this;
00245
00246 rendertool = (RenderTool *)current_viztool->GetSelectedTool(Render);
00247 rendertool->GetRenderWindow()->Render();
00248
00249
00250 char imagefile[4096];
00251 if (GetImageName(imagefile)) {
00252 cerr << "VizTool: writing image to file '" << imagefile << "'." << endl;
00253 rendertool->GetRenderWindow()->SetFilename(imagefile);
00254 rendertool->GetRenderWindow()->SaveImageAsPPM();
00255 image_next_num++;
00256 }
00257
00258 if (goFlag == 0) {
00259 InteractFlag = 1;
00260 while (InteractFlag == 1) {
00261 XtAppNextEvent(UIWindow::getAppContext(), &event_return);
00262 test = XtDispatchEvent(&event_return);
00263 }
00264 } else {
00265 while (XtAppPending(UIWindow::getAppContext())) {
00266 XtAppNextEvent(UIWindow::getAppContext(), &event_return);
00267 test = XtDispatchEvent(&event_return);
00268 if (test);
00269 }
00270 }
00271 interactIter++;
00272 }
00273
00274 void
00275 VizTool::InteractExit() {
00276 TAU_PROFILE("VizTool::InteractExit()", "void ()", TAU_VIZ);
00277
00278 InteractFlag = 0;
00279 }
00280
00281 void
00282 VizTool::InteractStopFlow() {
00283 TAU_PROFILE("VizTool::InteractExit()", "void ()", TAU_VIZ);
00284
00285 goFlag = 0;
00286 }
00287
00288 void
00289 VizTool::InteractGoFlow() {
00290 TAU_PROFILE("VizTool::InteractExit()", "void ()", TAU_VIZ);
00291
00292 goFlag = 1;
00293 }
00294
00295 void
00296 VizTool::connect(void *caller, char *value, void *tool, ConnectDataType ctype) {
00297 TAU_PROFILE("VizTool::connect()", "void (void *, char *, void *, ConnectDataType)",
00298 TAU_VIZ);
00299
00300
00301 VizRecord *viz_record;
00302
00303 viz_record = new VizRecord();
00304
00305 if (ctype == FieldDataType) {
00306 viz_record->tool = (ReadFieldTool *)tool;
00307 viz_record->tooltype = ReadField;
00308 } else {
00309 viz_record->tool = (ReadParticleTool *)tool;
00310
00311
00312 viz_record->tooltype = ReadParticle;
00313 }
00314 viz_record->caller = caller;
00315 strcpy(viz_record->name, value);
00316 viz_record->id = GetUniqueToolId(viz_record->tooltype);
00317 viz_db->AddItem(viz_record);
00318 mainWindow->AddDataItem(value);
00319 }
00320
00321 void VizTool::disconnect(void *caller) {
00322 TAU_PROFILE("VizTool::disconnect()", "void (void *)", TAU_VIZ);
00323
00324 VizRecord *find, *data;
00325
00326 find = new VizRecord();
00327 find->caller = caller;
00328 data = viz_db->FindItem(find);
00329 viz_db->RemoveItem(data);
00330 mainWindow->DeleteDataItem(data->name);
00331 delete find;
00332 }
00333
00334 void
00335 VizTool::update(void *caller) {
00336 TAU_PROFILE("VizTool::update()", "void (void *)", TAU_VIZ);
00337
00338 VizRecord *find, *data;
00339
00340 find = new VizRecord();
00341 find->caller = caller;
00342 data = viz_db->FindItem(find);
00343 delete find;
00344
00345
00346
00347 if (data->tooltype == ReadField) {
00348 ReadFieldTool *readFieldTool;
00349
00350 readFieldTool = (ReadFieldTool *)data->tool;
00351 readFieldTool->Update();
00352 } else {
00353 ReadParticleTool *readParticleTool;
00354
00355 readParticleTool = (ReadParticleTool *)data->tool;
00356 readParticleTool->Update();
00357 }
00358 mainWindow->UpdateTools(caller);
00359
00360 }
00361
00362
00363 void VizTool::SetImageFileBase(const char *nm) {
00364 if (image_file_base != 0)
00365 delete [] image_file_base;
00366 if (nm == 0) {
00367 image_file_base = 0;
00368 } else {
00369 image_file_base = new char[strlen(nm) + 1];
00370 strcpy(image_file_base, nm);
00371 }
00372 }
00373
00374
00375 void VizTool::SetImageFileExt(const char *nm) {
00376 if (image_file_ext != 0)
00377 delete [] image_file_ext;
00378 if (nm == 0) {
00379 image_file_ext = 0;
00380 } else {
00381 image_file_ext = new char[strlen(nm) + 1];
00382 strcpy(image_file_ext, nm);
00383 }
00384 }
00385
00386
00387 void VizTool::SetImageNextNum(unsigned int n) { image_next_num = n; }
00388
00389
00390 bool VizTool::GetImageName(char *namebuf) {
00391
00392 if (image_file_base == 0)
00393 return false;
00394
00395
00396 strcpy(namebuf, image_file_base);
00397 return true;
00398 }
00399
00400
00401
00402
00403
00404
00405