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

📄 tabellipse.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// tabellipse.cpp: implementation of the TABEllipse class.////////////////////////////////////////////////////////////////////////#include "tabellipse.h"#include "ugk_errhandle.h"#include "ugk_memopr.h"#include "ugk_string.h"#include "ugkpolygon.h"#include "ugklinearring.h"#include "tabmapobjrectellipse.h"/********************************************************************** *                   TABEllipse::TABEllipse() * * Constructor. **********************************************************************/TABEllipse::TABEllipse(UGKFeatureDefn *poDefnIn):              TABFeature(poDefnIn){}/********************************************************************** *                   TABEllipse::~TABEllipse() * * Destructor. **********************************************************************/TABEllipse::~TABEllipse(){}/********************************************************************** *                     TABEllipse::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 *TABEllipse::CloneTABFeature(UGKFeatureDefn *poNewDefn/*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABEllipse *poNew = new TABEllipse(poNewDefn ? poNewDefn :                                                    GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class     *----------------------------------------------------------------*/    // ITABFeaturePen    *(poNew->GetPenDefRef()) = *GetPenDefRef();    // ITABFeatureBrush    *(poNew->GetBrushDefRef()) = *GetBrushDefRef();    poNew->m_dCenterX = m_dCenterX;    poNew->m_dCenterY = m_dCenterY;    poNew->m_dXRadius = m_dXRadius;    poNew->m_dYRadius = m_dYRadius;    return poNew;}/********************************************************************** *                   TABEllipse::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  TABEllipse::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){    UGKGeometry *poGeom;    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if ( (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ) ||         (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint ) )    {        m_nMapInfoType = TAB_GEOM_ELLIPSE;    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                 "TABEllipse: 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;}/********************************************************************** *                   TABEllipse::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 TABEllipse::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_ELLIPSE_C );    /*-----------------------------------------------------------------     * Read object information     *----------------------------------------------------------------*/    if (m_nMapInfoType == TAB_GEOM_ELLIPSE ||        m_nMapInfoType == TAB_GEOM_ELLIPSE_C )    {        // An ellipse 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;    }    /*-----------------------------------------------------------------     * Save info about the ellipse def. inside class members     *----------------------------------------------------------------*/    m_dCenterX = (dXMin + dXMax) / 2.0;    m_dCenterY = (dYMin + dYMax) / 2.0;    m_dXRadius = ABS( (dXMax - dXMin) / 2.0 );    m_dYRadius = ABS( (dYMax - dYMin) / 2.0 );    SetMBR(dXMin, dYMin, dXMax, dYMax);    /*-----------------------------------------------------------------     * Create and fill geometry object     *----------------------------------------------------------------*/    poPolygon = new UGKPolygon;    poRing = new UGKLinearRing();    /*-----------------------------------------------------------------     * For the UGK geometry, we generate an ellipse with 2 degrees line     * segments.     *----------------------------------------------------------------*/    TABGenerateArc(poRing, 180,                    m_dCenterX, m_dCenterY,                   m_dXRadius, m_dYRadius,                   0.0, 2.0*PI);    TABCloseRing(poRing);    poPolygon->addRingDirectly(poRing);    SetGeometryDirectly(poPolygon);    return 0;}/********************************************************************** *                   TABEllipse::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 TABEllipse::WriteGeometryToMAPFile(TABMAPFile *poMapFile,                                       TABMAPObjHdr *poObjHdr){    TABMAPObjectBlock   *poObjBlock;    UGKGeometry         *poGeom;    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);    poObjBlock = poMapFile->GetCurObjBlock();    /*-----------------------------------------------------------------     * Fetch and validate geometry... Polygon and point are accepted.     * Note that we will simply use the ellipse's MBR and don't really      * read the polygon geometry... this should be OK unless the      * polygon geometry was not really an ellipse.     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if ( (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ) ||         (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint )  )        poGeom->getEnvelope(&sEnvelope);    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                 "TABEllipse: Missing or Invalid Geometry!");        return -1;    }    /*-----------------------------------------------------------------     * Copy object information     *     * We use the center of the MBR as the ellipse center, and the      * X/Y radius to define the MBR size.  If X/Y radius are null then     * we'll try to use the MBR to recompute them.     *----------------------------------------------------------------*/    TABMAPObjRectEllipse *poRectHdr = (TABMAPObjRectEllipse *)poObjHdr;    // Reset RoundRect Corner members... just in case (unused for ellipse)    poRectHdr->m_nCornerWidth = poRectHdr->m_nCornerHeight = 0;    // An ellipse is defined by its MBR    double      dXCenter, dYCenter;    dXCenter = (sEnvelope.MaxX + sEnvelope.MinX)/2.0;    dYCenter = (sEnvelope.MaxY + sEnvelope.MinY)/2.0;    if (m_dXRadius == 0.0 && m_dYRadius == 0.0)

⌨️ 快捷键说明

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