Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BPy_ContextFunctions.cpp « python « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 43db0f0eb29832b87e7445861f75f6c7bc82b788 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
#include "BPy_ContextFunctions.h"
#include "BPy_Convert.h"

#include "../stroke/ContextFunctions.h"

#ifdef __cplusplus
extern "C" {
#endif
  
///////////////////////////////////////////////////////////////////////////////////////////

/*-----------------------Python API function prototypes for the ContextFunctions module--*/

static PyObject * ContextFunctions_GetTimeStampCF( PyObject* self );
static PyObject * ContextFunctions_GetCanvasWidthCF( PyObject* self );
static PyObject * ContextFunctions_GetCanvasHeightCF( PyObject* self );
static PyObject * ContextFunctions_LoadMapCF( PyObject *self, PyObject *args );
static PyObject * ContextFunctions_ReadMapPixelCF( PyObject *self, PyObject *args );
static PyObject * ContextFunctions_ReadCompleteViewMapPixelCF( PyObject *self, PyObject *args );
static PyObject * ContextFunctions_ReadDirectionalViewMapPixelCF( PyObject *self, PyObject *args );
static PyObject * ContextFunctions_GetSelectedFEdgeCF( PyObject *self );

/*-----------------------ContextFunctions module docstring-------------------------------*/

static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";

/*-----------------------ContextFunctions module functions definitions-------------------*/

static PyMethodDef module_functions[] = {
  {"GetTimeStampCF", (PyCFunction)ContextFunctions_GetTimeStampCF, METH_NOARGS, ""},
  {"GetCanvasWidthCF", (PyCFunction)ContextFunctions_GetCanvasWidthCF, METH_NOARGS, ""},
  {"GetCanvasHeightCF", (PyCFunction)ContextFunctions_GetCanvasHeightCF, METH_NOARGS, ""},
  {"LoadMapCF", (PyCFunction)ContextFunctions_LoadMapCF, METH_VARARGS, ""},
  {"ReadMapPixelCF", (PyCFunction)ContextFunctions_ReadMapPixelCF, METH_VARARGS, ""},
  {"ReadCompleteViewMapPixelCF", (PyCFunction)ContextFunctions_ReadCompleteViewMapPixelCF, METH_VARARGS, ""},
  {"ReadDirectionalViewMapPixelCF", (PyCFunction)ContextFunctions_ReadDirectionalViewMapPixelCF, METH_VARARGS, ""},
  {"GetSelectedFEdgeCF", (PyCFunction)ContextFunctions_GetSelectedFEdgeCF, METH_NOARGS, ""},
  {NULL, NULL, 0, NULL}
};

/*-----------------------ContextFunctions module definition--------------------------------*/

static PyModuleDef module_definition = {
    PyModuleDef_HEAD_INIT,
    "Freestyle.ContextFunctions",
    module_docstring,
    -1,
    module_functions
};

//------------------- MODULE INITIALIZATION --------------------------------

int ContextFunctions_Init( PyObject *module )
{	
  PyObject *m, *d, *f;

  if( module == NULL )
    return -1;

  m = PyModule_Create(&module_definition);
  if (m == NULL)
    return -1;
  Py_INCREF(m);
  PyModule_AddObject(module, "ContextFunctions", m);

  // from ContextFunctions import *
  d = PyModule_GetDict(m);
  for (PyMethodDef *p = module_functions; p->ml_name; p++) {
	f = PyDict_GetItemString(d, p->ml_name);
	Py_INCREF(f);
	PyModule_AddObject(module, p->ml_name, f);
  }

  return 0;
}

//------------------------ MODULE FUNCTIONS ----------------------------------

static PyObject *
ContextFunctions_GetTimeStampCF( PyObject* self )
{
  return PyLong_FromLong( ContextFunctions::GetTimeStampCF() );
}

static PyObject *
ContextFunctions_GetCanvasWidthCF( PyObject* self )
{
  return PyLong_FromLong( ContextFunctions::GetCanvasWidthCF() );
}

static PyObject *
ContextFunctions_GetCanvasHeightCF( PyObject* self )
{
  return PyLong_FromLong( ContextFunctions::GetCanvasHeightCF() );
}

static PyObject *
ContextFunctions_LoadMapCF( PyObject *self, PyObject *args )
{
  char *fileName, *mapName;
  unsigned nbLevels;
  float sigma;

  if( !PyArg_ParseTuple(args, "ssIf", &fileName, &mapName, &nbLevels, &sigma) )
    return NULL;

  ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);

  Py_RETURN_NONE;
}

static PyObject *
ContextFunctions_ReadMapPixelCF( PyObject *self, PyObject *args )
{
  char *mapName;
  int level;
  unsigned x, y;

  if( !PyArg_ParseTuple(args, "siII", &mapName, &level, &x, &y) )
    return NULL;

  float f = ContextFunctions::ReadMapPixelCF(mapName, level, x, y);

  return PyFloat_FromDouble( f );
}

static PyObject *
ContextFunctions_ReadCompleteViewMapPixelCF( PyObject *self, PyObject *args )
{
  int level;
  unsigned x, y;

  if( !PyArg_ParseTuple(args, "iII", &level, &x, &y) )
    return NULL;

  float f = ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y);

  return PyFloat_FromDouble( f );
}

static PyObject *
ContextFunctions_ReadDirectionalViewMapPixelCF( PyObject *self, PyObject *args )
{
  int orientation, level;
  unsigned x, y;

  if( !PyArg_ParseTuple(args, "iiII", &orientation, &level, &x, &y) )
    return NULL;

  float f = ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y);

  return PyFloat_FromDouble( f );
}

static PyObject *
ContextFunctions_GetSelectedFEdgeCF( PyObject *self )
{
  FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
  if( fe )
    return Any_BPy_FEdge_from_FEdge( *fe );

  Py_RETURN_NONE;
}

///////////////////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
}
#endif