Converterfile4.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:21k
- // KMCAD40-FileSwitch-Converterfile4.cpp-1.0
- // KmgConverter.cpp: implementation of the CKmgConverter class.
- //
- //////////////////////////////////////////////////////////////////////
- //Updata:
- //KMCAD40-FileSwitch-Converterfile4.cpp-1.2 -> 1.3.
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "DwgConverter.h"
- #include "KmLayer.h"
- #include "showdef.h"
- #include "entdef.h"
- #include "KmEntity.h"
- #include "Block.h"
- #include "WordStyle.h"
- #include "KmgReader.h"
- #include "Reader.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- extern CStdioFile g_CensorialFile;
- extern int g_mode;
- void CDwgConverter::AddObject()
- {
- adenhd->entcolor=m_enthead.scolor;
- adenhd->entltscale=m_enthead.dscale;
- adenhd->lineweight=m_enthead.swidth;
- adHancpy(adenhd->entltypeobjhandle,m_enthead.hltype);
- adHancpy(adenhd->entlayerobjhandle,m_enthead.hlayer);
- //short adAddEntityToList(AD_DB_HANDLE handle, AD_VMADDR addlist, PAD_ENT_HDR adenhd, PAD_ENT aden);
- sReturnValue=adAddEntityToList(m_dwghandle,m_DataVassel,adenhd,aden);
- if(sReturnValue!=1)
- {
- _ERROR;
- _WRITE(str="实体添加失败");
- }
- }
- void CDwgConverter::ConverterEntity_AdLine(double x1,double y1,double z1,double x2,double y2,double z2)
- {
- adenhd->enttype=AD_ENT_LINE;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- aden->line.pt0[0]=x1;
- aden->line.pt0[1]=y1;
- aden->line.pt0[2]=z1;
- aden->line.pt1[0]=x2;
- aden->line.pt1[1]=y2;
- aden->line.pt1[2]=z2;
- AddObject();
- return ;
- }
- void CDwgConverter::ConverterEntity_AdCircle(double x1,double y1,double z1,double ra)
- {
- adenhd->enttype=AD_ENT_CIRCLE;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- aden->circle.pt0[0]=x1;
- aden->circle.pt0[1]=y1;
- aden->circle.pt0[2]=z1;
- aden->circle.radius=ra;
- AddObject();
- return ;
- }
- void CDwgConverter::ConverterEntity_AdArc(double x1,double y1,double z1,double radius,double ba,double ea)
- {
- adenhd->enttype=AD_ENT_ARC;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- aden->arc.pt0[0]=x1;
- aden->arc.pt0[1]=y1;
- aden->arc.pt0[2]=z1;
- aden->arc.radius=radius;
- aden->arc.stang=ba*PI/180;
- aden->arc.endang=ea*PI/180;
- AddObject();
- return;
- }
- void CDwgConverter::ConverterEntity_AdText(S_TEXT* text)
- {
- double height=text->m_nHeight;
- try
- {
- double width;
- double bottomoffset;
- text->m_nMode=DRAWTOCALC;
- if(m_pTextCalcShow)
- {
- m_pTextCalcShow->DrawText(*text,NULL,FALSE,NULL,&width,&height,&bottomoffset,0);
- }
- }
- catch(...)
- {
- }
- //1.生成文字样式
- CString strFontName=text->m_lpszFacename;
- CString strBigFontName;
- int pos=strFontName.Find(';');
- if(pos!=-1&&pos>=0&&pos<strFontName.GetLength())
- {
- try
- {
- strBigFontName=strFontName.Right(strFontName.GetLength()-pos-1);
- strFontName=strFontName.Left(pos);
- }
- catch(...)
- {
- }
- }
- BOOL bUseShx=TRUE;
- if(strFontName.Find('.')==-1)
- {
- bUseShx=FALSE;
- }
- AD_OBJHANDLE handle;
- double dWidth;
- try
- {
- //增加对宽度比例的设置
- dWidth=text->m_nWidth/text->m_nHeight;
- }
- catch(...)
- {
- dWidth=1.0;
- }
- // if(bUseShx)
- {
- m_lShapeIndex++;
- adSetDefaultShapefile(&adtb->shptb);
- CString strShapeName;
- strShapeName.Format("%ld",m_lShapeIndex);
- CString strName=ConverterTabEntName(strShapeName);
- strcpy(adtb->shptb.name,strName);
- adtb->shptb.height=0.0;
- adtb->shptb.width=dWidth;
- adtb->shptb.angle=0.0;
- adtb->shptb.flag2=0;
- adtb->shptb.lastshapeheight= 5 ;
- if(!strBigFontName.IsEmpty())
- {
- strcpy(adtb->shptb.bigfontname,strBigFontName);
- }
- if(!strFontName.IsEmpty())
- {
- strcpy(adtb->shptb.file,strFontName);
- }
- adGenerateObjhandle(m_dwghandle,adtb->shptb.objhandle);
- adHancpy(handle, adtb->shptb.objhandle);
- if (!adAddShapefile(m_dwghandle,&adtb->shptb))
- {
- return;
- }
- }
- //1.生成文字
- adenhd->enttype=AD_ENT_MTEXT;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- CString strTemp=text->m_czText;
- //对英文字符宽度取半
- CString strKmText;
- //设置中文宽度
- //设置字间距比例
- if(text->m_dSpace>PRECISION)
- {
- double dSpace=1.0+text->m_dSpace/text->m_nWidth;
- if(dSpace<0.75-PRECISION)
- {
- dSpace=0.75;
- }
- if(dSpace>4.0-PRECISION)
- {
- dSpace=4.0;
- }
- CString str;
- try
- {
- str.Format("{\T%.2f;",dSpace);
- }
- catch(...)
- {
- str="\T1;";
- }
- strKmText+=str;
- }
- BOOL bASCIIStart=FALSE;
- for(int i=0;i<strTemp.GetLength();i++)
- {
- if( strTemp[i]>=0 && strTemp[i]<=0x7f )//ASCII字符
- {
- if(bASCIIStart)
- {//继续添加ACSII字符
- if(strTemp[i]=='\' || strTemp[i]== '}' || strTemp[i]== '{' )
- {
- strKmText+='\';
- }
- strKmText+=strTemp[i];
- }
- else
- {//开始添加ACSII字符
- bASCIIStart=TRUE;
- CString str;
- if(!bUseShx)//<<added by hq,2003.4.21
- str.Format("{\W%.2f;",dWidth*1.05);
- else //>>
- str.Format("{\W%.2f;",dWidth*0.5);
- strKmText+=str;
- if(strTemp[i]=='\' || strTemp[i]== '}' || strTemp[i]== '{' )
- {
- strKmText+='\';
- }
- strKmText+=strTemp[i];
- }
- }
- else
- {
- if(bASCIIStart)
- {//结束添加ACSII字符
- bASCIIStart=FALSE;
- strKmText+="}";
- strKmText+=strTemp[i];
- }
- else
- {//继续添加非ACSII字符
- strKmText+=strTemp[i];
- }
- }
- }
- if(bASCIIStart)
- {
- strKmText+="}";
- }
- //<<added by hq,2003.4.28
- if(false == bASCIIStart)
- {
- CString str;
- if(!bUseShx)//非形文字
- {
- str.Format("{\W%.2f;",dWidth*1.05);
- strKmText.Insert(0, str);
- strKmText+="}";
- }
- }
- //>>
- adHancpy(aden->mtext.shapefileobjhandle,handle);
- if(!bUseShx)
- {
- //CString str;
- //str.Format("{\W%.2f;",dWidth);
- //strKmText="{\f"+strFontName+";"+strKmText+"}";
- //modified by hq,2003.4.28
- strKmText="{\F"+strFontName+";"+strKmText+"}";
- //strKmText=str+strKmText+"}";
- }
- if(text->m_dSpace>PRECISION)
- {
- strKmText+="}";
- }
- //{added by hq,2003.5.7
- strKmText.Replace("%%c","φ");
- //}
- if(strKmText.GetLength()<=255)
- {//小于等于255时使用文字数组
- try
- {
- memcpy(aden->mtext.textstr,strKmText,strKmText.GetLength());
- aden->mtext.textstr[strKmText.GetLength()]=' ';
- }
- catch(...)
- {
- }
- }
- else
- {//使用blob
- try
- {
- CString strTemp;
- AD_VMADDR blob=adCreateBlob();//样式替代大小应小于4096
- PAD_BLOB_CTRL bcptr=adStartBlobWrite(blob);
- if(bcptr==NULL){adDeleteBlob(blob);return;}
- int count=0;
- while(!strKmText.IsEmpty()&&count<20)
- {
- count++;
- if(strKmText.GetLength()>255)
- {
- strTemp=strKmText.Left(255);
- strKmText=strKmText.Right(strKmText.GetLength()-255);
- //extern short ADCDECL adWriteMtextBlock _((PAD_BLOB_CTRL bcptr,char *str));
- adWriteMtextBlock(bcptr,(char*)(LPCTSTR)strTemp);
-
- }
- else
- {
- //extern short ADCDECL adWriteMtextBlock _((PAD_BLOB_CTRL bcptr,char *str));
- adWriteMtextBlock(bcptr,(char*)(LPCTSTR)strKmText);
- strKmText.Empty();
- break;
- }
- }
- if(!adEndBlobWrite(bcptr)){adDeleteBlob(blob);return;}
- aden->mtext.ldblob=blob;
- }
- catch(...)
- {
- return;
- }
- }
- //aden->text.tdata.generationflag
- if(!bUseShx)
- {
- //modified by hq,2003.4.19
- //kmg2003->dwg不需要做字高调整.
- {
- aden->mtext.ht=text->m_nHeight;
- #if(0)
- //{
- try
- {
- aden->mtext.ht=text->m_nHeight/calculate_findTTFHightRate(text->m_lpszFacename);
- }
- catch(...)
- {
- aden->mtext.ht=text->m_nHeight;
- }
- //}
- #endif
- }
- }
- else
- {
- aden->mtext.ht=text->m_nHeight;
- }
- calculate_finddir(text->m_nEscapement,aden->mtext.xdir);
- KmPoint pt(text->m_Offset.x,text->m_Offset.y);
- //modified by hq,2003.4.19
- {
- //STEXT(kmg)的文字为左上角对齐;
- //aden->mtext(dwg)的文字缺省对齐为左上角对齐;
- //但文字插入点的定义方,因此需要对文字插入点坐标校正:
- double dAjHtScale = 0;
- double dAjWidScale= 0;
- double dDeltaHt = 0;
- double dDeltaWid = 0;
- dAjHtScale = calculate_findTTFHightRate(text->m_lpszFacename);
- dAjWidScale = calculate_findTTFWidthRate(text->m_lpszFacename);
-
- if(0 == dAjHtScale || 1 == dAjHtScale)
- dDeltaHt = 0;
- else
- dDeltaHt = 0.4 * (text->m_nHeight / dAjHtScale - text->m_nHeight);
- if(0 == dAjWidScale || 1 == dAjWidScale)
- dDeltaWid = 0;
- else
- dDeltaWid = 0.4 * (text->m_nWidth / dAjWidScale - text->m_nWidth);
-
-
- if(bUseShx)
- {
- //double dAngle=::deg_to_rad(text->m_nEscapement)+PI*0.5;
- double dAngle=::deg_to_rad(text->m_nEscapement);
- pt.x=pt.x+dDeltaHt*sin(dAngle);
- pt.y=pt.y-dDeltaHt*cos(dAngle);
- pt.x=pt.x+dDeltaWid*cos(dAngle);
- pt.y=pt.y+dDeltaWid*sin(dAngle);
- }
- else
- {
- //double dAngle=::deg_to_rad(text->m_nEscapement)+PI*0.5;
- double dAngle=::deg_to_rad(text->m_nEscapement);
- pt.x=pt.x+dDeltaHt*sin(dAngle);
- pt.y=pt.y-dDeltaHt*cos(dAngle);
- pt.x=pt.x+dDeltaWid*cos(dAngle);
- pt.y=pt.y+dDeltaWid*sin(dAngle);
- }
- }
- aden->mtext.pt0[0]=pt.x;
- aden->mtext.pt0[1]=pt.y;
- aden->mtext.pt0[2]=0;
- AddObject();
- /* //转换为AD_ENT_TEXT的例子。
- adenhd->enttype=AD_ENT_TEXT;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- //左上角转换为左下角
- KmMatrix matrix;//旋转矩阵
- matrix.r11 = cos(text->m_nOrientation*PI/180);
- matrix.r21 = sin(text->m_nOrientation*PI/180);
- matrix.r31 = 0.0;
- matrix.r12 = -sin(text->m_nOrientation*PI/180);
- matrix.r22 = cos(text->m_nOrientation*PI/180);
- matrix.r32 = 0.0;
- matrix.r13 = text->m_Offset.x*(1.0 - cos(text->m_nOrientation*PI/180)) + text->m_Offset.y*sin(text->m_nOrientation*PI/180);
- matrix.r23 = text->m_Offset.y*(1.0 - cos(text->m_nOrientation*PI/180)) - text->m_Offset.x*sin(text->m_nOrientation*PI/180);
- matrix.r33 = 1.0;
- KmPoint pt(text->m_Offset.x+0,text->m_Offset.y-text->m_nHeight);
- pt = matrix * pt;
-
- aden->text.pt0[0]=pt.x;
- aden->text.pt0[1]=pt.y;
- aden->text.pt0[2]=0;
- CString strKmText=text->m_czText;
- try
- {
- memcpy(aden->text.textstr,strKmText,255);
- }
- catch(...)
- {
- #ifdef _DEBUG
- int a=1;
- #endif
- }
- //aden->text.tdata.generationflag
- aden->text.tdata.height=text->m_nHeight;
- //aden->text.tdata.justification
- if(text->m_bItalic)aden->text.tdata.oblique=15*PI/180;
- aden->text.tdata.rotang=text->m_nOrientation*PI/180;
- //aden->text.tdata.secondtextloc
- adHancpy(aden->text.tdata.shapefileobjhandle,handle);
- //aden->text.tdata.vertalignment
- aden->text.tdata.widthfactor=text->m_nWidth/text->m_nHeight;
- AddObject();*/
- }
- CString CDwgConverter::ConverterTabEntName(CString strName)
- {
- CString strNumber;
- CString strTemp;
- for(int i=0;i<strName.GetLength();i++)
- {
- if((unsigned char)strName[i]>0x7f)//中文字符
- {
- strTemp+=strName[i];
- if((i+1)<strName.GetLength())
- {
- strTemp+=strName[i+1];
- }
- i++;
- continue;
- }
- if(!( (strName[i]>='0'&&strName[i]<='9')||
- (strName[i]>='a'&&strName[i]<='z')||
- (strName[i]>='A'&&strName[i]<='Z') ))
- {
- strNumber.Format("%3d",strName[i]);
- for(int j=0;j<strNumber.GetLength();j++)
- {
- if(strNumber[j]==' ')
- {
- strNumber.SetAt(j,'0');
- }
- }
- strTemp+=strNumber;
- }
- else
- {
- strTemp+=strName[i];
- }
- }
- if(strTemp.GetLength()>255)
- {
- strTemp=strTemp.Left(255);
- }
- return strTemp;
- }
- BOOL CDwgConverter::ConverterEntity_KmBlockdef(CString strName,CMatch2* match)
- {
- //使用OpenDwg创建块
- //第一步:构造AD_BLKH实体.
- adSetDefaultBlockheader(&adtb->blkh);
- adtb->blkh.flag=0;
- adtb->blkh.xrefindex = -1;
- adtb->blkh.purgedflag=0;
- adtb->blkh.xdblob=AD_VMNULL;
- adtb->blkh.xrefblkisoverlaid=0;
- adtb->blkh.numreactors=0L;
- adtb->blkh.reactorblob=AD_VMNULL;
- adtb->blkh.previewblob=AD_VMNULL;
- strName=ConverterTabEntName(strName);
- strcpy(adtb->blkh.name,(char*)(LPCTSTR)strName);
- adGenerateObjhandle(m_dwghandle,adtb->blkh.objhandle);
- //第二步:添加到数据库的块链表中.
- //short adAddBlockheader _((AD_DB_HANDLE,PAD_BLKH));
- if (!adAddBlockheader(m_dwghandle,&adtb->blkh))
- {
- _ERROR;
- return FALSE;
- }
- adHancpy(match->m_handle,adtb->blkh.objhandle);
- return TRUE;
- }
- void CDwgConverter::ConverterEntity_AdInsert(double x0,double y0,double z0,double xs,double ys,double zs,double ang,AD_OBJHANDLE handle)
- {
- adenhd->enttype=AD_ENT_INSERT;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- adHancpy(aden->insert.blockheaderobjhandle,handle);
- aden->insert.pt0[0]=x0;
- aden->insert.pt0[1]=y0;
- aden->insert.pt0[2]=z0;
- aden->insert.xscale=xs;
- aden->insert.yscale=ys;
- aden->insert.zscale=zs;
- aden->insert.rotang=ang*PI/180;
- AddObject();
- return ;
- }
- void CDwgConverter::ConverterEntity_AdSolid(short scolor,double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
- {
- short scolorbackup=m_enthead.scolor;
- m_enthead.scolor=scolor;
- adenhd->enttype=AD_ENT_SOLID;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
- aden->solid.pt0[0]=x1;
- aden->solid.pt0[1]=y1;
- aden->solid.pt1[0]=x2;
- aden->solid.pt1[1]=y2;
- aden->solid.pt2[0]=x3;
- aden->solid.pt2[1]=y3;
- aden->solid.pt3[0]=x4;
- aden->solid.pt3[1]=y4;
- AddObject();
- m_enthead.scolor=scolorbackup;
- return ;
- }
- BOOL CDwgConverter::ConverterEntity_AdSimpleDim(KmDim* pDim,KmPoint p1,KmPoint p2,KmPoint p3,double dAngle,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimStyle,AD_VMADDR blob)
- {
- adenhd->enttype=AD_ENT_DIMENSION;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
-
- aden->dim.dimflag |= AD_DIMTYPE_ROTATED;
- //the first extension line is specified by defpt2.
- //The second extension line is specified by defpt3,
- //and the dimension line is specified by dimlinedefpt.
- adHancpy(aden->dim.dimstyleobjhandle,hDimStyle);
- adenhd->xdblob=blob;
- aden->dim.dimrotang=dAngle;
- aden->dim.defpt2[0]=p1.x;
- aden->dim.defpt2[1]=p1.y;
- aden->dim.defpt2[2]=0.0;
- aden->dim.defpt3[0]=p2.x;
- aden->dim.defpt3[1]=p2.y;
- aden->dim.defpt3[2]=0.0;
- aden->dim.dimlinedefpt[0]=p3.x;
- aden->dim.dimlinedefpt[1]=p3.y;
- aden->dim.dimlinedefpt[2]=0.0;
- if(!ConverterEntity_AdDimHead(pDim))
- {
- return FALSE;
- }
- //#ifndef _DEBUG
- adHancpy(aden->dim.blockheaderobjhandle,hBlock);
- //#endif
- AddObject();
- return TRUE;
- }
- BOOL CDwgConverter::ConverterEntity_AdRadiusDim(KmDim* pDim,KmPoint p1,KmPoint p2,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimStyle,AD_VMADDR blob)
- {
- adenhd->enttype=AD_ENT_DIMENSION;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
-
- aden->dim.dimflag |= AD_DIMTYPE_RADIUS;
- //dimlinedefpt 圆心
- //defpt4 圆上点
- adHancpy(aden->dim.dimstyleobjhandle,hDimStyle);
- adenhd->xdblob=blob;
- // aden->dim.dimrotang=dAngle;
- aden->dim.dimlinedefpt[0]=p1.x;
- aden->dim.dimlinedefpt[1]=p1.y;
- aden->dim.dimlinedefpt[2]=0.0;
- aden->dim.defpt4[0]=p2.x;
- aden->dim.defpt4[1]=p2.y;
- aden->dim.defpt4[2]=0.0;
- aden->dim.dimlinedefpt[2]=0.0;
- if(!ConverterEntity_AdDimHead(pDim))
- {
- return FALSE;
- }
- //#ifndef _DEBUG
- adHancpy(aden->dim.blockheaderobjhandle,hBlock);
- //#endif
- AddObject();
- return TRUE;
- }
- BOOL CDwgConverter::ConverterEntity_AdAngleDim(KmDim* pDim,KmPoint p1,KmPoint p2,KmPoint p3,KmPoint p4,KmPoint p5,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimStyle,AD_VMADDR blob)
- {
- adenhd->enttype=AD_ENT_DIMENSION;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
-
- aden->dim.dimflag |= AD_DIMTYPE_ANGULAR;
- //defpt2 and defpt3 are the endpoints of the first extension line.
- //dimlinedefpt and defpt4 are the endpoints of the second extension line.
- //arcdefpt specifies the dimension line arc.
- adHancpy(aden->dim.dimstyleobjhandle,hDimStyle);
- adenhd->xdblob=blob;
- // aden->dim.dimrotang=dAngle;
- aden->dim.defpt2[0]=p1.x;
- aden->dim.defpt2[1]=p1.y;
- aden->dim.defpt2[2]=0.0;
- aden->dim.defpt3[0]=p2.x;
- aden->dim.defpt3[1]=p2.y;
- aden->dim.defpt3[2]=0.0;
- aden->dim.dimlinedefpt[0]=p3.x;
- aden->dim.dimlinedefpt[1]=p3.y;
- aden->dim.dimlinedefpt[2]=0.0;
- aden->dim.defpt4[0]=p4.x;
- aden->dim.defpt4[1]=p4.y;
- aden->dim.defpt4[2]=0.0;
- aden->dim.arcdefpt[0]=p5.x;
- aden->dim.arcdefpt[1]=p5.y;
- aden->dim.arcdefpt[2]=0.0;
- if(!ConverterEntity_AdDimHead(pDim))
- {
- return FALSE;
- }
- //#ifndef _DEBUG
- adHancpy(aden->dim.blockheaderobjhandle,hBlock);
- //#endif
- AddObject();
- return TRUE;
- }
- BOOL CDwgConverter::ConverterEntity_AdDiameterDim(KmDim* pDim,KmPoint p1,KmPoint p2,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimStyle,AD_VMADDR blob)
- {
- adenhd->enttype=AD_ENT_DIMENSION;
- //void adSetEntityDefaults (AD_DB_HANDLE handle, PAD_ENT_HDR adenhd, PAD_ENT aden);
- adSetEntityDefaults(m_dwghandle,adenhd,aden);
- //void adGenerateObjhandle (AD_DB_HANDLE handle, unsigned char *newhandle);
- adGenerateObjhandle(m_dwghandle,adenhd->enthandle);
-
- aden->dim.dimflag |= AD_DIMTYPE_DIAMETER;
- //defpt4 is the point selected on the circle or arc being dimensioned.
- //dimlinedefpt is the point on the circle exactly across from the selection point.
- adHancpy(aden->dim.dimstyleobjhandle,hDimStyle);
- adenhd->xdblob=blob;
- // aden->dim.dimrotang=dAngle;
- aden->dim.defpt4[0]=p1.x;
- aden->dim.defpt4[1]=p1.y;
- aden->dim.defpt4[2]=0.0;
- aden->dim.dimlinedefpt[0]=p2.x;
- aden->dim.dimlinedefpt[1]=p2.y;
- aden->dim.dimlinedefpt[2]=0.0;
- if(!ConverterEntity_AdDimHead(pDim))
- {
- return FALSE;
- }
- //#ifndef _DEBUG
- adHancpy(aden->dim.blockheaderobjhandle,hBlock);
- //#endif
- AddObject();
- return TRUE;
- }
- BOOL CDwgConverter::ConverterEntity_AdDimHead(KmDim* pDim)
- {
- {
- aden->dim.dimtextrot=::deg_to_rad(pDim->GetTxtAng(pDim->GetTxtAngType()));
- aden->dim.dimflag|=AD_DIMTYPE_TEXTPOS;
- aden->dim.dimtextmidpt[0]=pDim->GetDimLinePos().x;
- aden->dim.dimtextmidpt[1]=pDim->GetDimLinePos().y;
- aden->dim.dimtextmidpt[2]=0.0;
- CString strTemp;
- if(pDim->GetIsMultiText())
- {
- if(pDim->GetMultiKmText())
- {
- if(!pDim->GetMultiKmText()->GetCString(strTemp))
- {
- strTemp=pDim->GetMultiText();
- }
- }
- else
- {
- strTemp=pDim->GetMultiText();
- }
- }
- else
- {
- strTemp=pDim->GetMultiText();
- //将上下标替换为AUTOCAD的上下标
- //KMCAD sx上标;下标;
- //AUTOCAD S上标^下标;
- try
- {
- CString strTemp2;
- CString strTemp3;
- int iPos=strTemp.Find("\sx");
- if(iPos>=0&&iPos<strTemp.GetLength())
- {
- iPos+=3;
- strTemp2=strTemp.Right(strTemp.GetLength()-iPos);
- int iPos2=strTemp2.Find(';');
- if(iPos2>=0&&iPos2<strTemp2.GetLength())
- {
- iPos2+=1;
- strTemp3=strTemp2.Right(strTemp2.GetLength()-iPos2);
- int iPos3=strTemp3.Find("\;");
- if(iPos3>=0&&iPos3<strTemp3.GetLength())
- {
- strTemp=strTemp.Left(iPos-3)+"\S"+strTemp2.Left(iPos2-1)+"^"
- + strTemp3.Left(iPos3)+";"+strTemp3.Right(strTemp3.GetLength()-iPos3-2);
- }
- }
- }
- }
- catch(...)
- {
- }
- }
- strcpy(aden->dim.dimtext,strTemp);
- }
- return TRUE;
- }
- void CDwgConverter::GetAppHandle(AD_OBJHANDLE* objhandle)
- {
- // AD_APP adapp;
- // extern short ADCDECL adFindRegappByName _((AD_DB_HANDLE handle, char *name, AD_OBJHANDLE thehandle));
- adFindRegappByName(m_dwghandle,"ACAD",*objhandle);
- // extern short ADCDECL adStartRegappGet _((AD_DB_HANDLE handle));
- // extern short ADCDECL adGetRegapp _((AD_DB_HANDLE handle,PAD_APP adapp));
-
- // adSetDefaultRegapp(&adapp);
- // adHancpy(*objhandle,adapp.objhandle);
- }