📄 tabfontpoint.cpp
字号:
// tabfontpoint.cpp: implementation of the TABFontPoint class.////////////////////////////////////////////////////////////////////////#include "tabfontpoint.h"#include "ugk_errhandle.h"#include "ugk_string.h"#include "ugkpoint.h"#include "tabmapobjfontpoint.h"/********************************************************************** * TABFontPoint::TABFontPoint() * * Constructor. **********************************************************************/TABFontPoint::TABFontPoint(UGKFeatureDefn *poDefnIn): TABPoint(poDefnIn){ m_nFontStyle = 0; m_dAngle = 0.0;}/********************************************************************** * TABFontPoint::~TABFontPoint() * * Destructor. **********************************************************************/TABFontPoint::~TABFontPoint(){}/********************************************************************** * TABFontPoint::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * This method calls the generic TABFeature::CloneTABFeature() and * then copies any members specific to its own type. **********************************************************************/TABFeature *TABFontPoint::CloneTABFeature(UGKFeatureDefn *poNewDefn /*=NULL*/){ /*----------------------------------------------------------------- * Alloc new feature and copy the base stuff *----------------------------------------------------------------*/ TABFontPoint *poNew = new TABFontPoint(poNewDefn ? poNewDefn : GetDefnRef()); CopyTABFeatureBase(poNew); /*----------------------------------------------------------------- * And members specific to this class *----------------------------------------------------------------*/ // ITABFeatureSymbol *(poNew->GetSymbolDefRef()) = *GetSymbolDefRef(); // ITABFeatureFont *(poNew->GetFontDefRef()) = *GetFontDefRef(); poNew->SetSymbolAngle( GetSymbolAngle() ); poNew->SetFontStyleTABValue( GetFontStyleTABValue() ); return poNew;}/********************************************************************** * TABFontPoint::ReadGeometryFromMAPFile() * * Fill the geometry and representation (color, etc...) part of the * feature from the contents of the .MAP object pointed to by poMAPFile. * * It is assumed that poMAPFile currently points to the beginning of * a map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFontPoint::ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr) //第二个参数根本没用{ UGKInt32 nX, nY; double dX, dY; UGKGeometry *poGeometry; TABMAPObjectBlock *poObjBlock; UGKBool bComprCoord; /*----------------------------------------------------------------- * Fetch and validate geometry type *----------------------------------------------------------------*/ m_nMapInfoType = poMapFile->GetCurObjType(); //第1字节对象类型 //接下来2-5为对象ID poObjBlock = poMapFile->GetCurObjBlock(); bComprCoord = (m_nMapInfoType == TAB_GEOM_FONTSYMBOL_C );//如果是TAB_GEOM_FONTSYMBOL_C类型则为压缩坐标 /*----------------------------------------------------------------- * Read object information * NOTE: This symbol type does not contain a reference to a * SymbolDef block in the file, but we still use the m_sSymbolDef * structure to store the information inside the class so that the * ITABFeatureSymbol methods work properly for the class user. *----------------------------------------------------------------*/ if (m_nMapInfoType == TAB_GEOM_FONTSYMBOL || //不是压缩坐标,对象块为26字节 m_nMapInfoType == TAB_GEOM_FONTSYMBOL_C ) //压缩坐标,对象块为22字节 { m_nSymbolDefIndex = -1; m_sSymbolDef.nRefCount = 0; m_sSymbolDef.nSymbolNo = poObjBlock->ReadByte(); // shape 第6字节 m_sSymbolDef.nPointSize = poObjBlock->ReadByte(); // point size 第7字节 m_nFontStyle = poObjBlock->ReadInt16(); // font style 第8,9字节 m_sSymbolDef.rgbColor = poObjBlock->ReadByte()*256*256 + //第10字节 poObjBlock->ReadByte()*256 + //第11字节 poObjBlock->ReadByte(); //第12字节 poObjBlock->ReadByte(); // ??? BG Color ??? 第13字节 poObjBlock->ReadByte(); // ??? 第14字节 poObjBlock->ReadByte(); // ??? 第15字节 /*------------------------------------------------------------- * Symbol Angle, in thenths of degree. * Contrary to arc start/end angles, no conversion based on * origin quadrant is required here *------------------------------------------------------------*/ m_dAngle = poObjBlock->ReadInt16()/10.0; //第16,17字节 poObjBlock->ReadIntCoord(bComprCoord, nX, nY); //如果是压缩坐标就是 18-21字节 //不是压缩坐标,就是18-25字节 m_nFontDefIndex = poObjBlock->ReadByte(); // Font name index 22或26字节 poMapFile->ReadFontDef(m_nFontDefIndex, &m_sFontDef); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)", m_nMapInfoType, m_nMapInfoType); return -1; } /*----------------------------------------------------------------- * Create and fill geometry object *----------------------------------------------------------------*/ poMapFile->Int2Coordsys(nX, nY, dX, dY); //将其转换为坐标系统 ??(须研究一下) poGeometry = new UGKPoint(dX, dY); SetGeometryDirectly(poGeometry); SetMBR(dX, dY, dX, dY); return 0;}/********************************************************************** * TABFontPoint::WriteGeometryToMAPFile() * * Write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that poMAPFile currently points to a valid map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFontPoint::WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr){ UGKInt32 nX, nY; UGKGeometry *poGeom; UGKPoint *poPoint; /*----------------------------------------------------------------- * We assume that ValidateMapInfoType() was called already and that * the type in poObjHdr->m_nType is valid. *----------------------------------------------------------------*/ assert(m_nMapInfoType == poObjHdr->m_nType); /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) poPoint = (UGKPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABFontPoint: Missing or Invalid Geometry!"); return -1; } poMapFile->Coordsys2Int(poPoint->getX(), poPoint->getY(), nX, nY); /*----------------------------------------------------------------- * Copy object information * NOTE: This symbol type does not contain a reference to a * SymbolDef block in the file, but we still use the m_sSymbolDef * structure to store the information inside the class so that the * ITABFeatureSymbol methods work properly for the class user. *----------------------------------------------------------------*/ TABMAPObjFontPoint *poPointHdr = (TABMAPObjFontPoint *)poObjHdr; poPointHdr->m_nX = nX; poPointHdr->m_nY = nY; poPointHdr->SetMBR(nX, nY, nX, nY); poPointHdr->m_nSymbolId = (UGKByte)m_sSymbolDef.nSymbolNo; // shape poPointHdr->m_nPointSize = (UGKByte)m_sSymbolDef.nPointSize; // point size poPointHdr->m_nFontStyle = m_nFontStyle; // font style poPointHdr->m_nR = COLOR_R(m_sSymbolDef.rgbColor); poPointHdr->m_nG = COLOR_G(m_sSymbolDef.rgbColor); poPointHdr->m_nB = COLOR_B(m_sSymbolDef.rgbColor); /*------------------------------------------------------------- * Symbol Angle, in thenths of degree. * Contrary to arc start/end angles, no conversion based on * origin quadrant is required here *------------------------------------------------------------*/ poPointHdr->m_nAngle = ROUND_INT(m_dAngle * 10.0); // Write Font Def m_nFontDefIndex = poMapFile->WriteFontDef(&m_sFontDef); poPointHdr->m_nFontId = m_nFontDefIndex; // Font name index if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABFontPoint::QueryFontStyle() * * Return TRUE if the specified font style attribute is turned ON, * or FALSE otherwise. See enum TABFontStyle for the list of styles * that can be queried on. **********************************************************************/UGKBool TABFontPoint::QueryFontStyle(TABFontStyle eStyleToQuery){ return (m_nFontStyle & (int)eStyleToQuery) ? TRUE: FALSE;}void TABFontPoint::ToggleFontStyle(TABFontStyle eStyleToToggle, UGKBool bStyleOn){ if (bStyleOn) m_nFontStyle |= (int)eStyleToToggle; else m_nFontStyle &= ~(int)eStyleToToggle;}/********************************************************************** * TABFontPoint::GetFontStyleMIFValue() * * Return the Font Style value for this object using the style values * that are used in a MIF FONT() clause. See MIF specs (appendix A). * * The reason why we have to differentiate between the TAB and the MIF font * style values is that in TAB, TABFSBox is included in the style value * as code 0x100, but in MIF it is not included, instead it is implied by * the presence of the BG color in the FONT() clause (the BG color is * present only when TABFSBox or TABFSHalo is set). * This also has the effect of shifting all the other style values > 0x100 * by 1 byte. * * NOTE: Even if there is no BG color for font symbols, we inherit this * problem because Font Point styles use the same codes as Text Font styles. **********************************************************************/int TABFontPoint::GetFontStyleMIFValue(){ // The conversion is simply to remove bit 0x100 from the value and shift // down all values past this bit. return (m_nFontStyle & 0xff) + (m_nFontStyle & (0xff00-0x0100))/2;}void TABFontPoint:: SetFontStyleMIFValue(int nStyle){ m_nFontStyle = (nStyle & 0xff) + (nStyle & 0x7f00)*2;}/********************************************************************** * TABFontPoint::SetSymbolAngle() * * Set the symbol angle value in degrees, making sure the value is * always in the range [0..360] **********************************************************************/void TABFontPoint::SetSymbolAngle(double dAngle){ while(dAngle < 0.0) dAngle += 360.0; while(dAngle > 360.0) dAngle -= 360.0; m_dAngle = dAngle;}/********************************************************************** * TABFontPoint::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABFontPoint::GetStyleString(){ if (m_pszStyleString == NULL) { m_pszStyleString = UGKStrdup(GetSymbolStyleString(GetSymbolAngle())); } return m_pszStyleString;}/********************************************************************** * **********************************************************************/int TABFontPoint::ReadGeometryFromMIFFile(MIDDATAFile *fp){ UGKGeometry *poGeometry; char **papszToken; const char *pszLine; double dfX,dfY; papszToken = TokenizeString2(fp->GetSavedLine(), " \t", 0x0001); if (CountOfList(papszToken) !=3) { FreeStrList(papszToken); return -1; } dfX = fp->GetXTrans(atof(papszToken[1])); dfY = fp->GetYTrans(atof(papszToken[2])); FreeStrList(papszToken); papszToken = TokenizeStringComplex(fp->GetLastLine()," ,()\t", TRUE,FALSE); if (CountOfList(papszToken) !=7) { FreeStrList(papszToken); return -1; } SetSymbolNo(atoi(papszToken[1])); SetSymbolColor(atoi(papszToken[2])); SetSymbolSize(atoi(papszToken[3])); SetFontName(papszToken[4]); SetFontStyleMIFValue(atoi(papszToken[5])); SetSymbolAngle(atof(papszToken[6])); FreeStrList(papszToken); poGeometry = new UGKPoint(dfX, dfY); SetGeometryDirectly(poGeometry); SetMBR(dfX, dfY, dfX, dfY); /* Go to the first line of the next feature */ while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) ; return 0; }/********************************************************************** * **********************************************************************/int TABFontPoint::WriteGeometryToMIFFile(MIDDATAFile *fp){ UGKGeometry *poGeom; UGKPoint *poPoint; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) poPoint = (UGKPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABFontPoint: Missing or Invalid Geometry!"); return -1; } fp->WriteLine("Point %.16g %.16g\n",poPoint->getX(),poPoint->getY()); fp->WriteLine(" Symbol (%d,%d,%d,\"%s\",%d,%.16g)\n", GetSymbolNo(),GetSymbolColor(), GetSymbolSize(),GetFontNameRef(),GetFontStyleMIFValue(), GetSymbolAngle()); return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -