📄 dgnread.cpp
字号:
if( psDGN->dimension == 2 ) { psCell->rnglow.x = DGN_INT32( psDGN->abyElem + 52 ); psCell->rnglow.y = DGN_INT32( psDGN->abyElem + 56 ); psCell->rnghigh.x = DGN_INT32( psDGN->abyElem + 60 ); psCell->rnghigh.y = DGN_INT32( psDGN->abyElem + 64 ); psCell->origin.x = DGN_INT32( psDGN->abyElem + 84 ); psCell->origin.y = DGN_INT32( psDGN->abyElem + 88 ); { double a, b, c, d, a2, c2; a = DGN_INT32( psDGN->abyElem + 68 ); b = DGN_INT32( psDGN->abyElem + 72 ); c = DGN_INT32( psDGN->abyElem + 76 ); d = DGN_INT32( psDGN->abyElem + 80 ); a2 = a * a; c2 = c * c; psCell->xscale = sqrt(a2 + c2) / 214748; psCell->yscale = sqrt(b*b + d*d) / 214748; psCell->rotation = acos(a / sqrt(a2 + c2)); if (b <= 0) psCell->rotation = psCell->rotation * 180 / PI; else psCell->rotation = 360 - psCell->rotation * 180 / PI; } } else { psCell->rnglow.x = DGN_INT32( psDGN->abyElem + 52 ); psCell->rnglow.y = DGN_INT32( psDGN->abyElem + 56 ); psCell->rnglow.z = DGN_INT32( psDGN->abyElem + 60 ); psCell->rnghigh.x = DGN_INT32( psDGN->abyElem + 64 ); psCell->rnghigh.y = DGN_INT32( psDGN->abyElem + 68 ); psCell->rnghigh.z = DGN_INT32( psDGN->abyElem + 72 ); psCell->origin.x = DGN_INT32( psDGN->abyElem + 112 ); psCell->origin.y = DGN_INT32( psDGN->abyElem + 116 ); psCell->origin.z = DGN_INT32( psDGN->abyElem + 120 ); } DGNTransformPoint( psDGN, &(psCell->rnglow) ); DGNTransformPoint( psDGN, &(psCell->rnghigh) ); DGNTransformPoint( psDGN, &(psCell->origin) ); } break; case DGNT_CELL_LIBRARY: { DGNElemCellLibrary *psCell; int iWord; psCell = (DGNElemCellLibrary *) CPLCalloc(sizeof(DGNElemCellLibrary),1); psElement = (DGNElemCore *) psCell; psElement->stype = DGNST_CELL_LIBRARY; DGNParseCore( psDGN, psElement ); DGNRad50ToAscii( psDGN->abyElem[32] + psDGN->abyElem[33] * 256, psCell->name + 0 ); DGNRad50ToAscii( psDGN->abyElem[34] + psDGN->abyElem[35] * 256, psCell->name + 3 ); psElement->properties = psDGN->abyElem[38] + psDGN->abyElem[39] * 256; psCell->dispsymb = psDGN->abyElem[40] + psDGN->abyElem[41] * 256; psCell->cclass = psDGN->abyElem[42] + psDGN->abyElem[43] * 256; psCell->levels[0] = psDGN->abyElem[44] + psDGN->abyElem[45] * 256; psCell->levels[1] = psDGN->abyElem[46] + psDGN->abyElem[47] * 256; psCell->levels[2] = psDGN->abyElem[48] + psDGN->abyElem[49] * 256; psCell->levels[3] = psDGN->abyElem[50] + psDGN->abyElem[51] * 256; psCell->numwords = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; memset( psCell->description, 0, sizeof(psCell->description) ); for( iWord = 0; iWord < 9; iWord++ ) { int iOffset = 52 + iWord * 2; DGNRad50ToAscii( psDGN->abyElem[iOffset] + psDGN->abyElem[iOffset+1] * 256, psCell->description + iWord * 3 ); } } break; case DGNT_LINE: { DGNElemMultiPoint *psLine; psLine = (DGNElemMultiPoint *) CPLCalloc(sizeof(DGNElemMultiPoint),1); psElement = (DGNElemCore *) psLine; psElement->stype = DGNST_MULTIPOINT; DGNParseCore( psDGN, psElement ); psLine->num_vertices = 2; if( psDGN->dimension == 2 ) { psLine->vertices[0].x = DGN_INT32( psDGN->abyElem + 36 ); psLine->vertices[0].y = DGN_INT32( psDGN->abyElem + 40 ); psLine->vertices[1].x = DGN_INT32( psDGN->abyElem + 44 ); psLine->vertices[1].y = DGN_INT32( psDGN->abyElem + 48 ); } else { psLine->vertices[0].x = DGN_INT32( psDGN->abyElem + 36 ); psLine->vertices[0].y = DGN_INT32( psDGN->abyElem + 40 ); psLine->vertices[0].z = DGN_INT32( psDGN->abyElem + 44 ); psLine->vertices[1].x = DGN_INT32( psDGN->abyElem + 48 ); psLine->vertices[1].y = DGN_INT32( psDGN->abyElem + 52 ); psLine->vertices[1].z = DGN_INT32( psDGN->abyElem + 56 ); } DGNTransformPoint( psDGN, psLine->vertices + 0 ); DGNTransformPoint( psDGN, psLine->vertices + 1 ); } break; case DGNT_LINE_STRING: case DGNT_SHAPE: case DGNT_CURVE: case DGNT_BSPLINE: { DGNElemMultiPoint *psLine; int i, count; int pntsize = psDGN->dimension * 4; count = psDGN->abyElem[36] + psDGN->abyElem[37]*256; psLine = (DGNElemMultiPoint *) CPLCalloc(sizeof(DGNElemMultiPoint)+(count-2)*sizeof(DGNPoint),1); psElement = (DGNElemCore *) psLine; psElement->stype = DGNST_MULTIPOINT; DGNParseCore( psDGN, psElement ); if( psDGN->nElemBytes < 38 + count * pntsize ) { CPLError( CE_Warning, CPLE_AppDefined, "Trimming multipoint vertices to %d from %d because\n" "element is short.\n", (psDGN->nElemBytes - 38) / pntsize, count ); count = (psDGN->nElemBytes - 38) / pntsize; } psLine->num_vertices = count; for( i = 0; i < psLine->num_vertices; i++ ) { psLine->vertices[i].x = DGN_INT32( psDGN->abyElem + 38 + i*pntsize ); psLine->vertices[i].y = DGN_INT32( psDGN->abyElem + 42 + i*pntsize ); if( psDGN->dimension == 3 ) psLine->vertices[i].z = DGN_INT32( psDGN->abyElem + 46 + i*pntsize ); DGNTransformPoint( psDGN, psLine->vertices + i ); } } break; case DGNT_GROUP_DATA: if( nLevel == DGN_GDL_COLOR_TABLE ) { psElement = DGNParseColorTable( psDGN ); } else { psElement = (DGNElemCore *) CPLCalloc(sizeof(DGNElemCore),1); psElement->stype = DGNST_CORE; DGNParseCore( psDGN, psElement ); } break; case DGNT_ELLIPSE: { DGNElemArc *psEllipse; psEllipse = (DGNElemArc *) CPLCalloc(sizeof(DGNElemArc),1); psElement = (DGNElemCore *) psEllipse; psElement->stype = DGNST_ARC; DGNParseCore( psDGN, psElement ); memcpy( &(psEllipse->primary_axis), psDGN->abyElem + 36, 8 ); DGN2IEEEDouble( &(psEllipse->primary_axis) ); psEllipse->primary_axis *= psDGN->scale; memcpy( &(psEllipse->secondary_axis), psDGN->abyElem + 44, 8 ); DGN2IEEEDouble( &(psEllipse->secondary_axis) ); psEllipse->secondary_axis *= psDGN->scale; if( psDGN->dimension == 2 ) { psEllipse->rotation = DGN_INT32( psDGN->abyElem + 52 ); psEllipse->rotation = psEllipse->rotation / 360000.0; memcpy( &(psEllipse->origin.x), psDGN->abyElem + 56, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 64, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); } else { /* leave quaternion for later */ memcpy( &(psEllipse->origin.x), psDGN->abyElem + 68, 8 ); DGN2IEEEDouble( &(psEllipse->origin.x) ); memcpy( &(psEllipse->origin.y), psDGN->abyElem + 76, 8 ); DGN2IEEEDouble( &(psEllipse->origin.y) ); memcpy( &(psEllipse->origin.z), psDGN->abyElem + 84, 8 ); DGN2IEEEDouble( &(psEllipse->origin.z) ); } DGNTransformPoint( psDGN, &(psEllipse->origin) ); psEllipse->startang = 0.0; psEllipse->sweepang = 360.0; } break; case DGNT_ARC: { DGNElemArc *psEllipse; GInt32 nSweepVal; psEllipse = (DGNElemArc *) CPLCalloc(sizeof(DGNElemArc),1); psElement = (DGNElemCore *) psEllipse; psElement->stype = DGNST_ARC; DGNParseCore( psDGN, psElement ); psEllipse->startang = DGN_INT32( psDGN->abyElem + 36 ); psEllipse->startang = psEllipse->startang / 360000.0; if( psDGN->abyElem[41] & 0x80 ) { psDGN->abyElem[41] &= 0x7f; nSweepVal = -1 * DGN_INT32( psDGN->abyElem + 40 ); } else nSweepVal = DGN_INT32( psDGN->abyElem + 40 ); if( nSweepVal == 0 ) psEllipse->sweepang = 360.0; else psEllipse->sweepang = nSweepVal / 360000.0; memcpy( &(psEllipse->primary_axis), psDGN->abyElem + 44, 8 ); DGN2IEEEDouble( &(psEllipse->primary_axis) ); psEllipse->primary_axis *= psDGN->scale; memcpy( &(psEllipse->secondary_axis), psDGN->abyElem + 52, 8 ); DGN2IEEEDouble( &(psEllipse->secondary_axis) ); psEllipse->secondary_axis *= psDGN->scale; 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) ); } 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) = w & 0xFF; n++; // skip 1 byte; } else { // if extend code area : 2 byte Korean character *(psText->string + n) = w >> 8; // hi *(psText->string + n + 1) = 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 =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -