?? mitab_mapobjectblock.cpp
字號:
case TAB_GEOM_ELLIPSE_C:
case TAB_GEOM_ELLIPSE:
poObj = new TABMAPObjRectEllipse;
break;
case TAB_GEOM_TEXT_C:
case TAB_GEOM_TEXT:
poObj = new TABMAPObjText;
break;
case TAB_GEOM_MULTIPOINT_C:
case TAB_GEOM_MULTIPOINT:
case TAB_GEOM_V800_MULTIPOINT_C:
case TAB_GEOM_V800_MULTIPOINT:
poObj = new TABMAPObjMultiPoint;
break;
case TAB_GEOM_COLLECTION_C:
case TAB_GEOM_COLLECTION:
case TAB_GEOM_V800_COLLECTION_C:
case TAB_GEOM_V800_COLLECTION:
poObj = new TABMAPObjCollection();
break;
default:
CPLError(CE_Failure, CPLE_AssertionFailed,
"TABMAPObjHdr::NewObj(): Unsupported object type %d",
nNewObjType);
}
if (poObj)
{
poObj->m_nType = nNewObjType;
poObj->m_nId = nId;
poObj->m_nMinX = poObj->m_nMinY = poObj->m_nMaxX = poObj->m_nMaxY = 0;
}
return poObj;
}
/**********************************************************************
* TABMAPObjHdr::ReadNextObj()
*
* Read next object in this block and allocate/init a new object for it
* if succesful.
* Returns NULL in case of error or if we reached end of block.
**********************************************************************/
TABMAPObjHdr *TABMAPObjHdr::ReadNextObj(TABMAPObjectBlock *poObjBlock,
TABMAPHeaderBlock *poHeader)
{
TABMAPObjHdr *poObjHdr = NULL;
if (poObjBlock->AdvanceToNextObject(poHeader) != -1)
{
poObjHdr=TABMAPObjHdr::NewObj(poObjBlock->GetCurObjectType());
if (poObjHdr &&
((poObjHdr->m_nId = poObjBlock->GetCurObjectId()) == -1 ||
poObjHdr->ReadObj(poObjBlock) != 0 ) )
{
// Failed reading object in block... an error was already produced
delete poObjHdr;
return NULL;
}
}
return poObjHdr;
}
/**********************************************************************
* TABMAPObjHdr::IsCompressedType()
*
* Returns TRUE if the current object type uses compressed coordinates
* or FALSE otherwise.
**********************************************************************/
GBool TABMAPObjHdr::IsCompressedType()
{
// Compressed types are 1, 4, 7, etc.
return ((m_nType % 3) == 1 ? TRUE : FALSE);
}
/**********************************************************************
* TABMAPObjHdr::WriteObjTypeAndId()
*
* Writetype+object id information... should be called only by the derived
* classes' WriteObj() methods.
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjHdr::WriteObjTypeAndId(TABMAPObjectBlock *poObjBlock)
{
poObjBlock->WriteByte(m_nType);
return poObjBlock->WriteInt32(m_nId);
}
/**********************************************************************
* TABMAPObjHdr::SetMBR()
*
**********************************************************************/
void TABMAPObjHdr::SetMBR(GInt32 nMinX, GInt32 nMinY,
GInt32 nMaxX, GInt32 nMaxY)
{
m_nMinX = MIN(nMinX, nMaxX);
m_nMinY = MIN(nMinY, nMaxY);
m_nMaxX = MAX(nMinX, nMaxX);
m_nMaxY = MAX(nMinY, nMaxY);
}
/**********************************************************************
* class TABMAPObjLine
*
* Applies to 2-points LINEs only
**********************************************************************/
/**********************************************************************
* TABMAPObjLine::ReadObj()
*
* Read Object information starting after the object id which should
* have been read by TABMAPObjHdr::ReadNextObj() already.
* This function should be called only by TABMAPObjHdr::ReadNextObj().
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjLine::ReadObj(TABMAPObjectBlock *poObjBlock)
{
poObjBlock->ReadIntCoord(IsCompressedType(), m_nX1, m_nY1);
poObjBlock->ReadIntCoord(IsCompressedType(), m_nX2, m_nY2);
m_nPenId = poObjBlock->ReadByte(); // Pen index
SetMBR(m_nX1, m_nY1, m_nX2, m_nY2);
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* TABMAPObjLine::WriteObj()
*
* Write Object information with the type+object id
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjLine::WriteObj(TABMAPObjectBlock *poObjBlock)
{
// Write object type and id
TABMAPObjHdr::WriteObjTypeAndId(poObjBlock);
poObjBlock->WriteIntCoord(m_nX1, m_nY1, IsCompressedType());
poObjBlock->WriteIntCoord(m_nX2, m_nY2, IsCompressedType());
poObjBlock->WriteByte(m_nPenId); // Pen index
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* class TABMAPObjPLine
*
* Applies to PLINE, MULTIPLINE and REGION object types
**********************************************************************/
/**********************************************************************
* TABMAPObjPLine::ReadObj()
*
* Read Object information starting after the object id which should
* have been read by TABMAPObjHdr::ReadNextObj() already.
* This function should be called only by TABMAPObjHdr::ReadNextObj().
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjPLine::ReadObj(TABMAPObjectBlock *poObjBlock)
{
m_nCoordBlockPtr = poObjBlock->ReadInt32();
m_nCoordDataSize = poObjBlock->ReadInt32();
if (m_nCoordDataSize & 0x80000000)
{
m_bSmooth = TRUE;
m_nCoordDataSize &= 0x7FFFFFFF; //Take smooth flag out of the value
}
else
{
m_bSmooth = FALSE;
}
#ifdef TABDUMP
printf("TABMAPObjPLine::ReadObj: m_nCoordDataSize = %d @ %d\n",
m_nCoordDataSize, m_nCoordBlockPtr);
#endif
// Number of line segments applies only to MULTIPLINE/REGION but not PLINE
if (m_nType == TAB_GEOM_PLINE_C ||
m_nType == TAB_GEOM_PLINE )
{
m_numLineSections = 1;
}
else if (m_nType == TAB_GEOM_V800_REGION ||
m_nType == TAB_GEOM_V800_REGION_C ||
m_nType == TAB_GEOM_V800_MULTIPLINE ||
m_nType == TAB_GEOM_V800_MULTIPLINE_C )
{
/* V800 REGIONS/MULTIPLINES use an int32 */
m_numLineSections = poObjBlock->ReadInt32();
/* ... followed by 33 unknown bytes */
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadByte();
}
else
{
/* V300 and V450 REGIONS/MULTIPLINES use an int16 */
m_numLineSections = poObjBlock->ReadInt16();
}
#ifdef TABDUMP
printf("PLINE/REGION: id=%d, type=%d, "
"CoordBlockPtr=%d, CoordDataSize=%d, numLineSect=%d, bSmooth=%d\n",
m_nId, m_nType, m_nCoordBlockPtr, m_nCoordDataSize,
m_numLineSections, m_bSmooth);
#endif
if (IsCompressedType())
{
// Region center/label point, relative to compr. coord. origin
// No it's not relative to the Object block center
m_nLabelX = poObjBlock->ReadInt16();
m_nLabelY = poObjBlock->ReadInt16();
// Compressed coordinate origin (present only in compressed case!)
m_nComprOrgX = poObjBlock->ReadInt32();
m_nComprOrgY = poObjBlock->ReadInt32();
m_nLabelX += m_nComprOrgX;
m_nLabelY += m_nComprOrgY;
m_nMinX = m_nComprOrgX + poObjBlock->ReadInt16(); // Read MBR
m_nMinY = m_nComprOrgY + poObjBlock->ReadInt16();
m_nMaxX = m_nComprOrgX + poObjBlock->ReadInt16();
m_nMaxY = m_nComprOrgY + poObjBlock->ReadInt16();
}
else
{
// Region center/label point, relative to compr. coord. origin
// No it's not relative to the Object block center
m_nLabelX = poObjBlock->ReadInt32();
m_nLabelY = poObjBlock->ReadInt32();
m_nMinX = poObjBlock->ReadInt32(); // Read MBR
m_nMinY = poObjBlock->ReadInt32();
m_nMaxX = poObjBlock->ReadInt32();
m_nMaxY = poObjBlock->ReadInt32();
}
if ( ! IsCompressedType() )
{
// Init. Compr. Origin to a default value in case type is ever changed
m_nComprOrgX = (m_nMinX + m_nMaxX) / 2;
m_nComprOrgY = (m_nMinY + m_nMaxY) / 2;
}
m_nPenId = poObjBlock->ReadByte(); // Pen index
if (m_nType == TAB_GEOM_REGION ||
m_nType == TAB_GEOM_REGION_C ||
m_nType == TAB_GEOM_V450_REGION ||
m_nType == TAB_GEOM_V450_REGION_C ||
m_nType == TAB_GEOM_V800_REGION ||
m_nType == TAB_GEOM_V800_REGION_C )
{
m_nBrushId = poObjBlock->ReadByte(); // Brush index... REGION only
}
else
{
m_nBrushId = 0;
}
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* TABMAPObjPLine::WriteObj()
*
* Write Object information with the type+object id
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjPLine::WriteObj(TABMAPObjectBlock *poObjBlock)
{
// Write object type and id
TABMAPObjHdr::WriteObjTypeAndId(poObjBlock);
poObjBlock->WriteInt32(m_nCoordBlockPtr);
// Combine smooth flag in the coord data size.
if (m_bSmooth)
poObjBlock->WriteInt32( m_nCoordDataSize | 0x80000000 );
else
poObjBlock->WriteInt32( m_nCoordDataSize );
// Number of line segments applies only to MULTIPLINE/REGION but not PLINE
if (m_nType == TAB_GEOM_V800_REGION ||
m_nType == TAB_GEOM_V800_REGION_C ||
m_nType == TAB_GEOM_V800_MULTIPLINE ||
m_nType == TAB_GEOM_V800_MULTIPLINE_C )
{
/* V800 REGIONS/MULTIPLINES use an int32 */
poObjBlock->WriteInt32(m_numLineSections);
/* ... followed by 33 unknown bytes */
poObjBlock->WriteZeros(33);
}
else if (m_nType != TAB_GEOM_PLINE_C &&
m_nType != TAB_GEOM_PLINE )
{
/* V300 and V450 REGIONS/MULTIPLINES use an int16 */
poObjBlock->WriteInt16(m_numLineSections);
}
if (IsCompressedType())
{
// Region center/label point, relative to compr. coord. origin
// No it's not relative to the Object block center
poObjBlock->WriteInt16(m_nLabelX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nLabelY - m_nComprOrgY);
// Compressed coordinate origin (present only in compressed case!)
poObjBlock->WriteInt32(m_nComprOrgX);
poObjBlock->WriteInt32(m_nComprOrgY);
}
else
{
// Region center/label point
poObjBlock->WriteInt32(m_nLabelX);
poObjBlock->WriteInt32(m_nLabelY);
}
// MBR
if (IsCompressedType())
{
// MBR relative to PLINE origin (and not object block center)
poObjBlock->WriteInt16(m_nMinX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nMinY - m_nComprOrgY);
poObjBlock->WriteInt16(m_nMaxX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nMaxY - m_nComprOrgY);
}
else
{
poObjBlock->WriteInt32(m_nMinX);
poObjBlock->WriteInt32(m_nMinY);
poObjBlock->WriteInt32(m_nMaxX);
poObjBlock->WriteInt32(m_nMaxY);
}
poObjBlock->WriteByte(m_nPenId); // Pen index
if (m_nType == TAB_GEOM_REGION ||
m_nType == TAB_GEOM_REGION_C ||
m_nType == TAB_GEOM_V450_REGION ||
m_nType == TAB_GEOM_V450_REGION_C ||
m_nType == TAB_GEOM_V800_REGION ||
m_nType == TAB_GEOM_V800_REGION_C )
{
poObjBlock->WriteByte(m_nBrushId); // Brush index... REGION only
}
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -