00001
00002
00003
00004
00005
00006
00007
00012
00013 #ifndef Interp_EVENT_H
00014 #define Interp_EVENT_H
00015
00016 #include "Command.h"
00017 #include "JString.h"
00018 #include "TextInterp.h"
00019 #include "utilities.h"
00020 #include "DisplayDevice.h"
00021
00022 #include <ctype.h>
00023
00024 class TextInterp;
00025
00027 class InterpEvent : public Command {
00028 public:
00029 InterpEvent()
00030 : Command(INTERP_EVENT) {}
00031 virtual ~InterpEvent() {}
00032 virtual void do_callback(TextInterp *) = 0;
00033 };
00034
00036 class UserKeyEvent : public InterpEvent {
00037 private:
00038 char key_desc[128];
00039
00040
00041
00042
00043
00044 void canonicalize(char c, int shiftstate) {
00045 key_desc[0] = 0;
00046 char tmp[2];
00047 tmp[1] = '\0';
00048
00049
00050 if (shiftstate & DisplayDevice::AUX) {
00051 sprintf(key_desc, "Aux-%c", c);
00052 return;
00053 }
00054
00055
00056 if (shiftstate & DisplayDevice::SHIFT) {
00057 tmp[0] = toupper(c);
00058 } else {
00059 tmp[0] = tolower(c);
00060 }
00061
00062 if (shiftstate & DisplayDevice::ALT) {
00063 strcat(key_desc, "Alt-");
00064 }
00065 if (shiftstate & DisplayDevice::CONTROL) {
00066 strcat(key_desc, "Control-");
00067
00068
00069 if (0 < tmp[0] && tmp[0] <= 26) {
00070 tmp[0] += int('a') - 1;
00071
00072 if (shiftstate & DisplayDevice::SHIFT) {
00073 tmp[0] = tolower(tmp[0]);
00074 }
00075 } else {
00076
00077 switch (tmp[0]) {
00078 case 0: tmp[0] = '2'; break;
00079 case 27: tmp[0] = '3'; break;
00080 case 28: tmp[0] = '4'; break;
00081 case 29: tmp[0] = '5'; break;
00082 case 30: tmp[0] = '6'; break;
00083 case 31: tmp[0] = '7'; break;
00084 case 127: tmp[0] = '8'; break;
00085 default: break;
00086 }
00087 }
00088 }
00089
00090 strcat(key_desc, tmp);
00091 }
00092 public:
00093 UserKeyEvent(char thekey, int theshiftstate) {
00094 canonicalize(thekey, theshiftstate);
00095 }
00096 virtual void do_callback(TextInterp *interp) {
00097 interp->userkey_cb(key_desc);
00098 }
00099 };
00100
00102 class TclEvalEvent : public InterpEvent {
00103 private:
00104 JString keystring;
00105 public:
00106 TclEvalEvent(const char *k)
00107 : keystring(k) {}
00108 virtual void do_callback(TextInterp *interp) {
00109 interp->tcl_cb((const char *)keystring);
00110 }
00111 };
00112
00115 class PythonEvalEvent : public InterpEvent {
00116 private:
00117 JString keystring;
00118 public:
00119 PythonEvalEvent(const char *k)
00120 : keystring(k) {}
00121 virtual void do_callback(TextInterp *interp) {
00122 interp->python_cb((const char *)keystring);
00123 }
00124 };
00125
00126
00128 class FrameEvent : public InterpEvent {
00129 private:
00130 int mol, frame;
00131 public:
00132 FrameEvent(int m, int f)
00133 : mol(m), frame(f) {}
00134 virtual void do_callback(TextInterp *interp) {
00135 interp->frame_cb(mol, frame);
00136 }
00137 };
00138
00139
00141 class InitializeStructureEvent : public InterpEvent {
00142 private:
00143 int mol, code;
00144 public:
00145 InitializeStructureEvent(int m, int c)
00146 : mol(m), code(c) {}
00147 virtual void do_callback(TextInterp *interp) {
00148 interp->initialize_structure_cb(mol, code);
00149 }
00150 };
00151
00154 class MoleculeEvent : public InterpEvent {
00155 private:
00156 int mol, code;
00157 public:
00158 enum MolEvent { MOL_DELETE=0, MOL_NEW=1, MOL_RENAME=2, MOL_REGEN=3 };
00159 MoleculeEvent(int m, MolEvent c)
00160 : mol(m), code((int) c) {}
00161 virtual void do_callback(TextInterp *interp) {
00162 interp->molecule_changed_cb(mol, code);
00163 }
00164 };
00165
00166
00168 class MouseModeEvent : public InterpEvent {
00169 private:
00170 JString mode;
00171 int submode;
00172
00173 public:
00174 MouseModeEvent(const char *m, int sm) : mode(m), submode(sm) {}
00175 virtual void do_callback(TextInterp *interp) {
00176 interp->mousemode_cb((const char *)mode, submode);
00177 }
00178 };
00179
00180
00182 class MousePositionEvent : public InterpEvent {
00183 private:
00184 float x, y;
00185 int buttondown;
00186
00187 public:
00188 MousePositionEvent(float xv, float yv, int bdown) : x(xv), y(yv), buttondown(bdown) {}
00189 virtual void do_callback(TextInterp *interp) {
00190 interp->mouse_pos_cb(x, y, buttondown);
00191 }
00192 };
00193
00194
00196 class SpaceballEvent : public InterpEvent {
00197 private:
00198 float tx;
00199 float ty;
00200 float tz;
00201 float rx;
00202 float ry;
00203 float rz;
00204 int buttondown;
00205
00206 public:
00207 SpaceballEvent(float utx, float uty, float utz,
00208 float urx, float ury, float urz,
00209 int bdown) : tx(utx), ty(uty), tz(utz),
00210 rx(urx), ry(ury), rz(urz), buttondown(bdown) {}
00211 virtual void do_callback(TextInterp *interp) {
00212 interp->spaceball_cb(tx, ty, tz, rx, ry, rz, buttondown);
00213 }
00214 };
00215
00216
00218 class PickValueEvent : public InterpEvent {
00219 private:
00220 double val;
00221 public:
00222 PickValueEvent(double v) : val(v) {}
00223 virtual void do_callback(TextInterp *interp) {
00224 interp->pick_value_cb((float) val);
00225 }
00226 };
00227
00228
00230 class PickAtomEvent : public InterpEvent {
00231 private:
00232 int mol, atom, key_shift_state;
00233 bool is_pick;
00234 public:
00235 PickAtomEvent(int m, int a , int ss, bool ispick=false)
00236 : mol(m), atom(a), key_shift_state(ss), is_pick(ispick) {}
00237 virtual void do_callback(TextInterp *interp) {
00238 interp->pick_atom_cb(mol, atom, key_shift_state, is_pick);
00239 }
00240 };
00241
00243 class PickGraphicsEvent : public InterpEvent {
00244 private:
00245 int mol, tag, btn, key_shift_state;
00246 public:
00247 PickGraphicsEvent(int m, int t , int b, int ss)
00248 : mol(m), tag(t), btn(b), key_shift_state(ss) {}
00249 virtual void do_callback(TextInterp *interp) {
00250 interp->pick_graphics_cb(mol, tag, btn, key_shift_state);
00251 }
00252 };
00253
00255 class PickAtomCallbackEvent : public InterpEvent {
00256 private:
00257 int mol, atom;
00258 JString client;
00259 public:
00260 PickAtomCallbackEvent(int m, int a, const char *c)
00261 : mol(m), atom(a), client(c) {}
00262 virtual void do_callback(TextInterp *interp) {
00263 interp->pick_atom_callback_cb(mol, atom, (const char *)client);
00264 }
00265 };
00266
00267
00269 class TrajectoryReadEvent : public InterpEvent {
00270 private:
00271 int id;
00272 char *name;
00273 public:
00274 TrajectoryReadEvent(int m, const char *n) {
00275 id = m;
00276 name = stringdup(n);
00277 }
00278 ~TrajectoryReadEvent() { delete [] name; }
00279 virtual void do_callback(TextInterp *interp) {
00280 interp->trajectory_cb(id, name);
00281 }
00282 };
00283
00284
00286 class TimestepEvent : public InterpEvent {
00287 private:
00288 int id, frame;
00289 public:
00290 TimestepEvent(int m, int f) : id(m), frame(f) {}
00291 virtual void do_callback(TextInterp *interp) {
00292 interp->timestep_cb(id, frame);
00293 }
00294 };
00295
00296
00298 class HelpEvent : public InterpEvent {
00299 private:
00300 JString str;
00301 public:
00302 HelpEvent(const char *topic)
00303 : str(topic) {}
00304 virtual void do_callback(TextInterp *interp) {
00305 interp->help_cb((const char *)str);
00306 }
00307 };
00308
00309
00311 class LogfileEvent : public InterpEvent {
00312 private:
00313 JString str;
00314 public:
00315 LogfileEvent(const char *event)
00316 : str(event) {}
00317 virtual void do_callback(TextInterp *interp) {
00318 interp->logfile_cb((const char *)str);
00319 }
00320 };
00321
00322
00325 class GraphLabelEvent : public InterpEvent {
00326 private:
00327 char *type;
00328 int *ids;
00329 int nlabels;
00330 public:
00331 GraphLabelEvent(const char *labeltype, const int *labels, int n) {
00332 type = stringdup(labeltype);
00333 nlabels = n;
00334 if (n > 0) {
00335 ids = new int[n];
00336 memcpy(ids, labels, n*sizeof(int));
00337 } else {
00338 ids = NULL;
00339 }
00340 }
00341 virtual void do_callback(TextInterp *interp) {
00342 interp->graph_label_cb(type, ids, nlabels);
00343 }
00344 ~GraphLabelEvent() {
00345 delete [] type;
00346 delete [] ids;
00347 }
00348 };
00349
00350
00352 class PickSelectionEvent : public InterpEvent {
00353 private:
00354 int num;
00355 int *atoms;
00356 public:
00357 PickSelectionEvent(int n, const int *a) : num(n) {
00358 if (n > 0) {
00359 atoms = new int[n];
00360 memcpy(atoms, a, n*sizeof(int));
00361 } else {
00362 atoms = NULL;
00363 }
00364 }
00365 ~PickSelectionEvent() { delete [] atoms; }
00366 virtual void do_callback(TextInterp *interp) {
00367 interp->pick_selection_cb(num, atoms);
00368 }
00369 };
00370
00371 #endif