00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "py_commands.h"
00022 #include "VMDApp.h"
00023 #include "DisplayDevice.h"
00024
00025
00026
00027 static PyObject *update(PyObject *self, PyObject *args) {
00028 if (!PyArg_ParseTuple(args, (char *)":display.update"))
00029 return NULL;
00030
00031 VMDApp *app = get_vmdapp();
00032 app->display_update();
00033
00034 Py_INCREF(Py_None);
00035 return Py_None;
00036 }
00037
00038
00039
00040 static PyObject *update_ui(PyObject *self, PyObject *args) {
00041 if (!PyArg_ParseTuple(args, (char *)":display.update_ui"))
00042 return NULL;
00043
00044 VMDApp *app = get_vmdapp();
00045 app->display_update_ui();
00046
00047 Py_INCREF(Py_None);
00048 return Py_None;
00049 }
00050
00051
00052 static PyObject *update_on(PyObject *self, PyObject *args) {
00053 if (!PyArg_ParseTuple(args, (char *)":display.update_on"))
00054 return NULL;
00055
00056 VMDApp *app = get_vmdapp();
00057 app->display_update_on(1);
00058
00059 Py_INCREF(Py_None);
00060 return Py_None;
00061 }
00062
00063
00064 static PyObject *update_off(PyObject *self, PyObject *args) {
00065 if (!PyArg_ParseTuple(args, (char *)":display.update_off"))
00066 return NULL;
00067
00068 VMDApp *app = get_vmdapp();
00069 app->display_update_on(0);
00070
00071 Py_INCREF(Py_None);
00072 return Py_None;
00073 }
00074
00075 static char *kwlist[] = {
00076 (char *)"eyesep", (char *)"focallength", (char *)"height",
00077 (char *)"distance", (char *)"nearclip", (char *)"farclip",
00078 (char *)"antialias", (char *)"depthcue", (char *)"culling",
00079 (char *)"stereo", (char *)"projection", (char *)"size",
00080 NULL };
00081 static const int num_keys = 12;
00082
00083
00084 static PyObject *set(PyObject *self, PyObject *args, PyObject *keywds) {
00085
00086 float eyesep, focallength, height, distance, nearclip, farclip;
00087 PyObject *antialias, *depthcue, *culling;
00088 char *stereo, *projection;
00089 PyObject *size;
00090
00091 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"|ffffffOOOssO:display.set", kwlist,
00092 &eyesep, &focallength, &height, &distance, &nearclip, &farclip,
00093 &antialias, &depthcue, &culling, &stereo,
00094 &projection, &size))
00095 return NULL;
00096
00097
00098 VMDApp *app = get_vmdapp();
00099 int w, h;
00100 for (int i=0; i<num_keys; i++) {
00101 if (PyDict_GetItemString(keywds, kwlist[i]) == NULL)
00102 continue;
00103 switch (i) {
00104 case 0: app->display_set_eyesep(eyesep); break;
00105 case 1: app->display_set_focallen(focallength); break;
00106 case 2: app->display_set_screen_height(height); break;
00107 case 3: app->display_set_screen_distance(distance); break;
00108 case 4: app->display_set_nearclip(nearclip, 0); break;
00109 case 5: app->display_set_farclip(farclip, 0); break;
00110 case 6: app->display_set_aa(PyObject_IsTrue(antialias)); break;
00111 case 7: app->display_set_depthcue(PyObject_IsTrue(depthcue)); break;
00112 case 8: app->display_set_culling(PyObject_IsTrue(culling)); break;
00113 case 9: app->display_set_stereo(stereo); break;
00114 case 10:
00115 if (!app->display_set_projection(projection)) {
00116 PyErr_SetString(PyExc_ValueError, "Invalid projection");
00117 return NULL;
00118 }
00119 break;
00120 case 11:
00121 if (!PyList_Check(size) || PyList_Size(size) != 2) {
00122 PyErr_SetString(PyExc_ValueError, "size argument must be a two-element list");
00123 return NULL;
00124 }
00125 w = PyInt_AsLong(PyList_GET_ITEM(size, 0));
00126 h = PyInt_AsLong(PyList_GET_ITEM(size, 1));
00127 if (PyErr_Occurred()) return NULL;
00128 app->display_set_size(w, h);
00129 break;
00130 default: ;
00131 }
00132 }
00133
00134 Py_INCREF(Py_None);
00135 return Py_None;
00136 }
00137
00138 static char *get_kwlist[] = {
00139 (char *)"eyesep", (char *)"focallength", (char *)"height",
00140 (char *)"distance", (char *)"nearclip", (char *)"farclip",
00141 (char *)"antialias", (char *)"depthcue",
00142 (char *)"culling",
00143 (char *)"stereo", (char *)"projection", (char *)"size"
00144 };
00145
00146 static const int num_get_keys = 12;
00147
00148
00149 static PyObject *get(PyObject *self, PyObject *args) {
00150
00151 char *key;
00152 if (!PyArg_ParseTuple(args, (char *)"s:display.get", &key))
00153 return NULL;
00154
00155 int i=0;
00156 for (; i<num_get_keys; i++)
00157 if (!strcmp(key, get_kwlist[i]))
00158 break;
00159 if (i == num_get_keys) {
00160 PyErr_SetString(PyExc_ValueError, "Invalid attribute");
00161 return NULL;
00162 }
00163 VMDApp *app = get_vmdapp();
00164 DisplayDevice *disp = app->display;
00165 int w, h;
00166 switch (i) {
00167 case 0: return PyFloat_FromDouble(disp->eyesep());
00168 case 1: return PyFloat_FromDouble(disp->eye_dist());
00169 case 2: return PyFloat_FromDouble(disp->screen_height());
00170 case 3: return PyFloat_FromDouble(disp->distance_to_screen());
00171 case 4: return PyFloat_FromDouble(disp->near_clip());
00172 case 5: return PyFloat_FromDouble(disp->far_clip());
00173 case 6: return PyInt_FromLong(disp->aa_enabled() ? 1 : 0);
00174 case 7: return PyInt_FromLong(disp->cueing_enabled() ? 1 : 0);
00175 case 8: return PyInt_FromLong(disp->culling_enabled() ? 1 : 0);
00176 case 9: return PyString_FromString(
00177 disp->stereo_name(disp->stereo_mode()));
00178 case 10: return PyString_FromString(
00179 disp->get_projection());
00180 case 11:
00181 app->display_get_size(&w, &h);
00182 return Py_BuildValue((char *)"[i,i]", w, h);
00183 default: ;
00184 }
00185 PyErr_SetString(PyExc_RuntimeError, "Internal error in get()");
00186 return NULL;
00187 }
00188
00189 static PyObject *stereomodes(PyObject *self, PyObject *args) {
00190 if (!PyArg_ParseTuple(args, (char *)":display.stereomodes"))
00191 return NULL;
00192
00193 DisplayDevice *disp = get_vmdapp()->display;
00194 int num = disp->num_stereo_modes();
00195 PyObject *newlist = PyList_New(num);
00196 for (int j=0; j<num; j++)
00197 PyList_SET_ITEM(newlist, j, PyString_FromString(disp->stereo_name(j)));
00198 return newlist;
00199 }
00200
00201 static PyMethodDef DisplayMethods[] = {
00202 {(char *)"update", (vmdPyMethod)update, METH_VARARGS },
00203 {(char *)"update_ui", (vmdPyMethod)update_ui, METH_VARARGS },
00204 {(char *)"update_on", (vmdPyMethod)update_on, METH_VARARGS },
00205 {(char *)"update_off", (vmdPyMethod)update_off, METH_VARARGS },
00206 {(char *)"set", (PyCFunction)set, METH_VARARGS | METH_KEYWORDS},
00207 {(char *)"get", (vmdPyMethod)get, METH_VARARGS},
00208 {(char *)"stereomodes", (vmdPyMethod)stereomodes, METH_VARARGS},
00209 {NULL, NULL}
00210 };
00211
00212 void initdisplay() {
00213 PyObject *m = Py_InitModule((char *)"display", DisplayMethods);
00214
00215 PyModule_AddStringConstant(m, (char *)"PROJ_PERSP", (char *)"Perspective");
00216 PyModule_AddStringConstant(m, (char *)"PROJ_ORTHO", (char *)"Orthographic");
00217 }
00218