Processfile.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:68k
- // KMCAD40-FileSwitch-Processfile.cpp-1.0
- //----------------------------------------
- //KMCAD40-FileSwitch-Processfile.cpp-1.0 -> 1.1
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "DwgReader.h"
- #include "KmSection.h"
- #include "propertyList.h"
- #include "SpaceConvDlg.h"
- #include "Reader.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- BOOL CDwgReader::CallSpaceConvDlg(HWND hWnd,CStringArray &m_strSpaceNames,CStringArray &m_strSpaceFiles,int &iCur)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- HINSTANCE hPreInstResource=AfxGetResourceHandle();
- AfxSetResourceHandle(::GetModuleHandle(NULL) );
- if(m_strSpaceNames.GetSize()!=m_strSpaceFiles.GetSize())
- {
- AfxSetResourceHandle(hPreInstResource);
- return FALSE;
- }
- CWnd* pWnd=CWnd::FromHandle(hWnd);
- CSpaceConvDlg dlg(pWnd);
- for(int i=0;i<m_strSpaceNames.GetSize();i++)
- {
- dlg.m_strSpaceNames.Add(m_strSpaceNames[i]);
- dlg.m_strSpaceFiles.Add(m_strSpaceFiles[i]);
- }
- if(dlg.DoModal()==IDOK)
- {
- if(m_strSpaceFiles.GetSize()!=dlg.m_strSpaceFiles.GetSize())
- {
- AfxSetResourceHandle(hPreInstResource);
- return FALSE;
- }
- for(i=0;i<m_strSpaceFiles.GetSize();i++)
- {
- m_strSpaceFiles[i]=dlg.m_strSpaceFiles[i];
- }
- iCur=dlg.m_iCur;
- AfxSetResourceHandle(hPreInstResource);
- return TRUE;
- }
- AfxSetResourceHandle(hPreInstResource);
- return FALSE;
- }
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- extern CTypedPtrMap<CMapStringToPtr, CString, void*> g_afont;
- BOOL CDwgReader::processfile(AD_DB_HANDLE dwghandle,BOOL bPaper)
- {
- m_pProgress->SetProgressInfoAbsolute(0.31,"分析文件头...");
- if(!processheader(dwghandle))
- {
- _WRITE(str="转换Header节失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.32,"分析系统变量...");
- if(!processsysvar(dwghandle))
- {
- _WRITE(str="转换系统变量失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.33,"分析代码页...");
- if(!processcodepage(dwghandle))
- {
- _WRITE(str="代码页失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.34,"分析颜色...");
- if(!processcolor(dwghandle))
- {
- _WRITE(str="转换颜色失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.35,"分析线宽...");
- if(!processlinewidth(dwghandle))
- {
- _WRITE(str="转换线宽失败");
- return FALSE;
- }
- if(!processobject(dwghandle))
- {
- _WRITE(str="转换OBJECT时失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.37,"分析代理实体...");
- if(!preprocess_Convertproxy(dwghandle,m_dproxyconvmode))
- {
- _WRITE(str="预处理代理实体失败");
- return FALSE;
- }
- //多行文字转换为单行文字尚不成熟
- // if(!preprocess_Convertmtext(dwghandle,m_dmtextconvmode))
- // {
- // _WRITE(str="预处理多行文字失败");
- // return FALSE;
- // }
- m_pProgress->SetProgressInfoAbsolute(0.38,"分析外部引用...");
- //外部参照暂不考虑
- if(!preprocess_Convertxref(dwghandle))
- {
- _WRITE(str="预处理外部引用失败");
- }
- m_pProgress->SetProgressInfoAbsolute(0.39,"分析线形...");
- if(!processlinetype(dwghandle))
- {
- _WRITE(str="转换线形失败");
- return FALSE;
- }
- if(!processplotstyle(dwghandle))
- {
- _WRITE(str="转换打印样式失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.40,"分析层...");
- m_iCurPlotStyleTable=m_iModelPlotStyleTable;
- if(!processlayer(dwghandle)) //层有线型属性,需要放到线型后面.
- {
- _WRITE(str="转换层失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.41,"分析线形比例...");
- if(!processlinescale(dwghandle))
- {
- _WRITE(str="转换线形比例失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.42,"分析形文件...");
- if(!processshapefile(dwghandle))
- {
- _WRITE(str="转换形文件时失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.36,"分析尺寸样式...");
- if(!processdimstyle(dwghandle))
- {
- _WRITE(str="转换尺寸样式失败");
- }
- m_pProgress->SetProgressInfoAbsolute(0.43,"分析块定义...");
- if(!processblockdefine(dwghandle)) //转换块定义.
- {
- _WRITE(str="转换块定义失败");
- return FALSE;
- }
- //块中实体的打印样式按模型空间转换
- m_iCurPlotStyleTable=m_iModelPlotStyleTable;
- if(!processblockdefineobjs(dwghandle)) //清理空的块定义,将块定义的基点坐标重算.
- {
- _WRITE(str="转换块定义中的实体失败");
- return FALSE;
- }
- if(!processnouseblock(dwghandle))
- {
- _WRITE(str="清理无效块定义失败");
- return FALSE;
- }
- m_pProgress->SetProgressInfoAbsolute(0.60,"分析模型空间...");
- //模型空间实体的打印样式按模型空间转换
- m_iCurPlotStyleTable=m_iModelPlotStyleTable;
- BOOL bSelected=FALSE;
- CStringArray strSpaceNames;
- CStringArray strSpaceFiles;
- {
- strSpaceNames.Add("模型空间");
- strSpaceFiles.Add(m_pCommand->m_strAimName);
- }
- {
- CMatch3* match;
- CFileFind filefind;
- POSITION pos=m_apaper.GetHeadPosition();
- while(pos!=NULL)
- {
- match=m_apaper.GetNext(pos);
- //short adSeekBlockheader (AD_DB_HANDLE handle, AD_OBJHANDLE thehandle, PAD_BLKH adblkh);
- sReturnValue=adSeekBlockheader(dwghandle,match->m_handle,&adtb->blkh);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- int index2=1;
- CString strfilename=m_pCommand->m_strAimName;
- CString strfileext=strfilename.Right(4);
- strfilename=strfilename.Left(strfilename.GetLength()-4);
- strfilename+="_"+match->m_layeroutname;
- CString strfilename2=strfilename+strfileext;
-
- int index=1;
- CString strTemp;
- while(filefind.FindFile((LPCTSTR)strfilename2))
- {
- strTemp.Format("#%d",index);
- strfilename2=strfilename+strTemp+strfileext;
- index++;
- }
- strSpaceNames.Add(match->m_layeroutname);
- strSpaceFiles.Add(strfilename2);
- }
- }
- extern CFileSwitchApp theApp;
- //《《《《《注册表 ――――――――――检查是否需要选择空间
- if(theApp.GetProfileInt("FileConv","SelectSpace",0))
- {
- //》》》》》注册表 ――――――――――申明不需要选择空间
- theApp.WriteProfileInt("FileConv","SelectSpace",0);
- //》》》》》注册表 ――――――――――申明选择的空间为空
- theApp.WriteProfileString("FileConv","SpaceFileName","");
- //。。。转换。。。
- {
- int iCur=-1;
- if(CallSpaceConvDlg(m_pCommand->m_hmainfrm,strSpaceNames,strSpaceFiles,iCur))
- {
- bSelected=TRUE;
- iCur--;
- if(iCur>=0&&iCur<strSpaceFiles.GetSize())
- {
- //》》》》》注册表 ――――――――――选择的空间
- theApp.WriteProfileString("FileConv","SpaceFileName",strSpaceFiles[iCur]);
- }
- }
- }
- }
- if(!bSelected)
- {
- //》》》》》注册表 ――――――――――申明选择的空间为空
- theApp.WriteProfileString("FileConv","SpaceFileName","");
- if(!processmodalentity(dwghandle,NULL,NULL))
- {
- _WRITE(str="转换模型空间的实体失败");
- return FALSE;
- }
- if(bPaper)
- {
- m_pProgress->SetProgressInfoAbsolute(0.80,"分析纸区空间...");
- if(!processpaperentity(dwghandle,NULL,NULL))
- {
- _WRITE(str="转换纸区空间的实体失败");
- return FALSE;
- }
- }
- }
- else
- {
- if(!processmodalentity(dwghandle,&strSpaceNames,&strSpaceFiles))
- {
- _WRITE(str="转换模型空间的实体失败");
- return FALSE;
- }
- if(bPaper)
- {
- m_pProgress->SetProgressInfoAbsolute(0.80,"分析纸区空间...");
- if(!processpaperentity(dwghandle,&strSpaceNames,&strSpaceFiles))
- {
- _WRITE(str="转换纸区空间的实体失败");
- return FALSE;
- }
- }
- }
- return TRUE;
- }
- BOOL CDwgReader::processheader(AD_DB_HANDLE dwghandle)
- {
- PAD_DWGHDR adhd;
- //PAD_DWGHDR adHeaderPointer(AD_DB_HANDLE handle);
- adhd=adHeaderPointer(dwghandle);
- if(adhd==NULL)
- {
- _WRITE("没有文件头.");
- return TRUE;
- }
- double dltscale = adhd->ltscale;
- if(dltscale<=PRECISION)
- {
- dltscale = 1.0 ;
- }
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
- var.vt = VT_R8;
- var.dblVal = dltscale;
- m_pConverter->ConverterDbVar(LTSCALE,var);
- //默认线宽存放于注册表中.
- return TRUE;
- }
- BOOL CDwgReader::processsysvar(AD_DB_HANDLE dwghandle)
- {
- /* _WRITE(str="tip:样条做近似处理,如需严格转换请设置转换模式为样条转换为折线以得到控制点");
- _WRITE(str="tip:平行线的两端的连接弧没有处理");
- _WRITE(str="tip:线形中嵌入的形和文字没处理");
- _WRITE(str="tip:模型空间和纸区空间的实体颜色随块处理为使用系统颜色");
- _WRITE(str="tip:打印风格没有转换");
- _WRITE(str="tip:Header节没有转换");
- _WRITE(str="tip:没有生成面域,请将AutoCAD的系统变量fillmode设置为0则显示效果相同");
- _WRITE(str="tip:部分三维对象没有处理,如三维视口,Acis实体没有处理");
- _WRITE(str="tip:视口裁减操作功能有限,不支持多边形视口");
- _WRITE(str="tip:文字的字体没有转换,颠倒反向垂直都没有处理,斜体没有处理");
- _WRITE(str="tip:文字的转义字符转换有偏差");
- _WRITE(str="tip:块定义中的属性定义Attdef将被忽略,而在块引用后紧跟的块属性实体被转换到了与块引用同级的数据容器中");
- _WRITE(str="tip:外部文字暂不予处理");
- */
- m_dlinespacemodify=0.5;//行距校正系数
- m_dtoltextwidthf=1.0;//形位公差的字宽//调整带框字符的宽度已修复宽度误差
- m_dtoltextspacef=1.0;//形位公差的字间距
- {
- PAD_DWGHDR dwghd;
- dwghd=adHeaderPointer(dwghandle);
- if(dwghd)
- {
- m_pConverter->m_dSysDimScale=dwghd->dimscale;
- }
- }
-
- CWinApp* pApp=::AfxGetApp();
- if(!pApp)
- {
- return FALSE;
- }
-
- CString strTemp;
- m_icolorbyback = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("ColorByBack"), (int)RGB(255,255,255));
- _WRITE(str.Format("tip:颜色随底色转换为R(%d)G(%d)B(%d)",GetRValue(DWORD(m_icolorbyback)),GetBValue(DWORD(m_icolorbyback)),GetGValue(DWORD(m_icolorbyback))));
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("ColorByBack"), m_icolorbyback);//用于保证保存了数据
- m_ilinewidthdefault = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("DefaultLineWidth"), 25);
- _WRITE(str.Format("tip:缺省线宽转换为%d",m_ilinewidthdefault));
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("DefaultLineWidth"), m_ilinewidthdefault);//用于保证保存了数据
-
- strTemp = pApp->GetProfileString(_T("Dwg2Kmg"), _T("PointRadius"), "0.001");
- m_dpointtocircleradius = ::atof(LPCTSTR(strTemp));
- _WRITE(str.Format("tip:点转换为圆时的半径为%f",m_dpointtocircleradius));
- if(m_dpointtocircleradius<=0)
- {
- m_dpointtocircleradius = 0.001;
- strTemp.Format("%lf",m_dpointtocircleradius);
- }
- pApp->WriteProfileString(_T("Dwg2Kmg"), _T("PointRadius"), strTemp);
- strTemp = pApp->GetProfileString(_T("Dwg2Kmg"), _T("Constructionlinelength"), "1000");
- m_dconstrulinelength = ::atof(LPCTSTR(strTemp));
- _WRITE(str.Format("tip:结构线转换为长度为%f的线段",m_dconstrulinelength));
- if(m_dconstrulinelength<1000)
- {
- m_dconstrulinelength = 1000;
- strTemp.Format("%lf",m_dconstrulinelength);
- }
- pApp->WriteProfileString(_T("Dwg2Kmg"), _T("Constructionlinelength"), strTemp);
- m_ddimconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("DimConvMode"), 2);
- switch(m_ddimconvmode)
- {
- case 1:
- _WRITE(str="tip:尺寸转换为块,不可以再进行编辑");
- break;
- case 2:
- _WRITE(str="tip:尺寸转换为无目标尺寸,可以编辑");
- break;
- default:
- m_ddimconvmode=1;
- _WRITE(str="tip:尺寸转换为块,不可以再进行编辑");
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("DimConvMode"), m_ddimconvmode);//用于保证保存了数据
- // m_dmtextconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("MtextConvMode"), 1);
- // switch(m_dmtextconvmode)
- // {
- // case 1:
- // _WRITE(str="tip:多行文字转换为KM文字");
- // break;
- // case 2:
- // _WRITE(str="tip:多行文字转换为单行文字");
- // break;
- // default:
- // _WRITE(str="tip:多行文字转换为KM文字");
- // m_dmtextconvmode=1;
- // break;
- //
- // }
- // pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("MtextConvMode"), m_dmtextconvmode);//用于保证保存了数据
- m_dproxyconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("ProxyConvMode"), 1);
- switch(m_dproxyconvmode)
- {
- case 1:
- _WRITE(str="tip:代理实体转换为块");
- break;
- case 2:
- _WRITE(str="tip:代理实体转换为实体");
- break;
- default:
- _WRITE(str="tip:代理实体转换为块");
- m_dproxyconvmode=1;
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("ProxyConvMode"), m_dproxyconvmode);//用于保证保存了数据
- m_dsplineconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("SplineConvMode"), 1);
- switch(m_dsplineconvmode)
- {
- case 1:
- _WRITE(str="tip:样条转换为样条");
- break;
- case 2:
- _WRITE(str="tip:样条转换为折线");
- break;
- default:
- _WRITE(str="tip:样条转换为样条");
- m_dsplineconvmode=1;
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("SplineConvMode"), m_dsplineconvmode);//用于保证保存了数据
- m_dviewcutconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("ViewCutConvMode"), 2);
- switch(m_dviewcutconvmode)
- {
- case 1:
- _WRITE(str="tip:视口裁减方式为与视口相交的均保留");
- break;
- case 2:
- _WRITE(str="tip:视口裁减方式为视口裁减(有些实体不支持)");
- break;
- case 3:
- _WRITE(str="tip:不裁减");
- break;
- default:
- _WRITE(str="tip:样条转换为样条");
- m_dviewcutconvmode=1;
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("ViewCutConvMode"), m_dviewcutconvmode);//用于保证保存了数据
- //默认为不转换打印样式。
- m_dplotstyleconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("PlotStyleConvMode"), 2);
- switch(m_dplotstyleconvmode)
- {
- case 1:
- _WRITE(str="tip:转换打印样式");
- break;
- case 2:
- _WRITE(str="tip:不转换打印样式");
- break;
- default:
- _WRITE(str="tip:转换打印样式");
- m_dplotstyleconvmode=2;
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("PlotStyleConvMode"), m_dplotstyleconvmode);//用于保证保存了数据
- m_ddimstyleconvmode = pApp->GetProfileInt(_T("Dwg2Kmg"), _T("DimStyleConvMode"), 1);
- switch(m_ddimstyleconvmode)
- {
- case 1:
- _WRITE(str="tip:转换打印样式");
- break;
- case 2:
- _WRITE(str="tip:不转换打印样式");
- break;
- default:
- _WRITE(str="tip:转换打印样式");
- m_ddimstyleconvmode=1;
- break;
- }
- pApp->WriteProfileInt(_T("Dwg2Kmg"), _T("DimStyleConvMode"), m_ddimstyleconvmode);//用于保证保存了数据
- strTemp = pApp->GetProfileString(_T("Dwg2Kmg"), _T("ACADpath"), "C:\Program Files\Autodesk AutoCAD\support;C:\Program Files\Autodesk AutoCAD\fonts;C:\Program Files\Autodesk AutoCAD\help;C:\Program Files\Autodesk AutoCAD\express;");
- m_strACADpath = strTemp;
- pApp->WriteProfileString(_T("Dwg2Kmg"), _T("ACADpath"), (LPCTSTR)m_strACADpath);
- strTemp = pApp->GetProfileString(_T("Dwg2Kmg"), _T("DimStyleFullName"), "");
- m_strDimStyleFullName = strTemp;
- pApp->WriteProfileString(_T("Dwg2Kmg"), _T("DimStyleFullName"), (LPCTSTR)m_strDimStyleFullName);
-
- //测试方法:
- // CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,"幼圆");
- // CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
- // CDC* pDC=pDesktop->GetDC();
- // pDC->SelectObject(&fonttext);
- // CFont* fontold=pDC->SelectObject(&fonttext);
- // OUTLINETEXTMETRIC out;
- // UINT a=pDC->GetOutlineTextMetrics(1,NULL);
- // pDC->GetOutlineTextMetrics(a,&out);
- //字体 测试字高 基线上 基线下 发音 扩展 行间距 字模正方形 ACAD发音
- // uTH=tm.tmHeight+tm.tmExternalLeading;
- // uHight=tm.tmHeight-tm.tmInternalLeading-tm.tmDescent;
- // uTop=tm.tmExternalLeading+tm.tmInternalLeading;
- // if(uTH!=uHight)
- // {
- // m_Text.m_nHeight*=TEXT_ADJUST*uTH/uHight;
- // m_Text.m_Offset.x-=m_Text.m_nHeight*uTop/uTH*sin(m_Text.m_nEscapement*PI/180);
- // m_Text.m_Offset.y+=m_Text.m_nHeight*uTop/uTH*cos(m_Text.m_nEscapement*PI/180);
- // }
- double a;
- //华文彩云 1000= 782+ 218; 35 0 139 1000 695
- {
- a= (1000.0 -35.0)* (782.0 -35.0) / ( 695.0 * TEXT_ADJUST * ( 1000.0 + 0.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文彩云"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STCaiyun"), strTemp);
- }
- //方正舒体 1000= 866+ 134; 48 4 138 256 566
- {
- a= (1000.0-48.0) * (866.0 -48.0) / ( 566.0 * TEXT_ADJUST * ( 1000.0 + 4.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("方正舒体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("FZShuTi"), strTemp);
- }
- //方正姚体 1000 876 125 114 7 131 256 665
- {
- a= (1000.0-114.0) * (876.0 -114.0) / ( 665.0 * TEXT_ADJUST * ( 1000.0 + 7.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("方正姚体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("FZYaoTi"), strTemp);
- }
- //仿宋_GB2312 1000= 859+ 141; 0 141 141 256 722
- {
- a= 1000.0 * (859.0 -0.0) / ( 722.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("仿宋_GB2312"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("FangSong_GB2312"), strTemp);
- }
- //字体 测试字高 基线上 基线下 发音 扩展 行间距 字模正方形 ACAD发音
- //黑体 1000= 859+ 141; 0 141 141 256 692
- {
- //a=(高度 -发音 )* (线上-发音) ) / (ACAD * TEXT_ADJUST * (高度+扩展))
- a= 1000.0 * (859.0 -0.0) / ( 692.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("黑体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("SimHei"), strTemp);
- }
- //华文细黑 1000= 807+ 193; 73 276 133 1000 693
- {
- a= (1000.0-73.0) * (807.0 -73.0) / ( 693.0 * TEXT_ADJUST * ( 1000.0 + 276.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文细黑"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STXihei"), strTemp);
- }
- //华文新魏 1000= 768+ 232; 17 19 142 1000 693
- {
- a= (1000.0-17.0) * (768.0 -17.0) / ( 693.0 * TEXT_ADJUST * ( 1000.0 + 19.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文新魏"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STXinwei"), strTemp);
- }
- //华文行楷 1000= 725+ 275; 48 39 137 1000 612
- {
- a= (1000.0 -48.0)* (725.0 -48.0) / ( 612.0 * TEXT_ADJUST * ( 1000.0 + 39.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文行楷"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STXingkai"), strTemp);
- }
- //华文中宋 1000= 802+ 198; 120 165 127 1000 630
- {
- a= (1000.0-120.0) * (802.0 -120.0) / ( 630.0 * TEXT_ADJUST * ( 1000.0 + 165.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文中宋"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STZhongsong"), strTemp);
- }
- //楷体_GB2312 1000= 859+ 141; 0 141 141 256 722
- {
- a= 1000.0 * (859.0 -0.0) / ( 722.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("楷体_GB2312"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("KaiTi"), strTemp);
- }
- //隶书 1000= 859+ 141; 0 141 141 256 705
- {
- a= 1000.0 * (859.0 -0.0) / ( 705.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("隶书"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("LiSu"), strTemp);
- }
- //宋体 1000= 859+ 141; 0 141 141 256 705
- {
- a= 1000.0 * (859.0 -0.0) / ( 705.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("宋体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("SimSun"), strTemp);
- }
- //新宋体 1000= 859+ 141; 0 141 141 256 700
- {
- a= 1000.0 * (859.0 -0.0) / ( 700.0 * TEXT_ADJUST * ( 1000.0 + 141.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("新宋体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("NSimSun"), strTemp);
- }
- //幼圆 1000= 859+ 141; 0 102 141 256 700
- {
- a= 1000.0 * (859.0 -0.0) / ( 700.0 * TEXT_ADJUST * ( 1000.0 + 102.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("幼圆"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("YouYuan"), strTemp);
- }
- //华文仿宋 1000= 768+ 232; 107 162 * * 822-232
- {
- //a=(高度 -发音 )* (线上-发音) ) / (ACAD * TEXT_ADJUST * (高度+扩展))
- a= (1000.0-107.0) * (768.0 -107.0) / (590.0 * TEXT_ADJUST * ( 1000.0 + 162.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文仿宋"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STFangsong"), strTemp);
- }
- //华文楷体 1000= 768+ 232; 107 162 * * 822-232
- {
- a= (1000.0-107.0) * (768.0 -107.0) / (590.0 * TEXT_ADJUST * ( 1000.0 + 162.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文楷体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STKaiti"), strTemp);
- }
- //华文琥珀 1000= 774+ 226; 30 2 * * 888-226
- {
- a= (1000.0-30.0) * (774.0 -30.0) / (662.0 * TEXT_ADJUST * ( 1000.0 + 2.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文琥珀"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STHupo"), strTemp);
- }
- //华文宋体 1000= 768+ 232; 107 162 * * 821-232
- {
- a= (1000.0-107.0) * (768.0 -107.0) / (589.0 * TEXT_ADJUST * ( 1000.0 + 162.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文宋体"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STSong"), strTemp);
- }
- //华文隶书 1000= 744+ 256; 11 47 * * 865-256
- {
- a= (1000.0-11.0) * (768.0 -11.0) / (609.0 * TEXT_ADJUST * ( 1000.0 + 47.0 ) );
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("华文隶书"), strTemp);
- strTemp.Format("%lf",a);pApp->WriteProfileString(_T("DwgFontHightRate"), _T("STLiti"), strTemp);
- }
- return TRUE;
- }
- BOOL CDwgReader::processcolor(AD_DB_HANDLE dwghandle)
- {
- short ACI[240]=
- { 255,255,206,206,156,156,123,123,74 ,74 , //顶峰
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 189,255,156,206,115,156,90 ,123,57 ,74 ,
- 123,222,99 ,181,74 ,132,57 ,107,33 ,66 ,
- 57 ,189,49 ,156,33 ,115,24 ,90 ,16 ,57 ,
- 0 ,156,0 ,123,0 ,90 ,0 ,74 ,0 ,41 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,//低谷
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,123,0 ,99 ,0 ,74 ,0 ,57 ,0 ,33 ,
- 0 ,156,0 ,123,0 ,90 ,0 ,74 ,0 ,41 ,
- 57 ,189,49 ,156,33 ,115,24 ,90 ,16 ,57 ,
- 123,222,99 ,181,74 ,132,57 ,107,33 ,66 ,
- 189,255,156,206,115,156,90 ,123,57 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74 ,
- 255,255,206,206,156,156,123,123,74 ,74
- };
- try
- {
- m_aColor.SetSize(256);
- }
- catch(CMemoryException* e)
- {
- TCHAR szCause[255];
- e->GetErrorMessage(szCause, 255);
- _WRITE(str=szCause);
- return FALSE;
- }
- catch(...)
- {
- _WRITE(str="颜色转换时发生未知错误");
- return FALSE;
- }
- m_aColor[1]=(int)RGB(255,0,0);
- m_aColor[2]=(int)RGB(255,255,0);
- m_aColor[3]=(int)RGB(0,255,0);
- m_aColor[4]=(int)RGB(0,255,255);
- m_aColor[5]=(int)RGB(0,0,255);
- m_aColor[6]=(int)RGB(255,0,255);
- m_aColor[7]=m_icolorbyback;//黑/白缺省颜色是 7,白色或黑色(由背景色决定)。所有其他颜色必须由 ACI 编号指定(8 到 255)。
- m_aColor[8]=(int)RGB(132,130,132);
- m_aColor[9]=(int)RGB(198,195,198);
- int i;
- for(i=10;i<90;i++)
- {
- m_aColor[i]=(int)RGB(ACI[i-10],ACI[/*i-10+160*/i+150],ACI[/*i-10+320-240*/i+70]);
- }
- for(i=90;i<170;i++)
- {
- m_aColor[i]=(int)RGB(ACI[i-10],ACI[/*i-10+160-240*/i-90],ACI[/*i-10+320-240*/i+70]);
- }
- for(i=170;i<250;i++)
- {
- m_aColor[i]=(int)RGB(ACI[i-10],ACI[/*i-10+160-240*/i-90],ACI[/*i-10+320-240-240*/i-170]);
- }
- m_aColor[250]=(int)RGB(49,48,49);
- m_aColor[251]=(int)RGB(90,89,90);
- m_aColor[252]=(int)RGB(132,134,132);
- m_aColor[253]=(int)RGB(173,174,173);
- m_aColor[254]=(int)RGB(214,215,214);
- m_aColor[255]=(int)RGB(255,255,255);
- return TRUE;
- }
- BOOL CDwgReader::processlinewidth(AD_DB_HANDLE dwghandle)
- {
- //_WRITE(str="tip:线宽为0转换为绝对细实线");
- // m_alwidth.SetSize(4);
- // m_alwidth[0]=ABS_THIN_WIDTH;
- // m_alwidth[1]=LWIDTH_BYLAYER;
- // m_alwidth[2]=LWIDTH_BYBLOCK;//?
- // m_alwidth[3]=m_ilinewidthdefault;
- return TRUE;
- }
- //函数功能:
- // 分析AutoCAD的线型数据,转换为KmCAD的线型数据,并记录到线型匹配链表中.
- //函数说明:
- // 使用以下函数遍历AutoCAD线型数据:
- // adStartLinetypeGet:开始获得AutoCAD线型数据.
- // adNumLinetypes:获得AutoCAD线型类型总数.
- // adGetLinetype:获得指定AutoCAD线型的线型数据.
- //输入参数:
- // AD_DB_HANDLE dwghandle:AutoCAD文件句柄.
- BOOL CDwgReader::processlinetype(AD_DB_HANDLE dwghandle)
- {
- _WRITE(str="_________开始转换线形");
- //short adStartLinetypeGet (AD_DB_HANDLE handle);
- sReturnValue=adStartLinetypeGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //long adNumLinetypes (AD_DB_HANDLE handle);
- for(long i=0;i<adNumLinetypes(dwghandle);i++)
- {
- //short adGetLinetype (AD_DB_HANDLE handle, PAD_LTYPE adltype);
- sReturnValue=adGetLinetype(dwghandle,&adtb->ltype);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adtb->ltype.purgedflag==1)
- {
- continue;
- }
- int ikmhandle;
- double dkmlinescale;
-
- CString strName;
- strName=adtb->ltype.name;
- if(strName=="Continuous")
- {
- ikmhandle=SOLID_LINE;
- dkmlinescale=1.0;
- }
- else if(strName=="ByLayer")
- {
- ikmhandle=LTYPE_BYLAYER;
- dkmlinescale=-1.0;//函数processentity_enthead中会修正
- }
- else if(strName=="ByBlock")
- {
- ikmhandle=LTYPE_BYBLOCK;
- dkmlinescale=1.0;
- }
- else if(strName=="BORDER")
- {//{11,6, {5,2,5,2,1,2}},//DDASH_DOT_LINE,11//双画单点线
- ikmhandle=DDASH_DOT_LINE;
- dkmlinescale=2.8;
- dkmlinescale=((double)5)/((double)12.7);
- }
- else if(strName=="BORDER2")
- {//{11,6, {5,2,5,2,1,2}},//DDASH_DOT_LINE,11//双画单点线
- ikmhandle=DDASH_DOT_LINE;
- dkmlinescale=1.4;
- dkmlinescale=((double)5)/((double)6.35);
- }
- else if(strName=="BORDERX2")
- {//{11,6, {5,2,5,2,1,2}},//DDASH_DOT_LINE,11//双画单点线
- ikmhandle=DDASH_DOT_LINE;
- dkmlinescale=5.6;
- dkmlinescale=((double)5)/((double)25.4);
- }
- else if(strName=="CENTER")
- {//{8, 4, {10,2,3,2}},//LONGDASH_SHORTDASH_LINE,8//长画短画线
- ikmhandle=LONGDASH_SHORTDASH_LINE;
- dkmlinescale=3.2;
- dkmlinescale=((double)10)/((double)31.75);
- }
- else if(strName=="CENTER2")
- {//{8, 4, {10,2,3,2}},//LONGDASH_SHORTDASH_LINE,8//长画短画线
- ikmhandle=LONGDASH_SHORTDASH_LINE;
- dkmlinescale=1.6;
- dkmlinescale=((double)10)/((double)19.05);
- }
- else if(strName=="CENTERX2")
- {//{8, 4, {10,2,3,2}},//LONGDASH_SHORTDASH_LINE,8//长画短画线
- ikmhandle=LONGDASH_SHORTDASH_LINE;
- dkmlinescale=6.4;
- dkmlinescale=((double)10)/((double)63.5);
- }
- else if(strName=="DASHDOT")
- {//{10, 4, {5,2,1,2}},//SHORTDASH_DOT_LINE,10//画点线
- ikmhandle=SHORTDASH_DOT_LINE;
- dkmlinescale=2.8;
- dkmlinescale=((double)5)/((double)12.7);
- }
- else if(strName=="DASHDOT2")
- {//{10, 4, {5,2,1,2}},//SHORTDASH_DOT_LINE,10//画点线
- ikmhandle=SHORTDASH_DOT_LINE;
- dkmlinescale=1.4;
- dkmlinescale=((double)5)/((double)6.35);
- }
- else if(strName=="DASHDOTX2")
- {//{10, 4, {5,2,1,2}},//SHORTDASH_DOT_LINE,10//画点线
- ikmhandle=SHORTDASH_DOT_LINE;
- dkmlinescale=5.6;
- dkmlinescale=((double)5)/((double)25.4);
- }
- else if(strName=="DASHED")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=2.8;
- dkmlinescale=((double)5)/((double)12.7);
- }
- else if(strName=="DASHED2")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=1.4;
- dkmlinescale=((double)5)/((double)6.35);
- }
- else if(strName=="DASHEDX2")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=5.6;
- dkmlinescale=((double)5)/((double)25.4);
- }
- else if(strName=="HIDDEN")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=2.8;
- dkmlinescale=((double)5)/((double)6.35);
- }
- else if(strName=="HIDDEN2")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=1.4;
- dkmlinescale=((double)5)/((double)3.175);
- }
- else if(strName=="HIDDENX2")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=5.6;
- dkmlinescale=((double)5)/((double)12.7);
- }
- else if(strName=="DIVIDE")
- {//{12,6, {5,2,1,2,1,2}},//SDASH_DDOT_LINE,12//画双点划线
- ikmhandle=SDASH_DDOT_LINE;
- dkmlinescale=2.8;
- dkmlinescale=((double)5)/((double)12.7);
- }
- else if(strName=="DIVIDE2")
- {//{12,6, {5,2,1,2,1,2}},//SDASH_DDOT_LINE,12//画双点划线
- ikmhandle=SDASH_DDOT_LINE;
- dkmlinescale=1.4;
- dkmlinescale=((double)5)/((double)6.35);
- }
- else if(strName=="DIVIDEX2")
- {//{12,6, {5,2,1,2,1,2}},//SDASH_DDOT_LINE,12//画双点划线
- ikmhandle=SDASH_DDOT_LINE;
- dkmlinescale=5.6;
- dkmlinescale=((double)5)/((double)25.4);
- }
- else if(strName=="PHANTOM")
- {//{9, 6, {10,2,3,2,3,2}},//LONGDASH_DSHORTDASH_LINE,9//长画双短画线
- ikmhandle=LONGDASH_DSHORTDASH_LINE;
- dkmlinescale=((double)10)/((double)31.75);
- }
- else if(strName=="PHANTOM2")
- {//{9, 6, {10,2,3,2,3,2}},//LONGDASH_DSHORTDASH_LINE,9//长画双短画线
- ikmhandle=LONGDASH_DSHORTDASH_LINE;
- dkmlinescale=((double)10)/((double)15.875);
- }
- else if(strName=="PHANTOMX2")
- {//{9, 6, {10,2,3,2,3,2}},//LONGDASH_DSHORTDASH_LINE,9//长画双短画线
- ikmhandle=LONGDASH_DSHORTDASH_LINE;
- dkmlinescale=((double)10)/((double)63.5);
- }
- else if(strName=="DOT")
- {
- ikmhandle=DOT_LINE;
- dkmlinescale=2.8;
- }
- else if(strName=="DOT2")
- {
- ikmhandle=DOT_LINE;
- //dkmlinescale=1.4;
- dkmlinescale=5.6;
- }
- else if(strName=="DOTX2")
- {
- ikmhandle=DOT_LINE;
- //dkmlinescale=5.6;
- dkmlinescale=1.4;
- }
- else if(strName=="ACAD_ISO02W100")
- {//{2, 2, {5,2}},//DASHED_LINE,2//虚线
- ikmhandle=DASHED_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO03W100")
- {//{6, 2, {5,7}},//DASH_SPACE_LINE,6//间隔画线
- ikmhandle=DASH_SPACE_LINE;
- dkmlinescale=2.5;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO04W100")
- {//{3, 4, {10, 2, 1, 2}},//POINT_LINE,3//点划线
- ikmhandle=POINT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)10)/((double)24);
- }
- else if(strName=="ACAD_ISO05W100")
- {//{12,6, {5,2,1,2,1,2}},//SDASH_DDOT_LINE,12//画双点划线
- ikmhandle=SDASH_DDOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)24);
- }
- else if(strName=="ACAD_ISO06W100")
- {//{14,8, {5,2,1,2,1,2,1,2}}, //SDASH_TRIDOT_LINE,14//画三点线
- ikmhandle=SDASH_TRIDOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)24);
- }
- else if(strName=="ACAD_ISO07W100")
- {//{7, 2, {2,2}},//DOT_LINE,7//点线
- ikmhandle=DOT_LINE;
- dkmlinescale=1.5;
- }
- else if(strName=="ACAD_ISO08W100")
- {//{10, 4, {5,2,1,2}},//SHORTDASH_DOT_LINE,10//画点线
- ikmhandle=SHORTDASH_DOT_LINE;
- dkmlinescale=4;
- dkmlinescale=((double)5)/((double)24);
- }
- else if(strName=="ACAD_ISO09W100")
- {//{9, 6, {10,2,3,2,3,2}},//LONGDASH_DSHORTDASH_LINE,9//长画双短画线
- ikmhandle=LONGDASH_DSHORTDASH_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)10)/((double)24);
- }
- else if(strName=="ACAD_ISO10W100")
- {//{10, 4, {5,2,1,2}},//SHORTDASH_DOT_LINE,10//画点线
- ikmhandle=SHORTDASH_DOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO11W100")
- {//{11,6, {5,2,5,2,1,2}},//DDASH_DOT_LINE,11//双画单点线
- ikmhandle=DDASH_DOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO12W100")
- {//{12,6, {5,2,1,2,1,2}},//SDASH_DDOT_LINE,12//画双点划线
- ikmhandle=SDASH_DDOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO13W100")
- {//{13,8, {5,2,5,2,1,2,1,2}},//DDASH_DDOT_LINE,13//双画双点线
- ikmhandle=DDASH_DDOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(strName=="ACAD_ISO14W100")
- {//{5, 8, {10,2,1,2,1,2,1,2}},//DASH_TRIDOT_LINE,5//三点画线
- ikmhandle=DASH_TRIDOT_LINE;
- dkmlinescale=1.2;
- dkmlinescale=((double)10)/((double)12);
- }
- else if(strName=="ACAD_ISO15W100")
- {//{15,10,{5,2,5,2,1,2,1,2,1,2}},//DDASH_TRIDOT_LINE
- ikmhandle=DDASH_TRIDOT_LINE;
- dkmlinescale=2;
- dkmlinescale=((double)5)/((double)12);
- }
- else if(adtb->ltype.numlinetypesegs==0)
- {
- ikmhandle=SOLID_LINE;
- dkmlinescale=1.0;
- }
- else
- {
- int iBlankNum=0;
- int iDotNum=0;
- for(short i=0;i<adtb->ltype.numlinetypesegs;i++)
- {
- if(adtb->ltype.segdata[i].val<0)
- {
- iBlankNum++;
- continue;
- }
- if(adtb->ltype.segdata[i].val<1)
- {
- iDotNum++;
- continue;
- }
- }
- if(iBlankNum==0)
- {
- ikmhandle=SOLID_LINE;
- dkmlinescale=1.0;
- }
- else
- {
- //adtb->ltype.numlinetypesegs!=0
- dkmlinescale=(adtb->ltype.numlinetypesegs/adtb->ltype.patternlength);
- switch(iDotNum)
- {
- case 0:
- ikmhandle=DASHED_LINE;
- break;
- case 1:
- if(iBlankNum<3)
- {
- ikmhandle=SHORTDASH_DOT_LINE;
- }
- else
- {
- ikmhandle=DDASH_DOT_LINE;
- }
- break;
- case 2:
- if(iBlankNum<5)
- {
- ikmhandle=SDASH_DDOT_LINE;
- }
- else
- {
- ikmhandle=DDASH_DDOT_LINE;
- }
- break;
- default:
- if(iBlankNum<7)
- {
- ikmhandle=SDASH_TRIDOT_LINE;
- }
- else
- {
- ikmhandle=DDASH_TRIDOT_LINE;
- }
- break;
- }
- }
- }
- m_altype.Add(adtb->ltype.objhandle,ikmhandle,dkmlinescale,(short)i);
- _WRITE(str.Format("线形:%s描述:%s转换为%d线形比例:%f",adtb->ltype.name,adtb->ltype.text,ikmhandle,dkmlinescale));
- }
- _WRITE(str="_________结束转换线形");
- return TRUE;
- }
- BOOL CDwgReader::processplotstyle(AD_DB_HANDLE dwghandle)
- {
-
- return TRUE;
- }
- //函数功能:
- // 分析AutoCAD的层数据,转换为KmCAD的层数据,并记录到层匹配链表中.
- //函数说明:
- // 使用以下函数遍历AutoCAD线型数据:
- // adStartLayerGet:开始获得AutoCAD层的数据.
- // adNumLayers:获得AutoCAD层的数目.
- // GetLayer:获得AutoCAD的指定层的数据.
- // 使用以下辅助函数分析AutoCAD的层的数据.
- // adGetLayerState:分析AutoCAD层的状态.
- //输入参数:
- // AD_DB_HANDLE dwghandle:AutoCAD文件句柄.
- BOOL CDwgReader::processlayer(AD_DB_HANDLE dwghandle)
- {
- _WRITE(str="_________开始转换层");
- //short adStartLayerGet (AD_DB_HANDLE handle);
- sReturnValue=adStartLayerGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //long adNumLayers (AD_DB_HANDLE handle);
- for(long i=0;i<adNumLayers(dwghandle);i++)
- {
- //short adGetLayer (AD_DB_HANDLE handle, PAD_LAY adlay);
- sReturnValue=adGetLayer(dwghandle,&adtb->lay);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adtb->lay.purgedflag==1)
- {
- continue;
- }
- char on,frozen,vpfrozen,locked;
- //short adGetLayerState (AD_DB_HANDLE handle, AD_OBJHANDLE layhandle, char *on, char *frozen, char *vpfrozen, char *locked);
- sReturnValue=adGetLayerState(dwghandle,adtb->lay.objhandle,&on,&frozen,&vpfrozen,&locked);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- BOOL bon,bfrozen;
- if(on==1)
- {
- bon=TRUE;
- }
- else
- {
- bon=FALSE;
- }
- if(frozen==1)
- {
- bfrozen=TRUE;
- }
- else
- {
- bfrozen=FALSE;
- }
- short color=adtb->lay.color;
- if(!bon)
- {
- color=~color+1;
- }
- short width=adtb->lay.lineweight;
- {
- if((unsigned short)width==AD_WEIGHT_DEFAULT)
- {
- width=m_ilinewidthdefault;
- }
- else if((unsigned short)width==AD_WEIGHT_BYBLOCK)
- {
- width=LWIDTH_BYBLOCK;
- }
- else if((unsigned short)width==AD_WEIGHT_BYLAYER)
- {
- width=LWIDTH_BYLAYER;
- }
- else
- {
- width=::GetLineWidthAsInt(double(abs(width))/100.0);
- }
- }
- int itype;double lscale;
- m_altype.Get(adtb->lay.linetypeobjhandle,itype,lscale);
- int icolor=0;
- if(color>=0&&color<m_aColor.GetSize())
- {
- icolor=m_aColor[color];
- }
- int iwidth=(int)width;
- if(m_dplotstyleconvmode==1)
- {
- UsePlotStyle(adtb->lay.color,iwidth,icolor,itype,lscale,adtb->lay.plotstyleobjhandle,0);
- }
- UINT dwKmID=m_pConverter->ConverterEnthead_Layer(bon,bfrozen,adtb->lay.name,icolor,iwidth,itype);
- m_alayer.Add(adtb->lay.objhandle,dwKmID,lscale,FALSE);
- _WRITE(str.Format("层:%s转换为%u",adtb->lay.name,dwKmID));
- }
- m_pConverter->SaveLayerStatus();
- _WRITE(str="_________结束转换层");
- return TRUE;
- }
- //函数功能:
- // 分析AutoCAD的块数据,转换为KmCAD的块数据,并记录到块匹配链表中.
- //函数说明:
- // 块实体中的第一个实体是AD_ENT_BLOCK,记录了块定义的信息,最后一个实体是AD_ENT_ENDBLK标志块的结束.
- // 使用以下函数遍历AutoCAD块定义:
- // adStartBlockheaderGet:开始获得AutoCAD中的块的数据.
- // adGetBlockheader:获得AutoCAD块的数据头.
- // 使用以下函数遍历AutoCAD块中的实体的定义:
- // adStartEntityGet:开始获得AutoCAD块中的实体的数据.
- // adGetEntity:获得AutoCAD块中指定实体的数据.
- //输入参数:
- // AD_DB_HANDLE dwghandle:AutoCAD文件句柄.
- BOOL CDwgReader::processblockdefine(AD_DB_HANDLE dwghandle)
- {
- _WRITE(str="_________开始转换块定义");
- //short adStartBlockheaderGet (AD_DB_HANDLE handle);
- sReturnValue=adStartBlockheaderGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- BOOL bRef;
- //long adNumBlockheaders (AD_DB_HANDLE handle);
- for(long i=0; i<adNumBlockheaders(dwghandle);i++) // note --无0 -2 so we don't get the model and paperspace blocks
- {
- bRef=FALSE;
- //short adGetBlockheader (AD_DB_HANDLE handle, PAD_BLKH adblkh);
- sReturnValue=adGetBlockheader(dwghandle,&adtb->blkh);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adtb->blkh.purgedflag==1)
- {
- continue;
- }
- CString strName(adtb->blkh.name);
- strName.MakeLower();
- if(strName=="*model_space")
- {
- continue;
- }
- if(strName=="*paper_space")
- {
- continue;
- }
- if(m_apaper.IsInList(adtb->blkh.objhandle))
- {
- continue;
- }
- if(adtb->blkh.flag&AD_BLOCK_XREF)
- {
- continue;
- }
- UINT dwKmID=m_pConverter->ConverterEnthead_Blockdefine(adtb->blkh.name,adtb->blkh.description);
- _WRITE(str.Format("块:%s描述:%s转换为块%u",adtb->blkh.name,adtb->blkh.description,dwKmID));
- m_ablock.Add(adtb->blkh.objhandle,dwKmID,1.0,bRef);
- }
- _WRITE(str="_________结束转换块定义");
- return TRUE;
- }
- BOOL CDwgReader::processlinescale(AD_DB_HANDLE dwghandle)
- {
- return TRUE;
- }
- BOOL CDwgReader::processobject(AD_DB_HANDLE dwghandle)
- {
- _WRITE(str="_________开始转换物体");
- //short adStartObjectGet (AD_DB_HANDLE handle);
- sReturnValue=adStartObjectGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //short adGetObject(AD_DB_HANDLE handle, PAD_OBJ_HDR adobhd, PAD_OBJ adob);
- while(adGetObject(dwghandle,adobhd,adob))
- {
- //#define AD_OBJ_CLASS 34
- //#define AD_OBJ_PROXY 100
- //#define AD_OBJ_XRECORD 101
- switch(adobhd->objtype)
- {
- case AD_OBJ_DICTIONARY:
- {
- PAD_BLOB_CTRL bcptr;
- AD_DICITEM dicitem;
- if(adob->dic.numdicitems>0L)
- {
- bcptr=adStartBlobRead(adob->dic.itemblob);
- for(int i=0; i<adob->dic.numdicitems; i++)
- {
- adReadDicItem(bcptr,&dicitem);
- }
- adEndBlobRead(bcptr);
- }
- }
- break;
- case AD_OBJ_MLINESTYLE:
- processobject_mlinestyle(dwghandle);
- break;
- case AD_OBJ_GROUP:
- break;
- default:// others are proxys
- if(adobhd->objtype==adObjectptrObjtype(dwghandle))
- {
- _WRITE(str="Objptr没有处理");
- }
- else if(adobhd->objtype==adPlaceholderObjtype(dwghandle))
- {
- _WRITE(str="Placehold没有处理");
- }
- else if(adobhd->objtype==adSortentstableObjtype(dwghandle))
- {
- _WRITE(str="Sortents没有处理");
- }
- else if(adobhd->objtype==adSpatialindexObjtype(dwghandle))
- {
- _WRITE(str="Spaindex没有处理");
- }
- else if(adobhd->objtype==adVbaProjectObjtype(dwghandle))
- {
- _WRITE(str="VbaProj没有处理");
- }
- else if(adobhd->objtype==adWipeoutVariablesObjtype(dwghandle))
- {
- _WRITE(str="WipeoutVar没有处理");
- }
- else if(adobhd->objtype==adLayoutObjtype(dwghandle))
- {
- processobject_layout(dwghandle);
- }
- else if(adobhd->objtype==adLayerindexObjtype(dwghandle))
- {
- _WRITE(str="LayerIndex没有处理");
- }
- else if(adobhd->objtype==adDictionarywdfltObjtype(dwghandle))
- {
- _WRITE(str="Dicwdflt没有处理");
- {
- PAD_BLOB_CTRL bcptr;
- AD_DICITEM dicitem;
- if(adob->dictionarywdflt.numitems>0L)
- {
- bcptr=adStartBlobRead(adob->dictionarywdflt.itemblob);
- for(int i=0; i<adob->dictionarywdflt.numitems; i++)
- {
- adReadDicItem(bcptr,&dicitem);
- m_aplot.Add(dicitem.itemhandle,dicitem.str);
- }
- adEndBlobRead(bcptr);
- }
- }
- }
- //short adXrecordObjtype(AD_DB_HANDLE handle);
- else if(adobhd->objtype==adXrecordObjtype(dwghandle))
- {
- _WRITE(str="Xrecord没有处理");
- }
- //short adIdbufferObjtype(AD_DB_HANDLE handle);
- else if(adobhd->objtype==adIdbufferObjtype(dwghandle))
- {
- _WRITE(str="Idbuffer没有处理");
- }
- else if (adobhd->objtype==adDictionaryvarObjtype(dwghandle))
- {
- _WRITE(str="DictionaryvarObjtype没有处理");
- }
- else if (adobhd->objtype==adImagedefreactorObjtype(dwghandle))
- {
- _WRITE(str="IMAGEDEFReactor没有处理");
- }
- else if (adobhd->objtype==adImagedefObjtype(dwghandle))
- {
- _WRITE(str="IMAGEDEFObjtype没有处理");
- }
- else if (adobhd->objtype==adRastervariablesObjtype(dwghandle))
- {
- _WRITE(str="RASTERVARIABLES没有处理");
- }
- else if (adobhd->objtype==adSpatialfilterObjtype(dwghandle))
- {
- _WRITE(str="SPATIAL_FILTER OBJECT没有处理");
- }
- else if (AD_IS_A_GENERIC_PROXYOBJ(adobhd->objtype))
- {
- _WRITE(str="GENERIC PROXY OBJECT没有处理");
- }
- else
- {
- _WRITE(str="未知类型的OBJECT没有处理");
- }
- /* AD_DIC dic;
- AD_DICTIONARYVAR dictionaryvar;
- AD_GRP grp;
- AD_IDBUFFER idbuffer;
- AD_IMAGEDEF imagedef;
- AD_IMAGEDEFREACTOR imagedefreactor;
- AD_MLSTYLE mlstyle;
- AD_PROXYOBJ proxyobj;
- AD_RASTERVARIABLES rastervariables;
- AD_SORTENTSTABLE sortentstable;
- AD_SPATIALFILTER spatialfilter;
- AD_XRECORD xrecord;
- AD_OBJECTPTR objectptr;
- AD_LAYERINDEX layerindex;
- AD_SPATIALINDEX spatialindex;
- AD_PLOTSETTINGS plotsettings;
- AD_DICTIONARYWDFLT dictionarywdflt;
- AD_PLACEHOLDER placeholder;
- AD_LAYOUT layout;
- AD_VBAPROJECT vbaproject;
- AD_WIPEOUTVARIABLES wipeoutvariables;
- AD_DIMASSOC dimassoc;
- */
- break;
- }
- }
- _WRITE(str="_________结束转换物体");
- return TRUE;
- }
- BOOL CDwgReader::processblockdefineobjs(AD_DB_HANDLE dwghandle,BOOL bref)
- {
- _WRITE(str="_________开始转换块定义中的实体");
- sReturnValue=adStartBlockheaderGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //long adNumBlockheaders (AD_DB_HANDLE handle);
- for(long i=0; i<adNumBlockheaders(dwghandle);i++) // note --无0 -2 so we don't get the model and paperspace blocks
- {
- //short adGetBlockheader (AD_DB_HANDLE handle, PAD_BLKH adblkh);
- sReturnValue=adGetBlockheader(dwghandle,&adtb->blkh);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adtb->blkh.purgedflag==1)
- {
- continue;
- }
- CString strName(adtb->blkh.name);
- strName.MakeLower();
- if(strName=="*model_space")
- {
- continue;
- }
- //if(strName=="*paper_space")
- //{
- // continue;
- //}
- if(m_apaper.IsInList(adtb->blkh.objhandle))
- {
- continue;
- }
- UINT id;
- if(!m_ablock.Get(id,adtb->blkh.objhandle))
- {
- continue;
- }
- if(!m_pConverter->SetDataVessel(DATAVESSEL_BLOCKDEF,id))
- {
- _WRITE(str.Format("无法找到第%d号块定义",id));
- return FALSE;
- }
- if((!(adtb->blkh.xrefindex==-1||adtb->blkh.xrefindex==0))
- &&(!adtb->blkh.unloaded))
- {
- continue;
- /*if(bref)
- {
- continue;
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adtb->blkh.entitylist);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adGetEntity(adtb->blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_BLOCK)
- {
- AD_DB_HANDLE refhandle;
- AD_OBJHANDLE handle;
- AD_BLKH blkh;
- //AD_DB_HANDLE adGetXrefDbHandle(AD_DB_HANDLE main, void *filename);
- //refhandle=adGetXrefDbHandle(dwghandle,aden->block.xrefpath);
- //if(refhandle[0]==0&&refhandle[1]==0&&refhandle[2]==0&&refhandle[3]==0&&refhandle[4]==0&&refhandle[5]==0&&refhandle[6]==0&&refhandle[7]==0)
- //{
- // continue;
- //}
-
- //short adGetBlockHandle (AD_DB_HANDLE handle, AD_OBJHANDLE handle, short type);
- sReturnValue=adGetBlockHandle(refhandle,handle,AD_MODELSPACE_HANDLE);
- if(sReturnValue!=1)
- {
- _ERROR;
- continue;
- }
- //short adSeekBlockheader (AD_DB_HANDLE handle, AD_OBJHANDLE thehandle, PAD_BLKH adblkh);
- sReturnValue=adSeekBlockheader(refhandle,handle,&blkh);
- if(sReturnValue!=1)
- {
- _ERROR;
- continue;
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(blkh.entitylist);
- if(sReturnValue!=1)
- {
- _ERROR;
- continue;
- }
- //short adGetEntity (AD_VMADDR list,PAD_ENT_HDR adenhd,PAD_ENT aden);
- while(adGetEntity(blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- if(adenhd->enttype==AD_ENT_POLYLINE)
- {
- if(!processentity_polyline(dwghandle,adtb->blkh.entitylist))
- {
- _WRITE("转换多段线时发生错误");
- }
- }
- if(!processentity(refhandle))
- {
- _WRITE(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]));
- continue;
- }
- }
- }
- }
- continue;*/
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adtb->blkh.entitylist);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //short adGetEntity (AD_VMADDR list,PAD_ENT_HDR adenhd,PAD_ENT aden);
- while(adGetEntity(adtb->blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- if(adenhd->enttype==AD_ENT_POLYLINE)
- {
- if(!processentity_polyline(dwghandle,adtb->blkh.entitylist))
- {
- _WRITE("转换多段线时发生错误");
- }
- }
- if(!processentity(dwghandle))
- {
- _WRITE(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]));
- continue;
- }
- }
- }
-
- _WRITE(str="_________结束转换块定义中的实体");
- return TRUE;
- }
- BOOL CDwgReader::processmodalentity(AD_DB_HANDLE dwghandle,CStringArray *pstrSpaceNames,CStringArray *pstrSpaceFiles)
- {
- _WRITE(str="_________开始转换模型空间的实体");
- AD_OBJHANDLE handle;
- //short adGetBlockHandle (AD_DB_HANDLE handle, AD_OBJHANDLE handle, short type);
- sReturnValue=adGetBlockHandle(dwghandle,handle,AD_MODELSPACE_HANDLE);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(!m_pConverter->SetDataVessel(DATAVESSEL_MODELSPACE,0))
- {
- return FALSE;
- }
- //AD_VMADDR adEntityList (AD_DB_HANDLE handle, AD_OBJHANDLE whichblk);
- adtb->blkh.entitylist=adEntityList(dwghandle,handle);
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adtb->blkh.entitylist);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //short adGetEntity (AD_VMADDR list,PAD_ENT_HDR adenhd,PAD_ENT aden);
- while(adGetEntity(adtb->blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- if(adenhd->enttype==AD_ENT_POLYLINE)
- {
- if(!processentity_polyline(dwghandle,adtb->blkh.entitylist))
- {
- _WRITE("转换多段线时发生错误");
- }
- }
- if(!processentity(dwghandle))
- {
- _WRITE(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]));
- continue;
- }
- }
- CString strFileNameT=m_pCommand->m_strAimName;
- //CStringArray *pstrSpaceNames,CStringArray *pstrSpaceFiles
- if(pstrSpaceNames&&pstrSpaceFiles)
- {
- for(int i=0;i<pstrSpaceNames->GetSize();i++)
- {
- if(pstrSpaceNames->GetAt(i)=="模型空间")
- {
- if(i<pstrSpaceFiles->GetSize())
- {
- strFileNameT=pstrSpaceFiles->GetAt(i);
- }
- }
- }
- }
- UINT utDimStyleReplace=(UINT)(-1);
- if(!m_strDimStyleFullName.IsEmpty())
- {
- UINT utID=0;
- if(m_adimstyle.Get(utID,m_hFirstDimStyle))
- {
- utDimStyleReplace=utID;
- }
- }
- if(!m_pConverter->SaveAndReinitDataBase(utDimStyleReplace,strFileNameT))
- {
- _WRITE(str="保存模型空间文件时失败");
- return FALSE;
- }
- _WRITE(str="_________结束转换模型空间中的实体");
- return TRUE;
- }
- BOOL CDwgReader::processpaperentity(AD_DB_HANDLE dwghandle,CStringArray *pstrSpaceNames,CStringArray *pstrSpaceFiles)
- {
- _WRITE(str="_________开始转换纸区空间中的实体");
- CMatch3* match;
- CFileFind filefind;
- POSITION pos=m_apaper.GetHeadPosition();
- while(pos!=NULL)
- {
- match=m_apaper.GetNext(pos);
- m_iCurPlotStyleTable=match->m_iplotsheet;
- //short adSeekBlockheader (AD_DB_HANDLE handle, AD_OBJHANDLE thehandle, PAD_BLKH adblkh);
- sReturnValue=adSeekBlockheader(dwghandle,match->m_handle,&adtb->blkh);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
-
- if(!m_pConverter->SetDataVessel(DATAVESSEL_DATABASE,0))
- {
- return FALSE;
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adtb->blkh.entitylist);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- BOOL bhaveviewportorentity=FALSE;
- //short adGetEntity (AD_VMADDR list,PAD_ENT_HDR adenhd,PAD_ENT aden);
- BOOL bFirst=TRUE;
- while(adGetEntity(adtb->blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- if(adenhd->enttype==AD_ENT_VIEWPORT)
- {
- if(bFirst)
- {
- bFirst=FALSE;
- continue;
- }
- if(!processentity_viewport(dwghandle))
- {
- _WRITE(str="转换一个视口失败");
- }
- else
- {
- bhaveviewportorentity=TRUE;
- }
- }
- if(adenhd->enttype!=AD_ENT_BLOCK)
- {
- if(adenhd->enttype!=AD_ENT_VIEWPORT)
- {
- bhaveviewportorentity=TRUE;
- }
- }
- if(adenhd->enttype==AD_ENT_POLYLINE)
- {
- if(!processentity_polyline(dwghandle,adtb->blkh.entitylist))
- {
- _WRITE("转换多段线时发生错误");
- }
- }
- if(!processentity(dwghandle))
- {
- _WRITE(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]));
- continue;
- }
- }
- if(!bhaveviewportorentity)
- {
- continue;
- }
- int index2=1;
- CString strfilename=m_pCommand->m_strAimName;
- CString strfileext=strfilename.Right(4);
- strfilename=strfilename.Left(strfilename.GetLength()-4);
- strfilename+="_"+match->m_layeroutname;
- CString strfilename2=strfilename+strfileext;
-
- int index=1;
- CString strTemp;
- while(filefind.FindFile((LPCTSTR)strfilename2))
- {
- strTemp.Format("#%d",index);
- strfilename2=strfilename+strTemp+strfileext;
- index++;
- }
- CString strFileNameT=strfilename2;
- //CStringArray *pstrSpaceNames,CStringArray *pstrSpaceFiles
- if(pstrSpaceNames&&pstrSpaceFiles)
- {
- for(int i=0;i<pstrSpaceNames->GetSize();i++)
- {
- if(pstrSpaceNames->GetAt(i)==match->m_layeroutname)
- {
- if(i<pstrSpaceFiles->GetSize())
- {
- strFileNameT=pstrSpaceFiles->GetAt(i);
- }
- }
- }
- }
- UINT utDimStyleReplace=(UINT)(-1);
- if(!m_strDimStyleFullName.IsEmpty())
- {
- UINT utID=0;
- if(m_adimstyle.Get(utID,m_hFirstDimStyle))
- {
- utDimStyleReplace=utID;
- }
- }
- if(!m_pConverter->SaveAndReinitDataBase(utDimStyleReplace,strFileNameT,FALSE))
- {
- _WRITE(str="保存纸区空间文件时失败");
- filefind.Close();
- return FALSE;
- }
- }
- _WRITE(str="_________结束转换纸区空间中的实体");
- filefind.Close();
- return TRUE;
- }
- //注意 OpenDwg将文字样式与形混为一起.
- BOOL CDwgReader::processshapefile(AD_DB_HANDLE dwghandle)
- {
- calculate_findfonts(&g_afont);
- #ifdef _DEBUG
- // for(int index=0;index<m_afont.GetCount();index++)
- // {
- // m_afont.GetStartPosition();
- // m_afont.GetNextAssoc(.HashKey()
- // }
- #endif
- _WRITE(str="_________开始转换形文件");
- //short adStartShapefileGet (AD_DB_HANDLE handle);
- sReturnValue=adStartShapefileGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- //long adNumShapefiles (AD_DB_HANDLE handle);
- for(long i=0;i<adNumShapefiles(dwghandle);i++)
- {
- BOOL bUseSHX=FALSE;
- //short adGetShapefile (AD_DB_HANDLE handle, PAD_SHPTB adshptb);
- sReturnValue=adGetShapefile(dwghandle,&adtb->shptb);
- if(adtb->shptb.flag&AD_SHAPEFILE_SHAPES)//形,不是形字体
- {
- continue;
- }
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
- if(adtb->shptb.purgedflag==1)
- {
- continue;
- }
- //========================================================
- //new shape
- //========================================================
- //1.读出扩展数据.
- CString strTempFontName;
- CShape* shape=new CShape;
- if(adtb->shptb.xdblob!=AD_VMNULL)
- {
- PAD_BLOB_CTRL bcptr;
- bcptr=adStartBlobRead(adtb->shptb.xdblob);
- while(adReadExtendeddata(bcptr,adxd))
- {
- if(adxd->xddxfnumber==1000)
- {
- strTempFontName=adxd->xddata.xdstring;//ttf字体的名称
- }
- else if (adxd->xddxfnumber==1071)
- {
- shape->m_lShapeCapacity=adxd->xddata.xdlong;
- }
- }
- adEndBlobRead(bcptr);
- }
- shape->m_strShapename=adtb->shptb.name;
- //2.分析文件名
- {
- CString strfilename=adtb->shptb.file;
- //2.1 文件名为空,数据在扩展数据中.
- if(strfilename.IsEmpty())
- {
- bUseSHX=FALSE;
- }
- else if(strfilename.Find('.')!=-1)
- {//2.2 有扩展名,则依扩展名判断
- if(strfilename.GetLength()<=4)
- {
- bUseSHX=FALSE;
- }
- else
- {
- CString strExt=strfilename.Right(4);
- strExt.MakeLower();
- if(strExt==".shx")
- {
- bUseSHX=TRUE;
- }
- else
- {
- bUseSHX=FALSE;
- }
- }
- }
- else
- {//2.3 没有扩展名则智能判断.
- //strfilename.MakeLower();
- try
- {
- void* pv = NULL;
- if (g_afont.Lookup(strfilename, pv)) // found it
- {
- bUseSHX=FALSE;
- }
- else
- {
- strfilename+=".shx";
- bUseSHX=TRUE;
- }
- // CFont fonttext;
- // if(fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strfilename))
- // {
- // bUseSHX=FALSE;
- // }
- // else
- // {
- // strfilename+=".shx";
- // bUseSHX=TRUE;
- // }
- }
- catch(...)
- {
- strfilename+=".shx";
- bUseSHX=TRUE;
- }
- }
- if(bUseSHX)
- {
- if(!strfilename.IsEmpty())
- {
- calculate_DefaultExamineFile(strfilename,"fonts");
- }
- shape->m_strShapefilename=strfilename;
- strfilename=adtb->shptb.bigfontname;
- if(strfilename.IsEmpty())
- {
- //没有大字体.
- }
- else if(strfilename.GetLength()<4)//文字样式的形文件名都有后缀,只有txt出外,因此认为没有后缀则后缀为shx
- {
- strfilename+=".shx";
- }
- else
- {
- CString strExt=strfilename.Right(4);
- strExt.MakeLower();
- if(strExt!=".shx")
- {
- strfilename+=".shx";
- }
- }
- if(!strfilename.IsEmpty())
- {
- calculate_DefaultExamineFile(strfilename,"fonts");
- }
- shape->m_strBigFontfilename=strfilename;
- shape->m_bUseSHX=TRUE;
- }
- else
- {
- //解读字体文件,分析出字体名称.
- if((!strfilename.IsEmpty())&&(strfilename.Find('.')!=-1))
- {
- if(strfilename.Find('\')==-1)
- {
- TCHAR szDirName[MAX_PATH];
- if(::GetWindowsDirectory(szDirName,MAX_PATH))
- {
- CString strTemp=strfilename;
- CString strDirName=szDirName;
- strTemp=strDirName+"\Fonts\"+strTemp;
- if(calculate_findfontname(strfilename,strTemp,strTemp))
- {
- if(!strTemp.IsEmpty())
- {
- strfilename=strTemp;
- }
- }
- else if(!strTempFontName.IsEmpty())
- {
- strfilename=strTempFontName;
- }
- }
- }
- shape->m_strShapefilename=strfilename;
- shape->m_strBigFontfilename.Empty();
- shape->m_bUseSHX=FALSE;
- }
- else if(strTempFontName.IsEmpty())
- {
- shape->m_strShapefilename="txt.shx";
- shape->m_strBigFontfilename="bzdft.shx";
- shape->m_bUseSHX=TRUE;
- }
- }
- }
- if(shape->m_strShapefilename.IsEmpty())
- {
- shape->m_strShapefilename=strTempFontName;
- }
- shape->m_utShapeflag1=adtb->shptb.flag;
- shape->m_utShapeflag2=adtb->shptb.flag2;
- shape->m_dShapeAngle=adtb->shptb.angle*180/PI;
- shape->m_dShapeHeight=adtb->shptb.height;
- shape->m_dShapeWidth=adtb->shptb.width;
- m_ashape.Add(adtb->shptb.objhandle,shape);
- }
- _WRITE(str="_________结束转换形文件");
- return TRUE;
- }
- BOOL CDwgReader::processcodepage(AD_DB_HANDLE dwghandle)
- {
- PAD_DWGHDR dwghd;
- dwghd=adHeaderPointer(dwghandle);
- if(!dwghd)
- {
- _WRITE("文件头错误");
- return TRUE;
- }
- m_pConverter->m_sCodePage=dwghd->dwgcodepage;
- // unsigned short ch;
- // short ch2;
- // for(unsigned short index=0;index<0xffff;index++)
- // {
- // adUnicodeToCodePageChar(index,m_pConverter->m_sCodePage,&ch2);//936表示是中文
- // _WRITE(str.Format("%xdt%xd",index,ch2));
- // }
- return TRUE;
- }
- BOOL CDwgReader::processdimstyle(AD_DB_HANDLE dwghandle)
- {
- BOOL bLoadedDimStyle=FALSE;
- CDimStyle cdimstyle;
- if(!m_strDimStyleFullName.IsEmpty())
- {
- CFileFind filefind;
- if(filefind.FindFile(m_strDimStyleFullName))
- {
- if(cdimstyle.Load((LPCTSTR)m_strDimStyleFullName))
- {
- bLoadedDimStyle=TRUE;
- }
- }
- }
- //short adStartDimstyleGet (AD_DB_HANDLE handle);
- sReturnValue=adStartDimstyleGet(dwghandle);
- if(sReturnValue!=1)
- {
- _ERROR;
- return FALSE;
- }
-
- //long adNumDimstyles(AD_DB_HANDLE handle);
- for(short i=0; i<(short)adNumDimstyles(dwghandle); i++)
- {
- //short adGetDimstyle (AD_DB_HANDLE handle, PAD_DIMSTYLE addimst);
- sReturnValue=adGetDimstyle(dwghandle,&adtb->dimst);
- if(sReturnValue!=1)
- {
- _ERROR;
- continue;
- }
- if(i==0)
- {
- adHancpy(m_hFirstDimStyle,adtb->dimst.objhandle);
- }
- if(!adtb->dimst.purgedflag)
- {
- //{调整尺寸样式
- BOOL bAdjusted=FALSE;
- //文字高度调整
- double dTextHeight=1.0;
- //箭头大小调整
- double dArrowSize=1.0;
- //尺寸数值调整
- double dDimValueRate=1.0;
- //文字样式调整
- UINT utWordStyle=((UINT)-1);
- if(m_ddimstyleconvmode==2)
- {
- CShape* pShape=new CShape;
- if(m_ashape.GetHead())
- {
- (*pShape)=(*m_ashape.GetHead());
- }
- {
- sReturnValue=adStartBlockheaderGet(dwghandle);
- if(sReturnValue!=1)
- {
- delete pShape;
- _ERROR;
- return FALSE;
- }
- AD_TB adtbtemp;
- //遍历所有空间的所有的尺寸
- //long adNumBlockheaders (AD_DB_HANDLE handle);
- for(long j=0; j<adNumBlockheaders(dwghandle);j++) // note --无0 -2 so we don't get the model and paperspace blocks
- {
- //short adGetBlockheader (AD_DB_HANDLE handle, PAD_BLKH adblkh);
- sReturnValue=adGetBlockheader(dwghandle,&adtbtemp.blkh);
- if(sReturnValue!=1)
- {
- delete pShape;
- _ERROR;
- return FALSE;
- }
- if(adtbtemp.blkh.purgedflag==1)
- {
- continue;
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adtbtemp.blkh.entitylist);
- if(sReturnValue!=1)
- {
- delete pShape;
- _ERROR;
- return FALSE;
- }
- //short adGetEntity (AD_VMADDR list,PAD_ENT_HDR adenhd,PAD_ENT aden);
- while(adGetEntity(adtbtemp.blkh.entitylist,adenhd,aden))
- {
- if(adenhd->enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- if(adenhd->enttype==AD_ENT_DIMENSION)
- {
- BOOL bFirst=TRUE;
- if(bFirst||((aden->dim.dimflag & ' 7')==AD_DIMTYPE_ROTATED))
- {
- if(!adHansame(aden->dim.blockheaderobjhandle,NULLOBJHANDLE))
- {
- if( adHansame(aden->dim.dimstyleobjhandle,adtb->dimst.objhandle)||adHansame(aden->dim.dimstyleobjhandle,NULLOBJHANDLE))
- {
- AD_BLKH adblkhtemp;
- AD_ENT_HDR adenhdtemp;
- AD_ENT adentemp;
- sReturnValue=adSeekBlockheader(dwghandle,aden->dim.blockheaderobjhandle,&adblkhtemp);
- if(sReturnValue!=1)
- {
- delete pShape;
- _ERROR;
- return FALSE;
- }
- //short adStartEntityGet (AD_VMADDR list);
- sReturnValue=adStartEntityGet(adblkhtemp.entitylist);
- if(sReturnValue!=1)
- {
- delete pShape;
- _ERROR;
- return FALSE;
- }
- BOOL bAdjustTexted=FALSE;
- BOOL bAdjustArrowed=FALSE;
- //{计算出调整系数
- while(adGetEntity(adblkhtemp.entitylist,&adenhdtemp,&adentemp))
- {
- if(adenhdtemp.enttype==AD_ENT_ENDBLK)
- {
- break;
- }
- //文字高度调整
- //尺寸数值调整
- if((!bAdjustTexted)&&adenhdtemp.enttype==AD_ENT_TEXT)
- {
-
- {
- CMatch5* pMatch;
- if(m_ashape.Get(adentemp.text.tdata.shapefileobjhandle,pMatch))
- {
- (*pShape)=(*pMatch->m_shape);
- }
-
- pShape->m_strShapename="dim";
- //pShape->m_strShapefilename=;
- //pShape->m_strBigFontfilename=;
- //pShape->m_lShapeCapacity=;
- //pShape->m_utShapeflag1=;
- //pShape->m_utShapeflag2=;
- //pShape->m_dShapeAngle=;
- //pShape->m_dShapeHeight=;
- pShape->m_dShapeWidth=adentemp.text.tdata.widthfactor;
- //pShape->m_bUseSHX=;
- //pShape->m_KmWordStyleID=;
- }
- dTextHeight=adentemp.text.tdata.height;
- if((aden->dim.dimflag & ' 7')==AD_DIMTYPE_ROTATED)
- {
- dDimValueRate=::atof(adentemp.text.textstr);
- KmPoint p1(aden->dim.defpt2[0],aden->dim.defpt2[1]);
- KmPoint p2(aden->dim.defpt3[0],aden->dim.defpt3[1]);
- double dAngle=::standard(::rad_to_deg(aden->dim.dimrotang));
- if(dAngle<45||(dAngle>135&&dAngle<225)||dAngle>315)
- {//水平
- try
- {
- dDimValueRate=fabs(dDimValueRate/(p1.x-p2.x));
- }
- catch(...)
- {
- }
- }
- else
- {//垂直
- try
- {
- dDimValueRate=fabs(dDimValueRate/(p1.y-p2.y));
- }
- catch(...)
- {
- }
- }
- bAdjustTexted=TRUE;
- if(bAdjustArrowed)
- {
- break;
- }
- }
- else
- {
- bFirst=FALSE;
- }
- }
- if((!bAdjustTexted)&&adenhdtemp.enttype==AD_ENT_MTEXT)
- {
- {
- CMatch5* pMatch;
- if(m_ashape.Get(adentemp.mtext.shapefileobjhandle,pMatch))
- {
- (*pShape)=(*pMatch->m_shape);
- }
- pShape->m_strShapename="dim";
- //pShape->m_strShapefilename=;
- //pShape->m_strBigFontfilename=;
- //pShape->m_lShapeCapacity=;
- //pShape->m_utShapeflag1=;
- //pShape->m_utShapeflag2=;
- //pShape->m_dShapeAngle=;
- //pShape->m_dShapeHeight=;
- //pShape->m_dShapeWidth=adentemp.mtext.;
- //pShape->m_bUseSHX=;
- //pShape->m_KmWordStyleID=;
- }
- dTextHeight=adentemp.mtext.ht;
- if((aden->dim.dimflag & ' 7')==AD_DIMTYPE_ROTATED)
- {
- if(adentemp.mtext.ldblob==AD_VMNULL)
- {
- dDimValueRate=::atof(adentemp.mtext.textstr);
- }
- else
- {
- continue;
- }
- KmPoint p1(aden->dim.defpt2[0],aden->dim.defpt2[1]);
- KmPoint p2(aden->dim.defpt3[0],aden->dim.defpt3[1]);
- double dAngle=::standard(::rad_to_deg(aden->dim.dimrotang));
- if(dAngle<45||(dAngle>135&&dAngle<225)||dAngle>315)
- {//水平
- try
- {
- dDimValueRate=fabs(dDimValueRate/(p1.x-p2.x));
- }
- catch(...)
- {
- }
- }
- else
- {//垂直
- try
- {
- dDimValueRate=fabs(dDimValueRate/(p1.y-p2.y));
- }
- catch(...)
- {
- }
- }
- bAdjustTexted=TRUE;
- if(bAdjustArrowed)
- {
- break;
- }
- }
- else
- {
- bFirst=FALSE;
- }
- }
-
- if((!bAdjustArrowed)&&adenhdtemp.enttype==AD_ENT_SOLID)
- {
- double dDistancePower2_bottom= (adentemp.solid.pt2[0]-adentemp.solid.pt0[0])*
- (adentemp.solid.pt2[0]-adentemp.solid.pt0[0])+
- (adentemp.solid.pt2[1]-adentemp.solid.pt0[1])*
- (adentemp.solid.pt2[1]-adentemp.solid.pt0[1]);
- double dDistancePower2_length= (adentemp.solid.pt1[0]-adentemp.solid.pt0[0])*
- (adentemp.solid.pt1[0]-adentemp.solid.pt0[0])+
- (adentemp.solid.pt1[1]-adentemp.solid.pt0[1])*
- (adentemp.solid.pt1[1]-adentemp.solid.pt0[1]);
- dArrowSize=sqrt(fabs(dDistancePower2_length-dDistancePower2_bottom/4));
- bAdjustArrowed=TRUE;
- if(bAdjustTexted)
- {
- break;
- }
- }
- //箭头大小调整
- }
- //}
- if(bAdjustTexted&&bAdjustArrowed)
- {
- bAdjusted=TRUE;
- break;
- }
- }
- }
- }
- }
- }
- if(bAdjusted)
- {
- break;
- }
- }
- }
-
- AD_OBJHANDLE objhandle;
- adHancpy(objhandle,NULLOBJHANDLE);
- m_ashape.Add(objhandle,pShape);
- utWordStyle=pShape->m_KmWordStyleID;
- }
- if(bLoadedDimStyle)
- {
- /* CMatch5* match;
- if(m_ashape.Get(adtb->dimst.shapefileobjhandle,match))
- {
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
- var.vt=VT_INT;var.intVal=match->m_shape->m_KmWordStyleID;
- cdimstyle.SetDimStlVar(DIMTXSTY,var);
- }*/
-
- UINT id=m_pConverter->ConverterEnthead_Dimstyle(cdimstyle,bAdjusted,dTextHeight,dArrowSize,dDimValueRate,utWordStyle);
- m_adimstyle.Add(adtb->dimst.objhandle,id,1.0,FALSE);
- }
- else
- {
- UINT id=m_pConverter->ConverterEnthead_Dimstyle(&adtb->dimst,m_aColor,m_ilinewidthdefault,m_ashape,bAdjusted,dTextHeight,dArrowSize,dDimValueRate,utWordStyle);
- m_adimstyle.Add(adtb->dimst.objhandle,id,1.0,FALSE);
- }
- }
- }
- return TRUE;
- }
- BOOL CDwgReader::processnouseblock(AD_DB_HANDLE dwghandle)
- {
- return TRUE;
- CMatch2* match;
- POSITION pos=m_ablock.GetHeadPosition();
- while(pos!=NULL)
- {
- match=m_ablock.GetNext(pos);
- if(!m_pConverter->CheckNoUseBlock(match->m_id))
- {
- match->m_bUseful=FALSE;
- }
- }
- return TRUE;
- }