📄 tabmapfile.cpp
字号:
nStatus = m_poSpIndex->AddEntry(nXMin, nYMin, nXMax, nYMax, m_poCurObjBlock->GetStartAddress()); m_poHeader->m_nMaxSpIndexDepth = MAX(m_poHeader->m_nMaxSpIndexDepth, m_poSpIndex->GetCurMaxDepth()+1); } /*----------------------------------------------------------------- * Reinitialize the obj block only if requested *----------------------------------------------------------------*/ if (bInitNewBlock && nStatus == 0) { nStatus = m_poCurObjBlock->InitNewBlock(m_fp,512, m_oBlockManager.AllocNewBlock()); } return nStatus;}/********************************************************************** * TABMAPFile::GetCurObjType() * * Return the MapInfo object type of the object that the m_poCurObjBlock * is pointing to. This value is set after a call to MoveToObjId(). * * Returns a value >= 0 on success, -1 on error. **********************************************************************/int TABMAPFile::GetCurObjType(){ return m_nCurObjType;}/********************************************************************** * TABMAPFile::GetCurObjId() * * Return the MapInfo object id of the object that the m_poCurObjBlock * is pointing to. This value is set after a call to MoveToObjId(). * * Returns a value >= 0 on success, -1 on error. **********************************************************************/int TABMAPFile::GetCurObjId(){ return m_nCurObjId;}/********************************************************************** * TABMAPFile::GetCurObjBlock() * * Return the m_poCurObjBlock. If MoveToObjId() has previously been * called then m_poCurObjBlock points to the beginning of the current * object data. * * Returns a reference to an object owned by this TABMAPFile object, or * NULL on error. **********************************************************************/TABMAPObjectBlock *TABMAPFile::GetCurObjBlock(){ return m_poCurObjBlock;}/********************************************************************** * TABMAPFile::GetCurCoordBlock() * * Return the m_poCurCoordBlock. This function should be used after * PrepareNewObj() to get the reference to the coord block that has * just been initialized. * * Returns a reference to an object owned by this TABMAPFile object, or * NULL on error. **********************************************************************/TABMAPCoordBlock *TABMAPFile::GetCurCoordBlock(){ return m_poCurCoordBlock;}/********************************************************************** * TABMAPFile::GetCoordBlock() * * Return a TABMAPCoordBlock object ready to read coordinates from it. * The block that contains nFileOffset will automatically be * loaded, and if nFileOffset is the beginning of a new block then the * pointer will be moved to the beginning of the data. * * The contents of the returned object is only valid until the next call * to GetCoordBlock(). * * Returns a reference to an object owned by this TABMAPFile object, or * NULL on error. **********************************************************************/TABMAPCoordBlock *TABMAPFile::GetCoordBlock(int nFileOffset){ if (m_eAccessMode != TABRead) return NULL; if (m_poCurCoordBlock == NULL) { m_poCurCoordBlock = new TABMAPCoordBlock(m_eAccessMode); m_poCurCoordBlock->InitNewBlock(m_fp, 512); } /*----------------------------------------------------------------- * Use GotoByteInFile() to go to the requested location. This will * force loading the block if necessary and reading its header. * If nFileOffset is at the beginning of the requested block, then * we make sure to move the read pointer past the 8 bytes header * to be ready to read coordinates data *----------------------------------------------------------------*/ if ( m_poCurCoordBlock->GotoByteInFile(nFileOffset) != 0) { // Failed... an error has already been reported. return NULL; } if (nFileOffset % 512 == 0) m_poCurCoordBlock->GotoByteInBlock(8); // Skip Header return m_poCurCoordBlock;}/********************************************************************** * TABMAPFile::GetHeaderBlock() * * Return a reference to the MAP file's header block. * * The returned pointer is a reference to an object owned by this TABMAPFile * object and should not be deleted by the caller. * * Return NULL if file has not been opened yet. **********************************************************************/TABMAPHeaderBlock *TABMAPFile::GetHeaderBlock(){ return m_poHeader;}/********************************************************************** * TABMAPFile::GetIDFileRef() * * Return a reference to the .ID file attached to this .MAP file * * The returned pointer is a reference to an object owned by this TABMAPFile * object and should not be deleted by the caller. * * Return NULL if file has not been opened yet. **********************************************************************/TABIDFile *TABMAPFile::GetIDFileRef(){ return m_poIdIndex;}/********************************************************************** * TABMAPFile::GetIndexBlock() * 返回要求的索引块或则对象块的引用 -ZGQ * Return a reference to the requested index or object block.. * * Ownership of the returned block is turned over to the caller, who should * delete it when no longer needed. The type of the block can be determined * with the GetBlockType() method. * * @param nFileOffset--the offset in the map file of the spatial index * block or object block to load. * * @return The requested TABMAPIndexBlock, TABMAPObjectBlock or NULL if the * read fails for some reason. **********************************************************************/TABRawBinBlock *TABMAPFile::GetIndexObjectBlock( int nFileOffset ){ /*---------------------------------------------------------------- * Read from the file *---------------------------------------------------------------*/ UGKByte abyData[512]; if (fseek(m_fp, nFileOffset, SEEK_SET) != 0 || fread(abyData, sizeof(UGKByte), 512, m_fp) != 512 ) { UGKError(ET_Failure, UGKErr_FileIO, "GetIndexBlock() failed reading %d bytes at offset %d.", 512, nFileOffset); return NULL; }/* -------------------------------------------------------------------- *//* Create and initialize depending on the block type. *//* -------------------------------------------------------------------- */ int nBlockType = abyData[0]; TABRawBinBlock *poBlock; if( nBlockType == TABMAP_INDEX_BLOCK ) poBlock = new TABMAPIndexBlock(); else poBlock = new TABMAPObjectBlock(); if( poBlock->InitBlockFromData(abyData,512,TRUE,m_fp,nFileOffset) == -1 ) { delete poBlock; poBlock = NULL; } return poBlock;}/********************************************************************** * TABMAPFile::InitDrawingTools() * * Init the drawing tools for this file. * * In Read mode, this will load the drawing tools from the file. * * In Write mode, this function will init an empty the tool def table. * * Reutrns 0 on success, -1 on error. **********************************************************************/int TABMAPFile::InitDrawingTools(){ int nStatus = 0; if (m_poHeader == NULL) return -1; // File not opened yet! /*------------------------------------------------------------- * We want to perform this initialisation only ONCE *------------------------------------------------------------*/ if (m_poToolDefTable != NULL) return 0; /*------------------------------------------------------------- * Create a new ToolDefTable... no more initialization is required * unless we want to read tool blocks from file. *------------------------------------------------------------*/ m_poToolDefTable = new TABToolDefTable; if (m_eAccessMode == TABRead && m_poHeader->m_nFirstToolBlock != 0) { TABMAPToolBlock *poBlock; poBlock = new TABMAPToolBlock(m_eAccessMode); poBlock->InitNewBlock(m_fp, 512); /*------------------------------------------------------------- * Use GotoByteInFile() to go to the first block's location. This will * force loading the block if necessary and reading its header. * Also make sure to move the read pointer past the 8 bytes header * to be ready to read drawing tools data *------------------------------------------------------------*/ if ( poBlock->GotoByteInFile(m_poHeader->m_nFirstToolBlock)!= 0) { // Failed... an error has already been reported. delete poBlock; return -1; } poBlock->GotoByteInBlock(8); nStatus = m_poToolDefTable->ReadAllToolDefs(poBlock); delete poBlock; } return nStatus;}/********************************************************************** * TABMAPFile::CommitDrawingTools() * * Write the drawing tools for this file. * * This function applies only to write access mode. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMAPFile::CommitDrawingTools(){ int nStatus = 0; if (m_eAccessMode != TABWrite || m_poHeader == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "CommitDrawingTools() failed: file not opened for write access."); return -1; } if (m_poToolDefTable == NULL || (m_poToolDefTable->GetNumPen() + m_poToolDefTable->GetNumBrushes() + m_poToolDefTable->GetNumFonts() + m_poToolDefTable->GetNumSymbols()) == 0) { return 0; // Nothing to do! } /*------------------------------------------------------------- * Create a new TABMAPToolBlock and update header fields *------------------------------------------------------------*/ TABMAPToolBlock *poBlock; poBlock = new TABMAPToolBlock(m_eAccessMode); poBlock->InitNewBlock(m_fp, 512, m_oBlockManager.AllocNewBlock()); poBlock->SetMAPBlockManagerRef(&m_oBlockManager); m_poHeader->m_nFirstToolBlock = poBlock->GetStartAddress(); m_poHeader->m_numPenDefs = m_poToolDefTable->GetNumPen(); m_poHeader->m_numBrushDefs = m_poToolDefTable->GetNumBrushes(); m_poHeader->m_numFontDefs = m_poToolDefTable->GetNumFonts(); m_poHeader->m_numSymbolDefs = m_poToolDefTable->GetNumSymbols(); /*------------------------------------------------------------- * Do the actual work and delete poBlock * (Note that poBlock will have already been committed to the file * by WriteAllToolDefs() ) *------------------------------------------------------------*/ nStatus = m_poToolDefTable->WriteAllToolDefs(poBlock); m_poHeader->m_numMapToolBlocks = poBlock->GetNumBlocksInChain(); delete poBlock; return nStatus;}/********************************************************************** * TABMAPFile::ReadPenDef() * * Fill the TABPenDef structure with the definition of the specified pen * index... (1-based pen index) * * If nPenIndex==0 or is invalid, then the structure is cleared. * * Returns 0 on success, -1 on error (i.e. Pen not found). **********************************************************************/int TABMAPFile::ReadPenDef(int nPenIndex, TABPenDef *psDef){ TABPenDef *psTmp; if (m_poToolDefTable == NULL && InitDrawingTools() != 0) return -1; if (psDef && m_poToolDefTable && (psTmp = m_poToolDefTable->GetPenDefRef(nPenIndex)) != NULL) { *psDef = *psTmp; } else if (psDef) { /* Init to MapInfo default */ static const TABPenDef csDefaultPen = MITAB_PEN_DEFAULT; *psDef = csDefaultPen; return -1; } return 0;}/********************************************************************** * TABMAPFile::WritePenDef() * * Write a Pen Tool to the map file and return the pen index that has * been attributed to this Pen tool definition, or -1 if something went * wrong
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -