Skip to content

Commit

Permalink
msOGRUpdateStyle(): split it in 4 subfunctions. No functional change
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 1, 2014
1 parent 18ef92d commit 5ffa2f2
Showing 1 changed file with 75 additions and 24 deletions.
99 changes: 75 additions & 24 deletions mapogr.cpp
Expand Up @@ -2887,6 +2887,17 @@ static int msOGRGetSymbolId(symbolSetObj *symbolset, const char *pszSymbolId,
} }
#endif #endif


#ifdef USE_OGR

static int msOGRUpdateStyleParseLabel(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hLabelStyle);
static int msOGRUpdateStyleParsePen(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hPenStyle, int bIsBrush);
static int msOGRUpdateStyleParseBrush(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hBrushStyle, int* pbIsBrush);
static int msOGRUpdateStyleParseSymbol(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hSymbolStyle);

/********************************************************************** /**********************************************************************
* msOGRUpdateStyle() * msOGRUpdateStyle()
* *
Expand All @@ -2895,13 +2906,9 @@ static int msOGRGetSymbolId(symbolSetObj *symbolset, const char *pszSymbolId,
* msOGRUpdateStyleFromString * msOGRUpdateStyleFromString
**********************************************************************/ **********************************************************************/


#ifdef USE_OGR
static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer, classObj *c) static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer, classObj *c)
{ {
GBool bIsNull, bIsBrush=MS_FALSE; GBool bIsBrush=MS_FALSE;
int r=0,g=0,b=0,t=0;
double dfTmp;
int try_addimage_if_notfound = MS_FALSE;
int numParts = OGR_SM_GetPartCount(hStyleMgr, NULL); int numParts = OGR_SM_GetPartCount(hStyleMgr, NULL);


/* ------------------------------------------------------------------ /* ------------------------------------------------------------------
Expand All @@ -2928,7 +2935,34 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
OGR_ST_SetUnit(hStylePart, OGRSTUPixel, map->cellsize*72.0*39.37); OGR_ST_SetUnit(hStylePart, OGRSTUPixel, map->cellsize*72.0*39.37);


if (eStylePartType == OGRSTCLabel) { if (eStylePartType == OGRSTCLabel) {
OGRStyleToolH hLabelStyle = hStylePart; int ret = msOGRUpdateStyleParseLabel(map, layer, c, hStylePart);
if( ret != MS_SUCCESS )
return ret;
} else if (eStylePartType == OGRSTCPen) {
int ret = msOGRUpdateStyleParsePen(map, layer, c, hStylePart, bIsBrush);
if( ret != MS_SUCCESS )
return ret;
} else if (eStylePartType == OGRSTCBrush) {
int ret = msOGRUpdateStyleParseBrush(map, layer, c, hStylePart, &bIsBrush);
if( ret != MS_SUCCESS )
return ret;
} else if (eStylePartType == OGRSTCSymbol) {
int ret = msOGRUpdateStyleParseSymbol(map, layer, c, hStylePart);
if( ret != MS_SUCCESS )
return ret;
}

OGR_ST_Destroy(hStylePart);

}
return MS_SUCCESS;
}

static int msOGRUpdateStyleParseLabel(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hLabelStyle)
{
GBool bIsNull;
int r=0,g=0,b=0,t=0;


// Enclose the text string inside quotes to make sure it is seen // Enclose the text string inside quotes to make sure it is seen
// as a string by the parser inside loadExpression(). (bug185) // as a string by the parser inside loadExpression(). (bug185)
Expand Down Expand Up @@ -3073,8 +3107,15 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
if (!bFont) { if (!bFont) {
c->labels[0]->size = MS_MEDIUM; c->labels[0]->size = MS_MEDIUM;
} }
} else if (eStylePartType == OGRSTCPen) {
OGRStyleToolH hPenStyle = hStylePart; return MS_SUCCESS;
}

static int msOGRUpdateStyleParsePen(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hPenStyle, int bIsBrush)
{
GBool bIsNull;
int r=0,g=0,b=0,t=0;


const char *pszPenName, *pszPattern, *pszCap, *pszJoin; const char *pszPenName, *pszPattern, *pszCap, *pszJoin;
colorObj oPenColor; colorObj oPenColor;
Expand Down Expand Up @@ -3201,7 +3242,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
// This is a multipart symbology, so pen defn goes in the // This is a multipart symbology, so pen defn goes in the
// overlaysymbol params // overlaysymbol params
if (msMaybeAllocateClassStyle(c, 1)) { if (msMaybeAllocateClassStyle(c, 1)) {
OGR_ST_Destroy(hStylePart); OGR_ST_Destroy(hPenStyle);
return(MS_FAILURE); return(MS_FAILURE);
} }


Expand All @@ -3219,7 +3260,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
} else { } else {
// Single part symbology // Single part symbology
if (msMaybeAllocateClassStyle(c, 0)) { if (msMaybeAllocateClassStyle(c, 0)) {
OGR_ST_Destroy(hStylePart); OGR_ST_Destroy(hPenStyle);
return(MS_FAILURE); return(MS_FAILURE);
} }


Expand All @@ -3240,8 +3281,14 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
memcpy(c->styles[0]->pattern, pattern, sizeof(double) * patternlength); memcpy(c->styles[0]->pattern, pattern, sizeof(double) * patternlength);
} }


} else if (eStylePartType == OGRSTCBrush) { return MS_SUCCESS;
OGRStyleToolH hBrushStyle = hStylePart; }

static int msOGRUpdateStyleParseBrush(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hBrushStyle, int* pbIsBrush)
{
GBool bIsNull;
int r=0,g=0,b=0,t=0;


const char *pszBrushName = OGR_ST_GetParamStr(hBrushStyle, const char *pszBrushName = OGR_ST_GetParamStr(hBrushStyle,
OGRSTBrushId, OGRSTBrushId,
Expand All @@ -3250,7 +3297,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer


/* We need 1 style */ /* We need 1 style */
if (msMaybeAllocateClassStyle(c, 0)) { if (msMaybeAllocateClassStyle(c, 0)) {
OGR_ST_Destroy(hStylePart); OGR_ST_Destroy(hBrushStyle);
return(MS_FAILURE); return(MS_FAILURE);
} }


Expand All @@ -3259,7 +3306,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
if (pszBrushName && strstr(pszBrushName, "ogr-brush-1") != NULL) { if (pszBrushName && strstr(pszBrushName, "ogr-brush-1") != NULL) {
MS_INIT_COLOR(c->styles[0]->color, -1, -1, -1, 255); MS_INIT_COLOR(c->styles[0]->color, -1, -1, -1, 255);
} else { } else {
bIsBrush = TRUE; *pbIsBrush = TRUE;
const char *pszColor = OGR_ST_GetParamStr(hBrushStyle, const char *pszColor = OGR_ST_GetParamStr(hBrushStyle,
OGRSTBrushFColor, OGRSTBrushFColor,
&bIsNull); &bIsNull);
Expand Down Expand Up @@ -3312,12 +3359,19 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
} }
} }
} }
} else if (eStylePartType == OGRSTCSymbol) {
OGRStyleToolH hSymbolStyle = hStylePart; return MS_SUCCESS;
}

