?? ogrfeaturestyle.cpp
字號:
/****************************************************************************/
/* int OGRStyleMgr::GetPartCount(const char *pszStyleString) */
/* return the number of part in the stylestring */
/****************************************************************************/
int OGRStyleMgr::GetPartCount(const char *pszStyleString)
{
const char *pszPart;
int nPartCount = 1;
const char *pszString;
const char *pszStrTmp;
if (pszStyleString != NULL)
pszString = pszStyleString;
else
pszString = m_pszStyleString;
if (pszString == NULL)
return 0;
pszStrTmp = pszString;
while ((pszPart = strstr(pszStrTmp,";")) != NULL)
{
pszStrTmp = &pszPart[1];
nPartCount++;
}
return nPartCount;
}
/****************************************************************************/
/* OGRStyleTool *OGRStyleMgr::GetPart(int hPartId, */
/* const char *pszStyleString) */
/* */
/* Return a StyleTool of the type of the wanted part, could return NULL */
/****************************************************************************/
OGRStyleTool *OGRStyleMgr::GetPart(int hPartId,
const char *pszStyleString)
{
char **papszStyleString;
const char *pszStyle;
const char *pszString;
OGRStyleTool *poStyleTool;
if (pszStyleString)
pszStyle = pszStyleString;
else
pszStyle = m_pszStyleString;
if (pszStyle == NULL)
return NULL;
papszStyleString = CSLTokenizeString2(pszStyle, ";",
CSLT_HONOURSTRINGS
| CSLT_PRESERVEQUOTES
| CSLT_PRESERVEESCAPES );
pszString = CSLGetField( papszStyleString, hPartId );
if ( pszString || strlen(pszString) > 0 )
{
poStyleTool = CreateStyleToolFromStyleString(pszString);
if ( poStyleTool )
poStyleTool->SetStyleString(pszString);
CSLDestroy( papszStyleString );
return poStyleTool;
}
else
{
CSLDestroy(papszStyleString);
return NULL;
}
}
/****************************************************************************/
/* OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString) */
/* */
/* create a Style tool from the gived StyleString, it should contain only a */
/* part of a StyleString */
/****************************************************************************/
OGRStyleTool *OGRStyleMgr::CreateStyleToolFromStyleString(const char *
pszStyleString)
{
char **papszToken = CSLTokenizeString2(pszStyleString,"();",
CSLT_HONOURSTRINGS
| CSLT_PRESERVEQUOTES
| CSLT_PRESERVEESCAPES );
OGRStyleTool *poStyleTool;
if (CSLCount(papszToken) <2)
poStyleTool = NULL;
else if (EQUAL(papszToken[0],"PEN"))
poStyleTool = new OGRStylePen();
else if (EQUAL(papszToken[0],"BRUSH"))
poStyleTool = new OGRStyleBrush();
else if (EQUAL(papszToken[0],"SYMBOL"))
poStyleTool = new OGRStyleSymbol();
else if (EQUAL(papszToken[0],"LABEL"))
poStyleTool = new OGRStyleLabel();
else if (EQUAL(papszToken[0],"VECTOR"))
poStyleTool = new OGRStyleVector();
else
poStyleTool = NULL;
CSLDestroy( papszToken );
return poStyleTool;
}
/* ======================================================================== */
/* OGRStyleTable */
/* Object Used to manage and store a styletable */
/* ======================================================================== */
/****************************************************************************/
/* OGRStyleTable::OGRStyleTable() */
/* */
/****************************************************************************/
OGRStyleTable::OGRStyleTable()
{
m_papszStyleTable = NULL;
}
/****************************************************************************/
/* OGRStyleTable::~OGRStyleTable() */
/* */
/****************************************************************************/
OGRStyleTable::~OGRStyleTable()
{
Clear();
}
/****************************************************************************/
/* void OGRStyleTable::Clear() */
/* */
/****************************************************************************/
void OGRStyleTable::Clear()
{
if (m_papszStyleTable)
CSLDestroy(m_papszStyleTable);
m_papszStyleTable = NULL;
}
/****************************************************************************/
/* const char *OGRStyleTable::GetStyleName(const char *pszStyleString) */
/* */
/* return the Name of a gived stylestring otherwise NULL */
/****************************************************************************/
const char *OGRStyleTable::GetStyleName(const char *pszStyleString)
{
int i;
const char *pszStyleStringBegin;
static char *pszName = NULL;
char *pszTmp;
if (pszName)
CPLFree(pszName);
pszName = NULL;
for (i=0;i<CSLCount(m_papszStyleTable);i++)
{
pszStyleStringBegin = strstr(m_papszStyleTable[i],":");
if (pszStyleStringBegin && EQUAL(&pszStyleStringBegin[1],
pszStyleString))
{
pszName = CPLStrdup(m_papszStyleTable[i]);
pszTmp = strstr(pszName,":");
if (pszTmp)
pszTmp[0] = '\0';
break;
}
}
return pszName;
}
/****************************************************************************/
/* GBool OGRStyleTable::AddStyle(char *pszName, */
/* char *pszStyleString) */
/* */
/* Add a new style in the table, no comparaison will be done on the */
/* Style string, only on the name, TRUE success, FALSE error */
/****************************************************************************/
GBool OGRStyleTable::AddStyle(const char *pszName, const char *pszStyleString)
{
int nPos;
const char *pszNewString = NULL;
if (pszName && pszStyleString)
{
if ((nPos = IsExist(pszName)) != -1)
return FALSE;
pszNewString = CPLSPrintf("%s:%s",pszName,pszStyleString);
m_papszStyleTable = CSLAddString(m_papszStyleTable,pszNewString);
return TRUE;
}
return FALSE;
}
/****************************************************************************/
/* GBool OGRStyleTable::RemoveStyle(char *pszName) */
/* */
/* Remove the gived style in the table based on the name, return TRUE */
/* on success otherwise FALSE */
/****************************************************************************/
GBool OGRStyleTable::RemoveStyle(const char *pszName)
{
int nPos;
if ((nPos = IsExist(pszName)) != -1)
{
m_papszStyleTable = CSLRemoveStrings(m_papszStyleTable,nPos,1,NULL);
return TRUE;
}
return FALSE;
}
/****************************************************************************/
/* GBool OGRStyleTable::ModifyStyle(char *pszName, */
/* char *pszStyleString) */
/* */
/* Modify the gived style, if the style doesn't exist, it will be added */
/* return TRUE on success otherwise return FALSE */
/****************************************************************************/
GBool OGRStyleTable::ModifyStyle(const char *pszName,
const char * pszStyleString)
{
if (pszName == NULL || pszStyleString == NULL)
return FALSE;
RemoveStyle(pszName);
return AddStyle(pszName, pszStyleString);
}
/****************************************************************************/
/* GBool OGRStyleTable::SaveStyleTable(char *) */
/* */
/* Save the StyleTable in the gived file, return TRUE on success */
/* otherwise return FALSE */
/****************************************************************************/
GBool OGRStyleTable::SaveStyleTable(const char *pszFilename)
{
if (pszFilename == NULL)
return FALSE;
if (CSLSave(m_papszStyleTable,pszFilename) == 0)
return FALSE;
else
return TRUE;
}
/****************************************************************************/
/* GBool OGRStyleTable::LoadStyleTable(char *) */
/* */
/* Read the Style table from a file, return TRUE on success */
/* otherwise return FALSE */
/****************************************************************************/
GBool OGRStyleTable::LoadStyleTable(const char *pszFilename)
{
if (pszFilename == NULL)
return FALSE;
CSLDestroy(m_papszStyleTable);
m_papszStyleTable = CSLLoad(pszFilename);
if (m_papszStyleTable == NULL)
return FALSE;
else
return TRUE;
}
/****************************************************************************/
/* const char *OGRStyleTable::Find(const char *pszName) */
/* */
/* return the StyleString based on the gived name, */
/* otherwise return NULL */
/****************************************************************************/
const char *OGRStyleTable::Find(const char *pszName)
{
const char *pszDash = NULL;
const char *pszOutput = NULL;
int nPos;
if ((nPos = IsExist(pszName)) != -1)
{
pszOutput = CSLGetField(m_papszStyleTable,nPos);
pszDash = strstr(pszOutput,":");
if (pszDash)
return &pszDash[1];
}
return NULL;
}
/****************************************************************************/
/* OGRStyleTable::Print(FILE *fpOut) */
/* */
/****************************************************************************/
void OGRStyleTable::Print(FILE *fpOut)
{
VSIFPrintf(fpOut,"#OFS-Version: 1.0\n");
VSIFPrintf(fpOut,"#StyleField: style\n");
if (m_papszStyleTable)
{
CSLPrint(m_papszStyleTable,fpOut);
}
}
/****************************************************************************/
/* GBool OGRStyleTable::IsExist(const char *pszName) */
/* */
/* return a index of the style in the table otherwise return -1 */
/****************************************************************************/
int OGRStyleTable::IsExist(const char *pszName)
{
int i;
const char *pszNewString;
if (pszName == NULL)
return -1;
pszNewString = CPLSPrintf("%s:",pszName);
for (i=0;i<CSLCount(m_papszStyleTable);i++)
{
if (strstr(m_papszStyleTable[i],pszNewString) != NULL)
{
return i;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -