Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cmd_display.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_display.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.79 $       $Date: 2020/07/08 04:20:45 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for controlling the OpenGL display window
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 #include "FPS.h"
00040 
00041 // These are the Command:: enums used by this file:
00042 //  DISP_RESHAPE, DISP_STEREO, DISP_STEREOSWAP, 
00043 //  DISP_PROJ, DISP_EYESEP, DISP_FOCALLEN, 
00044 //  DISP_LIGHT_ON, DISP_LIGHT_HL, DISP_LIGHT_ROT, DISP_MATERIALS_CHANGE,
00045 //  DISP_CLIP, DISP_DEPTHCUE, DISP_ANTIALIAS, DISP_SCRHEIGHT, DISP_SCRDIST,
00046 //  CMD_AXES, CMD_STAGE
00047 
00048 
00052 
00053 // text callback routine for 'display'; return TCL_ERROR if an error occurs.
00054 #define TCL_RET(fmt, val)      \
00055 sprintf(s, fmt, val);          \
00056 Tcl_AppendElement(interp, s);  \
00057 return TCL_OK
00058 
00059 int text_cmd_display(ClientData cd, Tcl_Interp *interp, int argc, 
00060                      const char *argv[]) {
00061   VMDApp *app = (VMDApp *)cd;
00062 
00063   // not much help, but anything is nice
00064   if (argc <= 1) {
00065     Tcl_SetResult(interp,
00066        (char *)
00067        "display get <eyesep | focallength | height | distance | antialias |\n"
00068        "             depthcue | culling | size | \n"
00069        "             stereo | stereomodes | stereoswap |\n"
00070        "             cachemode | cachemodes | rendermode | rendermodes |\n"
00071        "             projection | projections | nearclip | farclip |\n"
00072        "             cuestart | cueend | cuedensity | cuemode |\n" 
00073        "             shadows | ambientocclusion | aoambient | aodirect |\n"
00074        "             dof | dof_fnumber | dof_focaldist | backgroundgradient>\n"
00075        "display <reshape | resetview | resize | reposition>\n"
00076        "display <eyesep | focallength | height | distance | antialias |\n"
00077        "         depthcue | culling | cachemode | rendermode |\n"
00078        "         stereo | stereoswap |\n"
00079        "         shadows | ambientocclusion | aoambient | aodirect |\n"
00080        "         dof | dof_fnumber | dof_focaldist |\n"
00081        "         backgroundgradient> newvalue\n"
00082        "display <nearclip | farclip> <set | add> newvalue\n"
00083        "display <cuestart | cueend | cuedensity | cuemode> newvalue\n"
00084        "display fps [on | off ]\n"
00085        "display update [on | off | status | ui]",
00086        TCL_STATIC);
00087     return TCL_ERROR;
00088   }
00089 
00090   // the new 'get' commands
00091   if (argc == 3 && !strupncmp(argv[1], "get", CMDLEN)) {
00092     char s[128] = { 0 };
00093     if (!strupncmp(argv[2], "eyesep", CMDLEN)) {
00094       TCL_RET("%f", app->display->eyesep());
00095 #if 1
00096     // XXX undocumented eye manipulation commands
00097     // To use these in the model coordinate system, one must set the 
00098     // model to world coordinate system transformation matrices to identity
00099     // matrices.  Future code should automatically transform the provided
00100     // eye position/direction/up etc into the model coordinate system.
00101     } else if (!strupncmp(argv[2], "eyepos", CMDLEN)) {
00102       float pos[3];
00103       app->display->get_eye_pos(&pos[0]);
00104       for (int i=0; i<3; i++) {
00105         sprintf(s, "%f",  pos[i]);
00106         Tcl_AppendElement(interp, s);
00107       }
00108       return TCL_OK;
00109     } else if (!strupncmp(argv[2], "eyedir", CMDLEN)) {
00110       float dir[3];
00111       app->display->get_eye_dir(&dir[0]);
00112       for (int i=0; i<3; i++) {
00113         sprintf(s, "%f",  dir[i]);
00114         Tcl_AppendElement(interp, s);
00115       }
00116       return TCL_OK;
00117     } else if (!strupncmp(argv[2], "eyeup", CMDLEN)) {
00118       float up[3];
00119       app->display->get_eye_up(&up[0]);
00120       for (int i=0; i<3; i++) {
00121         sprintf(s, "%f",  up[i]);
00122         Tcl_AppendElement(interp, s);
00123       }
00124       return TCL_OK;
00125 #endif
00126     } else if (!strupncmp(argv[2], "focallength", CMDLEN)) {
00127       TCL_RET("%f", app->display->eye_dist());
00128     } else if (!strupncmp(argv[2], "height", CMDLEN)) {
00129       TCL_RET("%f", app->display->screen_height());
00130     } else if (!strupncmp(argv[2], "distance", CMDLEN)) {
00131       TCL_RET("%f", app->display->distance_to_screen());
00132 
00133     } else if (!strupncmp(argv[2], "ambientocclusion", CMDLEN)) {
00134       Tcl_AppendElement(interp, 
00135         app->display->ao_enabled() ? "on" : "off");
00136       return TCL_OK;
00137     } else if (!strupncmp(argv[2], "aoambient", CMDLEN)) {
00138       TCL_RET("%f", app->display->get_ao_ambient());
00139     } else if (!strupncmp(argv[2], "aodirect", CMDLEN)) {
00140       TCL_RET("%f", app->display->get_ao_direct());
00141 
00142     } else if (!strupncmp(argv[2], "dof", CMDLEN)) {
00143       Tcl_AppendElement(interp, 
00144         app->display->dof_enabled() ? "on" : "off");
00145       return TCL_OK;
00146     } else if (!strupncmp(argv[2], "dof_fnumber", CMDLEN)) {
00147       TCL_RET("%f", app->display->get_dof_fnumber());
00148     } else if (!strupncmp(argv[2], "dof_focaldist", CMDLEN)) {
00149       TCL_RET("%f", app->display->get_dof_focal_dist());
00150 
00151     } else if (!strupncmp(argv[2], "antialias", CMDLEN)) {
00152       Tcl_AppendElement(interp, 
00153         app->display->aa_enabled() ? "on" : "off");
00154       return TCL_OK;
00155     } else if (!strupncmp(argv[2], "depthcue", CMDLEN)) {
00156       Tcl_AppendElement(interp, 
00157         app->display->cueing_enabled() ? "on" : "off");
00158       return TCL_OK;
00159     } else if (!strupncmp(argv[2], "backgroundgradient", CMDLEN)) {
00160       Tcl_AppendElement(interp, 
00161         app->scene->background_mode() ? "on" : "off");
00162       return TCL_OK;
00163     } else if (!strupncmp(argv[2], "culling", CMDLEN)) {
00164       Tcl_AppendElement(interp, 
00165         app->display->culling_enabled() ? "on" : "off");
00166       return TCL_OK;
00167     } else if (!strupncmp(argv[2], "shadows", CMDLEN)) {
00168       Tcl_AppendElement(interp, 
00169         app->display->shadows_enabled() ? "on" : "off");
00170       return TCL_OK;
00171     } else if (!strupncmp(argv[2], "size", CMDLEN)) {
00172       int w, h;
00173       app->display_get_size(&w, &h);
00174       sprintf(s, "%d", w);
00175       Tcl_AppendElement(interp, s);
00176       sprintf(s, "%d", h);
00177       Tcl_AppendElement(interp, s);
00178       return TCL_OK;
00179     } else if (!strupncmp(argv[2], "fps", CMDLEN)) {
00180       Tcl_AppendElement(interp, app->fps->displayed() ? "on" : "off");
00181       return TCL_OK;
00182     } else if (!strupncmp(argv[2], "stereo", CMDLEN)) {
00183       Tcl_AppendElement(interp, 
00184                         app->display->stereo_name(app->display->stereo_mode()));
00185       return TCL_OK;
00186     } else if (!strupncmp(argv[2], "stereoswap", CMDLEN)) {
00187       Tcl_AppendElement(interp, app->display->stereo_swap() ? "on" : "off");
00188       return TCL_OK;
00189     } else if (!strupncmp(argv[2], "stereomodes", CMDLEN)) {
00190       int i;
00191       for (i=0; i<app->display->num_stereo_modes(); i++) {
00192         Tcl_AppendElement(interp, app->display->stereo_name(i));
00193       }
00194       return TCL_OK;
00195     } else if (!strupncmp(argv[2], "cachemode", CMDLEN)) {
00196       Tcl_AppendElement(interp, 
00197         app->display->cache_name(app->display->cache_mode()));
00198       return TCL_OK;
00199     } else if (!strupncmp(argv[2], "cachemodes", CMDLEN)) {
00200       int i;
00201       for (i=0; i<app->display->num_cache_modes(); i++) {
00202         Tcl_AppendElement(interp, app->display->cache_name(i));
00203       }
00204       return TCL_OK;
00205     } else if (!strupncmp(argv[2], "rendermode", CMDLEN)) {
00206       Tcl_AppendElement(interp, 
00207         app->display->render_name(app->display->render_mode()));
00208       return TCL_OK;
00209     } else if (!strupncmp(argv[2], "rendermodes", CMDLEN)) {
00210       int i;
00211       for (i=0; i<app->display->num_render_modes(); i++) {
00212         Tcl_AppendElement(interp, app->display->render_name(i));
00213       }
00214       return TCL_OK;
00215     } else if (!strupncmp(argv[2], "projection", CMDLEN)) {
00216       Tcl_AppendResult(interp, app->display->get_projection(), NULL);
00217       return TCL_OK;
00218     } else if (!strupncmp(argv[2], "projections", CMDLEN)) {
00219       for (int i=0; i<app->display->num_projections(); i++)
00220         Tcl_AppendElement(interp, app->display->projection_name(i));
00221       return TCL_OK;
00222     } else if (!strupncmp(argv[2], "nearclip", CMDLEN)) {
00223       TCL_RET("%f", app->display->near_clip());
00224     } else if (!strupncmp(argv[2], "farclip", CMDLEN)) {
00225       TCL_RET("%f", app->display->far_clip());
00226     } else if (!strupncmp(argv[2], "cuestart", CMDLEN)) {
00227       TCL_RET("%f", app->display->get_cue_start());
00228     } else if (!strupncmp(argv[2], "cueend", CMDLEN)) {
00229       TCL_RET("%f", app->display->get_cue_end());
00230     } else if (!strupncmp(argv[2], "cuedensity", CMDLEN)) {
00231       TCL_RET("%f", app->display->get_cue_density());
00232     } else if (!strupncmp(argv[2], "cuemode", CMDLEN)) {
00233       Tcl_AppendResult(interp, app->display->get_cue_mode(), NULL);
00234       return TCL_OK;
00235     } else {
00236       Tcl_SetResult(interp,
00237         (char *)
00238         "possible parameters to 'display get' are:\n"
00239         "eyesep focallength height distance antialias depthcue culling\n"
00240         "stereo stereomodes stereoswap nearclip farclip\n" 
00241         "cuestart cueend cuedensity cuemode\n"
00242         "shadows, ambientocclusion, aoambient, aodirect\n",
00243         TCL_STATIC);
00244       return TCL_ERROR;
00245     }
00247   }
00248 
00249   if (argc == 2) {
00250     if(!strupncmp(argv[1],"resetview",CMDLEN)) {
00251       app->scene_resetview();
00252       return TCL_OK;
00253     } else if(!strupncmp(argv[1],"update",CMDLEN)) {
00254       app->display_update();
00255       return TCL_OK;
00256     } else
00257       return TCL_ERROR;
00258 
00259   } else if (argc == 3) {
00260     if (!strupncmp(argv[1], "fps", CMDLEN)) {
00261       int on;
00262       if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK) return TCL_ERROR;
00263       app->display_set_fps(on);
00264 #if 1
00265     // XXX undocumented eye manipulation commands
00266     // To use these in the model coordinate system, one must set the 
00267     // model to world coordinate system transformation matrices to identity
00268     // matrices.  Future code should automatically transform the provided
00269     // eye position/direction/up etc into the model coordinate system.
00270     } else if (!strupncmp(argv[1], "eyepos", CMDLEN)) {
00271       float pos[3];
00272       if (tcl_get_vector(argv[2], &pos[0],  interp) != TCL_OK) {
00273         return TCL_ERROR;
00274       }
00275       app->display->set_eye_pos(&pos[0]);
00276       return TCL_OK;
00277     } else if (!strupncmp(argv[1], "eyedir", CMDLEN)) {
00278       float dir[3];
00279       if (tcl_get_vector(argv[2], &dir[0],  interp) != TCL_OK) {
00280         return TCL_ERROR;
00281       }
00282       app->display->set_eye_dir(&dir[0]);
00283       return TCL_OK;
00284     } else if (!strupncmp(argv[1], "eyeup", CMDLEN)) {
00285       float up[3];
00286       if (tcl_get_vector(argv[2], &up[0],  interp) != TCL_OK) {
00287         return TCL_ERROR;
00288       }
00289       app->display->set_eye_up(&up[0]);
00290       return TCL_OK;
00291 #endif
00292     } else if(!strupncmp(argv[1],"eyesep",CMDLEN)) {
00293       app->display_set_eyesep((float)atof(argv[2]));
00294     } else if(!strupncmp(argv[1],"focallength",CMDLEN)) {
00295       app->display_set_focallen((float)atof(argv[2]));
00296     } else if(!strupncmp(argv[1],"height",CMDLEN)) {
00297       app->display_set_screen_height((float) atof(argv[2]));
00298     } else if(!strupncmp(argv[1],"distance",CMDLEN)) {
00299       app->display_set_screen_distance((float) atof(argv[2]));
00300 
00301     } else if(!strupncmp(argv[1],"ambientocclusion",CMDLEN)) {
00302       int onoff=0;
00303       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00304       app->display_set_ao(onoff);
00305     } else if(!strupncmp(argv[1],"aoambient",CMDLEN)) {
00306       double val=0;
00307       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00308       app->display_set_ao_ambient((float)val);
00309     } else if(!strupncmp(argv[1],"aodirect",CMDLEN)) {
00310       double val=0;
00311       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00312       app->display_set_ao_direct((float)val);
00313 
00314     } else if(!strupncmp(argv[1],"dof",CMDLEN)) {
00315       int onoff=0;
00316       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00317       app->display_set_dof(onoff);
00318     } else if(!strupncmp(argv[1],"dof_fnumber",CMDLEN)) {
00319       double val=0;
00320       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00321       app->display_set_dof_fnumber((float)val);
00322     } else if(!strupncmp(argv[1],"dof_focaldist",CMDLEN)) {
00323       double val=0;
00324       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00325       app->display_set_dof_focal_dist((float)val);
00326 
00327     } else if(!strupncmp(argv[1],"antialias",CMDLEN)) {
00328       int onoff=0;
00329       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00330       app->display_set_aa(onoff);
00331     } else if(!strupncmp(argv[1],"depthcue",CMDLEN)) {
00332       int onoff=0;
00333       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00334       app->display_set_depthcue(onoff);
00335     } else if(!strupncmp(argv[1],"backgroundgradient",CMDLEN)) {
00336       int onoff=0;
00337       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00338       app->display_set_background_mode(onoff);
00339     } else if(!strupncmp(argv[1],"culling",CMDLEN)) {
00340       int onoff=0;
00341       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00342       app->display_set_culling(onoff);
00343     } else if(!strupncmp(argv[1],"shadows",CMDLEN)) {
00344       int onoff=0;
00345       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00346       app->display_set_shadows(onoff);
00347     } else if(!strupncmp(argv[1],"stereo",CMDLEN)) {
00348       app->display_set_stereo(argv[2]);
00349     } else if(!strupncmp(argv[1],"stereoswap",CMDLEN)) {
00350       int onoff=0;
00351       if (Tcl_GetBoolean(interp, argv[2], &onoff) != TCL_OK) return TCL_ERROR;
00352       app->display_set_stereo_swap(onoff);
00353     } else if(!strupncmp(argv[1],"cachemode",CMDLEN)) {
00354       app->display_set_cachemode(argv[2]);
00355     } else if(!strupncmp(argv[1],"rendermode",CMDLEN)) {
00356       app->display_set_rendermode(argv[2]);
00357     } else if (!strupncmp(argv[1], "projection", CMDLEN) ||
00358                !strupncmp(argv[1], "proj", CMDLEN)) {
00359       if (!app->display_set_projection(argv[2])) {
00360         Tcl_AppendResult(interp, "Invalid projection: ", argv[2], NULL);
00361         return TCL_ERROR;
00362       }
00363     } else if(!strupncmp(argv[1],"update",CMDLEN)) {
00364       int booltmp;
00365       if (!strcmp(argv[2], "status")) {
00366         char s[20];
00367         TCL_RET("%d", app->display_update_status());
00368       } else if (!strcmp(argv[2], "ui")) {
00369         app->display_update_ui();
00370         return TCL_OK;
00371       } else if (Tcl_GetBoolean(interp, argv[2], &booltmp) == TCL_OK) {
00372         app->display_update_on(booltmp); 
00373         return TCL_OK;
00374       } else {
00375         return TCL_ERROR;
00376       }
00377     } else if(!strupncmp(argv[1],"cuemode",CMDLEN)) {
00378       if (!app->depthcue_set_mode(argv[2])) {
00379         Tcl_AppendResult(interp, "Illegal cuemode: ", argv[2], NULL);
00380         return TCL_ERROR;
00381       }
00382     } else if(!strupncmp(argv[1],"cuestart",CMDLEN)) {
00383       double val=0;
00384       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00385       app->depthcue_set_start((float)val);
00386     } else if(!strupncmp(argv[1],"cueend",CMDLEN)) {
00387       double val=0;
00388       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00389       app->depthcue_set_end((float)val);
00390     } else if(!strupncmp(argv[1],"cuedensity",CMDLEN)) {
00391       double val=0;
00392       if (Tcl_GetDouble(interp, argv[2], &val) != TCL_OK) return TCL_ERROR;
00393       app->depthcue_set_density((float)val);
00394     } else
00395       return TCL_ERROR;
00396 
00397   } else if(argc == 4) {
00398     if(!strupncmp(argv[1],"nearclip",CMDLEN)) {
00399       int isdelta = -1;
00400       if(!strupncmp(argv[2],"set",CMDLEN))
00401         isdelta = 0;
00402       else if(!strupncmp(argv[2],"add",CMDLEN))
00403         isdelta = 1;
00404       if (isdelta < 0) return TCL_ERROR;
00405       app->display_set_nearclip((float)atof(argv[3]), isdelta);
00406     } else if(!strupncmp(argv[1],"farclip",CMDLEN)) {
00407       int isdelta = -1;
00408       if(!strupncmp(argv[2],"set",CMDLEN))
00409         isdelta = 0;
00410       else if(!strupncmp(argv[2],"add",CMDLEN))
00411         isdelta = 1;
00412       if (isdelta < 0) return TCL_ERROR;
00413       app->display_set_farclip((float)atof(argv[3]), isdelta);
00414     } else if (!strupncmp(argv[1], "resize", CMDLEN)) {
00415       int w, h;
00416       if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK ||
00417           Tcl_GetInt(interp, argv[3], &h) != TCL_OK)
00418         return TCL_ERROR;
00419       app->display_set_size(w, h);
00420     } else if (!strupncmp(argv[1], "reposition", CMDLEN)) {
00421       int x, y;
00422       if (Tcl_GetInt(interp, argv[2], &x) != TCL_OK ||
00423           Tcl_GetInt(interp, argv[3], &y) != TCL_OK)
00424         return TCL_ERROR;
00425       app->display_set_position(x, y);
00426     } else
00427       return TCL_ERROR;
00428   } else
00429     return TCL_ERROR;
00430 
00431   // if here, completed successfully
00432   return TCL_OK;
00433 }
00434 
00435 
00436 int text_cmd_light(ClientData cd, Tcl_Interp *interp, int argc, 
00437                    const char *argv[]) {
00438   VMDApp *app = (VMDApp *)cd;
00439   Scene *scene = app->scene;
00440 
00441   if (argc <= 1) {
00442     Tcl_SetResult(interp, 
00443       (char *) 
00444       "light <number> [on|off|highlight|unhighlight|status]\n"
00445       "light <number> rot <axis> <deg>\n"
00446       "light <number> pos\n"
00447       "light <number> pos [{x y z} | default]\n"
00448       "light num\n", 
00449       TCL_STATIC);
00450     return TCL_ERROR;
00451   }
00452 
00453   if ((argc == 3 || argc == 4) && !strupncmp(argv[2], "pos", CMDLEN)) {
00454     int num = atoi(argv[1]);
00455     if (argc == 4) {
00456       float pos[3];
00457       if (!strupncmp(argv[3], "default", 8)) {
00458         const float *def = scene->light_pos_default(num);
00459         if (!def) return TCL_ERROR;
00460         for (int i=0; i<3; i++) {
00461           char buf[20];
00462           sprintf(buf, "%f", def[i]);
00463           Tcl_AppendElement(interp, buf);
00464         }
00465         return TCL_OK;
00466         
00467       } else if (tcl_get_vector(argv[3], pos, interp) != TCL_OK) {
00468         return TCL_ERROR;
00469       }
00470       app->light_move(num, pos);
00471       return TCL_OK;
00472     } else {
00473       const float *pos = scene->light_pos(num);
00474       if (!pos) return TCL_ERROR;
00475       for (int i=0; i<3; i++) {
00476         char buf[20];
00477         sprintf(buf, "%f", pos[i]);
00478         Tcl_AppendElement(interp, buf);
00479       }
00480       return TCL_OK;
00481     }
00482   }  
00483 
00484   if (argc == 2 && !strupncmp(argv[1], "num", CMDLEN)) {
00485     // return the number of lights
00486     char tmpstring[64];
00487     sprintf(tmpstring, "%d", DISP_LIGHTS);
00488     Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00489     return TCL_OK;
00490   }
00491   int n;
00492   if (Tcl_GetInt(interp, argv[1], &n) != TCL_OK) {
00493     Tcl_AppendResult(interp, " -- light <number> ...", NULL);
00494     return TCL_ERROR;
00495   }
00496 
00497   if (argc == 3) {
00498     if(!strupncmp(argv[2],"on",CMDLEN))
00499       app->light_on(n, 1);
00500     else if(!strupncmp(argv[2],"off",CMDLEN))
00501       app->light_on(n, 0);
00502     else if(!strupncmp(argv[2],"highlight",CMDLEN))
00503       app->light_highlight(n, 1);
00504     else if(!strupncmp(argv[2],"unhighlight",CMDLEN))
00505       app->light_highlight(n, 0);
00506     else if(!strupncmp(argv[2],"status",CMDLEN)) {
00507       char tmpstring[1024];
00508 
00509       // return the pair { is on , is highlight} as eg: {on unhighlight}
00510       if (n < 0 || n >= DISP_LIGHTS) {
00511         sprintf(tmpstring, "light value %d out of range", n);
00512         Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00513         return TCL_ERROR;
00514       }
00515       sprintf(tmpstring, "%s %s", 
00516         app->scene->light_active(n) ? "on" : "off",
00517         app->scene->light_highlighted(n) ?  "highlight" : "unhighlight");
00518       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00519       return TCL_OK;
00520     } else {
00521       return TCL_ERROR;
00522     }
00523   } else if(argc == 5 && !strupncmp(argv[2],"rot",CMDLEN)) {
00524     char axis = (char)(tolower(argv[3][0]));
00525     float deg = (float) atof(argv[4]);
00526     app->light_rotate(n, deg, axis);
00527 
00528   } else {
00529     return TCL_ERROR;
00530   }
00531 
00532   // if here, completed successfully
00533   return TCL_OK;
00534 }
00535 
00536 
00537 int text_cmd_point_light(ClientData cd, Tcl_Interp *interp, int argc, 
00538                          const char *argv[]) {
00539   VMDApp *app = (VMDApp *)cd;
00540   Scene *scene = app->scene;
00541 
00542   if (argc <= 1) {
00543     Tcl_SetResult(interp, 
00544       (char *) 
00545       "pointlight <number> [on|off|highlight|unhighlight|status]\n"
00546 //      "pointlight <number> rot <axis> <deg>\n"
00547       "pointlight <number> pos\n"
00548       "pointlight <number> pos [{x y z} | default]\n"
00549       "pointlight <number> attenuation [{constant linear quadratic} | default]\n"
00550       "pointlight num\n", 
00551       TCL_STATIC);
00552     return TCL_ERROR;
00553   }
00554     if ((argc == 3 || argc == 4) && !strupncmp(argv[2], "pos", CMDLEN)) {
00555       int num = atoi(argv[1]);
00556       if (argc == 4) {
00557         float pos[3];
00558         if (!strupncmp(argv[3], "default", 8)) {
00559           const float *def = scene->adv_light_pos_default(num);
00560           if (!def) return TCL_ERROR;
00561           for (int i=0; i<3; i++) {
00562             char buf[20];
00563             sprintf(buf, "%f", def[i]);
00564             Tcl_AppendElement(interp, buf);
00565           }
00566           return TCL_OK;
00567           
00568         } else if (tcl_get_vector(argv[3], pos, interp) != TCL_OK) {
00569           return TCL_ERROR;
00570         }
00571 // XXX hack
00572 #if 1
00573         // XXX need to save the active coordinate transform so the 
00574         //     user's local model coordinates can be used here.
00575         scene->move_adv_light(num, pos);
00576 #else
00577 //        app->light_move(num, pos);
00578         scene->move_adv_light(num, pos);
00579 #endif
00580         return TCL_OK;
00581       } else {
00582         const float *pos = scene->adv_light_pos(num);
00583         if (!pos) return TCL_ERROR;
00584         for (int i=0; i<3; i++) {
00585           char buf[20];
00586           sprintf(buf, "%f", pos[i]);
00587           Tcl_AppendElement(interp, buf);
00588         }
00589         return TCL_OK;
00590       }
00591     }  
00592 
00593     if ((argc == 3 || argc == 4) && !strupncmp(argv[2], "attenuation", CMDLEN)) {
00594       int num = atoi(argv[1]);
00595       if (argc == 4) {
00596         float factors[3] = { 1.0f, 0.0f, 0.0f };
00597         if (!strupncmp(argv[3], "default", 8)) {
00598           scene->adv_light_attenuation(num, factors[0], factors[1], factors[2]);
00599           return TCL_OK;
00600           
00601         } else if (tcl_get_vector(argv[3], factors, interp) != TCL_OK) {
00602           return TCL_ERROR;
00603         }
00604 // XXX hack
00605 #if 1
00606         scene->adv_light_attenuation(num, factors[0], factors[1], factors[2]);
00607 #endif
00608         return TCL_OK;
00609       } else {
00610         float factors[3] = { 1.0f, 0.0f, 0.0f };
00611         scene->adv_light_get_attenuation(num, factors[0], factors[1], factors[2]);
00612         for (int i=0; i<3; i++) {
00613           char buf[20];
00614           sprintf(buf, "%f", factors[i]);
00615           Tcl_AppendElement(interp, buf);
00616         }
00617         return TCL_OK;
00618       }
00619     }  
00620 
00621     if (argc == 2 && !strupncmp(argv[1], "num", CMDLEN)) {
00622       // return the number of lights
00623       char tmpstring[64];
00624       sprintf(tmpstring, "%d", DISP_LIGHTS);
00625       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00626       return TCL_OK;
00627     }
00628     int n;
00629     if (Tcl_GetInt(interp, argv[1], &n) != TCL_OK) {
00630       Tcl_AppendResult(interp, " -- pointlight <number> ...", NULL);
00631       return TCL_ERROR;
00632     }
00633 
00634     if (argc == 3) {
00635       if(!strupncmp(argv[2],"on", CMDLEN))
00636         scene->activate_adv_light(n, 1);
00637       else if(!strupncmp(argv[2],"off", CMDLEN))
00638         scene->activate_adv_light(n, 0);
00639       else if(!strupncmp(argv[2],"highlight", CMDLEN))
00640         scene->highlight_adv_light(n, 1);
00641       else if(!strupncmp(argv[2],"unhighlight", CMDLEN))
00642         scene->highlight_adv_light(n, 0);
00643       else if(!strupncmp(argv[2],"status", CMDLEN)) {
00644         char tmpstring[1024];
00645 
00646       // return the pair { is on , is highlight} as eg: {on unhighlight}
00647       if (n < 0 || n >= DISP_LIGHTS) {
00648         sprintf(tmpstring, "light value %d out of range", n);
00649         Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00650         return TCL_ERROR;
00651       }
00652       sprintf(tmpstring, "%s %s", 
00653         app->scene->adv_light_active(n) ? "on" : "off",
00654         app->scene->adv_light_highlighted(n) ?  "highlight" : "unhighlight");
00655       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00656       return TCL_OK;
00657     } else {
00658       return TCL_ERROR;
00659     }
00660 
00661 #if 0
00662     } else if(argc == 5 && !strupncmp(argv[2],"rot",CMDLEN)) {
00663       char axis = (char)(tolower(argv[3][0]));
00664       float deg = (float) atof(argv[4]);
00665       app->light_rotate(n, deg, axis);
00666 #endif
00667   } else {
00668     return TCL_ERROR;
00669   }
00670 
00671   // if here, completed successfully
00672   return TCL_OK;
00673 }
00674 
00675 
00676 int text_cmd_axes(ClientData cd, Tcl_Interp *interp, int argc, 
00677                      const char *argv[]) {
00678 
00679   VMDApp *app = (VMDApp *)cd;
00680 
00681   if (app->axes && argc == 2) {
00682     if (!strupncmp(argv[1],"location", CMDLEN)) {
00683       // return the current location
00684       Tcl_SetResult(interp, app->axes->loc_description(app->axes->location()), TCL_VOLATILE);
00685       return TCL_OK;
00686     } else if(!strupncmp(argv[1],"locations", CMDLEN)) {
00687       // return all the possible locations
00688       for (int ii=0; ii<app->axes->locations(); ii++) {
00689         Tcl_AppendElement(interp, app->axes->loc_description(ii));
00690       }
00691       return TCL_OK;
00692     }
00693     // else we are at an error, so return a short list
00694     Tcl_AppendResult(interp, 
00695                      "axes [location|locations]\n",
00696                      "axes location [off|origin|lowerleft|lowerright|"
00697                      "upperleft|upperright]",
00698                      NULL);
00699     return TCL_ERROR;
00700   }
00701   if (app->axes && argc == 3) {
00702     if (!strupncmp(argv[1],"location", CMDLEN)) {
00703       if  (!app->axes_set_location(argv[2])) {
00704         Tcl_AppendResult(interp, "Invalid axes location: ", argv[2], NULL);
00705         return TCL_ERROR;
00706       }
00707     }
00708   } else
00709     return TCL_ERROR;
00710  
00711   // if here, completed successfully
00712   return TCL_OK;
00713 }
00714 
00715 // text callback routine for 'stage'; return TCL_ERROR if an error occurs.
00716 int text_cmd_stage(ClientData cd, Tcl_Interp *interp, int argc, 
00717                      const char *argv[]) {
00718 
00719   VMDApp *app = (VMDApp *)cd;
00720   Stage *stage = app->stage;
00721   if (!stage)
00722     return TCL_ERROR;
00723 
00724   if (argc < 2 || argc > 3) {
00725     int i;
00726     Tcl_AppendResult(interp, (char *) "stage location <", NULL);
00727     for (i=0; i < stage->locations(); i++) {
00728       Tcl_AppendResult(interp, stage->loc_description(i), NULL);
00729       if (i < (stage->locations()-1))
00730         Tcl_AppendResult(interp, " | ", NULL);
00731     }
00732     Tcl_AppendResult(interp, (char *) ">\n", NULL);
00733     Tcl_AppendResult(interp, (char *) "stage locations\n", NULL);
00734     Tcl_AppendResult(interp, (char *) "stage panels [ numpanels ]\n", NULL);
00735     Tcl_AppendResult(interp, (char *) "stage size [ value ]\n", NULL);
00736     return TCL_ERROR;
00737   }
00738 
00739   if (argc == 2) {
00740     if (!strupncmp(argv[1], "location", CMDLEN)) {
00741       Tcl_AppendElement(interp, stage->loc_description(stage->location()));
00742       return TCL_OK;
00743     } else if (!strupncmp(argv[1], "locations", CMDLEN)) {
00744       int i;
00745       for (i=0; i < stage->locations(); i++) {
00746         Tcl_AppendElement(interp, stage->loc_description(i));
00747       }
00748       return TCL_OK;
00749     } else if (!strupncmp(argv[1], "panels", CMDLEN)) {
00750       char s[20];
00751       sprintf(s, "%d", stage->panels());
00752       Tcl_AppendElement(interp, s);
00753       return TCL_OK;
00754     } else if (!strupncmp(argv[1], "size", CMDLEN)) {
00755       char s[20];
00756       sprintf(s, "%f", stage->size());
00757       Tcl_AppendElement(interp, s);
00758       return TCL_OK;
00759     } else {
00760       Tcl_AppendResult(interp, "possible commands are: location, locations, "
00761                        "panels [value]",  NULL);
00762       return TCL_ERROR;
00763     }
00764     // doesn't get here
00765   }
00766 
00767   if (argc == 3) {
00768     int i;
00769     if (!strupncmp(argv[1],"location",CMDLEN)) {
00770       if (app->stage_set_location(argv[2])) return TCL_OK;
00771       Tcl_AppendResult(interp, "Possible locations are ",  NULL);
00772       for (i=0; i<stage->locations(); i++) 
00773         Tcl_AppendElement(interp, stage->loc_description(i));
00774       return TCL_ERROR;
00775     } else if(!strupncmp(argv[1],"panels",CMDLEN)) {
00776       int num=0;
00777       if (Tcl_GetInt(interp, argv[2], &num) != TCL_OK ||
00778           !app->stage_set_numpanels(num)) 
00779         return TCL_ERROR;
00780     } else if(!strupncmp(argv[1],"size",CMDLEN)) {
00781       double sz=1.0;
00782       if (Tcl_GetDouble(interp, argv[2], &sz) != TCL_OK ||
00783           !app->stage_set_size((float) sz))
00784         return TCL_ERROR;
00785     } else {
00786       return TCL_ERROR;
00787     } 
00788   }
00789  
00790   // if here, completed successfully
00791   return TCL_OK;
00792 }
00793 
00794 
00795 

Generated on Thu Apr 25 02:42:00 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002