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

绘图程序

开发平台:

Visual C++

  1. // Core.cpp: implementation of the CCore class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "graphsoft.h"
  6. #include "Core.h"
  7. #include "CoreLog.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CCore::CCore(CGraphSoftDoc*  pDoc,CGraphSoftView* pView)
  17. {
  18. m_pDoc=pDoc;
  19. m_pView=pView;
  20. m_bEnableUndo=FALSE;
  21. m_bSendMessageLog=FALSE;
  22. m_pLog=new CCoreLog();
  23. }
  24. CCore::~CCore()
  25. {
  26. delete m_pLog;
  27. }
  28. ////////////////////////////////////////////////////////////////////
  29. void CCore::OnEditUndo()
  30. {
  31. CWaitCursor wait;
  32. m_pLog->OnEditUndo(this);
  33. }
  34. void CCore::OnEditRedo()
  35. {
  36. CWaitCursor wait;
  37. m_pLog->OnEditRedo(this);
  38. }
  39. BOOL CCore::IsAbleToUndo()
  40. {
  41. // return (m_bEnableUndo && m_pLog->IsAbleToUndo() && !m_bPowerStageMode2);
  42. return (m_pLog->IsAbleToUndo());
  43. }
  44. BOOL CCore::IsAbleToRedo()
  45. {
  46. // return (m_bEnableUndo && m_pLog->IsAbleToRedo() && !m_bPowerStageMode2);
  47. return (m_pLog->IsAbleToRedo());
  48. }
  49. void CCore::EnableUndo(BOOL bFlag)
  50. {
  51. m_bEnableUndo = bFlag;
  52. }
  53. BOOL CCore::WriteLogString(CString text)
  54. {
  55. m_pLog->WriteLogString(text);
  56. return true;
  57. }
  58. void CCore::AddUndoItem(CUND_Base* pUndo)
  59. {
  60. m_pLog->AddUndoItem(pUndo);
  61. }
  62. void CCore::DelLastUndoItem()
  63. {
  64. m_pLog->DelLastUndoItem();
  65. }
  66. //////////////////////////////////////////////////////////////////////
  67. // MODULE   :DrawGraph
  68. // ABSTRACT :绘画/清空图形
  69. // FUNCTION :一般在撤消/恢复中用到
  70. // NOTE     :
  71. // RETURN   :
  72. // ARGUMENTS:
  73. //              I/O           TYPE      NAME       EXPLANATION
  74. //               I              BOOL     bFlag      TRUE-Draw  FALSE-Clear
  75. // CREATE   :  FNST)handwolf  2004-4-23
  76. // UPDATE   :  
  77. //          : Modify reason
  78. //////////////////////////////////////////////////////////////////////
  79. void CCore::DrawGraph(CShape* pShape,BOOL bFlag)
  80. {
  81. CDC* pDC=CDC::FromHandle(GetDC(m_pView->GetSafeHwnd()));
  82. m_pView->OnPrepareDC(pDC);
  83. if(!bFlag){
  84. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),m_pView->m_rectTarget,m_pView->m_rectMaxWindow);
  85. }else{
  86. pShape->DrawCutToRect(pDC,m_pView->m_rectTarget,m_pView->m_rectMaxWindow);
  87. }
  88. }
  89. CShape* CCore::GetShapeByID(unsigned long nID)
  90. {
  91. CShape* pShape=NULL;
  92. POSITION pos;
  93. pos=m_pDoc->m_shapeList.GetHeadPosition();
  94. while (pos!=NULL) {
  95. pShape=m_pDoc->m_shapeList.GetNext(pos);
  96.         if(pShape->GetID()==nID){
  97. break;
  98.         }
  99. }
  100. return pShape;
  101. }
  102. void CCore::ReMoveShape(unsigned long nID)
  103. {
  104. CShape* pShape=NULL;
  105. POSITION pos,posPre;
  106. pos=m_pDoc->m_shapeList.GetHeadPosition();
  107. while (pos!=NULL) {
  108. posPre=pos;
  109. pShape=m_pDoc->m_shapeList.GetNext(pos);
  110.         if(pShape->GetID()==nID){
  111. m_pDoc->m_shapeList.RemoveAt(posPre);
  112. break;
  113.         }
  114. }
  115. }