Skip to content

Commit

Permalink
Modify the graticule layer to store settings in a custom object inste…
Browse files Browse the repository at this point in the history
…ad of layerinfo (#4913)
  • Loading branch information
szekerest committed Apr 27, 2014
1 parent 1d64d27 commit a5348b8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 43 deletions.
41 changes: 41 additions & 0 deletions mapcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,36 @@ int msCopyCluster(clusterObj *dst, clusterObj *src)
return MS_SUCCESS;
}

/***********************************************************************
* msCopyGrid() *
**********************************************************************/

int msCopyGrid(graticuleObj *dst, graticuleObj *src)
{
MS_COPYSTELEM(dwhichlatitude);
MS_COPYSTELEM(dwhichlongitude);
MS_COPYSTELEM(dstartlatitude);
MS_COPYSTELEM(dstartlongitude);
MS_COPYSTELEM(dendlatitude);
MS_COPYSTELEM(dendlongitude);
MS_COPYSTELEM(dincrementlatitude);
MS_COPYSTELEM(dincrementlongitude);
MS_COPYSTELEM(minarcs);
MS_COPYSTELEM(maxarcs);
MS_COPYSTELEM(minincrement);
MS_COPYSTELEM(maxincrement);
MS_COPYSTELEM(minsubdivides);
MS_COPYSTELEM(maxsubdivides);
MS_COPYSTELEM(bvertical);
MS_COPYSTELEM(blabelaxes);
MS_COPYSTELEM(ilabelstate);
MS_COPYSTELEM(ilabeltype);
MS_COPYRECT(&(dst->extent), &(src->extent));
MS_COPYSTRING(dst->labelformat, src->labelformat);

return MS_SUCCESS;
}

#ifdef why_on_earth_would_you_copy_a_labelcache

/***********************************************************************
Expand Down Expand Up @@ -1053,6 +1083,17 @@ int msCopyLayer(layerObj *dst, layerObj *src)
MS_COPYSTRING(dst->classgroup, src->classgroup);
MS_COPYSTRING(dst->mask, src->mask);

if (src->grid) {
if (dst->grid) {
freeGrid(dst->grid);
msFree(dst->grid);
}
dst->grid = (void *) malloc(sizeof(graticuleObj));
MS_CHECK_ALLOC(dst->grid, sizeof(graticuleObj), -1);
initGrid(dst->grid);
msCopyGrid(dst->grid, src->grid);
}

return MS_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion mapdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ int msLayerIsVisible(mapObj *map, layerObj *layer)
{
int i;

if(!layer->data && !layer->tileindex && !layer->connection && !layer->features && !layer->layerinfo)
if(!layer->data && !layer->tileindex && !layer->connection && !layer->features && !layer->grid)
return(MS_FALSE); /* no data associated with this layer, not an error since layer may be used as a template from MapScript */

if(layer->type == MS_LAYER_QUERY || layer->type == MS_LAYER_TILEINDEX) return(MS_FALSE);
Expand Down
43 changes: 30 additions & 13 deletions mapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,13 @@ void initGrid( graticuleObj *pGraticule )
memset( pGraticule, 0, sizeof( graticuleObj ) );
}

void freeGrid( graticuleObj *pGraticule )
{
msFree(pGraticule->labelformat);
msFree(pGraticule->pboundingpoints);
msFree(pGraticule->pboundinglines);
}