static int msOGRUpdateStyleParseSymbol(mapObj *map, layerObj *layer, classObj *c,
OGRStyleToolH hSymbolStyle)
{
GBool bIsNull;
int r=0,g=0,b=0,t=0;


/* We need 1 style */ /* We need 1 style */
if (msMaybeAllocateClassStyle(c, 0)) { if (msMaybeAllocateClassStyle(c, 0)) {
OGR_ST_Destroy(hStylePart); OGR_ST_Destroy(hSymbolStyle);
return(MS_FAILURE); return(MS_FAILURE);
} }


Expand All @@ -3343,7 +3397,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
c->styles[0]->angle = OGR_ST_GetParamNum(hSymbolStyle, c->styles[0]->angle = OGR_ST_GetParamNum(hSymbolStyle,
OGRSTSymbolAngle, OGRSTSymbolAngle,
&bIsNull); &bIsNull);
dfTmp = OGR_ST_GetParamNum(hSymbolStyle, OGRSTSymbolSize, &bIsNull); double dfTmp = OGR_ST_GetParamNum(hSymbolStyle, OGRSTSymbolSize, &bIsNull);
if (!bIsNull) if (!bIsNull)
c->styles[0]->size = dfTmp; c->styles[0]->size = dfTmp;


Expand All @@ -3357,7 +3411,7 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
if (bIsNull) if (bIsNull)
pszName = NULL; pszName = NULL;


try_addimage_if_notfound = MS_FALSE; int try_addimage_if_notfound = MS_FALSE;
#ifdef USE_CURL #ifdef USE_CURL
if (pszName && strncasecmp(pszName, "http", 4) == 0) if (pszName && strncasecmp(pszName, "http", 4) == 0)
try_addimage_if_notfound =MS_TRUE; try_addimage_if_notfound =MS_TRUE;
Expand All @@ -3366,13 +3420,10 @@ static int msOGRUpdateStyle(OGRStyleMgrH hStyleMgr, mapObj *map, layerObj *layer
c->styles[0]->symbol = msOGRGetSymbolId(&(map->symbolset), c->styles[0]->symbol = msOGRGetSymbolId(&(map->symbolset),
pszName, pszName,
"default-marker", try_addimage_if_notfound); "default-marker", try_addimage_if_notfound);
}


OGR_ST_Destroy(hStylePart); return MS_SUCCESS;

}
return MS_SUCCESS;
} }

#endif /* USE_OGR */ #endif /* USE_OGR */




Expand Down

0 comments on commit 5ffa2f2

Please sign in to comment.