dgnhelp.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 1,438 行 · 第 1/3 页
CPP
1,438 行
/****************************************************************************** * $Id: dgnhelp.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: Microstation DGN Access Library * Purpose: Application visible helper functions for parsing DGN information. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Avenza Systems Inc, http://www.avenza.com/ * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/#include "dgnlibp.h"CPL_CVSID("$Id: dgnhelp.cpp 10646 2007-01-18 02:38:10Z warmerdam $");static unsigned char abyDefaultPCT[256][3] = { {255,255,255}, {0,0,255}, {0,255,0}, {255,0,0}, {255,255,0}, {255,0,255}, {255,127,0}, {0,255,255}, {64,64,64}, {192,192,192}, {254,0,96}, {160,224,0}, {0,254,160}, {128,0,160}, {176,176,176}, {0,240,240}, {240,240,240}, {0,0,240}, {0,240,0}, {240,0,0}, {240,240,0}, {240,0,240}, {240,122,0}, {0,240,240}, {240,240,240}, {0,0,240}, {0,240,0}, {240,0,0}, {240,240,0}, {240,0,240}, {240,122,0}, {0,225,225}, {225,225,225}, {0,0,225}, {0,225,0}, {225,0,0}, {225,225,0}, {225,0,225}, {225,117,0}, {0,225,225}, {225,225,225}, {0,0,225}, {0,225,0}, {225,0,0}, {225,225,0}, {225,0,225}, {225,117,0}, {0,210,210}, {210,210,210}, {0,0,210}, {0,210,0}, {210,0,0}, {210,210,0}, {210,0,210}, {210,112,0}, {0,210,210}, {210,210,210}, {0,0,210}, {0,210,0}, {210,0,0}, {210,210,0}, {210,0,210}, {210,112,0}, {0,195,195}, {195,195,195}, {0,0,195}, {0,195,0}, {195,0,0}, {195,195,0}, {195,0,195}, {195,107,0}, {0,195,195}, {195,195,195}, {0,0,195}, {0,195,0}, {195,0,0}, {195,195,0}, {195,0,195}, {195,107,0}, {0,180,180}, {180,180,180}, {0,0,180}, {0,180,0}, {180,0,0}, {180,180,0}, {180,0,180}, {180,102,0}, {0,180,180}, {180,180,180}, {0,0,180}, {0,180,0}, {180,0,0}, {180,180,0}, {180,0,180}, {180,102,0}, {0,165,165}, {165,165,165}, {0,0,165}, {0,165,0}, {165,0,0}, {165,165,0}, {165,0,165}, {165,97,0}, {0,165,165}, {165,165,165}, {0,0,165}, {0,165,0}, {165,0,0}, {165,165,0}, {165,0,165}, {165,97,0}, {0,150,150}, {150,150,150}, {0,0,150}, {0,150,0}, {150,0,0}, {150,150,0}, {150,0,150}, {150,92,0}, {0,150,150}, {150,150,150}, {0,0,150}, {0,150,0}, {150,0,0}, {150,150,0}, {150,0,150}, {150,92,0}, {0,135,135}, {135,135,135}, {0,0,135}, {0,135,0}, {135,0,0}, {135,135,0}, {135,0,135}, {135,87,0}, {0,135,135}, {135,135,135}, {0,0,135}, {0,135,0}, {135,0,0}, {135,135,0}, {135,0,135}, {135,87,0}, {0,120,120}, {120,120,120}, {0,0,120}, {0,120,0}, {120,0,0}, {120,120,0}, {120,0,120}, {120,82,0}, {0,120,120}, {120,120,120}, {0,0,120}, {0,120,0}, {120,0,0}, {120,120,0}, {120,0,120}, {120,82,0}, {0,105,105}, {105,105,105}, {0,0,105}, {0,105,0}, {105,0,0}, {105,105,0}, {105,0,105}, {105,77,0}, {0,105,105}, {105,105,105}, {0,0,105}, {0,105,0}, {105,0,0}, {105,105,0}, {105,0,105}, {105,77,0}, {0,90,90}, {90,90,90}, {0,0,90}, {0,90,0}, {90,0,0}, {90,90,0}, {90,0,90}, {90,72,0}, {0,90,90}, {90,90,90}, {0,0,90}, {0,90,0}, {90,0,0}, {90,90,0}, {90,0,90}, {90,72,0}, {0,75,75}, {75,75,75}, {0,0,75}, {0,75,0}, {75,0,0}, {75,75,0}, {75,0,75}, {75,67,0}, {0,75,75}, {75,75,75}, {0,0,75}, {0,75,0}, {75,0,0}, {75,75,0}, {75,0,75}, {75,67,0}, {0,60,60}, {60,60,60}, {0,0,60}, {0,60,0}, {60,0,0}, {60,60,0}, {60,0,60}, {60,62,0}, {0,60,60}, {60,60,60}, {0,0,60}, {0,60,0}, {60,0,0}, {60,60,0}, {60,0,60}, {60,62,0}, {0,45,45}, {45,45,45}, {0,0,45}, {0,45,0}, {45,0,0}, {45,45,0}, {45,0,45}, {45,57,0}, {0,45,45}, {45,45,45}, {0,0,45}, {0,45,0}, {45,0,0}, {45,45,0}, {45,0,45}, {45,57,0}, {0,30,30}, {30,30,30}, {0,0,30}, {0,30,0}, {30,0,0}, {30,30,0}, {30,0,30}, {30,52,0}, {0,30,30}, {30,30,30}, {0,0,30}, {0,30,0}, {30,0,0}, {30,30,0}, {30,0,30}, {192,192,192}, {28,0,100}};/************************************************************************//* DGNLookupColor() *//************************************************************************//** * Translate color index into RGB values. * * If no color table has yet been encountered in the file a hard-coded * "default" color table will be used. This seems to be what Microstation * uses as a color table when there isn't one in a DGN file but I am not * absolutely convinced it is appropriate. * * @param hDGN the file. * @param color_index the color index to lookup. * @param red location to put red component. * @param green location to put green component. * @param blue location to put blue component. * * @return TRUE on success or FALSE on failure. May fail if color_index is * out of range. */int DGNLookupColor( DGNHandle hDGN, int color_index, int * red, int * green, int * blue ){ DGNInfo *psDGN = (DGNInfo *) hDGN; if( color_index < 0 || color_index > 255 ) return FALSE; if( !psDGN->got_color_table ) { *red = abyDefaultPCT[color_index][0]; *green = abyDefaultPCT[color_index][1]; *blue = abyDefaultPCT[color_index][2]; } else { *red = psDGN->color_table[color_index][0]; *green = psDGN->color_table[color_index][1]; *blue = psDGN->color_table[color_index][2]; } return TRUE;}/************************************************************************//* DGNGetShapeFillInfo() *//************************************************************************//** * Fetch fill color for a shape. * * This method will check for a 0x0041 user attribute linkaged with fill * color information for the element. If found the function returns TRUE, * and places the fill color in *pnColor, otherwise FALSE is returned and * *pnColor is not updated. * * @param hDGN the file. * @param psElem the element. * @param pnColor the location to return the fill color. * * @return TRUE on success or FALSE on failure. */int DGNGetShapeFillInfo( DGNHandle hDGN, DGNElemCore *psElem, int *pnColor ){ int iLink; for( iLink = 0; TRUE; iLink++ ) { int nLinkType, nLinkSize; unsigned char *pabyData; pabyData = DGNGetLinkage( hDGN, psElem, iLink, &nLinkType, NULL, NULL, &nLinkSize ); if( pabyData == NULL ) return FALSE; if( nLinkType == DGNLT_SHAPE_FILL && nLinkSize >= 7 ) { *pnColor = pabyData[8]; return TRUE; } }}/************************************************************************//* DGNGetAssocID() *//************************************************************************//** * Fetch association id for an element. * * This method will check if an element has an association id, and if so * returns it, otherwise returning -1. Association ids are kept as a * user attribute linkage where present. * * @param hDGN the file. * @param psElem the element. * * @return The id or -1 on failure. */int DGNGetAssocID( DGNHandle hDGN, DGNElemCore *psElem ){ int iLink; for( iLink = 0; TRUE; iLink++ ) { int nLinkType, nLinkSize; unsigned char *pabyData; pabyData = DGNGetLinkage( hDGN, psElem, iLink, &nLinkType, NULL, NULL, &nLinkSize ); if( pabyData == NULL ) return -1; if( nLinkType == DGNLT_ASSOC_ID && nLinkSize >= 8 ) { return pabyData[4] + pabyData[5] * 256 + pabyData[6]*256*256 + pabyData[7] * 256*256*256; } }}/************************************************************************//* DGNRad50ToAscii() *//* *//* Convert one 16-bits Radix-50 to ASCII (3 chars). *//************************************************************************/void DGNRad50ToAscii(unsigned short sRad50, char *str ){ unsigned short sValue; char ch = '\0'; unsigned short saQuots[3] = {1600,40,1}; int i; for ( i=0; i<3; i++) { sValue = sRad50; sValue /= saQuots[i]; /* Map 0..39 to ASCII */ if (sValue==0) ch = ' '; /* space */ else if (sValue >= 1 && sValue <= 26) ch = (char) (sValue-1+'A');/* printable alpha A..Z */ else if (sValue == 27) ch = '$'; /* dollar */ else if (sValue == 28) ch = '.'; /* period */ else if (sValue == 29) ch = ' '; /* unused char, emit a space instead */ else if (sValue >= 30 && sValue <= 39) ch = (char) (sValue-30+'0'); /* digit 0..9 */ *str = ch; str++; sRad50-=(sValue*saQuots[i]); } /* Do zero-terminate */ *str = '\0';}/************************************************************************//* DGNAsciiToRad50() *//************************************************************************/void DGNAsciiToRad50( const char *str, unsigned short *pRad50 ){ unsigned short rad50 = 0; int i; for( i = 0; i < 3; i++ ) { unsigned short value; if( i >= (int) strlen(str) )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?