00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <ctype.h>
00024 #include <tcl.h>
00025
00026 #if defined(ARCH_AIX4)
00027 #include <strings.h>
00028 #endif
00029
00030 #include "config.h"
00031 #include "DisplayDevice.h"
00032 #include "Axes.h"
00033 #include "CommandQueue.h"
00034 #include "MoleculeList.h"
00035 #include "VMDApp.h"
00036 #include "Stage.h"
00037 #include "TclCommands.h"
00038 #include "Scene.h"
00039
00040
00041
00042
00043
00044
00045
00046
00050
00051
00052 #define TCL_RET(fmt, val) \
00053 sprintf(s, fmt, val); \
00054 Tcl_AppendElement(interp, s); \
00055 return TCL_OK
00056
00057 int text_cmd_display(ClientData cd, Tcl_Interp *interp, int argc,
00058 const char *argv[]) {
00059 VMDApp *app = (VMDApp *)cd;
00060
00061
00062 if (argc <= 1) {
00063 Tcl_SetResult(interp,
00064 (char *)
00065 "display get <eyesep | focallength | height | distance | antialias |\n"
00066 " depthcue | culling | size | stereo | stereomodes |\n"
00067 " cachemode | cachemodes | rendermode | rendermodes |\n"
00068 " projection | projections | nearclip | farclip |\n"
00069 " cuestart | cueend | cuedensity | cuemode |\n"
00070 " backgroundgradient>\n"
00071 "display <reshape | resetview>\n"
00072 "display <eyesep | focallength | height | distance | antialias |\n"
00073 " depthcue | culling | cachemode | rendermode | stereo |\n"
00074 " backgroundgradient> newvalue\n"
00075 "display <nearclip | farclip> <set | add> newvalue\n"
00076 "display <cuestart | cueend | cuedensity | cuemode> newvalue\n"
00077 "display fps [on | off ]\n"
00078 "display update [on | off | status | ui]",
00079 TCL_STATIC);
00080 return TCL_ERROR;
00081 }
00082
00083
00084 if (argc == 3 && !strupncmp(argv[1], "get", CMDLEN)) {
00085 char s[128];
00086 if (!strupncmp(argv[2], "eyesep", CMDLEN)) {
00087 TCL_RET("%f", app->display->eyesep());
00088 #if 1
00089
00090
00091
00092
00093
00094 } else if (!strupncmp(argv[2], "eyepos", CMDLEN)) {
00095 float pos[3];
00096 app->display->get_eye_pos(&pos[0]);
00097 for (int i=0; i<3; i++) {
00098 sprintf(s, "%f", pos[i]);
00099 Tcl_AppendElement(interp, s);
00100 }
00101 return TCL_OK;
00102 } else if (!strupncmp(argv[2], "eyedir", CMDLEN)) {
00103 float dir[3];
00104 app->display->get_eye_dir(&dir[0]);
00105 for (int i=0; i<3; i++) {
00106 sprintf(s, "%f", dir[i]);
00107 Tcl_AppendElement(interp, s);
00108 }
00109 return TCL_OK;
00110 } else if (!strupncmp(argv[2], "eyeup", CMDLEN)) {
00111 float up[3];
00112 app->display->get_eye_up(&up[0]);
00113 for (int i=0; i<3; i++) {
00114 sprintf(s, "%f", up[i]);
00115 Tcl_AppendElement(interp, s);
00116 }
00117 return TCL_OK;
00118 #endif
00119 } else if (!strupncmp(argv[2], "focallength", CMDLEN)) {
00120 TCL_RET("%f", app->display->eye_dist());
00121 } else if (!strupncmp(argv[2], "height", CMDLEN)) {
00122 TCL_RET("%f", app->display->screen_height());
00123 } else if (!strupncmp(argv[2], "distance", CMDLEN)) {
00124 TCL_RET("%f", app->display->distance_to_screen());
00125 } else if (!strupncmp(argv[2], "antialias", CMDLEN)) {
00126 Tcl_AppendElement(interp,
00127 app->display->aa_enabled() ? "on" : "off");
00128 return TCL_OK;
00129 } else if (!strupncmp(argv[2], "depthcue", CMDLEN)) {
00130 Tcl_AppendElement(interp,
00131 app->display->cueing_enabled() ? "on" : "off");
00132 return TCL_OK;
00133 } else if (!strupncmp(argv[2], "backgroundgradient", CMDLEN)) {
00134 Tcl_AppendElement(interp,
00135 app->scene->background_mode() ? "on" : "off");
00136 return TCL_OK;
00137 } else if (!strupncmp(argv[2], "culling", CMDLEN)) {
00138 Tcl_AppendElement(interp,
00139 app->display->culling_enabled() ? "on" : "off");
00140 return TCL_OK;
00141 } else if (!strupncmp(argv[2], "size", CMDLEN)) {
00142 int w, h;
00143 app->display_get_size(&w, &h);
00144 sprintf(s, "%d", w);
00145 Tcl_AppendElement(interp, s);
00146 sprintf(s, "%d", h);
00147 Tcl_AppendElement(interp, s);
00148 return TCL_OK;
00149 } else if (!strupncmp(argv[2], "stereo", CMDLEN)) {
00150 Tcl_AppendElement(interp,
00151 app->display->stereo_name(app->display->stereo_mode()));
00152 return TCL_OK;
00153 } else if (!strupncmp(argv[2], "stereomodes", CMDLEN)) {
00154 int i;
00155 for (i=0; i<app->display->num_stereo_modes(); i++) {
00156 Tcl_AppendElement(interp, app->display->stereo_name(i));
00157 }
00158 return TCL_OK;
00159 } else if (!strupncmp(argv[2], "cachemode", CMDLEN)) {
00160 Tcl_AppendElement(interp,
00161 app->display->cache_name(app->display->cache_mode()));
00162 return TCL_OK;
00163 } else if (!strupncmp(argv[2], "cachemodes", CMDLEN)) {
00164 int i;
00165 for (i=0; i<app->display->num_cache_modes(); i++) {
00166 Tcl_AppendElement(interp, app->display->cache_name(i));
00167 }
00168 return TCL_OK;
00169 } else if (!strupncmp(argv[2], "rendermode", CMDLEN)) {
00170 Tcl_AppendElement(interp,
00171 app->display->render_name(app->display->render_mode()));
00172 return TCL_OK;
00173 } else if (!strupncmp(argv[2], "rendermodes", CMDLEN)) {
00174 int i;
00175 for (i=0; i<app->display->num_render_modes(); i++) {
00176 Tcl_AppendElement(interp, app->display->render_name(i));
00177 }
00178 return TCL_OK;
00179 } else if (!strupncmp(argv[2], "projection", CMDLEN)) {
00180 Tcl_AppendResult(interp, app->display->get_projection(), NULL);
00181 return TCL_OK;
00182 } else if (!strupncmp(argv[2], "projections", CMDLEN)) {
00183 for (int i=0; i<app->display->num_projections(); i++)
00184 Tcl_AppendElement(interp, app->display->projection_name(i));
00185 return TCL_OK;
00186 } else if (!strupncmp(argv[2], "nearclip", CMDLEN)) {
00187 TCL_RET("%f", app->display->near_clip());
00188 } else if (!strupncmp(argv[2], "farclip", CMDLEN)) {
00189 TCL_RET("%f", app->display->far_clip());
00190 } else if (!strupncmp(argv[2], "cuestart", CMDLEN)) {
00191 TCL_RET("%f", app->display->get_cue_start());
00192 } else if (!strupncmp(argv[2], "cueend", CMDLEN)) {
00193 TCL_RET("%f", app->display->get_cue_end());
00194 } else if (!strupncmp(argv[2], "cuedensity", CMDLEN)) {
00195 TCL_RET("%f", app->display->get_cue_density());
00196 } else if (!strupncmp(argv[2], "cuemode", CMDLEN)) {
00197 Tcl_AppendResult(interp, app->display->get_cue_mode(), NULL);
00198 return TCL_OK;
00199 } else {
00200 Tcl_SetResult(interp,
00201 (char *)
00202 "possible parameters to 'display get' are:\n"
00203 "eyesep focallength height distance antialias depthcue culling\n"
00204 "stereo stereomodes nearclip farclip\n"
00205 "cuestart cueend cuedensity cuemode\n",
00206 TCL_STATIC);
00207 return TCL_ERROR;
00208 }
00210 }
00211
00212 if(argc == 2) {
00213 if(!strupncmp(argv[1],"resetview",CMDLEN)) {
00214 app->scene_resetview();
00215 return TCL_OK;
00216 } else if(!strupncmp(argv[1],"update",CMDLEN)) {
00217 app->display_update();
00218 return TCL_OK;
00219 } else
00220 return TCL_ERROR;
00221
00222 } else if(argc == 3) {
00223 if (!strupncmp(argv[1], "fps", CMDLEN)) {
00224 int on;
00225 if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK) return TCL_ERROR;
00226 app->display_set_fps(on);
00227 #if 1
00228
00229
00230
00231
00232
00233 } else if (!strupncmp(argv[1], "eyepos", CMDLEN)) {
00234 float pos[3];
00235 if (tcl_get_vector(argv[2], &pos[0], interp) != TCL_OK) {
00236 return TCL_ERROR;
00237 }
00238 app->display->set_eye_pos(&pos[0]);
00239 return TCL_OK;
00240 } else if (!strupncmp(argv[1], "eyedir", CMDLEN)) {
00241 float dir[3];
00242 if (tcl_get_vector(argv[2], &dir[0], interp) != TCL_OK) {
00243 return TCL_ERROR;
00244 }
00245 app->display->set_eye_dir(&dir[0]);
00246 return TCL_OK;
00247 } else if (!strupncmp(argv[1], "eyeup", CMDLEN)) {
00248 float up[3];
00249 if (tcl_get_vector(argv[2], &up[0], interp) != TCL_OK) {
00250 return TCL_ERROR;
00251 }
00252 app->display->set_eye_up(&up[0]);
00253 return TCL_OK;
00254 #endif
00255 } else if(!strupncmp(argv[1],"eyesep",CMDLEN)) {
00256 app->display_set_eyesep((float)atof(argv[2]));
00257 } else if(!strupncmp(argv[1],"focallength",CMDLEN)) {
00258 app->display_set_focallen((float)atof(argv[2]));
00259 } else if(!strupncmp(argv[1],"height",CMDLEN)) {
00260 app->display_set_screen_height((float) atof(argv[2]));
00261 } else if(!strupncmp(argv[1],"distance",CMDLEN)) {
00262 app->display_set_screen_distance((float) atof(argv[2]));
00263 } else if(!strupncmp(argv[1],"antialias",CMDLEN)) {
00264 int onoff=0;
00265 if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00266 app->display_set_aa(onoff);
00267 } else if(!strupncmp(argv[1],"depthcue",CMDLEN)) {
00268 int onoff=0;
00269 if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00270 app->display_set_depthcue(onoff);
00271 } else if(!strupncmp(argv[1],"backgroundgradient",CMDLEN)) {
00272 int onoff=0;
00273 if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00274 app->display_set_background_mode(onoff);
00275 } else if(!strupncmp(argv[1],"culling",CMDLEN)) {
00276 int onoff=0;
00277 if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00278 app->display_set_culling(onoff);
00279 } else if(!strupncmp(argv[1],"stereo",CMDLEN)) {
00280 app->display_set_stereo(argv[2]);
00281 } else if(!strupncmp(argv[1],"cachemode",CMDLEN)) {
00282 app->display_set_cachemode(argv[2]);
00283 } else if(!strupncmp(argv[1],"rendermode",CMDLEN)) {
00284 app->display_set_rendermode(argv[2]);
00285 } else if (!strupncmp(argv[1], "projection", CMDLEN) ||
00286 !strupncmp(argv[1], "proj", CMDLEN)) {
00287 if (!app->display_set_projection(argv[2])) {
00288 Tcl_AppendResult(interp, "Invalid projection: ", argv[2], NULL);
00289 return TCL_ERROR;
00290 }
00291 } else if(!strupncmp(argv[1],"update",CMDLEN)) {
00292 int booltmp;
00293 if (!strcmp(argv[2], "status")) {
00294 char s[20];
00295 TCL_RET("%d", app->display_update_status());
00296 } else if (!strcmp(argv[2], "ui")) {
00297 app->display_update_ui();
00298 return TCL_OK;
00299 } else if (Tcl_GetBoolean(interp, argv[2], &booltmp) == TCL_OK) {
00300 app->display_update_on(booltmp);
00301 return TCL_OK;
00302 } else {
00303 return TCL_ERROR;
00304 }
00305 } else if(!strupncmp(argv[1],"cuemode",CMDLEN)) {
00306 if (!app->depthcue_set_mode(argv[2])) {
00307 Tcl_AppendResult(interp, "Illegal cuemode: ", argv[2], NULL);
00308 return TCL_ERROR;
00309 }
00310 } else if(!strupncmp(argv[1],"cuestart",CMDLEN)) {
00311 double val=0;
00312 if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00313 app->depthcue_set_start((float)val);
00314 } else if(!strupncmp(argv[1],"cueend",CMDLEN)) {
00315 double val=0;
00316 if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00317 app->depthcue_set_end((float)val);
00318 } else if(!strupncmp(argv[1],"cuedensity",CMDLEN)) {
00319 double val=0;
00320 if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00321 app->depthcue_set_density((float)val);
00322 } else
00323 return TCL_ERROR;
00324
00325 } else if(argc == 4) {
00326 if(!strupncmp(argv[1],"nearclip",CMDLEN)) {
00327 int isdelta = -1;
00328 if(!strupncmp(argv[2],"set",CMDLEN))
00329 isdelta = 0;
00330 else if(!strupncmp(argv[2],"add",CMDLEN))
00331 isdelta = 1;
00332 if (isdelta < 0) return TCL_ERROR;
00333 app->display_set_nearclip((float)atof(argv[3]), isdelta);
00334 } else if(!strupncmp(argv[1],"farclip",CMDLEN)) {
00335 int isdelta = -1;
00336 if(!strupncmp(argv[2],"set",CMDLEN))
00337 isdelta = 0;
00338 else if(!strupncmp(argv[2],"add",CMDLEN))
00339 isdelta = 1;
00340 if (isdelta < 0) return TCL_ERROR;
00341 app->display_set_farclip((float)atof(argv[3]), isdelta);
00342
00343 } else if (!strupncmp(argv[1], "resize", CMDLEN)) {
00344 int w, h;
00345 if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK ||
00346 Tcl_GetInt(interp, argv[3], &h) != TCL_OK)
00347 return TCL_ERROR;
00348 app->display_set_size(w, h);
00349
00350 } else if (!strupncmp(argv[1], "reposition", CMDLEN)) {
00351 int x, y;
00352 if (Tcl_GetInt(interp, argv[2], &x) != TCL_OK ||
00353 Tcl_GetInt(interp, argv[3], &y) != TCL_OK)
00354 return TCL_ERROR;
00355 app->display_set_position(x, y);
00356 } else
00357 return TCL_ERROR;
00358 } else
00359 return TCL_ERROR;
00360
00361
00362 return TCL_OK;
00363 }
00364
00365
00366 int text_cmd_light(ClientData cd, Tcl_Interp *interp, int argc,
00367 const char *argv[]) {
00368
00369 VMDApp *app = (VMDApp *)cd;
00370 Scene *scene = app->scene;
00371
00372 if (argc <= 1) {
00373 Tcl_SetResult(interp,
00374 (char *)
00375 "light <number> [on|off|highlight|unhighlight|status]\n"
00376 "light <number> rot <axis> <deg>\n"
00377 "light <number> pos\n"
00378 "light <number> pos [{x y z} | default]\n"
00379 "light num\n",
00380 TCL_STATIC);
00381 return TCL_ERROR;
00382 }
00383 if ((argc == 3 || argc == 4) && !strupncmp(argv[2], "pos", CMDLEN)) {
00384 int num = atoi(argv[1]);
00385 if (argc == 4) {
00386 float pos[3];
00387 if (!strupncmp(argv[3], "default", 8)) {
00388 const float *def = scene->light_pos_default(num);
00389 if (!def) return TCL_ERROR;
00390 for (int i=0; i<3; i++) {
00391 char buf[20];
00392 sprintf(buf, "%f", def[i]);
00393 Tcl_AppendElement(interp, buf);
00394 }
00395 return TCL_OK;
00396
00397 } else if (tcl_get_vector(argv[3], pos, interp) != TCL_OK) {
00398 return TCL_ERROR;
00399 }
00400 app->light_move(num, pos);
00401 return TCL_OK;
00402 } else {
00403 const float *pos = scene->light_pos(num);
00404 if (!pos) return TCL_ERROR;
00405 for (int i=0; i<3; i++) {
00406 char buf[20];
00407 sprintf(buf, "%f", pos[i]);
00408 Tcl_AppendElement(interp, buf);
00409 }
00410 return TCL_OK;
00411 }
00412 }
00413 if (argc == 2 && !strupncmp(argv[1], "num", CMDLEN)) {
00414
00415 char tmpstring[64];
00416 sprintf(tmpstring, "%d", DISP_LIGHTS);
00417 Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00418 return TCL_OK;
00419 }
00420 int n;
00421 if (Tcl_GetInt(interp, argv[1], &n) != TCL_OK) {
00422 Tcl_AppendResult(interp, " -- light <number> ...", NULL);
00423 return TCL_ERROR;
00424 }
00425 if(argc == 3) {
00426 if(!strupncmp(argv[2],"on",CMDLEN))
00427 app->light_on(n, 1);
00428 else if(!strupncmp(argv[2],"off",CMDLEN))
00429 app->light_on(n, 0);
00430 else if(!strupncmp(argv[2],"highlight",CMDLEN))
00431 app->light_highlight(n, 1);
00432 else if(!strupncmp(argv[2],"unhighlight",CMDLEN))
00433 app->light_highlight(n, 0);
00434 else if(!strupncmp(argv[2],"status",CMDLEN)) {
00435 char tmpstring[1024];
00436
00437
00438 if (n < 0 || n >= DISP_LIGHTS) {
00439 sprintf(tmpstring, "light value %d out of range", n);
00440 Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00441 return TCL_ERROR;
00442 }
00443 sprintf(tmpstring, "%s %s",
00444 app->scene->light_active(n) ? "on" : "off",
00445 app->scene->light_highlighted(n) ?
00446 "highlight" : "unhighlight");
00447 Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00448 return TCL_OK;
00449 } else
00450 return TCL_ERROR;
00451
00452 } else if(argc == 5 && !strupncmp(argv[2],"rot",CMDLEN)) {
00453 char axis = (char)(tolower(argv[3][0]));
00454 float deg = (float) atof(argv[4]);
00455 app->light_rotate(n, deg, axis);
00456
00457 } else
00458 return TCL_ERROR;
00459
00460
00461 return TCL_OK;
00462 }
00463
00464
00465 int text_cmd_axes(ClientData cd, Tcl_Interp *interp, int argc,
00466 const char *argv[]) {
00467
00468 VMDApp *app = (VMDApp *)cd;
00469
00470 if (app->axes && argc == 2) {
00471 if(!strupncmp(argv[1],"location",CMDLEN)) {
00472
00473 Tcl_SetResult(interp, app->axes->loc_description(app->axes->location()), TCL_VOLATILE);
00474 return TCL_OK;
00475 } else if(!strupncmp(argv[1],"locations",CMDLEN)) {
00476
00477 for (int ii=0; ii<app->axes->locations(); ii++) {
00478 Tcl_AppendElement(interp, app->axes->loc_description(ii));
00479 }
00480 return TCL_OK;
00481 }
00482
00483 Tcl_AppendResult(interp,
00484 "axes [location|locations]\n",
00485 "axes location [off|origin|lowerleft|lowerright|"
00486 "upperleft|upperright]",
00487 NULL
00488 );
00489 return TCL_ERROR;
00490
00491 }
00492 if(app->axes && argc == 3) {
00493 if(!strupncmp(argv[1],"location",CMDLEN)) {
00494 if (!app->axes_set_location(argv[2])) {
00495 Tcl_AppendResult(interp, "Invalid axes location: ", argv[2], NULL);
00496 return TCL_ERROR;
00497 }
00498 }
00499 } else
00500 return TCL_ERROR;
00501
00502
00503 return TCL_OK;
00504 }
00505
00506
00507 int text_cmd_stage(ClientData cd, Tcl_Interp *interp, int argc,
00508 const char *argv[]) {
00509
00510 VMDApp *app = (VMDApp *)cd;
00511 Stage *stage = app->stage;
00512
00513 if (stage && argc == 2) {
00514 if (!strupncmp(argv[1], "location", CMDLEN)) {
00515 Tcl_AppendElement(interp, stage->loc_description(stage->location()));
00516 return TCL_OK;
00517 } else if (!strupncmp(argv[1], "locations", CMDLEN)) {
00518 int i;
00519 for (i=0; i < stage->locations(); i++) {
00520 Tcl_AppendElement(interp, stage->loc_description(i));
00521 }
00522 return TCL_OK;
00523 } else if (!strupncmp(argv[1], "panels", CMDLEN)) {
00524 char s[20];
00525 sprintf(s, "%d", stage->panels());
00526 Tcl_AppendElement(interp, s);
00527 return TCL_OK;
00528 } else {
00529 Tcl_AppendResult(interp, "possible commands are: location, locations, "
00530 "panels [value]", NULL);
00531 return TCL_ERROR;
00532 }
00533
00534 }
00535 if(stage && argc == 3) {
00536 int i;
00537 if(!strupncmp(argv[1],"location",CMDLEN)) {
00538 if (app->stage_set_location(argv[2])) return TCL_OK;
00539 Tcl_AppendResult(interp, "Possible locations are ", NULL);
00540 for (i=0; i<stage->locations(); i++)
00541 Tcl_AppendElement(interp, stage->loc_description(i));
00542
00543 return TCL_ERROR;
00544 } else if(!strupncmp(argv[1],"panels",CMDLEN)) {
00545 int num=0;
00546 if (Tcl_GetInt(interp, argv[2], &num) != TCL_OK ||
00547 !app->stage_set_numpanels(num))
00548 return TCL_ERROR;
00549
00550 } else
00551 return TCL_ERROR;
00552
00553 } else
00554 return TCL_ERROR;
00555
00556
00557 return TCL_OK;
00558 }