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

cmd_mouse.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_mouse.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.30 $      $Date: 2019/01/17 21:21:03 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for mouse input control
00019  ***************************************************************************/
00020 
00021 #include <stdlib.h>
00022 #include <tcl.h>
00023 #include "config.h"
00024 #include "VMDApp.h"
00025 #include "Mouse.h"
00026 #include "PickModeList.h"
00027 #include "utilities.h"
00028 
00029 
00030 // print usage message
00031 static void mouse_usage(Tcl_Interp *interp) {
00032   Tcl_AppendResult(interp, "mouse usage:\n",
00033       "mouse callback [on|off]\n",
00034       "mouse rocking [on|off]\n",
00035       "mouse mode <mode> <submode>\n",
00036       "   modes: rotate, translate, scale, light, userpoint\n",
00037       "   pick, center, query, labelatom\n",
00038       "   labelbond, labelangle, labeldihedral\n",
00039       "   moveatom, moveres, movefrag, movemol, moverep\n",
00040       "   forceatom, forceres, forcefrag, addbond\n", 
00041       NULL);
00042 }
00043 
00044 
00045 // The following use MOUSE_MODE
00046 int text_cmd_mouse(ClientData cd, Tcl_Interp *interp, int argc,
00047                             const char *argv[]) {
00048 
00049   VMDApp *app = (VMDApp *)cd;
00050 
00051   if (argc == 2 && !strupncmp(argv[1], "stoprotation", CMDLEN)) {
00052     app->scene_stoprotation();
00053     return TCL_OK;
00054   } else if(argc < 3 || argc > 4) {
00055     // if here, something went wrong, so return an error message
00056     mouse_usage(interp);
00057     return TCL_ERROR;
00058   }
00059 
00060   // get the mouse submode, if there is one
00061   int m2 = (argc > 3 ? atoi(argv[3]) : (-1));
00062     
00063   // the modes are:
00064   //  ROTATION == 0, ... USER == 6 ; as defined in Mouse.h
00065   if(!strupncmp(argv[1], "mode", CMDLEN)) {
00066     int m1;
00067     // see if these are string values
00068     if (!strupncmp(argv[2], "rotate", CMDLEN))          m1 = Mouse::ROTATION;  
00069     else if (!strupncmp(argv[2], "translate", CMDLEN))  m1 = Mouse::TRANSLATION;  
00070     else if (!strupncmp(argv[2], "scale", CMDLEN))      m1 = Mouse::SCALING;  
00071     else if (!strupncmp(argv[2], "light", CMDLEN))      m1 = Mouse::LIGHT;  
00072     else if (!strupncmp(argv[2], "userpoint", CMDLEN))  m1 = Mouse::USERPOINT;
00073     // picking modes...
00074     else if (!strupncmp(argv[2], "query", CMDLEN))      m1 = Mouse::QUERY;
00075     else if (!strupncmp(argv[2], "center", CMDLEN))     m1 = Mouse::CENTER;
00076     else if (!strupncmp(argv[2], "labelatom", CMDLEN))  m1 = Mouse::LABELATOM;
00077     else if (!strupncmp(argv[2], "labelbond", CMDLEN))  m1 = Mouse::LABELBOND;
00078     else if (!strupncmp(argv[2], "labelangle", CMDLEN)) m1 = Mouse::LABELANGLE;
00079     else if (!strupncmp(argv[2], "labeldihedral", CMDLEN)) m1 = Mouse::LABELDIHEDRAL;
00080     else if (!strupncmp(argv[2], "moveatom", CMDLEN))   m1 = Mouse::MOVEATOM;
00081     else if (!strupncmp(argv[2], "moveres", CMDLEN))    m1 = Mouse::MOVERES;
00082     else if (!strupncmp(argv[2], "movefrag", CMDLEN))   m1 = Mouse::MOVEFRAG;
00083     else if (!strupncmp(argv[2], "movemol", CMDLEN))    m1 = Mouse::MOVEMOL;
00084     else if (!strupncmp(argv[2], "forceatom", CMDLEN))  m1 = Mouse::FORCEATOM;
00085     else if (!strupncmp(argv[2], "forceres", CMDLEN))   m1 = Mouse::FORCERES;
00086     else if (!strupncmp(argv[2], "forcefrag", CMDLEN))  m1 = Mouse::FORCEFRAG;
00087     else if (!strupncmp(argv[2], "moverep", CMDLEN))    m1 = Mouse::MOVEREP;
00088     else if (!strupncmp(argv[2], "addbond", CMDLEN))    m1 = Mouse::ADDBOND;
00089     else if (!strupncmp(argv[2], "pick", CMDLEN)) { 
00090       if (argc == 3 || m2 == -1)
00091         m1 = Mouse::PICK;  
00092       else {
00093         // if pick is called with a submode, we process it the "old" way
00094         // This is only for backward-compatibility
00095         switch (m2) {
00096           case PickModeList::QUERY:          m1 = Mouse::QUERY; break;
00097           case PickModeList::CENTER:         m1 = Mouse::CENTER; break;
00098           case PickModeList::LABELATOM:      m1 = Mouse::LABELATOM; break;
00099           case PickModeList::LABELBOND:      m1 = Mouse::LABELBOND; break;
00100           case PickModeList::LABELANGLE:     m1 = Mouse::LABELANGLE; break;
00101           case PickModeList::LABELDIHEDRAL:  m1 = Mouse::LABELDIHEDRAL; break;
00102           case PickModeList::MOVEATOM:       m1 = Mouse::MOVEATOM; break;
00103           case PickModeList::MOVERES:        m1 = Mouse::MOVERES; break;
00104           case PickModeList::MOVEFRAG:       m1 = Mouse::MOVEFRAG; break;
00105           case PickModeList::MOVEMOL:        m1 = Mouse::MOVEMOL; break;
00106           case PickModeList::FORCEATOM:      m1 = Mouse::FORCEATOM; break;
00107           case PickModeList::FORCERES:       m1 = Mouse::FORCERES; break;
00108           case PickModeList::FORCEFRAG:      m1 = Mouse::FORCEFRAG; break;
00109           case PickModeList::MOVEREP:        m1 = Mouse::MOVEREP; break;
00110           case PickModeList::ADDBOND:        m1 = Mouse::ADDBOND; break;
00111           case PickModeList::PICK:           m1 = Mouse::PICK; break;
00112           default:                  
00113             m1 = Mouse::QUERY; // shouldn't happen...
00114         }
00115       }
00116     } else if (!strupncmp(argv[2], "user", CMDLEN)) { 
00117       // this is obsolete (left in for backwards-compatibility)
00118       m1 = Mouse::PICK;  
00119     }
00120     else {
00121       // not a string so convert to a number
00122       // XXX need to check if atoi fails..
00123       m1 = atoi(argv[2]);
00124     }
00125 
00126     if (!app->mouse_set_mode(m1, m2)) {
00127       Tcl_AppendResult(interp, "Unable to set mouse mode to ",
00128           argv[2], argc > 3 ? argv[3] : NULL, NULL);
00129 
00130       // if here, something went wrong, so return an error message
00131       mouse_usage(interp);
00132 
00133       return TCL_ERROR;
00134     }
00135     
00136   } else if(!strupncmp(argv[1], "callback", CMDLEN)) {
00137     int on=-1;
00138     if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK) return TCL_ERROR;
00139     if(on!=-1) {
00140       app->set_mouse_callbacks(on);
00141     }
00142   } else if (argc == 3 && !strupncmp(argv[1], "rocking", CMDLEN)) {
00143     int on = 0;
00144     if (Tcl_GetBoolean(interp, argv[2], &on) != TCL_OK) return TCL_ERROR;
00145     app->set_mouse_rocking(on);
00146   } else {
00147     // if here, something went wrong, so return an error message
00148     mouse_usage(interp);
00149     return TCL_ERROR;
00150   }
00151   
00152   // if here, everything worked out ok
00153   return TCL_OK;
00154 }
00155 

Generated on Wed Dec 4 02:43:03 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002