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

CAD

开发平台:

Visual C++

  1. //      KMCAD40-FileSwitch-Processfile7.cpp-1.0 
  2. // KmgReader.cpp: implementation of the CKmgReader class.
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. #include "stdafx.h"
  6. #include "FileSwitch.h"
  7. #include "KmgReader.h"
  8. #include "Database.h"
  9. #include "Reader.h"
  10. #include "CShow.h"
  11. #include "KmObject.h"
  12. #include "EntDef.h"
  13. #include "block.h"
  14. #include "KmDim.h"
  15. #include "KmSymbl.h"
  16. #include "KmTable.h"
  17. #include "KmSection.h"
  18. #include "KmPartNo.h"
  19. #include "ArcText.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. extern CStdioFile g_CensorialFile; //监察转换进度的文件
  26. extern int g_mode;
  27. BOOL CKmgReader::processentity(CKmDataManager* pData)
  28. {
  29. KmBuffer buff;
  30.     CShow* pShow = new CGDIShow((CWnd*)NULL);
  31. KmObject* pObj;
  32. for(UINT index=0;index<::GetEntDicSize();index++)
  33. {
  34. if(!::GetEntDicAt(index))continue;
  35. KmIteratorPtr pI(pData->CreateIterator(::GetEntDicAt(index)));
  36. KmObject* pTemp=(KmObject*)::GetEntDicAt(index)->CreateObject();
  37. if(!pTemp)continue;
  38. if(pTemp->Type()=="KmBlockRef")
  39. {
  40. for(pI->First(); !pI->IsDone(); pI->Next())
  41. {
  42. pObj = pI->CurrentItem();
  43. if(((KmBlockRef*)pObj)->GetKmAttrMap())
  44. {
  45. if(((KmBlockRef*)pObj)->GetKmAttrMap()->GetAttrItems())
  46. {
  47. if(((KmBlockRef*)pObj)->GetKmAttrMap()->GetAttrItems()->GetCount())
  48. {//如果是属性块则另行创建块定义
  49. processentityhead(pData,pObj);
  50. CMatch2* match=new CMatch2;
  51. //1.创建块定义
  52. CString str;
  53. str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
  54. m_pConverter->ConverterEntity_KmBlockdef(str,match);
  55. m_pConverter->SetBlockDataVassel(match->m_handle);
  56. //2.增加AD_ENT_BLOCK
  57. m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
  58. processentityhead(pData,pObj);
  59. processentity_buf(pData,pObj);
  60. m_pConverter->AddEndBlkSign();
  61. m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
  62. delete match;
  63. continue;
  64. }
  65. }
  66. }
  67. processentityhead(pData,pObj);
  68. AD_OBJHANDLE handle;
  69. KmBlockRef* pRef=(KmBlockRef*)pObj;
  70. m_ablock.Get(handle,pRef->GetBlockDefID());
  71. m_pConverter->ConverterEntity_AdInsert(pRef->GetInsertPoint().x,pRef->GetInsertPoint().y,0.0,pRef->GetScale(),pRef->GetScale(),pRef->GetScale(),pRef->GetAngle(),handle);
  72. }
  73. }
  74. else if( (pTemp->IsKindOf(RUNTIME_CLASS(KmSymbl)))||
  75. //(pTemp->IsKindOf(RUNTIME_CLASS(KmTable)))||
  76. (pTemp->IsKindOf(RUNTIME_CLASS(KmText)))||
  77. (pTemp->IsKindOf(RUNTIME_CLASS(KmArcText)))||
  78. (pTemp->IsKindOf(RUNTIME_CLASS(KmPartSerialNo)))||
  79. (pTemp->IsKindOf(RUNTIME_CLASS(KmSection))))
  80. {
  81. for(pI->First(); !pI->IsDone(); pI->Next())
  82. {
  83. pObj = pI->CurrentItem();
  84. if(pObj->GetFlag()&KMOBJ_HIDED)
  85. {
  86. continue;
  87. }
  88. processentityhead(pData,pObj);
  89. CMatch2* match=new CMatch2;
  90. //1.创建块定义
  91. CString str;
  92. str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
  93. m_pConverter->ConverterEntity_KmBlockdef(str,match);
  94. m_pConverter->SetBlockDataVassel(match->m_handle);
  95. //2.增加AD_ENT_BLOCK
  96. m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
  97. processentityhead(pData,pObj);
  98. processentity_buf(pData,pObj);
  99. m_pConverter->AddEndBlkSign();
  100. m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
  101. delete match;
  102. }
  103. }
  104. else if( pTemp->IsKindOf(RUNTIME_CLASS(KmDim)) )
  105. {
  106. for(pI->First(); !pI->IsDone(); pI->Next())
  107. {
  108. pObj = pI->CurrentItem();
  109. CMatch2* match=new CMatch2;
  110. //1.创建块定义
  111. CString str;
  112. str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
  113. m_pConverter->ConverterEntity_KmBlockdef(str,match);
  114. m_pConverter->SetBlockDataVassel(match->m_handle);
  115. //2.增加AD_ENT_BLOCK
  116. m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
  117. processentityhead(pData,pObj);
  118. processentity_buf(pData,pObj);
  119. m_pConverter->AddEndBlkSign();
  120. processentityhead(pData,pObj);
  121. if(!processentity_dim(pData,pObj,match->m_handle))
  122. {
  123. delete match;
  124. m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
  125. }
  126. else
  127. {
  128. delete match;
  129. }
  130. }
  131. }
  132. else if( pTemp->IsKindOf(RUNTIME_CLASS(KmLine)) )
  133. {
  134. for(pI->First(); !pI->IsDone(); pI->Next())
  135. {
  136. pObj = pI->CurrentItem();
  137. processentityhead(pData,pObj);
  138. m_pConverter->ConverterEntity_AdLine(((KmLine*)pObj)->bx,((KmLine*)pObj)->by,0.0,((KmLine*)pObj)->ex,((KmLine*)pObj)->ey,0.0);
  139. }
  140. }
  141. else if( pTemp->IsKindOf(RUNTIME_CLASS(KmCircle)) )
  142. {
  143. for(pI->First(); !pI->IsDone(); pI->Next())
  144. {
  145. pObj = pI->CurrentItem();
  146. processentityhead(pData,pObj);
  147. if(((KmCircle*)pObj)->message&MESSAGE_CIRCLE_FULL)
  148. {
  149. m_pConverter->ConverterEntity_AdCircle(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius());
  150. }
  151. else if(((KmCircle*)pObj)->message&MESSAGE_CIRCLE_NEGATIVE)
  152. {
  153. m_pConverter->ConverterEntity_AdArc(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius(),((KmCircle*)pObj)->e_angle,((KmCircle*)pObj)->b_angle);
  154. }
  155. else
  156. {
  157. m_pConverter->ConverterEntity_AdArc(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius(),((KmCircle*)pObj)->b_angle,((KmCircle*)pObj)->e_angle);
  158. }
  159. }
  160. }
  161. else
  162. {
  163. for(pI->First(); !pI->IsDone(); pI->Next())
  164. {
  165. pObj = pI->CurrentItem();
  166. processentityhead(pData,pObj);
  167. if(!processentity(pData,pObj))
  168. {
  169. pObj->Draw(pShow,pObj->color,DRAWPRESENT,&buff);
  170. }
  171. }
  172. }
  173. delete pTemp;
  174. }
  175. int size=buff.GetLineBuffSize();
  176. for(int i=0;i<size;i++)
  177. {
  178. if(!processentity_buf_line(pData,buff.GetLineEnt(i)))
  179. {
  180. _WRITE(str="转换buf直线失败");
  181. }
  182. }
  183. size=buff.GetCircleBuffSize();
  184. for(i=0;i<size;i++)
  185. {
  186. if(!processentity_buf_circle(pData,buff.GetCircleEnt(i)))
  187. {
  188. _WRITE(str="转换buf圆失败");
  189. }
  190. }
  191. size=buff.GetRegionBuffSize();
  192. for(i=0;i<size;i++)
  193. {
  194. if(!processentity_buf_region(pData,buff.GetRegionEnt(i)))
  195. {
  196. _WRITE(str="转换buf区域失败");
  197. }
  198. }
  199. size=buff.GetTextBuffSize();
  200. for(i=0;i<size;i++)
  201. {
  202. if(!processentity_buf_text(pData,buff.GetTextEnt(i)))
  203. {
  204. _WRITE(str="转换buf文字失败");
  205. }
  206. }
  207. delete pShow;
  208. buff.ClearKmBuffer();
  209. return TRUE;
  210. }
  211. BOOL CKmgReader::processentity(CKmDataManager* pData,KmObject* pObj)
  212. {
  213. return processentity_buf(pData,pObj);
  214. }
  215. BOOL CKmgReader::processentity_buf(CKmDataManager* pData,KmObject* pObj)
  216. {
  217. KmBuffer buff;
  218.     CShow* pShow = new CGDIShow((CWnd*)NULL);
  219. pObj->Draw(pShow,pObj->color,DRAWPRESENT,&buff);
  220. int size=buff.GetLineBuffSize();
  221. for(int i=0;i<size;i++)
  222. {
  223. if(!processentity_buf_line(pData,buff.GetLineEnt(i)))
  224. {
  225. _WRITE(str="转换buf直线失败");
  226. }
  227. }
  228. size=buff.GetCircleBuffSize();
  229. for(i=0;i<size;i++)
  230. {
  231. if(!processentity_buf_circle(pData,buff.GetCircleEnt(i)))
  232. {
  233. _WRITE(str="转换buf圆失败");
  234. }
  235. }
  236. size=buff.GetRegionBuffSize();
  237. for(i=0;i<size;i++)
  238. {
  239. if(!processentity_buf_region(pData,buff.GetRegionEnt(i)))
  240. {
  241. _WRITE(str="转换buf区域失败");
  242. }
  243. }
  244. size=buff.GetTextBuffSize();
  245. for(i=0;i<size;i++)
  246. {
  247. if(!processentity_buf_text(pData,buff.GetTextEnt(i)))
  248. {
  249. _WRITE(str="转换buf文字失败");
  250. }
  251. }
  252. delete pShow;
  253. buff.ClearKmBuffer();
  254. return TRUE;
  255. }
  256. BOOL CKmgReader::processentity_buf_line(CKmDataManager* pData,S_LINE_BUFFER* line)
  257. {
  258. ENTDWGHEAD headback=m_pConverter->m_enthead;
  259. short scolor;
  260. if(line->Color==COLOR_BYBLOCK)
  261. {
  262. scolor=AD_COLOR_BYBLOCK;
  263. }
  264. else if(line->Color==COLOR_BYLAYER)
  265. {
  266. scolor=AD_COLOR_BYLAYER;
  267. }
  268. else
  269. {
  270. scolor=AD_COLOR_BYLAYER;
  271. for(int i=1;i<m_aColor.GetSize();i++)
  272. {
  273. if( (fabs(GetRValue(line->Color)-GetRValue(m_aColor[i]))+
  274.  fabs(GetGValue(line->Color)-GetGValue(m_aColor[i]))+
  275.  fabs(GetBValue(line->Color)-GetBValue(m_aColor[i])))<20)
  276. {
  277. scolor=i;
  278. break;
  279. }
  280. }
  281. }
  282. //2
  283. short swidth=1;
  284. double dscale=1.0;
  285. AD_OBJHANDLE hltype;
  286. if(line->Width==ABS_THIN_WIDTH)
  287. {
  288. swidth=0;
  289. }
  290. else if(line->Width==LWIDTH_BYLAYER)
  291. {
  292. swidth=(short)AD_WEIGHT_BYLAYER;
  293. }
  294. else if(line->Width==LWIDTH_BYBLOCK)
  295. {
  296. swidth=(short)AD_WEIGHT_BYBLOCK;
  297. }
  298. else
  299. {
  300. swidth=(short)(::GetLineWidthAsDouble(line->Width)*100.0);
  301. if(swidth<=5)swidth=5;
  302. else if(swidth<=9)swidth=9;
  303. else if(swidth<=13)swidth=13;
  304. else if(swidth<=15)swidth=15;
  305. else if(swidth<=18)swidth=18;
  306. else if(swidth<=20)swidth=20;
  307. else if(swidth<=25)swidth=25;
  308. else if(swidth<=30)swidth=30;
  309. else if(swidth<=35)swidth=35;
  310. else if(swidth<=40)swidth=40;
  311. else if(swidth<=50)swidth=50;
  312. else if(swidth<=53)swidth=53;
  313. else if(swidth<=60)swidth=60;
  314. else if(swidth<=70)swidth=70;
  315. else if(swidth<=80)swidth=80;
  316. else if(swidth<=90)swidth=90;
  317. else if(swidth<=100)swidth=100;
  318. else if(swidth<=106)swidth=106;
  319. else if(swidth<=120)swidth=120;
  320. else if(swidth<=140)swidth=140;
  321. else if(swidth<=158)swidth=158;
  322. else if(swidth<=200)swidth=200;
  323. else swidth=211;
  324. }
  325. m_altype.Get(hltype,line->LineType);
  326. dscale=line->LineScale;
  327. m_pConverter->WriteEnthead(scolor,swidth,dscale,hltype,headback.hlayer);
  328. m_pConverter->ConverterEntity_AdLine(line->P1.x,line->P1.y,0,line->P2.x,line->P2.y,0);
  329. m_pConverter->m_enthead=headback;
  330. return TRUE;
  331. }
  332. BOOL CKmgReader::processentity_buf_circle(CKmDataManager* pData,S_CIRCLE_BUFFER* circle)
  333. {
  334. ENTDWGHEAD headback=m_pConverter->m_enthead;
  335. short scolor;
  336. if(circle->Color==COLOR_BYBLOCK)
  337. {
  338. scolor=AD_COLOR_BYBLOCK;
  339. }
  340. else if(circle->Color==COLOR_BYLAYER)
  341. {
  342. scolor=AD_COLOR_BYLAYER;
  343. }
  344. else
  345. {
  346. scolor=AD_COLOR_BYLAYER;
  347. for(int i=1;i<m_aColor.GetSize();i++)
  348. {
  349. if( (fabs(GetRValue(circle->Color)-GetRValue(m_aColor[i]))+
  350.  fabs(GetGValue(circle->Color)-GetGValue(m_aColor[i]))+
  351.  fabs(GetBValue(circle->Color)-GetBValue(m_aColor[i])))<20)
  352. {
  353. scolor=i;
  354. break;
  355. }
  356. }
  357. }
  358. //2
  359. short swidth=1;
  360. double dscale=1.0;
  361. AD_OBJHANDLE hltype;
  362. if(circle->Width==ABS_THIN_WIDTH)
  363. {
  364. swidth=0;
  365. }
  366. else if(circle->Width==LWIDTH_BYLAYER)
  367. {
  368. swidth=(short)AD_WEIGHT_BYLAYER;
  369. }
  370. else if(circle->Width==LWIDTH_BYBLOCK)
  371. {
  372. swidth=(short)AD_WEIGHT_BYBLOCK;
  373. }
  374. else
  375. {
  376. swidth=(short)(::GetLineWidthAsDouble(circle->Width)*100.0);
  377. if(swidth<=5)swidth=5;
  378. else if(swidth<=9)swidth=9;
  379. else if(swidth<=13)swidth=13;
  380. else if(swidth<=15)swidth=15;
  381. else if(swidth<=18)swidth=18;
  382. else if(swidth<=20)swidth=20;
  383. else if(swidth<=25)swidth=25;
  384. else if(swidth<=30)swidth=30;
  385. else if(swidth<=35)swidth=35;
  386. else if(swidth<=40)swidth=40;
  387. else if(swidth<=50)swidth=50;
  388. else if(swidth<=53)swidth=53;
  389. else if(swidth<=60)swidth=60;
  390. else if(swidth<=70)swidth=70;
  391. else if(swidth<=80)swidth=80;
  392. else if(swidth<=90)swidth=90;
  393. else if(swidth<=100)swidth=100;
  394. else if(swidth<=106)swidth=106;
  395. else if(swidth<=120)swidth=120;
  396. else if(swidth<=140)swidth=140;
  397. else if(swidth<=158)swidth=158;
  398. else if(swidth<=200)swidth=200;
  399. else swidth=211;
  400. }
  401. m_altype.Get(hltype,circle->LineType);
  402. dscale=circle->LineScale;
  403. m_pConverter->WriteEnthead(scolor,swidth,dscale,hltype,headback.hlayer);
  404. if(circle->message&MESSAGE_CIRCLE_FULL)
  405. {
  406. m_pConverter->ConverterEntity_AdCircle(circle->center.x,circle->center.y,0,circle->radius);
  407. }
  408. else if(circle->message&MESSAGE_CIRCLE_NEGATIVE)
  409. {
  410. m_pConverter->ConverterEntity_AdArc(circle->center.x,circle->center.y,0,circle->radius,circle->e_angle,circle->b_angle);
  411. }
  412. else
  413. {
  414. m_pConverter->ConverterEntity_AdArc(circle->center.x,circle->center.y,0,circle->radius,circle->b_angle,circle->e_angle);
  415. }
  416. m_pConverter->m_enthead=headback;
  417. return TRUE;
  418. }
  419. BOOL CKmgReader::processentity_buf_region(CKmDataManager* pData,S_REGION* region)
  420. {
  421. short scolor = AD_COLOR_BYLAYER;
  422. if(region->Color==COLOR_BYBLOCK)
  423. {
  424. scolor=AD_COLOR_BYBLOCK;
  425. }
  426. else if(region->Color==COLOR_BYLAYER)
  427. {
  428. scolor=AD_COLOR_BYLAYER;
  429. }
  430. else
  431. {
  432. for(int i=1;i<m_aColor.GetSize();i++)
  433. {
  434. if( (fabs(GetRValue(region->Color)-GetRValue(m_aColor[i]))+
  435.  fabs(GetGValue(region->Color)-GetGValue(m_aColor[i]))+
  436.  fabs(GetBValue(region->Color)-GetBValue(m_aColor[i])))<20)
  437. {
  438. scolor=i;
  439. break;
  440. }
  441. }
  442. }
  443. if(region->ptNum==3)
  444. {
  445. m_pConverter->ConverterEntity_AdSolid(scolor,region->p1.x,region->p1.y,region->p2.x,region->p2.y,region->p3.x,region->p3.y,region->p3.x,region->p3.y);
  446. }
  447. else if(region->ptNum==4)
  448. {
  449. m_pConverter->ConverterEntity_AdSolid(scolor,region->p1.x,region->p1.y,region->p2.x,region->p2.y,region->p3.x,region->p3.y,region->p4.x,region->p4.y);
  450. }
  451. return TRUE;
  452. }
  453. BOOL CKmgReader::processentity_buf_text(CKmDataManager* pData,S_TEXT* text)
  454. {
  455. ENTDWGHEAD headback=m_pConverter->m_enthead;
  456. short scolor;
  457. if(text->m_dwColor==COLOR_BYBLOCK)
  458. {
  459. scolor=AD_COLOR_BYBLOCK;
  460. }
  461. else if(text->m_dwColor==COLOR_BYLAYER)
  462. {
  463. scolor=AD_COLOR_BYLAYER;
  464. }
  465. else
  466. {
  467. scolor=AD_COLOR_BYLAYER;
  468. for(int i=1;i<m_aColor.GetSize();i++)
  469. {
  470. if( (fabs(GetRValue(text->m_dwColor)-GetRValue(m_aColor[i]))+
  471.  fabs(GetGValue(text->m_dwColor)-GetGValue(m_aColor[i]))+
  472.  fabs(GetBValue(text->m_dwColor)-GetBValue(m_aColor[i])))<20)
  473. {
  474. scolor=i;
  475. break;
  476. }
  477. }
  478. }
  479. m_pConverter->WriteEnthead(scolor,headback.swidth,headback.dscale,headback.hltype,headback.hlayer);
  480. m_pConverter->ConverterEntity_AdText(text);
  481. m_pConverter->m_enthead=headback;
  482. return TRUE;
  483. }