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

CAD

开发平台:

Visual C++

  1.  // ExtendInfoIdentify.cpp: implementation of the CExtendInfoIdentify class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "fileswitch.h"
  6. #include "ExtendInfoIdentify.h"
  7. #include "CShow.h"
  8. #include "DataBase.h"
  9. #include "KmEntity.h"
  10. #include "block.h"
  11. #include "KmText.h"
  12. #include "KmSText.h"
  13. #include "KmObject.h"
  14. #include "KmShare.h"
  15. #include "MXManager.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[]=__FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21. //////////////////////////////////////////////////////////////////////
  22. // Construction/Destruction
  23. //////////////////////////////////////////////////////////////////////
  24. CExtendInfoIdentify::CExtendInfoIdentify(KmBuffer* pExtendInfoSource)
  25. {
  26. ASSERT(pExtendInfoSource);
  27. m_pExtendInfoSource=pExtendInfoSource;
  28. }
  29. CExtendInfoIdentify::~CExtendInfoIdentify()
  30. {
  31. ASSERT(m_pExtendInfoSource);
  32. if(m_pExtendInfoSource)
  33. {
  34. m_pExtendInfoSource->ClearKmBuffer();
  35. delete m_pExtendInfoSource;
  36. m_pExtendInfoSource=NULL;
  37. }
  38. }
  39. //从数据库创建扩展信息分析源集合的函数
  40. KmBuffer* CExtendInfoIdentify::CreateExtendInfoSourceBuffer(CKmDataManager* pDataManager,BOOL& bRected,KmRect &rectOutSide)
  41. {
  42. bRected=FALSE;
  43. ASSERT(pDataManager);
  44. if(pDataManager)
  45. {
  46. KmBuffer* pBuffer=new KmBuffer;
  47. CKmDataManager* pBack=::GetActiveDataManager();
  48. ::SetActiveDataManager(pDataManager);
  49. {//处理当前活动数据库,内部禁止处理当前活动数据库。
  50. CShow* pShow = new CGDIShow((CWnd*)NULL);
  51. {//遍历数据库生成扩展信息集合
  52. DICTIONARY_ITEM dic;
  53. KmObject* pObj;
  54. for(UINT i=0;i<::GetEntDicSize();i++)
  55. {
  56. dic=::GetEntDicAt((int)i);
  57. if(dic==NULL)
  58. {
  59. continue;
  60. }
  61. if(dic->IsDerivedFrom(RUNTIME_CLASS(KmBlockRef)))
  62. {
  63. KmIteratorPtr pIterator(pDataManager->CreateIterator(dic));
  64. for(pIterator->First();!pIterator->IsDone();pIterator->Next())
  65. {
  66. pObj=pIterator->CurrentItem();
  67. if(pObj==NULL)
  68. {
  69. continue;
  70. }
  71. if(!pObj->IsVisual())
  72. {
  73. continue;
  74. }
  75. KmObject* pTemp=NULL;
  76. KmBlockRef* pRef=(KmBlockRef*)pObj;
  77. for(UINT j=0;j<pRef->GetObjectNum(TRUE);j++)
  78. {
  79. pRef->GetObjectAt(j,pTemp,TRUE);
  80. if(pTemp==NULL)
  81. {
  82. continue;
  83. }
  84. if(!pTemp->IsKindOf(RUNTIME_CLASS(KmCurve)))
  85. {
  86. if(!pTemp->IsKindOf(RUNTIME_CLASS(KmText)))
  87. {
  88. if(!pTemp->IsKindOf(RUNTIME_CLASS(KmSText)))
  89. {
  90. continue;//只处理曲线和文字
  91. }
  92. }
  93. }
  94. pTemp->Draw(pShow,RGB(0,0,0),DRAWPRESENT,pBuffer);
  95. }
  96. }
  97. continue;//块引用分析完了
  98. }
  99. if(!dic->IsDerivedFrom(RUNTIME_CLASS(KmCurve)))
  100. {
  101. if(!dic->IsDerivedFrom(RUNTIME_CLASS(KmText)))
  102. {
  103. if(!dic->IsDerivedFrom(RUNTIME_CLASS(KmSText)))
  104. {
  105. continue;
  106. }
  107. }
  108. }
  109. KmIteratorPtr pIterator(pDataManager->CreateIterator(dic));
  110. for(pIterator->First();!pIterator->IsDone();pIterator->Next())
  111. {
  112. pObj=pIterator->CurrentItem();
  113. if(pObj==NULL)
  114. {
  115. continue;
  116. }
  117. if(!pObj->IsVisual())
  118. {
  119. continue;
  120. }
  121. pObj->Draw(pShow,RGB(0,0,0),DRAWPRESENT,pBuffer);
  122. }
  123. //分析仅针对块引用、直线和文字而言。
  124. }
  125. }
  126. pShow->UnInitial();
  127. delete pShow;
  128. pShow=NULL;
  129. }
  130. ::SetActiveDataManager(pBack);
  131. CArray<S_LINE_BUFFER*,S_LINE_BUFFER*>* paLines=pBuffer->GetLineBuffer();
  132. S_LINE_BUFFER* pLine=NULL;
  133. for(int index=0;index<paLines->GetSize();index++)
  134. {
  135. pLine=paLines->GetAt(index);
  136. if(pLine!=NULL)
  137. {
  138. if(pLine->LineType==SOLID_LINE)
  139. {
  140. if(pLine->P1!=pLine->P2)
  141. {
  142. if(fabs(pLine->P1.x-pLine->P2.x)<0.01)
  143. {
  144. continue;
  145. }
  146. if(fabs(pLine->P1.y-pLine->P2.y)<0.01)
  147. {
  148. continue;
  149. }
  150. }
  151. }
  152. }
  153. delete paLines->GetAt(index);
  154. paLines->RemoveAt(index);
  155. index--;
  156. }
  157. CArray<S_TEXT*,S_TEXT*>* paTexts=pBuffer->GetTextBuffer();
  158. S_TEXT* pText=NULL;
  159. for(index=0;index<paTexts->GetSize();index++)
  160. {
  161. pText=paTexts->GetAt(index);
  162. if(pText!=NULL)
  163. {
  164. if(fabs(pText->m_nEscapement)<0.01)
  165. {
  166. calculate_text_boundary(pText);
  167. continue;
  168. }
  169. }
  170. delete paTexts->GetAt(index);
  171. paTexts->RemoveAt(index);
  172. index--;
  173. }
  174. return pBuffer;
  175. }
  176. return NULL;
  177. }
  178. //识别图框
  179. BOOL CExtendInfoIdentify::IdentifyLegend(KmLegend* &pLegend,double& dShowScale,KmPoint& ptRightBottom)
  180. {
  181. try
  182. {
  183. /*xlf:识别假设 
  184. 只有一个图框
  185. 图框的线是连续的。
  186. //xlf*/
  187. ASSERT(pLegend);
  188. ASSERT(m_pExtendInfoSource);
  189. int up_line_in =-1, down_line_in =-1, right_line_in =-1, left_line_in =-1,
  190. up_line_out=-1, down_line_out=-1, right_line_out=-1, left_line_out=-1;
  191. double h_length=0.0, v_length=0.0;
  192. double xmin =1.0e8, ymin =1.0e8;
  193. double v_len1=0.0, v_len2=0.0;
  194. BOOL out_boundary_ok =TRUE,in_boundary_ok =TRUE;
  195. //找到外图框
  196. for(int i=0; i<m_pExtendInfoSource->GetLineBuffSize(); i++)
  197. {
  198. // if(m_pExtendInfoSource->GetLineEnt(i)->LineType!=SOLID_LINE)
  199. // {
  200. // continue;
  201. // }
  202. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) < PRECISION) //竖直
  203. {
  204. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x < xmin)       
  205. {
  206. xmin=m_pExtendInfoSource->GetLineEnt(i)->P1.x;
  207. }
  208. if(left_line_out==-1)
  209. {
  210. left_line_out=i;
  211. }
  212. if(right_line_out==-1)
  213. {
  214. right_line_out=i;
  215. }
  216. double minx, maxx;
  217. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) >= v_length*0.85)
  218. {
  219. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length) 
  220. {
  221. v_length =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y);
  222. }
  223. minx =m_pExtendInfoSource->GetLineEnt(left_line_out)->P1.x;
  224. maxx =m_pExtendInfoSource->GetLineEnt(right_line_out)->P1.x;
  225. if(fabs(minx)<=PRECISION)
  226. {
  227. minx =0;
  228. }
  229. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x < minx+PRECISION)
  230. {
  231. left_line_out  =i;
  232. }
  233. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x > maxx-PRECISION)
  234. {
  235. right_line_out =i;
  236. }
  237. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length*1.05)
  238. {
  239. if( fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(left_line_out)->P1.x) 
  240. < fabs(m_pExtendInfoSource->GetLineEnt(right_line_out)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P1.x))
  241. {
  242. left_line_out = i;
  243. }
  244. else
  245. {
  246. right_line_out = i;
  247. }
  248. }
  249. }
  250. else 
  251. {
  252. continue;
  253. }
  254. }
  255. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) < PRECISION)
  256. {
  257. if(m_pExtendInfoSource->GetLineEnt(i)->P1.y<ymin)
  258. {
  259. ymin =m_pExtendInfoSource->GetLineEnt(i)->P1.y;
  260. }
  261. if(up_line_out == -1)
  262. {
  263. up_line_out =i;
  264. }
  265. if(down_line_out == -1)
  266. {
  267. down_line_out =i;
  268. }
  269. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) >= h_length*0.85)
  270. {
  271. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length) 
  272. {
  273. h_length =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x);
  274. }
  275. if(m_pExtendInfoSource->GetLineEnt(i)->P1.y < m_pExtendInfoSource->GetLineEnt(down_line_out)->P1.y+PRECISION)
  276. {
  277. down_line_out = i;
  278. }
  279. else if(m_pExtendInfoSource->GetLineEnt(i)->P1.y > m_pExtendInfoSource->GetLineEnt(up_line_out)->P1.y-PRECISION)
  280. {
  281. up_line_out = i;
  282. }
  283. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length*1.05)
  284. {
  285. if( fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(down_line_out)->P1.y) 
  286. < fabs(m_pExtendInfoSource->GetLineEnt(up_line_out)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P1.y))
  287. {
  288. down_line_out = i;
  289. }
  290. else
  291. {
  292. up_line_out = i; 
  293. }
  294. }
  295. }
  296. else
  297. {
  298. continue;
  299. }
  300. }
  301. }
  302. if(up_line_out == -1 || down_line_out == -1 || right_line_out == -1 || left_line_out == -1)
  303. {
  304. out_boundary_ok  = FALSE;
  305. }
  306. if(out_boundary_ok)
  307. {
  308. out_boundary_ok =calculate_check_boundary(up_line_out, down_line_out, right_line_out ,left_line_out);//检查是否围成矩形框
  309. }
  310. if(out_boundary_ok)
  311. {
  312. double dleft=m_pExtendInfoSource->GetLineEnt(left_line_out)->P1.x;
  313. double dright=m_pExtendInfoSource->GetLineEnt(right_line_out)->P1.x;
  314. double dtop=m_pExtendInfoSource->GetLineEnt(up_line_out)->P1.y;
  315. double dbottom=m_pExtendInfoSource->GetLineEnt(down_line_out)->P1.y;
  316. double dtemp;
  317. if(dleft>dright)
  318. {
  319. dtemp=dright;
  320. dright=dleft;
  321. dleft=dtemp;
  322. }
  323. if(dbottom>dtop)
  324. {
  325. dtemp=dtop;
  326. dtop=dbottom;
  327. dbottom=dtemp;
  328. }
  329. {
  330. double temp=fabs(dleft-dright)*PRECISION;
  331. dleft+=temp;
  332. dright-=temp;
  333. temp=fabs(dtop-dbottom)*PRECISION;
  334. dtop-=temp;
  335. dbottom+=temp;
  336. }
  337. h_length /= 2.0;//外框
  338. v_length /= 2.0;
  339. for(int rate=0;rate<4;rate++)
  340. {
  341. double dratesmall=1.0;
  342. double dratelarge=1.0;
  343. switch(rate)
  344. {
  345. case 0:
  346. dratesmall=0.85;
  347. dratelarge=1.05;
  348. break;
  349. case 1:
  350. dratesmall=0.90;
  351. dratelarge=1.0375;
  352. break;
  353. case 2:
  354. dratesmall=0.95;
  355. dratelarge=1.025;
  356. break;
  357. case 3:
  358. dratesmall=0.99;
  359. dratelarge=1.01;
  360. break;
  361. default:
  362. ASSERT(FALSE);
  363. break;
  364. }
  365. double h_length_2=h_length, v_length_2=v_length;
  366. {
  367. //找内图框
  368. for(i=0; i<m_pExtendInfoSource->GetLineBuffSize(); i++)
  369. {
  370. if(i == left_line_out)
  371. {
  372. continue;
  373. }
  374. if(i == right_line_out)
  375. {
  376. continue;
  377. }
  378. if(i == up_line_out)
  379. {
  380. continue;
  381. }
  382. if(i == down_line_out)
  383. {
  384. continue;
  385. }
  386. /// if(m_pExtendInfoSource->GetLineEnt(i)->LineType!=SOLID_LINE)
  387. // {
  388. // continue;
  389. // }
  390. //竖直的线
  391. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x - m_pExtendInfoSource->GetLineEnt(i)->P2.x) < PRECISION && m_pExtendInfoSource->GetLineEnt(i)->P1.x >dleft && m_pExtendInfoSource->GetLineEnt(i)->P1.x <dright) //竖直
  392. {
  393. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) >= v_length_2*dratesmall)
  394. {
  395. if(left_line_in == -1)
  396. {
  397. left_line_in =i;
  398. }
  399. if(right_line_in == -1)
  400. {
  401. right_line_in =i;
  402. }
  403. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length_2)
  404. {
  405. v_length_2 =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y);
  406. }
  407. if( (m_pExtendInfoSource->GetLineEnt(i)->P1.x < m_pExtendInfoSource->GetLineEnt(left_line_in)->P1.x+PRECISION) 
  408. && (m_pExtendInfoSource->GetLineEnt(i)->P1.x > m_pExtendInfoSource->GetLineEnt(left_line_out)->P1.x-PRECISION))
  409. {
  410. left_line_in = i;
  411. }
  412. if((m_pExtendInfoSource->GetLineEnt(i)->P1.x > m_pExtendInfoSource->GetLineEnt(right_line_in)->P1.x-PRECISION) 
  413. && (m_pExtendInfoSource->GetLineEnt(i)->P1.x < m_pExtendInfoSource->GetLineEnt(right_line_out)->P1.x+PRECISION))
  414. {
  415. right_line_in = i;
  416. }
  417. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length_2*dratesmall)
  418. {
  419. if( fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(left_line_in)->P1.x) 
  420. < fabs(m_pExtendInfoSource->GetLineEnt(right_line_in)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P1.x))
  421. {
  422. left_line_in =i;
  423. }
  424. else
  425. {
  426. right_line_in =i;
  427. }
  428. }
  429. }
  430. else 
  431. {
  432. continue;
  433. }
  434. }
  435. //水平的线
  436. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) < PRECISION&& m_pExtendInfoSource->GetLineEnt(i)->P1.y >dbottom&& m_pExtendInfoSource->GetLineEnt(i)->P1.y <dtop)
  437. {
  438. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) >= h_length_2*dratesmall)
  439. {
  440. if(up_line_in == -1)
  441. {
  442. up_line_in =i;
  443. }
  444. if(down_line_in == -1)
  445. {
  446. down_line_in =i;
  447. }
  448. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length_2)
  449. {
  450. h_length_2 =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x);
  451. }
  452. if((m_pExtendInfoSource->GetLineEnt(i)->P1.y < m_pExtendInfoSource->GetLineEnt(down_line_in)->P1.y)+PRECISION 
  453. && (m_pExtendInfoSource->GetLineEnt(i)->P1.y > m_pExtendInfoSource->GetLineEnt(down_line_out)->P1.y-PRECISION))
  454. {
  455. down_line_in = i;
  456. }
  457. else if((m_pExtendInfoSource->GetLineEnt(i)->P1.y > m_pExtendInfoSource->GetLineEnt(up_line_in)->P1.y)-PRECISION 
  458. && (m_pExtendInfoSource->GetLineEnt(i)->P1.y < m_pExtendInfoSource->GetLineEnt(up_line_out)->P1.y+PRECISION))
  459. {
  460. up_line_in = i;
  461. }
  462. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length_2*dratesmall)
  463. {
  464. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(down_line_in)->P1.y) 
  465. < fabs(m_pExtendInfoSource->GetLineEnt(up_line_in)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P1.y))
  466. {
  467. down_line_in = i;
  468. }
  469. else 
  470. {
  471. up_line_in = i;
  472. }
  473. }
  474. }
  475. else
  476. {
  477. continue;
  478. }
  479. }
  480. }
  481. }
  482. if(up_line_in == -1 || down_line_in == -1 || right_line_in == -1 || left_line_in == -1)
  483. {
  484. in_boundary_ok = FALSE;
  485. }
  486. if(in_boundary_ok)
  487. {
  488. in_boundary_ok  =calculate_check_boundary(up_line_in, down_line_in, right_line_in,left_line_in);//检查是否围成矩形框
  489. if(in_boundary_ok  )
  490. {
  491. break;
  492. }
  493. }
  494. {
  495. if(!in_boundary_ok)
  496. {//使用第二种算法寻找
  497. in_boundary_ok=TRUE;
  498. up_line_in =-1, down_line_in =-1, right_line_in =-1, left_line_in =-1,
  499. xmin =1.0e8, ymin =1.0e8;
  500. v_len1=0.0, v_len2=0.0;
  501. //找到外图框
  502. for(int i=0; i<m_pExtendInfoSource->GetLineBuffSize(); i++)
  503. {
  504. // if(m_pExtendInfoSource->GetLineEnt(i)->LineType!=SOLID_LINE)
  505. // {
  506. // continue;
  507. // }
  508. if(i == left_line_out)
  509. {
  510. continue;
  511. }
  512. if(i == right_line_out)
  513. {
  514. continue;
  515. }
  516. if(i == up_line_out)
  517. {
  518. continue;
  519. }
  520. if(i == down_line_out)
  521. {
  522. continue;
  523. }
  524. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) < PRECISION&& m_pExtendInfoSource->GetLineEnt(i)->P1.x >dleft && m_pExtendInfoSource->GetLineEnt(i)->P1.x <dright) //竖直
  525. {
  526. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x < xmin)       
  527. {
  528. xmin=m_pExtendInfoSource->GetLineEnt(i)->P1.x;
  529. }
  530. if(left_line_in==-1)
  531. {
  532. left_line_in=i;
  533. }
  534. if(right_line_in==-1)
  535. {
  536. right_line_in=i;
  537. }
  538. double minx, maxx;
  539. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) >= v_length_2*dratesmall)
  540. {
  541. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length_2) 
  542. {
  543. v_length_2 =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y);
  544. }
  545. minx =m_pExtendInfoSource->GetLineEnt(left_line_in)->P1.x;
  546. maxx =m_pExtendInfoSource->GetLineEnt(right_line_in)->P1.x;
  547. if(fabs(minx)<=PRECISION)
  548. {
  549. minx =0;
  550. }
  551. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x < minx+PRECISION)
  552. {
  553. left_line_in  =i;
  554. }
  555. if(m_pExtendInfoSource->GetLineEnt(i)->P1.x > maxx-PRECISION)
  556. {
  557. right_line_in =i;
  558. }
  559. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) > v_length_2*dratesmall)
  560. {
  561. if( fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(left_line_in)->P1.x) 
  562. < fabs(m_pExtendInfoSource->GetLineEnt(right_line_in)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P1.x))
  563. {
  564. left_line_in = i;
  565. }
  566. else
  567. {
  568. right_line_in = i;
  569. }
  570. }
  571. }
  572. else 
  573. {
  574. continue;
  575. }
  576. }
  577. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P2.y) < PRECISION&& m_pExtendInfoSource->GetLineEnt(i)->P1.y >dbottom&& m_pExtendInfoSource->GetLineEnt(i)->P1.y <dtop)
  578. {
  579. if(m_pExtendInfoSource->GetLineEnt(i)->P1.y<ymin)
  580. {
  581. ymin =m_pExtendInfoSource->GetLineEnt(i)->P1.y;
  582. }
  583. if(up_line_in == -1)
  584. {
  585. up_line_in =i;
  586. }
  587. if(down_line_in == -1)
  588. {
  589. down_line_in =i;
  590. }
  591. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) >= h_length_2*dratesmall)
  592. {
  593. if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length_2) 
  594. {
  595. h_length_2 =fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x);
  596. }
  597. if(m_pExtendInfoSource->GetLineEnt(i)->P1.y < m_pExtendInfoSource->GetLineEnt(down_line_in)->P1.y+PRECISION)
  598. {
  599. down_line_in = i;
  600. }
  601. else if(m_pExtendInfoSource->GetLineEnt(i)->P1.y > m_pExtendInfoSource->GetLineEnt(up_line_in)->P1.y-PRECISION)
  602. {
  603. up_line_in = i;
  604. }
  605. else if(fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.x-m_pExtendInfoSource->GetLineEnt(i)->P2.x) > h_length_2*dratesmall)
  606. {
  607. if( fabs(m_pExtendInfoSource->GetLineEnt(i)->P1.y-m_pExtendInfoSource->GetLineEnt(down_line_in)->P1.y) 
  608. < fabs(m_pExtendInfoSource->GetLineEnt(up_line_in)->P1.y-m_pExtendInfoSource->GetLineEnt(i)->P1.y))
  609. {
  610. down_line_in = i;
  611. }
  612. else
  613. {
  614. up_line_in = i; 
  615. }
  616. }
  617. }
  618. else
  619. {
  620. continue;
  621. }
  622. }
  623. }
  624. if(up_line_in == -1 || down_line_in == -1 || right_line_in == -1 || left_line_in == -1)
  625. {
  626. in_boundary_ok  = FALSE;
  627. }
  628. if(in_boundary_ok)
  629. {
  630. in_boundary_ok  =calculate_check_boundary(up_line_in, down_line_in, right_line_in,left_line_in);//检查是否围成矩形框
  631. if(in_boundary_ok)
  632. {
  633. break;
  634. }
  635. }
  636. }
  637. }
  638. }
  639. }
  640. if(out_boundary_ok) //图框找对
  641. {
  642. double dleft=m_pExtendInfoSource->GetLineEnt(left_line_out)->P1.x;
  643. double dright=m_pExtendInfoSource->GetLineEnt(right_line_out)->P1.x;
  644. double dtop=m_pExtendInfoSource->GetLineEnt(up_line_out)->P1.y;
  645. double dbottom=m_pExtendInfoSource->GetLineEnt(down_line_out)->P1.y;
  646. if(in_boundary_ok)
  647. {
  648. double dleftin=m_pExtendInfoSource->GetLineEnt(left_line_in)->P1.x;
  649. double drightin=m_pExtendInfoSource->GetLineEnt(right_line_in)->P1.x;
  650. double dtopin=m_pExtendInfoSource->GetLineEnt(up_line_in)->P1.y;
  651. double dbottomin=m_pExtendInfoSource->GetLineEnt(down_line_in)->P1.y;
  652. ptRightBottom.x=drightin;
  653. ptRightBottom.y=dbottomin;
  654. if(pLegend->SetRect(dleft,dright,dtop,dbottom,dleftin,drightin,dtopin,dbottomin,TRUE,dShowScale))
  655. {
  656. return TRUE;
  657. }
  658. }
  659. else
  660. {
  661. ptRightBottom.x=dright;
  662. ptRightBottom.y=dbottom;
  663. if(pLegend->SetRect(dleft,dright,dtop,dbottom,0.0,0.0,0.0,0.0,FALSE,dShowScale))
  664. {
  665. return TRUE;
  666. }
  667. }
  668. }
  669. else
  670. {
  671. dShowScale=-1;
  672. return FALSE;
  673. }
  674. }
  675. catch(...)
  676. {
  677. dShowScale=-1;
  678. return FALSE;
  679. }
  680. dShowScale=-1;
  681. return FALSE;
  682. }
  683. void CExtendInfoIdentify::calculate_text_boundary(S_TEXT* &pText)
  684. {
  685. int nSize=strlen(pText->m_czText);
  686. int nSpecChars=nSize-1;
  687. for(int i=0; i<nSize; i++)
  688. {
  689. if(IsDBCSLeadByte(pText->m_czText[i]))///判断是否为双字节 
  690. i++;
  691. nSpecChars--;
  692. }
  693. }
  694. //角度已知为0
  695. pText->m_nWidth=nSize*pText->m_nWidth*0.5+pText->m_dSpace*nSpecChars;
  696. pText->m_Offset.x+=pText->m_nWidth*0.5;
  697. pText->m_Offset.y-=pText->m_nHeight*0.5;
  698. pText->m_nWidth*=0.9;//缩小百分之十
  699. pText->m_nHeight*=0.9;//缩小百分之十
  700. }
  701. //检查是否围成矩形框
  702. //up_line     上框线
  703. //down_line   下框线
  704. //right_line  右框线
  705. //left_line   左框线
  706. BOOL CExtendInfoIdentify::calculate_check_boundary(int up_line, int down_line,int right_line, int left_line )
  707. {
  708. BOOL flag = TRUE;
  709. double temp;
  710. double up_line_xb,up_line_yb,up_line_xe,up_line_ye;
  711. double down_line_xb,down_line_yb,down_line_xe,down_line_ye;
  712. double left_line_xb,left_line_yb,left_line_xe,left_line_ye;
  713. double right_line_xb,right_line_yb,right_line_xe,right_line_ye;
  714. up_line_xb=m_pExtendInfoSource->GetLineEnt(up_line)->P1.x;
  715. up_line_yb=m_pExtendInfoSource->GetLineEnt(up_line)->P1.y;
  716. up_line_xe=m_pExtendInfoSource->GetLineEnt(up_line)->P2.x;
  717. up_line_ye=m_pExtendInfoSource->GetLineEnt(up_line)->P2.y;
  718. down_line_xb=m_pExtendInfoSource->GetLineEnt(down_line)->P1.x;
  719. down_line_yb=m_pExtendInfoSource->GetLineEnt(down_line)->P1.y;
  720. down_line_xe=m_pExtendInfoSource->GetLineEnt(down_line)->P2.x;
  721. down_line_ye=m_pExtendInfoSource->GetLineEnt(down_line)->P2.y;
  722. left_line_xb=m_pExtendInfoSource->GetLineEnt(left_line)->P1.x;
  723. left_line_yb=m_pExtendInfoSource->GetLineEnt(left_line)->P1.y;
  724. left_line_xe=m_pExtendInfoSource->GetLineEnt(left_line)->P2.x;
  725. left_line_ye=m_pExtendInfoSource->GetLineEnt(left_line)->P2.y;
  726. right_line_xb=m_pExtendInfoSource->GetLineEnt(right_line)->P1.x;
  727. right_line_yb=m_pExtendInfoSource->GetLineEnt(right_line)->P1.y;
  728. right_line_xe=m_pExtendInfoSource->GetLineEnt(right_line)->P2.x;
  729. right_line_ye=m_pExtendInfoSource->GetLineEnt(right_line)->P2.y;
  730. if( up_line_xb > up_line_xe )
  731. {
  732. temp = up_line_xb;
  733. up_line_xb = up_line_xe;
  734. up_line_xe = temp;
  735. }
  736. if( down_line_xb > down_line_xe )
  737. {
  738. temp = down_line_xb;
  739. down_line_xb =  down_line_xe;
  740. down_line_xe = temp;
  741. }
  742. if( left_line_yb > left_line_ye )
  743. {
  744. temp = left_line_yb;
  745. left_line_yb = left_line_ye;
  746. left_line_ye = temp;
  747. }
  748. if( right_line_yb > right_line_ye )
  749. {
  750. temp = right_line_yb;
  751. right_line_yb = right_line_ye;
  752. right_line_ye = temp;
  753. }
  754. if( fabs(up_line_xb - down_line_xb) > 2 ||
  755. fabs(up_line_xe - down_line_xe) > 2 )
  756. {
  757. flag = FALSE;
  758. return flag;
  759. }
  760. if( fabs(left_line_yb - right_line_yb) > 2 ||
  761. fabs(left_line_ye - right_line_ye) > 2 )
  762. {
  763. flag = FALSE;
  764. return flag;
  765. }
  766. if( fabs( (up_line_yb - down_line_yb) - (right_line_ye - right_line_yb) ) > 4 )
  767. {
  768. flag = FALSE;
  769. return flag;
  770. }
  771. if( fabs( (right_line_xb - left_line_xb) - (up_line_xe - up_line_xb) ) > 4 )
  772. {
  773. flag = FALSE;
  774. return flag;
  775. }
  776. return flag;
  777. }
  778. CCellInfo::CCellInfo()
  779. {
  780. m_strCellInfo="";
  781. m_strCellData="";
  782. }
  783. CCellInfo::CCellInfo(CCellInfo& cCellInfo)
  784. {
  785. m_strCellInfo=cCellInfo.m_strCellInfo;
  786. m_strCellData=cCellInfo.m_strCellData;
  787. m_cRect=cCellInfo.m_cRect;
  788. }
  789. CCellInfo::~CCellInfo()
  790. {
  791. }
  792. void CCellInfo::Zoom(double dScale)
  793. {
  794. m_cRect.left=m_cRect.left*dScale;
  795. m_cRect.right=m_cRect.right*dScale;
  796. m_cRect.bottom=m_cRect.bottom*dScale;
  797. m_cRect.top=m_cRect.top*dScale;
  798. }
  799. void CCellInfo::Move(KmPoint ptOffset)
  800. {
  801. m_cRect.left+=ptOffset.x;
  802. m_cRect.right+=ptOffset.x;
  803. m_cRect.bottom+=ptOffset.y;
  804. m_cRect.top+=ptOffset.y;
  805. }
  806. BOOL CCellInfo::IsSurround(KmBuffer* pData)
  807. {
  808. double dWidthPrec=m_cRect.Width()*0.1;//精度为宽度得十分之一
  809. double dHeightPrec=m_cRect.Height()*0.1;
  810. double dleft=m_cRect.left+dWidthPrec;
  811. double dright=m_cRect.right-dWidthPrec;
  812. double dbottom=m_cRect.bottom+dHeightPrec;
  813. double dtop=m_cRect.top-dHeightPrec;
  814. double dTemp;
  815. BOOL bleft=FALSE;
  816. BOOL bright=FALSE;
  817. BOOL bbottom=FALSE;
  818. BOOL btop=FALSE;
  819. ASSERT(pData);
  820. S_LINE_BUFFER* pLine=NULL;
  821. for(int i=0;i<pData->GetLineBuffSize();i++)
  822. {
  823. pLine=pData->GetLineEnt(i);
  824. if(fabs(pLine->P1.x-pLine->P2.x)<0.01)
  825. {
  826. if(pLine->P1.y>pLine->P2.y)
  827. {
  828. dTemp=pLine->P1.y;
  829. pLine->P1.y=pLine->P2.y;
  830. pLine->P2.y=dTemp;
  831. }
  832. //p1.y <= p2.y
  833. if(!bleft)
  834. {
  835. if(fabs(pLine->P1.x-m_cRect.left)<dWidthPrec)
  836. {
  837. if(dbottom>pLine->P1.y&&dtop<pLine->P2.y)
  838. {
  839. bleft=TRUE;
  840. if(bleft&&bright&&bbottom&&btop)
  841. {
  842. return TRUE;
  843. }
  844. }
  845. }
  846. }
  847. if(!bright)
  848. {
  849. if(fabs(pLine->P1.x-m_cRect.right)<dWidthPrec)
  850. {
  851. if(dbottom>pLine->P1.y&&dtop<pLine->P2.y)
  852. {
  853. bright=TRUE;
  854. if(bleft&&bright&&bbottom&&btop)
  855. {
  856. return TRUE;
  857. }
  858. }
  859. }
  860. }
  861. }
  862. if(fabs(pLine->P1.y-pLine->P2.y)<0.01)
  863. {
  864. if(pLine->P1.x>pLine->P2.x)
  865. {
  866. dTemp=pLine->P1.x;
  867. pLine->P1.x=pLine->P2.x;
  868. pLine->P2.x=dTemp;
  869. }
  870. //p1.x <= p2.x
  871. if(!bbottom)
  872. {
  873. if(fabs(pLine->P1.y-m_cRect.bottom)<dHeightPrec)
  874. {
  875. if(dleft>pLine->P1.x&&dright<pLine->P2.x)
  876. {
  877. bbottom=TRUE;
  878. if(bleft&&bright&&bbottom&&btop)
  879. {
  880. return TRUE;
  881. }
  882. }
  883. }
  884. }
  885. if(!btop)
  886. {
  887. if(fabs(pLine->P1.y-m_cRect.top)<dHeightPrec)
  888. {
  889. if(dleft>pLine->P1.x&&dright<pLine->P2.x)
  890. {
  891. btop=TRUE;
  892. if(bleft&&bright&&bbottom&&btop)
  893. {
  894. return TRUE;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. return FALSE;
  902. }
  903. void CCellInfo::SetData(KmBuffer* pData,BOOL &bWordStyle,CWordStyle& ws)
  904. {
  905. double dWidth=m_cRect.Width();
  906. double dHeight=m_cRect.Height();
  907. m_strCellData.Empty();
  908. S_TEXT* pText=NULL;
  909. CArray<S_TEXT*,S_TEXT*>aTexts;
  910. CArray<S_TEXT*,S_TEXT*>* paTexts=pData->GetTextBuffer();
  911. for(int i=0;i<paTexts->GetSize();i++)
  912. {
  913. pText=paTexts->GetAt(i);
  914. if(pText)
  915. {
  916. if(m_cRect.PtInRect(pText->m_Offset))
  917. {
  918. //1.中心点在矩形内.
  919. if(dWidth>pText->m_nWidth&&dHeight>pText->m_nHeight)
  920. {
  921. if(bWordStyle)
  922. {
  923. ws.SetFontName(pText->m_lpszFacename);
  924. ws.SetHeight(pText->m_nHeight);
  925. try
  926. {
  927. ws.SetWFactor(pText->m_nWidth/pText->m_nHeight);
  928. }
  929. catch (...) {
  930. }
  931. bWordStyle=FALSE;
  932. }
  933. paTexts->RemoveAt(i);
  934. i--;
  935. aTexts.Add(pText);
  936. }
  937. }
  938. }
  939. }
  940. if(aTexts.GetSize())
  941. {
  942. if(aTexts.GetSize()==1)
  943. {
  944. m_strCellData=aTexts[0]->m_czText;
  945. }
  946. else
  947. {
  948. int j=0;
  949. S_TEXT* pTemp=NULL;
  950. for(i=aTexts.GetSize()-1;i>=0;i--)
  951. {
  952. for(j=0;j<i;j++)
  953. {
  954. //按Y从大到小 如果Y相同 X从小到大排序。
  955. if(fabs(aTexts[i]->m_Offset.y-aTexts[j]->m_Offset.y)<(aTexts[i]->m_nHeight*0.4))
  956. {
  957. if(aTexts[i]->m_Offset.x<aTexts[j]->m_Offset.x)
  958. {
  959. pTemp=aTexts[i];
  960. aTexts[i]=aTexts[j];
  961. aTexts[j]=pTemp;
  962. }
  963. }
  964. else if(aTexts[i]->m_Offset.y>aTexts[j]->m_Offset.y)
  965. {
  966. pTemp=aTexts[i];
  967. aTexts[i]=aTexts[j];
  968. aTexts[j]=pTemp;
  969. }
  970. }
  971. }
  972. for(i=0;i<aTexts.GetSize();i++)
  973. {
  974. m_strCellData+=aTexts[i]->m_czText;
  975. }
  976. }
  977. for(i=0;i<aTexts.GetSize();i++)
  978. {
  979. delete aTexts[i];
  980. }
  981. aTexts.RemoveAll();
  982. }
  983. }
  984. CProductInfo::CProductInfo()
  985. {
  986. m_bHaveBiaoTi=TRUE;
  987. }
  988. CProductInfo::~CProductInfo()
  989. {
  990. }
  991. void CProductInfo::SetBaseInfo(KmPoint ptRightBottom,double dShowScale)
  992. {
  993. m_ptRightBottom=ptRightBottom; //右下角
  994. m_dBiaoTiHight*=dShowScale; //标题栏高度
  995. m_dBiaoTiWidth*=dShowScale; //标题栏宽度
  996. m_dMingXiBottomHight*=dShowScale;//明细底栏高度
  997. m_dMingXiHight*=dShowScale; //明细栏高度
  998. m_dMingXiWidth*=dShowScale; //明细栏宽度
  999. for(int i=0;i<m_aBiaoTi.GetSize();i++)
  1000. {
  1001. m_aBiaoTi[i].Zoom(dShowScale);
  1002. m_aBiaoTi[i].Move(ptRightBottom);
  1003. }//标题栏CELL
  1004. // for(i=0;i<m_aMingXiBottom.GetSize();i++)
  1005. // {
  1006. // m_aMingXiBottom[i].Zoom(dShowScale);
  1007. // m_aMingXiBottom[i].Move(ptRightBottom);
  1008. // }//明细底栏CELL
  1009. for(i=0;i<m_aMingXi.GetSize();i++)
  1010. {
  1011. m_aMingXi[i].Zoom(dShowScale);
  1012. m_aMingXi[i].Move(ptRightBottom);
  1013. }//明细栏CELL
  1014. }
  1015. BOOL CProductInfo::LoadFromFile(CString strFileName)
  1016. {
  1017. try
  1018. {
  1019. CString strTemp;
  1020. CStdioFile file;
  1021. if(!file.Open(strFileName, CFile::modeRead))
  1022. {
  1023. return FALSE;
  1024. }
  1025. while(file.ReadString(strTemp))
  1026. {
  1027. if(strTemp=="@@标题栏@@")
  1028. {
  1029. if(!file.ReadString(strTemp))
  1030. {
  1031. return FALSE;
  1032. }
  1033. int iCount=0;
  1034. if(::sscanf(strTemp,"%d,%lf,%lf",&iCount,&m_dBiaoTiWidth,&m_dBiaoTiHight)!=3)
  1035. {
  1036. if(::sscanf(strTemp,"%lf,%lf",&m_dBiaoTiWidth,&m_dBiaoTiHight)!=2)
  1037. {//兼容模式读取。
  1038. return FALSE;
  1039. }
  1040. }
  1041. for(int i=0;i<iCount;i++)
  1042. {
  1043. CCellInfo cCellInfo;
  1044. if(!file.ReadString(strTemp))
  1045. {
  1046. return FALSE;
  1047. }
  1048. int index;
  1049. int iPos=-1;
  1050. iPos=strTemp.Find(',');
  1051. if(iPos==-1)
  1052. {
  1053. return FALSE;
  1054. }
  1055. cCellInfo.m_strCellInfo=strTemp.Right(strTemp.GetLength()-1-iPos);
  1056. strTemp=strTemp.Left(iPos);
  1057. index=::atoi(strTemp);
  1058. if(!file.ReadString(strTemp))
  1059. {
  1060. return FALSE;
  1061. }
  1062. if(::sscanf(strTemp,"%lf,%lf,%lf,%lf",&cCellInfo.m_cRect.left,&cCellInfo.m_cRect.bottom,&cCellInfo.m_cRect.right,&cCellInfo.m_cRect.top)!=4)
  1063. {
  1064. return FALSE;
  1065. }
  1066. cCellInfo.m_cRect.right=cCellInfo.m_cRect.left+cCellInfo.m_cRect.right;
  1067. cCellInfo.m_cRect.top=cCellInfo.m_cRect.bottom+cCellInfo.m_cRect.top;
  1068. m_aBiaoTi.Add(cCellInfo);
  1069. }
  1070. }
  1071. else if(strTemp=="@@明细栏@@")
  1072. {
  1073. if(!file.ReadString(strTemp))
  1074. {
  1075. return FALSE;
  1076. }
  1077. int iCount=0;
  1078. double dTemp1,dTemp2,dTemp3;
  1079. int iTemp;
  1080. //明细栏排列方式(暂固定为1),明细栏列数,明细栏宽,明细底栏高,明细栏数据栏高,
  1081. if(::sscanf(strTemp,"%d,%d,%lf,%lf,%lf,%d,%d,%d",&iTemp,&iCount,&m_dMingXiWidth,&m_dMingXiBottomHight,&m_dMingXiHight,&dTemp1,&dTemp2,&dTemp3)!=8)
  1082. {
  1083. return FALSE;
  1084. }
  1085. for(int i=0;i<iCount;i++)
  1086. {
  1087. CCellInfo cCellInfo;
  1088. if(!file.ReadString(strTemp))
  1089. {
  1090. return FALSE;
  1091. }
  1092. int index;
  1093. int iPos=-1;
  1094. iPos=strTemp.Find(',');
  1095. if(iPos==-1)
  1096. {
  1097. return FALSE;
  1098. }
  1099. cCellInfo.m_strCellInfo=strTemp.Right(strTemp.GetLength()-1-iPos);
  1100. strTemp=strTemp.Left(iPos);
  1101. index=::atoi(strTemp);
  1102. if(!file.ReadString(strTemp))
  1103. {
  1104. return FALSE;
  1105. }
  1106. if(index!=i+1)
  1107. {
  1108. i--;
  1109. continue;
  1110. }
  1111. iPos=strTemp.Find(',');
  1112. if(iPos==-1)
  1113. {
  1114. return FALSE;
  1115. }
  1116. cCellInfo.m_cRect.left=::atof(strTemp.Left(iPos));
  1117. strTemp=strTemp.Right(strTemp.GetLength()-1-iPos);
  1118. iPos=strTemp.Find(',');
  1119. if(iPos==-1)
  1120. {
  1121. return FALSE;
  1122. }
  1123. cCellInfo.m_cRect.right=::atof(strTemp.Left(iPos));
  1124. strTemp=strTemp.Right(strTemp.GetLength()-1-iPos);//对齐方式
  1125. {
  1126. cCellInfo.m_cRect.right=cCellInfo.m_cRect.left+cCellInfo.m_cRect.right;
  1127. cCellInfo.m_cRect.left-=m_dMingXiWidth;
  1128. cCellInfo.m_cRect.right-=m_dMingXiWidth;
  1129. }
  1130. cCellInfo.m_cRect.bottom=0.0;
  1131. cCellInfo.m_cRect.top=m_dMingXiBottomHight;
  1132. m_aMingXiBottom.Add(cCellInfo);
  1133. cCellInfo.m_cRect.top=m_dMingXiHight;
  1134. m_aMingXi.Add(cCellInfo);
  1135. }
  1136. }
  1137. }
  1138. }
  1139. catch(...)
  1140. {
  1141. return FALSE;
  1142. }
  1143. return TRUE;
  1144. }
  1145. void CProductInfo::SetHaveBiaoTi(BOOL bHaveBiaoTi)
  1146. {
  1147. m_bHaveBiaoTi=bHaveBiaoTi;
  1148. }
  1149. void CProductInfo::SetMingXiBottom()
  1150. {
  1151. // if(m_bHaveBiaoTi)
  1152. // {
  1153. // KmPoint ptOffset;
  1154. // ptOffset.x=0.0;
  1155. // ptOffset.y=m_dBiaoTiHight;
  1156. // for(int i=0;i<m_aMingXiBottom.GetSize();i++)
  1157. // {
  1158. // m_aMingXiBottom[i].Move(ptOffset);
  1159. // }//明细底栏CELL
  1160. // }
  1161. }
  1162. void CProductInfo::SetMingXi(int ix,int iy)
  1163. {
  1164. KmPoint ptOffset;
  1165. if(m_bHaveBiaoTi)
  1166. {
  1167. if(ix<1)
  1168. {//第一列
  1169. ptOffset.x=-1*m_dMingXiWidth*ix;
  1170. ptOffset.y=m_dBiaoTiHight+m_dMingXiBottomHight+m_dMingXiHight*iy;
  1171. }
  1172. else
  1173. {//第二列以上
  1174. ptOffset.x=-1*m_dBiaoTiWidth-1*m_dMingXiWidth*(ix-1);
  1175. ptOffset.y=m_dMingXiBottomHight+m_dMingXiHight*iy;
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if(ix<1)
  1181. {//第一列
  1182. ptOffset.x=-1*m_dMingXiWidth*ix;
  1183. ptOffset.y=m_dBiaoTiHight+m_dMingXiBottomHight+m_dMingXiHight*iy;
  1184. }
  1185. else
  1186. {//第二列以上
  1187. ptOffset.x=-1*m_dMingXiWidth*ix;
  1188. ptOffset.y=m_dMingXiBottomHight+m_dMingXiHight*iy;
  1189. }
  1190. }
  1191. m_aMingXiTemp.RemoveAll();
  1192. int j=0;
  1193. for(int i=0;i<m_aMingXi.GetSize();i++)
  1194. {
  1195. j=m_aMingXiTemp.Add(m_aMingXi[i]);
  1196. m_aMingXiTemp[j].Move(ptOffset);
  1197. }
  1198. }
  1199. BOOL CExtendInfoIdentify::IdentifyProductInfo(double dShowScale,KmPoint ptRightBottom,CKmDataManager* pDataMgr)
  1200. {
  1201. BOOL bWordStyle;
  1202. CWordStyle ws;
  1203. if(!pDataMgr)
  1204. {
  1205. return FALSE;
  1206. }
  1207. char szFileName[MAX_PATH+100];
  1208. ::GetModuleFileName(NULL,szFileName,MAX_PATH);
  1209. (*::strrchr(szFileName, '\' ))='';
  1210. ::strcat(szFileName, "\support\minxiconv.con");
  1211. CProductInfo cProductInfo;
  1212. if(!cProductInfo.LoadFromFile(szFileName))
  1213. {
  1214. ::GetModuleFileName(NULL,szFileName,MAX_PATH);
  1215. (*::strrchr(szFileName, '\' ))='';
  1216. ::strcat(szFileName, "\support\mingxiconv.con");
  1217. if(!cProductInfo.LoadFromFile(szFileName))
  1218. {
  1219. return FALSE;
  1220. }
  1221. }
  1222. cProductInfo.SetBaseInfo(ptRightBottom,1/dShowScale);
  1223. BOOL bHaveBiaoTi=TRUE;
  1224. if(!pDataMgr->GetPicInfoPtr())
  1225. {
  1226. bHaveBiaoTi=FALSE;
  1227. }
  1228. else
  1229. {
  1230. for(int i=0;i<cProductInfo.m_aBiaoTi.GetSize();i++)
  1231. {
  1232. if(!cProductInfo.m_aBiaoTi[i].IsSurround(m_pExtendInfoSource))
  1233. {
  1234. bHaveBiaoTi=FALSE;
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. if(bHaveBiaoTi&&pDataMgr->GetPicInfoPtr())
  1240. {
  1241. PICINFO cInfo;
  1242. cInfo=pDataMgr->GetPicInfoPtr()->GetPicInfo();
  1243. cInfo.Flag=0x330000;
  1244. for(int i=0;i<cInfo.ValueField.GetSize();i++)
  1245. {
  1246. cInfo.ValueField[i].Empty();
  1247. }
  1248. bWordStyle=FALSE;
  1249. //识别标题栏
  1250. for(i=0;i<cProductInfo.m_aBiaoTi.GetSize();i++)
  1251. {
  1252. cProductInfo.m_aBiaoTi[i].SetData(m_pExtendInfoSource,bWordStyle,ws);
  1253. for(int j=0;j<cInfo.AttribField.GetSize();j++)
  1254. {
  1255. if(cProductInfo.m_aBiaoTi[i].m_strCellInfo==cInfo.AttribField[j])
  1256. {
  1257. cInfo.ValueField[j]=cProductInfo.m_aBiaoTi[i].m_strCellData;
  1258. break;
  1259. }
  1260. }
  1261. //不匹配不予处理
  1262. // if(!bFind)
  1263. // {
  1264. // cInfo.AttribField.Add(cProductInfo.m_aBiaoTi[i].m_strCellInfo);
  1265. // cInfo.ValueField.Add(cProductInfo.m_aBiaoTi[i].m_strCellData);
  1266. // }
  1267. }
  1268. pDataMgr->GetPicInfoPtr()->SetPicInfo(cInfo);
  1269. // KmMxManager mxmgr;
  1270. // mxmgr.GenerateBiaotiTable();
  1271. }
  1272. cProductInfo.SetHaveBiaoTi(bHaveBiaoTi);
  1273. BOOL bHaveMingXi=TRUE;
  1274. //由于配置文件中没有明细底栏分两行时底高度信息,故不判断
  1275. // cProductInfo.SetMingXiBottom();
  1276. // for(int i=0;i<cProductInfo.m_aMingXiBottom.GetSize();i++)
  1277. // {
  1278. // if(!cProductInfo.m_aMingXiBottom[i].IsSurround(m_pExtendInfoSource))
  1279. // {
  1280. // bHaveMingXi=FALSE;
  1281. // break;
  1282. // }
  1283. // }
  1284. int utMingXiText=-1;
  1285. if(bHaveMingXi)
  1286. {
  1287. //设置明细配置项数组
  1288. KmMxConfig* pMxConfig=pDataMgr->GetMxConfig();
  1289. if(pMxConfig)
  1290. {
  1291. pMxConfig->m_BomHeight=cProductInfo.m_dMingXiBottomHight*dShowScale;
  1292. pMxConfig->m_OtherHeight=cProductInfo.m_dMingXiHight*dShowScale;
  1293. KmMxContent* pMxContent=pDataMgr->GetMxContent();
  1294. if(pMxConfig&&pMxContent)
  1295. {
  1296. //首先清空明细记录。
  1297. KmMxRec* pOld=NULL;
  1298. while(pMxContent->RemoveMxRecAt(0,pOld))
  1299. {
  1300. delete pOld;
  1301. pOld=NULL;
  1302. }
  1303. //然后清空明细配置
  1304. CArray<MxConfigItem,MxConfigItem>* pMxConfigItems=pMxConfig->GetConfigItems();
  1305. ASSERT(pMxConfigItems);
  1306. pMxConfigItems->RemoveAll();
  1307. //再添加明细配置
  1308. MxConfigItem cMxConfigItem;
  1309. for(int i=0;i<cProductInfo.m_aMingXiBottom.GetSize();i++)
  1310. {
  1311. cMxConfigItem.m_uIndex=(UINT)(i+1);//从1开始
  1312. cMxConfigItem.m_strName=cProductInfo.m_aMingXiBottom[i].m_strCellInfo;
  1313. cMxConfigItem.m_fColWidth=cProductInfo.m_aMingXiBottom[i].m_cRect.Width();
  1314. cMxConfigItem.m_uAlignMode=KT_ALIGN_CENTER|KT_ALIGN_LEFT;
  1315. pMxConfigItems->Add(cMxConfigItem);
  1316. }
  1317. KmMxRec cKmMxRec;
  1318. int index=0;
  1319. int ix=0;
  1320. do
  1321. {
  1322. int iy=0;
  1323. do
  1324. {
  1325. {//doing
  1326. cProductInfo.SetMingXi(ix,iy);
  1327. BOOL bRight=TRUE;
  1328. for(int i=0;i<cProductInfo.m_aMingXiTemp.GetSize();i++)
  1329. {
  1330. if(!cProductInfo.m_aMingXiTemp[i].IsSurround(m_pExtendInfoSource))
  1331. {
  1332. bRight=FALSE;
  1333. break;
  1334. }
  1335. }
  1336. if(!bRight)
  1337. {
  1338. ix=10000;
  1339. iy=10000;
  1340. break;
  1341. }
  1342. //读出一条明细内容。
  1343. cKmMxRec.m_uFlag=OTHER_MX;
  1344. cKmMxRec.m_aContent.RemoveAll();
  1345. for(i=0;i<cProductInfo.m_aMingXiTemp.GetSize();i++)
  1346. {
  1347. if(utMingXiText<=0)
  1348. {
  1349. bWordStyle=TRUE;
  1350. cProductInfo.m_aMingXiTemp[i].SetData(m_pExtendInfoSource,bWordStyle,ws);
  1351. if(!bWordStyle)
  1352. {
  1353. ws.SetHeight(ws.GetHeight()*dShowScale);
  1354. utMingXiText=pDataMgr->AddWordStyle(ws);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. bWordStyle=FALSE;
  1360. cProductInfo.m_aMingXiTemp[i].SetData(m_pExtendInfoSource,bWordStyle,ws);
  1361. ws.SetHeight(ws.GetHeight()*dShowScale);
  1362. }
  1363. cKmMxRec.m_aContent.Add(cProductInfo.m_aMingXiTemp[i].m_strCellData);
  1364. }
  1365. //写到东方CAD中去。
  1366. pMxContent->AddMxRec(cKmMxRec);
  1367. }
  1368. iy++;
  1369. }
  1370. while(iy<200);//最多200列
  1371. ix++;
  1372. }
  1373. while(ix<10);//最多十行
  1374. }
  1375. for(int m=0;m<pMxContent->GetMxRecNum();m++)
  1376. pMxContent->GetMxRecAt(m).Release();
  1377. pMxContent->SetBaseWSID(utMingXiText);
  1378. CKmDataManager* pBack=::GetActiveDataManager();
  1379. ::SetActiveDataManager(pDataMgr);
  1380. KmMxManager mxmgr;
  1381. mxmgr.GenerateMxTable(TRUE);
  1382. mxmgr.HideMx(TRUE,NULL);
  1383. ::SetActiveDataManager(pBack);
  1384. }
  1385. }
  1386. return TRUE;
  1387. }