Permalink
Browse files

Python mapscript : fix setting pattern on mapscript.styleObj (#4943)

  • Loading branch information...
rouault committed Jul 7, 2014
1 parent f8044b6 commit 3e8aa5a4d92c9bad105306ebe5117ed29d2b0e7c
Showing with 120 additions and 1 deletion.
  1. +46 −0 mapscript/python/pyextend.i
  2. +65 −0 mapscript/python/pymodule.i
  3. +8 −0 mapserver.h
  4. +1 −1 msautotest
@@ -400,3 +400,49 @@ def fromstring(data, mappath=None):
}
/******************************************************************************
* Extensions to styleObj
*****************************************************************************/
%extend styleObj {
void pattern_set(int nListSize, double* pListValues)
{
if( nListSize < 2 )
{
msSetError(MS_SYMERR, "Not enough pattern elements. A minimum of 2 are required", "pattern_set()");
return;
}
if( nListSize > MS_MAXPATTERNLENGTH )
{
msSetError(MS_MISCERR, "Too many elements", "pattern_set()");
return;
}
memcpy( self->pattern, pListValues, sizeof(double) * nListSize);
self->patternlength = nListSize;
}
void pattern_get(double** argout, int* pnListSize)
{
*pnListSize = self->patternlength;
*argout = (double*) malloc(sizeof(double) * *pnListSize);
memcpy( *argout, self->pattern, sizeof(double) * *pnListSize);
}
void patternlength_set2(int patternlength)
{
msSetError(MS_MISCERR, "pattern is read-only", "patternlength_set()");
}
%pythoncode {
__swig_setmethods__["patternlength"] = _mapscript.styleObj_patternlength_set2
__swig_getmethods__["patternlength"] = _mapscript.styleObj_patternlength_get
if _newclass:patternlength = _swig_property(_mapscript.styleObj_patternlength_get, _mapscript.styleObj_patternlength_set2)
__swig_setmethods__["pattern"] = _mapscript.styleObj_pattern_set
__swig_getmethods__["pattern"] = _mapscript.styleObj_pattern_get
if _newclass:pattern = _swig_property(_mapscript.styleObj_pattern_get, _mapscript.styleObj_pattern_set)
}
}
@@ -37,6 +37,71 @@
msFree($1.data);
}
/*
* Typemap for counted arrays of doubles <- PySequence
*/
%typemap(in,numinputs=1) (int nListSize, double* pListValues)
{
int i;
/* %typemap(in,numinputs=1) (int nListSize, double* pListValues)*/
/* check if is List */
if ( !PySequence_Check($input) ) {
PyErr_SetString(PyExc_TypeError, "not a sequence");
SWIG_fail;
}
$1 = PySequence_Size($input);
$2 = (double*) malloc($1*sizeof(double));
for( i = 0; i<$1; i++ ) {
PyObject *o = PySequence_GetItem($input,i);
if ( !PyArg_Parse(o,"d",&$2[i]) ) {
PyErr_SetString(PyExc_TypeError, "not a number");
Py_DECREF(o);
SWIG_fail;
}
Py_DECREF(o);
}
}
%fragment("CreateTupleFromDoubleArray","header") %{
static PyObject *
CreateTupleFromDoubleArray( double *first, unsigned int size ) {
unsigned int i;
PyObject *out = PyTuple_New( size );
for( i=0; i<size; i++ ) {
PyObject *val = PyFloat_FromDouble( *first );
++first;
PyTuple_SetItem( out, i, val );
}
return out;
}
%}
%typemap(freearg) (int nListSize, double* pListValues)
{
/* %typemap(freearg) (int nListSize, double* pListValues) */
if ($2) {
free((void*) $2);
}
}
%typemap(in,numinputs=0) (double** argout, int* pnListSize) ( double* argout, int nListSize ) {
/* %typemap(python,in,numinputs=0) (double *val, int*hasval) */
$1 = &argout;
$2 = &nListSize;
}
%typemap(argout,fragment="t_output_helper,CreateTupleFromDoubleArray") (double** argout, int* pnListSize)
{
/* %typemap(argout) (double* argout, int* pnListSize) */
PyObject *r;
r = CreateTupleFromDoubleArray(*$1, *$2);
free(*$1);
$result = t_output_helper($result,r);
}
/**************************************************************************
* MapServer Errors and Python Exceptions
**************************************************************************
View
@@ -939,8 +939,16 @@ extern "C" {
double size;
double minsize, maxsize;
#if defined(SWIG) && defined(SWIGPYTHON) /* would probably make sense to mark it immutable for other binding languages than Python */
%immutable;
#endif
int patternlength; /*moved from symbolObj in version 6.0*/
#if defined(SWIG) && defined(SWIGPYTHON)
%mutable;
#endif
#if !(defined(SWIG) && defined(SWIGPYTHON)) /* in Python we use a special typemap for this */
double pattern[MS_MAXPATTERNLENGTH]; /*moved from symbolObj in version 6.0*/
#endif
double gap; /*moved from symbolObj in version 6.0*/
double initialgap;
Submodule msautotest updated from 7ce12f to 23f72f

0 comments on commit 3e8aa5a

Please sign in to comment.