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

cmd_tool.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_tool.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.36 $       $Date: 2019/01/17 21:21:03 $
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     Tcl_AppendResult(interp,buf, NULL);
00223 
00224     int j=0;
00225     char *devices[5];
00226     const float *offset;
00227     float scale;
00228 
00229     offset = tool->getoffset();
00230     if (offset==NULL) {
00231       Tcl_AppendResult(interp, "tool info:\n", "NULL Offset...?\n", NULL); 
00232       return TCL_ERROR;
00233     }
00234 
00235     scale = tool->getscale();
00236 
00237     tool->getdevices(devices);
00238     JString buf2;
00239     while(devices[j]!=NULL) {
00240       buf2 += devices[j++];
00241       buf2 += " ";
00242     }
00243 
00244     sprintf(buf,"Scale: %.2f\n"
00245             "Offset: %.2f %.2f %.2f\n"
00246             "USL: %s\n", scale, offset[0],
00247             offset[1], offset[2], (const char *)buf2);
00248     Tcl_AppendResult(interp,buf, NULL);
00249     return TCL_OK;
00250   }
00251 #endif  
00252 
00253   /* Assigning a representation to a tool */
00254   if(!strupncmp(argv[1], "rep", CMDLEN)) {
00255     if (argc != 3 && argc != 5) {
00256       Tcl_AppendResult(interp, "tool rep usage:\n",
00257                        "Usage: tool rep toolnum [molid repnum]", NULL); 
00258       return TCL_ERROR;
00259     }
00260     int toolnum, molid, repnum;
00261     toolnum = atoi(argv[2]);
00262     if (argc == 5) {
00263       molid = atoi(argv[3]);
00264       repnum = atoi(argv[4]);
00265     } else {
00266       molid = repnum = -1;
00267     }
00268     cmdQueue->runcommand(new CmdToolRep(toolnum, molid, repnum));
00269     return TCL_OK;
00270   }
00271 
00272   /* Adding a device to a tool */
00273   if(!strupncmp(argv[1], "adddevice", CMDLEN) &&
00274      (argc == 3 || argc == 4)) {
00275     int i=0;
00276 
00277     if(argc==4) { // default to 0
00278       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00279         return TCL_ERROR;
00280     }
00281     cmdQueue->runcommand(new CmdToolAddDevice(argv[2],i));
00282     return TCL_OK;
00283   }
00284 
00285   /* Removing a device to a tool */
00286   if(!strupncmp(argv[1], "removedevice", CMDLEN) &&
00287      (argc == 3 || argc == 4)) {
00288     int i=0;
00289 
00290     if(argc==4) { // default to 0
00291       if (Tcl_GetInt(interp, argv[3], &i) != TCL_OK)
00292         return TCL_ERROR;
00293     }
00294     cmdQueue->runcommand(new CmdToolDeleteDevice(argv[2],i));
00295     return TCL_OK;
00296   }
00297 
00298   /* Turning on callbacks for a tool */
00299   if(!strupncmp(argv[1], "callback", CMDLEN)) {
00300     if(argc==3) {
00301       int on=-1;
00302       if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK)
00303         return TCL_ERROR;
00304       if (on!=-1) {
00305         cmdQueue->runcommand(new CmdToolCallback(on));
00306         return TCL_OK;
00307       }
00308     }
00309     Tcl_AppendResult(interp," tool callback usage:\n",
00310                      "Usage: tool callback on/off [<toolid>]",NULL);
00311     return TCL_ERROR;
00312   }
00313     
00314   return TCL_ERROR;
00315 }
00316 

Generated on Sat Oct 12 02:43:33 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002