Processfile2.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:81k
- // KMCAD40-FileSwitch-Processfile2.cpp-1.0
- //---------------------------------------------
- //KMCAD40-FileSwitch-Processfile2.cpp-1.1 -> 1.2
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "DwgReader.h"
- #include "KmSection.h"
- #include "KmPouQie.h"
- #include "KmSymbl.h"
- #include "Vector.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- /*
- {
- short i;
- if (adxd->xddxfnumber==1000) TRACE("1000n%sn",adxd->xddata.xdstring);
- else if (adxd->xddxfnumber==1001)TRACE("1001n");
- else if (adxd->xddxfnumber==1003)TRACE("1003n");
- else if (adxd->xddxfnumber==1005)TRACE("1005n");
- else if (adxd->xddxfnumber==1010)TRACE("1010n%fn1020n%fn1030n%fn", adxd->xddata.xd3dpt[0],adxd->xddata.xd3dpt[1],adxd->xddata.xd3dpt[2]);
- else if (adxd->xddxfnumber==1040)TRACE("1040n%fn",adxd->xddata.xdreal);
- else if (adxd->xddxfnumber==1070)TRACE("1070n%dn",adxd->xddata.xdint);
- else if (adxd->xddxfnumber==1071)TRACE("1071n%ldn",adxd->xddata.xdlong);
- else if (adxd->xddxfnumber==1002)TRACE("1002n%cn",adxd->xddata.xdcontrol);
- else if (adxd->xddxfnumber==1004){TRACE("1004n");for (i=0; i<adxd->xdbindatalength; i++) TRACE("%.02X",((unsigned)adxd->xddata.xdbindata[i]) & 255);TRACE("n"); }
- else if (adxd->xddxfnumber==1011)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworldpos[0],adxd->xddata.xdworldpos[1],adxd->xddata.xdworldpos[2]);
- else if (adxd->xddxfnumber==1012)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworlddisp[0],adxd->xddata.xdworlddisp[1],adxd->xddata.xdworlddisp[2]);
- else if (adxd->xddxfnumber==1013)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworlddir[0],adxd->xddata.xdworlddir[1],adxd->xddata.xdworlddir[2]);
- else if (adxd->xddxfnumber==1041)TRACE("1041n%fn",adxd->xddata.xddist);
- else if (adxd->xddxfnumber==1042)TRACE("1042n%fn",adxd->xddata.xdscale);
- }
- */
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- CVector::CVector()
- {
- m_bwidth=FALSE;
- m_widthbegin=0.0;
- m_widthend=0.0;
- m_bulge=0.0;
- m_x=0.0;
- m_y=0.0;
- m_z=0.0;
- }
- CVector::~CVector()
- {
- }
- BOOL CDwgReader::processentity(AD_DB_HANDLE dwghandle)
- {
- //#define adEntIsInvisible(a) (a & AD_INVISIBLE)
- if(adEntIsInvisible(adenhd->entflags))
- {
- return TRUE;
- }
- if(!processentity_enthead(dwghandle))
- {
- return FALSE;
- }
- switch(adenhd->enttype)
- {
- case AD_ENT_LINE://1
- return processentity_line(dwghandle);
- case AD_ENT_POINT://2
- return processentity_point(dwghandle);
- case AD_ENT_CIRCLE://3
- return processentity_circle(dwghandle);
- case AD_ENT_SHAPE:/*4*/
- return processentity_shape(dwghandle);
- case AD_ENT_ELLIPSE://5
- return processentity_ellipse(dwghandle);
- case AD_ENT_SPLINE://
- return processentity_spline(dwghandle);
- case AD_ENT_TEXT:/*7*/
- return processentity_text(dwghandle);
- case AD_ENT_ARC://8
- return processentity_arc(dwghandle);
- case AD_ENT_TRACE://9转换为4根线 宽度线
- return processentity_trace(dwghandle);
- case AD_ENT_REGION:/*10*/
- case AD_ENT_BODY:
- case AD_ENT_SOLID3D:
- return processentity_acis(dwghandle);
- case AD_ENT_SOLID:/*11*/
- return processentity_solid(dwghandle);
- case AD_ENT_BLOCK://12
- return processentity_block(dwghandle);
- case AD_ENT_ENDBLK://13
- _WRITE(str="块结束标志符没有被正常处理");
- return FALSE;
- case AD_ENT_INSERT://14
- return processentity_insert(dwghandle);
- case AD_ENT_ATTDEF:
- return processentity_attdef(dwghandle);
- case AD_ENT_ATTRIB:
- return processentity_attrib(dwghandle);
- case AD_ENT_POLYLINE://多段线开始标志
- case AD_ENT_VERTEX://多段线顶点
- case AD_ENT_SEQEND://insert+attribs或polyline+vertexs的结束标志,前者不予考虑 以上三种实体配合起来实现了多段线的完整转换.
- break;
- case AD_ENT_LINE3D:
- return processentity_3dline(dwghandle);
- case AD_ENT_FACE3D:
- return processentity_3dface(dwghandle);
- case AD_ENT_DIMENSION:
- return processentity_dim(dwghandle);
- case AD_ENT_VIEWPORT://公共部分不予处理
- break;
- case AD_ENT_RAY:
- return processentity_ray(dwghandle);
- case AD_ENT_XLINE:
- return processentity_xline(dwghandle);
- case AD_ENT_MTEXT:
- return processentity_mtext(dwghandle);
- case AD_ENT_LEADER://完成但仍然可以进一步优化 样条
- return processentity_leader(dwghandle);
- case AD_ENT_TOLERANCE:
- return processentity_tolerance(dwghandle);
- case AD_ENT_MLINE://完成 平行线
- return processentity_mline(dwghandle);
- default:
- if(adenhd->enttype==adArcAlignedTextEnttype(dwghandle))
- {//圆弧文字
- return processentity_atext(dwghandle);
- }
- else if(adenhd->enttype==adHatchEnttype(dwghandle))
- {
- return processentity_hatch(dwghandle);
- }
- else if(adenhd->enttype==adImageEnttype(dwghandle))
- {
- //图像
- //return processentity_image( adenHead, aden, bPaper, bBlock);
- }
- else if(adenhd->enttype==adLwplineEnttype(dwghandle))
- {
- return processentity_lwpline(dwghandle);
- }
- else if(adenhd->enttype==adOle2frameEnttype(dwghandle))
- {
- //OLE
- //return processentity_ole2frame( adenHead, aden, bPaper, bBlock);
- }
- else if(adenhd->enttype==adRtextEnttype(dwghandle))
- {//远程文字
- return processentity_rtext(dwghandle);
- }
- else if(adenhd->enttype==adWipeoutEnttype(dwghandle))
- {
- //带maskcolor的图像
- //return processentity_wipeout( adenHead, aden, bPaper, bBlock);
- }
- else if(adenhd->enttype==adDimAssocObjtype(dwghandle))
- {
- //2002新增实体AD_DIMASSOC
- //return processentity_wipeout( adenHead, aden, bPaper, bBlock);
- }
- else if(AD_IS_A_PROXYENT(adenhd->enttype))
- {
- _WRITE(str="遗漏的代理实体没有处理");
- }
- else
- {
- _WRITE(str="未知类型的ENTITY没有处理");
- }
- break;
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_enthead(AD_DB_HANDLE dwghandle)
- {
- unsigned short slwidth;
- int icolor;
- int iltype;
- double dlscale;
- UINT idlayer;
- double dscalelayer;
- double dscaleltype;
- m_alayer.Get(adenhd->entlayerobjhandle,idlayer,dscalelayer);
- m_altype.Get(adenhd->entltypeobjhandle,iltype,dscaleltype);
- try
- {
- if(adenhd->entcolor==AD_COLOR_BYBLOCK)
- {
- icolor=COLOR_BYBLOCK;//随块
- }
- else if(adenhd->entcolor==AD_COLOR_BYLAYER)
- {
- icolor=COLOR_BYLAYER;
- }
- else
- {
- if(adenhd->entcolor>=0 && adenhd->entcolor<m_aColor.GetSize())
- {
- icolor=m_aColor[adenhd->entcolor];
- }
- else
- {
- TRACE("errordata");
- }
- }
- }
- catch(...)
- {
- _WRITE(str="非法的颜色码");
- return FALSE;
- }
- if(dscaleltype<0)//线形随层
- {
- dlscale=adenhd->entltscale/dscalelayer;
- }
- else
- {
- dlscale=adenhd->entltscale/dscaleltype;
- }
- slwidth=adenhd->lineweight;
- int ilwidth=slwidth;
- {
- if(slwidth==AD_WEIGHT_DEFAULT)
- {
- ilwidth=m_ilinewidthdefault;
- }
- else if(slwidth==AD_WEIGHT_BYBLOCK)
- {
- ilwidth=LWIDTH_BYBLOCK;
- }
- else if(slwidth==AD_WEIGHT_BYLAYER)
- {
- ilwidth=LWIDTH_BYLAYER;
- }
- else
- {
- ilwidth=::GetLineWidthAsInt(double(abs(slwidth))/100.0);
- }
- }
- //应用打印样式
- if(m_dplotstyleconvmode==1)
- {
- UsePlotStyle(adenhd->entcolor,ilwidth,icolor,iltype,dlscale,adenhd->plotstyleobjhandle,adenhd->entflags);
- }
- m_pConverter->WriteEnthead(ilwidth,icolor,iltype,dlscale,idlayer);
- return TRUE;
- }
- void CDwgReader::UsePlotStyle(int acicolor,int &ilwidth, int &icolor, int &iltype, double &dlscale, AD_OBJHANDLE plotstyleobjhandle,unsigned char flag)
- {
- if(flag!=0)
- {
- //#define AD_BYBLOCK_PLOTSTYLE 32
- //#define AD_BYLAYER_PLOTSTYLE 64
- if(adEntHasByLayerPlotStyle(flag))
- {
- ilwidth=LWIDTH_BYLAYER;
- icolor=COLOR_BYLAYER;
- iltype=LTYPE_BYLAYER;
- return;
- }
- if(adEntHasByBlockPlotStyle(flag))
- {
- ilwidth=LWIDTH_BYBLOCK;
- icolor=COLOR_BYBLOCK;
- iltype=LTYPE_BYBLOCK;
- return;
- }
- }
- CString strPlotSheetName;
- if(!m_aplot.Get(plotstyleobjhandle,strPlotSheetName))return;
- if(strPlotSheetName=="Normal")
- {
- strPlotSheetName.Format("Color_%d",acicolor);
- //strPlotSheetName=""
- }
- /*
- typedef struct tagADPLOTSTYLE
- {
- short nPhysicalPenNumber; //笔号
- short nVirtualPenNumber; //虚拟笔
- OdaLong nColor; //颜色
- short nColorPolicy; //颜色方案
- short nScreen; //淡显
- double dblLinePatternSize;
- short nLinetype; //线型
- char bAdaptiveLinetype; //线型的自适应调整
- short nLineweight; //线宽 是指线宽表中的值
- short nFillStyle; //填充
- short nEndStyle; //端点
- short nJoinStyle; //链接
- } ADPLOTSTYLE;
- */
- ADPLOTSTYLE* pPlotStyle=NULL;
- int iPlotStyle=-1;
- if(m_iCurPlotStyleTable>=0&&m_iCurPlotStyleTable<m_aPlotStyleTable.GetSize())
- {
- pPlotStyle=NULL;
- //extern short ADCDECL adFindPlotStyleByName _((char *pszSearchName, ADPLOTSTYLETABLE *pTable, ADPLOTSTYLE **ppStyle));
- sReturnValue=adFindPlotStyleByName((char*)(LPCTSTR)strPlotSheetName,m_aPlotStyleTable[m_iCurPlotStyleTable],&pPlotStyle);
- if(sReturnValue!=1)
- {
- pPlotStyle=NULL;
- }
- }
- if(pPlotStyle==NULL)
- {
- for(int i=0;i<m_aPlotStyleTable.GetSize();i++)
- {
- if(i==m_iCurPlotStyleTable)continue;
- pPlotStyle=NULL;
- //extern short ADCDECL adFindPlotStyleByName _((char *pszSearchName, ADPLOTSTYLETABLE *pTable, ADPLOTSTYLE **ppStyle));
- sReturnValue=adFindPlotStyleByName((char*)(LPCTSTR)strPlotSheetName,m_aPlotStyleTable[i],&pPlotStyle);
- if(sReturnValue==1)
- {
- if(pPlotStyle!=NULL)
- {
- iPlotStyle=i;
- break;
- }
- }
- else
- {
- pPlotStyle=NULL;
- }
- }
- }
- else
- {
- iPlotStyle=m_iCurPlotStyleTable;
- }
- if(pPlotStyle==NULL)return;
- if(! (iPlotStyle>=0&&iPlotStyle<m_aPlotStyleTable.GetSize()) )
- {
- return;
- }
- if(pPlotStyle->nColor!=AD_COLOR_USEOBJECT)
- {
- // #define AD_COLORPOLICY_INDEX 1
- // #define AD_COLORPOLICY_GRAYSCALE 3
- // #define AD_COLORPOLICY_RGB 5
- if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_INDEX)
- {
- }
- if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_RGB)
- {
- BYTE br=GetRValue(pPlotStyle->nColor);
- BYTE bg=GetGValue(pPlotStyle->nColor);
- BYTE bb=GetBValue(pPlotStyle->nColor);
- icolor=RGB(bb,bg,br);
- }
- if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_GRAYSCALE)//转换为灰度
- {
- //亮度=0.5(min(r,g,b)+max(r,g,b));
- }
- }
- if(pPlotStyle->nLineweight!=AD_WEIGHT_USEOBJECT)
- {
- try
- {
- double dWidth=m_aPlotStyleTable[iPlotStyle]->aLineweights[pPlotStyle->nLineweight-1];
- ilwidth=::GetLineWidthAsInt(dWidth);
- }
- catch(...)
- {
- }
- }
- if(pPlotStyle->nLinetype!=AD_LINETYPE_USEOBJECT)
- {
- switch(pPlotStyle->nLinetype)
- {
- case AD_LINETYPE_LTPSOLID :
- iltype=SOLID_LINE;
- break;
- case AD_LINETYPE_LTPDASHED :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPDOTTED :
- iltype=DOT_LINE;
- break;
- case AD_LINETYPE_LTPDASHDOT :
- iltype=DASH_DOT_LINE;
- break;
- case AD_LINETYPE_LTPSHORTDASH :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPMEDIUMDASH :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPLONGDASH :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPSHORTDASHX2 :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPMEDIUMDASHX2 :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPLONGDASHX2 :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPMEDIUMLONGDASH :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPMEDIUMDASHSHORTDASHSHORTDASH :
- iltype=LONGDASH_DSHORTDASH_LINE;
- break;
- case AD_LINETYPE_LTPLONGDASHSHORTDASH :
- iltype=LONGDASH_SHORTDASH_LINE;
- break;
- case AD_LINETYPE_LTPLONGDASHDOTDOT :
- iltype=SDASH_DDOT_LINE;
- break;
- case AD_LINETYPE_LTPLONGDASHDOT :
- iltype=DASH_DOT_LINE;
- break;
- case AD_LINETYPE_LTPMEDIUMDASHDOTSHORTDASHDOT :
- iltype=LONGDASH_DSHORTDASH_LINE;
- break;
- case AD_LINETYPE_LTPSPARSEDOT :
- iltype=DOT_LINE;
- break;
- case AD_LINETYPE_LTPISODASH :
- iltype=DASHED_LINE;
- break;
- case AD_LINETYPE_LTPISODASHSPACE :
- iltype=DASH_SPACE_LINE;
- break;
- case AD_LINETYPE_LTPISOLONGDASHDOT :
- iltype=DASH_DOT_LINE;
- break;
- case AD_LINETYPE_LTPISOLONGDASHDOUBLEDOT :
- iltype=SDASH_DDOT_LINE;
- break;
- case AD_LINETYPE_LTPISOLONGDASHTRIPLEDOT :
- iltype=SDASH_TRIDOT_LINE;
- break;
- case AD_LINETYPE_LTPISODOT :
- iltype=DOT_LINE;
- break;
- case AD_LINETYPE_LTPISOLONGDASHSHORTDASH :
- iltype=LONGDASH_SHORTDASH_LINE;
- break;
- case AD_LINETYPE_LTPISOLONGDASHDOUBLESHORTDASH :
- iltype=LONGDASH_DSHORTDASH_LINE;
- break;
- case AD_LINETYPE_LTPISODASHDOT :
- iltype=DASH_DOT_LINE;
- break;
- case AD_LINETYPE_LTPISODOUBLEDASHDOT :
- iltype=DDASH_DOT_LINE;
- break;
- case AD_LINETYPE_LTPISODASHDOUBLEDOT :
- iltype=DASH_DDOT_LINE;
- break;
- case AD_LINETYPE_LTPISODOUBLEDASHDOUBLEDOT :
- iltype=DDASH_DDOT_LINE;
- break;
- case AD_LINETYPE_LTPISODASHTRIPLEDOT :
- iltype=SDASH_TRIDOT_LINE;
- break;
- case AD_LINETYPE_LTPISODOUBLEDASHTRIPLEDOT :
- iltype=DDASH_TRIDOT_LINE;
- break;
- }
- }
- }
- void CDwgReader::RGBtoHSV(double r, double g, double b, double *h, double *s, double *v)
- {
- }
- BOOL CDwgReader::processentity_line(AD_DB_HANDLE dwghandle)
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->line.pt0[0],aden->line.pt0[1],aden->line.pt0[2],
- aden->line.pt1[0],aden->line.pt1[1],aden->line.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("直线%x%x%x%x%x%x%x%x转换为第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_3dline(AD_DB_HANDLE dwghandle)
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->line3d.pt0[0],aden->line3d.pt0[1],aden->line3d.pt0[2],
- aden->line3d.pt1[0],aden->line3d.pt1[1],aden->line3d.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("3D直线%x%x%x%x%x%x%x%x转换为第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_point(AD_DB_HANDLE dwghandle)
- {
- int index=m_pConverter->ConverterEntiey_KmCircle(aden->point.pt0[0],aden->point.pt0[1],aden->point.pt0[2],m_dpointtocircleradius).dwEntIndex;
- _WRITE2(str.Format("点%x%x%x%x%x%x%x%x转换为第%d号圆",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_circle(AD_DB_HANDLE dwghandle)
- {
- if(calculate_BackView())
- {
- int index=m_pConverter->ConverterEntiey_KmCircle(-1*aden->circle.pt0[0],aden->circle.pt0[1],aden->circle.pt0[1],aden->circle.radius).dwEntIndex;
- _WRITE2(str.Format("圆%x%x%x%x%x%x%x%x转换为第%d号圆",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- else
- {
- int index=m_pConverter->ConverterEntiey_KmCircle(aden->circle.pt0[0],aden->circle.pt0[1],aden->circle.pt0[1],aden->circle.radius).dwEntIndex;
- _WRITE2(str.Format("圆%x%x%x%x%x%x%x%x转换为第%d号圆",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_ellipse(AD_DB_HANDLE dwghandle)
- {
- if(calculate_BackView())
- {
- double lr=calculate_3ddpdistance(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1],aden->ellipse.pt1offset[2]);
- double sr=lr*aden->ellipse.minortomajorratio;
- double angle=calculate_2dangle(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1]);
- if(fabs(fabs(aden->ellipse.startparam-aden->ellipse.endparam)-2*PI)<(PI/10000))
- {
- int index=m_pConverter->ConverterEntiey_KmEllipse(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,FALSE).dwEntIndex;
- _WRITE2(str.Format("椭圆%x%x%x%x%x%x%x%x转换为第%d号椭圆",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- //int index=m_pConverter->ConverterEntiey_KmEllipseArc(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,
- // angle-calculate_2dangle(-lr*cos(aden->ellipse.startparam),-sr*sin(aden->ellipse.startparam)),
- // angle-calculate_2dangle(-lr*cos(aden->ellipse.endparam),-sr*sin(aden->ellipse.endparam)),FALSE).dwEntIndex;
- int index=m_pConverter->ConverterEntiey_KmEllipseArc(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,
- angle,
- 2*angle-(angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.endparam),-sr*sin(aden->ellipse.endparam))),
- 2*angle-(angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.startparam),-sr*sin(aden->ellipse.startparam))),FALSE).dwEntIndex;
- _WRITE2(str.Format("椭圆弧%x%x%x%x%x%x%x%x转换为第%d号椭圆弧",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- else
- {
- double lr=calculate_3ddpdistance(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1],aden->ellipse.pt1offset[2]);
- double sr=lr*aden->ellipse.minortomajorratio;
- double angle=calculate_2dangle(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1]);
- if(fabs(fabs(aden->ellipse.startparam-aden->ellipse.endparam)-2*PI)<(PI/10000))
- {
- int index=m_pConverter->ConverterEntiey_KmEllipse(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,FALSE).dwEntIndex;
- _WRITE2(str.Format("椭圆%x%x%x%x%x%x%x%x转换为第%d号椭圆",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- int index=m_pConverter->ConverterEntiey_KmEllipseArc(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.startparam),-sr*sin(aden->ellipse.startparam)),angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.endparam),-sr*sin(aden->ellipse.endparam)),FALSE).dwEntIndex;
- _WRITE2(str.Format("椭圆弧%x%x%x%x%x%x%x%x转换为第%d号椭圆弧",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_arc(AD_DB_HANDLE dwghandle)
- {
- if(calculate_BackView())
- {
- int index=m_pConverter->ConverterEntiey_KmArc(-aden->arc.pt0[0],aden->arc.pt0[1],aden->arc.pt0[1],aden->arc.radius,PI-aden->arc.endang,PI-aden->arc.stang).dwEntIndex;
- _WRITE2(str.Format("圆弧%x%x%x%x%x%x%x%x转换为第%d号圆弧",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- else
- {
- int index=m_pConverter->ConverterEntiey_KmArc(aden->arc.pt0[0],aden->arc.pt0[1],aden->arc.pt0[1],aden->arc.radius,aden->arc.stang,aden->arc.endang).dwEntIndex;
- _WRITE2(str.Format("圆弧%x%x%x%x%x%x%x%x转换为第%d号圆弧",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_xline(AD_DB_HANDLE dwghandle)
- {
- double x1=aden->xline.pt0[0]-m_dconstrulinelength*aden->xline.unitvec[0];
- double y1=aden->xline.pt0[1]-m_dconstrulinelength*aden->xline.unitvec[1];
- double z1=aden->xline.pt0[2]-m_dconstrulinelength*aden->xline.unitvec[2];
- double x2=aden->xline.pt0[0]+m_dconstrulinelength*aden->xline.unitvec[0];
- double y2=aden->xline.pt0[1]+m_dconstrulinelength*aden->xline.unitvec[1];
- double z2=aden->xline.pt0[2]+m_dconstrulinelength*aden->xline.unitvec[2];
- int index=m_pConverter->ConverterEntiey_KmLine(x1,y1,z1,x2,y2,z2).dwEntIndex;
- _WRITE2(str.Format("结构线%x%x%x%x%x%x%x%x转换为第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_3dface(AD_DB_HANDLE dwghandle)
- {
- if(!(aden->face3d.faceflag&AD_FACE3D_FACE1INVIS))
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->face3d.pt0[0],aden->face3d.pt0[1],aden->face3d.pt0[2],aden->face3d.pt1[0],aden->face3d.pt1[1],aden->face3d.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("结构线%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- if(!(aden->face3d.faceflag&AD_FACE3D_FACE2INVIS))
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->face3d.pt1[0],aden->face3d.pt1[1],aden->face3d.pt1[2],aden->face3d.pt2[0],aden->face3d.pt2[1],aden->face3d.pt2[2]).dwEntIndex;
- _WRITE2(str.Format("结构线%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- if(!(aden->face3d.faceflag&AD_FACE3D_FACE3INVIS))
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->face3d.pt2[0],aden->face3d.pt2[1],aden->face3d.pt2[2],aden->face3d.pt3[0],aden->face3d.pt3[1],aden->face3d.pt3[2]).dwEntIndex;
- _WRITE2(str.Format("结构线%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- if(!(aden->face3d.faceflag&AD_FACE3D_FACE4INVIS))
- {
- int index=m_pConverter->ConverterEntiey_KmLine(aden->face3d.pt3[0],aden->face3d.pt3[1],aden->face3d.pt3[2],aden->face3d.pt0[0],aden->face3d.pt0[1],aden->face3d.pt0[2]).dwEntIndex;
- _WRITE2(str.Format("结构线%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_ray(AD_DB_HANDLE dwghandle)
- {
- double x1=aden->ray.pt0[0]+m_dconstrulinelength*aden->ray.unitvec[0];
- double y1=aden->ray.pt0[1]+m_dconstrulinelength*aden->ray.unitvec[1];
- double z1=aden->ray.pt0[2]+m_dconstrulinelength*aden->ray.unitvec[2];
- int index=m_pConverter->ConverterEntiey_KmLine(aden->ray.pt0[0],aden->ray.pt0[1],aden->ray.pt0[2],x1,y1,z1).dwEntIndex;
- _WRITE2(str.Format("射线%x%x%x%x%x%x%x%x转换为第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_spline(AD_DB_HANDLE dwghandle)
- {
- int mode;
- if(aden->spline.numctlpts>0)
- {
- switch(m_dsplineconvmode)
- {
- case 1:
- mode=2; //二次样条曲线
- break;
- default:
- mode=10+2; //折线
- break;
- }
- }
- else if(aden->spline.numfitpts>0)
- {
- switch(m_dsplineconvmode)
- {
- case 1:
- mode=3; //三次样条曲线
- break;
- default:
- mode=10+3; //折线
- break;
- }
- }
- else
- {
- _WRITE(str="样条没有控制点,没有转换");
- return FALSE;
- }
-
- int index=m_pConverter->ConverterEntiey_KmSPline(mode,aden->spline.ldblob,aden->spline.numknots,aden->spline.numctlpts,aden->spline.numfitpts).dwEntIndex;
- _WRITE2(str.Format("样条%x%x%x%x%x%x%x%x转换为第%d号样条",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_insert(AD_DB_HANDLE dwghandle)
- {
- //short attribsfollow;是否有属性文字,紧接着是属性实体,不予特别考虑
- UINT id;
- int index;
- double lscale;
- KmPoint pt;
- double dx=aden->insert.rowdist;
- double dy=aden->insert.coldist;
- m_ablock.Get(aden->insert.blockheaderobjhandle,id,lscale);
- if(id==0)
- {
- return TRUE;
- }
- BOOL b90mirror=calculate_BackView();
- for(int i=0;i<aden->insert.numrows;i++)//行
- {
- for(int j=0;j<aden->insert.numcols;j++)//列
- {
- pt=calculate_2drotate(aden->insert.pt0[0],aden->insert.pt0[1],i*dx,j*dy,aden->insert.rotang);
- index=m_pConverter->ConverterEntiey_KmBlockref(pt.x,pt.y,aden->insert.pt0[2],aden->insert.xscale,aden->insert.yscale,aden->insert.zscale,aden->insert.rotang,id,b90mirror).dwEntIndex;
- _WRITE2(str.Format("块引用%x%x%x%x%x%x%x%x转换生成第%d号块引用",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- }
- /* if(aden->insert.xdblob != AD_VMNULL)
- {
- AD_ENT_HDR HatchEntHdr;
- AD_ENT HatchEnt;
- HatchEntHdr.enttype = adHatchEnttype(dwghandle);
- adSetEntityDefaults(dwghandle, &HatchEntHdr, &HatchEnt);
- //Purpose: Retrieve the hatch data from "xdata" of INSERT entity.
- if(!processentity_XData(dwghandle, &HatchEnt.hatch, adenhd, HatchHandle))
- {
- _WRITE(str="转换块引用的xdblob中中的剖面线失败");
- }
- }*/
- return TRUE;
- }
- BOOL CDwgReader::processentity_block(AD_DB_HANDLE dwghandle)
- {//aden->block.xrefpath暂不考虑引用块
- return m_pConverter->ConverterEntiey_KmBlockdef(aden->block.base[0],aden->block.base[1],aden->block.base[2]);
- }
- BOOL CDwgReader::processentity_mline(AD_DB_HANDLE dwghandle)
- {
- if(aden->mline.linesinstyle<=1)
- {
- _WRITE(str="平行线段数小于2段不能转换");
- return FALSE;
- }
- CMatch4* match;
- if(!m_amltype.Get(aden->mline.mlinestyleobjhandle,match))
- {
- return FALSE;
- }
- PAD_BLOB_CTRL bcptr;
- double pt0[3],ptemp[3],vertdir[3],miterdir[3];
- CArray<double,double>pt10;
- CArray<double,double>pt11;
- CArray<double,double>pt12;
- CArray<double,double>pt20;
- CArray<double,double>pt21;
- CArray<double,double>pt22;
- pt10.SetSize(aden->mline.linesinstyle);
- pt11.SetSize(aden->mline.linesinstyle);
- pt12.SetSize(aden->mline.linesinstyle);
- pt20.SetSize(aden->mline.linesinstyle);
- pt21.SetSize(aden->mline.linesinstyle);
- pt22.SetSize(aden->mline.linesinstyle);
- short numsegparms,numareafillparms;
- double segparm,areafillparm;
- //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
- bcptr=adStartBlobRead(aden->mline.ldblob);
- unsigned short i,j,k;
- for(i=0;i<aden->mline.numverts;i++)
- {
- adReadBlob3Double(bcptr,pt0);//鼠标点击点
- adReadBlob3Double(bcptr,vertdir);//鼠标点击点的方向,无需转换
- adReadBlob3Double(bcptr,miterdir);//平行点偏移方向
- for(j=0;j<aden->mline.linesinstyle; j++)
- {
- m_pConverter->WriteEnthead(match->segcolor[j],match->segltyle[j]);
- adReadBlobShort(bcptr,&numsegparms);
- for (k=0; k<numsegparms; k++)
- {
- adReadBlobDouble(bcptr,&segparm);//第一个数据为沿偏移方向的平面偏移
- if(k==0)
- {
- if(i==0)
- {
- pt10[j]=pt20[j]=pt0[0]+segparm*miterdir[0];
- pt11[j]=pt21[j]=pt0[1]+segparm*miterdir[1];
- pt12[j]=pt22[j]=pt0[2]+segparm*miterdir[2];
- }
- else
- {//生成线段
- ptemp[0]=pt0[0]+segparm*miterdir[0];
- ptemp[1]=pt0[1]+segparm*miterdir[1];
- ptemp[2]=pt0[2]+segparm*miterdir[2];
- m_pConverter->ConverterEntiey_KmLine(pt20[j],pt21[j],pt22[j],ptemp[0],ptemp[1],ptemp[2]);
- pt20[j]=ptemp[0];
- pt21[j]=ptemp[1];
- pt22[j]=ptemp[2];
- }
- }
- }
- adReadBlobShort(bcptr,&numareafillparms);
- for (k=0; k<numareafillparms; k++)
- {
- adReadBlobDouble(bcptr,&areafillparm);//无需转换
- }
- //处理连接弧
- }
- if( (match->m_startline&&(i==0))||
- (match->m_endline&&(i==(aden->mline.numverts-1)))||
- (match->m_showmiter&&((i!=0)||(i!=(aden->mline.numverts-1)))))
- {//会自动排序
- m_pConverter->WriteEnthead(match->segcolor[0],match->segltyle[0]);
- m_pConverter->ConverterEntiey_KmLine(pt20[0],pt21[0],pt22[0],pt0[0],pt0[1],pt0[2]);
- m_pConverter->WriteEnthead(match->segcolor[aden->mline.linesinstyle-1],match->segltyle[aden->mline.linesinstyle-1]);
- m_pConverter->ConverterEntiey_KmLine(pt20[aden->mline.linesinstyle-1],pt21[aden->mline.linesinstyle-1],pt22[aden->mline.linesinstyle-1],pt0[0],pt0[1],pt0[2]);
- }
- if(i==(aden->mline.numverts-1))
- {//结束
- if(aden->mline.openclosed&AD_MLINE_CLOSED)
- {
- for(j=0;j<aden->mline.linesinstyle;j++)
- {
- m_pConverter->WriteEnthead(match->segcolor[j],match->segltyle[j]);
- m_pConverter->ConverterEntiey_KmLine(pt10[j],pt11[j],pt12[j],pt20[j],pt21[j],pt22[j]);
- }
- }
- }
- }
- adEndBlobRead(bcptr);
- pt10.RemoveAll();
- pt11.RemoveAll();
- pt12.RemoveAll();
- pt20.RemoveAll();
- pt21.RemoveAll();
- pt22.RemoveAll();
- _WRITE2(str.Format("平行线%x%x%x%x%x%x%x%x成功被转换",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7]));
- return TRUE;
- }
- //DEL BOOL CDwgReader::processentity_shape(AD_DB_HANDLE dwghandle)
- //DEL {
- //DEL //形所在的形文件句柄,形在的形文件所有形中的序号
- //DEL //形的基点,缩放,倾斜,旋转,宽高比
- //DEL m_ashape.processentity(m_pConverter,aden->shape.shapefileobjhandle,aden->shape.whichshape,
- //DEL aden->shape.pt0[0],aden->shape.pt0[1],aden->shape.pt0[2],aden->shape.scale,aden->shape.oblique,aden->shape.rotang,aden->shape.widthfactor);
- //DEL return TRUE;
- //DEL }
- BOOL CDwgReader::processentity_solid(AD_DB_HANDLE dwghandle)
- {
- //对于等腰三角形可以转换为东方箭头
- if( m_pConverter->ConverterEntiey_KmArrowHead(
- aden->solid.pt0[0],aden->solid.pt0[1],
- aden->solid.pt1[0],aden->solid.pt1[1],
- aden->solid.pt2[0],aden->solid.pt2[1],
- aden->solid.pt3[0],aden->solid.pt3[1]) )
- {
- return TRUE;
- }
- //1 2
- int index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt0[0],aden->solid.pt0[1],aden->solid.pt0[2],
- aden->solid.pt1[0],aden->solid.pt1[1],aden->solid.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("Solid%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- //1 3
- index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt0[0],aden->solid.pt0[1],aden->solid.pt0[2],
- aden->solid.pt2[0],aden->solid.pt2[1],aden->solid.pt2[2]).dwEntIndex;
- _WRITE2(str.Format("Solid%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- //3 4 如果用户按ENTER生成三角形面域则不生成该直线
- if(!(aden->solid.pt2[0]==aden->solid.pt3[0] && aden->solid.pt2[1]==aden->solid.pt3[1] && aden->solid.pt2[2]==aden->solid.pt3[2]))
- {
- index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt2[0],aden->solid.pt2[1],aden->solid.pt2[2],
- aden->solid.pt3[0],aden->solid.pt3[1],aden->solid.pt3[2]).dwEntIndex;
- _WRITE2(str.Format("Solid%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- //2 4
- index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt1[0],aden->solid.pt1[1],aden->solid.pt1[2],
- aden->solid.pt3[0],aden->solid.pt3[1],aden->solid.pt3[2]).dwEntIndex;
- _WRITE2(str.Format("Solid%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_acis(AD_DB_HANDLE dwghandle)
- {
- //acis数据较为复杂,应当启动acis程序分析出投影数据来.
- if(aden->acisobj.ldblob!=AD_VMNULL)
- {
- PAD_BLOB_CTRL bcptr;
- char str[520];
- bcptr=adStartBlobRead(aden->acisobj.ldblob);
- while(adReadAcisString(bcptr,str))
- {//分析acis数据
-
- }
- adEndBlobRead(bcptr);
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_trace(AD_DB_HANDLE dwghandle)
- {
- //对于等腰三角形可以转换为东方箭头
- if( m_pConverter->ConverterEntiey_KmArrowHead(
- aden->trace.pt0[0],aden->trace.pt0[1],
- aden->trace.pt1[0],aden->trace.pt1[1],
- aden->trace.pt2[0],aden->trace.pt2[1],
- aden->trace.pt3[0],aden->trace.pt3[1]) )
- {
- return TRUE;
- }
- //1 2
- int index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt0[0],aden->trace.pt0[1],aden->trace.pt0[2],
- aden->trace.pt1[0],aden->trace.pt1[1],aden->trace.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("trace%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- //1 3
- index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt0[0],aden->trace.pt0[1],aden->trace.pt0[2],
- aden->trace.pt2[0],aden->trace.pt2[1],aden->trace.pt2[2]).dwEntIndex;
- _WRITE2(str.Format("trace%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- //3 4
- index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt2[0],aden->trace.pt2[1],aden->trace.pt2[2],
- aden->trace.pt3[0],aden->trace.pt3[1],aden->trace.pt3[2]).dwEntIndex;
- _WRITE2(str.Format("trace%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- //2 4
- index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt3[0],aden->trace.pt3[1],aden->trace.pt3[2],
- aden->trace.pt1[0],aden->trace.pt1[1],aden->trace.pt1[2]).dwEntIndex;
- _WRITE2(str.Format("trace%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- /*
- 函数说明:
- 功能:转换视口。
- */
- BOOL CDwgReader::processentity_viewport(AD_DB_HANDLE dwghandle)
- {
- ASSERT(adenhd);
- ASSERT(aden);
-
- if(aden->vpent.statusflags&AD_VPENT_STATUS_OFF)
- {
- return TRUE;
- }
- if(aden->vpent.purgedflag==1)
- {
- return TRUE;
- }
- if(aden->vpent.viewheight==0)
- {
- return TRUE;
- }
- double cx=aden->vpent.cen[0];
- double cy=aden->vpent.cen[1];
- double w=aden->vpent.width*0.5;
- double h=aden->vpent.height*0.5;
- double minx=cx-w;
- double miny=cy-h;
- double maxx=cx+w;
- double maxy=cy+h;
- DWORD dwKmId;
- if(m_pConverter->GetDataVessel(dwKmId)==DATAVESSEL_DATABASE)
- {
- CString strName;
- CString strDes;
- strName="*ViewPort";
- strName+=aden->vpent.name;
- strDes="转换至视口";
- strDes+=aden->vpent.name;
- UINT id=m_pConverter->ConverterEnthead_Blockdefine(strName,strDes);
- BOOL bsucc=m_pConverter->SetDataVessel(DATAVESSEL_BLOCKDEF,id);
- m_pConverter->WriteEnthead(RGB(0,0,0),SOLID_LINE);//设置视口边的转化属性。
- int index=m_pConverter->ConverterEntiey_KmLine(minx,miny,0,minx,maxy,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(minx,maxy,0,maxx,maxy,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(maxx,maxy,0,maxx,miny,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(maxx,miny,0,minx,miny,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- if(!m_pConverter->ConverterEntiey_KmBlockdef(cx,cy,0))
- {
- _WRITE(str="error in conv blockdef");
- }
- if(!m_pConverter->SetDataVessel(DATAVESSEL_DATABASE))
- {
- _WRITE(str="error in set datavessel");
- }
- m_pConverter->ConverterEntiey_KmBlockref(cx,cy,0,1,1,1,0,id,FALSE);
- }
- else
- {
- m_pConverter->WriteEnthead(RGB(0,0,0),SOLID_LINE);//设置视口边的转化属性。
- int index=m_pConverter->ConverterEntiey_KmLine(minx,miny,0,minx,maxy,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(minx,maxy,0,maxx,maxy,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(maxx,maxy,0,maxx,miny,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- index=m_pConverter->ConverterEntiey_KmLine(maxx,miny,0,minx,miny,0).dwEntIndex;
- _WRITE2(str.Format("视口%x%x%x%x%x%x%x%x转换生成第%d号直线",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- }
- double s=aden->vpent.height / aden->vpent.viewheight;
- m_pConverter->UniteModelToSpace(aden->vpent.cen[0] - aden->vpent.viewcenter[0]*s,aden->vpent.cen[1] - aden->vpent.viewcenter[1]*s,0,s,minx,miny,maxx,maxy,m_dviewcutconvmode);
- return TRUE;
- }
- //说明 AutoCAD的字高完全为英文定制
- // 规则1: 字高的数值=标准英文字母(不含个别出头的字母)字高
- // 规则2: 汉字肯定要上下出头 出头量总共为22.77% 上下分别为11.37%
- // KmCAD的字高为汉字定制
- // 规则1: 字高的数值=标准的汉字字高(并略有缩小,忽略不计)
- //因此涉及到计算左上角的问题 和涉及到计算字高的问题都应当考虑
- BOOL CDwgReader::processentity_text(AD_DB_HANDLE dwghandle)
- {
- #ifdef _BAOJI_
- static double textHeight = 0.0;
- static KmPoint ptPos;
- static int icount = 0;
- static BOOL bFristTime = FALSE;
- if (strstr(aden->text.textstr,"黄色")) {
- int stop;
- stop = 1;
- }
-
- if (strstr(aden->text.textstr,"技术要求")) {
- icount = 0;
- bFristTime = TRUE;
- }
- if (icount == 1) {
- ptPos = KmPoint(aden->text.pt0[0],aden->text.pt0[1]);
- textHeight = aden->text.tdata.height;
- }
- if (m_dwTextcount == 0) {
- m_dTotalTxtHeight += aden->text.tdata.height;
- m_dwTextcount ++;
- }
- double averHeight = m_dTotalTxtHeight / (double) m_dwTextcount;
- if (aden->text.tdata.height * 4.0 < averHeight)
- {
- if (icount < 20)
- {
- if (aden->text.tdata.height * 8.0 < textHeight)
- {
- if (bFristTime)
- {
- aden->text.pt0[0] += 2.0 * textHeight;
- bFristTime = FALSE;
- }
- else
- {
- aden->text.pt0[0] = ptPos.x;
- ptPos.y -= textHeight * 1.2;
- aden->text.pt0[1] = ptPos.y;
- }
- }
- aden->text.tdata.height = textHeight;
- }
- else
- {
- aden->text.pt0[1] -= averHeight * 0.4;
- aden->text.tdata.height = averHeight;
- }
- }
-
- if (m_dwTextcount != 0) {
- m_dTotalTxtHeight += aden->text.tdata.height;
- m_dwTextcount ++;
- }
- icount ++;
- #endif
- if(aden->text.textstr[0]==0x0){return TRUE;}
- if(aden->text.textstr[0]==10){if(aden->text.textstr[1]==0x0){return TRUE;}}
- if(aden->text.textstr[0]==32){if(aden->text.textstr[1]==0x0){return TRUE;}}//空格符号
- CShape* shape;
- {
- CMatch5* match=NULL;
- if(!m_ashape.Get(aden->text.tdata.shapefileobjhandle,match))
- {
- _WRITE(str="没有找到文字样式");
- return FALSE;
- }
- shape=match->m_shape;
- }
- //左下角转换为左上角
- KmPoint pRT=calculate_2drotate(aden->text.pt0[0],aden->text.pt0[1],0,aden->text.tdata.height*(calculate_findTTFPosRate(shape->m_strShapefilename)),aden->text.tdata.rotang);
- aden->text.tdata.height=aden->text.tdata.height;//*calculate_findTTFHightRate(shape->m_strShapefilename);
- aden->text.tdata.widthfactor=aden->text.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
- int index=m_pConverter->ConverterEntiey_KmSText(aden->text.textstr,pRT.x,pRT.y,aden->text.pt0[2],&aden->text.tdata,shape).dwEntIndex;
- _WRITE2(str.Format("文字%x%x%x%x%x%x%x%x转换为第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_attdef(AD_DB_HANDLE dwghandle)
- {
- //属性定义,只有在非块中的才转换
- DWORD dwKmId;
- switch(m_pConverter->GetDataVessel(dwKmId))
- {
- case DATAVESSEL_BLOCKDEF:
- return TRUE;
- default:
- {
- CShape* shape;
- {
- CMatch5* match;
- if(!m_ashape.Get(aden->attdef.tdata.shapefileobjhandle,match))
- {
- _WRITE(str="无法找到文字样式");
- return FALSE;
- }
- shape=match->m_shape;
- }
- KmPoint pRT=calculate_2drotate(aden->attdef.pt0[0],aden->attdef.pt0[1],0,aden->attdef.tdata.height*(calculate_findTTFPosRate(shape->m_strShapefilename)),aden->attdef.tdata.rotang);
- aden->attdef.tdata.height=aden->attdef.tdata.height;//*calculate_findTTFHightRate(shape->m_strShapefilename);
- aden->attdef.tdata.widthfactor=aden->attdef.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
- int index=m_pConverter->ConverterEntiey_KmSText(aden->attdef.tag,pRT.x,pRT.y,aden->attdef.pt0[2],&aden->attdef.tdata,shape).dwEntIndex;
- _WRITE(str.Format("属性定义%x%x%x%x%x%x%x%x转换为第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- break;
- }
- return TRUE;
- }
- BOOL CDwgReader::processentity_attrib(AD_DB_HANDLE dwghandle)
- {
- //#define AD_ATTRIB_INVIS 1 不可见指定在插入块时不显示属性值。ATTDISP 可替代“不可见”模式。
- //#define AD_ATTRIB_CONST 2 固定在插入块时给属性赋固定值。
- //#define AD_ATTRIB_VERIFY 4 验证在插入块时提示验证属性值是否正确。
- //#define AD_ATTRIB_PRESET 8 预置在插入包含预置属性值的块时将属性设为缺省值。
- if(aden->attrib.attflag&AD_ATTRIB_INVIS)
- {
- return FALSE;
- }
- //左下角转换为左上角
- CShape* shape;
- {
- CMatch5* match;
- if(!m_ashape.Get(aden->attrib.tdata.shapefileobjhandle,match))
- {
- _WRITE(str="无法找到文字样式");
- return FALSE;
- }
- shape=match->m_shape;
- }
- KmPoint pRT=calculate_2drotate(aden->attrib.pt0[0],aden->attrib.pt0[1],0,aden->attrib.tdata.height*(calculate_findTTFPosRate(shape->m_strShapefilename)),aden->attrib.tdata.rotang);
- aden->attrib.tdata.height=aden->attrib.tdata.height;
- aden->attrib.tdata.widthfactor=aden->attrib.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
- int index=m_pConverter->ConverterEntiey_KmSText(aden->attrib.attval,pRT.x,pRT.y,aden->attrib.pt0[2],&aden->attrib.tdata,shape).dwEntIndex;
- _WRITE2(str.Format("属性实体%x%x%x%x%x%x%x%x转换为第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_polyline(AD_DB_HANDLE dwghandle,AD_VMADDR list)
- {
- if(adenhd->enttype!=AD_ENT_POLYLINE)
- {
- _WRITE(str="输入的实体不是多段线,无法处理");
- return FALSE;
- }
- if(!processentity_enthead(dwghandle))
- {
- return FALSE;
- }
- unsigned short ployflag=aden->pline.polyflag;
-
- CArray<CVector*,CVector*>avectors;
- short res;
- int dSplinevertextype=0;//AD_VERTEX_SPLINEVERTEX or AD_VERTEX_SPLINEFRAME
- CVector* pvector=NULL;
- do
- {
- res = adGetEntity(list,adenhd,aden);
- if(res && adenhd->enttype==AD_ENT_VERTEX)
- {
- pvector=new CVector;
- pvector->m_x=aden->vertex.pt0[0];
- pvector->m_y=aden->vertex.pt0[1];
- pvector->m_z=aden->vertex.pt0[2];
- pvector->m_bulge=aden->vertex.bulge;
- if(ployflag&AD_PLINE_SPLINEFIT)
- {
- if(dSplinevertextype==0)
- {
- if(aden->vertex.vertexflag&AD_VERTEX_SPLINEFRAME)
- {
- dSplinevertextype=1;
- avectors.Add(pvector);
- }
- else if(aden->vertex.vertexflag&AD_VERTEX_SPLINEVERTEX)
- {
- dSplinevertextype=2;
- avectors.Add(pvector);
- }
- else
- {
- delete pvector;
- }
- }
- else if((dSplinevertextype==1)&&(aden->vertex.vertexflag&AD_VERTEX_SPLINEFRAME))
- {
- avectors.Add(pvector);
- }
- else if((dSplinevertextype==2)&&(aden->vertex.vertexflag&AD_VERTEX_SPLINEVERTEX))
- {
- avectors.Add(pvector);
- }
- else
- {
- delete pvector;
- }
- }
- else
- {
- avectors.Add(pvector);
- }
- }
- }
- while(res && adenhd->enttype==AD_ENT_VERTEX );
- if((!res)||(adenhd->enttype!=AD_ENT_SEQEND)||(avectors.GetSize()<=1))//理论上res应当不为零,块的实体链表必须由AD_ENT_ENDBLK实体结束
- {
- _WRITE(str="无法找到块结束或多段线结束标记");
- for(int i=0;i<avectors.GetSize();i++)
- {
- delete avectors[i];
- }
- avectors.RemoveAll();
- return FALSE;
- }
- //ref:
- //#define AD_PLINE_CLOSED 1
- //#define AD_PLINE_SPLINEFIT 4
- if(ployflag&AD_PLINE_CLOSED)
- {
- pvector=new CVector;
- pvector->m_x=avectors[0]->m_x;
- pvector->m_y=avectors[0]->m_y;
- pvector->m_z=avectors[0]->m_z;
- pvector->m_bulge=avectors[0]->m_bulge;
- avectors.Add(pvector);
- }
- if(ployflag&AD_PLINE_SPLINEFIT)
- {
- KmSpLine* pspline=new KmSpLine;
- pspline->m_iType=T_BPLINE;
- pspline->m_nNodeNum=avectors.GetSize();
- for(int i=0;i<avectors.GetSize();i++)
- {
- pspline->m_aNode.Add(KmPoint(avectors[i]->m_x,avectors[i]->m_y));
- }
- m_pConverter->ConverterEntiey_KmObject(pspline);
- }
- else
- {
- calculate_3dbulgelines(avectors);
- }
- for(int i=0;i<avectors.GetSize();i++)
- {
- delete avectors[i];
- }
- avectors.RemoveAll();
- return TRUE;
- }
- BOOL CDwgReader::processentity_lwpline(AD_DB_HANDLE dwghandle)
- {
- double pt[3];pt[2]=0.0;
- CArray<CVector*,CVector*>avectors;
- CVector* pvector;
- //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
- PAD_BLOB_CTRL bcptr;
- bcptr=adStartBlobRead(aden->lwpline.ldblob);
- for(int i=0;i<aden->lwpline.numpoints;i++)
- {
- pvector=new CVector;
- //short adReadBlob2Double (PAD_BLOB_CTRL bcptr,double *doub);
- sReturnValue=adReadBlob2Double(bcptr,pt);
- if(sReturnValue!=1)
- {
- _ERROR;
- }
- pvector->m_x=pt[0];
- pvector->m_y=pt[1];
- pvector->m_z=pt[2];
- if(aden->lwpline.flag&AD_LWPLINE_HAS_BULGES)
- {
- //short adReadBlobDouble (PAD_BLOB_CTRL bcptr,double *doub);
- sReturnValue=adReadBlobDouble(bcptr,pt);
- if(sReturnValue!=1)
- {
- _ERROR;
- }
- pvector->m_bulge=pt[0];
- }
- else
- {
- pvector->m_bulge=0;
- }
- if(aden->lwpline.flag & AD_LWPLINE_HAS_WIDTHS)
- {
-
- //short adReadBlob2Double (PAD_BLOB_CTRL bcptr,double *doub);
- sReturnValue=adReadBlob2Double(bcptr,pt);
- if(sReturnValue!=1)
- {
- _ERROR;
- }
- else
- {
- if(pt[0]>1.0e-6||pt[1]>1.0e-6)
- {
- pvector->m_bwidth=TRUE;
- pvector->m_widthbegin=pt[0];
- pvector->m_widthend=pt[1];
- }
- }
- }
- avectors.Add(pvector);
- }
- //short adEndBlobRead (PAD_BLOB_CTRL bcptr);
- sReturnValue=adEndBlobRead(bcptr);
- if(sReturnValue!=1)
- {
- _ERROR;
- }
- if(aden->lwpline.flag & AD_LWPLINE_IS_CLOSED)
- {
- pvector=new CVector;
- pvector->m_x=avectors[0]->m_x;
- pvector->m_y=avectors[0]->m_y;
- pvector->m_z=avectors[0]->m_z;
- pvector->m_bulge=avectors[0]->m_bulge;
- avectors.Add(pvector);
- }
- calculate_3dbulgelines(avectors);
- for(i=0;i<avectors.GetSize();i++)
- {
- delete avectors[i];
- }
- avectors.RemoveAll();
- return TRUE;
- }
- BOOL CDwgReader::processentity_mtext(AD_DB_HANDLE dwghandle)
- {
- //转换文字第1步-得到文字样式.
- CShape* shape;
- {
- CMatch5* match;
- if(!m_ashape.Get(aden->mtext.shapefileobjhandle,match))
- {
- _WRITE(str="无法找到文字样式");
- return FALSE;
- }
- shape=match->m_shape;
- }
- //转换文字第2步-得到文字的内容.
- CString strEnter;
- {
- if (aden->mtext.ldblob==AD_VMNULL)
- {
- if(aden->mtext.textstr[0]==0)
- {
- return TRUE;
- }
- if(aden->mtext.textstr[0]==10)
- {
- if(aden->mtext.textstr[1]==0x0)//回车符号
- {
- return TRUE;
- }
- }
- if(aden->mtext.textstr[0]==32)
- {
- if(aden->mtext.textstr[1]==0x0)//空格符号
- {
- return TRUE;
- }
- }
- strEnter=aden->mtext.textstr;
- }
- else
- {
- char textstr[257];
- PAD_BLOB_CTRL bcptr;
- //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
- bcptr=adStartBlobRead(aden->mtext.ldblob);
- //short adReadMtextBlock (PAD_BLOB_CTRL bcptr, char *str);
- while(adReadMtextBlock(bcptr,textstr))
- {
- for(int i=0;i<256;i++)
- {
- if(textstr[i]==0)
- {
- break;
- }
- strEnter+=textstr[i];
- }
- }
- //short adEndBlobRead (PAD_BLOB_CTRL bcptr);
- if(adEndBlobRead(bcptr)!=1)
- {
- _ERROR;
- }
- }
- if(strEnter.GetLength()<=0)
- {
- return TRUE;
- }
- if(strEnter.GetLength()==1)
- {
- if(strEnter[0]==10)
- {
- return TRUE;
- }
- if(strEnter[0]==32)
- {
- return TRUE;
- }
- }
- }
- //转换文字第3步-得到角度,高度,宽度. (一个旋转的矩形A)
- double angle;
- double Height;
- double Width;
- {
- angle=calculate_2dangle(aden->mtext.xdir[0],aden->mtext.xdir[1]);
- Height = 0.0;
- Width = 0.0;//文字边框宽,高
- if((aden->mtext.boxht <= 0) || (aden->mtext.boxwid <= 0))
- {
- DOUBRECTFULL rect;
- rect.pt0[0]=0.0;
- rect.pt0[1]=0.0;
- rect.pt1[0]=0.0;
- rect.pt1[1]=0.0;
- double bottomy;
- AD_TDATA tdata;
- AD_SHPTB shp;
- sReturnValue=adSeekShapefile(dwghandle,aden->mtext.shapefileobjhandle, &shp);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(shp.bigfontname[0]==0&&shp.file[0]==0
- &&shp.name[0]==0)
- {
- _ERROR;
- return FALSE;
- }
- tdata.height = aden->mtext.ht;
- tdata.widthfactor = shape->m_dShapeWidth;
- tdata.oblique = shape->m_dShapeAngle*PI/180;
- tdata.rotang = angle;
- if(aden->mtext.boxht <= 0)
- {
- int num=1;
- for(int k=0;k<strEnter.GetLength();k++)
- {
- if(strEnter[k]=='\n')
- {
- num++;
- }
- }
- Height=aden->mtext.ht*num;
- }
- else
- {
- Height=aden->mtext.boxht;
- }
- if(aden->mtext.boxwid<= 0)
- {
- try //说明 该OpenDWG函数不稳定,有可能死在该函数内部.
- {
- sReturnValue=adTextBoundingBox(dwghandle,(unsigned char*)aden->mtext.textstr,&tdata,0,shp.file[0] ? shp.file : NULL, shp.bigfontname[0] ? shp.bigfontname : NULL, 1, &rect, &bottomy);
- if(sReturnValue!=1)
- {//位置1
- sReturnValue=adTextBoundingBox(dwghandle,(unsigned char*)aden->mtext.textstr,&tdata,0,NULL,NULL,1,&rect,&bottomy);
- if(sReturnValue!=1)
- {//实在无法计算出宽度则自己计算宽度。
- Width=calculate_findstringlength(strEnter)*aden->mtext.ht*shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
- }
- else
- {
- Width=rect.pt1[0] - rect.pt0[0];
- }
- }
- else
- {//位置2
- Width=rect.pt1[0] - rect.pt0[0];
- }
- }
- catch(...)
- {
- if(0 == aden->mtext.ht)
- return FALSE;
- else//added by hq,2003.4.28
- {//位置3
- //adTextBoundingBox使用不当造成的逻辑异常,
- //为了不对其他部分造成影响,增加else判断:
- Width=calculate_findstringlength(strEnter)*aden->mtext.ht*shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
- }
- }
- }
- else
- {
- Width = aden->mtext.boxwid;
- }
- }
- else
- {//位置4
- Height = aden->mtext.boxht;
- Width = aden->mtext.boxwid;
- }
- }
- //转换文字第4步-得到左上角坐标 (一个旋转的矩形B)
- KmPoint pRT;
- pRT.x=aden->mtext.pt0[0];
- pRT.y=aden->mtext.pt0[1];
- switch( aden->mtext.attachpt)
- {
- case AD_MTEXT_ATTACH_TOPLEFT://左上
- break;
- case AD_MTEXT_ATTACH_TOPCENTER://中上 -> 左上 x-0.5W
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,0,angle);
- break;
- case AD_MTEXT_ATTACH_TOPRIGHT:
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width,0,angle);
- break;
- case AD_MTEXT_ATTACH_MIDDLELEFT:
- pRT=calculate_2drotate(pRT.x,pRT.y,0,Height*0.5,angle);
- break;
- case AD_MTEXT_ATTACH_MIDDLECENTER:
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,Height*0.5,angle);
- break;
- case AD_MTEXT_ATTACH_MIDDLERIGHT:
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width,Height*0.5,angle);
- break;
- case AD_MTEXT_ATTACH_BOTTOMLEFT:
- pRT=calculate_2drotate(pRT.x,pRT.y,0,Height,angle);
- break;
- case AD_MTEXT_ATTACH_BOTTOMCENTER:
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,Height,angle);
- break;
- case AD_MTEXT_ATTACH_BOTTOMRIGHT:
- pRT=calculate_2drotate(pRT.x,pRT.y,-Width,Height,angle);
- break;
- default:
- break;
- }
- //#ifdef _DEBUG
- // {
- // KmPoint p1=pRT;
- // KmPoint p2=calculate_2drotate(pRT.x,pRT.y,Width,0,angle);
- // KmPoint p3=calculate_2drotate(pRT.x,pRT.y,Width,-Height,angle);
- // KmPoint p4=calculate_2drotate(pRT.x,pRT.y,0,-Height,angle);
- //
- // m_pConverter->ConverterEntiey_KmLine(p1.x,p1.y,0.0,p2.x,p2.y,0.0);
- // m_pConverter->ConverterEntiey_KmLine(p2.x,p2.y,0.0,p3.x,p3.y,0.0);
- // m_pConverter->ConverterEntiey_KmLine(p3.x,p3.y,0.0,p4.x,p4.y,0.0);
- // m_pConverter->ConverterEntiey_KmLine(p4.x,p4.y,0.0,p1.x,p1.y,0.0);
- // }
- //#endif
- //WAIT TO DO double dtexthight=aden->mtext.ht*(1+2*m_dtextposmodify);
- double dtexthight=aden->mtext.ht;
- //检查是否有中文字符,如有则加大字高
- // for(int m=0;m<strEnter.GetLength();m++)
- /// {
- // if((unsigned char)strEnter[m]>0x7f)
- // {
- // dtexthight*=1.2423;//1.311;
- // break;
- // }
- // }
- //针对KmCAD校正左上角坐标pRT=calculate_2drotate(pRT.x,pRT.y,0,aden->mtext.ht*(m_dtextposmodify),angle);
- #ifdef _DEBUG
- if(pRT.x>1000000)
- {
- _WRITE(str="错误的文字");
- }
- if(pRT.x<-1000000)
- {
- _WRITE(str="错误的文字");
- }
- if(pRT.y>1000000)
- {
- _WRITE(str="错误的文字");
- }
- if(pRT.y<-1000000)
- {
- _WRITE(str="错误的文字");
- }
- #endif
- double spacehight=aden->mtext.linespacingfactor*(m_dlinespacemodify*aden->mtext.ht);//行距约等于高度的一半
- double widthhight=shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
- int index=m_pConverter->ConverterEntiey_KmText(strEnter,pRT.x,pRT.y,aden->mtext.pt0[2],angle,dtexthight,widthhight,spacehight,aden->mtext.attachpt,Height,Width,shape,aden->mtext.refrectwid).dwEntIndex;
- _WRITE2(str.Format("多行文字%x%x%x%x%x%x%x%x转换成第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_leader(AD_DB_HANDLE dwghandle)
- {
- //引出转换为东方的单项标注
- PAD_BLOB_CTRL bcptr=adStartBlobRead(aden->leader.ldblob);
- if( (short)aden->leader.numpoints<2 )
- {
- return FALSE;
- }
- int i;
- double pt0[3];
- KmDXBZ* pDXBZ=new KmDXBZ;
- CArray<KmPoint,KmPoint>pts;
- for (i=0; i<(short)aden->leader.numpoints; i++)
- {
- adReadBlob3Double(bcptr,pt0);
- pts.Add(KmPoint(pt0[0],pt0[1]));
-
- //<<added by hq,2003.4.29
- if(2 == aden->leader.numpoints && 1 == i)
- {
- if(1 == aden->leader.hashookline)
- {
- if(1 == aden->leader.hooklineonxdir)
- pts.Add(KmPoint((pt0[0]-aden->leader.annowid),pt0[1]));
- else
- pts.Add(KmPoint((pt0[0]+aden->leader.annowid),pt0[1]));
- }
- }
- //>>
- }
- adEndBlobRead(bcptr);
- for(i=pts.GetSize();i>0;i--)
- {
- pDXBZ->m_aPts.Add(pts[i-1]);
- }
- if(aden->leader.arrowheadon)
- {
- pDXBZ->m_uType=1;
- //extern short ADCDECL adSeekDimstyle _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_DIMSTYLE addimst));
- AD_DIMSTYLE dimstyle;
- if(adSeekDimstyle(dwghandle,aden->leader.dimstyleobjhandle,&dimstyle)==1)
- {
- pDXBZ->m_dArrowSize=dimstyle.dimasz;
- }
- }
- else
- {
- pDXBZ->m_uType=0;
- }
- m_pConverter->ConverterEntiey_KmObject(pDXBZ);
-
- /* int i;
- KmPoint pB;
- KmPoint pE;
- double pt0[3];
- KmPoint pTempPoint;
- KmPoint pArrowPoint;
- double dArrowAngle;
- PAD_BLOB_CTRL bcptr=adStartBlobRead(aden->leader.ldblob);
- if( (short)aden->leader.numpoints<2 )
- {
- return FALSE;
- }
- adReadBlob3Double(bcptr,pt0);
- pTempPoint.x=pt0[0];
- pTempPoint.y=pt0[1];
- pArrowPoint=pTempPoint;
- for (i=1; i<(short)aden->leader.numpoints; i++)
- {
- adReadBlob3Double(bcptr,pt0);
- // 可以处理pt0
- if(i==1)
- {
- dArrowAngle=atan2(pt0[1]-pTempPoint.y,pt0[0]-pTempPoint.x);
- }
- //从pTempPoint到pt0[i],pt0[i];
- pB=pTempPoint;
- pE.x=pt0[0];
- pE.y=pt0[1];
- m_pConverter->ConverterEntiey_KmLine(pB.x,pB.y,0.0,pE.x,pE.y,pt0[2]);
- pTempPoint.x=pt0[0];
- pTempPoint.y=pt0[1];
- }
- adEndBlobRead(bcptr);
-
- if(aden->leader.arrowheadon)//引出有箭头
- {
- //pArrowPoint 箭头顶点
- //dArrowAngle 箭头角度
- if(adenhd->xdblob != AD_VMNULL)//尺寸有扩展数据
- {
- int tag=0;
- AD_XD adxd;
- PAD_BLOB_CTRL bcptr2;
- bcptr2 = adStartBlobRead(adenhd->xdblob);
- while(adReadExtendeddata(bcptr2,&adxd))
- {
- //连续读入四个1070组,来得到它们的尺寸类型信息
- //且顺序为1070,7,1070,style,1070,6,1070, style
- //当不是这个顺序时,tag赋零,
- if (adxd.xddxfnumber == 1070 || (adxd.xddxfnumber == 1000 && (tag==1||tag==3) ) )
- {
- tag++;
- }
- else
- {
- tag=0;
- }
- switch(tag)
- {
- case 1:
- if(adxd.xddata.xdint != 7)
- {
- tag = 0;
- }
- break;
- case 2: //第一个箭头
- break;
- case 3:
- if(adxd.xddata.xdint != 6)
- {
- tag = 0;
- }
- break;
- case 4: //第2个箭头
- if(strcmp((char*)adxd.xddata.xdbindata, "_DOT") == 0) //点
- {
- //生成圆 (-x y) distx/3500
- pB.x=-pArrowPoint.x;
- pB.y=pArrowPoint.y;
- m_pConverter->ConverterEntiey_KmCircle(pB.x,pB.y,0.0,m_dpointtocircleradius);
- break;
- }
- else //其余的转成箭头
- {
- //生成箭头 (x y) (3cos(a)+x 3sin(a)+y (0 1) )
- pB.x=3*cos(dArrowAngle)+pArrowPoint.x;
- pB.y=3*sin(dArrowAngle)+pArrowPoint.y;
- pE=pArrowPoint;
- m_pConverter->ConverterEntiey_KmArrow(pB.x,pB.y,0.0,pE.x,pE.y,0.0,1);
- }
- tag = 0;
- break;
- }
- }
- adEndBlobRead(bcptr2);
- }
- else
- {
- adStartDimstyleGet (dwghandle);
- AD_DIMSTYLE DimStyle;
- for(i=0; i<adNumDimstyles(dwghandle); i++)
- {
- adGetDimstyle(dwghandle,&DimStyle);//得到尺寸风格
- if(!memcmp((char*)DimStyle.objhandle, (char*)aden->leader.dimstyleobjhandle, 8))
- {
- if(!strcmp((char*)DimStyle.dimblk2objhandle, "_DOT"))//点箭头
- {
- //生成圆 (x y) distx/3500
- pB.x=-pArrowPoint.x;
- pB.y=pArrowPoint.y;
- m_pConverter->ConverterEntiey_KmCircle(pB.x,pB.y,0.0,m_dpointtocircleradius);
- break;
- }
- else //其余的转成三角型箭头
- {
- //生成箭头 (x y) (3cos(a)+x 3sin(a)+y (0 1) )
- pB.x=3*cos(dArrowAngle)+pArrowPoint.x;
- pB.y=3*sin(dArrowAngle)+pArrowPoint.y;
- pE=pArrowPoint;
- m_pConverter->ConverterEntiey_KmArrow(pB.x,pB.y,0.0,pE.x,pE.y,0.0,1);
- break;
- }
- }
- }
- }
- }
- _WRITE2(str.Format("引出标注%x%x%x%x%x%x%x%x转换成功",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7]));*/
- return TRUE;
- }
- BOOL CDwgReader::processentity_tolerance(AD_DB_HANDLE dwghandle)
- {
- CShape* shape;
- {
- AD_DIMSTYLE dimstyle;
- //extern short ADCDECL adSeekDimstyle _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_DIMSTYLE addimst));
- if(adSeekDimstyle(dwghandle,aden->tolerance.dimstyleobjhandle,&dimstyle)!=1)
- {
- _ERROR;
- return FALSE;
- }
- CMatch5* match;
- if(!m_ashape.Get(dimstyle.shapefileobjhandle,match))
- {
- _WRITE(str="无法找到文字样式");
- return FALSE;
- }
- shape=match->m_shape;
- }
- double texthight;
- if(fabs(aden->tolerance.textht)<0.0000001)
- {
- texthight=-1;
- if(adenhd->xdblob!=AD_VMNULL)
- {
- {
- BOOL bControlStart=FALSE;
- BOOL bControlCode=FALSE;
- int dControlCode=0;
- PAD_BLOB_CTRL bcptr;
- bcptr=adStartBlobRead(adenhd->xdblob);
- while(adReadExtendeddata(bcptr,adxd))
- {
- if (adxd->xddxfnumber==1040) //adxd->xddata.xdreal
- {
- if(bControlStart==TRUE)
- {
- if(bControlCode)
- {
- processentity_tol_blob(dControlCode,adxd->xddxfnumber,texthight);
- bControlCode=FALSE;
- }
- else
- {
- TRACE("错误的blob数据");
- }
- }
- //else 忽略
- }
- else if (adxd->xddxfnumber==1070) //adxd->xddata.xdint
- {
- if(bControlStart==TRUE)
- {
- if(!bControlCode)
- {
- dControlCode=adxd->xddata.xdint;
- bControlCode=TRUE;
- }
- }
- //else 忽略
- }
- else if (adxd->xddxfnumber==1002) //adxd->xddata.xdcontrol 123 '{' 125 '}'
- {
- if(adxd->xddata.xdcontrol=='{')
- {
- if(bControlStart==TRUE)
- {
- TRACE("错误的blob数据");
- }
- else
- {
- bControlStart=TRUE;
- }
- }
- else if(adxd->xddata.xdcontrol=='}')
- {
- if(bControlStart==TRUE)
- {
- bControlStart=FALSE;
- }
- else
- {
- TRACE("错误的blob数据");
- }
- }
- }
- }
- adEndBlobRead(bcptr);
- }
- }
- if(texthight<0.0000001)
- {
- AD_DIMSTYLE addimst;
- //short adSeekDimstyle (AD_DB_HANDLE handle, AD_OBJHANDLE thehandle, PAD_DIMSTYLE addimst);
- sReturnValue=adSeekDimstyle(dwghandle,aden->tolerance.dimstyleobjhandle,&addimst);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- texthight=addimst.dimtxt;//DIMTXT 标注文字高度
- }
- }
- else
- {
- texthight=aden->tolerance.textht;
- }
- texthight=texthight*calculate_findTTFHightRate(shape->m_strShapefilename);
- //{xlf:ACAD认为形位公差的高度等于形位公差文字高度的2倍,
- //KCAD认为形位公差的高度等于形位公差文字高度的1.2倍。
- texthight=texthight*(2.0);//调整带框字符和不带框字符的字高误差
- double angle=calculate_2dangle(aden->tolerance.xdir[0],aden->tolerance.xdir[1]);
- KmPoint pRT=calculate_2drotate(aden->tolerance.pt0[0],aden->tolerance.pt0[1],0,texthight*calculate_findTTFPosRate(shape->m_strShapefilename)*0.5,angle);//*0.5的原因在于形位公差以左中为基点.
- int index=m_pConverter->ConverterEntiey_KmText(TRUE,aden->tolerance.textstr,pRT.x,pRT.y,aden->tolerance.pt0[2],texthight*calculate_findTTFHightRate(shape->m_strShapefilename),angle,m_dtoltextwidthf,m_dtoltextspacef,shape).dwEntIndex;
- _WRITE2(str.Format("形位公差%x%x%x%x%x%x%x%x转换为第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- void CDwgReader::processentity_tol_blob(int code,short datatype,double &tolhight)
- {//目前仅读出形位公差的高度,以后如有需要则可仿照..._dim_blob读出来
- switch(code)
- {
- case 140://DIMTXT
- if(datatype!=1040)
- {
- TRACE("错误的数据");
- break;
- }
- tolhight=adxd->xddata.xdreal;
- break;
- }
- }
- BOOL CDwgReader::processentity_atext(AD_DB_HANDLE dwghandle)
- {
- CShape* shape;
- {
- CMatch5* match=NULL;
- if(!m_ashape.Get(aden->arcalignedtext.textstyleobjhandle,match))
- {
- _WRITE(str="没有找到文字样式");
- }
- shape=match->m_shape;
- }
- AD_TDATA data;
- adHancpy(data.shapefileobjhandle,aden->arcalignedtext.textstyleobjhandle);
- KmPoint pRT,ptemp;
- pRT.x=aden->arcalignedtext.pt0[0]+aden->arcalignedtext.radius*cos(aden->arcalignedtext.startangle);
- pRT.y=aden->arcalignedtext.pt0[1]+aden->arcalignedtext.radius*sin(aden->arcalignedtext.startangle);
- ptemp.x=aden->arcalignedtext.pt0[0]+aden->arcalignedtext.radius*cos(aden->arcalignedtext.endangle);
- ptemp.y=aden->arcalignedtext.pt0[1]+aden->arcalignedtext.radius*sin(aden->arcalignedtext.endangle);
- data.height=aden->arcalignedtext.height;
- data.rotang=calculate_2dangle(ptemp.x-pRT.x,ptemp.y-pRT.y);
- data.widthfactor=aden->arcalignedtext.widthfactor;
- data.widthfactor=data.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
- int index=m_pConverter->ConverterEntiey_KmSText(aden->arcalignedtext.text,pRT.x,pRT.y,aden->arcalignedtext.pt0[2],&data,shape).dwEntIndex;
- _WRITE2(str.Format("文字%x%x%x%x%x%x%x%x转换为第%d号文字",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- BOOL CDwgReader::processentity_rtext(AD_DB_HANDLE dwghandle)
- {
- //外部文字暂不予处理
- return TRUE;
- }
- void CDwgReader::calculate_rotatealix(double &x,double &y,double a)
- {
- KmMatrix matrix;//旋转矩阵
- double angle = -1*a;
- KmPoint pt(x,y) ;
- matrix.r11 = (double)cos(angle);
- matrix.r21 = (double)sin(angle);
- matrix.r31 = 0.0;
- matrix.r12 = (double)(-sin(angle));
- matrix.r22 = (double)cos(angle);
- matrix.r32 = 0.0;
- matrix.r13 = 0.0;
- matrix.r23 = 0.0;
- matrix.r33 = 1.0;
- pt=matrix*pt;
- x=pt.x;
- y=pt.y;
- }
- BOOL CDwgReader::processentity_hatch(AD_DB_HANDLE dwghandle)
- {
- PAD_BLOB_CTRL bcptr;//,boundarybcptr;
- long il,jl,kl,numpathsegs,pathflag,splineknots,splinedegree,splinectrlpts,numboundaryobjects;
- unsigned char pathtypestatus;
- double pt0[2],pt1[2],radius,startangle,endangle,center[2],axisendpt[2],startparam,endparam;
- double minmajratio,knot,ctrlpt[2];
- unsigned short rational,periodic,closed;
- short i,j;
- double lineangle,patternthrough[2],patternoffset[2],dashitem;
- // double seedptx,seedpty;
- double vertpt[2],bulge,weight;
- short dashlengthitems,bulgespresent;
- short isccw;
- // AD_OBJHANDLE temphandle;
- // char temphandlestr[20];
- // char pixelsizepresent;
-
- // if (aden->hatch.boundaryobjblob!=AD_VMNULL)
- // boundarybcptr=adStartBlobRead(aden->hatch.boundaryobjblob);
- // pixelsizepresent=0;
- PATH2* path=new PATH2;
- bcptr=adStartBlobRead(aden->hatch.pathblob);
- for (il=0; il<aden->hatch.numpaths; il++)
- {
- if(adReadBlobLong(bcptr,&pathflag)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- //#define AD_HATCH_PATHFLAG_DEFAULT 0
- //#define AD_HATCH_PATHFLAG_EXTERNAL 1
- //#define AD_HATCH_PATHFLAG_DERIVED 4
- //#define AD_HATCH_PATHFLAG_TEXTBOX 8
- //#define AD_HATCH_PATHFLAG_OUTERMOST 16
- // if (pathflag & 4)
- // {
- // pixelsizepresent=1; /* if ANY of them meet this criterion */
- // }
- if (!(pathflag & AD_HATCH_PATHFLAG_POLYLINE))
- {
- if(adReadBlobLong(bcptr,&numpathsegs)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- for (jl=0; jl<numpathsegs; jl++)
- {
- if(adReadBlobByte(bcptr,(char*)&pathtypestatus)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if (pathtypestatus==AD_HATCH_PATHTYPE_LINE)
- {
- if(adReadBlob2Double(bcptr,pt0)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlob2Double(bcptr,pt1)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(calculate_BackView())
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_line(path,-1*pt0[0],pt0[1],-1*pt1[0],pt1[1]);
- }
- }
- else
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_line(path,pt0[0],pt0[1],pt1[0],pt1[1]);
- }
- }
- }
- else if (pathtypestatus==AD_HATCH_PATHTYPE_CIRCARC)
- {
- if(adReadBlob2Double(bcptr,pt0)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&radius)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&startangle)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&endangle)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobShort(bcptr,(short *)&isccw)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- KmCircle* pCircle=new KmCircle;
- pCircle->SetCenter(pt0[0],pt0[1]);
- pCircle->SetRadius(radius);
- pCircle->SetBAngle((-1*startangle)*180/PI);
- pCircle->SetEAngle((-1*endangle)*180/PI);
- if(isccw)//c clockwise 逆时针方向
- {
- pCircle->SetBAngle((startangle)*180/PI);
- pCircle->SetEAngle((endangle)*180/PI);
- pCircle->SetMessage(MESSAGE_CIRCLE_POSITIVE);
- }
- else
- {
- pCircle->SetBAngle((-1*startangle)*180/PI);
- pCircle->SetEAngle((-1*endangle)*180/PI);
- pCircle->SetMessage(MESSAGE_CIRCLE_NEGATIVE);
- }
- if(calculate_BackView())
- {
- pCircle->xo=-1*pCircle->xo;
- pCircle->b_angle=PI+pCircle->b_angle;
- pCircle->e_angle=PI+pCircle->e_angle;
- }
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_object(path,pCircle);
- }
- delete pCircle;
- }
- else if (pathtypestatus==AD_HATCH_PATHTYPE_ELLIPARC)
- {
- if(adReadBlob2Double(bcptr,center)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlob2Double(bcptr,axisendpt)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&minmajratio)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&startparam)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobDouble(bcptr,&endparam)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobShort(bcptr,(short *)&isccw)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- KmEllipse* pellipse=new KmEllipse;
- pellipse->SetMessage(MESSAGE_CIRCLE_POSITIVE);
- pellipse->SetCenter(KmPoint(center[0],center[1]));
- double lr=calculate_3ddpdistance(axisendpt[0],axisendpt[1],0);
- double sr=lr*minmajratio;
- double a=calculate_2dangle(axisendpt[0],axisendpt[1]);
- pellipse->SetLr(lr);
- pellipse->SetSr(sr);
- pellipse->SetAngle(a*180/PI);
- if(isccw)
- {
- pellipse->SetBeginAngle((a+PI+calculate_2dangle(-lr*cos(startparam),-sr*sin(startparam)))*180/PI);
- pellipse->SetEndAngle((a+PI+calculate_2dangle(-lr*cos(endparam),-sr*sin(endparam)))*180/PI);
- }
- else
- {
- pellipse->SetEndAngle((a+PI-calculate_2dangle(-lr*cos(startparam),-sr*sin(startparam)))*180/PI);
- pellipse->SetBeginAngle((a+PI-calculate_2dangle(-lr*cos(endparam),-sr*sin(endparam)))*180/PI);
- }
- if(calculate_BackView())
- {
- pellipse->Mirror(KmPoint(0,0),90);
- }
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_object(path,pellipse);
- }
- delete pellipse;
- }
- else if (pathtypestatus==AD_HATCH_PATHTYPE_SPLINE)
- {
- if(adReadBlobLong(bcptr,&splinedegree)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobShort(bcptr,(short *)&rational)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobShort(bcptr,(short *)&periodic)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobLong(bcptr,&splineknots)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobLong(bcptr,&splinectrlpts)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- for (kl=0L; kl<splineknots; kl++)
- {
- if(adReadBlobDouble(bcptr,&knot)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- }
- KmSpLine* pspline=new KmSpLine;
- pspline->m_nNodeNum=splinectrlpts;
- pspline->m_iType=T_BPLINE;
- for (kl=0L; kl<splinectrlpts; kl++)
- {
- if(adReadBlob2Double(bcptr,ctrlpt)!=1)
- {
- _ERROR;
- delete path;
- delete pspline;
- return FALSE;
- }
- pspline->m_aNode.Add(KmPoint(ctrlpt[0],ctrlpt[1]));
- if (rational)
- {
- if(adReadBlobDouble(bcptr,&weight)!=1)
- {
- _ERROR;
- delete path;
- delete pspline;
- return FALSE;
- }
- }
- }
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_object(path,pspline);
- }
- delete pspline;
- }
- } /* for jl */
- }
- else
- { /* pathflag & 2 is true */
- if(adReadBlobShort(bcptr,&bulgespresent)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobShort(bcptr,(short *)&closed)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(adReadBlobLong(bcptr,&numpathsegs)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- double lastx=0,firstx=0;
- double lasty=0,firsty=0;
- double lastb=0;
- for (jl=0L; jl<numpathsegs; jl++)
- {
- if(adReadBlob2Double(bcptr,vertpt)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if (bulgespresent)
- {
- if(adReadBlobDouble(bcptr,&bulge)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(jl!=0)
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_bugleline(path,lastx,lasty,lastb,vertpt[0],vertpt[1]);
- }
- }
- else
- {
- firstx=vertpt[0];
- firsty=vertpt[1];
- }
- lastx=vertpt[0];
- lasty=vertpt[1];
- lastb=bulge;
- }
- else
- {
- if(jl!=0)
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_line(path,lastx,lasty,vertpt[0],vertpt[1]);
- }
- }
- else
- {
- firstx=vertpt[0];
- firsty=vertpt[1];
- }
- lastx=vertpt[0];
- lasty=vertpt[1];
- }
- }
- if(closed)
- {
- if (bulgespresent)
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_bugleline(path,vertpt[0],vertpt[1],lastb,firstx,firsty);
- }
- }
- else
- {
- if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
- {
- calculate_path_line(path,vertpt[0],vertpt[1],firstx,firsty);
- }
- }
- }
- }
- if(adReadBlobLong(bcptr,&numboundaryobjects)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- } /* il < numpaths */
- if(adEndBlobRead(bcptr)!=1)
- {
- _ERROR;
- delete path;
- return FALSE;
- }
- if(path->b_angle.GetSize()<=1)
- {
- _WRITE(str="剖面的路径数为零");
- return FALSE;
- }
- if(aden->hatch.solidfill==1)//实心的
- {
- KmSection* pSection=new KmSection;
- pSection->m_Path.Add(path);
- pSection->m_PathNumber=1;
- pSection->SetReticleflag(TRUE);
- //限定剖面线的条数最多为500条.
- KmRect rect=pSection->GetRect();
- if(aden->hatch.pixelsize<rect.Height()*0.002)
- {
- aden->hatch.pixelsize=rect.Height()*0.002;
- }
- if(aden->hatch.pixelsize<rect.Width()*0.002)
- {
- aden->hatch.pixelsize=rect.Width()*0.002;
- }
- pSection->SetSpace(aden->hatch.pixelsize);
- int index=m_pConverter->ConverterEntiey_KmObject(pSection).dwEntIndex;
- _WRITE2(str.Format("剖面%x%x%x%x%x%x%x%x转换为第%d号剖面",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- if(aden->hatch.patterntype==0)//用户定义的单向剖面线
- {
- KmSection* pSection=new KmSection;
- pSection->m_Path.Add(path);
- pSection->m_PathNumber=1;
- if(aden->hatch.doublehatch==1)
- {
- pSection->SetReticleflag(TRUE);
- }
- else
- {
- pSection->SetReticleflag(FALSE);
- }
- pSection->SetAngle((int)(aden->hatch.angle*180/PI));
- pSection->SetSpace(aden->hatch.scaleorspacing);
- int index=m_pConverter->ConverterEntiey_KmObject(pSection).dwEntIndex;
- _WRITE2(str.Format("剖面%x%x%x%x%x%x%x%x转换出第%d号剖面",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- return TRUE;
- }
- KmPatternSection* pPSection=new KmPatternSection;
- pPSection->m_Path.Add(path);
- pPSection->m_PathNumber=1;
- pPSection->m_PatternNumber=0;
- bcptr=adStartBlobRead(aden->hatch.hatchblob);
- for (i=0; i<(short)aden->hatch.numdeflines; i++)
- {
- if(adReadBlobDouble(bcptr,&lineangle)!=1)
- {//角度
- _ERROR;
- delete pPSection;
- return FALSE;
- }
- if(adReadBlob2Double(bcptr,patternthrough)!=1)
- {//原点
- _ERROR;
- delete pPSection;
- return FALSE;
- }
- if(adReadBlob2Double(bcptr,patternoffset)!=1)
- {//偏移
- _ERROR;
- delete pPSection;
- return FALSE;
- }
- calculate_rotatealix(patternoffset[0],patternoffset[1],lineangle);
- if(adReadBlobShort(bcptr,&dashlengthitems)!=1)
- {
- _ERROR;
- delete pPSection;
- return FALSE;
- }
- CArray<double,double>dashs;
- for(j=0;j<dashlengthitems; j++)
- {
- if(adReadBlobDouble(bcptr,&dashitem)!=1)
- {
- _ERROR;
- delete pPSection;
- return FALSE;
- }
- dashs.Add(fabs(dashitem));
- }
- if(dashlengthitems<=1)
- {
- KmPattern* pPattern2=new KmPattern;
- pPattern2->dBasex=patternthrough[0];
- pPattern2->dBasey=patternthrough[1];
- pPattern2->dOffsetx=patternoffset[0];
- pPattern2->dOffsety=patternoffset[1];
- pPattern2->dAngle=lineangle*180/PI;
- pPattern2->bDash=FALSE;
- pPattern2->dBright=0;
- pPattern2->dHidden=0;
- pPSection->m_PatternArray.Add(pPattern2);
- pPSection->m_PatternNumber++;
- continue;
- }
- if((dashs.GetSize()%2))
- {
- dashs.RemoveAt(dashs.GetSize()-1);
- }
- //1.计算出路径的总长度.
- double totallength=0;
- for(int i=0;i<dashs.GetSize();i++)
- {
- if(dashs[i]<PRECISION)//AutoCAD中的点转换为0.1的长度
- dashs[i]=0.1;
- totallength+=dashs[i];
- }
- //2.
- double prelength=0;
- for(int k=0;k<dashs.GetSize();k++)
- {
- if(!(k%2))
- {
- if(k+1<dashs.GetSize())
- {
- //k k+1 prelength;
- {
- KmPattern* pPattern2=new KmPattern;
- pPattern2->dBasex=patternthrough[0]+prelength*cos(lineangle);
- pPattern2->dBasey=patternthrough[1]+prelength*sin(lineangle);
- pPattern2->dOffsetx=patternoffset[0];
- pPattern2->dOffsety=patternoffset[1];
- pPattern2->dAngle=lineangle*180/PI;
- pPattern2->bDash=TRUE;
- pPattern2->dBright=dashs[k];
- pPattern2->dHidden=dashs[k+1];
- pPSection->m_PatternArray.Add(pPattern2);
- pPSection->m_PatternNumber++;
- }
- prelength+=dashs[k];
- prelength+=dashs[k+1];
- k++;
- continue;
- }
- }
- prelength+=dashs[k];
- }
- }
- adEndBlobRead(bcptr);
- if(pPSection->m_PatternNumber==0)
- {
- delete pPSection;
- _WRITE(str="没有找到剖面的填充风格");
- return FALSE;
- }
- /* if(aden->hatch.scaleorspacing!=0)
- {
- double scale;
- try
- {
- scale=1/aden->hatch.scaleorspacing;
- scale=fabs(scale);
- if(scale<0.1)scale=0.1;
- }
- catch(...)
- {
- scale=1.0;
- }
- pPSection->SetScale(scale);
- }*/
- int index=m_pConverter->ConverterEntiey_KmObject(pPSection).dwEntIndex;
- _WRITE2(str.Format("剖面%x%x%x%x%x%x%x%x转换出第%d号剖面",adenhd->enthandle[0],adenhd->enthandle[1],adenhd->enthandle[2],adenhd->enthandle[3],adenhd->enthandle[4],adenhd->enthandle[5],adenhd->enthandle[6],adenhd->enthandle[7],index));
- // if (pixelsizepresent)
- // {
- // TRACE("47n%fn",aden->hatch.pixelsize);
- // }
- // bcptr=adStartBlobRead(aden->hatch.seedpointblob);
- // for (il=0; il<aden->hatch.numseedpoints; il++)
- // {
- // adReadBlobDouble(bcptr,&seedptx);
- // adReadBlobDouble(bcptr,&seedpty);
- // }
- // adEndBlobRead(bcptr);
- // if (aden->hatch.boundaryobjblob!=AD_VMNULL)
- // adEndBlobRead(boundarybcptr);
- return TRUE;
- }
- BOOL CDwgReader::processentity_shape(AD_DB_HANDLE dwghandle)
- {
- KmBuffer buff;
- if(!calculate_findshape(dwghandle,aden->shape.shapefileobjhandle,aden->shape.whichshape,&aden->shape.pt0[0],&aden->shape.pt0[1],
- ((double)aden->shape.rotang),
- 1,aden->shape.scale,aden->shape.widthfactor,
- &buff))return FALSE;
- AD_TB adtbtemp;
- //extern short ADCDECL adSeekShapefile _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_SHPTB theshptb));
- short sReturnValue = adSeekShapefile(dwghandle,aden->shape.shapefileobjhandle,&adtbtemp.shptb);
- if(sReturnValue!=1)
- {
- return FALSE;
- }
- return m_pConverter->ConverterEntiey_KmBuffer(buff,adtbtemp.shptb.name,adtbtemp.shptb.name,KmPoint(aden->shape.pt0[0],aden->shape.pt0[1]));
- }