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

Generated on Sat Jul 19 01:27:09 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002