GraphSoftDoc.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:19k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // GraphSoftDoc.cpp : implementation of the CGraphSoftDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "GraphSoft.h"
  5. #include "MainFrm.h"
  6. #include "GraphSoftDoc.h"
  7. #include "GraphSoftView.h"
  8. #include "GraphDefines.h"
  9. #include "FullViewBtn.h"
  10. #include "UND_Create.h"
  11. #include "UND_Move.h"
  12. #include "UND_Rotate.h"
  13. #include "UND_Magnify.h"
  14. #include "UND_ShowPoints.h"
  15. #include "UND_TopToBtm.h"
  16. #include "UND_LeftToRight.h"
  17. #include "UND_Delete.h"
  18. #include "UND_Copy.h"
  19. #include "UND_Edit.h"
  20. #include "UND_Property.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CGraphSoftDoc
  28. IMPLEMENT_DYNCREATE(CGraphSoftDoc, CDocument)
  29. BEGIN_MESSAGE_MAP(CGraphSoftDoc, CDocument)
  30. //{{AFX_MSG_MAP(CGraphSoftDoc)
  31. ON_COMMAND(ID_FILE_NEW, OnFileNew)
  32. ON_COMMAND(ID_FILE_IMPORT, OnFileImport)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CGraphSoftDoc construction/destruction
  37. CGraphSoftDoc::CGraphSoftDoc()
  38. {
  39. // TODO: add one-time construction code here
  40.      m_nCurrentShapeType=_shape_none;  
  41.  m_pCore=new CCore(this,NULL);
  42.  m_sizeDoc = CSize(800*36,650*36);//36最大扩大倍数
  43. }
  44. CGraphSoftDoc::~CGraphSoftDoc()
  45. {
  46. delete m_pCore;
  47. }
  48. BOOL CGraphSoftDoc::OnNewDocument()
  49. {
  50.  
  51. if (!CDocument::OnNewDocument())
  52. return FALSE;
  53. // TODO: add reinitialization code here
  54. // (SDI documents will reuse this document)
  55. return TRUE;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CGraphSoftDoc serialization
  59. void CGraphSoftDoc::Serialize(CArchive& ar)
  60. {
  61. if (ar.IsStoring())
  62. {
  63. // TODO: add storing code here
  64. }
  65. else
  66. {
  67. // TODO: add loading code here
  68. }
  69. m_shapeList.Serialize(ar);
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CGraphSoftDoc diagnostics
  73. #ifdef _DEBUG
  74. void CGraphSoftDoc::AssertValid() const
  75. {
  76. CDocument::AssertValid();
  77. }
  78. void CGraphSoftDoc::Dump(CDumpContext& dc) const
  79. {
  80. CDocument::Dump(dc);
  81. }
  82. #endif //_DEBUG
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CGraphSoftDoc commands
  85. void CGraphSoftDoc::DeleteContents() 
  86. {
  87. // TODO: Add your specialized code here and/or call the base class
  88. while(!m_shapeList.IsEmpty())
  89. {
  90. m_shapeList.RemoveHead();
  91. }
  92. CDocument::DeleteContents();
  93. }
  94. BOOL CGraphSoftDoc::OnSaveDocument(LPCTSTR lpszPathName) 
  95. {
  96. // TODO: Add your specialized code here and/or call the base class
  97. ((CGraphSoftApp*)AfxGetApp())->m_strFileName = lpszPathName;
  98. return CDocument::OnSaveDocument(lpszPathName);
  99. }
  100. void CGraphSoftDoc::OnCloseDocument() 
  101. {
  102. // TODO: Add your specialized code here and/or call the base class
  103. CDocument::OnCloseDocument();
  104. }
  105. void CGraphSoftDoc::OnFileNew() 
  106. {
  107. // TODO: Add your command handler code here
  108. if(m_pCore->IsAbleToUndo()||m_pCore->IsAbleToRedo()){
  109. CString strTitle,strDetail;
  110. strTitle.LoadString(IDS_FILE_SAVE_TITLE);
  111. strDetail.LoadString(IDS_FILE_SAVE_STRING);
  112. int nRtn=AfxGetApp()->GetMainWnd()->MessageBox(strDetail,strTitle,MB_YESNOCANCEL);
  113. if(nRtn==IDYES){
  114. SendMessage(AfxGetApp()->GetMainWnd()->GetSafeHwnd(),WM_COMMAND,WPARAM(ID_FILE_SAVE),NULL);
  115. }else if(nRtn==IDCANCEL){
  116. return ;
  117. }
  118. }
  119. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  120. m_nCurrentShapeType=_shape_none;
  121. if(pView!=NULL)
  122. {
  123. pView->m_graph_op=_graph_noneOp;
  124. pView->m_bDrawFlag = FALSE;
  125. }
  126. delete m_pCore;
  127. m_pCore=new CCore(this,pView);
  128. CDocument::UpdateAllViews(NULL);
  129. CDocument::OnNewDocument();
  130. }
  131. ////////////////////////////////////////////////////////
  132. bool CGraphSoftDoc::HasGraphSelected()
  133. {
  134. bool bRlt=FALSE;
  135.     POSITION pos;
  136. pos=m_shapeList.GetHeadPosition();
  137. while (pos!=NULL) {
  138. CShape* pShape=m_shapeList.GetNext(pos);
  139. if(pShape->IsSelected()){
  140. bRlt=TRUE;
  141. break;
  142. }
  143. }
  144. return bRlt;
  145. }
  146. //////////////////////////////////////////////////////////////////
  147. CRect CGraphSoftDoc::GetSelectGraphBoundaryRect()
  148. {
  149. CRect rectRltVal(0,0,0,0);
  150. CRect rectTemp;
  151. int nflag=0;
  152.     if(HasGraphSelected()){
  153. POSITION pos;
  154. pos=m_shapeList.GetHeadPosition();
  155. while (pos!=NULL) {
  156. CShape* pShape=m_shapeList.GetNext(pos);
  157. if(pShape->IsSelected()){
  158. if(nflag==0){
  159. rectRltVal=pShape->GetBoundaryRect();
  160. nflag=1;
  161. }else{
  162. rectTemp=pShape->GetBoundaryRect();
  163. rectRltVal.left=min(rectRltVal.left,rectTemp.left);
  164. rectRltVal.right=max(rectRltVal.right,rectTemp.right);
  165. rectRltVal.top=min(rectRltVal.top,rectTemp.top);
  166. rectRltVal.bottom=max(rectRltVal.bottom,rectTemp.bottom);
  167. }
  168. }
  169. }         
  170.     }
  171. return rectRltVal;
  172. }
  173. ///////////////////////////////////////////////////////
  174. void CGraphSoftDoc::RefreshSelectGraph()
  175. {
  176. POSITION pos;
  177. pos=m_shapeList.GetHeadPosition();
  178. while (pos!=NULL) {
  179. CShape* pShape=m_shapeList.GetNext(pos);
  180. if(pShape->IsSelected()){
  181. pShape->RefreshData(TRUE);
  182. }
  183. }         
  184. }
  185. //////////////////////////////////////////////////////////
  186. /////////////////////////////////////////////////////////////////////////////
  187. void CGraphSoftDoc::SelectInRect(CRect* pRect,CDC* pDC,UINT nFlag,bool bDraw)
  188. {
  189.     CRect rect;
  190. POSITION pos;
  191. rect.left=pRect->left<pRect->right?pRect->left:pRect->right;
  192. rect.right=pRect->left<pRect->right?pRect->right:pRect->left;
  193. rect.top=pRect->top<pRect->bottom?pRect->top:pRect->bottom;
  194. rect.bottom=pRect->top<pRect->bottom?pRect->bottom:pRect->top;
  195.     
  196. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  197. //    int old_rop = pDC->SetROP2(R2_XORPEN);
  198. pos=m_shapeList.GetHeadPosition();
  199. while (pos!=NULL) {
  200. CShape* pShape=m_shapeList.GetNext(pos);
  201. if(nFlag&MK_SHIFT){
  202. if(pShape->IsInRect(rect)){
  203. pShape->SetSelectFlag(!pShape->IsSelected());
  204. if(pShape->IsSelected()){
  205. pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),pView->m_rectTarget,pView->m_rectMaxWindow);
  206. }else{
  207. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  208. }
  209. }
  210. }else{
  211. if(pShape->IsInRect(rect)){
  212. if(bDraw) 
  213. pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),pView->m_rectTarget,pView->m_rectMaxWindow);
  214. pShape->SetSelectFlag(TRUE);
  215. }
  216. else if(pShape->IsSelected())
  217. {
  218. pShape->SetSelectFlag(FALSE);
  219. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  220. }
  221. }
  222. }
  223. // pDC->SetROP2(old_rop);
  224. }
  225. ////////////
  226. int CGraphSoftDoc::GetSelectNum()
  227. {
  228. POSITION pos;
  229. int nRltVal=0;
  230. pos=m_shapeList.GetHeadPosition();
  231. while (pos!=NULL) {
  232. CShape* pShape=m_shapeList.GetNext(pos);
  233.         if(pShape->IsSelected())
  234. {
  235. nRltVal++;
  236. }
  237. }
  238. return nRltVal;
  239. }
  240. void CGraphSoftDoc::SetGraphDrawPtFlag(int nFlag,CDC* pDC)
  241. {
  242. POSITION pos;
  243. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  244. pos=m_shapeList.GetHeadPosition();
  245. while (pos!=NULL) {
  246. CShape* pShape=m_shapeList.GetNext(pos);
  247.         if(pShape->IsSelected())
  248. {
  249. if(pShape->GetDrawPointsFlag()==1){
  250. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  251. }
  252. pShape->SetDrawPointsFlag(nFlag);
  253. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  254. }
  255. }
  256. CRect rect=GetSelectGraphBoundaryRect();
  257. rect.left/=1000;
  258. rect.top/=1000;
  259. rect.bottom/=1000;
  260. rect.right/=1000;
  261. pView->Redraw(pDC,&rect);
  262. }
  263. void CGraphSoftDoc::GraphLeftToRight(CDC* pDC)
  264. {
  265. POSITION pos;
  266. CRect rect=GetSelectGraphBoundaryRect();
  267. pos=m_shapeList.GetHeadPosition();
  268. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  269. while (pos!=NULL) {
  270. CShape* pShape=m_shapeList.GetNext(pos);
  271.         if(pShape->IsSelected())
  272. {
  273. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  274. pShape->LeftToRight(pDC,rect);
  275. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  276. }
  277. }
  278. rect.left/=1000;
  279. rect.top/=1000;
  280. rect.bottom/=1000;
  281. rect.right/=1000;
  282. pView->Redraw(pDC,&rect);
  283. }
  284. void CGraphSoftDoc::GraphTopToBottom(CDC* pDC)
  285. {
  286. POSITION pos;
  287. CRect rect=GetSelectGraphBoundaryRect();
  288. pos=m_shapeList.GetHeadPosition();
  289. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  290. while (pos!=NULL) {
  291. CShape* pShape=m_shapeList.GetNext(pos);
  292.         if(pShape->IsSelected())
  293. {
  294. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  295. pShape->TopToBottom(pDC,rect);
  296. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  297. }
  298. }
  299. rect.left/=1000;
  300. rect.top/=1000;
  301. rect.bottom/=1000;
  302. rect.right/=1000;
  303. pView->Redraw(pDC,&rect);
  304. }
  305. ////////
  306. void CGraphSoftDoc::SetEditStateCursor(float flx,float fly,float flRate)
  307. {
  308. POSITION pos;
  309. CShape* pShape;
  310. pos=m_shapeList.GetHeadPosition();
  311. while (pos!=NULL) {
  312. pShape=m_shapeList.GetNext(pos);
  313.         if(pShape->IsSelected())
  314. {
  315. break;
  316. }
  317. }
  318. UINT unID=0;
  319. if(pShape->IsSelected()){
  320. if(pShape->GetPtState(flx,fly,flRate)==1){
  321. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_POINTSEL));
  322. unID=IDC_GRAPH_POINTSEL;
  323. }else if(pShape->GetPtState(flx,fly,flRate)==2){
  324. float flRate=pShape->GetSelectLineRate();
  325. if(flRate>=2){
  326. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT_LINE0));
  327. unID=IDC_GRAPH_EDIT_LINE0;
  328. }else if(flRate>=0.5){
  329.                 SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT_LINE3));
  330. unID=IDC_GRAPH_EDIT_LINE3;
  331. }else if(flRate>=-0.5){
  332.                 SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT_LINE2));
  333. unID=IDC_GRAPH_EDIT_LINE2;
  334. }else if(flRate>=-2){
  335.                 SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT_LINE1));
  336. unID=IDC_GRAPH_EDIT_LINE1;
  337. }else {
  338.                 SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT_LINE0));
  339. unID=IDC_GRAPH_EDIT_LINE0;
  340. }
  341. }else{
  342. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_EDIT));
  343. unID=IDC_GRAPH_EDIT;
  344. }
  345. }
  346. ((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView())->m_unPrevCur=unID;
  347. }
  348. void CGraphSoftDoc::ExPort(FILE* outStream)
  349. {
  350. POSITION pos;
  351. CShape* pShape;
  352. int num=m_shapeList.GetCount();
  353. fprintf(outStream,"%dn",num);
  354. pos=m_shapeList.GetHeadPosition();
  355. while (pos!=NULL) {
  356.    pShape=m_shapeList.GetNext(pos);
  357.        pShape->ExPort(outStream);
  358. }
  359. }
  360. void CGraphSoftDoc::ImPort(FILE* inStream)
  361. {
  362. m_shapeList.RemoveAll();
  363. int num;
  364. // int nshapeType;
  365. CShape* pShape;
  366. fscanf(inStream,"%d",&num);
  367. for(int i=0;i<num;i++){
  368. char strClassName[50];
  369. fscanf(inStream,"%s",strClassName);
  370. /* switch(nshapeType) {//bad programme!!!
  371. case _shape_Line:
  372. pShape=new CLine();
  373. break;
  374. case _shape_Rectangle:
  375. pShape=new CRectangle();
  376. break;
  377. case _shape_Parallelogram: 
  378. pShape=new CParallelogram();
  379. break;
  380. case _shape_Polygon:
  381. pShape=new CPolygon();
  382. break;
  383. case _shape_Circle:
  384. pShape=new CCircle();
  385. break;
  386. case _shape_Ellipse:
  387. pShape=new CEllipse();
  388. break;
  389. case _shape_RoundRect:
  390. pShape=new CRoundRect();
  391. break;
  392. case _shape_ModelCurve3Param:
  393. pShape=new CModelCurve3Param();
  394. break;
  395. case _shape_ModelCurve2AvB:
  396. pShape=new CModelCurve2AvB();
  397. break;
  398. case _shape_BezierCurve:
  399. pShape=new CBezierCurve();
  400. break;
  401. }
  402. */
  403. pShape=GetShapeClass(strClassName);
  404. pShape->ImPort(inStream);
  405. m_shapeList.AddTail(pShape);
  406. CUND_Base* pUndo = new CUND_Create(pShape);
  407. m_pCore->AddUndoItem(pUndo);
  408. }
  409. CDocument::UpdateAllViews(NULL);
  410. }
  411. //////////////////////////////////////////////////////////////////
  412. void CGraphSoftDoc::OnFileImport() 
  413. {
  414. // TODO: Add your command handler code here
  415. CFileDialog dlg(true,_T("lld"),_T("*.lld"),OFN_ENABLESIZING,_T("*.lld|*.lld"));
  416. if (dlg.DoModal()==IDOK)
  417. {
  418. if(dlg.GetFileExt()=="lld"){
  419. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  420. CString strTitle,strDetail;
  421. strTitle.LoadString(IDS_FILE_SAVE_TITLE);
  422. strDetail.LoadString(IDS_FILE_SAVE_STRING);
  423. if(m_pCore->IsAbleToUndo()||m_pCore->IsAbleToRedo())
  424. {
  425. int nRtn=AfxGetApp()->GetMainWnd()->MessageBox(strDetail,strTitle,MB_YESNOCANCEL|MB_APPLMODAL);
  426. if(nRtn==IDYES){
  427. SendMessage(AfxGetApp()->GetMainWnd()->GetSafeHwnd(),WM_COMMAND,WPARAM(ID_FILE_SAVE),NULL);
  428. }else if(nRtn==IDCANCEL){
  429. return ;
  430. }
  431. }
  432. m_nCurrentShapeType=_shape_none;
  433. if(pView!=NULL)
  434. {
  435. pView->m_graph_op=_graph_noneOp;
  436. pView->m_bDrawFlag = FALSE;
  437. }
  438. delete m_pCore;
  439. m_pCore=new CCore(this,pView);
  440. FILE *InStream;
  441. InStream = fopen(dlg.GetPathName(), "r" );
  442. ImPort(InStream);
  443. fclose(InStream);
  444. CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
  445. if(pMainFrm && pView){
  446. pMainFrm->m_wndFullView.m_pBtn->m_targetrect=pMainFrm->m_wndFullView.m_pBtn->m_MaxRect;
  447. pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
  448. pView->m_rectMaxWindow = pView->m_rectTarget = CRect(0,0,800,650);
  449. pView->SetScrollSizes(MM_TEXT,CSize(0,0));
  450. pView->Invalidate(TRUE);
  451. }
  452. }
  453. }
  454. }
  455. void CGraphSoftDoc::SetSelGraphColor(COLORREF color,CDC* pDC)
  456. {
  457. POSITION pos;
  458. CRect rect=GetSelectGraphBoundaryRect();
  459. pos=m_shapeList.GetHeadPosition();
  460. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  461. while (pos!=NULL) {
  462. CShape* pShape=m_shapeList.GetNext(pos);
  463.         if(pShape->IsSelected())
  464. {
  465. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  466. pShape->SetColor(color);
  467. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  468. }
  469. }
  470. rect.left/=1000;
  471. rect.top/=1000;
  472. rect.bottom/=1000;
  473. rect.right/=1000;
  474. pView->Redraw(pDC,&rect);
  475. }
  476. void CGraphSoftDoc::SetSelGraphFillClr(COLORREF color,CDC* pDC)
  477. {
  478. POSITION pos;
  479. CRect rect=GetSelectGraphBoundaryRect();
  480. pos=m_shapeList.GetHeadPosition();
  481. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  482. while (pos!=NULL) {
  483. CShape* pShape=m_shapeList.GetNext(pos);
  484.         if(pShape->IsSelected())
  485. {
  486. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  487. pShape->SetFillStyle(_shape_solid_fill);
  488. pShape->SetFillColor(color);
  489. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  490. }
  491. }
  492. rect.left/=1000;
  493. rect.top/=1000;
  494. rect.bottom/=1000;
  495. rect.right/=1000;
  496. pView->Redraw(pDC,&rect);
  497. }
  498. void CGraphSoftDoc::SetSelGraphFillSty(SHAPE_FILLSTYLE nStyle,CDC* pDC)
  499. {
  500. POSITION pos;
  501. CRect rect=GetSelectGraphBoundaryRect();
  502. pos=m_shapeList.GetHeadPosition();
  503. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  504. while (pos!=NULL) {
  505. CShape* pShape=m_shapeList.GetNext(pos);
  506.         if(pShape->IsSelected())
  507. {
  508. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  509. pShape->SetFillStyle(nStyle);
  510. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  511. }
  512. }
  513. rect.left/=1000;
  514. rect.top/=1000;
  515. rect.bottom/=1000;
  516. rect.right/=1000;
  517. pView->Redraw(pDC,&rect);
  518. }
  519. void CGraphSoftDoc::SetSelGraphPenWidth(int nWidth,CDC* pDC)
  520. {
  521. POSITION pos;
  522. CRect rect=GetSelectGraphBoundaryRect();
  523. pos=m_shapeList.GetHeadPosition();
  524. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  525. while (pos!=NULL) {
  526. CShape* pShape=m_shapeList.GetNext(pos);
  527.         if(pShape->IsSelected())
  528. {
  529. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),pView->m_rectTarget,pView->m_rectMaxWindow);
  530. pShape->SetPenWidth(nWidth);
  531. pShape->DrawCutToRect(pDC,pView->m_rectTarget,pView->m_rectMaxWindow);
  532. }
  533. }
  534. rect.left/=1000;
  535. rect.top/=1000;
  536. rect.bottom/=1000;
  537. rect.right/=1000;
  538. pView->Redraw(pDC,&rect);
  539. }
  540. void CGraphSoftDoc::GetSelGraphIDArray(CArray<unsigned long,unsigned long>& arrID)
  541. {
  542. POSITION pos;
  543. pos=m_shapeList.GetHeadPosition();
  544. arrID.RemoveAll();
  545. while (pos!=NULL) {
  546. CShape* pShape=m_shapeList.GetNext(pos);
  547.         if(pShape->IsSelected())
  548. {
  549. arrID.Add(pShape->GetID());
  550. }
  551. }
  552. }
  553. void CGraphSoftDoc::GetSelGraphArray(CArray<CShape*,CShape*>& ArrShape)
  554. {
  555. POSITION pos;
  556. pos=m_shapeList.GetHeadPosition();
  557. ArrShape.RemoveAll();
  558. while (pos!=NULL) {
  559. CShape* pShape=m_shapeList.GetNext(pos);
  560.         if(pShape->IsSelected())
  561. {
  562. ArrShape.Add(pShape);
  563. }
  564. }
  565. }
  566. void CGraphSoftDoc::GetSelGraphPropertyArr(CArray<SUNDPropertyUnit,SUNDPropertyUnit>& ArrProperty)
  567. {
  568. POSITION pos;
  569. pos=m_shapeList.GetHeadPosition();
  570. ArrProperty.RemoveAll();
  571. while (pos!=NULL) {
  572. CShape* pShape=m_shapeList.GetNext(pos);
  573.         if(pShape->IsSelected())
  574. {
  575. SUNDPropertyUnit unitProperty;
  576. unitProperty.nID=pShape->GetID();
  577. unitProperty.color=pShape->GetColor();
  578. unitProperty.colorFill=pShape->GetFillColor();
  579. unitProperty.fillStyle=pShape->GetFillStyle();
  580. unitProperty.nPenWidth=pShape->GetPenWidth();
  581. unitProperty.nPtShow=pShape->GetDrawPointsFlag();
  582. ArrProperty.Add(unitProperty);
  583. }
  584. }
  585. }
  586. ////////////////////////////////////////////////////////////////////////////////
  587. //End of File
  588. BOOL CGraphSoftDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  589. {
  590. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  591. CString strTitle,strDetail;
  592. strTitle.LoadString(IDS_FILE_SAVE_TITLE);
  593. strDetail.LoadString(IDS_FILE_SAVE_STRING);
  594. if(m_pCore->IsAbleToUndo()||m_pCore->IsAbleToRedo())
  595. {
  596. int nRtn=AfxGetApp()->GetMainWnd()->MessageBox(strDetail,strTitle,MB_YESNOCANCEL|MB_APPLMODAL);
  597. if(nRtn==IDYES){
  598. SendMessage(AfxGetApp()->GetMainWnd()->GetSafeHwnd(),WM_COMMAND,WPARAM(ID_FILE_SAVE),NULL);
  599. }else if(nRtn==IDCANCEL){
  600. return FALSE;
  601. }
  602. }
  603. m_nCurrentShapeType=_shape_none;
  604. if(pView!=NULL)
  605. {
  606. pView->m_graph_op=_graph_noneOp;
  607. pView->m_bDrawFlag = FALSE;
  608. }
  609. if(((CGraphSoftApp*)AfxGetApp())->m_strFileName.Compare(lpszPathName)!=0) {
  610. delete m_pCore;//删除撤消/恢复对象指针,以及删除图形对象指针
  611. m_shapeList.RemoveAll();
  612. m_pCore=new CCore(this,pView);    
  613. }
  614. if (!CDocument::OnOpenDocument(lpszPathName))
  615. return FALSE;
  616. // TODO: Add your specialized creation code here
  617. if(((CGraphSoftApp*)AfxGetApp())->m_strFileName.Compare(lpszPathName)!=0) {
  618. CUND_Base* pUNDBase;
  619. POSITION pos=m_shapeList.GetHeadPosition();
  620. while (pos!=NULL) {
  621. CShape* pShape=m_shapeList.GetNext(pos);
  622. pUNDBase = new CUND_Create(pShape);
  623. m_pCore->AddUndoItem(pUNDBase);
  624. }
  625. }
  626. ((CGraphSoftApp*)AfxGetApp())->m_strFileName = lpszPathName;
  627. CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
  628. if(pMainFrm && pView){
  629. pMainFrm->m_wndFullView.m_pBtn->m_targetrect=pMainFrm->m_wndFullView.m_pBtn->m_MaxRect;
  630. pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
  631. pView->m_rectMaxWindow = pView->m_rectTarget = CRect(0,0,800,650);
  632. pView->SetScrollSizes(MM_TEXT,CSize(0,0));
  633. pView->Invalidate(TRUE);
  634. }
  635. return TRUE;
  636. }