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
00090
00091 if (ind >= 0) {
00092
00093
00094 if (picking() && (currPickable == p)) {
00095
00096 currPickDim = currPickTag = (-1);
00097 currPickable = NULL;
00098 }
00099
00100 pickableObjs.remove(ind);
00101 }
00102 }
00103
00105
00106
00108
00109 app->commandQueue->runcommand(new PickAtomCallbackEvent(-1,-1,callback_client));
00110 }
00111
00112 Pickable *PickList::pick_check(int dim, const float
00113 *pos, int &tag, int *cell, float window_size,
00114 char *callback_client){
00115
00116
00117 if(pos==NULL) {
00118 msgErr << "pick_check called with NULL pos" << sendmsg;
00119 return NULL;
00120 }
00121
00122 Pickable *currObj, *retobj = NULL;
00123 float eyedist = (-1.0);
00124 int currtag, rettag = (-1);
00125 int i, np = num_pickable();
00126
00127 if(!np)
00128 return NULL;
00129
00130
00131 app->display->left();
00132
00133
00134 for(i=0; i < np; i++) {
00135 currObj = pickable(i);
00136 if(currObj->pickable_on()) {
00137 currtag = app->display->pick(dim, pos, currObj->pick_cmd_list(), eyedist,
00138 cell, window_size);
00139 if(currtag != -1) {
00140
00141 retobj = currObj;
00142 rettag = currtag;
00143 }
00144 }
00145 }
00146
00147
00148 app->display->update(FALSE);
00149
00150
00151
00152
00153
00154 if(callback_client != NULL) {
00155 if(retobj) {
00156 int mol,atom;
00157 Molecule *m = app->moleculeList->check_pickable(retobj);
00158 if (m) {
00159 mol = m->id();
00160 atom = rettag;
00161 app->commandQueue->runcommand(new PickAtomCallbackEvent(mol,atom,callback_client));
00162 }
00163 }
00164 else {
00165 app->commandQueue->runcommand(new PickAtomCallbackEvent(-1,-1,callback_client));
00166 }
00167 }
00168
00169 if(retobj) {
00170 tag = rettag;
00171
00172 if(callback_client==NULL) {
00173 PickEvent *event = new PickEvent(retobj, tag);
00174 print_atom_info(app, event);
00175 app->commandQueue->runcommand(event);
00176 }
00177 }
00178 return retobj;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 int PickList::pick_start(int b, int dim,
00189 const float *pos) {
00190 Pickable *closePickable;
00191 int tag = (-1);
00192 int cell[3];
00193 float window_size = 0.01f;
00194 if (dim == 3) window_size *= 5;
00195
00196
00197 if(picking())
00198 return (-1);
00199
00200 cell[0] = cell[1] = cell[2] = 0;
00201
00202
00203 if((closePickable = pick_check(dim, pos, tag, cell, window_size)) != NULL) {
00204
00205 currPickDim = dim;
00206 currPickTag = tag;
00207 currPickable = closePickable;
00208
00209
00210 app->display->left();
00211
00212
00213 PickMode *pm = app->pickModeList->current_pick_mode();
00214 if (pm != NULL)
00215 closePickable->pick_start(pm, app->display, b, currPickTag, cell, dim, pos);
00216
00217
00218 app->display->update(FALSE);
00219 }
00220 return tag;
00221 }
00222
00223
00224
00225
00226
00227
00228 int PickList::pick_move(const float *pos) {
00229
00230
00231 if(!picking() )
00232 return FALSE;
00233
00234
00235 app->display->left();
00236
00237 currPickable->pick_move(app->pickModeList->current_pick_mode(), app->display, currPickTag,
00238 currPickDim, pos);
00239
00240 app->display->update(FALSE);
00241
00242 return TRUE;
00243 }
00244
00245
00246
00247
00248
00249
00250 int PickList::pick_end() {
00251
00252 if(!picking() )
00253 return FALSE;
00254
00255
00256 app->display->left();
00257
00258 currPickable->pick_end(app->pickModeList->current_pick_mode(), app->display);
00259
00260
00261 app->display->update(FALSE);
00262
00263
00264 currPickDim = currPickTag = (-1);
00265 currPickable = NULL;
00266
00267 return TRUE;
00268 }
00269
00270
00271
00272 static void print_atom_info(VMDApp *app, PickEvent *event) {
00273 Molecule *mol = app->moleculeList->check_pickable(event->pickable);
00274 if (!mol) return;
00275 int atomindex = event->tag;
00276 if (atomindex >= mol->nAtoms) return;
00277
00278 MolAtom *a = mol->atom(atomindex);
00279
00280 msgInfo << "picked atom: \n------------\n"
00281 << "molecule id: " << mol->id()
00282 << "\ntrajectory frame: " << app->molecule_frame(mol->id())
00283 << "\nname: " << mol->atomNames.name(a->nameindex)
00284 << "\ntype: " << mol->atomTypes.name(a->typeindex)
00285 << "\nindex: " << atomindex
00286 << "\nresidue: " << a->uniq_resid
00287 << "\nresname: " << mol->resNames.name(a->resnameindex)
00288 << "\nresid: " << a->resid
00289 << "\nchain: " << mol->chainNames.name(a->chainindex)
00290 << "\nsegname: " << mol->segNames.name(a->segnameindex)
00291 << "\nx: " << mol->current()->pos[3L*atomindex]
00292 << "\ny: " << mol->current()->pos[3L*atomindex+1]
00293 << "\nz: " << mol->current()->pos[3L*atomindex+2] << "\n"
00294 << sendmsg;
00295 }