⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dgnwrite.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//     sMax.z = psCone->center_2.z;    DGNWriteBounds( psDGN, psCore, &sMin, &sMax );        return psCore;}                                 /************************************************************************//*                         DGNCreateTextElem()                          *//************************************************************************//** * Create text element. * * The newly created element will still need to be written to file using * DGNWriteElement(). Also the level and other core values will be defaulted. * Use DGNUpdateElemCore() on the element before writing to set these values. * * @param hDGN the file on which the element will eventually be written. * @param pszText the string of text.  * @param nFontId microstation font id for the text.  1 may be used as default. * @param nJustification text justification.  One of DGNJ_LEFT_TOP,  * DGNJ_LEFT_CENTER, DGNJ_LEFT_BOTTOM, DGNJ_CENTER_TOP, DGNJ_CENTER_CENTER,  * DGNJ_CENTER_BOTTOM, DGNJ_RIGHT_TOP, DGNJ_RIGHT_CENTER, DGNJ_RIGHT_BOTTOM. * @param dfLengthMult character width in master units. * @param dfHeightMult character height in master units. * @param dfRotation Counterclockwise text rotation in degrees. * @param panQuaternion 3D orientation quaternion (NULL to use rotation). * @param dfOriginX Text origin (X). * @param dfOriginY Text origin (Y). * @param dfOriginZ Text origin (Z). *  * @return the new element (DGNElemText) or NULL on failure. */DGNElemCore *DGNCreateTextElem( DGNHandle hDGN, const char *pszText,                    int nFontId, int nJustification,                    double dfLengthMult, double dfHeightMult,                    double dfRotation, int *panQuaternion,                   double dfOriginX, double dfOriginY, double dfOriginZ ){    DGNElemText *psText;    DGNElemCore *psCore;    DGNInfo *psDGN = (DGNInfo *) hDGN;    DGNPoint sMin, sMax, sLowLeft, sLowRight, sUpLeft, sUpRight;    GInt32 nIntValue, nBase;    double length, height, diagonal;    DGNLoadTCB( hDGN );/* -------------------------------------------------------------------- *//*      Allocate element.                                               *//* -------------------------------------------------------------------- */    psText = (DGNElemText *)         CPLCalloc( sizeof(DGNElemText)+strlen(pszText), 1 );    psCore = &(psText->core);    DGNInitializeElemCore( hDGN, psCore );    psCore->stype = DGNST_TEXT;    psCore->type = DGNT_TEXT;/* -------------------------------------------------------------------- *//*      Set arc specific information in the structure.                  *//* -------------------------------------------------------------------- */    psText->font_id = nFontId;    psText->justification = nJustification;    psText->length_mult = dfLengthMult;    psText->height_mult = dfHeightMult;    psText->rotation = dfRotation;    psText->origin.x = dfOriginX;    psText->origin.y = dfOriginY;    psText->origin.z = dfOriginZ;    strcpy( psText->string, pszText );/* -------------------------------------------------------------------- *//*      Setup Raw data for the text specific portion.                   *//* -------------------------------------------------------------------- */    if( psDGN->dimension == 2 )        psCore->raw_bytes = 60 + strlen(pszText);    else        psCore->raw_bytes = 76 + strlen(pszText);    psCore->raw_bytes += (psCore->raw_bytes % 2);    psCore->raw_data = (unsigned char*) CPLCalloc(psCore->raw_bytes,1);    psCore->raw_data[36] = (unsigned char) nFontId;    psCore->raw_data[37] = (unsigned char) nJustification;    nIntValue = (int) (dfLengthMult * 1000.0 / (psDGN->scale * 6.0));    DGN_WRITE_INT32( nIntValue, psCore->raw_data + 38 );        nIntValue = (int) (dfHeightMult * 1000.0 / (psDGN->scale * 6.0));    DGN_WRITE_INT32( nIntValue, psCore->raw_data + 42 );    if( psDGN->dimension == 2 )    {        nIntValue = (int) (dfRotation * 360000.0);        DGN_WRITE_INT32( nIntValue, psCore->raw_data + 46 );        DGNInverseTransformPointToInt( psDGN, &(psText->origin),                                        psCore->raw_data + 50 );        nBase = 58;    }    else    {        int anQuaternion[4];        if( panQuaternion == NULL )            DGNRotationToQuaternion( dfRotation, anQuaternion );        else            memcpy( anQuaternion, panQuaternion, sizeof(int) * 4 );        DGN_WRITE_INT32( anQuaternion[0], psCore->raw_data + 46 );        DGN_WRITE_INT32( anQuaternion[1], psCore->raw_data + 50 );        DGN_WRITE_INT32( anQuaternion[2], psCore->raw_data + 54 );        DGN_WRITE_INT32( anQuaternion[3], psCore->raw_data + 58 );        DGNInverseTransformPointToInt( psDGN, &(psText->origin),                                        psCore->raw_data + 62 );        nBase = 74;    }    psCore->raw_data[nBase] = (unsigned char) strlen(pszText);    psCore->raw_data[nBase+1] = 0; /* edflds? */    memcpy( psCore->raw_data + nBase+2, pszText, strlen(pszText) );    /* -------------------------------------------------------------------- *//*      Set the core raw data, including the bounds.                    *//*                                                                      *//*      Code contributed by Mart Kelder.                                *//* -------------------------------------------------------------------- */    DGNUpdateElemCoreExtended( hDGN, psCore );    //calculate bounds if rotation is 0    sMin.x = dfOriginX;    sMin.y = dfOriginY;    sMin.z = 0.0;    sMax.x = dfOriginX + dfLengthMult * strlen(pszText);    sMax.y = dfOriginY + dfHeightMult;    sMax.z = 0.0;    //calculate rotated bounding box coordinates    length = sMax.x-sMin.x;    height = sMax.y-sMin.y;    diagonal=sqrt(length*length+height*height);    sLowLeft.x=sMin.x;    sLowLeft.y=sMin.y;    sLowRight.x=sMin.x+cos(psText->rotation*PI/180.0)*length;    sLowRight.y=sMin.y+sin(psText->rotation*PI/180.0)*length;    sUpRight.x=sMin.x+cos((psText->rotation*PI/180.0)+atan(height/length))*diagonal;    sUpRight.y=sMin.y+sin((psText->rotation*PI/180.0)+atan(height/length))*diagonal;    sUpLeft.x=sMin.x+cos((psText->rotation+90.0)*PI/180.0)*height;    sUpLeft.y=sMin.y+sin((psText->rotation+90.0)*PI/180.0)*height;    //calculate new values for bounding box    sMin.x=MIN(sLowLeft.x,MIN(sLowRight.x,MIN(sUpLeft.x,sUpRight.x)));    sMin.y=MIN(sLowLeft.y,MIN(sLowRight.y,MIN(sUpLeft.y,sUpRight.y)));    sMax.x=MAX(sLowLeft.x,MAX(sLowRight.x,MAX(sUpLeft.x,sUpRight.x)));    sMax.y=MAX(sLowLeft.y,MAX(sLowRight.y,MAX(sUpLeft.y,sUpRight.y)));    sMin.x = dfOriginX - dfLengthMult * strlen(pszText);    sMin.y = dfOriginY - dfHeightMult;    sMin.z = 0.0;    sMax.x = dfOriginX + dfLengthMult * strlen(pszText);    sMax.y = dfOriginY + dfHeightMult;    sMax.z = 0.0;    DGNWriteBounds( psDGN, psCore, &sMin, &sMax );        return psCore;}/************************************************************************//*                      DGNCreateColorTableElem()                       *//************************************************************************//** * Create color table element. * * Creates a color table element with the indicated color table.  * * Note that color table elements are actally of type DGNT_GROUP_DATA(5) * and always on level 1.  Do not alter the level with DGNUpdateElemCore() * or the element will essentially be corrupt.  * * The newly created element will still need to be written to file using * DGNWriteElement(). Also the level and other core values will be defaulted. * Use DGNUpdateElemCore() on the element before writing to set these values. * * @param hDGN the file to which the element will eventually be written. * @param nScreenFlag the screen to which the color table applies * (0 = left, 1 = right).  * @param abyColorInfo[8][3] array of 256 color entries. The first is * the background color.  * * @return the new element (DGNElemColorTable) or NULL on failure.  */DGNElemCore *DGNCreateColorTableElem( DGNHandle hDGN, int nScreenFlag,                          GByte abyColorInfo[256][3] ){    DGNElemColorTable *psCT;    DGNElemCore *psCore;/* -------------------------------------------------------------------- *//*      Allocate element.                                               *//* -------------------------------------------------------------------- */    psCT = (DGNElemColorTable *) CPLCalloc( sizeof(DGNElemColorTable), 1 );    psCore = &(psCT->core);    DGNInitializeElemCore( hDGN, psCore );    psCore->stype = DGNST_COLORTABLE;    psCore->type = DGNT_GROUP_DATA;    psCore->level = DGN_GDL_COLOR_TABLE;/* -------------------------------------------------------------------- *//*      Set colortable specific information in the structure.           *//* -------------------------------------------------------------------- */    psCT->screen_flag = nScreenFlag;    memcpy( psCT->color_info, abyColorInfo, 768 );/* -------------------------------------------------------------------- *//*      Setup Raw data for the color table specific portion.            *//* -------------------------------------------------------------------- */    psCore->raw_bytes = 806;    psCore->raw_data = (unsigned char*) CPLCalloc(psCore->raw_bytes,1);    psCore->raw_data[36] = (unsigned char) (nScreenFlag % 256);    psCore->raw_data[37] = (unsigned char) (nScreenFlag / 256);    memcpy( psCore->raw_data + 38, abyColorInfo[255], 3 );    memcpy( psCore->raw_data + 41, abyColorInfo, 783 );    /* -------------------------------------------------------------------- *//*      Set the core raw data.                                          *//* -------------------------------------------------------------------- */    DGNUpdateElemCoreExtended( hDGN, psCore );        return psCore;}/************************************************************************//*                     DGNCreateComplexHeaderElem()                     *//************************************************************************//** * Create complex chain/shape header. * * The newly created element will still need to be written to file using * DGNWriteElement(). Also the level and other core values will be defaulted. * Use DGNUpdateElemCore() on the element before writing to set these values. * * The nTotLength is the sum of the size of all elements in the complex  * group plus 5.  The DGNCreateComplexHeaderFromGroup() can be used to build * a complex element from the members more conveniently.   * * @param hDGN the file on which the element will be written. * @param nType DGNT_COMPLEX_CHAIN_HEADER, DGNT_COMPLEX_SHAPE_HEADER,  * DGNT_3DSURFACE_HEADER or DGNT_3DSOLID_HEADER. * depending on whether the list is open or closed (last point equal to last) * or if the object represents a surface or a solid. * @param nSurfType the surface/solid type, one of DGNSUT_* or DGNSOT_*.  * Ignored if nType is DGNT_COMPLEX_CHAIN_HEADER or DGNT_COMPLEX_SHAPE_HEADER. * @param nTotLength the value of the totlength field in the element. * @param nNumElems the number of elements in the complex group not including * the header element.  * * @return the new element (DGNElemComplexHeader) or NULL on failure.  */DGNElemCore *DGNCreateComplexHeaderElem( DGNHandle hDGN, int nType, int nSurfType,                            int nTotLength, int nNumElems ){    DGNElemComplexHeader *psCH;    DGNElemCore *psCore;    unsigned char abyRawZeroLinkage[8] = {0,0,0,0,0,0,0,0};    CPLAssert( nType == DGNT_COMPLEX_CHAIN_HEADER                || nType == DGNT_COMPLEX_SHAPE_HEADER               || nType == DGNT_3DSURFACE_HEADER                || nType == DGNT_3DSOLID_HEADER );    DGNLoadTCB( hDGN );/* -------------------------------------------------------------------- *//*      Allocate element.                                               *//* -------------------------------------------------------------------- */    psCH = (DGNElemComplexHeader *)         CPLCalloc( sizeof(DGNElemComplexHeader), 1 );    psCore = &(psCH->core);    DGNInitializeElemCore( hDGN, psCore );    psCore->stype = DGNST_COMPLEX_HEADER;    psCore->type = nType;/* -------------------------------------------------------------------- *//*      Set complex header specific information in the structure.       *//* -------------------------------------------------------------------- */    psCH->totlength = nTotLength - 4;    psCH->numelems = nNumElems;    psCH->surftype = nSurfType;/* -------------------------------------------------------------------- *//*      Setup Raw data for the complex specific portion.                *//* -------------------------------------------------------------------- */    if ( nType == DGNT_COMPLEX_CHAIN_HEADER          || nType == DGNT_COMPLEX_SHAPE_HEADER )       psCore->raw_bytes = 40;    else       psCore->raw_bytes = 42;    psCore->raw_data = (unsigned char*) CPLCalloc(psCore->raw_bytes,1);    psCore->raw_data[36] = (unsigned char) ((nTotLength-4) % 256);    psCore->raw_data[37] = (unsigned char) ((nTotLength-4) / 256);    psCore->raw_data[38] = (unsigned char) (nNumElems % 256);    psCore->raw_data[39] = (unsigned char) (nNumElems / 256);    if ( nType == DGNT_3DSURFACE_HEADER || nType == DGNT_3DSOLID_HEADER ) {      psCore->raw_data[40] = (unsigned char) (psCH->surftype % 256);      psCore->raw_data[41] = (unsigned char) (psCH->surftype / 256);    }/* -------------------------------------------------------------------- *//*      Set the core raw data.                                          *//* -------------------------------------------------------------------- */    DGNUpdateElemCoreExtended( hDGN, psCore );/* -------------------------------------------------------------------- *//*      Elements have to be at least 48 bytes long, so we have to       *//*      add a dummy bit of attribute d

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -