File: lightmodule.c

package info (click to toggle)
viewmol 2.4.1-13
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,212 kB
  • ctags: 2,054
  • sloc: ansic: 30,727; python: 1,849; sh: 921; awk: 433; makefile: 205
file content (157 lines) | stat: -rw-r--r-- 4,700 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*******************************************************************************
*                                                                              *
*                                   Viewmol                                    *
*                                                                              *
*                          L I G H T M O D U L E . C                           *
*                                                                              *
*                 Copyright (c) Joerg-R. Hill, October 2003                    *
*                                                                              *
********************************************************************************
*
* $Id: lightmodule.c,v 1.2 2003/11/07 11:05:34 jrh Exp $
* $Log: lightmodule.c,v $
* Revision 1.2  2003/11/07 11:05:34  jrh
* Release 2.4
*
* Revision 1.1  2000/12/10 15:10:17  jrh
* Initial revision
*
*/     
#include<stdio.h>
#include<Xm/DrawingA.h>
#include<Xm/ToggleB.h>
#include "viewmol.h"

#define PyLight_API_pointers 1
#define PyLightSpec_Type_NUM 0

PyLightSpecObject *light_new(void);
static PyObject *light_rotate(PyObject *, PyObject *);
static PyObject *light_switch(PyObject *, PyObject *);
static PyObject *light_getattr(PyLightSpecObject *, char *);
static void light_dealloc(PyLightSpecObject *);

extern void getRotation(int, int, int, int);
extern int checkInterrupt(void);

extern float *rotObject;
extern int moveItem, rotateXY, rotateZ, lights;

static char PyLightSpec_Type__doc__[] =
  "Light specification";

statichere PyTypeObject PyLightSpec_Type = {
  PyObject_HEAD_INIT(NULL)
  0,                               /*ob_size*/
  "LightSpec",                     /*tp_name*/
  sizeof(PyLightSpecObject),       /*tp_basicsize*/
  0,                               /*tp_itemsize*/
  /* methods */
  (destructor)light_dealloc,       /*tp_dealloc*/
  0,                               /*tp_print*/
  (getattrfunc)light_getattr,      /*tp_getattr*/
  0,                               /*tp_setattr*/
  0,                               /*tp_compare*/
  0,                               /*tp_repr*/
  0,                               /*tp_as_number*/
  0,                               /*tp_as_sequence*/
  0,                               /*tp_as_mapping*/
  0,                               /*tp_hash*/
  0,                               /*tp_call*/
  0,                               /*tp_str*/
  0,                               /*tp_getattro*/
  0,                               /*tp_setattro*/
  /* Space for future expansion */
  0L,0L,
  /* Documentation string */
  PyLightSpec_Type__doc__
};

static PyMethodDef light_methods[] = {
  {"rotate",           light_rotate,    1},
  {"switch",           light_switch,    1},
  {NULL,               NULL}
};

static PyObject *light_rotate(PyObject *self, PyObject *args)
{
  PyLightSpecObject *s;
  int moveItem_save, which, x, y, z;

  if (checkInterrupt()) return(NULL);
  if (!PyArg_ParseTuple(args, "iii", &x, &y, &z)) return(NULL);
 
  s=(PyLightSpecObject *)self;
  which=s->lightID;
  rotObject[4*which]=rotObject[4*which+1]=rotObject[4*which+2]=0.0;
  rotObject[4*which+3]=1.0;
  moveItem_save=moveItem;
  moveItem=which;
  getRotation(x, y, z, 1);
  moveItem=moveItem_save;
  Py_INCREF(Py_None);
  return(Py_None);
}

static PyObject *light_switch(PyObject *self, PyObject *args)
{
  PyLightSpecObject *s;
  int which, i, mode;

  if (checkInterrupt()) return(NULL);
  if (!PyArg_ParseTuple(args, "i", &mode)) return(NULL);
 
  if (mode != TRUE && mode != FALSE)
  {
    PyErr_SetString(PyExc_ValueError, "Mode must be ON or OFF");
    return(NULL);
  }
  s=(PyLightSpecObject *)self;
  which=s->lightID-1;
  i=1 << which;
  if (mode)
    lights|=i;
  else
    lights&=~i;
  Py_INCREF(Py_None);
  return(Py_None);
}

PyLightSpecObject *light_new(void)
{
  PyLightSpecObject *self;

  self=PyObject_NEW(PyLightSpecObject, &PyLightSpec_Type);
  if (self == NULL)
  {
    PyErr_NoMemory();
    return(NULL);
  }
  self->lightID=0;
  return((PyLightSpecObject *)self);
}

static void light_dealloc(PyLightSpecObject *self)
{
  if (!self) return;
  PyObject_Del(self);
}

static PyObject *light_getattr(PyLightSpecObject *self, char *name)
{
  return(Py_FindMethod(light_methods, (PyObject *)self, name));
}

void initLightModule(void)
{
  PyObject *module, *dict;
  static void *PyLight_API[PyLight_API_pointers];

  PyLightSpec_Type.ob_type=&PyType_Type;

  module=Py_InitModule("light", light_methods);
  dict=PyModule_GetDict(module);

  PyLight_API[PyLightSpec_Type_NUM]=(void *)&PyLightSpec_Type;
  PyDict_SetItemString(dict, "_C_API", PyCObject_FromVoidPtr((void *)PyLight_API, NULL));
}