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 #include <math.h>
00028 #include "PickModeMolLabel.h"
00029 #include "Pickable.h"
00030 #include "DisplayDevice.h"
00031 #include "Inform.h"
00032 #include "DrawMolecule.h"
00033 #include "CommandQueue.h"
00034 #include "TextEvent.h"
00035 #include "VMDApp.h"
00036 #include "utilities.h"
00037
00038 PickModeMolLabel::PickModeMolLabel(const char *nm, int size, VMDApp *vmdapp)
00039 : needItems(size), app(vmdapp) {
00040
00041 modename = stringdup(nm);
00042
00043 needName = FALSE;
00044
00045
00046 molids = new int[size];
00047 atmids = new int[size];
00048 cells = new int[3L*size];
00049
00050
00051 haveItems = 0;
00052 }
00053
00054 PickModeMolLabel::~PickModeMolLabel(void) {
00055
00056 delete [] molids;
00057 delete [] atmids;
00058 delete [] cells;
00059 delete [] modename;
00060 }
00061
00062
00063 void PickModeMolLabel::pick_molecule_start(DrawMolecule *mol, DisplayDevice *d,
00064 int, int tag, const int *cell, int dim, const float *pos) {
00065 atom = tag;
00066
00067 memcpy(pPos, pos, dim*sizeof(float));
00068 memcpy(lastCell, cell, 3*sizeof(int));
00069 needName = TRUE;
00070
00071 int shift_pressed = d->shift_state() & DisplayDevice::SHIFT;
00072 app->commandQueue->runcommand(new PickAtomEvent(mol->id(), tag,
00073 shift_pressed));
00074 }
00075
00076 void PickModeMolLabel::pick_molecule_move(DrawMolecule *, DisplayDevice *,
00077 int, int dim, const float *pos) {
00078
00079
00080 if(needName) {
00081 float mvdist = 0.0;
00082 for(int i=0; i < dim; i++)
00083 mvdist += (float) fabs(pPos[i] - pos[i]);
00084
00085 if(mvdist > 0.01)
00086 needName = FALSE;
00087 }
00088 }
00089
00090 void PickModeMolLabel::pick_molecule_end(DrawMolecule *m, DisplayDevice *) {
00091
00092 if(needName) {
00093
00094
00095 int id = m->id();
00096 molids[haveItems] = id;
00097 atmids[haveItems] = atom;
00098 memcpy(cells+3*haveItems, lastCell, 3*sizeof(int));
00099
00100
00101 app->label_add("Atoms", 1, &id, &atom, lastCell, 0.0f, 1);
00102
00103
00104 haveItems++;
00105
00106
00107 if(haveItems >= needItems) {
00108
00109 if(needItems > 1) {
00110
00111 app->label_add(modename, needItems, molids, atmids, cells, 0.0f, 1);
00112 }
00113
00114
00115 haveItems = 0;
00116 }
00117 }
00118 needName = FALSE;
00119 }
00120
00121 void PickModeMolLabel::pick_graphics(int molid, int tag, int btn, DisplayDevice *d) {
00122 int shift_pressed = d->shift_state() & DisplayDevice::SHIFT;
00123 app->commandQueue->runcommand(new PickGraphicsEvent(molid, tag, btn, shift_pressed));
00124 }
00125