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

cmd_tool.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2011 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_tool.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.33 $       $Date: 2011/02/24 20:56:32 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Text commands for control of the VMD VR "Tools" 
00019  *
00020  ***************************************************************************/
00021 
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <stdlib.h>
00025 #include <tcl.h>
00026 #include "JString.h"
00027 #include "config.h"
00028 #include "UIObject.h"
00029 #include "CommandQueue.h"
00030 #include "Displayable.h"
00031 #include "DispCmds.h"
00032 #include "Matrix4.h"
00033 #include "MoleculeList.h"
00034 #include "Command.h"
00035 #include "P_Tracker.h"
00036 #include "P_Buttons.h"
00037 #include "P_Feedback.h"
00038 #include "P_Tool.h"
00039 #include "P_CmdTool.h"
00040 #include "VMDApp.h"
00041 
00042 int text_cmd_tool(ClientData cd, Tcl_Interp *interp, int argc,
00043                             const char *argv[]) {
00044 
00045   VMDApp *app = (VMDApp *)cd;
00046   CommandQueue *cmdQueue = app->commandQueue;
00047 
00048   char buf[400];
00049 
00050   if(argc<2) {
00051     Tcl_SetResult(interp, 
00052       (char *)
00053       "tool create <type> [<name> [<name> ...]]\n"
00054       "tool change <type> [<toolid>]\n"
00055       "tool scale <scale> [<toolid>]\n"
00056       "tool scaleforce <scale> [<toolid>]\n"
00057       "tool offset <x> <y> <z> [<toolid>]\n"
00058       "tool delete [<toolid>]\n"
00059 #if 0
00060       "tool info [<toolid>]\n"
00061 #endif
00062       "tool rep <toolid> <mol id> <rep id>\n"
00063       "tool adddevice <name> [<toolid>]\n"
00064       "tool removedevice <name> [<toolid>]\n"
00065       "tool callback on/off",
00066       TCL_STATIC);
00067     return TCL_ERROR;
00068   }
00069 
00070   /* creating a new tool with some number of USLs */
00071   if(!strupncmp(argv[1], "create", CMDLEN) && argc>=3) {
00072     if (!app->tool_create(argv[2], argc-3, argv+3)) {
00073       Tcl_AppendResult(interp, "Failed to create new tool.", NULL);
00074       return TCL_ERROR;
00075     }
00076     return TCL_OK;
00077   } 
00078 
00079   /* changing the tool but preserving the sensor */
00080   if(!strupncmp(argv[1], "change", CMDLEN) && (argc==4 || argc==3)) {
00081     int i=0;
00082 
00083     if(argc==4) { // default to 0
00084       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK) 
00085         return TCL_ERROR;
00086     }
00087     if (!app->tool_change_type(i, argv[2])) {
00088       Tcl_AppendResult(interp, "Unable to change tool type.", NULL);
00089       return TCL_ERROR;
00090     }
00091     return TCL_OK;
00092   }
00093 
00094   /* Setting the scale of a tool */
00095   if(!strupncmp(argv[1], "scale", CMDLEN) && (argc==3 || argc==4)) {
00096     int i=0;
00097     double dscale=0.0;
00098     float scale=0.0f;
00099     if(argc==4) {  // default to 0
00100       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK) 
00101         return TCL_ERROR;
00102     }
00103     if (Tcl_GetDouble(interp, argv[2], &dscale) != TCL_OK)
00104       return TCL_ERROR;
00105     scale = (float)dscale;
00106     if (app->tool_set_position_scale(i, scale)) {
00107       return TCL_OK;
00108     }
00109     Tcl_AppendResult(interp, "Unable to set position scale", NULL);
00110     return TCL_ERROR;
00111   }
00112 
00113   /* Setting the scale of the force on a tool */
00114   if(!strupncmp(argv[1], "scaleforce", CMDLEN) && (argc==3 || argc==4)) {
00115     int i=0;
00116     double dscale=0;
00117     float scale=0;
00118     if(argc==4) {  // default to 0
00119       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00120         return TCL_ERROR;
00121     }
00122     if (Tcl_GetDouble(interp, argv[2], &dscale) != TCL_OK)
00123       return TCL_ERROR;
00124     scale = (float)dscale;
00125     if (app->tool_set_force_scale(i, scale))
00126       return TCL_OK;
00127     Tcl_AppendResult(interp, "Unable to set force scale", NULL);
00128     return TCL_ERROR;
00129   }
00130 
00131   /* Setting the scale of the spring on a tool */
00132   if(!strupncmp(argv[1], "scalespring", CMDLEN) && (argc==3 || argc==4)) {
00133     int i=0;
00134     double dscale=0;
00135     float scale=0;
00136     if(argc==4) { // default to 0
00137       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00138         return TCL_ERROR;
00139     }
00140     if (Tcl_GetDouble(interp, argv[2], &dscale) != TCL_OK)
00141       return TCL_ERROR;
00142     scale = (float)dscale;
00143     if (app->tool_set_spring_scale(i, scale))
00144       return TCL_OK;
00145     Tcl_AppendResult(interp, "Unable to set spring scale", NULL);
00146     return TCL_ERROR;
00147   }
00148 
00149   /* Setting the offset of a tool */
00150   if(!strupncmp(argv[1], "offset", CMDLEN) && (argc==5 || argc==6)) {
00151     int i=0,j;
00152     double d_offset[3];
00153     float offset[3];
00154     if(argc==6) { // default to 0
00155       if (Tcl_GetInt(interp, argv[5], &i) != TCL_OK)
00156         return TCL_ERROR;
00157     }
00158     
00159     if (Tcl_GetDouble(interp, argv[2], &d_offset[0]) != TCL_OK)
00160       return TCL_ERROR;
00161     if (Tcl_GetDouble(interp, argv[3], &d_offset[1]) != TCL_OK)
00162       return TCL_ERROR;
00163     if (Tcl_GetDouble(interp, argv[4], &d_offset[2]) != TCL_OK)
00164       return TCL_ERROR;
00165     for(j=0;j<3;j++) offset[j] = (float)d_offset[j];
00166     cmdQueue->runcommand(new CmdToolOffset(offset,i));
00167 
00168     sprintf(buf,"Setting offset of tool %i.", i);
00169     Tcl_AppendResult(interp, buf, NULL);
00170     return TCL_OK;
00171 
00172   }
00173 
00174   /* deleting a tool */
00175   if(!strupncmp(argv[1], "delete", CMDLEN) && (argc==3 || argc==2)) {
00176     int i=0;
00177 
00178     if(argc==3) { // default to 0
00179       if (Tcl_GetInt(interp, argv[2], &i) != TCL_OK)
00180         return TCL_ERROR;
00181     }
00182     cmdQueue->runcommand(new CmdToolDelete(i));
00183     sprintf(buf,"Deleting tool %i.\n",i);
00184     Tcl_AppendResult(interp, buf, NULL);
00185     return TCL_OK;
00186   }
00187 
00188 #if 0 // XXX
00189   /* getting info about a tool */
00190   if(!strupncmp(argv[1], "info", CMDLEN) && (argc==3 || argc==2)) {
00191     int i=0;
00192     Tool *tool;
00193 
00194     if(argc==3) {  // default to 0
00195       if (Tcl_GetInt(interp, argv[2], &i) != TCL_OK)
00196         return TCL_ERROR;
00197     }
00198     tool = vmdGlobal.uiVR->gettool(i);
00199     if(tool==NULL) {
00200       Tcl_AppendResult(interp, "No such tool.", NULL);
00201       return TCL_ERROR;
00202     }
00203 
00204     sprintf(buf,"Info for tool %i (%s)\n",i,tool->type_name());
00205     Tcl_AppendResult(interp,buf, NULL);
00206 
00207     const float *pos = tool->position();
00208     const Matrix4 *rot = tool->orientation();
00209     if(pos==NULL) {
00210       Tcl_AppendResult(interp, "Tool has no position!", NULL);
00211       return TCL_ERROR;
00212     }
00213       
00214     sprintf(buf,"Postion: %.2f %.2f %.2f\n"
00215             "Orientation: %.2f %.2f %.2f\n"
00216             "             %.2f %.2f %.2f\n"
00217             "             %.2f %.2f %.2f\n",
00218             pos[0],pos[1],pos[2],
00219             rot->mat[4*0+0],rot->mat[4*0+1],rot->mat[4*0+2],
00220             rot->mat[4*1+0],rot->mat[4*1+1],rot->mat[4*1+2],
00221             rot->mat[4*2+0],rot->mat[4*2+1],rot->mat[4*2+2]);
00222 
00223     Tcl_AppendResult(interp,buf, NULL);
00224 
00225     int j=0;
00226     char *devices[5];
00227     const float *offset;
00228     float scale;
00229 
00230     offset = tool->getoffset();
00231     if(offset==NULL) {
00232       Tcl_AppendResult(interp, "tool info:\n",
00233         "NULL Offset...?\n", NULL); 
00234       return TCL_ERROR;
00235     }
00236 
00237     scale = tool->getscale();
00238 
00239     tool->getdevices(devices);
00240     JString buf2;
00241     while(devices[j]!=NULL) {
00242       buf2 += devices[j++];
00243       buf2 += " ";
00244     }
00245 
00246     sprintf(buf,"Scale: %.2f\n"
00247             "Offset: %.2f %.2f %.2f\n"
00248             "USL: %s\n", scale, offset[0],
00249             offset[1], offset[2], (const char *)buf2);
00250 
00251     Tcl_AppendResult(interp,buf, NULL);
00252 
00253     return TCL_OK;
00254   }
00255 
00256 #endif  
00257 
00258   /* Assigning a representation to a tool */
00259   if(!strupncmp(argv[1], "rep", CMDLEN)) {
00260     if (argc != 3 && argc != 5) {
00261       Tcl_AppendResult(interp, "tool rep usage:\n",
00262         "Usage: tool rep toolnum [molid repnum]", NULL); 
00263       return TCL_ERROR;
00264     }
00265     int toolnum, molid, repnum;
00266     toolnum = atoi(argv[2]);
00267     if (argc == 5) {
00268       molid = atoi(argv[3]);
00269       repnum = atoi(argv[4]);
00270     } else {
00271       molid = repnum = -1;
00272     }
00273     cmdQueue->runcommand(new CmdToolRep(toolnum, molid, repnum));
00274     return TCL_OK;
00275   }
00276 
00277   /* Adding a device to a tool */
00278   if(!strupncmp(argv[1], "adddevice", CMDLEN) &&
00279      (argc == 3 || argc == 4)) {
00280     int i=0;
00281 
00282     if(argc==4) { // default to 0
00283       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00284         return TCL_ERROR;
00285     }
00286     cmdQueue->runcommand(new CmdToolAddDevice(argv[2],i));
00287     return TCL_OK;
00288   }
00289 
00290   /* Removing a device to a tool */
00291   if(!strupncmp(argv[1], "removedevice", CMDLEN) &&
00292      (argc == 3 || argc == 4)) {
00293     int i=0;
00294 
00295     if(argc==4) { // default to 0
00296       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00297         return TCL_ERROR;
00298     }
00299     cmdQueue->runcommand(new CmdToolDeleteDevice(argv[2],i));
00300     return TCL_OK;
00301   }
00302 
00303   /* Turning on callbacks for a tool */
00304   if(!strupncmp(argv[1], "callback", CMDLEN)) {
00305     if(argc==3) {
00306       int on=-1;
00307       if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK)
00308         return TCL_ERROR;
00309       if(on!=-1) {
00310         cmdQueue->runcommand(new CmdToolCallback(on));
00311         return TCL_OK;
00312       }
00313     }
00314     Tcl_AppendResult(interp," tool callback usage:\n",
00315                      "Usage: tool callback on/off [<toolid>]",NULL);
00316     return TCL_ERROR;
00317   }
00318     
00319   return TCL_ERROR;
00320 }
00321 

Generated on Wed May 23 01:49:42 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002