From: <and...@us...> - 2009-08-12 15:48:49
|
Revision: 10232 http://plplot.svn.sourceforge.net/plplot/?rev=10232&view=rev Author: andrewross Date: 2009-08-12 15:48:42 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Further tweaking with python plslabelfunc support and preliminary update of example 19. Still not working correctly. Modified Paths: -------------- trunk/bindings/python/plplotcmodule.i trunk/examples/python/xw19.py Modified: trunk/bindings/python/plplotcmodule.i =================================================================== --- trunk/bindings/python/plplotcmodule.i 2009-08-12 15:28:07 UTC (rev 10231) +++ trunk/bindings/python/plplotcmodule.i 2009-08-12 15:48:42 UTC (rev 10232) @@ -617,7 +617,7 @@ typedef void (*pltr_func)(PLFLT, PLFLT, PLFLT *, PLFLT*, PLPointer); typedef void (*mapform_func)(PLINT, PLFLT *, PLFLT*); typedef PLFLT (*f2eval_func)(PLINT, PLINT, PLPointer); -typedef char * (*label_func)(PLINT, PLFLT, PLPointer); +typedef char * (*label_func)(PLINT, PLFLT, char *, PLINT, PLPointer); %{ typedef PLINT (*defined_func)(PLFLT, PLFLT); @@ -951,12 +951,17 @@ %} %typemap(in) pltr_func pltr { - /* it must be a callable */ - if(!PyCallable_Check((PyObject*)$input)) { - PyErr_SetString(PyExc_ValueError, "pltr argument must be callable"); - return NULL; + /* it must be a callable or None */ + if($input == Py_None) { + $1 = NULL; } - $1 = marshal_pltr($input); + else { + if(!PyCallable_Check((PyObject*)$input)) { + PyErr_SetString(PyExc_ValueError, "pltr argument must be callable"); + return NULL; + } + $1 = marshal_pltr($input); + } } %typemap(freearg) pltr_func pltr { cleanup_pltr(); @@ -969,12 +974,17 @@ } %typemap(in) mapform_func mapform { - /* it must be a callable */ - if(!PyCallable_Check((PyObject*)$input)) { - PyErr_SetString(PyExc_ValueError, "mapform argument must be callable"); - return NULL; + /* it must be a callable or none */ + if($input == Py_None) { + $1 = NULL; } - $1 = marshal_mapform($input); + else { + if(!PyCallable_Check((PyObject*)$input)) { + PyErr_SetString(PyExc_ValueError, "mapform argument must be callable"); + return NULL; + } + $1 = marshal_mapform($input); + } } %typemap(freearg) mapform_func mapform { cleanup_mapform(); @@ -1022,35 +1032,45 @@ /* marshall the f2eval function pointer argument */ %typemap(in) f2eval_func f2eval { - /* it must be a callable */ - if(!PyCallable_Check((PyObject*)$input)) { - PyErr_SetString(PyExc_ValueError, "pltr argument must be callable"); - return NULL; + /* it must be a callable or None */ + if($input == Py_None) { + $1 = NULL; } - /* hold a reference to it */ - Py_XINCREF((PyObject*)$input); - python_f2eval = (PyObject*)$input; - /* this function handles calling the python function */ - $1 = do_f2eval_callback; + else { + if(!PyCallable_Check((PyObject*)$input)) { + PyErr_SetString(PyExc_ValueError, "pltr argument must be callable"); + return NULL; + } + /* hold a reference to it */ + Py_XINCREF((PyObject*)$input); + python_f2eval = (PyObject*)$input; + /* this function handles calling the python function */ + $1 = do_f2eval_callback; + } } %typemap(freearg) f2eval_func f2eval { Py_XDECREF(python_f2eval); python_f2eval = 0; } /* marshall the label function pointer argument */ -%typemap(in) label_func label { - /* it must be a callable */ - if(!PyCallable_Check((PyObject*)$input)) { - PyErr_SetString(PyExc_ValueError, "label_func argument must be callable"); - return NULL; +%typemap(in) label_func lf { + /* it must be a callable or None */ + if($input == Py_None) { + $1 = NULL; } - /* hold a reference to it */ - Py_XINCREF((PyObject*)$input); - python_label = (PyObject*)$input; - /* this function handles calling the python function */ - $1 = do_label_callback; + else { + if(!PyCallable_Check((PyObject*)$input)) { + PyErr_SetString(PyExc_ValueError, "label_func argument must be callable"); + return NULL; + } + /* hold a reference to it */ + Py_XINCREF((PyObject*)$input); + python_label = (PyObject*)$input; + /* this function handles calling the python function */ + $1 = do_label_callback; + } } -%typemap(freearg) label_func label { +%typemap(freearg) label_func lf { Py_XDECREF(python_label); python_label = 0; } Modified: trunk/examples/python/xw19.py =================================================================== --- trunk/examples/python/xw19.py 2009-08-12 15:28:07 UTC (rev 10231) +++ trunk/examples/python/xw19.py 2009-08-12 15:48:42 UTC (rev 10232) @@ -38,11 +38,47 @@ y[i] = yp return [x,y] -# Null coordinate transform (equivalent to passing NULL to C -# version of plmap / plmeridians. -def nullmapform(n,x,y): - return [x,y] +## "Normalize" longitude values so that they always fall between -180.0 and +## 180.0 +def normalize_longitude(lon): + if ((lon >= -180.0) and (lon <= 180.0)): + return lon + else : + times = floor ((fabs(lon) + 180.0) / 360.0) + if (lon < 0.0) : + return(lon + 360.0 * times) + else : + return(lon - 360.0 * times) + +## A custom axis labeling function for longitudes and latitudes. +def geolocation_labeler(axis, value, data): + if (axis == PL_Y_AXIS) : + label_val = value + if (label_val > 0.0) : + direction_label = " N" + elif (label_val < 0.0) : + direction_label = " S" + + else : + direction_label = "Eq" + elif (axis == PL_X_AXIS) : + label_val = normalize_longitude(value) + if (label_val > 0.0) : + direction_label = " E" + elif (label_val < 0.0) : + direction_label = " W" + else : + direction_label = "" + + if (axis == PL_Y_AXIS and value == 0.0) : + # A special case for the equator + snprintf(label, length, "%s", direction_label) + else : + snprintf(label, length, "%.0f%s", fabs(label_val), direction_label) + return label + + # main # # Does a series of 3-d plots for a given data set, with different @@ -61,9 +97,12 @@ minx = 190 maxx = 190+360 + # Setup a custom latitude and longitude-based scaling function. + plslabelfunc(geolocation_labeler, None) + plcol0(1) - plenv(minx, maxx, miny, maxy, 1, -1) - plmap(nullmapform,"usaglobe", minx, maxx, miny, maxy) + plenv(minx, maxx, miny, maxy, 1, 70) + plmap(None,"usaglobe", minx, maxx, miny, maxy) # The Americas @@ -71,9 +110,12 @@ maxx = 340 plcol0(1) - plenv(minx, maxx, miny, maxy, 1, -1) - plmap(nullmapform, "usaglobe", minx, maxx, miny, maxy) + plenv(minx, maxx, miny, maxy, 1, 70) + plmap(None, "usaglobe", minx, maxx, miny, maxy) + # Clear the labeling function + plslabelfunc(None, None) + # Polar, Northern hemisphere minx = 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |