📄 tabrectangle.cpp
字号:
poRectHdr->m_nMaxX, poRectHdr->m_nMaxY); m_nPenDefIndex = poMapFile->WritePenDef(&m_sPenDef); poRectHdr->m_nPenId = m_nPenDefIndex; // Pen index m_nBrushDefIndex = poMapFile->WriteBrushDef(&m_sBrushDef); poRectHdr->m_nBrushId = m_nBrushDefIndex; // Brush index if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABRectangle::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABRectangle::GetStyleString(){ if (m_pszStyleString == NULL) { // Since GetPen/BrushStyleString() use CPLSPrintf(), we need // to use temporary buffers char *pszPen = UGKStrdup(GetPenStyleString()); char *pszBrush = UGKStrdup(GetBrushStyleString()); m_pszStyleString = UGKStrdup(UGKSPrintf("%s;%s", pszBrush, pszPen)); UGK_Free(pszPen); UGK_Free(pszBrush); } return m_pszStyleString;}/********************************************************************** * TABRectangle::DumpMIF() * * Dump feature geometry in a format similar to .MIF REGIONs. **********************************************************************/void TABRectangle::DumpMIF(FILE *fpOut /*=NULL*/){ UGKGeometry *poGeom; UGKPolygon *poPolygon = NULL; int i, numPoints; if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Output RECT or ROUNDRECT parameters *----------------------------------------------------------------*/ double dXMin, dYMin, dXMax, dYMax; GetMBR(dXMin, dYMin, dXMax, dYMax); if (m_bRoundCorners) fprintf(fpOut, "(ROUNDRECT %g %g %g %g %g %g)\n", dXMin, dYMin, dXMax, dYMax, m_dRoundXRadius, m_dRoundYRadius); else fprintf(fpOut, "(RECT %g %g %g %g)\n", dXMin, dYMin, dXMax, dYMax); /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon) { /*------------------------------------------------------------- * Generate rectangle output as a region * We could also output as a RECT or ROUNDRECT in a real MIF generator *------------------------------------------------------------*/ int iRing, numIntRings; poPolygon = (UGKPolygon*)poGeom; numIntRings = poPolygon->getNumInteriorRings(); fprintf(fpOut, "REGION %d\n", numIntRings+1); // In this loop, iRing=-1 for the outer ring. for(iRing=-1; iRing < numIntRings; iRing++) { UGKLinearRing *poRing; if (iRing == -1) poRing = poPolygon->getExteriorRing(); else poRing = poPolygon->getInteriorRing(iRing); if (poRing == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABRectangle: Object Geometry contains NULL rings!"); return; } numPoints = poRing->getNumPoints(); fprintf(fpOut, " %d\n", numPoints); for(i=0; i<numPoints; i++) fprintf(fpOut, "%g %g\n",poRing->getX(i),poRing->getY(i)); } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABRectangle: Missing or Invalid Geometry!"); return; } // Finish with PEN/BRUSH/etc. clauses DumpPenDef(); DumpBrushDef(); fflush(fpOut);}/********************************************************************** * **********************************************************************/int TABRectangle::ReadGeometryFromMIFFile(MIDDATAFile *fp){ const char *pszLine; char **papszToken; double dXMin, dYMin, dXMax, dYMax; UGKPolygon *poPolygon; UGKLinearRing *poRing; papszToken = TokenizeString2(fp->GetLastLine(), " \t", 0x0001); if (CountOfList(papszToken) < 5) { FreeStrList(papszToken); return -1; } dXMin = fp->GetXTrans(atof(papszToken[1])); dXMax = fp->GetXTrans(atof(papszToken[3])); dYMin = fp->GetYTrans(atof(papszToken[2])); dYMax = fp->GetYTrans(atof(papszToken[4])); /*----------------------------------------------------------------- * Call SetMBR() and GetMBR() now to make sure that min values are * really smaller than max values. *----------------------------------------------------------------*/ SetMBR(dXMin, dYMin, dXMax, dYMax); GetMBR(dXMin, dYMin, dXMax, dYMax); m_bRoundCorners = FALSE; m_dRoundXRadius = 0.0; m_dRoundYRadius = 0.0; if (EQUALN(papszToken[0],"ROUNDRECT",9)) { m_bRoundCorners = TRUE; if (CountOfList(papszToken) == 6) m_dRoundXRadius = m_dRoundYRadius = atof(papszToken[5])/2.0; else { FreeStrList(papszToken); papszToken = TokenizeString2(fp->GetLine(), " \t", 0x0001); if (CountOfList(papszToken) !=1 ) m_dRoundXRadius = m_dRoundYRadius = atof(papszToken[1])/2.0; } } FreeStrList(papszToken); papszToken = NULL; /*----------------------------------------------------------------- * Create and fill geometry object *----------------------------------------------------------------*/ poPolygon = new UGKPolygon; poRing = new UGKLinearRing(); if (m_bRoundCorners && m_dRoundXRadius != 0.0 && m_dRoundYRadius != 0.0) { /*------------------------------------------------------------- * For rounded rectangles, we generate arcs with 45 line * segments for each corner. We start with lower-left corner * and proceed counterclockwise * We also have to make sure that rounding radius is not too * large for the MBR however, we * always return the true X/Y radius (not adjusted) since this * is the way MapInfo seems to do it when a radius bigger than * the MBR is passed from TBA to MIF. *------------------------------------------------------------*/ double dXRadius = MIN(m_dRoundXRadius, (dXMax-dXMin)/2.0); double dYRadius = MIN(m_dRoundYRadius, (dYMax-dYMin)/2.0); TABGenerateArc(poRing, 45, dXMin + dXRadius, dYMin + dYRadius, dXRadius, dYRadius, PI, 3.0*PI/2.0); TABGenerateArc(poRing, 45, dXMax - dXRadius, dYMin + dYRadius, dXRadius, dYRadius, 3.0*PI/2.0, 2.0*PI); TABGenerateArc(poRing, 45, dXMax - dXRadius, dYMax - dYRadius, dXRadius, dYRadius, 0.0, PI/2.0); TABGenerateArc(poRing, 45, dXMin + dXRadius, dYMax - dYRadius, dXRadius, dYRadius, PI/2.0, PI); TABCloseRing(poRing); } else { poRing->addPoint(dXMin, dYMin); poRing->addPoint(dXMax, dYMin); poRing->addPoint(dXMax, dYMax); poRing->addPoint(dXMin, dYMax); poRing->addPoint(dXMin, dYMin); } poPolygon->addRingDirectly(poRing); SetGeometryDirectly(poPolygon); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = TokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CountOfList(papszToken) > 1) { if (EQUALN(papszToken[0],"PEN",3)) { if (CountOfList(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } else if (EQUALN(papszToken[0],"BRUSH", 5)) { if (CountOfList(papszToken) >=3) { SetBrushFGColor(atoi(papszToken[2])); SetBrushPattern(atoi(papszToken[1])); if (CountOfList(papszToken) == 4) SetBrushBGColor(atoi(papszToken[3])); else SetBrushTransparent(TRUE); } } } FreeStrList(papszToken); papszToken = NULL; } return 0; } /********************************************************************** * **********************************************************************/int TABRectangle::WriteGeometryToMIFFile(MIDDATAFile *fp){ UGKGeometry *poGeom; UGKPolygon *poPolygon; UGKEnvelope sEnvelope; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon) poPolygon = (UGKPolygon*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABRectangle: Missing or Invalid Geometry!"); return -1; } /*----------------------------------------------------------------- * Note that we will simply use the rectangle's MBR and don't really * read the polygon geometry... this should be OK unless the * polygon geometry was not really a rectangle. *----------------------------------------------------------------*/ poPolygon->getEnvelope(&sEnvelope); if (m_bRoundCorners == TRUE) { fp->WriteLine("Roundrect %.16g %.16g %.16g %.16g %.16g\n", sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX, sEnvelope.MaxY, m_dRoundXRadius*2.0); } else { fp->WriteLine("Rect %.16g %.16g %.16g %.16g\n", sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX, sEnvelope.MaxY); } if (GetPenPattern()) fp->WriteLine(" Pen (%d,%d,%d)\n",GetPenWidthMIF(),GetPenPattern(), GetPenColor()); if (GetBrushPattern()) { if (GetBrushTransparent() == 0) fp->WriteLine(" Brush (%d,%d,%d)\n",GetBrushPattern(), GetBrushFGColor(),GetBrushBGColor()); else fp->WriteLine(" Brush (%d,%d)\n",GetBrushPattern(), GetBrushFGColor()); } return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -