[mapserver-commits] r12788 - sandbox/sdlime/rfc-77
svn at osgeo.org
svn at osgeo.org
Fri Nov 18 19:37:17 EST 2011
Author: sdlime
Date: 2011-11-18 16:37:17 -0800 (Fri, 18 Nov 2011)
New Revision: 12788
Modified:
sandbox/sdlime/rfc-77/mapcopy.c
sandbox/sdlime/rfc-77/mapfile.c
sandbox/sdlime/rfc-77/mapserver.h
Log:
RFC-77 multi-label code. More to come...
Modified: sandbox/sdlime/rfc-77/mapcopy.c
===================================================================
--- sandbox/sdlime/rfc-77/mapcopy.c 2011-11-18 13:56:59 UTC (rev 12787)
+++ sandbox/sdlime/rfc-77/mapcopy.c 2011-11-19 00:37:17 UTC (rev 12788)
@@ -461,7 +461,7 @@
msFree(dst->styles);
dst->numstyles = 0;
- for (i = 0; i < src->numstyles; i++) {
+ for (i=0; i<src->numstyles; i++) {
if (msGrowClassStyles(dst) == NULL)
return MS_FAILURE;
if (initStyle(dst->styles[i]) != MS_SUCCESS) {
@@ -476,9 +476,14 @@
dst->numstyles++;
}
- if (msCopyLabel(&(dst->label), &(src->label)) != MS_SUCCESS) {
- msSetError(MS_MEMERR, "Failed to copy label.", "msCopyClass()");
- return MS_FAILURE;
+ for (i=0; i<src->numlabels; i++) {
+ if (msGrowClassLabels(dst) == NULL)
+ return MS_FAILURE;
+ initLabel(dst->labels[i]);
+ if (msCopyLabel(dst->labels[i], src->labels[i]) != MS_SUCCESS) {
+ msSetError(MS_MEMERR, "Failed to copy label.", "msCopyClass()");
+ return MS_FAILURE;
+ }
}
MS_COPYSTRING(dst->keyimage, src->keyimage);
Modified: sandbox/sdlime/rfc-77/mapfile.c
===================================================================
--- sandbox/sdlime/rfc-77/mapfile.c 2011-11-18 13:56:59 UTC (rev 12787)
+++ sandbox/sdlime/rfc-77/mapfile.c 2011-11-19 00:37:17 UTC (rev 12788)
@@ -1655,10 +1655,12 @@
return;
}
-static void freeLabel(labelObj *label)
+static int freeLabel(labelObj *label)
{
int i;
+ // if( MS_REFCNT_DECR_IS_NOT_ZERO(label) ) { return MS_FAILURE; }
+
msFree(label->font);
msFree(label->encoding);
@@ -1673,6 +1675,8 @@
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++)
msFree(label->bindings[i].item);
+
+ return MS_SUCCESS;
}
static int loadLabel(labelObj *label)
@@ -2802,8 +2806,6 @@
*/
int initClass(classObj *class)
{
- /* printf("Init class at %p\n", class); */
-
class->status = MS_ON;
class->debug = MS_OFF;
MS_REFCNT_INIT(class);
@@ -2813,9 +2815,6 @@
class->title = NULL;
initExpression(&(class->text));
- initLabel(&(class->label));
- class->label.size = -1; /* no default */
-
class->template = NULL;
class->type = -1;
@@ -2832,6 +2831,12 @@
class->numstyles = class->maxstyles = 0;
class->styles = NULL;
+ // RFC-77 REMOVE
+ // initLabel(&(class->label));
+ // class->label.size = -1; /* no default */
+ class->numlabels = class->maxlabels = 0;
+ class->labels = NULL;
+
class->keyimage = NULL;
class->group = NULL;
@@ -2844,9 +2849,7 @@
int i;
if( MS_REFCNT_DECR_IS_NOT_ZERO(class) ) { return MS_FAILURE; }
- /* printf("Freeing class at %p (%s)\n", class, class->name); */
-
- freeLabel(&(class->label));
+
freeExpression(&(class->expression));
freeExpression(&(class->text));
msFree(class->name);
@@ -2865,13 +2868,23 @@
}
}
msFree(class->styles);
+
+ for(i=0;i<class->numstyles;i++) { /* each label */
+ if(class->labels[i]!=NULL) {
+ if(freeLabel(class->labels[i]) == MS_SUCCESS) {
+ msFree(class->labels[i]);
+ }
+ }
+ }
+ msFree(class->labels);
+
msFree(class->keyimage);
return MS_SUCCESS;
}
/*
-** Ensure there is at least one free entry in the sttyles array of this
+** Ensure there is at least one free entry in the styles array of this
** classObj. Grow the allocated styles array if necessary and allocate
** a new style for styles[numstyles] if there is not already one,
** setting its contents to all zero bytes (i.e. does not call initStyle()
@@ -2974,8 +2987,6 @@
return MS_SUCCESS;
}
-
-
/*
* Reset style info in the class to defaults
* the only members we don't touch are name, expression, and join/query stuff
@@ -2985,7 +2996,16 @@
{
int i;
- freeLabel(&(class->label));
+ /* reset labels */
+ for(i=0; i<class->numlabels; i++) {
+ if(class->styles[i] != NULL) {
+ if(freeLabel(class->labels[i]) == MS_SUCCESS ) {
+ msFree(class->labels[i]);
+ }
+ class->labels[i] = NULL;
+ }
+ }
+ class->numlabels = 0;
freeExpression(&(class->text));
initExpression(&(class->text));
@@ -3001,13 +3021,38 @@
}
class->numstyles = 0;
- initLabel(&(class->label));
- class->label.size = -1; /* no default */
-
class->type = -1;
class->layer = NULL;
}
+labelObj *msGrowClassLabels( classObj *class ) {
+ /* Do we need to increase the size of labels[] by MS_LABEL_ALLOCSIZE?
+ */
+ if (class->numlabels == class->maxlabels) {
+ labelObj **newLabelPtr;
+ int i, newsize;
+
+ newsize = class->maxlabels + MS_LABEL_ALLOCSIZE;
+
+ /* Alloc/realloc labels */
+ newLabelPtr = (labelObj**)realloc(class->labels, newsize*sizeof(labelObj*));
+ MS_CHECK_ALLOC(newLabelPtr, newsize*sizeof(labelObj*), NULL);
+
+ class->labels = newLabelPtr;
+ class->maxlabels = newsize;
+ for(i=class->numlabels; i<class->maxlabels; i++) {
+ class->labels[i] = NULL;
+ }
+ }
+
+ if (class->labels[class->numlabels]==NULL) {
+ class->labels[class->numlabels]=(labelObj*)calloc(1,sizeof(labelObj));
+ MS_CHECK_ALLOC(class->labels[class->numlabels], sizeof(labelObj), NULL);
+ }
+
+ return class->labels[class->numlabels];
+}
+
int loadClass(classObj *class, layerObj *layer)
{
int state;
@@ -3061,8 +3106,10 @@
}
break;
case(LABEL):
- class->label.size = MS_MEDIUM; /* only set a default if the LABEL section is present */
- if(loadLabel(&(class->label)) == -1) return(-1);
+ if(msGrowClassLabels(class) == NULL) return(-1);
+ initLabel(class->labels[class->numlabels]);
+ class->labels[class->numlabels]->size = MS_MEDIUM; /* only set a default if the LABEL section is present */
+ if(loadLabel(class->labels[class->numlabels]) == -1) return(-1);
break;
case(MAXSCALE):
case(MAXSCALEDENOM):
@@ -3228,9 +3275,37 @@
}
}
+static int classResolveSymbolNames(classObj *class) {
+ int i,j;
+
+ /* step through styles and labels to resolve symbol names */
+ /* class styles */
+ for(i=0; i<class->numstyles; i++) {
+ if(class->styles[i]->symbolname) {
+ if((class->styles[i]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->styles[i]->symbolname, MS_TRUE)) == -1) {
+ msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, style %d of layer %s.", "classResolveSymbolNames()", class->styles[i]->symbolname, i, class->layer->name);
+ return MS_FAILURE;
+ }
+ }
+ }
+
+ /* label styles */
+ for(i=0; i<class->numlabels; i++) {
+ for(j=0; j<class->labels[i]->numstyles; j++) {
+ if(class->labels[i]->styles[j]->symbolname) {
+ if((class->labels[i]->styles[j]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->labels[i]->styles[j]->symbolname, MS_TRUE)) == -1) {
+ msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, label style %d of layer %s.", "classResolveSymbolNames()", class->labels[i]->styles[j]->symbolname, j, class->layer->name);
+ return MS_FAILURE;
+ }
+ }
+ }
+ }
+
+ return MS_SUCCESS;
+}
+
int msUpdateClassFromString(classObj *class, char *string, int url_string)
{
- int k;
if(!class || !string) return MS_FAILURE;
msAcquireLock( TLOCK_PARSER );
@@ -3252,28 +3327,8 @@
msyylex_destroy();
- /* step through styles and labels to resolve symbol names */
- /* class styles */
- for(k=0; k<class->numstyles; k++) {
- if(class->styles[k]->symbolname) {
- if((class->styles[k]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, style %d of layer %s.", "msUpdateClassFromString()", class->styles[k]->symbolname, k, class->layer->name);
- return MS_FAILURE;
- }
- }
- }
-
- /* label styles */
- for(k=0; k<class->label.numstyles; k++) {
- if(class->label.styles[k]->symbolname) {
- if((class->label.styles[k]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->label.styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, label style %d of layer %s.",
- "msUpdateClassFromString()", class->label.styles[k]->symbolname, k, class->layer->name);
- return MS_FAILURE;
- }
- }
- }
-
+ if(classResolveSymbolNames(class) != MS_SUCCESS) return MS_FAILURE;
+
return MS_SUCCESS;
}
@@ -3290,7 +3345,7 @@
writeNumber(stream, indent, "DEBUG", 0, class->debug);
writeExpression(stream, indent, "EXPRESSION", &(class->expression));
writeString(stream, indent, "KEYIMAGE", NULL, class->keyimage);
- writeLabel(stream, indent, &(class->label));
+ for(i=0; i<class->numlabels; i++) writeLabel(stream, indent, class->labels[i]);
writeNumber(stream, indent, "MAXSCALEDENOM", -1, class->maxscaledenom);
writeHashTable(stream, indent, "METADATA", &(class->metadata));
writeNumber(stream, indent, "MINSCALEDENOM", -1, class->minscaledenom);
@@ -3923,7 +3978,7 @@
int msUpdateLayerFromString(layerObj *layer, char *string, int url_string)
{
- int j, k;
+ int i;
if(!layer || !string) return MS_FAILURE;
@@ -3947,28 +4002,8 @@
msyylex_destroy();
/* step through classes to resolve symbol names */
- for(j=0; j<layer->numclasses; j++) {
-
- /* class styles */
- for(k=0; k<layer->class[j]->numstyles; k++) {
- if(layer->class[j]->styles[k]->symbolname) {
- if((layer->class[j]->styles[k]->symbol = msGetSymbolIndex(&(layer->map->symbolset), layer->class[j]->styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, style %d of layer %s.", "msUpdateLayerFromString()", layer->class[j]->styles[k]->symbolname, j, k, layer->name);
- return MS_FAILURE;
- }
- }
- }
-
- /* label styles */
- for(k=0; k<layer->class[j]->label.numstyles; k++) {
- if(layer->class[j]->label.styles[k]->symbolname) {
- if((layer->class[j]->label.styles[k]->symbol = msGetSymbolIndex(&(layer->map->symbolset), layer->class[j]->label.styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, label style %d of layer %s.",
- "msUpdateLayerFromString()", layer->class[j]->label.styles[k]->symbolname, j, k, layer->name);
- return MS_FAILURE;
- }
- }
- }
+ for(i=0; i<layer->numclasses; i++) {
+ if(classResolveSymbolNames(layer->class[i]) != MS_SUCCESS) return MS_FAILURE;
}
return MS_SUCCESS;
@@ -6216,36 +6251,14 @@
static int msResolveSymbolNames(mapObj* map)
{
- int i, j, k;
- /* step through layers and classes to resolve symbol names */
- for(i=0; i<map->numlayers; i++) {
- for(j=0; j<GET_LAYER(map, i)->numclasses; j++) {
- /* class styles */
- for(k=0; k<GET_LAYER(map, i)->class[j]->numstyles; k++) {
- if(GET_LAYER(map, i)->class[j]->styles[k]->symbolname) {
- if((GET_LAYER(map, i)->class[j]->styles[k]->symbol = msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, style %d of layer %s.", "msLoadMap()", GET_LAYER(map, i)->class[j]->styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
- return MS_FAILURE;
- }
- }
- if(!MS_IS_VALID_ARRAY_INDEX(GET_LAYER(map, i)->class[j]->styles[k]->symbol, map->symbolset.numsymbols)) {
- msSetError(MS_MISCERR, "Invalid symbol index in class %d, style %d of layer %s.", "msLoadMap()", j, k, GET_LAYER(map, i)->name);
- return MS_FAILURE;
- }
- }
+ int i, j;
- /* label styles */
- for(k=0; k<GET_LAYER(map, i)->class[j]->label.numstyles; k++) {
- if(GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname) {
- if((GET_LAYER(map, i)->class[j]->label.styles[k]->symbol = msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, MS_TRUE)) == -1) {
- msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, label style %d of layer %s.",
- "msLoadMap()", GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
- return MS_FAILURE;
- }
- }
- }
- }
+ /* step through layers and classes to resolve symbol names */
+ for(i=0; i<map->numlayers; i++) {
+ for(j=0; j<GET_LAYER(map, i)->numclasses; j++) {
+ if(classResolveSymbolNames(GET_LAYER(map, i)->class[j]) != MS_SUCCESS) return MS_FAILURE;
}
+ }
- return MS_SUCCESS;
+ return MS_SUCCESS;
}
Modified: sandbox/sdlime/rfc-77/mapserver.h
===================================================================
--- sandbox/sdlime/rfc-77/mapserver.h 2011-11-18 13:56:59 UTC (rev 12787)
+++ sandbox/sdlime/rfc-77/mapserver.h 2011-11-19 00:37:17 UTC (rev 12788)
@@ -225,6 +225,7 @@
#define MS_LAYER_ALLOCSIZE 64
#define MS_CLASS_ALLOCSIZE 8
#define MS_STYLE_ALLOCSIZE 4
+#define MS_LABEL_ALLOCSIZE 1 /* not too common */
#define MS_MAX_LABEL_PRIORITY 10
#define MS_DEFAULT_LABEL_PRIORITY 1
@@ -991,16 +992,15 @@
styleObj **styles;
int maxstyles;
#endif
- int numstyles;
+ int numstyles; /* should be immutable */
-#ifdef SWIG
-%immutable;
-#endif /* SWIG */
- labelObj label;
-#ifdef SWIG
-%mutable;
-#endif /* SWIG */
+#ifndef SWIG
+ labelObj **labels;
+ int maxlabels;
+#endif
+ int numlabels; /* should be immutable */
+
char *name; /* should be unique within a layer */
char *title; /* used for legend labeling */
@@ -1702,6 +1702,7 @@
MS_DLL_EXPORT int initClass(classObj *_class);
MS_DLL_EXPORT int freeClass( classObj * );
MS_DLL_EXPORT styleObj *msGrowClassStyles( classObj *_class );
+MS_DLL_EXPORT labelObj *msGrowClassLabels( classObj *_class );
MS_DLL_EXPORT styleObj *msGrowLabelStyles( labelObj *label );
MS_DLL_EXPORT int msMaybeAllocateClassStyle(classObj* c, int idx);
MS_DLL_EXPORT void initLabel(labelObj *label);
More information about the mapserver-commits
mailing list