[mapserver-commits] r12668 - in trunk/mapserver: . mapscript/php
mapscript/swiginc
svn at osgeo.org
svn at osgeo.org
Mon Oct 17 16:49:43 EDT 2011
Author: aboudreault
Date: 2011-10-17 13:49:43 -0700 (Mon, 17 Oct 2011)
New Revision: 12668
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/maplabel.c
trunk/mapserver/mapscript/php/label.c
trunk/mapserver/mapscript/php/mapscript_i.c
trunk/mapserver/mapscript/php/php_mapscript.h
trunk/mapserver/mapscript/php/style.c
trunk/mapserver/mapscript/swiginc/label.i
trunk/mapserver/mapserver.h
Log:
Fixed cannot add a style to a label in PHP/SWIG Mapscript (#4038)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/HISTORY.TXT 2011-10-17 20:49:43 UTC (rev 12668)
@@ -14,6 +14,9 @@
Current Version (SVN trunk, 6.1-dev, future 6.2):
-------------------------------------------------
+
+- Fixed cannot add a style to a label in PHP/SWIG Mapscript (#4038)
+
- Fixed schema validity issue for WCS 1.1 GetCoverage responses (#4047)
- remove default compiler search paths from the GD CFLAGS/LDFLAGS (#4046)
Modified: trunk/mapserver/maplabel.c
===================================================================
--- trunk/mapserver/maplabel.c 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/maplabel.c 2011-10-17 20:49:43 UTC (rev 12668)
@@ -1017,3 +1017,140 @@
return(MS_FALSE);
}
+
+/* For MapScript, exactly the same the msInsertStyle */
+int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) {
+ int i;
+
+ if (!style)
+ {
+ msSetError(MS_CHILDERR, "Can't insert a NULL Style", "msInsertLabelStyle()");
+ return -1;
+ }
+
+ /* Ensure there is room for a new style */
+ if (msGrowLabelStyles(label) == NULL) {
+ return -1;
+ }
+ /* Catch attempt to insert past end of styles array */
+ else if (nStyleIndex >= label->numstyles) {
+ msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", "insertLabelStyle()", label->numstyles-1);
+ return -1;
+ }
+ else if (nStyleIndex < 0) { /* Insert at the end by default */
+ label->styles[label->numstyles]=style;
+ MS_REFCNT_INCR(style);
+ label->numstyles++;
+ return label->numstyles-1;
+ }
+ else if (nStyleIndex >= 0 && nStyleIndex < label->numstyles) {
+ /* Move styles existing at the specified nStyleIndex or greater */
+ /* to a higher nStyleIndex */
+ for (i=label->numstyles-1; i>=nStyleIndex; i--) {
+ label->styles[i+1] = label->styles[i];
+ }
+ label->styles[nStyleIndex]=style;
+ MS_REFCNT_INCR(style);
+ label->numstyles++;
+ return nStyleIndex;
+ }
+ else {
+ msSetError(MS_CHILDERR, "Invalid nStyleIndex", "insertLabelStyle()");
+ return -1;
+ }
+}
+
+/**
+ * Move the style up inside the array of styles.
+ */
+int msMoveLabelStyleUp(labelObj *label, int nStyleIndex)
+{
+ styleObj *psTmpStyle = NULL;
+ if (label && nStyleIndex < label->numstyles && nStyleIndex >0)
+ {
+ psTmpStyle = (styleObj *)malloc(sizeof(styleObj));
+ initStyle(psTmpStyle);
+
+ msCopyStyle(psTmpStyle, label->styles[nStyleIndex]);
+
+ msCopyStyle(label->styles[nStyleIndex],
+ label->styles[nStyleIndex-1]);
+
+ msCopyStyle(label->styles[nStyleIndex-1], psTmpStyle);
+
+ return(MS_SUCCESS);
+ }
+ msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLabelStyleUp()",
+ nStyleIndex);
+ return (MS_FAILURE);
+}
+
+
+/**
+ * Move the style down inside the array of styles.
+ */
+int msMoveLabelStyleDown(labelObj *label, int nStyleIndex)
+{
+ styleObj *psTmpStyle = NULL;
+
+ if (label && nStyleIndex < label->numstyles-1 && nStyleIndex >=0)
+ {
+ psTmpStyle = (styleObj *)malloc(sizeof(styleObj));
+ initStyle(psTmpStyle);
+
+ msCopyStyle(psTmpStyle, label->styles[nStyleIndex]);
+
+ msCopyStyle(label->styles[nStyleIndex],
+ label->styles[nStyleIndex+1]);
+
+ msCopyStyle(label->styles[nStyleIndex+1], psTmpStyle);
+
+ return(MS_SUCCESS);
+ }
+ msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLabelStyleDown()",
+ nStyleIndex);
+ return (MS_FAILURE);
+}
+
+/**
+ * Delete the style identified by the index and shift
+ * styles that follows the deleted style.
+ */
+int msDeleteLabelStyle(labelObj *label, int nStyleIndex)
+{
+ int i = 0;
+ if (label && nStyleIndex < label->numstyles && nStyleIndex >=0)
+ {
+ if (freeStyle(label->styles[nStyleIndex]) == MS_SUCCESS)
+ msFree(label->styles[nStyleIndex]);
+ for (i=nStyleIndex; i< label->numstyles-1; i++)
+ {
+ label->styles[i] = label->styles[i+1];
+ }
+ label->styles[label->numstyles-1] = NULL;
+ label->numstyles--;
+ return(MS_SUCCESS);
+ }
+ msSetError(MS_CHILDERR, "Invalid index: %d", "msDeleteLabelStyle()",
+ nStyleIndex);
+ return (MS_FAILURE);
+}
+
+styleObj *msRemoveLabelStyle(labelObj *label, int nStyleIndex) {
+ int i;
+ styleObj *style;
+ if (nStyleIndex < 0 || nStyleIndex >= label->numstyles) {
+ msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", "removeLabelStyle()", nStyleIndex);
+ return NULL;
+ }
+ else {
+ style=label->styles[nStyleIndex];
+ for (i=nStyleIndex; i<label->numstyles-1; i++) {
+ label->styles[i]=label->styles[i+1];
+ }
+ label->styles[label->numstyles-1]=NULL;
+ label->numstyles--;
+ MS_REFCNT_DECR(style);
+ return style;
+ }
+}
Modified: trunk/mapserver/mapscript/php/label.c
===================================================================
--- trunk/mapserver/mapscript/php/label.c 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapscript/php/label.c 2011-10-17 20:49:43 UTC (rev 12668)
@@ -60,6 +60,22 @@
ZEND_ARG_INFO(0, labelBinding)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(label_getStyle_args, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(label_moveStyleUp_args, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(label_moveStyleDown_args, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(label_deleteStyle_args, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
/* {{{ proto void __construct()
labelObj CANNOT be instanciated, this will throw an exception on use */
PHP_METHOD(labelObj, __construct)
@@ -104,6 +120,7 @@
else IF_GET_LONG("minfeaturesize", php_label->label->minfeaturesize)
else IF_GET_LONG("autominfeaturesize", php_label->label->autominfeaturesize)
else IF_GET_LONG("repeatdistance", php_label->label->repeatdistance)
+ else IF_GET_LONG("numstyles", php_label->label->numstyles)
else IF_GET_LONG("mindistance", php_label->label->mindistance)
else IF_GET_LONG("partials", php_label->label->partials)
else IF_GET_LONG("force", php_label->label->force)
@@ -174,6 +191,10 @@
{
mapscript_throw_exception("Property '%s' is an object and can only be modified through its accessors." TSRMLS_CC, property);
}
+ else if (STRING_EQUAL("numstyles", property))
+ {
+ mapscript_throw_exception("Property '%s' is read-only and cannot be set." TSRMLS_CC, property);
+ }
else
{
mapscript_throw_exception("Property '%s' does not exist in this object." TSRMLS_CC, property);
@@ -331,6 +352,111 @@
}
/* }}} */
+/* {{{ proto int getstyle(int index)
+ return the style object. */
+PHP_METHOD(labelObj, getStyle)
+{
+ long index;
+ zval *zobj = getThis();
+ php_label_object *php_label;
+ styleObj *style = NULL;
+ parent_object parent;
+
+ PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &index) == FAILURE) {
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+ return;
+ }
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+
+ php_label = (php_label_object *) zend_object_store_get_object(zobj TSRMLS_CC);
+
+ if (index < 0 || index >= php_label->label->numstyles)
+ {
+ mapscript_throw_exception("Invalid style index." TSRMLS_CC);
+ return;
+ }
+
+ style = php_label->label->styles[index];
+
+ MAPSCRIPT_MAKE_PARENT(zobj, NULL);
+ mapscript_create_style(style, parent, return_value TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto int moveStyleUp(int index) */
+PHP_METHOD(labelObj, moveStyleUp)
+{
+ long index;
+ zval *zobj = getThis();
+ php_label_object *php_label;
+ int status = MS_FAILURE;
+
+ PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &index) == FAILURE) {
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+ return;
+ }
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+
+ php_label = (php_label_object *) zend_object_store_get_object(zobj TSRMLS_CC);
+
+ status = labelObj_moveStyleUp(php_label->label, index);
+
+ RETURN_LONG(status);
+}
+/* }}} */
+
+/* {{{ proto int moveStyleDown(int index) */
+PHP_METHOD(labelObj, moveStyleDown)
+{
+ long index;
+ zval *zobj = getThis();
+ php_label_object *php_label;
+ int status = MS_FAILURE;
+
+ PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &index) == FAILURE) {
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+ return;
+ }
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+
+ php_label = (php_label_object *) zend_object_store_get_object(zobj TSRMLS_CC);
+
+ status = labelObj_moveStyleDown(php_label->label, index);
+
+ RETURN_LONG(status);
+}
+/* }}} */
+
+ /* {{{ proto int deleteStyle(int index) */
+PHP_METHOD(labelObj, deleteStyle)
+{
+ long index;
+ zval *zobj = getThis();
+ php_label_object *php_label;
+ int status = MS_FAILURE;
+
+ PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &index) == FAILURE) {
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+ return;
+ }
+ PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
+
+ php_label = (php_label_object *) zend_object_store_get_object(zobj TSRMLS_CC);
+
+ status = labelObj_deleteStyle(php_label->label, index);
+
+ RETURN_LONG(status);
+}
+/* }}} */
+
/* {{{ proto int label.free()
Free the object */
PHP_METHOD(labelObj, free)
@@ -362,6 +488,10 @@
PHP_ME(labelObj, setBinding, label_setBinding_args, ZEND_ACC_PUBLIC)
PHP_ME(labelObj, getBinding, label_getBinding_args, ZEND_ACC_PUBLIC)
PHP_ME(labelObj, removeBinding, label_removeBinding_args, ZEND_ACC_PUBLIC)
+ PHP_ME(labelObj, getStyle, label_getStyle_args, ZEND_ACC_PUBLIC)
+ PHP_ME(labelObj, moveStyleUp, label_moveStyleUp_args, ZEND_ACC_PUBLIC)
+ PHP_ME(labelObj, moveStyleDown, label_moveStyleDown_args, ZEND_ACC_PUBLIC)
+ PHP_ME(labelObj, deleteStyle, label_deleteStyle_args, ZEND_ACC_PUBLIC)
PHP_ME(labelObj, free, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
Modified: trunk/mapserver/mapscript/php/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php/mapscript_i.c 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapscript/php/mapscript_i.c 2011-10-17 20:49:43 UTC (rev 12668)
@@ -723,6 +723,21 @@
return msUpdateLabelFromString(self, snippet);
}
+int labelObj_moveStyleUp(labelObj *self, int index)
+{
+ return msMoveLabelStyleUp(self, index);
+}
+
+int labelObj_moveStyleDown(labelObj *self, int index)
+{
+ return msMoveLabelStyleDown(self, index);
+}
+
+int labelObj_deleteStyle(labelObj *self, int index)
+{
+ return msDeleteLabelStyle(self, index);
+}
+
/**********************************************************************
* class extensions for legendObj
**********************************************************************/
@@ -1389,6 +1404,21 @@
return class->styles[class->numstyles-1];
}
+styleObj *styleObj_label_new(labelObj *label, styleObj *style) {
+ if(msGrowLabelStyles(label) == NULL)
+ return NULL;
+
+ if(initStyle(label->styles[label->numstyles]) == -1)
+ return NULL;
+
+ if (style)
+ msCopyStyle(label->styles[label->numstyles], style);
+
+ label->numstyles++;
+
+ return label->styles[label->numstyles-1];
+ }
+
int styleObj_updateFromString(styleObj *self, char *snippet) {
return msUpdateStyleFromString(self, snippet, MS_FALSE);
}
Modified: trunk/mapserver/mapscript/php/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php/php_mapscript.h 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapscript/php/php_mapscript.h 2011-10-17 20:49:43 UTC (rev 12668)
@@ -610,6 +610,9 @@
const char *library_str) ;
int labelObj_updateFromString(labelObj *self, char *snippet);
+int labelObj_moveStyleUp(labelObj *self, int index);
+int labelObj_moveStyleDown(labelObj *self, int index);
+int labelObj_deleteStyle(labelObj *self, int index);
int legendObj_updateFromString(legendObj *self, char *snippet);
@@ -741,6 +744,7 @@
DBFFieldType DBFInfo_getFieldType(DBFInfo *self, int iField);
styleObj *styleObj_new(classObj *class, styleObj *style);
+styleObj *styleObj_label_new(labelObj *label, styleObj *style);
int styleObj_updateFromString(styleObj *self, char *snippet);
int styleObj_setSymbolByName(styleObj *self, mapObj *map,
char* pszSymbolName);
Modified: trunk/mapserver/mapscript/php/style.c
===================================================================
--- trunk/mapserver/mapscript/php/style.c 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapscript/php/style.c 2011-10-17 20:49:43 UTC (rev 12668)
@@ -35,7 +35,7 @@
zend_object_handlers mapscript_style_object_handlers;
ZEND_BEGIN_ARG_INFO_EX(style___construct_args, 0, 0, 1)
- ZEND_ARG_OBJ_INFO(0, class, classObj, 0)
+ ZEND_ARG_INFO(0, parent)
ZEND_ARG_OBJ_INFO(0, style, styleObj, 0)
ZEND_END_ARG_INFO()
@@ -73,20 +73,21 @@
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
-/* {{{ proto void __construct(classObj class [, styleObj style])
- Create a new styleObj instance */
+/* {{{ proto void __construct(parent [, styleObj style])
+ Create a new styleObj instance. parent has to be a classObj or labelObj. */
PHP_METHOD(styleObj, __construct)
{
zval *zobj = getThis();
- zval *zclass, *zstyle = NULL;
+ zval *zparent, *zstyle = NULL;
styleObj *style;
- php_class_object *php_class;
+ php_class_object *php_class = NULL;
+ php_label_object *php_label = NULL;
php_style_object *php_style, *php_style2;
parent_object parent;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O",
- &zclass, mapscript_ce_class,
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|O",
+ &zparent,
&zstyle, mapscript_ce_style) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
@@ -94,21 +95,42 @@
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_style = (php_style_object *)zend_object_store_get_object(zobj TSRMLS_CC);
- php_class = (php_class_object *)zend_object_store_get_object(zclass TSRMLS_CC);
+
+ if (Z_TYPE_P(zparent) == IS_OBJECT && Z_OBJCE_P(zparent) == mapscript_ce_class)
+ php_class = (php_class_object *)zend_object_store_get_object(zparent TSRMLS_CC);
+ else if (Z_TYPE_P(zparent) == IS_OBJECT && Z_OBJCE_P(zparent) == mapscript_ce_label)
+ php_label = (php_label_object *)zend_object_store_get_object(zparent TSRMLS_CC);
+ else
+ {
+ mapscript_throw_mapserver_exception("Invalid argument 1: should be a classObj or labelObj" TSRMLS_CC);
+ return;
+ }
+
if (zstyle)
php_style2 = (php_style_object *)zend_object_store_get_object(zstyle TSRMLS_CC);
- if ((style = styleObj_new(php_class->class, (zstyle ? php_style2->style : NULL))) == NULL)
+ if (php_class)
{
- mapscript_throw_mapserver_exception("" TSRMLS_CC);
- return;
+ if ((style = styleObj_new(php_class->class, (zstyle ? php_style2->style : NULL))) == NULL)
+ {
+ mapscript_throw_mapserver_exception("" TSRMLS_CC);
+ return;
+ }
}
+ else
+ {
+ if ((style = styleObj_label_new(php_label->label, (zstyle ? php_style2->style : NULL))) == NULL)
+ {
+ mapscript_throw_mapserver_exception("" TSRMLS_CC);
+ return;
+ }
+ }
php_style->style = style;
-
- MAPSCRIPT_MAKE_PARENT(zclass, NULL);
+
+ MAPSCRIPT_MAKE_PARENT(zparent, NULL);
php_style->parent = parent;
- MAPSCRIPT_ADDREF(zclass);
+ MAPSCRIPT_ADDREF(zparent);
}
/* }}} */
Modified: trunk/mapserver/mapscript/swiginc/label.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/label.i 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapscript/swiginc/label.i 2011-10-17 20:49:43 UTC (rev 12668)
@@ -73,4 +73,41 @@
return MS_SUCCESS;
}
+
+ %newobject getStyle;
+ styleObj *getStyle(int i) {
+ if (i >= 0 && i < self->numstyles) {
+ MS_REFCNT_INCR(self->styles[i]);
+ return self->styles[i];
+ } else {
+ msSetError(MS_CHILDERR, "Invalid index: %d", "getStyle()", i);
+ return NULL;
+ }
+ }
+
+#ifdef SWIGCSHARP
+%apply SWIGTYPE *SETREFERENCE {styleObj *style};
+#endif
+ int insertStyle(styleObj *style, int index=-1) {
+ return msInsertLabelStyle(self, style, index);
+ }
+#ifdef SWIGCSHARP
+%clear styleObj *style;
+#endif
+
+ %newobject removeStyle;
+ styleObj *removeStyle(int index) {
+ styleObj* style = (styleObj *) msRemoveLabelStyle(self, index);
+ if (style)
+ MS_REFCNT_INCR(style);
+ return style;
+ }
+
+ int moveStyleUp(int index) {
+ return msMoveLabelStyleUp(self, index);
+ }
+
+ int moveStyleDown(int index) {
+ return msMoveLabelStyleDown(self, index);
+ }
}
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2011-10-16 12:32:08 UTC (rev 12667)
+++ trunk/mapserver/mapserver.h 2011-10-17 20:49:43 UTC (rev 12668)
@@ -2304,6 +2304,14 @@
int nStyleIndex);
MS_DLL_EXPORT styleObj *msRemoveStyle(classObj *classo, int index);
+/* maplabel.c */
+MS_DLL_EXPORT int msInsertLabelStyle(labelObj *label, styleObj *style,
+ int nStyleIndex);
+MS_DLL_EXPORT int msMoveLabelStyleUp(labelObj *label, int nStyleIndex);
+MS_DLL_EXPORT int msMoveLabelStyleDown(labelObj *label, int nStyleIndex);
+MS_DLL_EXPORT int msDeleteLabelStyle(labelObj *label, int nStyleIndex);
+MS_DLL_EXPORT styleObj *msRemoveLabelStyle(labelObj *label, int nStyleIndex);
+
/* Measured shape utility functions. */
MS_DLL_EXPORT pointObj *msGetPointUsingMeasure(shapeObj *shape, double m);
MS_DLL_EXPORT pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point);
More information about the mapserver-commits
mailing list