Processfile2.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:81k
源码类别:

CAD

开发平台:

Visual C++

  1. //      KMCAD40-FileSwitch-Processfile2.cpp-1.0 
  2. //---------------------------------------------
  3. //KMCAD40-FileSwitch-Processfile2.cpp-1.1 -> 1.2
  4. #include "stdafx.h"
  5. #include "FileSwitch.h"
  6. #include "DwgReader.h"
  7. #include "KmSection.h"
  8. #include "KmPouQie.h"
  9. #include "KmSymbl.h"
  10. #include "Vector.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[]=__FILE__;
  14. #define new DEBUG_NEW
  15. #endif
  16. /*
  17. {
  18.   short i;
  19.   if (adxd->xddxfnumber==1000)     TRACE("1000n%sn",adxd->xddata.xdstring);
  20.   else if (adxd->xddxfnumber==1001)TRACE("1001n");
  21.   else if (adxd->xddxfnumber==1003)TRACE("1003n");
  22.   else if (adxd->xddxfnumber==1005)TRACE("1005n");
  23.   else if (adxd->xddxfnumber==1010)TRACE("1010n%fn1020n%fn1030n%fn",      adxd->xddata.xd3dpt[0],adxd->xddata.xd3dpt[1],adxd->xddata.xd3dpt[2]);
  24.   else if (adxd->xddxfnumber==1040)TRACE("1040n%fn",adxd->xddata.xdreal);
  25.   else if (adxd->xddxfnumber==1070)TRACE("1070n%dn",adxd->xddata.xdint);
  26.   else if (adxd->xddxfnumber==1071)TRACE("1071n%ldn",adxd->xddata.xdlong);
  27.   else if (adxd->xddxfnumber==1002)TRACE("1002n%cn",adxd->xddata.xdcontrol);
  28.   else if (adxd->xddxfnumber==1004){TRACE("1004n");for (i=0; i<adxd->xdbindatalength; i++) TRACE("%.02X",((unsigned)adxd->xddata.xdbindata[i]) & 255);TRACE("n"); }
  29.   else if (adxd->xddxfnumber==1011)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworldpos[0],adxd->xddata.xdworldpos[1],adxd->xddata.xdworldpos[2]);
  30.   else if (adxd->xddxfnumber==1012)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworlddisp[0],adxd->xddata.xdworlddisp[1],adxd->xddata.xdworlddisp[2]);
  31.   else if (adxd->xddxfnumber==1013)TRACE("1011n%fn%fn%fn",adxd->xddata.xdworlddir[0],adxd->xddata.xdworlddir[1],adxd->xddata.xdworlddir[2]);
  32.   else if (adxd->xddxfnumber==1041)TRACE("1041n%fn",adxd->xddata.xddist);
  33.   else if (adxd->xddxfnumber==1042)TRACE("1042n%fn",adxd->xddata.xdscale);
  34. }
  35. */
  36. extern CStdioFile g_CensorialFile; //监察转换进度的文件
  37. extern int g_mode;
  38. CVector::CVector()
  39. {
  40. m_bwidth=FALSE;
  41. m_widthbegin=0.0;
  42. m_widthend=0.0;
  43. m_bulge=0.0;
  44. m_x=0.0;
  45. m_y=0.0;
  46. m_z=0.0;
  47. }
  48. CVector::~CVector()
  49. {
  50. }
  51. BOOL CDwgReader::processentity(AD_DB_HANDLE dwghandle)
  52. {
  53. //#define adEntIsInvisible(a)    (a & AD_INVISIBLE)
  54. if(adEntIsInvisible(adenhd->entflags))
  55. {
  56. return TRUE;
  57. }
  58. if(!processentity_enthead(dwghandle))
  59. {
  60. return FALSE;
  61. }
  62. switch(adenhd->enttype)
  63. {
  64. case AD_ENT_LINE://1
  65. return processentity_line(dwghandle);
  66. case  AD_ENT_POINT://2
  67. return processentity_point(dwghandle);
  68. case  AD_ENT_CIRCLE://3
  69. return processentity_circle(dwghandle);
  70. case  AD_ENT_SHAPE:/*4*/ 
  71. return processentity_shape(dwghandle);
  72. case  AD_ENT_ELLIPSE://5
  73. return processentity_ellipse(dwghandle);
  74. case  AD_ENT_SPLINE://
  75. return processentity_spline(dwghandle);
  76. case  AD_ENT_TEXT:/*7*/
  77. return processentity_text(dwghandle);
  78. case  AD_ENT_ARC://8
  79. return processentity_arc(dwghandle);
  80. case  AD_ENT_TRACE://9转换为4根线 宽度线      
  81. return processentity_trace(dwghandle);
  82. case  AD_ENT_REGION:/*10*/
  83. case  AD_ENT_BODY:
  84. case  AD_ENT_SOLID3D:   
  85. return processentity_acis(dwghandle);
  86. case  AD_ENT_SOLID:/*11*/ 
  87. return processentity_solid(dwghandle);
  88. case AD_ENT_BLOCK://12
  89. return processentity_block(dwghandle);
  90. case AD_ENT_ENDBLK://13
  91. _WRITE(str="块结束标志符没有被正常处理");
  92. return FALSE;
  93. case  AD_ENT_INSERT://14
  94. return processentity_insert(dwghandle);
  95. case  AD_ENT_ATTDEF:
  96. return processentity_attdef(dwghandle);
  97. case  AD_ENT_ATTRIB:
  98. return processentity_attrib(dwghandle);
  99. case  AD_ENT_POLYLINE://多段线开始标志
  100. case  AD_ENT_VERTEX://多段线顶点   
  101. case  AD_ENT_SEQEND://insert+attribs或polyline+vertexs的结束标志,前者不予考虑  以上三种实体配合起来实现了多段线的完整转换.    
  102. break;
  103. case  AD_ENT_LINE3D:
  104. return processentity_3dline(dwghandle);
  105. case  AD_ENT_FACE3D:
  106. return processentity_3dface(dwghandle);
  107. case  AD_ENT_DIMENSION:
  108. return processentity_dim(dwghandle);
  109. case AD_ENT_VIEWPORT://公共部分不予处理
  110. break;
  111. case  AD_ENT_RAY:
  112. return processentity_ray(dwghandle);
  113. case  AD_ENT_XLINE:
  114. return processentity_xline(dwghandle);
  115. case  AD_ENT_MTEXT:
  116. return processentity_mtext(dwghandle);
  117. case  AD_ENT_LEADER://完成但仍然可以进一步优化 样条
  118. return processentity_leader(dwghandle);
  119. case  AD_ENT_TOLERANCE:
  120. return processentity_tolerance(dwghandle);
  121. case  AD_ENT_MLINE://完成 平行线
  122. return processentity_mline(dwghandle);
  123. default:
  124. if(adenhd->enttype==adArcAlignedTextEnttype(dwghandle))
  125. {//圆弧文字
  126. return processentity_atext(dwghandle);
  127. }
  128. else if(adenhd->enttype==adHatchEnttype(dwghandle))
  129. {
  130. return processentity_hatch(dwghandle);
  131. }
  132. else if(adenhd->enttype==adImageEnttype(dwghandle))
  133. {
  134. //图像
  135. //return processentity_image( adenHead,  aden, bPaper, bBlock);
  136. }
  137. else if(adenhd->enttype==adLwplineEnttype(dwghandle))
  138. {
  139. return processentity_lwpline(dwghandle);
  140. }
  141. else if(adenhd->enttype==adOle2frameEnttype(dwghandle))
  142. {
  143. //OLE
  144. //return processentity_ole2frame( adenHead,  aden, bPaper, bBlock);
  145. }
  146. else if(adenhd->enttype==adRtextEnttype(dwghandle))
  147. {//远程文字
  148. return processentity_rtext(dwghandle);
  149. }
  150. else if(adenhd->enttype==adWipeoutEnttype(dwghandle))
  151. {
  152. //带maskcolor的图像
  153. //return processentity_wipeout( adenHead,  aden, bPaper, bBlock);
  154. else if(adenhd->enttype==adDimAssocObjtype(dwghandle))
  155. {
  156. //2002新增实体AD_DIMASSOC 
  157. //return processentity_wipeout( adenHead,  aden, bPaper, bBlock);
  158. }
  159. else if(AD_IS_A_PROXYENT(adenhd->enttype))
  160. {
  161. _WRITE(str="遗漏的代理实体没有处理");
  162. }
  163. else
  164. {
  165. _WRITE(str="未知类型的ENTITY没有处理");
  166. }
  167. break;
  168. }
  169. return TRUE;
  170. }
  171. BOOL CDwgReader::processentity_enthead(AD_DB_HANDLE dwghandle)
  172. {
  173. unsigned short slwidth;
  174. int icolor;
  175. int iltype;
  176. double dlscale;
  177. UINT idlayer;
  178. double dscalelayer;
  179. double dscaleltype;
  180. m_alayer.Get(adenhd->entlayerobjhandle,idlayer,dscalelayer);
  181. m_altype.Get(adenhd->entltypeobjhandle,iltype,dscaleltype);
  182. try
  183. {
  184. if(adenhd->entcolor==AD_COLOR_BYBLOCK)
  185. {
  186. icolor=COLOR_BYBLOCK;//随块
  187. }
  188. else if(adenhd->entcolor==AD_COLOR_BYLAYER)
  189. {
  190. icolor=COLOR_BYLAYER;
  191. }
  192. else
  193. {
  194. if(adenhd->entcolor>=0 && adenhd->entcolor<m_aColor.GetSize())
  195. {
  196. icolor=m_aColor[adenhd->entcolor];
  197. }
  198. else
  199. {
  200. TRACE("errordata");
  201. }
  202. }
  203. }
  204. catch(...)
  205. {
  206. _WRITE(str="非法的颜色码");
  207. return FALSE;
  208. }
  209. if(dscaleltype<0)//线形随层
  210. {
  211. dlscale=adenhd->entltscale/dscalelayer;
  212. }
  213. else
  214. {
  215. dlscale=adenhd->entltscale/dscaleltype;
  216. }
  217. slwidth=adenhd->lineweight;
  218. int ilwidth=slwidth;
  219. {
  220. if(slwidth==AD_WEIGHT_DEFAULT)
  221. {
  222. ilwidth=m_ilinewidthdefault;
  223. }
  224. else if(slwidth==AD_WEIGHT_BYBLOCK)
  225. {
  226. ilwidth=LWIDTH_BYBLOCK;
  227. }
  228. else if(slwidth==AD_WEIGHT_BYLAYER)
  229. {
  230. ilwidth=LWIDTH_BYLAYER;
  231. }
  232. else
  233. {
  234. ilwidth=::GetLineWidthAsInt(double(abs(slwidth))/100.0);
  235. }
  236. }
  237. //应用打印样式
  238. if(m_dplotstyleconvmode==1)
  239. {
  240. UsePlotStyle(adenhd->entcolor,ilwidth,icolor,iltype,dlscale,adenhd->plotstyleobjhandle,adenhd->entflags);
  241. }
  242. m_pConverter->WriteEnthead(ilwidth,icolor,iltype,dlscale,idlayer);
  243. return TRUE;
  244. }
  245. void CDwgReader::UsePlotStyle(int acicolor,int &ilwidth, int &icolor, int &iltype, double &dlscale, AD_OBJHANDLE plotstyleobjhandle,unsigned char flag)
  246. {
  247. if(flag!=0)
  248. {
  249. //#define AD_BYBLOCK_PLOTSTYLE    32
  250. //#define AD_BYLAYER_PLOTSTYLE    64
  251. if(adEntHasByLayerPlotStyle(flag))
  252. {
  253. ilwidth=LWIDTH_BYLAYER;
  254. icolor=COLOR_BYLAYER;
  255. iltype=LTYPE_BYLAYER;
  256. return;
  257. }
  258. if(adEntHasByBlockPlotStyle(flag))
  259. {
  260. ilwidth=LWIDTH_BYBLOCK;
  261. icolor=COLOR_BYBLOCK;
  262. iltype=LTYPE_BYBLOCK;
  263. return;
  264. }
  265. }
  266. CString strPlotSheetName;
  267. if(!m_aplot.Get(plotstyleobjhandle,strPlotSheetName))return;
  268. if(strPlotSheetName=="Normal")
  269. {
  270. strPlotSheetName.Format("Color_%d",acicolor);
  271. //strPlotSheetName=""
  272. }
  273. /*
  274. typedef struct tagADPLOTSTYLE
  275. {
  276.     short        nPhysicalPenNumber; //笔号
  277.     short        nVirtualPenNumber; //虚拟笔
  278.     OdaLong      nColor; //颜色
  279.     short        nColorPolicy; //颜色方案
  280.     short        nScreen; //淡显
  281.     double       dblLinePatternSize;
  282.     short        nLinetype; //线型
  283.     char         bAdaptiveLinetype; //线型的自适应调整
  284.     short        nLineweight; //线宽 是指线宽表中的值
  285.     short        nFillStyle; //填充
  286.     short        nEndStyle; //端点
  287.     short        nJoinStyle; //链接
  288. } ADPLOTSTYLE;
  289. */
  290. ADPLOTSTYLE* pPlotStyle=NULL;
  291. int iPlotStyle=-1;
  292. if(m_iCurPlotStyleTable>=0&&m_iCurPlotStyleTable<m_aPlotStyleTable.GetSize())
  293. {
  294. pPlotStyle=NULL;
  295. //extern  short  ADCDECL adFindPlotStyleByName _((char *pszSearchName, ADPLOTSTYLETABLE *pTable, ADPLOTSTYLE **ppStyle));
  296. sReturnValue=adFindPlotStyleByName((char*)(LPCTSTR)strPlotSheetName,m_aPlotStyleTable[m_iCurPlotStyleTable],&pPlotStyle);
  297. if(sReturnValue!=1)
  298. {
  299. pPlotStyle=NULL;
  300. }
  301. }
  302. if(pPlotStyle==NULL)
  303. {
  304. for(int i=0;i<m_aPlotStyleTable.GetSize();i++)
  305. {
  306. if(i==m_iCurPlotStyleTable)continue;
  307. pPlotStyle=NULL;
  308. //extern  short  ADCDECL adFindPlotStyleByName _((char *pszSearchName, ADPLOTSTYLETABLE *pTable, ADPLOTSTYLE **ppStyle));
  309. sReturnValue=adFindPlotStyleByName((char*)(LPCTSTR)strPlotSheetName,m_aPlotStyleTable[i],&pPlotStyle);
  310. if(sReturnValue==1)
  311. {
  312. if(pPlotStyle!=NULL)
  313. {
  314. iPlotStyle=i;
  315. break;
  316. }
  317. }
  318. else
  319. {
  320. pPlotStyle=NULL;
  321. }
  322. }
  323. }
  324. else
  325. {
  326. iPlotStyle=m_iCurPlotStyleTable;
  327. }
  328. if(pPlotStyle==NULL)return;
  329. if(! (iPlotStyle>=0&&iPlotStyle<m_aPlotStyleTable.GetSize()) ) 
  330. {
  331. return;
  332. }
  333. if(pPlotStyle->nColor!=AD_COLOR_USEOBJECT)
  334. {
  335. // #define AD_COLORPOLICY_INDEX        1
  336. // #define AD_COLORPOLICY_GRAYSCALE    3
  337. // #define AD_COLORPOLICY_RGB          5
  338. if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_INDEX)
  339. {
  340. }
  341. if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_RGB)
  342. {
  343. BYTE br=GetRValue(pPlotStyle->nColor);
  344. BYTE bg=GetGValue(pPlotStyle->nColor);
  345. BYTE bb=GetBValue(pPlotStyle->nColor);
  346. icolor=RGB(bb,bg,br);
  347. }
  348. if(pPlotStyle->nColorPolicy&AD_COLORPOLICY_GRAYSCALE)//转换为灰度
  349. {
  350. //亮度=0.5(min(r,g,b)+max(r,g,b));
  351. }
  352. }
  353. if(pPlotStyle->nLineweight!=AD_WEIGHT_USEOBJECT)
  354. {
  355. try
  356. {
  357. double dWidth=m_aPlotStyleTable[iPlotStyle]->aLineweights[pPlotStyle->nLineweight-1];
  358. ilwidth=::GetLineWidthAsInt(dWidth);
  359. }
  360. catch(...)
  361. {
  362. }
  363. }
  364. if(pPlotStyle->nLinetype!=AD_LINETYPE_USEOBJECT)
  365. {
  366. switch(pPlotStyle->nLinetype)
  367. {
  368. case AD_LINETYPE_LTPSOLID                            :
  369. iltype=SOLID_LINE;
  370. break;
  371. case AD_LINETYPE_LTPDASHED                           :
  372. iltype=DASHED_LINE;
  373. break;
  374. case AD_LINETYPE_LTPDOTTED                           :
  375. iltype=DOT_LINE;
  376. break;
  377. case AD_LINETYPE_LTPDASHDOT                          :
  378. iltype=DASH_DOT_LINE;
  379. break;
  380. case AD_LINETYPE_LTPSHORTDASH                        :
  381. iltype=DASHED_LINE;
  382. break;
  383. case AD_LINETYPE_LTPMEDIUMDASH                       :
  384. iltype=DASHED_LINE;
  385. break;
  386. case AD_LINETYPE_LTPLONGDASH                         :
  387. iltype=DASHED_LINE;
  388. break;
  389. case AD_LINETYPE_LTPSHORTDASHX2                      :
  390. iltype=DASHED_LINE;
  391. break;
  392. case AD_LINETYPE_LTPMEDIUMDASHX2                     :
  393. iltype=DASHED_LINE;
  394. break;
  395. case AD_LINETYPE_LTPLONGDASHX2                       :
  396. iltype=DASHED_LINE;
  397. break;
  398. case AD_LINETYPE_LTPMEDIUMLONGDASH                   :
  399. iltype=DASHED_LINE;
  400. break;
  401. case AD_LINETYPE_LTPMEDIUMDASHSHORTDASHSHORTDASH     :
  402. iltype=LONGDASH_DSHORTDASH_LINE;
  403. break;
  404. case AD_LINETYPE_LTPLONGDASHSHORTDASH                :
  405. iltype=LONGDASH_SHORTDASH_LINE;
  406. break;
  407. case AD_LINETYPE_LTPLONGDASHDOTDOT                   :
  408. iltype=SDASH_DDOT_LINE;
  409. break;
  410. case AD_LINETYPE_LTPLONGDASHDOT                      :
  411. iltype=DASH_DOT_LINE;
  412. break;
  413. case AD_LINETYPE_LTPMEDIUMDASHDOTSHORTDASHDOT        :
  414. iltype=LONGDASH_DSHORTDASH_LINE;
  415. break;
  416. case AD_LINETYPE_LTPSPARSEDOT                        :
  417. iltype=DOT_LINE;
  418. break;
  419. case AD_LINETYPE_LTPISODASH                          :
  420. iltype=DASHED_LINE;
  421. break;
  422. case AD_LINETYPE_LTPISODASHSPACE                     :
  423. iltype=DASH_SPACE_LINE;
  424. break;
  425. case AD_LINETYPE_LTPISOLONGDASHDOT                   :
  426. iltype=DASH_DOT_LINE;
  427. break;
  428. case AD_LINETYPE_LTPISOLONGDASHDOUBLEDOT             :
  429. iltype=SDASH_DDOT_LINE;
  430. break;
  431. case AD_LINETYPE_LTPISOLONGDASHTRIPLEDOT             :
  432. iltype=SDASH_TRIDOT_LINE;
  433. break;
  434. case AD_LINETYPE_LTPISODOT                           :
  435. iltype=DOT_LINE;
  436. break;
  437. case AD_LINETYPE_LTPISOLONGDASHSHORTDASH             :
  438. iltype=LONGDASH_SHORTDASH_LINE;
  439. break;
  440. case AD_LINETYPE_LTPISOLONGDASHDOUBLESHORTDASH       :
  441. iltype=LONGDASH_DSHORTDASH_LINE;
  442. break;
  443. case AD_LINETYPE_LTPISODASHDOT                       :
  444. iltype=DASH_DOT_LINE;
  445. break;
  446. case AD_LINETYPE_LTPISODOUBLEDASHDOT                 :
  447. iltype=DDASH_DOT_LINE;
  448. break;
  449. case AD_LINETYPE_LTPISODASHDOUBLEDOT                 :
  450. iltype=DASH_DDOT_LINE;
  451. break;
  452. case AD_LINETYPE_LTPISODOUBLEDASHDOUBLEDOT           :
  453. iltype=DDASH_DDOT_LINE;
  454. break;
  455. case AD_LINETYPE_LTPISODASHTRIPLEDOT                 :
  456. iltype=SDASH_TRIDOT_LINE;
  457. break;
  458. case AD_LINETYPE_LTPISODOUBLEDASHTRIPLEDOT           :
  459. iltype=DDASH_TRIDOT_LINE;
  460. break;
  461. }
  462. }
  463. }
  464. void CDwgReader::RGBtoHSV(double r, double g, double b, double *h, double *s, double *v)
  465. {
  466. }
  467. BOOL CDwgReader::processentity_line(AD_DB_HANDLE dwghandle)
  468. {
  469. int index=m_pConverter->ConverterEntiey_KmLine(aden->line.pt0[0],aden->line.pt0[1],aden->line.pt0[2],
  470. aden->line.pt1[0],aden->line.pt1[1],aden->line.pt1[2]).dwEntIndex;
  471. _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));
  472. return TRUE;
  473. }
  474. BOOL CDwgReader::processentity_3dline(AD_DB_HANDLE dwghandle)
  475. {
  476. int index=m_pConverter->ConverterEntiey_KmLine(aden->line3d.pt0[0],aden->line3d.pt0[1],aden->line3d.pt0[2],
  477. aden->line3d.pt1[0],aden->line3d.pt1[1],aden->line3d.pt1[2]).dwEntIndex;
  478. _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));
  479. return TRUE;
  480. }
  481. BOOL CDwgReader::processentity_point(AD_DB_HANDLE dwghandle)
  482. {
  483. int index=m_pConverter->ConverterEntiey_KmCircle(aden->point.pt0[0],aden->point.pt0[1],aden->point.pt0[2],m_dpointtocircleradius).dwEntIndex;
  484. _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));
  485. return TRUE;
  486. }
  487. BOOL CDwgReader::processentity_circle(AD_DB_HANDLE dwghandle)
  488. {
  489. if(calculate_BackView())
  490. {
  491. int index=m_pConverter->ConverterEntiey_KmCircle(-1*aden->circle.pt0[0],aden->circle.pt0[1],aden->circle.pt0[1],aden->circle.radius).dwEntIndex;
  492. _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));
  493. }
  494. else
  495. {
  496. int index=m_pConverter->ConverterEntiey_KmCircle(aden->circle.pt0[0],aden->circle.pt0[1],aden->circle.pt0[1],aden->circle.radius).dwEntIndex;
  497. _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));
  498. }
  499. return TRUE;
  500. }
  501. BOOL CDwgReader::processentity_ellipse(AD_DB_HANDLE dwghandle)
  502. {
  503. if(calculate_BackView())
  504. {
  505. double lr=calculate_3ddpdistance(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1],aden->ellipse.pt1offset[2]);
  506. double sr=lr*aden->ellipse.minortomajorratio;
  507. double angle=calculate_2dangle(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1]);
  508. if(fabs(fabs(aden->ellipse.startparam-aden->ellipse.endparam)-2*PI)<(PI/10000))
  509. {
  510. int index=m_pConverter->ConverterEntiey_KmEllipse(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,FALSE).dwEntIndex;
  511. _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));
  512. return TRUE;
  513. }
  514. //int index=m_pConverter->ConverterEntiey_KmEllipseArc(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,
  515. // angle-calculate_2dangle(-lr*cos(aden->ellipse.startparam),-sr*sin(aden->ellipse.startparam)),
  516. // angle-calculate_2dangle(-lr*cos(aden->ellipse.endparam),-sr*sin(aden->ellipse.endparam)),FALSE).dwEntIndex;
  517. int index=m_pConverter->ConverterEntiey_KmEllipseArc(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,
  518. angle,
  519. 2*angle-(angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.endparam),-sr*sin(aden->ellipse.endparam))),
  520. 2*angle-(angle+PI+calculate_2dangle(-lr*cos(aden->ellipse.startparam),-sr*sin(aden->ellipse.startparam))),FALSE).dwEntIndex;
  521. _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));
  522. }
  523. else
  524. {
  525. double lr=calculate_3ddpdistance(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1],aden->ellipse.pt1offset[2]);
  526. double sr=lr*aden->ellipse.minortomajorratio;
  527. double angle=calculate_2dangle(aden->ellipse.pt1offset[0],aden->ellipse.pt1offset[1]);
  528. if(fabs(fabs(aden->ellipse.startparam-aden->ellipse.endparam)-2*PI)<(PI/10000))
  529. {
  530. int index=m_pConverter->ConverterEntiey_KmEllipse(aden->ellipse.pt0[0],aden->ellipse.pt0[1],aden->ellipse.pt0[1],lr,sr,angle,FALSE).dwEntIndex;
  531. _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));
  532. return TRUE;
  533. }
  534. 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;
  535. _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));
  536. }
  537. return TRUE;
  538. }
  539. BOOL CDwgReader::processentity_arc(AD_DB_HANDLE dwghandle)
  540. {
  541. if(calculate_BackView())
  542. {
  543. 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;
  544. _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));
  545. }
  546. else
  547. {
  548. 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;
  549. _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));
  550. }
  551. return TRUE;
  552. }
  553. BOOL CDwgReader::processentity_xline(AD_DB_HANDLE dwghandle)
  554. {
  555. double x1=aden->xline.pt0[0]-m_dconstrulinelength*aden->xline.unitvec[0];
  556. double y1=aden->xline.pt0[1]-m_dconstrulinelength*aden->xline.unitvec[1];
  557. double z1=aden->xline.pt0[2]-m_dconstrulinelength*aden->xline.unitvec[2];
  558. double x2=aden->xline.pt0[0]+m_dconstrulinelength*aden->xline.unitvec[0];
  559. double y2=aden->xline.pt0[1]+m_dconstrulinelength*aden->xline.unitvec[1];
  560. double z2=aden->xline.pt0[2]+m_dconstrulinelength*aden->xline.unitvec[2];
  561. int index=m_pConverter->ConverterEntiey_KmLine(x1,y1,z1,x2,y2,z2).dwEntIndex;
  562. _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));
  563. return TRUE;
  564. }
  565. BOOL CDwgReader::processentity_3dface(AD_DB_HANDLE dwghandle)
  566. {
  567. if(!(aden->face3d.faceflag&AD_FACE3D_FACE1INVIS))
  568. {
  569. 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;
  570. _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));
  571. }
  572. if(!(aden->face3d.faceflag&AD_FACE3D_FACE2INVIS))
  573. {
  574. 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;
  575. _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));
  576. }
  577. if(!(aden->face3d.faceflag&AD_FACE3D_FACE3INVIS))
  578. {
  579. 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;
  580. _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));
  581. }
  582. if(!(aden->face3d.faceflag&AD_FACE3D_FACE4INVIS))
  583. {
  584. 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;
  585. _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));
  586. }
  587. return TRUE;
  588. }
  589. BOOL CDwgReader::processentity_ray(AD_DB_HANDLE dwghandle)
  590. {
  591. double x1=aden->ray.pt0[0]+m_dconstrulinelength*aden->ray.unitvec[0];
  592. double y1=aden->ray.pt0[1]+m_dconstrulinelength*aden->ray.unitvec[1];
  593. double z1=aden->ray.pt0[2]+m_dconstrulinelength*aden->ray.unitvec[2];
  594. int index=m_pConverter->ConverterEntiey_KmLine(aden->ray.pt0[0],aden->ray.pt0[1],aden->ray.pt0[2],x1,y1,z1).dwEntIndex;
  595. _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));
  596. return TRUE;
  597. }
  598. BOOL CDwgReader::processentity_spline(AD_DB_HANDLE dwghandle)
  599. {
  600. int mode;
  601. if(aden->spline.numctlpts>0)
  602. {
  603. switch(m_dsplineconvmode)
  604. {
  605. case 1:
  606. mode=2; //二次样条曲线
  607. break;
  608. default:
  609. mode=10+2; //折线
  610. break;
  611. }
  612. }
  613. else if(aden->spline.numfitpts>0)
  614. {
  615. switch(m_dsplineconvmode)
  616. {
  617. case 1:
  618. mode=3; //三次样条曲线
  619. break;
  620. default:
  621. mode=10+3; //折线
  622. break;
  623. }
  624. }
  625. else
  626. {
  627. _WRITE(str="样条没有控制点,没有转换");
  628. return FALSE;
  629. }
  630. int index=m_pConverter->ConverterEntiey_KmSPline(mode,aden->spline.ldblob,aden->spline.numknots,aden->spline.numctlpts,aden->spline.numfitpts).dwEntIndex;
  631. _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));
  632. return TRUE;
  633. }
  634. BOOL CDwgReader::processentity_insert(AD_DB_HANDLE dwghandle)
  635. {
  636. //short  attribsfollow;是否有属性文字,紧接着是属性实体,不予特别考虑
  637. UINT id;
  638. int index;
  639. double lscale;
  640. KmPoint pt;
  641. double dx=aden->insert.rowdist;
  642. double dy=aden->insert.coldist;
  643. m_ablock.Get(aden->insert.blockheaderobjhandle,id,lscale);
  644. if(id==0)
  645. {
  646. return TRUE;
  647. }
  648. BOOL b90mirror=calculate_BackView();
  649. for(int i=0;i<aden->insert.numrows;i++)//行
  650. {
  651. for(int j=0;j<aden->insert.numcols;j++)//列
  652. {
  653. pt=calculate_2drotate(aden->insert.pt0[0],aden->insert.pt0[1],i*dx,j*dy,aden->insert.rotang);
  654. 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;
  655. _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));
  656. }
  657. }
  658. /* if(aden->insert.xdblob != AD_VMNULL)
  659. {
  660. AD_ENT_HDR HatchEntHdr;
  661. AD_ENT HatchEnt;
  662. HatchEntHdr.enttype = adHatchEnttype(dwghandle);
  663. adSetEntityDefaults(dwghandle, &HatchEntHdr, &HatchEnt);
  664. //Purpose: Retrieve the hatch data from "xdata" of INSERT entity.
  665. if(!processentity_XData(dwghandle, &HatchEnt.hatch, adenhd, HatchHandle))
  666. {
  667. _WRITE(str="转换块引用的xdblob中中的剖面线失败");
  668. }
  669. }*/
  670. return TRUE;
  671. }
  672. BOOL CDwgReader::processentity_block(AD_DB_HANDLE dwghandle)
  673. {//aden->block.xrefpath暂不考虑引用块
  674. return m_pConverter->ConverterEntiey_KmBlockdef(aden->block.base[0],aden->block.base[1],aden->block.base[2]);
  675. }
  676. BOOL CDwgReader::processentity_mline(AD_DB_HANDLE dwghandle)
  677. {
  678. if(aden->mline.linesinstyle<=1)
  679. {
  680. _WRITE(str="平行线段数小于2段不能转换");
  681. return FALSE;
  682. }
  683. CMatch4* match;
  684. if(!m_amltype.Get(aden->mline.mlinestyleobjhandle,match))
  685. {
  686. return FALSE;
  687. }
  688. PAD_BLOB_CTRL bcptr;
  689. double pt0[3],ptemp[3],vertdir[3],miterdir[3];
  690. CArray<double,double>pt10;
  691. CArray<double,double>pt11;
  692. CArray<double,double>pt12;
  693. CArray<double,double>pt20;
  694. CArray<double,double>pt21;
  695. CArray<double,double>pt22;
  696. pt10.SetSize(aden->mline.linesinstyle);
  697. pt11.SetSize(aden->mline.linesinstyle);
  698. pt12.SetSize(aden->mline.linesinstyle);
  699. pt20.SetSize(aden->mline.linesinstyle);
  700. pt21.SetSize(aden->mline.linesinstyle);
  701. pt22.SetSize(aden->mline.linesinstyle);
  702. short numsegparms,numareafillparms;
  703. double segparm,areafillparm;
  704. //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
  705. bcptr=adStartBlobRead(aden->mline.ldblob);
  706. unsigned short i,j,k;
  707.     for(i=0;i<aden->mline.numverts;i++) 
  708. {
  709. adReadBlob3Double(bcptr,pt0);//鼠标点击点
  710. adReadBlob3Double(bcptr,vertdir);//鼠标点击点的方向,无需转换
  711. adReadBlob3Double(bcptr,miterdir);//平行点偏移方向
  712. for(j=0;j<aden->mline.linesinstyle; j++)
  713. {
  714. m_pConverter->WriteEnthead(match->segcolor[j],match->segltyle[j]);
  715. adReadBlobShort(bcptr,&numsegparms);
  716. for (k=0; k<numsegparms; k++) 
  717. {
  718. adReadBlobDouble(bcptr,&segparm);//第一个数据为沿偏移方向的平面偏移
  719. if(k==0)
  720. {
  721. if(i==0)
  722. {
  723. pt10[j]=pt20[j]=pt0[0]+segparm*miterdir[0];
  724. pt11[j]=pt21[j]=pt0[1]+segparm*miterdir[1];
  725. pt12[j]=pt22[j]=pt0[2]+segparm*miterdir[2];
  726. }
  727. else
  728. {//生成线段
  729. ptemp[0]=pt0[0]+segparm*miterdir[0];
  730. ptemp[1]=pt0[1]+segparm*miterdir[1];
  731. ptemp[2]=pt0[2]+segparm*miterdir[2];
  732. m_pConverter->ConverterEntiey_KmLine(pt20[j],pt21[j],pt22[j],ptemp[0],ptemp[1],ptemp[2]);
  733. pt20[j]=ptemp[0];
  734. pt21[j]=ptemp[1];
  735. pt22[j]=ptemp[2];
  736. }
  737. }
  738. }
  739. adReadBlobShort(bcptr,&numareafillparms);
  740. for (k=0; k<numareafillparms; k++) 
  741. {
  742. adReadBlobDouble(bcptr,&areafillparm);//无需转换
  743. }
  744. //处理连接弧
  745. }
  746. if( (match->m_startline&&(i==0))||
  747. (match->m_endline&&(i==(aden->mline.numverts-1)))||
  748. (match->m_showmiter&&((i!=0)||(i!=(aden->mline.numverts-1)))))
  749. {//会自动排序
  750. m_pConverter->WriteEnthead(match->segcolor[0],match->segltyle[0]);
  751. m_pConverter->ConverterEntiey_KmLine(pt20[0],pt21[0],pt22[0],pt0[0],pt0[1],pt0[2]);
  752. m_pConverter->WriteEnthead(match->segcolor[aden->mline.linesinstyle-1],match->segltyle[aden->mline.linesinstyle-1]);
  753. 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]);
  754. }
  755. if(i==(aden->mline.numverts-1))
  756. {//结束
  757. if(aden->mline.openclosed&AD_MLINE_CLOSED)
  758. {
  759. for(j=0;j<aden->mline.linesinstyle;j++)
  760. {
  761. m_pConverter->WriteEnthead(match->segcolor[j],match->segltyle[j]);
  762. m_pConverter->ConverterEntiey_KmLine(pt10[j],pt11[j],pt12[j],pt20[j],pt21[j],pt22[j]);
  763. }
  764. }
  765. }
  766.     }
  767.     adEndBlobRead(bcptr);
  768. pt10.RemoveAll();
  769. pt11.RemoveAll();
  770. pt12.RemoveAll();
  771. pt20.RemoveAll();
  772. pt21.RemoveAll();
  773. pt22.RemoveAll();
  774. _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]));
  775. return TRUE;
  776. }
  777. //DEL BOOL CDwgReader::processentity_shape(AD_DB_HANDLE dwghandle)
  778. //DEL {
  779. //DEL  //形所在的形文件句柄,形在的形文件所有形中的序号
  780. //DEL  //形的基点,缩放,倾斜,旋转,宽高比
  781. //DEL  m_ashape.processentity(m_pConverter,aden->shape.shapefileobjhandle,aden->shape.whichshape,
  782. //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);
  783. //DEL  return TRUE;
  784. //DEL }
  785. BOOL CDwgReader::processentity_solid(AD_DB_HANDLE dwghandle)
  786. {
  787. //对于等腰三角形可以转换为东方箭头
  788. if( m_pConverter->ConverterEntiey_KmArrowHead(
  789. aden->solid.pt0[0],aden->solid.pt0[1],
  790. aden->solid.pt1[0],aden->solid.pt1[1],
  791. aden->solid.pt2[0],aden->solid.pt2[1],
  792. aden->solid.pt3[0],aden->solid.pt3[1]) )
  793. {
  794. return TRUE;
  795. }
  796. //1 2
  797. int index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt0[0],aden->solid.pt0[1],aden->solid.pt0[2],
  798. aden->solid.pt1[0],aden->solid.pt1[1],aden->solid.pt1[2]).dwEntIndex;
  799. _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));
  800. //1 3
  801. index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt0[0],aden->solid.pt0[1],aden->solid.pt0[2],
  802. aden->solid.pt2[0],aden->solid.pt2[1],aden->solid.pt2[2]).dwEntIndex;
  803. _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));
  804. //3 4 如果用户按ENTER生成三角形面域则不生成该直线
  805. 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]))
  806. {
  807. index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt2[0],aden->solid.pt2[1],aden->solid.pt2[2],
  808. aden->solid.pt3[0],aden->solid.pt3[1],aden->solid.pt3[2]).dwEntIndex;
  809. _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));
  810. }
  811. //2 4
  812. index=m_pConverter->ConverterEntiey_KmLine(aden->solid.pt1[0],aden->solid.pt1[1],aden->solid.pt1[2],
  813. aden->solid.pt3[0],aden->solid.pt3[1],aden->solid.pt3[2]).dwEntIndex;
  814. _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));
  815. return TRUE;
  816. }
  817. BOOL CDwgReader::processentity_acis(AD_DB_HANDLE dwghandle)
  818. {
  819. //acis数据较为复杂,应当启动acis程序分析出投影数据来.
  820. if(aden->acisobj.ldblob!=AD_VMNULL)
  821. {
  822. PAD_BLOB_CTRL bcptr;
  823. char str[520];
  824. bcptr=adStartBlobRead(aden->acisobj.ldblob);
  825. while(adReadAcisString(bcptr,str)) 
  826. {//分析acis数据
  827. }
  828. adEndBlobRead(bcptr);
  829. }
  830. return TRUE;
  831. }
  832. BOOL CDwgReader::processentity_trace(AD_DB_HANDLE dwghandle)
  833. {
  834. //对于等腰三角形可以转换为东方箭头
  835. if( m_pConverter->ConverterEntiey_KmArrowHead(
  836. aden->trace.pt0[0],aden->trace.pt0[1],
  837. aden->trace.pt1[0],aden->trace.pt1[1],
  838. aden->trace.pt2[0],aden->trace.pt2[1],
  839. aden->trace.pt3[0],aden->trace.pt3[1]) )
  840. {
  841. return TRUE;
  842. }
  843. //1 2
  844. int index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt0[0],aden->trace.pt0[1],aden->trace.pt0[2],
  845. aden->trace.pt1[0],aden->trace.pt1[1],aden->trace.pt1[2]).dwEntIndex;
  846. _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));
  847. //1 3
  848. index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt0[0],aden->trace.pt0[1],aden->trace.pt0[2],
  849. aden->trace.pt2[0],aden->trace.pt2[1],aden->trace.pt2[2]).dwEntIndex;
  850. _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));
  851. //3 4
  852. index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt2[0],aden->trace.pt2[1],aden->trace.pt2[2],
  853. aden->trace.pt3[0],aden->trace.pt3[1],aden->trace.pt3[2]).dwEntIndex;
  854. _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));
  855. //2 4
  856. index=m_pConverter->ConverterEntiey_KmLine(aden->trace.pt3[0],aden->trace.pt3[1],aden->trace.pt3[2],
  857. aden->trace.pt1[0],aden->trace.pt1[1],aden->trace.pt1[2]).dwEntIndex;
  858. _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));
  859. return TRUE;
  860. }
  861. /*
  862. 函数说明:
  863. 功能:转换视口。
  864. */
  865. BOOL CDwgReader::processentity_viewport(AD_DB_HANDLE dwghandle)
  866. {
  867. ASSERT(adenhd);
  868. ASSERT(aden);
  869. if(aden->vpent.statusflags&AD_VPENT_STATUS_OFF)
  870. {
  871. return TRUE;
  872. }
  873.   if(aden->vpent.purgedflag==1)
  874. {
  875. return TRUE;
  876. }
  877. if(aden->vpent.viewheight==0)
  878. {
  879. return TRUE;
  880. }
  881. double cx=aden->vpent.cen[0];
  882. double cy=aden->vpent.cen[1];
  883. double w=aden->vpent.width*0.5;
  884. double h=aden->vpent.height*0.5;
  885. double minx=cx-w;
  886. double miny=cy-h;
  887. double maxx=cx+w;
  888. double maxy=cy+h;
  889. DWORD dwKmId;
  890. if(m_pConverter->GetDataVessel(dwKmId)==DATAVESSEL_DATABASE)
  891. {
  892. CString strName;
  893. CString strDes;
  894. strName="*ViewPort";
  895. strName+=aden->vpent.name;
  896. strDes="转换至视口";
  897. strDes+=aden->vpent.name;
  898. UINT id=m_pConverter->ConverterEnthead_Blockdefine(strName,strDes);
  899. BOOL bsucc=m_pConverter->SetDataVessel(DATAVESSEL_BLOCKDEF,id);
  900. m_pConverter->WriteEnthead(RGB(0,0,0),SOLID_LINE);//设置视口边的转化属性。
  901. int index=m_pConverter->ConverterEntiey_KmLine(minx,miny,0,minx,maxy,0).dwEntIndex;
  902. _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));
  903. index=m_pConverter->ConverterEntiey_KmLine(minx,maxy,0,maxx,maxy,0).dwEntIndex;
  904. _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));
  905. index=m_pConverter->ConverterEntiey_KmLine(maxx,maxy,0,maxx,miny,0).dwEntIndex;
  906. _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));
  907. index=m_pConverter->ConverterEntiey_KmLine(maxx,miny,0,minx,miny,0).dwEntIndex;
  908. _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));
  909. if(!m_pConverter->ConverterEntiey_KmBlockdef(cx,cy,0))
  910. {
  911. _WRITE(str="error in conv blockdef");
  912. }
  913. if(!m_pConverter->SetDataVessel(DATAVESSEL_DATABASE))
  914. {
  915. _WRITE(str="error in set datavessel");
  916. }
  917. m_pConverter->ConverterEntiey_KmBlockref(cx,cy,0,1,1,1,0,id,FALSE);
  918. }
  919. else
  920. {
  921. m_pConverter->WriteEnthead(RGB(0,0,0),SOLID_LINE);//设置视口边的转化属性。
  922. int index=m_pConverter->ConverterEntiey_KmLine(minx,miny,0,minx,maxy,0).dwEntIndex;
  923. _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));
  924. index=m_pConverter->ConverterEntiey_KmLine(minx,maxy,0,maxx,maxy,0).dwEntIndex;
  925. _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));
  926. index=m_pConverter->ConverterEntiey_KmLine(maxx,maxy,0,maxx,miny,0).dwEntIndex;
  927. _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));
  928. index=m_pConverter->ConverterEntiey_KmLine(maxx,miny,0,minx,miny,0).dwEntIndex;
  929. _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));
  930. }
  931. double s=aden->vpent.height / aden->vpent.viewheight;
  932. 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);
  933. return TRUE;
  934. }
  935. //说明  AutoCAD的字高完全为英文定制  
  936. // 规则1:  字高的数值=标准英文字母(不含个别出头的字母)字高
  937. // 规则2: 汉字肯定要上下出头 出头量总共为22.77%  上下分别为11.37% 
  938. // KmCAD的字高为汉字定制
  939. // 规则1: 字高的数值=标准的汉字字高(并略有缩小,忽略不计)
  940. //因此涉及到计算左上角的问题 和涉及到计算字高的问题都应当考虑
  941. BOOL CDwgReader::processentity_text(AD_DB_HANDLE dwghandle)
  942. {
  943. #ifdef _BAOJI_
  944. static double textHeight = 0.0;
  945. static KmPoint ptPos;
  946. static int icount = 0;
  947. static BOOL bFristTime = FALSE;
  948. if (strstr(aden->text.textstr,"黄色")) {
  949. int stop;
  950. stop = 1;
  951. }
  952. if (strstr(aden->text.textstr,"技术要求")) {
  953. icount = 0;
  954. bFristTime = TRUE;
  955. }
  956. if (icount == 1) {
  957. ptPos = KmPoint(aden->text.pt0[0],aden->text.pt0[1]);
  958. textHeight = aden->text.tdata.height;
  959. }
  960. if (m_dwTextcount == 0) {
  961. m_dTotalTxtHeight += aden->text.tdata.height;
  962. m_dwTextcount ++;
  963. }
  964. double averHeight = m_dTotalTxtHeight / (double) m_dwTextcount;
  965. if (aden->text.tdata.height * 4.0 < averHeight) 
  966. {
  967. if (icount < 20) 
  968. {
  969. if (aden->text.tdata.height * 8.0 < textHeight) 
  970. {
  971. if (bFristTime) 
  972. {
  973. aden->text.pt0[0] += 2.0 * textHeight;
  974. bFristTime = FALSE;
  975. }
  976. else
  977. {
  978. aden->text.pt0[0] = ptPos.x;
  979. ptPos.y -= textHeight * 1.2;
  980. aden->text.pt0[1] = ptPos.y;
  981. }
  982. }
  983. aden->text.tdata.height = textHeight;
  984. }
  985. else
  986. {
  987. aden->text.pt0[1] -= averHeight * 0.4;
  988. aden->text.tdata.height = averHeight;
  989. }
  990. }
  991. if (m_dwTextcount != 0) {
  992. m_dTotalTxtHeight += aden->text.tdata.height;
  993. m_dwTextcount ++;
  994. }
  995. icount ++;
  996. #endif
  997. if(aden->text.textstr[0]==0x0){return TRUE;}
  998. if(aden->text.textstr[0]==10){if(aden->text.textstr[1]==0x0){return TRUE;}}
  999. if(aden->text.textstr[0]==32){if(aden->text.textstr[1]==0x0){return TRUE;}}//空格符号
  1000. CShape* shape;
  1001. {
  1002. CMatch5* match=NULL;
  1003. if(!m_ashape.Get(aden->text.tdata.shapefileobjhandle,match))
  1004. {
  1005. _WRITE(str="没有找到文字样式");
  1006. return FALSE;
  1007. }
  1008. shape=match->m_shape;
  1009. }
  1010. //左下角转换为左上角
  1011. 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);
  1012. aden->text.tdata.height=aden->text.tdata.height;//*calculate_findTTFHightRate(shape->m_strShapefilename);
  1013. aden->text.tdata.widthfactor=aden->text.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1014. int index=m_pConverter->ConverterEntiey_KmSText(aden->text.textstr,pRT.x,pRT.y,aden->text.pt0[2],&aden->text.tdata,shape).dwEntIndex;
  1015. _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));
  1016. return TRUE;
  1017. }
  1018. BOOL CDwgReader::processentity_attdef(AD_DB_HANDLE dwghandle)
  1019. {
  1020. //属性定义,只有在非块中的才转换
  1021. DWORD dwKmId;
  1022. switch(m_pConverter->GetDataVessel(dwKmId))
  1023. {
  1024. case DATAVESSEL_BLOCKDEF:
  1025. return TRUE;
  1026. default:
  1027. {
  1028. CShape* shape;
  1029. {
  1030. CMatch5* match;
  1031. if(!m_ashape.Get(aden->attdef.tdata.shapefileobjhandle,match))
  1032. {
  1033. _WRITE(str="无法找到文字样式");
  1034. return FALSE;
  1035. }
  1036. shape=match->m_shape;
  1037. }
  1038. 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);
  1039. aden->attdef.tdata.height=aden->attdef.tdata.height;//*calculate_findTTFHightRate(shape->m_strShapefilename);
  1040. aden->attdef.tdata.widthfactor=aden->attdef.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1041. int index=m_pConverter->ConverterEntiey_KmSText(aden->attdef.tag,pRT.x,pRT.y,aden->attdef.pt0[2],&aden->attdef.tdata,shape).dwEntIndex;
  1042. _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));
  1043. return TRUE;
  1044. }
  1045. break;
  1046. }
  1047. return TRUE;
  1048. }
  1049. BOOL CDwgReader::processentity_attrib(AD_DB_HANDLE dwghandle)
  1050. {
  1051. //#define AD_ATTRIB_INVIS                1 不可见指定在插入块时不显示属性值。ATTDISP 可替代“不可见”模式。
  1052. //#define AD_ATTRIB_CONST                2 固定在插入块时给属性赋固定值。
  1053. //#define AD_ATTRIB_VERIFY               4 验证在插入块时提示验证属性值是否正确。
  1054. //#define AD_ATTRIB_PRESET               8 预置在插入包含预置属性值的块时将属性设为缺省值。
  1055. if(aden->attrib.attflag&AD_ATTRIB_INVIS)
  1056. {
  1057. return FALSE;
  1058. }
  1059. //左下角转换为左上角
  1060. CShape* shape;
  1061. {
  1062. CMatch5* match;
  1063. if(!m_ashape.Get(aden->attrib.tdata.shapefileobjhandle,match))
  1064. {
  1065. _WRITE(str="无法找到文字样式");
  1066. return FALSE;
  1067. }
  1068. shape=match->m_shape;
  1069. }
  1070. 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);
  1071. aden->attrib.tdata.height=aden->attrib.tdata.height;
  1072. aden->attrib.tdata.widthfactor=aden->attrib.tdata.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1073. int index=m_pConverter->ConverterEntiey_KmSText(aden->attrib.attval,pRT.x,pRT.y,aden->attrib.pt0[2],&aden->attrib.tdata,shape).dwEntIndex;
  1074. _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));
  1075. return TRUE;
  1076. }
  1077. BOOL CDwgReader::processentity_polyline(AD_DB_HANDLE dwghandle,AD_VMADDR list)
  1078. {
  1079. if(adenhd->enttype!=AD_ENT_POLYLINE)
  1080. {
  1081. _WRITE(str="输入的实体不是多段线,无法处理");
  1082. return FALSE;
  1083. }
  1084. if(!processentity_enthead(dwghandle))
  1085. {
  1086. return FALSE;
  1087. }
  1088. unsigned short ployflag=aden->pline.polyflag;
  1089. CArray<CVector*,CVector*>avectors;
  1090. short res;
  1091. int dSplinevertextype=0;//AD_VERTEX_SPLINEVERTEX or AD_VERTEX_SPLINEFRAME
  1092. CVector*      pvector=NULL;
  1093. do
  1094. {
  1095. res = adGetEntity(list,adenhd,aden);
  1096. if(res && adenhd->enttype==AD_ENT_VERTEX)
  1097. {
  1098. pvector=new CVector;
  1099. pvector->m_x=aden->vertex.pt0[0];
  1100. pvector->m_y=aden->vertex.pt0[1];
  1101. pvector->m_z=aden->vertex.pt0[2];
  1102. pvector->m_bulge=aden->vertex.bulge;
  1103. if(ployflag&AD_PLINE_SPLINEFIT)
  1104. {
  1105. if(dSplinevertextype==0)
  1106. {
  1107. if(aden->vertex.vertexflag&AD_VERTEX_SPLINEFRAME)
  1108. {
  1109. dSplinevertextype=1;
  1110. avectors.Add(pvector);
  1111. }
  1112. else if(aden->vertex.vertexflag&AD_VERTEX_SPLINEVERTEX)
  1113. {
  1114. dSplinevertextype=2;
  1115. avectors.Add(pvector);
  1116. }
  1117. else
  1118. {
  1119. delete pvector;
  1120. }
  1121. }
  1122. else if((dSplinevertextype==1)&&(aden->vertex.vertexflag&AD_VERTEX_SPLINEFRAME))
  1123. {
  1124. avectors.Add(pvector);
  1125. }
  1126. else if((dSplinevertextype==2)&&(aden->vertex.vertexflag&AD_VERTEX_SPLINEVERTEX))
  1127. {
  1128. avectors.Add(pvector);
  1129. }
  1130. else
  1131. {
  1132. delete pvector;
  1133. }
  1134. }
  1135. else
  1136. {
  1137. avectors.Add(pvector);
  1138. }
  1139. }
  1140. }
  1141. while(res && adenhd->enttype==AD_ENT_VERTEX );
  1142. if((!res)||(adenhd->enttype!=AD_ENT_SEQEND)||(avectors.GetSize()<=1))//理论上res应当不为零,块的实体链表必须由AD_ENT_ENDBLK实体结束
  1143. {
  1144. _WRITE(str="无法找到块结束或多段线结束标记");
  1145. for(int i=0;i<avectors.GetSize();i++)
  1146. {
  1147. delete avectors[i];
  1148. }
  1149. avectors.RemoveAll();
  1150. return FALSE;
  1151. }
  1152. //ref:
  1153. //#define AD_PLINE_CLOSED                1
  1154. //#define AD_PLINE_SPLINEFIT             4
  1155. if(ployflag&AD_PLINE_CLOSED)
  1156. {
  1157. pvector=new CVector;
  1158. pvector->m_x=avectors[0]->m_x;
  1159. pvector->m_y=avectors[0]->m_y;
  1160. pvector->m_z=avectors[0]->m_z;
  1161. pvector->m_bulge=avectors[0]->m_bulge;
  1162. avectors.Add(pvector);
  1163. }
  1164. if(ployflag&AD_PLINE_SPLINEFIT)
  1165. {
  1166. KmSpLine* pspline=new KmSpLine;
  1167. pspline->m_iType=T_BPLINE;
  1168. pspline->m_nNodeNum=avectors.GetSize();
  1169. for(int i=0;i<avectors.GetSize();i++)
  1170. {
  1171. pspline->m_aNode.Add(KmPoint(avectors[i]->m_x,avectors[i]->m_y));
  1172. }
  1173. m_pConverter->ConverterEntiey_KmObject(pspline);
  1174. }
  1175. else
  1176. {
  1177. calculate_3dbulgelines(avectors);
  1178. }
  1179. for(int i=0;i<avectors.GetSize();i++)
  1180. {
  1181. delete avectors[i];
  1182. }
  1183. avectors.RemoveAll();
  1184. return TRUE;
  1185. }
  1186. BOOL CDwgReader::processentity_lwpline(AD_DB_HANDLE dwghandle)
  1187. {
  1188. double pt[3];pt[2]=0.0;
  1189. CArray<CVector*,CVector*>avectors;
  1190. CVector* pvector;
  1191. //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
  1192. PAD_BLOB_CTRL bcptr;
  1193. bcptr=adStartBlobRead(aden->lwpline.ldblob);
  1194. for(int i=0;i<aden->lwpline.numpoints;i++)
  1195. {
  1196. pvector=new CVector;
  1197. //short adReadBlob2Double (PAD_BLOB_CTRL bcptr,double *doub);
  1198. sReturnValue=adReadBlob2Double(bcptr,pt);
  1199. if(sReturnValue!=1)
  1200. {
  1201. _ERROR;
  1202. }
  1203. pvector->m_x=pt[0];
  1204. pvector->m_y=pt[1];
  1205. pvector->m_z=pt[2];
  1206. if(aden->lwpline.flag&AD_LWPLINE_HAS_BULGES)
  1207. {
  1208. //short adReadBlobDouble (PAD_BLOB_CTRL bcptr,double *doub);
  1209. sReturnValue=adReadBlobDouble(bcptr,pt);
  1210. if(sReturnValue!=1)
  1211. {
  1212. _ERROR;
  1213. }
  1214. pvector->m_bulge=pt[0];
  1215. }
  1216. else
  1217. {
  1218. pvector->m_bulge=0;
  1219. }
  1220. if(aden->lwpline.flag & AD_LWPLINE_HAS_WIDTHS)
  1221. {
  1222. //short adReadBlob2Double (PAD_BLOB_CTRL bcptr,double *doub);
  1223. sReturnValue=adReadBlob2Double(bcptr,pt);
  1224. if(sReturnValue!=1)
  1225. {
  1226. _ERROR;
  1227. }
  1228. else
  1229. {
  1230. if(pt[0]>1.0e-6||pt[1]>1.0e-6)
  1231. {
  1232. pvector->m_bwidth=TRUE;
  1233. pvector->m_widthbegin=pt[0];
  1234. pvector->m_widthend=pt[1];
  1235. }
  1236. }
  1237. }
  1238. avectors.Add(pvector);
  1239. }
  1240. //short adEndBlobRead (PAD_BLOB_CTRL bcptr);
  1241. sReturnValue=adEndBlobRead(bcptr);
  1242. if(sReturnValue!=1)
  1243. {
  1244. _ERROR;
  1245. }
  1246. if(aden->lwpline.flag & AD_LWPLINE_IS_CLOSED)
  1247. {
  1248. pvector=new CVector;
  1249. pvector->m_x=avectors[0]->m_x;
  1250. pvector->m_y=avectors[0]->m_y;
  1251. pvector->m_z=avectors[0]->m_z;
  1252. pvector->m_bulge=avectors[0]->m_bulge;
  1253. avectors.Add(pvector);
  1254. }
  1255. calculate_3dbulgelines(avectors);
  1256. for(i=0;i<avectors.GetSize();i++)
  1257. {
  1258. delete avectors[i];
  1259. }
  1260. avectors.RemoveAll();
  1261. return TRUE;
  1262. }
  1263. BOOL CDwgReader::processentity_mtext(AD_DB_HANDLE dwghandle)
  1264. {
  1265. //转换文字第1步-得到文字样式.
  1266. CShape* shape;
  1267. {
  1268. CMatch5* match;
  1269. if(!m_ashape.Get(aden->mtext.shapefileobjhandle,match))
  1270. {
  1271. _WRITE(str="无法找到文字样式");
  1272. return FALSE;
  1273. }
  1274. shape=match->m_shape;
  1275. }
  1276. //转换文字第2步-得到文字的内容.
  1277. CString strEnter;
  1278. {
  1279. if (aden->mtext.ldblob==AD_VMNULL)
  1280. {
  1281. if(aden->mtext.textstr[0]==0)
  1282. {
  1283. return TRUE;
  1284. }
  1285. if(aden->mtext.textstr[0]==10)
  1286. {
  1287. if(aden->mtext.textstr[1]==0x0)//回车符号
  1288. {
  1289. return TRUE;
  1290. }
  1291. }
  1292. if(aden->mtext.textstr[0]==32)
  1293. {
  1294. if(aden->mtext.textstr[1]==0x0)//空格符号
  1295. {
  1296. return TRUE;
  1297. }
  1298. }
  1299. strEnter=aden->mtext.textstr;
  1300. }
  1301. else
  1302. {
  1303. char textstr[257];
  1304. PAD_BLOB_CTRL bcptr;
  1305. //PAD_BLOB_CTRL adStartBlobRead (AD_VMADDR blob);
  1306. bcptr=adStartBlobRead(aden->mtext.ldblob);
  1307. //short adReadMtextBlock (PAD_BLOB_CTRL bcptr, char *str);
  1308. while(adReadMtextBlock(bcptr,textstr))
  1309. {
  1310. for(int i=0;i<256;i++)
  1311. {
  1312. if(textstr[i]==0)
  1313. {
  1314. break;
  1315. }
  1316. strEnter+=textstr[i];
  1317. }
  1318. }
  1319. //short adEndBlobRead (PAD_BLOB_CTRL bcptr);
  1320. if(adEndBlobRead(bcptr)!=1)
  1321. {
  1322. _ERROR;
  1323. }
  1324. }
  1325. if(strEnter.GetLength()<=0)
  1326. {
  1327. return TRUE;
  1328. }
  1329. if(strEnter.GetLength()==1)
  1330. {
  1331. if(strEnter[0]==10)
  1332. {
  1333. return TRUE;
  1334. }
  1335. if(strEnter[0]==32)
  1336. {
  1337. return TRUE;
  1338. }
  1339. }
  1340. }
  1341. //转换文字第3步-得到角度,高度,宽度.   (一个旋转的矩形A)
  1342. double angle;
  1343. double Height;
  1344. double Width;
  1345. {
  1346. angle=calculate_2dangle(aden->mtext.xdir[0],aden->mtext.xdir[1]);
  1347. Height = 0.0;
  1348. Width  = 0.0;//文字边框宽,高
  1349. if((aden->mtext.boxht <= 0) || (aden->mtext.boxwid <= 0))
  1350. {
  1351. DOUBRECTFULL rect;
  1352. rect.pt0[0]=0.0;
  1353. rect.pt0[1]=0.0;
  1354. rect.pt1[0]=0.0;
  1355. rect.pt1[1]=0.0;
  1356. double bottomy;
  1357. AD_TDATA tdata;
  1358. AD_SHPTB shp;
  1359. sReturnValue=adSeekShapefile(dwghandle,aden->mtext.shapefileobjhandle, &shp);
  1360. if(sReturnValue!=1)
  1361. {
  1362. _ERROR;
  1363. return FALSE;
  1364. }
  1365. if(shp.bigfontname[0]==0&&shp.file[0]==0 
  1366.    &&shp.name[0]==0)
  1367. {
  1368. _ERROR;
  1369. return FALSE;
  1370. }
  1371. tdata.height = aden->mtext.ht;
  1372. tdata.widthfactor = shape->m_dShapeWidth;
  1373. tdata.oblique = shape->m_dShapeAngle*PI/180;
  1374. tdata.rotang = angle;
  1375. if(aden->mtext.boxht <= 0)
  1376. {
  1377. int num=1;
  1378. for(int k=0;k<strEnter.GetLength();k++)
  1379. {
  1380. if(strEnter[k]=='\n')
  1381. {
  1382. num++;
  1383. }
  1384. }
  1385. Height=aden->mtext.ht*num;
  1386. }
  1387. else
  1388. {
  1389. Height=aden->mtext.boxht;
  1390. }
  1391. if(aden->mtext.boxwid<= 0)
  1392. {
  1393. try //说明 该OpenDWG函数不稳定,有可能死在该函数内部.
  1394. {
  1395. 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);
  1396. if(sReturnValue!=1)
  1397. {//位置1
  1398. sReturnValue=adTextBoundingBox(dwghandle,(unsigned char*)aden->mtext.textstr,&tdata,0,NULL,NULL,1,&rect,&bottomy);
  1399. if(sReturnValue!=1)
  1400. {//实在无法计算出宽度则自己计算宽度。
  1401. Width=calculate_findstringlength(strEnter)*aden->mtext.ht*shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1402. }
  1403. else
  1404. {
  1405. Width=rect.pt1[0] - rect.pt0[0];
  1406. }
  1407. }
  1408. else
  1409. {//位置2
  1410. Width=rect.pt1[0] - rect.pt0[0];
  1411. }
  1412. }
  1413. catch(...)
  1414. {
  1415. if(0 == aden->mtext.ht)
  1416. return FALSE;
  1417. else//added by hq,2003.4.28
  1418. {//位置3
  1419. //adTextBoundingBox使用不当造成的逻辑异常,
  1420. //为了不对其他部分造成影响,增加else判断:
  1421. Width=calculate_findstringlength(strEnter)*aden->mtext.ht*shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1422. }
  1423. }
  1424. }
  1425. else
  1426. {
  1427. Width = aden->mtext.boxwid;
  1428. }
  1429. }
  1430. else
  1431. {//位置4
  1432. Height = aden->mtext.boxht;
  1433. Width = aden->mtext.boxwid;
  1434. }
  1435. }
  1436. //转换文字第4步-得到左上角坐标    (一个旋转的矩形B)
  1437. KmPoint pRT;
  1438. pRT.x=aden->mtext.pt0[0];
  1439. pRT.y=aden->mtext.pt0[1];
  1440. switch( aden->mtext.attachpt)
  1441. {
  1442. case AD_MTEXT_ATTACH_TOPLEFT://左上
  1443. break;
  1444. case AD_MTEXT_ATTACH_TOPCENTER://中上 -> 左上 x-0.5W 
  1445. pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,0,angle);
  1446. break;
  1447. case AD_MTEXT_ATTACH_TOPRIGHT:
  1448. pRT=calculate_2drotate(pRT.x,pRT.y,-Width,0,angle);
  1449. break;
  1450. case AD_MTEXT_ATTACH_MIDDLELEFT:
  1451. pRT=calculate_2drotate(pRT.x,pRT.y,0,Height*0.5,angle);
  1452. break;
  1453. case AD_MTEXT_ATTACH_MIDDLECENTER:
  1454. pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,Height*0.5,angle);
  1455. break;
  1456. case AD_MTEXT_ATTACH_MIDDLERIGHT:
  1457. pRT=calculate_2drotate(pRT.x,pRT.y,-Width,Height*0.5,angle);
  1458. break;
  1459. case AD_MTEXT_ATTACH_BOTTOMLEFT:
  1460. pRT=calculate_2drotate(pRT.x,pRT.y,0,Height,angle);
  1461. break;
  1462. case AD_MTEXT_ATTACH_BOTTOMCENTER:
  1463. pRT=calculate_2drotate(pRT.x,pRT.y,-Width*0.5,Height,angle);
  1464. break;
  1465. case AD_MTEXT_ATTACH_BOTTOMRIGHT:
  1466. pRT=calculate_2drotate(pRT.x,pRT.y,-Width,Height,angle);
  1467. break;
  1468. default:
  1469. break;
  1470. }
  1471. //#ifdef _DEBUG
  1472. // {
  1473. // KmPoint p1=pRT;
  1474. // KmPoint p2=calculate_2drotate(pRT.x,pRT.y,Width,0,angle);
  1475. // KmPoint p3=calculate_2drotate(pRT.x,pRT.y,Width,-Height,angle);
  1476. // KmPoint p4=calculate_2drotate(pRT.x,pRT.y,0,-Height,angle);
  1477. //
  1478. // m_pConverter->ConverterEntiey_KmLine(p1.x,p1.y,0.0,p2.x,p2.y,0.0);
  1479. // m_pConverter->ConverterEntiey_KmLine(p2.x,p2.y,0.0,p3.x,p3.y,0.0);
  1480. // m_pConverter->ConverterEntiey_KmLine(p3.x,p3.y,0.0,p4.x,p4.y,0.0);
  1481. // m_pConverter->ConverterEntiey_KmLine(p4.x,p4.y,0.0,p1.x,p1.y,0.0);
  1482. // }
  1483. //#endif
  1484. //WAIT TO DO double dtexthight=aden->mtext.ht*(1+2*m_dtextposmodify);
  1485. double dtexthight=aden->mtext.ht;
  1486. //检查是否有中文字符,如有则加大字高
  1487. // for(int m=0;m<strEnter.GetLength();m++)
  1488. /// {
  1489. // if((unsigned char)strEnter[m]>0x7f)
  1490. // {
  1491. // dtexthight*=1.2423;//1.311;
  1492. // break;
  1493. // }
  1494. // }
  1495. //针对KmCAD校正左上角坐标pRT=calculate_2drotate(pRT.x,pRT.y,0,aden->mtext.ht*(m_dtextposmodify),angle);
  1496. #ifdef _DEBUG
  1497. if(pRT.x>1000000)
  1498. {
  1499. _WRITE(str="错误的文字");
  1500. }
  1501. if(pRT.x<-1000000)
  1502. {
  1503. _WRITE(str="错误的文字");
  1504. }
  1505. if(pRT.y>1000000)
  1506. {
  1507. _WRITE(str="错误的文字");
  1508. }
  1509. if(pRT.y<-1000000)
  1510. {
  1511. _WRITE(str="错误的文字");
  1512. }
  1513. #endif
  1514. double spacehight=aden->mtext.linespacingfactor*(m_dlinespacemodify*aden->mtext.ht);//行距约等于高度的一半
  1515. double widthhight=shape->m_dShapeWidth*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1516. 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;
  1517. _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));
  1518. return TRUE;
  1519. }
  1520. BOOL CDwgReader::processentity_leader(AD_DB_HANDLE dwghandle)
  1521. {
  1522. //引出转换为东方的单项标注
  1523. PAD_BLOB_CTRL bcptr=adStartBlobRead(aden->leader.ldblob);
  1524. if( (short)aden->leader.numpoints<2 )
  1525. {
  1526. return FALSE;
  1527. }
  1528. int i;
  1529. double pt0[3];
  1530. KmDXBZ* pDXBZ=new KmDXBZ;
  1531. CArray<KmPoint,KmPoint>pts;
  1532. for (i=0; i<(short)aden->leader.numpoints; i++)
  1533. {
  1534. adReadBlob3Double(bcptr,pt0);
  1535. pts.Add(KmPoint(pt0[0],pt0[1]));
  1536. //<<added by hq,2003.4.29
  1537. if(2 == aden->leader.numpoints && 1 == i)
  1538. {
  1539. if(1 == aden->leader.hashookline)
  1540. {
  1541. if(1 == aden->leader.hooklineonxdir)
  1542. pts.Add(KmPoint((pt0[0]-aden->leader.annowid),pt0[1]));
  1543. else
  1544. pts.Add(KmPoint((pt0[0]+aden->leader.annowid),pt0[1]));
  1545. }
  1546. }
  1547. //>>
  1548. }
  1549. adEndBlobRead(bcptr);
  1550. for(i=pts.GetSize();i>0;i--)
  1551. {
  1552. pDXBZ->m_aPts.Add(pts[i-1]);
  1553. }
  1554. if(aden->leader.arrowheadon)
  1555. {
  1556. pDXBZ->m_uType=1;
  1557. //extern  short  ADCDECL adSeekDimstyle _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_DIMSTYLE addimst));
  1558. AD_DIMSTYLE dimstyle;
  1559. if(adSeekDimstyle(dwghandle,aden->leader.dimstyleobjhandle,&dimstyle)==1)
  1560. {
  1561. pDXBZ->m_dArrowSize=dimstyle.dimasz;
  1562. }
  1563. }
  1564. else
  1565. {
  1566. pDXBZ->m_uType=0;
  1567. }
  1568. m_pConverter->ConverterEntiey_KmObject(pDXBZ);
  1569. /* int i;
  1570. KmPoint pB;
  1571. KmPoint pE;
  1572. double pt0[3];
  1573. KmPoint pTempPoint;
  1574. KmPoint pArrowPoint;
  1575. double dArrowAngle;
  1576. PAD_BLOB_CTRL bcptr=adStartBlobRead(aden->leader.ldblob);
  1577. if( (short)aden->leader.numpoints<2 )
  1578. {
  1579. return FALSE;
  1580. }
  1581. adReadBlob3Double(bcptr,pt0);
  1582. pTempPoint.x=pt0[0];
  1583. pTempPoint.y=pt0[1];
  1584. pArrowPoint=pTempPoint;
  1585. for (i=1; i<(short)aden->leader.numpoints; i++)
  1586. {
  1587. adReadBlob3Double(bcptr,pt0);
  1588. // 可以处理pt0
  1589. if(i==1)
  1590. {
  1591. dArrowAngle=atan2(pt0[1]-pTempPoint.y,pt0[0]-pTempPoint.x);
  1592. }
  1593. //从pTempPoint到pt0[i],pt0[i];
  1594. pB=pTempPoint;
  1595. pE.x=pt0[0];
  1596. pE.y=pt0[1];
  1597. m_pConverter->ConverterEntiey_KmLine(pB.x,pB.y,0.0,pE.x,pE.y,pt0[2]);
  1598. pTempPoint.x=pt0[0];
  1599. pTempPoint.y=pt0[1];
  1600. }
  1601. adEndBlobRead(bcptr);
  1602. if(aden->leader.arrowheadon)//引出有箭头
  1603. {
  1604. //pArrowPoint 箭头顶点
  1605. //dArrowAngle 箭头角度
  1606. if(adenhd->xdblob != AD_VMNULL)//尺寸有扩展数据
  1607. {
  1608. int tag=0;
  1609. AD_XD adxd;
  1610. PAD_BLOB_CTRL bcptr2;
  1611. bcptr2 = adStartBlobRead(adenhd->xdblob);
  1612. while(adReadExtendeddata(bcptr2,&adxd))
  1613. {
  1614. //连续读入四个1070组,来得到它们的尺寸类型信息
  1615. //且顺序为1070,7,1070,style,1070,6,1070, style
  1616. //当不是这个顺序时,tag赋零,
  1617. if (adxd.xddxfnumber == 1070  || (adxd.xddxfnumber == 1000 && (tag==1||tag==3) ) )
  1618. {
  1619. tag++;                   
  1620. }
  1621. else
  1622. {
  1623. tag=0;
  1624. }
  1625. switch(tag)
  1626. {
  1627. case 1:
  1628. if(adxd.xddata.xdint != 7)
  1629. {
  1630. tag = 0;
  1631. }
  1632. break;
  1633. case 2:  //第一个箭头
  1634. break;
  1635. case 3:
  1636. if(adxd.xddata.xdint != 6)
  1637. {
  1638. tag = 0;
  1639. }
  1640. break;
  1641. case 4:  //第2个箭头
  1642. if(strcmp((char*)adxd.xddata.xdbindata, "_DOT") == 0)  //点
  1643. {
  1644. //生成圆 (-x y) distx/3500
  1645. pB.x=-pArrowPoint.x;
  1646. pB.y=pArrowPoint.y;
  1647. m_pConverter->ConverterEntiey_KmCircle(pB.x,pB.y,0.0,m_dpointtocircleradius);
  1648. break;
  1649. }
  1650. else //其余的转成箭头
  1651. {
  1652. //生成箭头 (x y) (3cos(a)+x 3sin(a)+y (0 1) ) 
  1653. pB.x=3*cos(dArrowAngle)+pArrowPoint.x;
  1654. pB.y=3*sin(dArrowAngle)+pArrowPoint.y;
  1655. pE=pArrowPoint;
  1656. m_pConverter->ConverterEntiey_KmArrow(pB.x,pB.y,0.0,pE.x,pE.y,0.0,1);
  1657. }
  1658. tag = 0;
  1659. break;
  1660. }
  1661. }
  1662. adEndBlobRead(bcptr2);
  1663. }
  1664. else
  1665. adStartDimstyleGet (dwghandle);
  1666. AD_DIMSTYLE DimStyle;
  1667. for(i=0; i<adNumDimstyles(dwghandle); i++)
  1668. {
  1669. adGetDimstyle(dwghandle,&DimStyle);//得到尺寸风格
  1670. if(!memcmp((char*)DimStyle.objhandle, (char*)aden->leader.dimstyleobjhandle, 8))
  1671. {
  1672. if(!strcmp((char*)DimStyle.dimblk2objhandle, "_DOT"))//点箭头
  1673. {
  1674. //生成圆 (x y) distx/3500
  1675. pB.x=-pArrowPoint.x;
  1676. pB.y=pArrowPoint.y;
  1677. m_pConverter->ConverterEntiey_KmCircle(pB.x,pB.y,0.0,m_dpointtocircleradius);
  1678. break;
  1679. }
  1680. else //其余的转成三角型箭头
  1681. {
  1682. //生成箭头 (x y) (3cos(a)+x 3sin(a)+y (0 1) ) 
  1683. pB.x=3*cos(dArrowAngle)+pArrowPoint.x;
  1684. pB.y=3*sin(dArrowAngle)+pArrowPoint.y;
  1685. pE=pArrowPoint;
  1686. m_pConverter->ConverterEntiey_KmArrow(pB.x,pB.y,0.0,pE.x,pE.y,0.0,1);
  1687. break;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. _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]));*/
  1694. return TRUE;
  1695. }
  1696. BOOL CDwgReader::processentity_tolerance(AD_DB_HANDLE dwghandle)
  1697. {
  1698. CShape* shape;
  1699. {
  1700. AD_DIMSTYLE dimstyle;
  1701. //extern  short  ADCDECL adSeekDimstyle _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_DIMSTYLE addimst));
  1702. if(adSeekDimstyle(dwghandle,aden->tolerance.dimstyleobjhandle,&dimstyle)!=1)
  1703. {
  1704. _ERROR;
  1705. return FALSE;
  1706. }
  1707. CMatch5* match;
  1708. if(!m_ashape.Get(dimstyle.shapefileobjhandle,match))
  1709. {
  1710. _WRITE(str="无法找到文字样式");
  1711. return FALSE;
  1712. }
  1713. shape=match->m_shape;
  1714. }
  1715. double texthight;
  1716. if(fabs(aden->tolerance.textht)<0.0000001)
  1717. {
  1718. texthight=-1;
  1719. if(adenhd->xdblob!=AD_VMNULL)
  1720. {
  1721. {
  1722. BOOL bControlStart=FALSE;
  1723. BOOL bControlCode=FALSE;
  1724. int  dControlCode=0;
  1725. PAD_BLOB_CTRL bcptr;
  1726. bcptr=adStartBlobRead(adenhd->xdblob);
  1727. while(adReadExtendeddata(bcptr,adxd)) 
  1728. {
  1729. if (adxd->xddxfnumber==1040) //adxd->xddata.xdreal
  1730. {
  1731. if(bControlStart==TRUE)
  1732. {
  1733. if(bControlCode)
  1734. {
  1735. processentity_tol_blob(dControlCode,adxd->xddxfnumber,texthight);
  1736. bControlCode=FALSE;
  1737. }
  1738. else
  1739. {
  1740. TRACE("错误的blob数据");
  1741. }
  1742. }
  1743. //else 忽略
  1744. }
  1745. else if (adxd->xddxfnumber==1070) //adxd->xddata.xdint
  1746. {
  1747. if(bControlStart==TRUE)
  1748. {
  1749. if(!bControlCode)
  1750. {
  1751. dControlCode=adxd->xddata.xdint;
  1752. bControlCode=TRUE;
  1753. }
  1754. }
  1755. //else 忽略
  1756. }
  1757. else if (adxd->xddxfnumber==1002) //adxd->xddata.xdcontrol   123 '{'   125 '}'
  1758. {
  1759. if(adxd->xddata.xdcontrol=='{')
  1760. {
  1761. if(bControlStart==TRUE)
  1762. {
  1763. TRACE("错误的blob数据");
  1764. }
  1765. else
  1766. {
  1767. bControlStart=TRUE;
  1768. }
  1769. }
  1770. else if(adxd->xddata.xdcontrol=='}')
  1771. {
  1772. if(bControlStart==TRUE)
  1773. {
  1774. bControlStart=FALSE;
  1775. }
  1776. else
  1777. {
  1778. TRACE("错误的blob数据");
  1779. }
  1780. }
  1781. }
  1782. }
  1783. adEndBlobRead(bcptr);
  1784. }
  1785. }
  1786. if(texthight<0.0000001)
  1787. {
  1788. AD_DIMSTYLE addimst;
  1789. //short adSeekDimstyle (AD_DB_HANDLE handle, AD_OBJHANDLE thehandle, PAD_DIMSTYLE addimst);
  1790. sReturnValue=adSeekDimstyle(dwghandle,aden->tolerance.dimstyleobjhandle,&addimst);
  1791. if(sReturnValue!=1)
  1792. {
  1793. _ERROR;
  1794. return FALSE;
  1795. }
  1796. texthight=addimst.dimtxt;//DIMTXT 标注文字高度
  1797. }
  1798. }
  1799. else
  1800. {
  1801. texthight=aden->tolerance.textht;
  1802. }
  1803. texthight=texthight*calculate_findTTFHightRate(shape->m_strShapefilename);
  1804. //{xlf:ACAD认为形位公差的高度等于形位公差文字高度的2倍,
  1805. //KCAD认为形位公差的高度等于形位公差文字高度的1.2倍。
  1806. texthight=texthight*(2.0);//调整带框字符和不带框字符的字高误差
  1807. double angle=calculate_2dangle(aden->tolerance.xdir[0],aden->tolerance.xdir[1]);
  1808. KmPoint pRT=calculate_2drotate(aden->tolerance.pt0[0],aden->tolerance.pt0[1],0,texthight*calculate_findTTFPosRate(shape->m_strShapefilename)*0.5,angle);//*0.5的原因在于形位公差以左中为基点.
  1809. 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;
  1810. _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));
  1811. return TRUE;
  1812. }
  1813. void CDwgReader::processentity_tol_blob(int code,short datatype,double &tolhight)
  1814. {//目前仅读出形位公差的高度,以后如有需要则可仿照..._dim_blob读出来
  1815. switch(code)
  1816. {
  1817. case 140://DIMTXT
  1818. if(datatype!=1040)
  1819. {
  1820. TRACE("错误的数据");
  1821. break;
  1822. }
  1823. tolhight=adxd->xddata.xdreal;
  1824. break;
  1825. }
  1826. }
  1827. BOOL CDwgReader::processentity_atext(AD_DB_HANDLE dwghandle)
  1828. {
  1829. CShape* shape;
  1830. {
  1831. CMatch5* match=NULL;
  1832. if(!m_ashape.Get(aden->arcalignedtext.textstyleobjhandle,match))
  1833. {
  1834. _WRITE(str="没有找到文字样式");
  1835. }
  1836. shape=match->m_shape;
  1837. }
  1838. AD_TDATA data;
  1839. adHancpy(data.shapefileobjhandle,aden->arcalignedtext.textstyleobjhandle);
  1840. KmPoint pRT,ptemp;
  1841. pRT.x=aden->arcalignedtext.pt0[0]+aden->arcalignedtext.radius*cos(aden->arcalignedtext.startangle);
  1842. pRT.y=aden->arcalignedtext.pt0[1]+aden->arcalignedtext.radius*sin(aden->arcalignedtext.startangle);
  1843. ptemp.x=aden->arcalignedtext.pt0[0]+aden->arcalignedtext.radius*cos(aden->arcalignedtext.endangle);
  1844. ptemp.y=aden->arcalignedtext.pt0[1]+aden->arcalignedtext.radius*sin(aden->arcalignedtext.endangle);
  1845. data.height=aden->arcalignedtext.height;
  1846. data.rotang=calculate_2dangle(ptemp.x-pRT.x,ptemp.y-pRT.y);
  1847. data.widthfactor=aden->arcalignedtext.widthfactor;
  1848. data.widthfactor=data.widthfactor*calculate_findTTFWidthRate(shape->m_strShapefilename);
  1849. int index=m_pConverter->ConverterEntiey_KmSText(aden->arcalignedtext.text,pRT.x,pRT.y,aden->arcalignedtext.pt0[2],&data,shape).dwEntIndex;
  1850. _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));
  1851. return TRUE;
  1852. }
  1853. BOOL CDwgReader::processentity_rtext(AD_DB_HANDLE dwghandle)
  1854. {
  1855. //外部文字暂不予处理
  1856. return TRUE;
  1857. }
  1858. void CDwgReader::calculate_rotatealix(double &x,double &y,double a)
  1859. {
  1860. KmMatrix matrix;//旋转矩阵
  1861. double angle = -1*a;
  1862. KmPoint pt(x,y) ;
  1863. matrix.r11 = (double)cos(angle);
  1864. matrix.r21 = (double)sin(angle);
  1865. matrix.r31 = 0.0;
  1866. matrix.r12 = (double)(-sin(angle));
  1867. matrix.r22 = (double)cos(angle);
  1868. matrix.r32 = 0.0;
  1869. matrix.r13 = 0.0;
  1870. matrix.r23 = 0.0;
  1871. matrix.r33 = 1.0;
  1872. pt=matrix*pt;
  1873. x=pt.x;
  1874. y=pt.y;
  1875. }
  1876. BOOL CDwgReader::processentity_hatch(AD_DB_HANDLE dwghandle)
  1877. {
  1878. PAD_BLOB_CTRL bcptr;//,boundarybcptr;
  1879. long il,jl,kl,numpathsegs,pathflag,splineknots,splinedegree,splinectrlpts,numboundaryobjects;
  1880. unsigned char pathtypestatus;
  1881. double pt0[2],pt1[2],radius,startangle,endangle,center[2],axisendpt[2],startparam,endparam;
  1882. double minmajratio,knot,ctrlpt[2];
  1883. unsigned short rational,periodic,closed;
  1884. short i,j;
  1885. double lineangle,patternthrough[2],patternoffset[2],dashitem;
  1886. // double seedptx,seedpty;
  1887. double vertpt[2],bulge,weight;
  1888. short dashlengthitems,bulgespresent;
  1889. short isccw;
  1890. // AD_OBJHANDLE temphandle;
  1891. // char temphandlestr[20];
  1892. // char pixelsizepresent;
  1893. // if (aden->hatch.boundaryobjblob!=AD_VMNULL)
  1894. // boundarybcptr=adStartBlobRead(aden->hatch.boundaryobjblob);
  1895. // pixelsizepresent=0;
  1896. PATH2* path=new PATH2;
  1897. bcptr=adStartBlobRead(aden->hatch.pathblob);
  1898. for (il=0; il<aden->hatch.numpaths; il++) 
  1899. {
  1900. if(adReadBlobLong(bcptr,&pathflag)!=1)
  1901. {
  1902. _ERROR;
  1903. delete path;
  1904. return FALSE;
  1905. }
  1906. //#define AD_HATCH_PATHFLAG_DEFAULT      0
  1907. //#define AD_HATCH_PATHFLAG_EXTERNAL     1
  1908. //#define AD_HATCH_PATHFLAG_DERIVED      4
  1909. //#define AD_HATCH_PATHFLAG_TEXTBOX      8
  1910. //#define AD_HATCH_PATHFLAG_OUTERMOST   16
  1911. // if (pathflag & 4)
  1912. // {
  1913. // pixelsizepresent=1;  /* if ANY of them meet this criterion */
  1914. // }
  1915. if (!(pathflag & AD_HATCH_PATHFLAG_POLYLINE)) 
  1916. {
  1917. if(adReadBlobLong(bcptr,&numpathsegs)!=1)
  1918. {
  1919. _ERROR;
  1920. delete path;
  1921. return FALSE;
  1922. }
  1923. for (jl=0; jl<numpathsegs; jl++) 
  1924. {
  1925. if(adReadBlobByte(bcptr,(char*)&pathtypestatus)!=1)
  1926. {
  1927. _ERROR;
  1928. delete path;
  1929. return FALSE;
  1930. }
  1931. if (pathtypestatus==AD_HATCH_PATHTYPE_LINE) 
  1932. {
  1933. if(adReadBlob2Double(bcptr,pt0)!=1)
  1934. {
  1935. _ERROR;
  1936. delete path;
  1937. return FALSE;
  1938. }
  1939. if(adReadBlob2Double(bcptr,pt1)!=1)
  1940. {
  1941. _ERROR;
  1942. delete path;
  1943. return FALSE;
  1944. }
  1945. if(calculate_BackView())
  1946. {
  1947. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  1948. {
  1949. calculate_path_line(path,-1*pt0[0],pt0[1],-1*pt1[0],pt1[1]);
  1950. }
  1951. }
  1952. else
  1953. {
  1954. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  1955. {
  1956. calculate_path_line(path,pt0[0],pt0[1],pt1[0],pt1[1]);
  1957. }
  1958. }
  1959. }
  1960. else if (pathtypestatus==AD_HATCH_PATHTYPE_CIRCARC) 
  1961. {
  1962. if(adReadBlob2Double(bcptr,pt0)!=1)
  1963. {
  1964. _ERROR;
  1965. delete path;
  1966. return FALSE;
  1967. }
  1968. if(adReadBlobDouble(bcptr,&radius)!=1)
  1969. {
  1970. _ERROR;
  1971. delete path;
  1972. return FALSE;
  1973. }
  1974. if(adReadBlobDouble(bcptr,&startangle)!=1)
  1975. {
  1976. _ERROR;
  1977. delete path;
  1978. return FALSE;
  1979. }
  1980. if(adReadBlobDouble(bcptr,&endangle)!=1)
  1981. {
  1982. _ERROR;
  1983. delete path;
  1984. return FALSE;
  1985. }
  1986. if(adReadBlobShort(bcptr,(short *)&isccw)!=1)
  1987. {
  1988. _ERROR;
  1989. delete path;
  1990. return FALSE;
  1991. }
  1992. KmCircle* pCircle=new KmCircle;
  1993. pCircle->SetCenter(pt0[0],pt0[1]);
  1994. pCircle->SetRadius(radius);
  1995. pCircle->SetBAngle((-1*startangle)*180/PI);
  1996. pCircle->SetEAngle((-1*endangle)*180/PI);
  1997. if(isccw)//c clockwise 逆时针方向
  1998. {
  1999. pCircle->SetBAngle((startangle)*180/PI);
  2000. pCircle->SetEAngle((endangle)*180/PI);
  2001. pCircle->SetMessage(MESSAGE_CIRCLE_POSITIVE);
  2002. }
  2003. else
  2004. {
  2005. pCircle->SetBAngle((-1*startangle)*180/PI);
  2006. pCircle->SetEAngle((-1*endangle)*180/PI);
  2007. pCircle->SetMessage(MESSAGE_CIRCLE_NEGATIVE);
  2008. }
  2009. if(calculate_BackView())
  2010. {
  2011. pCircle->xo=-1*pCircle->xo;
  2012. pCircle->b_angle=PI+pCircle->b_angle;
  2013. pCircle->e_angle=PI+pCircle->e_angle;
  2014. }
  2015. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2016. {
  2017. calculate_path_object(path,pCircle);
  2018. }
  2019. delete pCircle;
  2020. }
  2021. else if (pathtypestatus==AD_HATCH_PATHTYPE_ELLIPARC) 
  2022. {
  2023. if(adReadBlob2Double(bcptr,center)!=1)
  2024. {
  2025. _ERROR;
  2026. delete path;
  2027. return FALSE;
  2028. }
  2029. if(adReadBlob2Double(bcptr,axisendpt)!=1)
  2030. {
  2031. _ERROR;
  2032. delete path;
  2033. return FALSE;
  2034. }
  2035. if(adReadBlobDouble(bcptr,&minmajratio)!=1)
  2036. {
  2037. _ERROR;
  2038. delete path;
  2039. return FALSE;
  2040. }
  2041. if(adReadBlobDouble(bcptr,&startparam)!=1)
  2042. {
  2043. _ERROR;
  2044. delete path;
  2045. return FALSE;
  2046. }
  2047. if(adReadBlobDouble(bcptr,&endparam)!=1)
  2048. {
  2049. _ERROR;
  2050. delete path;
  2051. return FALSE;
  2052. }
  2053. if(adReadBlobShort(bcptr,(short *)&isccw)!=1)
  2054. {
  2055. _ERROR;
  2056. delete path;
  2057. return FALSE;
  2058. }
  2059. KmEllipse* pellipse=new KmEllipse;
  2060. pellipse->SetMessage(MESSAGE_CIRCLE_POSITIVE);
  2061. pellipse->SetCenter(KmPoint(center[0],center[1]));
  2062. double lr=calculate_3ddpdistance(axisendpt[0],axisendpt[1],0);
  2063. double sr=lr*minmajratio;
  2064. double a=calculate_2dangle(axisendpt[0],axisendpt[1]);
  2065. pellipse->SetLr(lr);
  2066. pellipse->SetSr(sr);
  2067. pellipse->SetAngle(a*180/PI);
  2068. if(isccw)
  2069. {
  2070. pellipse->SetBeginAngle((a+PI+calculate_2dangle(-lr*cos(startparam),-sr*sin(startparam)))*180/PI);
  2071. pellipse->SetEndAngle((a+PI+calculate_2dangle(-lr*cos(endparam),-sr*sin(endparam)))*180/PI);
  2072. }
  2073. else
  2074. {
  2075. pellipse->SetEndAngle((a+PI-calculate_2dangle(-lr*cos(startparam),-sr*sin(startparam)))*180/PI);
  2076. pellipse->SetBeginAngle((a+PI-calculate_2dangle(-lr*cos(endparam),-sr*sin(endparam)))*180/PI);
  2077. }
  2078. if(calculate_BackView())
  2079. {
  2080. pellipse->Mirror(KmPoint(0,0),90);
  2081. }
  2082. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2083. {
  2084. calculate_path_object(path,pellipse);
  2085. }
  2086. delete pellipse;
  2087. }
  2088. else if (pathtypestatus==AD_HATCH_PATHTYPE_SPLINE) 
  2089. {
  2090. if(adReadBlobLong(bcptr,&splinedegree)!=1)
  2091. {
  2092. _ERROR;
  2093. delete path;
  2094. return FALSE;
  2095. }
  2096. if(adReadBlobShort(bcptr,(short *)&rational)!=1)
  2097. {
  2098. _ERROR;
  2099. delete path;
  2100. return FALSE;
  2101. }
  2102. if(adReadBlobShort(bcptr,(short *)&periodic)!=1)
  2103. {
  2104. _ERROR;
  2105. delete path;
  2106. return FALSE;
  2107. }
  2108. if(adReadBlobLong(bcptr,&splineknots)!=1)
  2109. {
  2110. _ERROR;
  2111. delete path;
  2112. return FALSE;
  2113. }
  2114. if(adReadBlobLong(bcptr,&splinectrlpts)!=1)
  2115. {
  2116. _ERROR;
  2117. delete path;
  2118. return FALSE;
  2119. }
  2120. for (kl=0L; kl<splineknots; kl++) 
  2121. {
  2122. if(adReadBlobDouble(bcptr,&knot)!=1)
  2123. {
  2124. _ERROR;
  2125. delete path;
  2126. return FALSE;
  2127. }
  2128. }
  2129. KmSpLine* pspline=new KmSpLine;
  2130. pspline->m_nNodeNum=splinectrlpts;
  2131. pspline->m_iType=T_BPLINE;
  2132. for (kl=0L; kl<splinectrlpts; kl++) 
  2133. {
  2134. if(adReadBlob2Double(bcptr,ctrlpt)!=1)
  2135. {
  2136. _ERROR;
  2137. delete path;
  2138. delete pspline;
  2139. return FALSE;
  2140. }
  2141. pspline->m_aNode.Add(KmPoint(ctrlpt[0],ctrlpt[1]));
  2142. if (rational) 
  2143. {
  2144. if(adReadBlobDouble(bcptr,&weight)!=1)
  2145. {
  2146. _ERROR;
  2147. delete path;
  2148. delete pspline;
  2149. return FALSE;
  2150. }
  2151. }
  2152. }
  2153. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2154. {
  2155. calculate_path_object(path,pspline);
  2156. }
  2157. delete pspline;
  2158. }
  2159. } /* for jl */
  2160. }
  2161. else 
  2162. {  /* pathflag & 2 is true */
  2163. if(adReadBlobShort(bcptr,&bulgespresent)!=1)
  2164. {
  2165. _ERROR;
  2166. delete path;
  2167. return FALSE;
  2168. }
  2169. if(adReadBlobShort(bcptr,(short *)&closed)!=1)
  2170. {
  2171. _ERROR;
  2172. delete path;
  2173. return FALSE;
  2174. }
  2175. if(adReadBlobLong(bcptr,&numpathsegs)!=1)
  2176. {
  2177. _ERROR;
  2178. delete path;
  2179. return FALSE;
  2180. }
  2181. double lastx=0,firstx=0;
  2182. double lasty=0,firsty=0;
  2183. double lastb=0;
  2184. for (jl=0L; jl<numpathsegs; jl++) 
  2185. {
  2186. if(adReadBlob2Double(bcptr,vertpt)!=1)
  2187. {
  2188. _ERROR;
  2189. delete path;
  2190. return FALSE;
  2191. }
  2192. if (bulgespresent) 
  2193. {
  2194. if(adReadBlobDouble(bcptr,&bulge)!=1)
  2195. {
  2196. _ERROR;
  2197. delete path;
  2198. return FALSE;
  2199. }
  2200. if(jl!=0)
  2201. {
  2202. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2203. {
  2204. calculate_path_bugleline(path,lastx,lasty,lastb,vertpt[0],vertpt[1]);
  2205. }
  2206. }
  2207. else
  2208. {
  2209. firstx=vertpt[0];
  2210. firsty=vertpt[1];
  2211. }
  2212. lastx=vertpt[0];
  2213. lasty=vertpt[1];
  2214. lastb=bulge;
  2215. }
  2216. else
  2217. {
  2218. if(jl!=0)
  2219. {
  2220. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2221. {
  2222. calculate_path_line(path,lastx,lasty,vertpt[0],vertpt[1]);
  2223. }
  2224. }
  2225. else
  2226. {
  2227. firstx=vertpt[0];
  2228. firsty=vertpt[1];
  2229. }
  2230. lastx=vertpt[0];
  2231. lasty=vertpt[1];
  2232. }
  2233. }
  2234. if(closed)
  2235. {
  2236. if (bulgespresent) 
  2237. {
  2238. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2239. {
  2240. calculate_path_bugleline(path,vertpt[0],vertpt[1],lastb,firstx,firsty);
  2241. }
  2242. }
  2243. else
  2244. {
  2245. if(!(pathflag&AD_HATCH_PATHFLAG_TEXTBOX))
  2246. {
  2247. calculate_path_line(path,vertpt[0],vertpt[1],firstx,firsty);
  2248. }
  2249. }
  2250. }
  2251. }
  2252. if(adReadBlobLong(bcptr,&numboundaryobjects)!=1)
  2253. {
  2254. _ERROR;
  2255. delete path;
  2256. return FALSE;
  2257. }
  2258. } /* il < numpaths */
  2259. if(adEndBlobRead(bcptr)!=1)
  2260. {
  2261. _ERROR;
  2262. delete path;
  2263. return FALSE;
  2264. }
  2265. if(path->b_angle.GetSize()<=1)
  2266. {
  2267. _WRITE(str="剖面的路径数为零");
  2268. return FALSE;
  2269. }
  2270. if(aden->hatch.solidfill==1)//实心的
  2271. {
  2272. KmSection* pSection=new KmSection;
  2273. pSection->m_Path.Add(path);
  2274. pSection->m_PathNumber=1;
  2275. pSection->SetReticleflag(TRUE);
  2276. //限定剖面线的条数最多为500条.
  2277. KmRect rect=pSection->GetRect();
  2278. if(aden->hatch.pixelsize<rect.Height()*0.002)
  2279. {
  2280. aden->hatch.pixelsize=rect.Height()*0.002;
  2281. }
  2282. if(aden->hatch.pixelsize<rect.Width()*0.002)
  2283. {
  2284. aden->hatch.pixelsize=rect.Width()*0.002;
  2285. }
  2286. pSection->SetSpace(aden->hatch.pixelsize);
  2287. int index=m_pConverter->ConverterEntiey_KmObject(pSection).dwEntIndex;
  2288. _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));
  2289. return TRUE;
  2290. }
  2291. if(aden->hatch.patterntype==0)//用户定义的单向剖面线
  2292. {
  2293. KmSection* pSection=new KmSection;
  2294. pSection->m_Path.Add(path);
  2295. pSection->m_PathNumber=1;
  2296. if(aden->hatch.doublehatch==1)
  2297. {
  2298. pSection->SetReticleflag(TRUE);
  2299. }
  2300. else
  2301. {
  2302. pSection->SetReticleflag(FALSE);
  2303. }
  2304. pSection->SetAngle((int)(aden->hatch.angle*180/PI));
  2305. pSection->SetSpace(aden->hatch.scaleorspacing);
  2306. int index=m_pConverter->ConverterEntiey_KmObject(pSection).dwEntIndex;
  2307. _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));
  2308. return TRUE;
  2309. }
  2310. KmPatternSection* pPSection=new KmPatternSection;
  2311. pPSection->m_Path.Add(path);
  2312. pPSection->m_PathNumber=1;
  2313. pPSection->m_PatternNumber=0;
  2314. bcptr=adStartBlobRead(aden->hatch.hatchblob);
  2315. for (i=0; i<(short)aden->hatch.numdeflines; i++) 
  2316. {
  2317. if(adReadBlobDouble(bcptr,&lineangle)!=1)
  2318. {//角度
  2319. _ERROR;
  2320. delete pPSection;
  2321. return FALSE;
  2322. }
  2323. if(adReadBlob2Double(bcptr,patternthrough)!=1)
  2324. {//原点
  2325. _ERROR;
  2326. delete pPSection;
  2327. return FALSE;
  2328. }
  2329. if(adReadBlob2Double(bcptr,patternoffset)!=1)
  2330. {//偏移
  2331. _ERROR;
  2332. delete pPSection;
  2333. return FALSE;
  2334. }
  2335. calculate_rotatealix(patternoffset[0],patternoffset[1],lineangle);
  2336. if(adReadBlobShort(bcptr,&dashlengthitems)!=1)
  2337. {
  2338. _ERROR;
  2339. delete pPSection;
  2340. return FALSE;
  2341. }
  2342. CArray<double,double>dashs;
  2343. for(j=0;j<dashlengthitems; j++) 
  2344. {
  2345. if(adReadBlobDouble(bcptr,&dashitem)!=1)
  2346. {
  2347. _ERROR;
  2348. delete pPSection;
  2349. return FALSE;
  2350. }
  2351. dashs.Add(fabs(dashitem));
  2352. }
  2353. if(dashlengthitems<=1)
  2354. {
  2355. KmPattern* pPattern2=new KmPattern;
  2356. pPattern2->dBasex=patternthrough[0];
  2357. pPattern2->dBasey=patternthrough[1];
  2358. pPattern2->dOffsetx=patternoffset[0];
  2359. pPattern2->dOffsety=patternoffset[1];
  2360. pPattern2->dAngle=lineangle*180/PI;
  2361. pPattern2->bDash=FALSE;
  2362. pPattern2->dBright=0;
  2363. pPattern2->dHidden=0;
  2364. pPSection->m_PatternArray.Add(pPattern2);
  2365. pPSection->m_PatternNumber++;
  2366. continue;
  2367. }
  2368. if((dashs.GetSize()%2))
  2369. {
  2370. dashs.RemoveAt(dashs.GetSize()-1);
  2371. }
  2372. //1.计算出路径的总长度.
  2373. double totallength=0;
  2374. for(int i=0;i<dashs.GetSize();i++)
  2375. {
  2376. if(dashs[i]<PRECISION)//AutoCAD中的点转换为0.1的长度
  2377. dashs[i]=0.1;
  2378. totallength+=dashs[i];
  2379. }
  2380. //2.
  2381. double prelength=0;
  2382. for(int k=0;k<dashs.GetSize();k++)
  2383. {
  2384. if(!(k%2))
  2385. {
  2386. if(k+1<dashs.GetSize())
  2387. {
  2388. //k k+1 prelength;
  2389. {
  2390. KmPattern* pPattern2=new KmPattern;
  2391. pPattern2->dBasex=patternthrough[0]+prelength*cos(lineangle);
  2392. pPattern2->dBasey=patternthrough[1]+prelength*sin(lineangle);
  2393. pPattern2->dOffsetx=patternoffset[0];
  2394. pPattern2->dOffsety=patternoffset[1];
  2395. pPattern2->dAngle=lineangle*180/PI;
  2396. pPattern2->bDash=TRUE;
  2397. pPattern2->dBright=dashs[k];
  2398. pPattern2->dHidden=dashs[k+1];
  2399. pPSection->m_PatternArray.Add(pPattern2);
  2400. pPSection->m_PatternNumber++;
  2401. }
  2402. prelength+=dashs[k];
  2403. prelength+=dashs[k+1];
  2404. k++;
  2405. continue;
  2406. }
  2407. }
  2408. prelength+=dashs[k];
  2409. }
  2410. }
  2411. adEndBlobRead(bcptr);
  2412. if(pPSection->m_PatternNumber==0)
  2413. {
  2414. delete pPSection;
  2415. _WRITE(str="没有找到剖面的填充风格");
  2416. return FALSE;
  2417. }
  2418. /* if(aden->hatch.scaleorspacing!=0)
  2419. {
  2420. double scale;
  2421. try
  2422. {
  2423. scale=1/aden->hatch.scaleorspacing;
  2424. scale=fabs(scale);
  2425. if(scale<0.1)scale=0.1;
  2426. }
  2427. catch(...)
  2428. {
  2429. scale=1.0;
  2430. }
  2431. pPSection->SetScale(scale);
  2432. }*/
  2433. int index=m_pConverter->ConverterEntiey_KmObject(pPSection).dwEntIndex;
  2434. _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));
  2435. // if (pixelsizepresent) 
  2436. // {
  2437. // TRACE("47n%fn",aden->hatch.pixelsize);
  2438. // }
  2439. // bcptr=adStartBlobRead(aden->hatch.seedpointblob);
  2440. // for (il=0; il<aden->hatch.numseedpoints; il++) 
  2441. // {
  2442. // adReadBlobDouble(bcptr,&seedptx);
  2443. // adReadBlobDouble(bcptr,&seedpty);
  2444. // }
  2445. // adEndBlobRead(bcptr);
  2446. // if (aden->hatch.boundaryobjblob!=AD_VMNULL)
  2447. // adEndBlobRead(boundarybcptr);
  2448. return TRUE;
  2449. }
  2450. BOOL CDwgReader::processentity_shape(AD_DB_HANDLE dwghandle)
  2451. {
  2452. KmBuffer buff;
  2453. if(!calculate_findshape(dwghandle,aden->shape.shapefileobjhandle,aden->shape.whichshape,&aden->shape.pt0[0],&aden->shape.pt0[1],
  2454. ((double)aden->shape.rotang),
  2455. 1,aden->shape.scale,aden->shape.widthfactor,
  2456. &buff))return FALSE;
  2457. AD_TB adtbtemp;
  2458. //extern  short  ADCDECL adSeekShapefile _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_SHPTB theshptb));
  2459. short sReturnValue = adSeekShapefile(dwghandle,aden->shape.shapefileobjhandle,&adtbtemp.shptb);
  2460. if(sReturnValue!=1)
  2461. {
  2462. return FALSE;
  2463. }
  2464. return m_pConverter->ConverterEntiey_KmBuffer(buff,adtbtemp.shptb.name,adtbtemp.shptb.name,KmPoint(aden->shape.pt0[0],aden->shape.pt0[1]));
  2465. }