static int loadGrid( layerObj *pLayer )
{
for(;;) {
Expand All @@ -1041,35 +1048,35 @@ static int loadGrid( layerObj *pLayer )
case(GRID):
break; /* for string loads */
case( LABELFORMAT ):
if(getString(&((graticuleObj *)pLayer->layerinfo)->labelformat) == MS_FAILURE) {
if(getString(&(pLayer->grid->labelformat)) == MS_FAILURE) {
if(strcasecmp(msyystring_buffer, "DD") == 0) /* DD triggers a symbol to be returned instead of a string so check for this special case */
((graticuleObj *)pLayer->layerinfo)->labelformat = msStrdup("DD");
pLayer->grid->labelformat = msStrdup("DD");
else
return(-1);
}
break;
case( MINARCS ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->minarcs) == -1)
if(getDouble(&(pLayer->grid->minarcs)) == -1)
return(-1);
break;
case( MAXARCS ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->maxarcs) == -1)
if(getDouble(&(pLayer->grid->maxarcs)) == -1)
return(-1);
break;
case( MININTERVAL ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->minincrement) == -1)
if(getDouble(&(pLayer->grid->minincrement)) == -1)
return(-1);
break;
case( MAXINTERVAL ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->maxincrement) == -1)
if(getDouble(&(pLayer->grid->maxincrement)) == -1)
return(-1);
break;
case( MINSUBDIVIDE ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->minsubdivides) == -1)
if(getDouble(&(pLayer->grid->minsubdivides)) == -1)
return(-1);
break;
case( MAXSUBDIVIDE ):
if(getDouble(&((graticuleObj *)pLayer->layerinfo)->maxsubdivides) == -1)
if(getDouble(&(pLayer->grid->maxsubdivides)) == -1)
return(-1);
break;
default:
Expand Down Expand Up @@ -3803,6 +3810,7 @@ int initLayer(layerObj *layer, mapObj *map)

layer->mask = NULL;
layer->maskimage = NULL;
layer->grid = NULL;

initExpression(&(layer->_geomtransform));
layer->_geomtransform.type = MS_GEOMTRANSFORM_NONE;
Expand Down Expand Up @@ -3932,6 +3940,11 @@ int freeLayer(layerObj *layer)
msFreeImage(layer->maskimage);
}

if (layer->grid) {
freeGrid(layer->grid);
msFree(layer->grid);
}

freeExpression(&(layer->utfdata));
msFree(layer->utfitem);

Expand Down Expand Up @@ -4216,10 +4229,14 @@ int loadLayer(layerObj *layer, mapObj *map)
break;
case(GRID):
layer->connectiontype = MS_GRATICULE;
layer->layerinfo = (void *) malloc(sizeof(graticuleObj));
MS_CHECK_ALLOC(layer->layerinfo, sizeof(graticuleObj), -1);
if (layer->grid) {
freeGrid(layer->grid);
msFree(layer->grid);
}
layer->grid = (void *) malloc(sizeof(graticuleObj));
MS_CHECK_ALLOC(layer->grid, sizeof(graticuleObj), -1);

initGrid((graticuleObj *) layer->layerinfo);
initGrid(layer->grid);
loadGrid(layer);
break;
case(GROUP):
Expand Down Expand Up @@ -4610,8 +4627,8 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer)
for(i=0; i<layer->numjoins; i++) writeJoin(stream, indent, &(layer->joins[i]));
for(i=0; i<layer->numclasses; i++) writeClass(stream, indent, layer->class[i]);

