00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "PickList.h"
00045 #include "DisplayDevice.h"
00046 #include "Pickable.h"
00047 #include "PickModeList.h"
00048 #include "PickMode.h"
00049 #include "ResizeArray.h"
00050 #include "NameList.h"
00051 #include "Inform.h"
00052 #include "VMDApp.h"
00053 #include "CommandQueue.h"
00054 #include "TextEvent.h"
00055 #include "Molecule.h"
00056 #include "MoleculeList.h"
00057
00058
00059 static void print_atom_info(VMDApp *app, PickEvent *event);
00060
00062 PickList::PickList(VMDApp *vmdapp) : pickableObjs(32), app(vmdapp) {
00063
00064
00065 currPickDim = currPickTag = (-1);
00066 currPickable = NULL;
00067 app->pickModeList->set_pick_mode(2);
00068 total_callback_clients = 0;
00069 }
00070
00072
00073
00074 void PickList::add_pickable(Pickable *p) {
00075
00076
00077 int indx = pickableObjs.find(p);
00078
00079
00080 if(indx < 0) {
00081 pickableObjs.append(p);
00082 }
00083 }
00084
00085
00086
00087 void PickList::remove_pickable(Pickable *p) {
00088 int ind = pickableObjs.find(p);
00089 if (ind >= 0)
00090 pickableObjs.remove(ind);
00091 }
00092
00094
00095
00097
00098 app->commandQueue->runcommand(new PickAtomCallbackEvent(-1,-1,callback_client));
00099 }
00100
00101 Pickable *PickList::pick_check(int dim, const float
00102 *pos, int &tag, int *cell, float window_size,
00103 char *callback_client){
00104
00105
00106 if(pos==NULL) {
00107 msgErr << "pick_check called with NULL pos" << sendmsg;
00108 return NULL;
00109 }
00110
00111 Pickable *currObj, *retobj = NULL;
00112 float eyedist = (-1.0);
00113 int currtag, rettag = (-1);
00114 int i, np = num_pickable();
00115
00116 if(!np)
00117 return NULL;
00118
00119
00120 app->display->left();
00121
00122
00123 for(i=0; i < np; i++) {
00124 currObj = pickable(i);
00125 if(currObj->pickable_on()) {
00126 currtag = app->display->pick(dim, pos, currObj->pick_cmd_list(), eyedist,
00127 cell, window_size);
00128 if(currtag != -1) {
00129
00130 retobj = currObj;
00131 rettag = currtag;
00132 }
00133 }
00134 }
00135
00136
00137 app->display->update(FALSE);
00138
00139
00140
00141
00142
00143 if(callback_client != NULL) {
00144 if(retobj) {
00145 int mol,atom;
00146 Molecule *m = app->moleculeList->check_pickable(retobj);
00147 if (m) {
00148 mol = m->id();
00149 atom = rettag;
00150 app->commandQueue->runcommand(new PickAtomCallbackEvent(mol,atom,callback_client));
00151 }
00152 }
00153 else {
00154 app->commandQueue->runcommand(new PickAtomCallbackEvent(-1,-1,callback_client));
00155 }
00156 }
00157
00158 if(retobj) {
00159 tag = rettag;
00160
00161 if(callback_client==NULL) {
00162 PickEvent *event = new PickEvent(retobj, tag);
00163 print_atom_info(app, event);
00164 app->commandQueue->runcommand(event);
00165 }
00166 }
00167 return retobj;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177 int PickList::pick_start(int b, int dim,
00178 const float *pos) {
00179 Pickable *closePickable;
00180 int tag = (-1);
00181 int cell[3];
00182 float window_size = 0.01f;
00183 if (dim == 3) window_size *= 5;
00184
00185
00186 if(picking())
00187 return (-1);
00188
00189 cell[0] = cell[1] = cell[2] = 0;
00190
00191
00192 if((closePickable = pick_check(dim, pos, tag, cell, window_size)) != NULL) {
00193
00194 currPickDim = dim;
00195 currPickTag = tag;
00196 currPickable = closePickable;
00197
00198
00199 app->display->left();
00200
00201
00202 PickMode *pm = app->pickModeList->current_pick_mode();
00203 if (pm != NULL)
00204 closePickable->pick_start(pm, app->display, b, currPickTag, cell, dim, pos);
00205
00206
00207 app->display->update(FALSE);
00208 }
00209 return tag;
00210 }
00211
00212
00213
00214
00215
00216
00217 int PickList::pick_move(const float *pos) {
00218
00219
00220 if(!picking() )
00221 return FALSE;
00222
00223
00224 app->display->left();
00225
00226 currPickable->pick_move(app->pickModeList->current_pick_mode(), app->display, currPickTag,
00227 currPickDim, pos);
00228
00229 app->display->update(FALSE);
00230
00231 return TRUE;
00232 }
00233
00234
00235
00236
00237
00238
00239 int PickList::pick_end() {
00240
00241 if(!picking() )
00242 return FALSE;
00243
00244
00245 app->display->left();
00246
00247 currPickable->pick_end(app->pickModeList->current_pick_mode(), app->display);
00248
00249
00250 app->display->update(FALSE);
00251
00252
00253 currPickDim = currPickTag = (-1);
00254 currPickable = NULL;
00255
00256 return TRUE;
00257 }
00258
00259
00260
00261 static void print_atom_info(VMDApp *app, PickEvent *event) {
00262 Molecule *mol = app->moleculeList->check_pickable(event->pickable);
00263 if (!mol) return;
00264 int atomindex = event->tag;
00265 if (atomindex >= mol->nAtoms) return;
00266
00267 MolAtom *a = mol->atom(atomindex);
00268
00269 msgInfo << "picked atom: \n------------\n"
00270 << "molecule id: " << mol->id()
00271 << "\ntrajectory frame: " << app->molecule_frame(mol->id())
00272 << "\nname: " << mol->atomNames.name(a->nameindex)
00273 << "\ntype: " << mol->atomTypes.name(a->typeindex)
00274 << "\nindex: " << atomindex
00275 << "\nresidue: " << a->uniq_resid
00276 << "\nresname: " << mol->resNames.name(a->resnameindex)
00277 << "\nresid: " << a->resid
00278 << "\nchain: " << mol->chainNames.name(a->chainindex)
00279 << "\nsegname: " << mol->segNames.name(a->segnameindex)
00280 << "\nx: " << mol->current()->pos[3*atomindex]
00281 << "\ny: " << mol->current()->pos[3*atomindex+1]
00282 << "\nz: " << mol->current()->pos[3*atomindex+2] << "\n"
00283 << sendmsg;
00284 }