📄 dgnread.cpp
字号:
if( psDGN->dimension == 2 ) { psEllipse->rotation = DGN_INT32( psDGN->abyElem + 60 ); psEllipse->rotation = psEllipse->rotation / 360000.0; memcpy( &(psEllipse->origin.x), psDGN->abyElem + 64, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 72, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); } else { /* for now we don't try to handle quaternion */ psEllipse->rotation = 0; memcpy( &(psEllipse->origin.x), psDGN->abyElem + 76, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 84, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); memcpy( &(psEllipse->origin.z), psDGN->abyElem + 92, 8 ); DGN2IEEEDouble( &(psEllipse->origin.z) ); psEllipse->quat[0] = DGN_INT32( psDGN->abyElem + 60 ); psEllipse->quat[1] = DGN_INT32( psDGN->abyElem + 64 ); psEllipse->quat[2] = DGN_INT32( psDGN->abyElem + 68 ); psEllipse->quat[3] = DGN_INT32( psDGN->abyElem + 72 ); } DGNTransformPoint( psDGN, &(psEllipse->origin) ); } break; case DGNT_TEXT: { DGNElemText *psText; int num_chars, text_off; if( psDGN->dimension == 2 ) num_chars = psDGN->abyElem[58]; else num_chars = psDGN->abyElem[74]; psText = (DGNElemText *) CPLCalloc(sizeof(DGNElemText)+num_chars,1); psElement = (DGNElemCore *) psText; psElement->stype = DGNST_TEXT; DGNParseCore( psDGN, psElement ); psText->font_id = psDGN->abyElem[36]; psText->justification = psDGN->abyElem[37]; psText->length_mult = (DGN_INT32( psDGN->abyElem + 38 )) * psDGN->scale * 6.0 / 1000.0; psText->height_mult = (DGN_INT32( psDGN->abyElem + 42 )) * psDGN->scale * 6.0 / 1000.0; if( psDGN->dimension == 2 ) { psText->rotation = DGN_INT32( psDGN->abyElem + 46 ); psText->rotation = psText->rotation / 360000.0; psText->origin.x = DGN_INT32( psDGN->abyElem + 50 ); psText->origin.y = DGN_INT32( psDGN->abyElem + 54 ); text_off = 60; } else { /* leave quaternion for later */ psText->origin.x = DGN_INT32( psDGN->abyElem + 62 ); psText->origin.y = DGN_INT32( psDGN->abyElem + 66 ); psText->origin.z = DGN_INT32( psDGN->abyElem + 70 ); text_off = 76; } DGNTransformPoint( psDGN, &(psText->origin) ); /* experimental multibyte support from Ason Kang (hiska@netian.com)*/ if (*(psDGN->abyElem + text_off) == 0xFF && *(psDGN->abyElem + text_off + 1) == 0xFD) { int n=0; for (int i=0;i<num_chars/2-1;i++) { unsigned short w; memcpy(&w,psDGN->abyElem + text_off + 2 + i*2 ,2); w = CPL_LSBWORD16(w); if (w<256) { // if alpa-numeric code area : Normal character *(psText->string + n) = (char) (w & 0xFF); n++; // skip 1 byte; } else { // if extend code area : 2 byte Korean character *(psText->string + n) = (char) (w >> 8); // hi *(psText->string + n + 1) = (char) (w & 0xFF); // lo n+=2; // 2 byte } } psText->string[n] = '\0'; // terminate C string } else { memcpy( psText->string, psDGN->abyElem + text_off, num_chars ); psText->string[num_chars] = '\0'; } } break; case DGNT_TCB: psElement = DGNParseTCB( psDGN ); break; case DGNT_COMPLEX_CHAIN_HEADER: case DGNT_COMPLEX_SHAPE_HEADER: { DGNElemComplexHeader *psHdr; psHdr = (DGNElemComplexHeader *) CPLCalloc(sizeof(DGNElemComplexHeader),1); psElement = (DGNElemCore *) psHdr; psElement->stype = DGNST_COMPLEX_HEADER; DGNParseCore( psDGN, psElement ); psHdr->totlength = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; psHdr->numelems = psDGN->abyElem[38] + psDGN->abyElem[39] * 256; } break; case DGNT_TAG_VALUE: { DGNElemTagValue *psTag; psTag = (DGNElemTagValue *) CPLCalloc(sizeof(DGNElemTagValue),1); psElement = (DGNElemCore *) psTag; psElement->stype = DGNST_TAG_VALUE; DGNParseCore( psDGN, psElement ); psTag->tagType = psDGN->abyElem[74] + psDGN->abyElem[75] * 256; memcpy( &(psTag->tagSet), psDGN->abyElem + 68, 4 ); psTag->tagSet = CPL_LSBWORD32(psTag->tagSet); psTag->tagIndex = psDGN->abyElem[72] + psDGN->abyElem[73] * 256; psTag->tagLength = psDGN->abyElem[150] + psDGN->abyElem[151] * 256; if( psTag->tagType == 1 ) { psTag->tagValue.string = CPLStrdup( (char *) psDGN->abyElem + 154 ); } else if( psTag->tagType == 3 ) { memcpy( &(psTag->tagValue.integer), psDGN->abyElem + 154, 4 ); psTag->tagValue.integer = CPL_LSBWORD32( psTag->tagValue.integer ); } else if( psTag->tagType == 4 ) { memcpy( &(psTag->tagValue.real), psDGN->abyElem + 154, 8 ); DGN2IEEEDouble( &(psTag->tagValue.real) ); } } break; case DGNT_APPLICATION_ELEM: if( nLevel == 24 ) { psElement = DGNParseTagSet( psDGN ); } else { psElement = (DGNElemCore *) CPLCalloc(sizeof(DGNElemCore),1); psElement->stype = DGNST_CORE; DGNParseCore( psDGN, psElement ); } break; case DGNT_CONE: { DGNElemCone *psCone; psCone = (DGNElemCone *) CPLCalloc(sizeof(DGNElemCone),1); psElement = (DGNElemCore *) psCone; psElement->stype = DGNST_CONE; DGNParseCore( psDGN, psElement ); CPLAssert( psDGN->dimension == 3 ); psCone->unknown = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; psCone->quat[0] = DGN_INT32( psDGN->abyElem + 38 ); psCone->quat[1] = DGN_INT32( psDGN->abyElem + 42 ); psCone->quat[2] = DGN_INT32( psDGN->abyElem + 46 ); psCone->quat[3] = DGN_INT32( psDGN->abyElem + 50 ); memcpy( &(psCone->center_1.x), psDGN->abyElem + 54, 8 ); DGN2IEEEDouble( &(psCone->center_1.x) ); memcpy( &(psCone->center_1.y), psDGN->abyElem + 62, 8 ); DGN2IEEEDouble( &(psCone->center_1.y) ); memcpy( &(psCone->center_1.z), psDGN->abyElem + 70, 8 ); DGN2IEEEDouble( &(psCone->center_1.z) ); memcpy( &(psCone->radius_1), psDGN->abyElem + 78, 8 ); DGN2IEEEDouble( &(psCone->radius_1) ); memcpy( &(psCone->center_2.x), psDGN->abyElem + 86, 8 ); DGN2IEEEDouble( &(psCone->center_2.x) ); memcpy( &(psCone->center_2.y), psDGN->abyElem + 94, 8 ); DGN2IEEEDouble( &(psCone->center_2.y) ); memcpy( &(psCone->center_2.z), psDGN->abyElem + 102, 8 ); DGN2IEEEDouble( &(psCone->center_2.z) ); memcpy( &(psCone->radius_2), psDGN->abyElem + 110, 8 ); DGN2IEEEDouble( &(psCone->radius_2) ); psCone->radius_1 *= psDGN->scale; psCone->radius_2 *= psDGN->scale; DGNTransformPoint( psDGN, &psCone->center_1 ); DGNTransformPoint( psDGN, &psCone->center_2 ); } break; case DGNT_3DSURFACE_HEADER: case DGNT_3DSOLID_HEADER: { DGNElemComplexHeader *psShape; psShape = (DGNElemComplexHeader *) CPLCalloc(sizeof(DGNElemComplexHeader),1); psElement = (DGNElemCore *) psShape; psElement->stype = DGNST_COMPLEX_HEADER; DGNParseCore( psDGN, psElement ); // Read complex header psShape->totlength = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; psShape->numelems = psDGN->abyElem[38] + psDGN->abyElem[39] * 256; psShape->surftype = psDGN->abyElem[40] + psDGN->abyElem[41] * 256; } break; default: { psElement = (DGNElemCore *) CPLCalloc(sizeof(DGNElemCore),1); psElement->stype = DGNST_CORE; DGNParseCore( psDGN, psElement ); } break; }/* -------------------------------------------------------------------- *//* If the element structure type is "core" or if we are running *//* in "capture all" mode, record the complete binary image of *//* the element. *//* -------------------------------------------------------------------- */ if( psElement->stype == DGNST_CORE || (psDGN->options & DGNO_CAPTURE_RAW_DATA) ) { psElement->raw_bytes = psDGN->nElemBytes; psElement->raw_data = (unsigned char *)CPLMalloc(psElement->raw_bytes); memcpy( psElement->raw_data, psDGN->abyElem, psElement->raw_bytes ); }/* -------------------------------------------------------------------- *//* Collect some additional generic information. *//* -------------------------------------------------------------------- */ psElement->element_id = psDGN->next_element_id - 1; psElement->offset = VSIFTell( psDGN->fp ) - psDGN->nElemBytes; psElement->size = psDGN->nElemBytes; return psElement;}/************************************************************************//* DGNReadElement() *//************************************************************************//** * Read a DGN element. * * This function will return the next element in the file, starting with the * first. It is affected by DGNGotoElement() calls. * * The element is read into a structure which includes the DGNElemCore * structure. It is expected that applications will inspect the stype * field of the returned DGNElemCore and use it to cast the pointer to the * appropriate element structure type such as DGNElemMultiPoint. * * @param hDGN the handle of the file to read from. * * @return pointer to element structure, or NULL on EOF or processing error. * The structure should be freed with DGNFreeElement() when no longer needed. */DGNElemCore *DGNReadElement( DGNHandle hDGN ){ DGNInfo *psDGN = (DGNInfo *) hDGN; DGNElemCore *psElement = NULL; int nType, nLevel; int bInsideFilter;/* -------------------------------------------------------------------- *//* Load the element data into the current buffer. If a spatial *//* filter is in effect, loop until we get something within our *//* spatial constraints. *//* -------------------------------------------------------------------- */ do { bInsideFilter = TRUE; if( !DGNLoadRawElement( psDGN, &nType, &nLevel ) ) return NULL; if( psDGN->has_spatial_filter ) { GUInt32 nXMin, nXMax, nYMin, nYMax; if( !psDGN->sf_converted_to_uor ) DGNSpatialFilterToUOR( psDGN ); if( !DGNGetRawExtents( psDGN, nType, NULL, &nXMin, &nYMin, NULL, &nXMax, &nYMax, NULL ) ) { /* If we don't have spatial characterists for the element we will pass it through. */ bInsideFilter = TRUE; } else if( nXMin > psDGN->sf_max_x || nYMin > psDGN->sf_max_y || nXMax < psDGN->sf_min_x || nYMax < psDGN->sf_min_y ) bInsideFilter = FALSE; /* ** We want to select complex elements based on the extents of ** the header, not the individual elements. */ if( nType == DGNT_COMPLEX_CHAIN_HEADER || nType == DGNT_COMPLEX_SHAPE_HEADER ) { psDGN->in_complex_group = TRUE; psDGN->select_complex_group = bInsideFilter; } else if( psDGN->abyElem[0] & 0x80 /* complex flag set */ ) { if( psDGN->in_complex_group ) bInsideFilter = psDGN->select_complex_group; } else psDGN->in_complex_group = FALSE; } } while( !bInsideFilter );/* -------------------------------------------------------------------- *//* Convert into an element structure. *//* -------------------------------------------------------------------- */ psElement = DGNProcessElement( psDGN, nType, nLevel ); return psElement;}/************************************************************************//* DGNElemTypeHasDispHdr() *//************************************************************************//** * Does element type have display header.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -