⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabrectangle.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// tabrectangle.cpp: implementation of the TABRectangle class.////////////////////////////////////////////////////////////////////////#include "tabrectangle.h"#include "ugk_errhandle.h"#include "ugk_memopr.h"#include "ugk_string.h"#include "ugkpolygon.h"#include "ugklinearring.h"#include "tabmapobjrectellipse.h"/********************************************************************** *                   TABRectangle::TABRectangle() * * Constructor. **********************************************************************/TABRectangle::TABRectangle(UGKFeatureDefn *poDefnIn):                          TABFeature(poDefnIn){    m_bRoundCorners = FALSE;    m_dRoundXRadius = m_dRoundYRadius = 0.0;}/********************************************************************** *                   TABRectangle::~TABRectangle() * * Destructor. **********************************************************************/TABRectangle::~TABRectangle(){}/********************************************************************** *                     TABRectangle::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * This method calls the generic TABFeature::CopyTABFeatureBase() and  * then copies any members specific to its own type. **********************************************************************/TABFeature *TABRectangle::CloneTABFeature(UGKFeatureDefn *poNewDefn/*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABRectangle *poNew = new TABRectangle(poNewDefn ? poNewDefn :                                                        GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class     *----------------------------------------------------------------*/    // ITABFeaturePen    *(poNew->GetPenDefRef()) = *GetPenDefRef();    // ITABFeatureBrush    *(poNew->GetBrushDefRef()) = *GetBrushDefRef();    poNew->m_bRoundCorners = m_bRoundCorners;    poNew->m_dRoundXRadius = m_dRoundXRadius;    poNew->m_dRoundYRadius = m_dRoundYRadius;    return poNew;}/********************************************************************** *                   TABRectangle::ValidateMapInfoType() * * Check the feature's geometry part and return the corresponding * mapinfo object type code.  The m_nMapInfoType member will also * be updated for further calls to GetMapInfoType(); * * Returns TAB_GEOM_NONE if the geometry is not compatible with what * is expected for this object class. **********************************************************************/int  TABRectangle::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){    UGKGeometry *poGeom;    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon)    {        if (m_bRoundCorners && m_dRoundXRadius!=0.0 && m_dRoundYRadius!=0.0)            m_nMapInfoType = TAB_GEOM_ROUNDRECT;        else            m_nMapInfoType = TAB_GEOM_RECT;    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                  "TABRectangle: Missing or Invalid Geometry!");        m_nMapInfoType = TAB_GEOM_NONE;    }    /*-----------------------------------------------------------------     * Decide if coordinates should be compressed or not.     *----------------------------------------------------------------*/    // __TODO__ For now we always write uncompressed for this class...    // ValidateCoordType(poMapFile);    return m_nMapInfoType;}/********************************************************************** *                   TABRectangle::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 TABRectangle::ReadGeometryFromMAPFile(TABMAPFile *poMapFile,                                          TABMAPObjHdr *poObjHdr){    UGKInt32              nX, nY;    double              dXMin, dYMin, dXMax, dYMax;    UGKPolygon          *poPolygon;    UGKLinearRing       *poRing;    TABMAPObjectBlock   *poObjBlock;    UGKBool               bComprCoord;    /*-----------------------------------------------------------------     * Fetch and validate geometry type     *----------------------------------------------------------------*/    m_nMapInfoType = poMapFile->GetCurObjType();    poObjBlock = poMapFile->GetCurObjBlock();    bComprCoord = (m_nMapInfoType == TAB_GEOM_RECT_C ||                   m_nMapInfoType == TAB_GEOM_ROUNDRECT_C );    /*-----------------------------------------------------------------     * Read object information     *----------------------------------------------------------------*/    if (m_nMapInfoType == TAB_GEOM_RECT ||        m_nMapInfoType == TAB_GEOM_RECT_C ||        m_nMapInfoType == TAB_GEOM_ROUNDRECT ||        m_nMapInfoType == TAB_GEOM_ROUNDRECT_C)    {        // Read the corners radius        if (m_nMapInfoType == TAB_GEOM_ROUNDRECT ||            m_nMapInfoType == TAB_GEOM_ROUNDRECT_C)        {            // Read the corner's diameters            nX = bComprCoord? poObjBlock->ReadInt16():poObjBlock->ReadInt32();            nY = bComprCoord? poObjBlock->ReadInt16():poObjBlock->ReadInt32();            poMapFile->Int2CoordsysDist(nX, nY,                                         m_dRoundXRadius, m_dRoundYRadius);            // Divide by 2 since we store the corner's radius            m_dRoundXRadius /= 2.0;            m_dRoundYRadius /= 2.0;            m_bRoundCorners = TRUE;        }        else        {            m_bRoundCorners = FALSE;            m_dRoundXRadius = m_dRoundYRadius = 0.0;        }        // A rectangle is defined by its MBR        poObjBlock->ReadIntCoord(bComprCoord, nX, nY);        poMapFile->Int2Coordsys(nX, nY, dXMin, dYMin);        poObjBlock->ReadIntCoord(bComprCoord, nX, nY);        poMapFile->Int2Coordsys(nX, nY, dXMax, dYMax);        m_nPenDefIndex = poObjBlock->ReadByte();      // Pen index        poMapFile->ReadPenDef(m_nPenDefIndex, &m_sPenDef);        m_nBrushDefIndex = poObjBlock->ReadByte();    // Brush index        poMapFile->ReadBrushDef(m_nBrushDefIndex, &m_sBrushDef);    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,            "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)",                  m_nMapInfoType, m_nMapInfoType);        return -1;    }    /*-----------------------------------------------------------------     * 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);    /*-----------------------------------------------------------------     * 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 in the generated polygon... 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);    return 0;}/********************************************************************** *                   TABRectangle::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 TABRectangle::WriteGeometryToMAPFile(TABMAPFile *poMapFile,                                       TABMAPObjHdr *poObjHdr){    UGKGeometry         *poGeom;    UGKPolygon          *poPolygon;    UGKEnvelope         sEnvelope;    /*-----------------------------------------------------------------     * 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()) == 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);    /*-----------------------------------------------------------------     * Copy object information     *----------------------------------------------------------------*/    TABMAPObjRectEllipse *poRectHdr = (TABMAPObjRectEllipse *)poObjHdr;    if (m_nMapInfoType == TAB_GEOM_ROUNDRECT ||         m_nMapInfoType == TAB_GEOM_ROUNDRECT_C)    {        poMapFile->Coordsys2IntDist(m_dRoundXRadius*2.0, m_dRoundYRadius*2.0,                                    poRectHdr->m_nCornerWidth,                                    poRectHdr->m_nCornerHeight);    }    else    {        poRectHdr->m_nCornerWidth = poRectHdr->m_nCornerHeight = 0;    }    // A rectangle is defined by its MBR    poMapFile->Coordsys2Int(sEnvelope.MinX, sEnvelope.MinY,                             poRectHdr->m_nMinX, poRectHdr->m_nMinY);    poMapFile->Coordsys2Int(sEnvelope.MaxX, sEnvelope.MaxY, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -