dgnread.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 1,808 行 · 第 1/5 页
CPP
1,808 行
1.0 * DGN_INT32( psDGN->abyElem + 100 ) / (1<<31); psCell->trans[7] = 1.0 * DGN_INT32( psDGN->abyElem + 104 ) / (1<<31); psCell->trans[8] = 1.0 * DGN_INT32( psDGN->abyElem + 108 ) / (1<<31); 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_POLE: { 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_TEXT_NODE: { DGNElemTextNode *psNode; psNode = (DGNElemTextNode *) CPLCalloc(sizeof(DGNElemTextNode),1); psElement = (DGNElemCore *) psNode; psElement->stype = DGNST_TEXT_NODE; DGNParseCore( psDGN, psElement ); psNode->totlength = psDGN->abyElem[36] + psDGN->abyElem[37] * 256; psNode->numelems = psDGN->abyElem[38] + psDGN->abyElem[39] * 256; psNode->node_number = psDGN->abyElem[40] + psDGN->abyElem[41] * 256; psNode->max_length = psDGN->abyElem[42]; psNode->max_used = psDGN->abyElem[43]; psNode->font_id = psDGN->abyElem[44]; psNode->justification = psDGN->abyElem[45]; psNode->length_mult = (DGN_INT32( psDGN->abyElem + 50 )) * psDGN->scale * 6.0 / 1000.0; psNode->height_mult = (DGN_INT32( psDGN->abyElem + 54 )) * psDGN->scale * 6.0 / 1000.0; if( psDGN->dimension == 2 ) { psNode->rotation = DGN_INT32( psDGN->abyElem + 58 ) / 360000.0; psNode->origin.x = DGN_INT32( psDGN->abyElem + 62 ); psNode->origin.y = DGN_INT32( psDGN->abyElem + 66 ); } else { /* leave quaternion for later */ psNode->origin.x = DGN_INT32( psDGN->abyElem + 74 ); psNode->origin.y = DGN_INT32( psDGN->abyElem + 78 ); psNode->origin.z = DGN_INT32( psDGN->abyElem + 82 ); } DGNTransformPoint( psDGN, &(psNode->origin) ); } 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) ); psEllipse->quat[0] = DGN_INT32( psDGN->abyElem + 52 ); psEllipse->quat[1] = DGN_INT32( psDGN->abyElem + 56 ); psEllipse->quat[2] = DGN_INT32( psDGN->abyElem + 60 ); psEllipse->quat[3] = DGN_INT32( psDGN->abyElem + 64 ); } 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) ); 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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?