if( layer->layerinfo && layer->connectiontype == MS_GRATICULE)
writeGrid(stream, indent, (graticuleObj *) layer->layerinfo);
if( layer->grid && layer->connectiontype == MS_GRATICULE)
writeGrid(stream, indent, layer->grid);
else {
current = layer->features;
while(current != NULL) {
Expand Down
40 changes: 11 additions & 29 deletions mapgraticule.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int msGraticuleLayerInitItemInfo(layerObj *layer);
*/
int msGraticuleLayerOpen(layerObj *layer)
{
graticuleObj *pInfo = (graticuleObj *) layer->layerinfo;
graticuleObj *pInfo = layer->grid;

if( pInfo == NULL )
return MS_FAILURE;
Expand Down Expand Up @@ -115,7 +115,7 @@ int msGraticuleLayerOpen(layerObj *layer)
*/
int msGraticuleLayerIsOpen(layerObj *layer)
{
if(layer->layerinfo)
if(layer->grid)
return MS_TRUE;

return MS_FALSE;
Expand All @@ -127,26 +127,6 @@ int msGraticuleLayerIsOpen(layerObj *layer)
*/
int msGraticuleLayerClose(layerObj *layer)
{
graticuleObj *pInfo = (graticuleObj *) layer->layerinfo;

if( pInfo->labelformat ) {
free( pInfo->labelformat );
pInfo->labelformat = NULL;
}

if( pInfo->pboundingpoints ) {
free( pInfo->pboundingpoints );
pInfo->pboundingpoints = NULL;
}

if( pInfo->pboundinglines ) {
free( pInfo->pboundinglines );
pInfo->pboundinglines = NULL;
}

free(layer->layerinfo);
layer->layerinfo=NULL;

return MS_SUCCESS;
}

Expand All @@ -155,7 +135,7 @@ int msGraticuleLayerClose(layerObj *layer)
*/
int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
{
graticuleObj *pInfo = (graticuleObj *) layer->layerinfo;
graticuleObj *pInfo = layer->grid;
int iAxisTickCount = 0;
rectObj rectMapCoordinates;

Expand Down Expand Up @@ -207,7 +187,9 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
* These lines will be used when generating labels to get correct placement at arc/rect edge intersections.
*/
rectMapCoordinates = layer->map->extent;
msFree(pInfo->pboundinglines);
pInfo->pboundinglines = (lineObj *) msSmallMalloc( sizeof( lineObj ) * 4 );
msFree(pInfo->pboundingpoints);
pInfo->pboundingpoints = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 8 );

{
Expand Down Expand Up @@ -289,7 +271,7 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
*/
int msGraticuleLayerNextShape(layerObj *layer, shapeObj *shape)
{
graticuleObj *pInfo = (graticuleObj *) layer->layerinfo;
graticuleObj *pInfo = layer->grid;

if( pInfo->minsubdivides <= 0.0 || pInfo->maxsubdivides <= 0.0 )
pInfo->minsubdivides = pInfo->maxsubdivides = MAPGRATICULE_ARC_SUBDIVISION_DEFAULT;
Expand Down Expand Up @@ -535,7 +517,7 @@ int msGraticuleLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record
*/
int msGraticuleLayerGetExtent(layerObj *layer, rectObj *extent)
{
graticuleObj *pInfo = (graticuleObj *) layer->layerinfo;
graticuleObj *pInfo = layer->grid;

if(pInfo) {
*extent = pInfo->extent;
Expand Down Expand Up @@ -638,7 +620,7 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map,
if (layer->connectiontype != MS_GRATICULE)
return NULL;

pInfo = (graticuleObj *) layer->layerinfo;
pInfo = layer->grid;

/*set cellsize if bnot already set*/
if (map->cellsize == 0)
Expand Down Expand Up @@ -1009,7 +991,7 @@ int msGraticuleLayerInitializeVirtualTable(layerObj *layer)
*/
static void _FormatLabel( layerObj *pLayer, shapeObj *pShape, double dDataToFormat )
{
graticuleObj *pInfo = (graticuleObj *) pLayer->layerinfo;
graticuleObj *pInfo = pLayer->grid;
char cBuffer[32];
int iDegrees, iMinutes;

Expand Down Expand Up @@ -1044,14 +1026,14 @@ static void _FormatLabel( layerObj *pLayer, shapeObj *pShape, double dDataToForm
*/
static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticulePosition ePosition )
{
graticuleObj *pInfo = (graticuleObj *) pLayer->layerinfo;
graticuleObj *pInfo = pLayer->grid;
rectObj rectLabel;
pointObj ptPoint;
double size = -1;
char *labeltxt;

if( pInfo == NULL || pShape == NULL ) {
msSetError(MS_MISCERR, "Assertion failed: Null shape or layerinfo!, ", "_AdjustLabelPosition()");
msSetError(MS_MISCERR, "Assertion failed: Null shape or non-configured grid!, ", "_AdjustLabelPosition()");
return MS_FAILURE;
}

Expand Down
1 change: 1 addition & 0 deletions mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ extern "C" {

#ifndef SWIG
imageObj *maskimage;
graticuleObj* grid;
#endif
char *mask;

Expand Down

0 comments on commit a5348b8

Please sign in to comment.