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

绘图程序

开发平台:

Visual C++

  1. // GraphSoftView.cpp : implementation of the CGraphSoftView class
  2. //
  3. #include "stdafx.h"
  4. #include "stdAfx.h"
  5. #include "GraphSoft.h"
  6. #include "GraphDefines.h"
  7. #include "GraphSoftDoc.h"
  8. #include "GraphSoftView.h"
  9. #include "FullViewBtn.h"
  10. #include "GraphInfoDlg.h"
  11. #include "FullScreenHandler.h"
  12. #include "ColorSetDlg.h"
  13. #include "GlobalFunction.h"
  14. #include "MainFrm.h"
  15. #include "UND_Create.h"
  16. #include "UND_Move.h"
  17. #include "UND_Rotate.h"
  18. #include "UND_Magnify.h"
  19. #include "UND_ShowPoints.h"
  20. #include "UND_TopToBtm.h"
  21. #include "UND_LeftToRight.h"
  22. #include "UND_Delete.h"
  23. #include "UND_Copy.h"
  24. #include "UND_Edit.h"
  25. #include "UND_Property.h"
  26. #include <windowsx.h>
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CGraphSoftView
  34. IMPLEMENT_DYNCREATE(CGraphSoftView, CScrollView)
  35. BEGIN_MESSAGE_MAP(CGraphSoftView, CScrollView)
  36. //{{AFX_MSG_MAP(CGraphSoftView)
  37. ON_WM_LBUTTONDOWN()
  38. ON_WM_LBUTTONUP()
  39. ON_WM_MOUSEMOVE()
  40. ON_COMMAND(ID_DRAW_DDALINE, OnDrawDdaline)
  41. ON_COMMAND(ID_FILE_EXPORT, OnFileExport)
  42. ON_WM_CONTEXTMENU()
  43. ON_COMMAND(ID_GRAPH_MOVE, OnGraphMove)
  44. ON_WM_LBUTTONDBLCLK()
  45. ON_UPDATE_COMMAND_UI(ID_DRAW_DDALINE, OnUpdateDrawDdaline)
  46. ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle)
  47. ON_COMMAND(ID_DRAW_ROUNDRECT, OnDrawRoundrect)
  48. ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
  49. ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
  50. ON_UPDATE_COMMAND_UI(ID_DRAW_RECTANGLE, OnUpdateDrawRectangle)
  51. ON_UPDATE_COMMAND_UI(ID_DRAW_ROUNDRECT, OnUpdateDrawRoundrect)
  52. ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
  53. ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
  54. ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
  55. ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
  56. ON_COMMAND(ID_DRAW_NONE, OnDrawNone)
  57. ON_UPDATE_COMMAND_UI(ID_DRAW_NONE, OnUpdateDrawNone)
  58. ON_COMMAND(ID_GRAPH_MAGNIFY, OnGraphMagnify)
  59. ON_COMMAND(ID_GRAPH_ROTATE, OnGraphRotate)
  60. ON_COMMAND(ID_GRAPH_PROPERTIY, OnGraphPropertiy)
  61. ON_COMMAND(ID_GRAPH_DELETE, OnGraphDelete)
  62. ON_COMMAND(ID_GRAPH_COPY, OnGraphCopy)
  63. ON_WM_DESTROY()
  64. ON_COMMAND(ID_SELECT_ALL, OnSelectAll)
  65. ON_UPDATE_COMMAND_UI(ID_SELECT_ALL, OnUpdateSelectAll)
  66. ON_COMMAND(ID_OPERATION_OVER, OnOperationOver)
  67. ON_UPDATE_COMMAND_UI(ID_GRAPH_DELETE, OnUpdateGraphDelete)
  68. ON_COMMAND(ID_SELECT_PENWIDTH, OnSelectPenwidth)
  69. ON_UPDATE_COMMAND_UI(ID_SELECT_PENWIDTH, OnUpdateSelectPenwidth)
  70. ON_WM_SETCURSOR()
  71. ON_COMMAND(ID_DRAW_PARALLELOGRAM, OnDrawParallelogram)
  72. ON_UPDATE_COMMAND_UI(ID_DRAW_PARALLELOGRAM, OnUpdateDrawParallelogram)
  73. ON_COMMAND(ID_GRAPH_ROTATECENTER_SET, OnGraphRotatecenterSet)
  74. ON_COMMAND(ID_GRAPH_ROTATE_LEFT, OnGraphRotateLeft)
  75. ON_COMMAND(ID_GRAPH_ROTATE_RIGHT, OnGraphRotateRight)
  76. ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATECENTER_SET, OnUpdateGraphRotatecenterSet)
  77. ON_COMMAND(ID_INPUT_CONFIRM, OnInputConfirm)
  78. ON_COMMAND(ID_SHAPE_OVER, OnShapeOver)
  79. ON_COMMAND(ID_DRAW_MODELCURVE2AVB, OnDrawModelcurve2avb)
  80. ON_UPDATE_COMMAND_UI(ID_DRAW_MODELCURVE2AVB, OnUpdateDrawModelcurve2avb)
  81. ON_COMMAND(ID_DRAW_MODELCURVE3PARAM, OnDrawModelcurve3param)
  82. ON_UPDATE_COMMAND_UI(ID_DRAW_MODELCURVE3PARAM, OnUpdateDrawModelcurve3param)
  83. ON_UPDATE_COMMAND_UI(ID_GRAPH_COPY, OnUpdateGraphCopy)
  84. ON_UPDATE_COMMAND_UI(ID_GRAPH_MAGNIFY, OnUpdateGraphMagnify)
  85. ON_UPDATE_COMMAND_UI(ID_GRAPH_MOVE, OnUpdateGraphMove)
  86. ON_UPDATE_COMMAND_UI(ID_GRAPH_PROPERTIY, OnUpdateGraphPropertiy)
  87. ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE, OnUpdateGraphRotate)
  88. ON_COMMAND(ID_DRAW_BEZIERCURVE, OnDrawBeziercurve)
  89. ON_UPDATE_COMMAND_UI(ID_DRAW_BEZIERCURVE, OnUpdateDrawBeziercurve)
  90. ON_UPDATE_COMMAND_UI(ID_INPUT_CONFIRM, OnUpdateInputConfirm)
  91. ON_COMMAND(ID_SELECT_FILL_COLOR, OnSelectFillColor)
  92. ON_COMMAND(ID_GRAPH_EDIT, OnGraphEdit)
  93. ON_COMMAND(ID_GRAPH_POINTSHIDE, OnGraphPointshide)
  94. ON_COMMAND(ID_GRAPH_POINTSSHOW, OnGraphPointsshow)
  95. ON_COMMAND(ID_GRAPH_LEFTTORIGHT, OnGraphLefttoright)
  96. ON_COMMAND(ID_GRAPH_TOPTOBOTTOM, OnGraphToptobottom)
  97. ON_UPDATE_COMMAND_UI(ID_GRAPH_TOPTOBOTTOM, OnUpdateGraphToptobottom)
  98. ON_UPDATE_COMMAND_UI(ID_GRAPH_EDIT, OnUpdateGraphEdit)
  99. ON_UPDATE_COMMAND_UI(ID_GRAPH_LEFTTORIGHT, OnUpdateGraphLefttoright)
  100. ON_UPDATE_COMMAND_UI(ID_GRAPH_POINTSHIDE, OnUpdateGraphPointshide)
  101. ON_UPDATE_COMMAND_UI(ID_GRAPH_POINTSSHOW, OnUpdateGraphPointsshow)
  102. ON_UPDATE_COMMAND_UI(ID_OPERATION_OVER, OnUpdateOperationOver)
  103. ON_WM_INITMENUPOPUP()
  104. ON_WM_CREATE()
  105. ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE_LEFT, OnUpdateGraphRotateLeft)
  106. ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE_RIGHT, OnUpdateGraphRotateRight)
  107. ON_WM_ERASEBKGND()
  108. ON_MESSAGE(WM_SELGRAPH_POINT,OnSelGraphPoint)
  109. ON_MESSAGE(WM_SELGRAPH_ROTATE,OnSelGraphRotate)
  110. ON_MESSAGE(WM_SELGRAPH_COLOR,OnSelGraphColor)
  111. ON_MESSAGE(WM_SELGRAPH_FILLCOLOR,OnSelGraphFillClr)
  112. ON_MESSAGE(WM_SELGRAPH_FILLSTYLE,OnSelGraphFillSty)
  113. ON_MESSAGE(WM_SELGRAPH_PENWIDTH,OnSelGraphPenWidth)
  114. ON_WM_HSCROLL()
  115. ON_WM_VSCROLL()
  116. ON_COMMAND(ID_HELPFILE, OnHelpfile)
  117. //}}AFX_MSG_MAP
  118. // Standard printing commands
  119. ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  120. ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  121. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  122. END_MESSAGE_MAP()
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CGraphSoftView construction/destruction
  125. CGraphSoftView::CGraphSoftView()
  126. {
  127. // TODO: add construction code here
  128. m_nMouseFlag=0;
  129.     m_bDrawFlag=FALSE;
  130. //m_mouseStatePrev=_MOUSE_NONESTATE;
  131. m_nCurrentPenWidth=1;
  132. m_clrCurrentColor=RGB(0,0,0);
  133. m_clrCurrentFill=RGB(255,255,255);
  134. m_clrBkColor=RGB(255,255,255);
  135. m_clrDefaultColor=RGB(0,0,0);  
  136. m_flPrevX=m_flPrevY=0;
  137. m_flStartX=m_flStartY=0;
  138. m_graph_op=_graph_noneOp;
  139. m_bGraphOp=FALSE;
  140. m_bCanSelectGraphType=TRUE;
  141. m_ptSelectGraphCenter=CPoint(0,0);
  142. m_flRotCenterX=m_flRotCenterY=0;
  143. m_bSelectRotateCenter=FALSE;
  144.     m_rectSelectGraph=CRect(0,0,0,0);
  145. m_rectMaxWindow=CRect(0,0,800,650);
  146. m_rectTarget=m_rectMaxWindow;
  147. m_pCurrentShape=NULL;
  148. m_shapeCurFillStyle=_shape_none_fill;
  149.     m_flRate = 1;
  150. m_unPrevCur=0;  
  151. }
  152. CGraphSoftView::~CGraphSoftView()
  153. {
  154. }
  155. BOOL CGraphSoftView::PreCreateWindow(CREATESTRUCT& cs)
  156. {
  157. // TODO: Modify the Window class or styles here by modifying
  158. //  the CREATESTRUCT cs
  159. return CScrollView::PreCreateWindow(cs);
  160. }
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CGraphSoftView drawing
  163. void CGraphSoftView::OnDraw(CDC* pDC)
  164. {
  165. CGraphSoftDoc* pDoc = GetDocument();
  166. ASSERT_VALID(pDoc);
  167. // TODO: add draw code for native data here
  168. POSITION pos;
  169. pos=pDoc->m_shapeList.GetHeadPosition();
  170. while (pos!=NULL) {
  171. CShape* pShape=pDoc->m_shapeList.GetNext(pos);
  172. if(pShape->IsSelected()){
  173. //pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
  174.         pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
  175. }else{
  176. pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
  177. }
  178. }
  179. CClientDC dc(this);
  180. CBrush brush,*pOldBr;
  181. brush.CreateSolidBrush(RGB(255,0,0));
  182. pOldBr = dc.SelectObject(&brush);
  183. SelectObject(dc.GetSafeHdc(),&brush);
  184. dc.SelectObject(pOldBr);
  185. pDC->TextOut(0,0,FullScreenHandler.InFullScreenMode() ?_T("恢复窗口按 Ctrl-U ") : _T(""));
  186. }
  187. ////////////////////////////////////////////////////////////////////////////
  188. //////////////////////////////////////////////////////////////////////
  189. // MODULE   :Redraw
  190. // ABSTRACT :重绘所给矩形区域内的图形
  191. // FUNCTION :
  192. // NOTE     :
  193. // RETURN   :
  194. // ARGUMENTS:
  195. //              I/O           TYPE      NAME       EXPLANATION
  196. //               I            CRect*    pRect      所画矩形对应的逻辑坐标矩形
  197. // CREATE   :  FNST)handwolf  2004-4-20
  198. // UPDATE   :  
  199. //          : 
  200. //////////////////////////////////////////////////////////////////////
  201. void CGraphSoftView::Redraw(CDC* pDC,CRect* const pRect,bool bDrawRect,COLORREF color)
  202. {
  203. CRect rect,rect2;
  204. POSITION pos;
  205.     pRect->NormalizeRect();
  206. rect=*pRect;
  207. rect2.left=rect.left-m_nCurrentPenWidth-1;
  208. rect2.right=rect.right+m_nCurrentPenWidth+1;
  209. rect2.top=rect.top-m_nCurrentPenWidth+1;
  210. rect2.bottom=rect.bottom+m_nCurrentPenWidth+1;
  211. float left=rect.left;
  212. float top=rect.top;
  213. float right=rect.right;
  214. float bottom=rect.bottom;
  215. Lp2Dp(left,top);
  216. Lp2Dp(right,bottom);
  217. rect=CRect(left,top,right,bottom);
  218.     if(bDrawRect==TRUE&&color==RGB(255,255,255))
  219. {
  220. CPen pen,*poldPen;
  221. pen.CreatePen(PS_SOLID,1, color);  
  222. poldPen=pDC->SelectObject(&pen);  
  223. pDC->MoveTo(rect.TopLeft());
  224. pDC->LineTo(rect.left,rect.bottom);
  225. pDC->LineTo(rect.right,rect.bottom);
  226. pDC->LineTo(rect.right,rect.top);
  227. pDC->LineTo(rect.TopLeft());
  228. pDC->SelectObject(poldPen);
  229. }
  230. pos=GetDocument()->m_shapeList.GetHeadPosition();
  231. while (pos!=NULL) {
  232. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  233. if(pShape->IsInRect(rect2)){
  234. pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
  235. }
  236. }
  237. if(bDrawRect==TRUE&&color!=RGB(255,255,255))
  238. {
  239. CPen pen,*poldPen;
  240. pen.CreatePen(PS_SOLID,1, color);  
  241. poldPen=pDC->SelectObject(&pen);  
  242. pDC->MoveTo(rect.TopLeft());
  243. pDC->LineTo(rect.left,rect.bottom);
  244. pDC->LineTo(rect.right,rect.bottom);
  245. pDC->LineTo(rect.right,rect.top);
  246. pDC->LineTo(rect.TopLeft());
  247. pDC->SelectObject(poldPen);
  248. }
  249. }
  250. // CGraphSoftView printing
  251. BOOL CGraphSoftView::OnPreparePrinting(CPrintInfo* pInfo)
  252. {
  253. // default preparation
  254. return DoPreparePrinting(pInfo);
  255. }
  256. void CGraphSoftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  257. {
  258. // TODO: add extra initialization before printing
  259. }
  260. void CGraphSoftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  261. {
  262. // TODO: add cleanup after printing
  263. }
  264. /////////////////////////////////////////////////////////////////////////////
  265. // CGraphSoftView diagnostics
  266. #ifdef _DEBUG
  267. void CGraphSoftView::AssertValid() const
  268. {
  269. CScrollView::AssertValid();
  270. }
  271. void CGraphSoftView::Dump(CDumpContext& dc) const
  272. {
  273. CScrollView::Dump(dc);
  274. }
  275. CGraphSoftDoc* CGraphSoftView::GetDocument() // non-debug version is inline
  276. {
  277. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphSoftDoc)));
  278. return (CGraphSoftDoc*)m_pDocument;
  279. }
  280. #endif //_DEBUG
  281. /////////////////////////////////////////////////////////////////////////////
  282. // CGraphSoftView message handlers
  283. void CGraphSoftView::OnLButtonDown(UINT nFlags, CPoint point) 
  284. {
  285. // TODO: Add your message handler code here and/or call default
  286. CClientDC dc(this);
  287. OnPrepareDC(&dc);
  288. dc.DPtoLP(&point);
  289. float flX=point.x;
  290. float flY=point.y;
  291. Dp2Lp(flX,flY);     
  292. m_nMouseFlag=1;
  293. m_flPrevX=flX;
  294. m_flPrevY=flY;
  295. m_flStartX=flX;
  296. m_flStartY=flY;
  297. CUND_Base* pUndo;
  298. if(m_bGraphOp){
  299. m_bDrawFlag=FALSE;
  300. }else{
  301. m_bDrawFlag=TRUE;
  302. switch(GetDocument()->m_nCurrentShapeType) {
  303. case _shape_none:
  304. break;
  305. case _shape_Line:
  306. m_flArrayX.Add(flX);
  307. m_flArrayX.Add(flX);
  308. m_flArrayY.Add(flY);
  309. m_flArrayY.Add(flY);
  310. m_pCurrentShape=new CLine();
  311. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  312. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  313. pUndo = new CUND_Create(m_pCurrentShape);
  314. GetDocument()->m_pCore->AddUndoItem(pUndo);
  315. break;
  316. case _shape_Parallelogram:
  317. {
  318. if(m_flArrayX.GetSize()==0){
  319. m_flArrayX.Add(flX);
  320. m_flArrayY.Add(flY);
  321. }else if(m_flArrayX.GetSize()==1)
  322. {
  323. m_flArrayX.Add(flX);
  324. m_flArrayX.Add(flX);
  325. m_flArrayY.Add(flY);
  326. m_flArrayY.Add(flY);
  327. m_pCurrentShape=new CParallelogram();
  328. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  329. pUndo = new CUND_Create(m_pCurrentShape);
  330. GetDocument()->m_pCore->AddUndoItem(pUndo);
  331. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  332. int old_rop = dc.SetROP2(R2_XORPEN);
  333. // m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  334. float x1=m_flArrayX.GetAt(0);
  335. float y1=m_flArrayY.GetAt(0);
  336. float x2=m_flArrayX.GetAt(1);
  337. float y2=m_flArrayY.GetAt(1);
  338. Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
  339. Lp2Dp(x2,y2);
  340. DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);                   
  341. dc.SetROP2(old_rop);
  342. }
  343. }
  344. break;
  345. case _shape_Rectangle:
  346. m_flArrayX.Add(flX);
  347. m_flArrayX.Add(flX);
  348. m_flArrayY.Add(flY);
  349. m_flArrayY.Add(flY);
  350. m_pCurrentShape=new CRectangle();
  351. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  352. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  353. pUndo = new CUND_Create(m_pCurrentShape);
  354. GetDocument()->m_pCore->AddUndoItem(pUndo);
  355. break;
  356. case _shape_RoundRect:
  357. m_flArrayX.Add(flX);
  358. m_flArrayX.Add(flX);
  359. m_flArrayY.Add(flY);
  360. m_flArrayY.Add(flY);
  361. m_pCurrentShape=new CRoundRect();
  362. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  363. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  364. pUndo = new CUND_Create(m_pCurrentShape);
  365. GetDocument()->m_pCore->AddUndoItem(pUndo);
  366. break;
  367. case _shape_Circle:
  368. m_flArrayX.Add(flX);
  369. m_flArrayX.Add(flX);
  370. m_flArrayY.Add(flY);
  371. m_flArrayY.Add(flY);
  372. m_pCurrentShape=new CCircle();
  373. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  374. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  375. pUndo = new CUND_Create(m_pCurrentShape);
  376. GetDocument()->m_pCore->AddUndoItem(pUndo);
  377. break;
  378. case _shape_Ellipse:
  379. m_flArrayX.Add(flX);
  380. m_flArrayX.Add(flX);
  381. m_flArrayY.Add(flY);
  382. m_flArrayY.Add(flY);
  383. m_pCurrentShape=new CEllipse();
  384. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  385. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  386. pUndo = new CUND_Create(m_pCurrentShape);
  387. GetDocument()->m_pCore->AddUndoItem(pUndo);
  388. break;
  389. case _shape_Polygon:
  390. if(m_flArrayX.GetSize()==0){
  391. m_flArrayX.Add(flX);
  392. m_flArrayY.Add(flY);
  393. m_pCurrentShape=new CPolygon();
  394. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  395. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  396. int old_rop = dc.SetROP2(R2_XORPEN);
  397. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  398. dc.SetROP2(old_rop);
  399. pUndo = new CUND_Create(m_pCurrentShape);
  400. GetDocument()->m_pCore->AddUndoItem(pUndo);
  401. }
  402. break;
  403. case _shape_ModelCurve3Param:
  404. if(m_flArrayX.GetSize()==0){
  405. m_flArrayX.Add(flX);
  406. m_flArrayY.Add(flY);
  407. m_pCurrentShape=new CModelCurve3Param();
  408. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  409. pUndo = new CUND_Create(m_pCurrentShape);
  410. GetDocument()->m_pCore->AddUndoItem(pUndo);
  411. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  412. int old_rop = dc.SetROP2(R2_XORPEN);
  413. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  414. dc.SetROP2(old_rop);
  415. }
  416. break;
  417. case _shape_ModelCurve2AvB:
  418. if(m_flArrayX.GetSize()==0){
  419. m_flArrayX.Add(flX);
  420. m_flArrayY.Add(flY);
  421. m_pCurrentShape=new CModelCurve2AvB();
  422. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  423. pUndo = new CUND_Create(m_pCurrentShape);
  424. GetDocument()->m_pCore->AddUndoItem(pUndo);
  425. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  426. int old_rop = dc.SetROP2(R2_XORPEN);
  427. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  428. dc.SetROP2(old_rop);
  429. }
  430. break;
  431. case _shape_BezierCurve:
  432. if(m_flArrayX.GetSize()==0){
  433. m_flArrayX.Add(flX);
  434. m_flArrayY.Add(flY);
  435. m_pCurrentShape=new CBezierCurve();
  436. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  437. pUndo = new CUND_Create(m_pCurrentShape);
  438. GetDocument()->m_pCore->AddUndoItem(pUndo);
  439. GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
  440. int old_rop = dc.SetROP2(R2_XORPEN);
  441. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  442. dc.SetROP2(old_rop);
  443. }
  444. break;
  445. default:
  446. break;
  447. }
  448. }
  449. CRect rect;//矩形
  450. GetClientRect(&rect);
  451. ClientToScreen(&rect);
  452.     ClipCursor(&rect);
  453. CScrollView::OnLButtonDown(nFlags, point);
  454. }
  455. void CGraphSoftView::OnLButtonUp(UINT nFlags, CPoint point) 
  456. {
  457. // TODO: Add your message handler code here and/or call default
  458. CClientDC dc(this);
  459. OnPrepareDC(&dc);
  460. dc.DPtoLP(&point);
  461. float flX=point.x;
  462. float flY=point.y;
  463. Dp2Lp(flX,flY);     
  464. CRect rect;
  465. m_nMouseFlag=0;
  466. if(m_bGraphOp==FALSE&&m_bDrawFlag)
  467. {
  468. switch(GetDocument()->m_nCurrentShapeType) {
  469. case _shape_none:
  470. {
  471. int old_rop = dc.SetROP2(R2_XORPEN);
  472. dc.SetBkMode(TRANSPARENT);
  473. CPen pen,*poldPen;
  474. CBrush brush,*pOldbr;
  475. pen.CreatePen(PS_SOLID,1, RGB(0,200,0));  
  476. poldPen=dc.SelectObject(&pen);    
  477. brush.CreateSolidBrush(RGB(50,0,0));
  478. //brush.CreateSysColorBrush(2);
  479. pOldbr=dc.SelectObject(&brush);
  480. float x1,y1,x2,y2;
  481. x1=m_flStartX;
  482. y1=m_flStartY;
  483. x2=m_flPrevX;
  484. y2=m_flPrevY;
  485. Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
  486. Lp2Dp(x2,y2);
  487. CRect rt(x1,y1,x2,y2);
  488. rt.NormalizeRect();
  489. dc.Rectangle(&rt);
  490. dc.SelectObject(poldPen);
  491.                 dc.SelectObject(pOldbr);
  492. dc.SetROP2(old_rop);
  493. // Redraw(&dc,&rect,FALSE);
  494. rt=CRect(m_flStartX,m_flStartY,m_flPrevX,m_flPrevY);//用逻辑坐标,利于操作
  495. GetDocument()->SelectInRect(&rt,&dc,nFlags,TRUE);
  496. // SetDrawMenuEnable(!GetDocument()->HasGraphSelected());//协调一直
  497. m_bDrawFlag=FALSE;
  498. break;
  499. }
  500. case _shape_Line:
  501. case _shape_Rectangle:
  502. case _shape_RoundRect:
  503. case _shape_Circle:
  504. case _shape_Ellipse:
  505. {
  506. int old_rop = dc.SetROP2(R2_XORPEN);
  507. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  508. // m_pCurrentShape->Draw(&dc,RGB(0,255,0),m_nCurrentPenWidth+1);
  509. dc.SetROP2(old_rop);
  510. m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  511. // m_pCurrentShape->Draw(&dc);
  512. }
  513. m_bDrawFlag=FALSE;
  514. break;
  515. case _shape_Parallelogram:
  516. {
  517. int nTemp=m_flArrayX.GetSize();
  518. if(nTemp==3){
  519. int old_rop = dc.SetROP2(R2_XORPEN);
  520. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  521.                     m_flArrayX.SetAt(2,flX);
  522. m_flArrayY.SetAt(2,flY);
  523. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  524. dc.SetROP2(old_rop);
  525. m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  526.     m_bDrawFlag=FALSE; 
  527. }
  528. }
  529. break;
  530. case _shape_Polygon:
  531. case _shape_ModelCurve3Param:
  532. case _shape_ModelCurve2AvB:
  533. case _shape_BezierCurve:
  534. {
  535. int old_rop = dc.SetROP2(R2_XORPEN);
  536. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  537. m_flArrayX.SetAt(m_flArrayX.GetSize()-1,flX);
  538. m_flArrayY.SetAt(m_flArrayY.GetSize()-1,flY);
  539. m_flArrayX.Add(flX);
  540. m_flArrayY.Add(flY);
  541. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  542.                m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  543. dc.SetROP2(old_rop);
  544. }
  545. break;
  546. default:
  547. m_bDrawFlag=FALSE;
  548. break;
  549. }
  550. //
  551. }
  552. if(m_bGraphOp){
  553. float flxTemp,flyTemp;
  554. if(m_bSelectRotateCenter){
  555. int old_rop = dc.SetROP2(R2_XORPEN);
  556. float flxTemp,flyTemp;
  557. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  558. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  559. Lp2Dp(flxTemp,flyTemp);
  560. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  561. m_bSelectRotateCenter=FALSE;
  562. m_flRotCenterX=flX;//逻辑坐标点
  563. m_flRotCenterY=flY;            
  564. flxTemp=m_flRotCenterX;
  565. flyTemp=m_flRotCenterY;
  566. Lp2Dp(flxTemp,flyTemp);
  567. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  568. dc.SetROP2(old_rop);
  569. }else{
  570. CUND_Base* pUndo;
  571. switch(m_graph_op)
  572. {
  573. case _graph_magnify:
  574. {
  575. int old_rop = dc.SetROP2(R2_XORPEN);
  576. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  577. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  578. Lp2Dp(flxTemp,flyTemp);
  579. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  580. m_bGraphOp=FALSE;
  581. m_graph_op=_graph_noneOp;
  582. CPen pen,*poldPen;
  583. pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  584. poldPen=dc.SelectObject(&pen);  
  585. float flLx,flRx,flTy,flBy;
  586. flLx=m_rectSelectGraph.left/1000.0;
  587. flTy=m_rectSelectGraph.top/1000.0;
  588. flRx=m_rectSelectGraph.right/1000.0;
  589. flBy=m_rectSelectGraph.bottom/1000.0;
  590. Lp2Dp(flLx,flTy);
  591. Lp2Dp(flRx,flBy);
  592. dc.MoveTo(flLx,flTy);
  593. dc.LineTo(flLx,flBy);
  594. dc.LineTo(flRx,flBy);
  595. dc.LineTo(flRx,flTy);
  596. dc.LineTo(flLx,flTy);
  597. dc.SelectObject(poldPen);  
  598. dc.SetROP2(old_rop);
  599. GetDocument()->RefreshSelectGraph();
  600. SUNDMagnify *pStructMagnify=new SUNDMagnify();
  601. GetDocument()->GetSelGraphIDArray(pStructMagnify->ArrId);
  602. float flDisA,flDisB;
  603. flDisA=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flStartX,m_flStartY);//attention: m_ptStart 
  604. flDisB=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flPrevX,m_flPrevY);
  605. if(flDisA<0.5){
  606. flDisA=0.5;
  607. }
  608. pStructMagnify->flScale=flDisB/flDisA;
  609. pStructMagnify->flCX=m_ptSelectGraphCenter.x/1000.0;
  610. pStructMagnify->flCY=m_ptSelectGraphCenter.y/1000.0;
  611. pUndo = new CUND_Magnify(pStructMagnify);
  612. GetDocument()->m_pCore->AddUndoItem(pUndo);
  613. break;
  614. }
  615. case _graph_rotate:
  616. {
  617. int old_rop = dc.SetROP2(R2_XORPEN);
  618. flxTemp=m_flRotCenterX;
  619. flyTemp=m_flRotCenterY;
  620. Lp2Dp(flxTemp,flyTemp);
  621. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  622. TRACE("OnLButtonUp()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
  623. TRACE("OnLButtonUp()---Device  RotateCenter(%f,%f)n",flxTemp,flyTemp);
  624. m_bGraphOp=FALSE;
  625. m_graph_op=_graph_noneOp;
  626. // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
  627. dc.SetROP2(old_rop);
  628. GetDocument()->RefreshSelectGraph();
  629. SUNDRotate *pStructRotate=new SUNDRotate();
  630. GetDocument()->GetSelGraphIDArray(pStructRotate->ArrId);
  631. pStructRotate->flAngle=
  632. GetAngleFromPoints(m_flRotCenterX,m_flRotCenterY,
  633.      m_flStartX,m_flStartY,m_flPrevX,m_flPrevY);
  634. pStructRotate->flCX=m_flRotCenterX;
  635. pStructRotate->flCY=m_flRotCenterY;
  636. pUndo = new CUND_Rotate(pStructRotate);
  637. GetDocument()->m_pCore->AddUndoItem(pUndo);
  638. break;
  639. }
  640. case _graph_edit:
  641. // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
  642. GetDocument()->RefreshSelectGraph();
  643. break;
  644. case _graph_move:
  645. {
  646. m_bGraphOp=FALSE;
  647. m_graph_op=_graph_noneOp;
  648. SUNDMove *pStructMove=new SUNDMove();
  649. GetDocument()->GetSelGraphIDArray(pStructMove->ArrId);
  650. pStructMove->nStepX=m_flPrevX-m_flStartX;
  651. pStructMove->nStepY=m_flPrevY-m_flStartY;
  652. pUndo = new CUND_Move(pStructMove);
  653. GetDocument()->m_pCore->AddUndoItem(pUndo);
  654. break;
  655. }
  656. case _graph_property:
  657. {
  658. m_bGraphOp=FALSE;
  659. m_graph_op=_graph_noneOp;
  660. break;
  661. }
  662. case _graph_delete:
  663. {
  664. m_bGraphOp=FALSE;
  665. m_graph_op=_graph_noneOp;
  666. break;
  667. }
  668. case _graph_leftToRight:
  669. {
  670. m_bGraphOp=FALSE;
  671. m_graph_op=_graph_noneOp;
  672. break;
  673. }
  674. case _graph_topTobottom:
  675. {
  676. m_bGraphOp=FALSE;
  677. m_graph_op=_graph_noneOp;
  678. break;
  679. }
  680. case _graph_pointsShow:
  681. {
  682. m_bGraphOp=FALSE;
  683. m_graph_op=_graph_noneOp;
  684. break;
  685. }
  686. case _graph_pointsHide:
  687. {
  688. m_bGraphOp=FALSE;
  689. m_graph_op=_graph_noneOp;
  690. break;
  691. }
  692. case _graph_copy:
  693. // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
  694. {
  695. SUNDCopy *pStructCopy=new SUNDCopy();
  696. GetDocument()->GetSelGraphArray(pStructCopy->ArrShape);
  697. CUND_Base* pUndo = new CUND_Copy(pStructCopy);
  698. GetDocument()->m_pCore->AddUndoItem(pUndo);
  699. SendMessage(WM_COMMAND,WPARAM(ID_GRAPH_COPY));
  700.     break;
  701. }
  702. default:
  703. break;
  704. }
  705. }
  706. }
  707. if(!m_bDrawFlag){                //如果不画了,删除缓存的点。
  708. m_flArrayX.RemoveAll();
  709. m_flArrayY.RemoveAll();
  710. m_pCurrentShape=NULL;
  711. ClipCursor(NULL);
  712. }
  713. CScrollView::OnLButtonUp(nFlags, point);
  714. }
  715. void CGraphSoftView::OnMouseMove(UINT nFlags, CPoint point) 
  716. {
  717. // TODO: Add your message handler code here and/or call default
  718. CClientDC dc(this);
  719. OnPrepareDC(&dc);
  720. dc.DPtoLP(&point);
  721.     float flX=point.x;
  722. float flY=point.y;
  723. Dp2Lp(flX,flY);     
  724.   
  725.     CRect rect;
  726. if(m_bDrawFlag)
  727. {
  728. switch(GetDocument()->m_nCurrentShapeType) {
  729. case _shape_none:
  730. {
  731. int old_rop = dc.SetROP2(R2_XORPEN);
  732. CPen pen,*poldPen;
  733. CBrush brush,*pOldbr;
  734. pen.CreatePen(PS_SOLID,1, RGB(0,200,0));  
  735. poldPen=dc.SelectObject(&pen);    
  736. brush.CreateSolidBrush(RGB(50,0,0));
  737. pOldbr=dc.SelectObject(&brush);
  738. dc.SetBkMode(TRANSPARENT);
  739. float x1,y1,x2,y2;
  740. x1=m_flStartX;
  741. y1=m_flStartY;
  742. x2=m_flPrevX;
  743. y2=m_flPrevY;
  744. Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
  745. Lp2Dp(x2,y2);
  746. CRect rt(x1,y1,x2,y2);
  747. rt.NormalizeRect();
  748. x2=flX;
  749. y2=flY;
  750. Lp2Dp(x2,y2);
  751. CRect rectTmp(x1,y1,x2,y2);
  752. //if(rect.left<rectTmp.left||rect.right>rectTmp.right||rect.top<rectTmp.top||rect.bottom>rectTmp.bottom){
  753. dc.Rectangle(&rt);
  754. dc.Rectangle(&rectTmp);
  755. // Redraw(&dc,&rectTmp,FALSE);
  756. dc.SelectObject(poldPen);
  757.                 dc.SelectObject(pOldbr);
  758. dc.SetROP2(old_rop);
  759. break;
  760. }
  761. case _shape_Line:
  762. case _shape_Rectangle:
  763. case _shape_RoundRect:
  764. case _shape_Circle:
  765. case _shape_Ellipse:
  766. case _shape_Polygon:
  767. case _shape_ModelCurve3Param:
  768. case _shape_ModelCurve2AvB:
  769. case _shape_BezierCurve:
  770. {
  771. //m_pCurrentShape=GetDocument()->m_shapeList.GetTail();
  772. if(m_flArrayX.GetSize()>0){
  773. int old_rop = dc.SetROP2(R2_XORPEN);
  774. rect=m_pCurrentShape->GetBoundaryRect();
  775. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  776. // m_pCurrentShape->Draw(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1);
  777. m_flArrayX.SetAt(m_flArrayX.GetSize()-1,flX);
  778. m_flArrayY.SetAt(m_flArrayY.GetSize()-1,flY);
  779. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  780. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  781. //    m_pCurrentShape->Draw(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1);
  782. dc.SetROP2(old_rop);
  783. }
  784. break;
  785. }
  786. case _shape_Parallelogram:
  787. {
  788. if(m_flArrayX.GetSize()>0&&m_flArrayX.GetSize()<=2){
  789. int old_rop = dc.SetROP2(R2_XORPEN);
  790. //rect=GetRectFromPoint(m_ptStart,m_ptPrev);
  791. float x1=m_flStartX;
  792. float y1=m_flStartY;
  793. float x2=m_flPrevX;
  794. float y2=m_flPrevY;
  795. Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
  796. Lp2Dp(x2,y2);
  797. DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);  
  798.                    // Redraw(&dc,&rect);
  799. x2=flX;
  800. y2=flY;
  801. Lp2Dp(x2,y2);
  802. DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1); 
  803. dc.SetROP2(old_rop);
  804. } else if(m_flArrayX.GetSize()==3){
  805. int old_rop = dc.SetROP2(R2_XORPEN);
  806. // rect=m_pCurrentShape->GetBoundaryRect();
  807. // Redraw(&dc,&rect,FALSE);
  808. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  809. m_flArrayX.SetAt(2,flX);
  810. m_flArrayY.SetAt(2,flY);
  811. m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
  812. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  813.     dc.SetROP2(old_rop);
  814. }
  815. }
  816. break;
  817. default:
  818. break;
  819. }//switch{case:}
  820. }//if
  821. if(m_bGraphOp&&(nFlags&MK_LBUTTON)&&!m_bSelectRotateCenter){
  822.   GraphOperator(&dc,m_graph_op,m_flPrevX,m_flPrevY,flX,flY);
  823. }else if(m_bGraphOp&&m_graph_op==_graph_copy){//copy 例外
  824. GraphOperator(&dc,m_graph_op,m_flPrevX,m_flPrevY,flX,flY);
  825. }else if(m_bGraphOp&&m_graph_op==_graph_edit){
  826. GetDocument()->SetEditStateCursor(flX,flY,((float)m_rectTarget.Width())/m_rectMaxWindow.Width());
  827. }
  828. m_flPrevX=flX;
  829. m_flPrevY=flY;
  830. CString strTemp;
  831. strTemp.Format("屏幕:(%d,%d)    逻辑:(%d,%d)",point.x,point.y,(int)flX,(int)flY);
  832. //TRACE("%sn",strTemp);
  833. ((CMainFrame*)(AfxGetApp()->GetMainWnd()))->SetPaneText(1,LPCSTR(strTemp),TRUE);
  834. // CScrollView::OnMouseMove(nFlags, point);
  835. }
  836. ////////////////////////////////////////////////////////////////
  837. //function GraphOperator(...)
  838. //param 
  839. //opId-----the ID if Graph Operation that should be execute
  840. //nstepx---the  step in x direction 
  841. //nstepy---the  step in y direction
  842. //point----the present point of mouse
  843. /////////////////////////////////////////////////////////////// 
  844. void CGraphSoftView::GraphOperator(CDC *pDC,GRAPH_OPERATION opId,float PrevX,float PrevY,float CurX,float CurY)
  845. {
  846. CPoint ptPrev(PrevX,PrevY);
  847. CPoint ptPresent(CurX,CurY);
  848. POSITION pos;
  849. CRect rect=GetSelectGraphBoundaryRect();
  850. CPoint ptCenter=rect.CenterPoint();
  851. float flAngle;
  852.     float flScale=1;
  853. CPoint ptStart(m_flStartX,m_flStartY);
  854. //Get the angle that should rotate
  855. //先求出两点(前点与移动后点)向中心点的连线与水平线的交角
  856. //然后减一下即可得到转过的角度
  857.     int old_rop = pDC->SetROP2(R2_XORPEN);
  858. pDC->SetBkMode(TRANSPARENT);
  859. switch(opId){
  860. case _graph_magnify:
  861. {
  862. float flDisA,flDisB;
  863. flDisA=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flStartX,m_flStartY);//attention: m_ptStart 
  864. flDisB=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,CurX,CurY);
  865. if(flDisA<0.5){
  866. flDisA=0.5;
  867. }
  868. flScale=flDisB/flDisA;
  869. //Redraw(pDC,&rect,TRUE,RGB(255,255,255));
  870. CPen pen,*poldPen;
  871. pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  872. poldPen=pDC->SelectObject(&pen);  
  873. float flLx,flRx,flTy,flBy;
  874. flLx=rect.left/1000.0;
  875. flTy=rect.top/1000.0;
  876. flRx=rect.right/1000.0;
  877. flBy=rect.bottom/1000.0;
  878. Lp2Dp(flLx,flTy);
  879. Lp2Dp(flRx,flBy);
  880. pDC->MoveTo(flLx,flTy);
  881. pDC->LineTo(flLx,flBy);
  882. pDC->LineTo(flRx,flBy);
  883. pDC->LineTo(flRx,flTy);
  884. pDC->LineTo(flLx,flTy);
  885. float flxTemp,flyTemp;
  886. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  887. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  888. Lp2Dp(flxTemp,flyTemp);
  889. DrawOutRectPoint(pDC,flxTemp,flyTemp,RGB(0,255,0));
  890. pDC->SelectObject(poldPen);     
  891. //TRACE("SCALE:%fn",flScale);
  892. break;
  893. }
  894. case _graph_rotate:
  895. {
  896. if(ptPresent==ptPrev)
  897. return;
  898. //Redraw(pDC,&rect,FALSE);
  899. float flx,fly;
  900. flx=m_flRotCenterX;
  901. fly=m_flRotCenterY;
  902. Lp2Dp(flx,fly);
  903. DrawOutRectPoint(pDC,flx,fly,RGB(0,255,0));
  904. TRACE("GraphOperator()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
  905. TRACE("GraphOperator()---Device  RotateCenter(%f,%f)n",flx,fly);
  906. flAngle=GetAngleFromPoints(m_flRotCenterX,m_flRotCenterY,m_flStartX,m_flStartY,CurX,CurY);
  907. //TRACE("ANGLE:-%f,Cos----%f,Sin-----%fn",flAngle,cos(flAngle),sin(flAngle));
  908. break;
  909. }
  910. default:
  911. break;
  912. }//end switch
  913.     ////////////
  914. pDC->SetROP2(old_rop);
  915. pos=GetDocument()->m_shapeList.GetHeadPosition();
  916. while (pos!=NULL) {
  917. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  918. if(pShape->IsSelected()){
  919. pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  920. switch(opId)
  921. {
  922. case _graph_move:
  923. {
  924. pShape->Move(pDC,CurX-PrevX,CurY-PrevY);
  925. break;
  926. }
  927. case _graph_rotate:
  928. {
  929. pShape->Rotate(pDC,m_flRotCenterX,m_flRotCenterY,flAngle);
  930. break;
  931. }
  932. case _graph_magnify:
  933. {
  934. pShape->Magnify(pDC,m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,flScale);
  935. break;
  936. }
  937. case _graph_property:
  938. case _graph_delete:
  939. break;
  940. case _graph_copy:
  941. pShape->Move(pDC,CurX-PrevX,CurY-PrevY);
  942. break;
  943. case _graph_edit:
  944. pShape->PartMove(pDC,m_flPrevX,m_flPrevY,CurX,CurY);
  945.     SetCursor(AfxGetApp()->LoadCursor(m_unPrevCur));
  946. break;
  947. default:
  948. break;
  949. }
  950. }
  951. pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
  952. }
  953. pDC->SetROP2(R2_XORPEN);
  954. switch(opId){
  955. case _graph_move:
  956. //rect=GetSelectGraphBoundaryRect();
  957.         //Redraw(pDC,&rect,FALSE);
  958. break;
  959. case _graph_copy:
  960. // Redraw(pDC,&rect,FALSE);
  961.       //  rect=GetSelectGraphBoundaryRect();
  962. //Redraw(pDC,&rect,FALSE);
  963. break;
  964. case _graph_rotate:
  965. {
  966. //rect=GetSelectGraphBoundaryRect();
  967. float flx,fly;
  968. flx=m_flRotCenterX;
  969. fly=m_flRotCenterY;
  970. Lp2Dp(flx,fly);
  971. TRACE("GraphOperator()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
  972. TRACE("GraphOperator()---Device  RotateCenter(%f,%f)n",flx,fly);
  973. DrawOutRectPoint(pDC,flx,fly,RGB(0,255,0));
  974. //Redraw(pDC,&rect,FALSE);
  975. break;
  976. }
  977. case _graph_magnify:
  978. {
  979. rect=GetSelectGraphBoundaryRect();
  980. // Redraw(pDC,&rect,TRUE,RGB(255,255,0));
  981. CPen pen,*poldPen;
  982. pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  983. poldPen=pDC->SelectObject(&pen);  
  984. float flLx,flRx,flTy,flBy;
  985. flLx=m_rectSelectGraph.left/1000.0;
  986. flTy=m_rectSelectGraph.top/1000.0;
  987. flRx=m_rectSelectGraph.right/1000.0;
  988. flBy=m_rectSelectGraph.bottom/1000.0;
  989. Lp2Dp(flLx,flTy);
  990. Lp2Dp(flRx,flBy);
  991. pDC->MoveTo(flLx,flTy);
  992. pDC->LineTo(flLx,flBy);
  993. pDC->LineTo(flRx,flBy);
  994. pDC->LineTo(flRx,flTy);
  995. pDC->LineTo(flLx,flTy);
  996. float flxTemp,flyTemp;
  997. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  998. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  999. Lp2Dp(flxTemp,flyTemp);
  1000. DrawOutRectPoint(pDC,flxTemp,flyTemp,RGB(0,255,0));
  1001.     pDC->SelectObject(poldPen);     
  1002. break;
  1003. }
  1004. case _graph_edit:
  1005. // rect=GetSelectGraphBoundaryRect();
  1006. // Redraw(pDC,&rect,FALSE);
  1007. break;
  1008. default:
  1009. break;
  1010. }//end switch
  1011. }
  1012. //////////////////////////////////////////////////////
  1013. void CGraphSoftView::OnDrawDdaline() 
  1014. {
  1015. // TODO: Add your command handler code here
  1016. if(GetDocument()->m_nCurrentShapeType ==_shape_Line)
  1017. GetDocument()->m_nCurrentShapeType=_shape_none;
  1018. else
  1019. GetDocument()->m_nCurrentShapeType=_shape_Line;
  1020. OnOperationOver() ;
  1021. }
  1022. //////////////////////////////////////////////////////
  1023. void CGraphSoftView::OnFileExport() 
  1024. {
  1025. // TODO: Add your command handler code here
  1026. CClientDC dc(this);
  1027. // OnPrepareDC(&dc);
  1028. CDC  memDC;
  1029. CRect rect;
  1030. GetClientRect(rect);
  1031. memDC.CreateCompatibleDC(&dc);
  1032. CBitmap bm;
  1033. int Width = rect.Width();
  1034. int Height = rect.Height();
  1035. bm.CreateCompatibleBitmap(&dc, Width, Height);
  1036. CBitmap*  pOld = memDC.SelectObject(&bm);
  1037. memDC.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);
  1038. memDC.SelectObject(pOld);
  1039. BITMAP  btm;
  1040. bm.GetBitmap(&btm);
  1041. DWORD  size = btm.bmWidthBytes * btm.bmHeight;
  1042. LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);
  1043. BITMAPFILEHEADER   bfh;
  1044. /////////////////////////////////////////////
  1045. BITMAPINFOHEADER  bih;
  1046. bih.biBitCount = btm.bmBitsPixel;
  1047. bih.biClrImportant = 0;
  1048. bih.biClrUsed = 0;
  1049. bih.biCompression = 0;
  1050. bih.biHeight = btm.bmHeight;
  1051. bih.biPlanes = 1;
  1052. bih.biSize = sizeof(BITMAPINFOHEADER);
  1053. bih.biSizeImage = size;
  1054. bih.biWidth = btm.bmWidth;
  1055. bih.biXPelsPerMeter = 0;
  1056. bih.biYPelsPerMeter = 0;
  1057. GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
  1058. //bm.GetBitmapBits(size,lpData);//此函数在处理5-5-5模式的16位色下会出现颜色混乱
  1059. bfh.bfReserved1 = bfh.bfReserved2 = 0;
  1060. bfh.bfType = ((WORD)('M'<< 8)|'B');
  1061. bfh.bfSize = 54 + size;
  1062. bfh.bfOffBits = 54;
  1063. CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.lld|*.lld|*.*|*.*|"));
  1064. if (dlg.DoModal()==IDOK)
  1065. {
  1066. if(dlg.GetFileExt()=="bmp"){
  1067. CFile  bf;
  1068. CString ss=dlg.GetPathName();
  1069. if(bf.Open(ss, CFile::modeCreate | CFile::modeWrite))
  1070. {
  1071. bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
  1072. bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
  1073. bf.WriteHuge(lpData, size);
  1074. bf.Close();
  1075. CString str;
  1076. str.LoadString(IDS_STRING_SAVE_SUCCESS);
  1077. AfxMessageBox(str);
  1078. }
  1079. }else if(dlg.GetFileExt()=="lld"){
  1080. FILE *OutStream;
  1081. OutStream = fopen(dlg.GetPathName(), "w" );
  1082. GetDocument()->ExPort(OutStream);
  1083. fclose(OutStream);
  1084. }
  1085. }
  1086. GlobalFreePtr(lpData);
  1087. }
  1088. //////////////////////////////////////////////////
  1089. int CGraphSoftView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  1090. {
  1091. if (CScrollView::OnCreate(lpCreateStruct) == -1)
  1092. return -1;
  1093. GetDocument()->m_pCore->m_pView=this;
  1094. // TODO: Add your specialized creation code here
  1095. return 0;
  1096. }
  1097. void CGraphSoftView::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
  1098. {
  1099. CWnd ::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  1100. // TODO: Add your message handler code here
  1101. }
  1102. //////////////////////////////////////////////////////
  1103. void CGraphSoftView::OnContextMenu(CWnd* pWnd, CPoint point) 
  1104. {
  1105. // TODO: Add your message handler code here
  1106. CMenu popup;
  1107. // CMenu* pPopup;
  1108. CMenuEx menu;
  1109. CString str;
  1110. if(!m_nMouseFlag)
  1111. {
  1112. //图形操作
  1113. if(GetDocument()->HasGraphSelected()&&m_graph_op==_graph_noneOp)
  1114. {
  1115. m_pToolBar=&(((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndTBarGraphOp);
  1116. menu.CreatePopupMenu();
  1117. str.LoadString(ID_GRAPH_MOVE);//移动
  1118. str=str.Left(str.FindOneOf(_T("n")));
  1119. menu.AppendMenu(MF_ENABLED,ID_GRAPH_MOVE,str);
  1120. str.LoadString(ID_GRAPH_ROTATE);//旋转
  1121. str=str.Left(str.FindOneOf(_T("n")));
  1122. menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE,str);
  1123. str.LoadString(ID_GRAPH_MAGNIFY);//缩放
  1124. str=str.Left(str.FindOneOf(_T("n")));
  1125. menu.AppendMenu(MF_ENABLED,ID_GRAPH_MAGNIFY,str);
  1126. str.LoadString(ID_GRAPH_COPY);//拷贝
  1127. str=str.Left(str.FindOneOf(_T("n")));
  1128. menu.AppendMenu(MF_ENABLED,ID_GRAPH_COPY,str);
  1129. str.LoadString(ID_GRAPH_DELETE);//删除
  1130. str=str.Left(str.FindOneOf(_T("n")));
  1131. menu.AppendMenu(MF_ENABLED,ID_GRAPH_DELETE,str);
  1132. CMenuEx menuTemp; //显示/隐藏组成点---弹出菜单
  1133. menuTemp.CreatePopupMenu();
  1134. str.LoadString(ID_GRAPH_POINTSSHOW);//显示组成点
  1135. str=str.Left(str.FindOneOf(_T("n")));
  1136. menuTemp.AppendMenu(MF_ENABLED,ID_GRAPH_POINTSSHOW,str);
  1137. str.LoadString(ID_GRAPH_POINTSHIDE);//隐藏组成点
  1138. str=str.Left(str.FindOneOf(_T("n")));
  1139. menuTemp.AppendMenu(MF_ENABLED,ID_GRAPH_POINTSHIDE,str); 
  1140. menuTemp.InitPopupMenu(&menuTemp,IDR_GRAPH_OPERATION,m_pToolBar);
  1141. str.LoadString(IDS_GRAPH_POINTS);
  1142. menu.AppendMenu(MF_POPUP,(UINT)(menuTemp.GetSafeHmenu()),str);
  1143. if(GetDocument()->GetSelectNum()==1){
  1144. str.LoadString(ID_GRAPH_EDIT);//编辑
  1145. str=str.Left(str.FindOneOf(_T("n")));
  1146. menu.AppendMenu(MF_ENABLED,ID_GRAPH_EDIT,str);
  1147. }
  1148. str.LoadString(ID_GRAPH_PROPERTIY);
  1149. str=str.Left(str.FindOneOf(_T("n")));
  1150. menu.AppendMenu(MF_ENABLED,ID_GRAPH_PROPERTIY,str);//属性
  1151.     menu.AppendMenu(MF_GRAYED,ID_SEPARATOR);
  1152. str.LoadString(ID_GRAPHOP_MORE);
  1153. menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_MORE,str);
  1154. menu.InitPopupMenu(&menu,IDR_GRAPH_OPERATION,m_pToolBar);
  1155. UINT nMenuID=menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD ,
  1156. point.x,point.y, this);
  1157. while(nMenuID==ID_GRAPHOP_MORE||nMenuID==ID_GRAPHOP_LESS){
  1158. if(nMenuID==ID_GRAPHOP_MORE){
  1159. menu.DeleteMenu(ID_GRAPHOP_MORE,MF_BYCOMMAND);
  1160. menu.DeleteItem(ID_GRAPHOP_MORE);
  1161. str.LoadString(ID_GRAPHOP_LESS);
  1162. menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_LESS,str);   
  1163. str.LoadString(ID_GRAPH_LEFTTORIGHT);
  1164. str=str.Left(str.FindOneOf(_T("n")));
  1165. menu.AppendMenu(MF_ENABLED,ID_GRAPH_LEFTTORIGHT,str);//左右变换
  1166. str.LoadString(ID_GRAPH_TOPTOBOTTOM);
  1167. str=str.Left(str.FindOneOf(_T("n")));
  1168. menu.AppendMenu(MF_ENABLED,ID_GRAPH_TOPTOBOTTOM,str);//上下变换
  1169. }else{
  1170. menu.DeleteMenu(ID_GRAPHOP_LESS,MF_BYCOMMAND);
  1171. menu.DeleteItem(ID_GRAPHOP_LESS);
  1172. menu.DeleteMenu(ID_GRAPH_LEFTTORIGHT,MF_BYCOMMAND);
  1173. menu.DeleteItem(ID_GRAPH_LEFTTORIGHT);
  1174. menu.DeleteMenu(ID_GRAPH_TOPTOBOTTOM,MF_BYCOMMAND);
  1175. menu.DeleteItem(ID_GRAPH_TOPTOBOTTOM);
  1176.                     str.LoadString(ID_GRAPHOP_MORE);
  1177. menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_MORE,str);
  1178. }
  1179. menu.m_bInitial=FALSE;
  1180. menu.ChangeStyle(&menu,m_pToolBar,TRUE);
  1181. nMenuID=menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD ,
  1182. point.x,point.y, this); ;
  1183. }
  1184. this->SendMessage(WM_COMMAND,WPARAM(nMenuID));
  1185. menu.DestroyMenu();
  1186. menuTemp.DestroyMenu();
  1187. }
  1188. //图形操作子操作
  1189. else if(GetDocument()->HasGraphSelected()){
  1190. m_pToolBar=&(((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndTBarGraphOp);
  1191. menu.CreatePopupMenu();
  1192. switch(m_graph_op){
  1193. case _graph_rotate:
  1194. str.LoadString(ID_GRAPH_ROTATE_LEFT);
  1195. str=str.Left(str.FindOneOf(_T("n")));
  1196. menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE_LEFT,str);
  1197. str.LoadString(ID_GRAPH_ROTATE_RIGHT);
  1198. str=str.Left(str.FindOneOf(_T("n")));
  1199. menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE_RIGHT,str);
  1200. str.LoadString(ID_GRAPH_ROTATECENTER_SET);
  1201. str=str.Left(str.FindOneOf(_T("n")));
  1202. if(m_bSelectRotateCenter){
  1203. menu.AppendMenu(MF_ENABLED|MF_CHECKED,ID_GRAPH_ROTATECENTER_SET,str);
  1204. }else{
  1205. menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATECENTER_SET,str);
  1206. }
  1207. menu.AppendMenu(MF_ENABLED,ID_SEPARATOR);
  1208. break;
  1209. case _graph_magnify:
  1210. break;
  1211. case _graph_copy:
  1212. break;
  1213. default:
  1214. break;
  1215. }
  1216. str.LoadString(ID_OPERATION_OVER);
  1217. str=str.Left(str.FindOneOf(_T("n")));
  1218. menu.AppendMenu(MF_ENABLED,ID_OPERATION_OVER,str);
  1219. menu.InitPopupMenu(&menu,IDR_GRAPH_OPERATION,m_pToolBar);
  1220. menu.TrackPopupMenu(TPM_LEFTALIGN ,point.x,point.y,this);
  1221. menu.DestroyMenu();
  1222. }
  1223. //画图时的操作
  1224. else if(GetDocument()->m_nCurrentShapeType!=_shape_none){
  1225. CString strMenuTitle;
  1226. popup.CreatePopupMenu();
  1227. switch(GetDocument()->m_nCurrentShapeType){
  1228. case _shape_Polygon:
  1229. if(m_pCurrentShape!=NULL){
  1230. strMenuTitle.LoadString(ID_INPUT_CONFIRM);
  1231. popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
  1232. }
  1233. break;
  1234. case _shape_ModelCurve3Param:
  1235. if(m_pCurrentShape!=NULL){
  1236. strMenuTitle.LoadString(ID_INPUT_CONFIRM);
  1237. popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
  1238. }
  1239. break;
  1240. case _shape_ModelCurve2AvB:
  1241. if(m_pCurrentShape!=NULL){
  1242. strMenuTitle.LoadString(ID_INPUT_CONFIRM);
  1243. popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
  1244. }
  1245. break;
  1246. case _shape_BezierCurve:
  1247. if(m_pCurrentShape!=NULL){
  1248. strMenuTitle.LoadString(ID_INPUT_CONFIRM);
  1249. popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
  1250. }
  1251. break;
  1252. default:
  1253. break;
  1254. }
  1255. strMenuTitle.LoadString(ID_SHAPE_OVER);
  1256. strMenuTitle=strMenuTitle.Left(strMenuTitle.FindOneOf(_T("n")));
  1257. popup.AppendMenu(MF_ENABLED,ID_SHAPE_OVER,strMenuTitle);
  1258. //popup.EnableMenuItem(1,MF_BYPOSITION|MF_GRAYED);
  1259. popup.TrackPopupMenu(TPM_LEFTALIGN ,point.x,point.y,this);
  1260. popup.DestroyMenu();
  1261. }
  1262. }
  1263. }
  1264. //////////////////////////////////////////////////////
  1265. void CGraphSoftView::OnLButtonDblClk(UINT nFlags, CPoint point) 
  1266. {
  1267. // TODO: Add your message handler code here and/or call default
  1268. if(GetDocument()->m_nCurrentShapeType!=_shape_none){
  1269. SendMessage(WM_COMMAND,WPARAM(ID_INPUT_CONFIRM));
  1270. }
  1271. if(m_graph_op!=_graph_noneOp){
  1272. SendMessage(WM_COMMAND,WPARAM(ID_OPERATION_OVER));
  1273. }
  1274. CScrollView::OnLButtonDblClk(nFlags, point);
  1275. }
  1276. //////////////////////////////////////////////////////
  1277. void CGraphSoftView::SetDrawMenuEnable(bool bEnable)
  1278. {
  1279. m_bCanSelectGraphType=bEnable;
  1280. }
  1281. void CGraphSoftView::OnUpdateDrawDdaline(CCmdUI* pCmdUI) 
  1282. {
  1283. // TODO: Add your command update UI handler code here
  1284. pCmdUI->Enable(m_bCanSelectGraphType);
  1285. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Line?1:0);
  1286. }
  1287. void CGraphSoftView::OnDrawRectangle() 
  1288. {
  1289. // TODO: Add your command handler code here
  1290. if(GetDocument()->m_nCurrentShapeType ==_shape_Rectangle)
  1291. GetDocument()->m_nCurrentShapeType=_shape_none;
  1292. else
  1293. GetDocument()->m_nCurrentShapeType=_shape_Rectangle;
  1294. OnOperationOver() ;
  1295. }
  1296. void CGraphSoftView::OnDrawRoundrect() 
  1297. {
  1298. // TODO: Add your command handler code here
  1299. if(GetDocument()->m_nCurrentShapeType ==_shape_RoundRect)
  1300. GetDocument()->m_nCurrentShapeType=_shape_none;
  1301. else
  1302. GetDocument()->m_nCurrentShapeType=_shape_RoundRect;
  1303. OnOperationOver() ;
  1304. }
  1305. void CGraphSoftView::OnDrawPolygon() 
  1306. {
  1307. // TODO: Add your command handler code here
  1308. if(GetDocument()->m_nCurrentShapeType ==_shape_Polygon)
  1309. GetDocument()->m_nCurrentShapeType=_shape_none;
  1310. else
  1311. GetDocument()->m_nCurrentShapeType=_shape_Polygon;
  1312. OnOperationOver() ;
  1313. }
  1314. void CGraphSoftView::OnUpdateDrawPolygon(CCmdUI* pCmdUI) 
  1315. {
  1316. // TODO: Add your command update UI handler code here
  1317. pCmdUI->Enable(m_bCanSelectGraphType);
  1318. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Polygon?1:0);
  1319. }
  1320. void CGraphSoftView::OnUpdateDrawRectangle(CCmdUI* pCmdUI) 
  1321. {
  1322. // TODO: Add your command update UI handler code here
  1323. pCmdUI->Enable(m_bCanSelectGraphType);
  1324. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Rectangle?1:0);
  1325. }
  1326. void CGraphSoftView::OnUpdateDrawRoundrect(CCmdUI* pCmdUI) 
  1327. {
  1328. // TODO: Add your command update UI handler code here
  1329. pCmdUI->Enable(m_bCanSelectGraphType);
  1330. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_RoundRect?1:0);
  1331. }
  1332. void CGraphSoftView::OnDrawEllipse() 
  1333. {
  1334. // TODO: Add your command handler code here
  1335. if(GetDocument()->m_nCurrentShapeType ==_shape_Ellipse)
  1336. GetDocument()->m_nCurrentShapeType=_shape_none;
  1337. else
  1338. GetDocument()->m_nCurrentShapeType=_shape_Ellipse;
  1339. OnOperationOver() ;
  1340. }
  1341. void CGraphSoftView::OnUpdateDrawEllipse(CCmdUI* pCmdUI) 
  1342. {
  1343. // TODO: Add your command update UI handler code here
  1344. pCmdUI->Enable(m_bCanSelectGraphType);
  1345. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Ellipse?1:0);
  1346. }
  1347. void CGraphSoftView::OnDrawCircle() 
  1348. {
  1349. // TODO: Add your command handler code here
  1350. if(GetDocument()->m_nCurrentShapeType ==_shape_Circle)
  1351. GetDocument()->m_nCurrentShapeType=_shape_none;
  1352. else
  1353. GetDocument()->m_nCurrentShapeType=_shape_Circle;
  1354. OnOperationOver() ;
  1355. }
  1356. void CGraphSoftView::OnUpdateDrawCircle(CCmdUI* pCmdUI) 
  1357. {
  1358. // TODO: Add your command update UI handler code here
  1359. pCmdUI->Enable(m_bCanSelectGraphType);
  1360. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Circle?1:0);
  1361. }
  1362. void CGraphSoftView::OnDrawParallelogram() 
  1363. {
  1364. // TODO: Add your command handler code here
  1365. if(GetDocument()->m_nCurrentShapeType ==_shape_Parallelogram)
  1366. GetDocument()->m_nCurrentShapeType=_shape_none;
  1367. else
  1368. GetDocument()->m_nCurrentShapeType=_shape_Parallelogram;
  1369. OnOperationOver() ;
  1370. }
  1371. void CGraphSoftView::OnUpdateDrawParallelogram(CCmdUI* pCmdUI) 
  1372. {
  1373. // TODO: Add your command update UI handler code here
  1374. pCmdUI->Enable(m_bCanSelectGraphType);
  1375. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Parallelogram?1:0);
  1376. }
  1377. void CGraphSoftView::OnDrawNone() 
  1378. {
  1379. // TODO: Add your command handler code here
  1380. GetDocument()->m_nCurrentShapeType=_shape_none;
  1381. OnOperationOver() ;
  1382. }
  1383. void CGraphSoftView::OnUpdateDrawNone(CCmdUI* pCmdUI) 
  1384. {
  1385. // TODO: Add your command update UI handler code here
  1386. pCmdUI->Enable(m_bCanSelectGraphType);
  1387. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_none?1:0);
  1388. }
  1389. void CGraphSoftView::OnDrawModelcurve2avb() 
  1390. {
  1391. // TODO: Add your command handler code here
  1392. if(GetDocument()->m_nCurrentShapeType ==_shape_ModelCurve2AvB)
  1393. GetDocument()->m_nCurrentShapeType=_shape_none;
  1394. else
  1395. GetDocument()->m_nCurrentShapeType=_shape_ModelCurve2AvB;
  1396. OnOperationOver() ;
  1397. }
  1398. void CGraphSoftView::OnUpdateDrawModelcurve2avb(CCmdUI* pCmdUI) 
  1399. {
  1400. // TODO: Add your command update UI handler code here
  1401. pCmdUI->Enable(m_bCanSelectGraphType);
  1402. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_ModelCurve2AvB?1:0);
  1403. }
  1404. void CGraphSoftView::OnDrawModelcurve3param() 
  1405. {
  1406. // TODO: Add your command handler code here
  1407. if(GetDocument()->m_nCurrentShapeType ==_shape_ModelCurve3Param)
  1408. GetDocument()->m_nCurrentShapeType=_shape_none;
  1409. else
  1410. GetDocument()->m_nCurrentShapeType=_shape_ModelCurve3Param;
  1411. OnOperationOver() ;
  1412. }
  1413. void CGraphSoftView::OnUpdateDrawModelcurve3param(CCmdUI* pCmdUI) 
  1414. {
  1415. // TODO: Add your command update UI handler code here
  1416. pCmdUI->Enable(m_bCanSelectGraphType);
  1417. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_ModelCurve3Param?1:0);
  1418. }
  1419. void CGraphSoftView::OnDrawBeziercurve() 
  1420. {
  1421. // TODO: Add your command handler code here
  1422. if(GetDocument()->m_nCurrentShapeType ==_shape_BezierCurve)
  1423. GetDocument()->m_nCurrentShapeType=_shape_none;
  1424. else
  1425. GetDocument()->m_nCurrentShapeType=_shape_BezierCurve;
  1426. OnOperationOver() ;
  1427. }
  1428. void CGraphSoftView::OnUpdateDrawBeziercurve(CCmdUI* pCmdUI) 
  1429. {
  1430. // TODO: Add your command update UI handler code here
  1431. pCmdUI->Enable(m_bCanSelectGraphType);
  1432. pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_BezierCurve?1:0);
  1433. }
  1434. //////////////////////////////////////////////////////
  1435. CRect CGraphSoftView::GetSelectGraphBoundaryRect()
  1436. {
  1437. CRect rectRltVal(0,0,0,0);
  1438.     rectRltVal=GetDocument()->GetSelectGraphBoundaryRect();
  1439. m_rectSelectGraph=rectRltVal;
  1440. return rectRltVal;
  1441. }
  1442. ///////////////////////////////////////////////////////
  1443. //function----RefreshSelectGraph
  1444. //一般用于旋转和缩放选中图形后对数据的图形数据的更新
  1445. ////////////////////////////////////////////////////
  1446. //////////////////////////////////////////////////////
  1447. CPoint CGraphSoftView::GetSelectGraphCenter()
  1448. {
  1449. CRect rect=GetSelectGraphBoundaryRect();
  1450. //m_ptSelectGraphCenter=rect.CenterPoint();
  1451. return m_ptSelectGraphCenter;
  1452. }
  1453. //////////////////////////////////////////////////////
  1454. void CGraphSoftView::OnGraphMove() 
  1455. {
  1456. // TODO: Add your command handler code here
  1457. m_bDrawFlag=FALSE;
  1458. m_graph_op=_graph_move;
  1459. m_bGraphOp=TRUE;
  1460. }
  1461. void CGraphSoftView::OnGraphMagnify() 
  1462. {
  1463. // TODO: Add your command handler code here
  1464. m_bDrawFlag=FALSE;
  1465. m_graph_op=_graph_magnify;
  1466. m_bGraphOp=TRUE;
  1467. CClientDC dc(this);
  1468. OnPrepareDC(&dc);
  1469. int old_rop = dc.SetROP2(R2_XORPEN);
  1470. CRect rect;
  1471. rect=GetSelectGraphBoundaryRect();
  1472. m_ptSelectGraphCenter=rect.CenterPoint();
  1473. //Redraw(&dc,&rect,TRUE,RGB(255,255,0));
  1474. CPen pen,*poldPen;
  1475. pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  1476. poldPen=dc.SelectObject(&pen);  
  1477. float flLx,flRx,flTy,flBy;
  1478. flLx=m_rectSelectGraph.left/1000.0;
  1479. flTy=m_rectSelectGraph.top/1000.0;
  1480. flRx=m_rectSelectGraph.right/1000.0;
  1481. flBy=m_rectSelectGraph.bottom/1000.0;
  1482. Lp2Dp(flLx,flTy);
  1483. Lp2Dp(flRx,flBy);
  1484. dc.MoveTo(flLx,flTy);
  1485. dc.LineTo(flLx,flBy);
  1486. dc.LineTo(flRx,flBy);
  1487. dc.LineTo(flRx,flTy);
  1488. dc.LineTo(flLx,flTy);
  1489. dc.SelectObject(poldPen);   
  1490. float flxTemp,flyTemp;
  1491. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  1492. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  1493. Lp2Dp(flxTemp,flyTemp);
  1494. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  1495. dc.SetROP2(old_rop);
  1496. }
  1497. void CGraphSoftView::OnGraphRotate() 
  1498. {
  1499. // TODO: Add your command handler code here
  1500. m_bDrawFlag=FALSE;
  1501. m_graph_op=_graph_rotate;
  1502. m_bGraphOp=TRUE;
  1503. m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
  1504.     m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
  1505. m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
  1506. float flx,fly;
  1507. flx=m_flRotCenterX;
  1508. fly=m_flRotCenterY;
  1509. Lp2Dp(flx,fly);
  1510. m_bSelectRotateCenter=FALSE;
  1511. CClientDC dc(this);
  1512. OnPrepareDC(&dc);
  1513. int old_rop = dc.SetROP2(R2_XORPEN);
  1514. DrawOutRectPoint(&dc,flx,fly,RGB(0,255,0));
  1515. TRACE("OnGraphRotate()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
  1516. TRACE("OnGraphRotate()---Device  RotateCenter(%f,%f)n",flx,fly);
  1517. // dc.SetPixel(m_ptRotateCenter.x-1,m_ptRotateCenter.y-1,RGB(0,255,0));
  1518. // dc.SetPixel(m_ptRotateCenter.x-1,m_ptRotateCenter.y+1,RGB(0,255,0));
  1519. // dc.SetPixel(m_ptRotateCenter.x+1,m_ptRotateCenter.y-1,RGB(0,255,0));
  1520. // dc.SetPixel(m_ptRotateCenter.x+1,m_ptRotateCenter.y+1,RGB(0,255,0));
  1521. dc.SetROP2(old_rop);
  1522. }
  1523. void CGraphSoftView::OnGraphPropertiy() 
  1524. {
  1525. // TODO: Add your command handler code here
  1526. CGraphInfoDlg dlg(this);
  1527. SUNDProperty *pSProperty=new SUNDProperty();
  1528. GetDocument()->GetSelGraphPropertyArr(pSProperty->ArrPropertyPrev);
  1529. if(dlg.DoModal()==IDOK){
  1530. GetDocument()->GetSelGraphPropertyArr(pSProperty->ArrPropertyCur);
  1531. for(int i=0;i<pSProperty->ArrPropertyCur.GetSize();i++){
  1532. SUNDPropertyUnit& SPropertyUnitPrev = pSProperty->ArrPropertyPrev.GetAt(i);
  1533. SPropertyUnitPrev.flRCX=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().x/1000.0;
  1534.     SPropertyUnitPrev.flRCY=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().y/1000.0;
  1535. SPropertyUnitPrev.flAngle=dlg.m_nAngle*PI/180;
  1536. pSProperty->ArrPropertyPrev.SetAt(i,SPropertyUnitPrev);
  1537. SUNDPropertyUnit& SPropertyUnitCur =  pSProperty->ArrPropertyCur.GetAt(i);
  1538. SPropertyUnitCur.flRCX=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().x/1000.0;
  1539. SPropertyUnitCur.flRCY=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().y/1000.0;
  1540. SPropertyUnitCur.flAngle=-dlg.m_nAngle*PI/180;
  1541. pSProperty->ArrPropertyCur.SetAt(i,SPropertyUnitCur);
  1542. }
  1543. CUND_Base* pUndo = new CUND_Property(pSProperty);
  1544. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1545. }else{
  1546. delete pSProperty;
  1547. }
  1548. }
  1549. void CGraphSoftView::OnGraphDelete() 
  1550. {
  1551. // TODO: Add your command handler code here
  1552. m_bDrawFlag=FALSE;
  1553. m_graph_op=_graph_delete;
  1554. m_bGraphOp=TRUE;
  1555. SUNDDelete *pStructDel=new SUNDDelete();
  1556. GetDocument()->GetSelGraphArray(pStructDel->ArrShape);
  1557. CUND_Base* pUndo = new CUND_Delete(pStructDel);
  1558. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1559. CClientDC dc(this);
  1560. OnPrepareDC(&dc);
  1561. CRect rect=GetSelectGraphBoundaryRect();
  1562. POSITION pos,posPrev;
  1563. pos=GetDocument()->m_shapeList.GetHeadPosition();
  1564. while (pos!=NULL) {
  1565. posPrev=pos;
  1566. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  1567. if(pShape->IsSelected()){
  1568. GetDocument()->m_shapeList.RemoveAt(posPrev);
  1569. pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  1570. }
  1571. }
  1572. rect.left/=1000;
  1573. rect.top/=1000;
  1574. rect.right/=1000;
  1575. rect.bottom/=1000;
  1576. Redraw(&dc,&rect,FALSE);
  1577. }
  1578. void CGraphSoftView::OnGraphCopy() 
  1579. {
  1580. // TODO: Add your command handler code here
  1581. m_bDrawFlag=FALSE;
  1582. m_graph_op=_graph_copy;
  1583. m_bGraphOp=TRUE;
  1584. CGraphSoftDoc * pDoc=(CGraphSoftDoc *)GetDocument();
  1585. CClientDC dc(this);
  1586. OnPrepareDC(&dc);
  1587. //CRect rect=GetSelectGraphBoundaryRect();
  1588. POSITION pos;
  1589. pos=pDoc->m_shapeList.GetHeadPosition();
  1590. int nshapeCount=pDoc->m_shapeList.GetCount();
  1591. while ((nshapeCount--)!=0) {
  1592. CShape* pShape=pDoc->m_shapeList.GetNext(pos);
  1593. if(pShape->IsSelected()){
  1594. CShape* pShapeNew=pShape->GetCopy();
  1595. pDoc->m_shapeList.AddTail(pShapeNew);
  1596. pShape->SetSelectFlag(FALSE);
  1597. }
  1598. }
  1599. }
  1600. void CGraphSoftView::OnGraphEdit() 
  1601. {
  1602. // TODO: Add your command handler code here
  1603. m_bDrawFlag=FALSE;
  1604. m_graph_op=_graph_edit;
  1605. m_bGraphOp=TRUE;
  1606.     CShape* pShape=NULL;
  1607. POSITION pos=GetDocument()->m_shapeList.GetHeadPosition();
  1608. while (pos!=NULL) {
  1609. pShape=GetDocument()->m_shapeList.GetNext(pos);
  1610. if(pShape->IsSelected()){
  1611. break;
  1612. }
  1613. }
  1614. if(pShape!=NULL){
  1615. pShape->GetPtData(m_ArrDataPrevX,m_ArrDataPrevY);
  1616. }
  1617. }
  1618. void CGraphSoftView::OnGraphPointshide() 
  1619. {
  1620. // TODO: Add your command handler code here
  1621. CClientDC dc(this);
  1622. OnPrepareDC(&dc);
  1623. GetDocument()->SetGraphDrawPtFlag(0,&dc);
  1624. SUNDShowPoints *pStructShowPts=new SUNDShowPoints();
  1625. GetDocument()->GetSelGraphIDArray(pStructShowPts->ArrId);
  1626. pStructShowPts->nShowFlag=0;
  1627. CUND_Base* pUndo = new CUND_ShowPoints(pStructShowPts);
  1628. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1629. // m_bDrawFlag=FALSE;
  1630. // m_bGraphOp=TRUE;
  1631. // m_graph_op= _graph_pointsHide;
  1632. }
  1633. void CGraphSoftView::OnGraphPointsshow() 
  1634. {
  1635. // TODO: Add your command handler code here
  1636. CClientDC dc(this);
  1637. OnPrepareDC(&dc);
  1638. GetDocument()->SetGraphDrawPtFlag(1,&dc);
  1639. SUNDShowPoints *pStructShowPts=new SUNDShowPoints();
  1640. GetDocument()->GetSelGraphIDArray(pStructShowPts->ArrId);
  1641. pStructShowPts->nShowFlag=1;
  1642. CUND_Base* pUndo = new CUND_ShowPoints(pStructShowPts);
  1643. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1644. // m_bDrawFlag=FALSE;
  1645. // m_bGraphOp=TRUE;
  1646. // m_graph_op= _graph_pointsShow;
  1647. }
  1648. void CGraphSoftView::OnGraphLefttoright() 
  1649. {
  1650. // TODO: Add your command handler code here
  1651. CClientDC dc(this);
  1652. OnPrepareDC(&dc);
  1653. SUNDLeftToRight *pStructLfToRt=new SUNDLeftToRight();
  1654. GetDocument()->GetSelGraphIDArray(pStructLfToRt->ArrId);
  1655. pStructLfToRt->rtOut=GetDocument()->GetSelectGraphBoundaryRect();
  1656. CUND_Base* pUndo = new CUND_LeftToRight(pStructLfToRt);
  1657. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1658. GetDocument()->GraphLeftToRight(&dc);
  1659. // m_bDrawFlag=FALSE;
  1660. // m_bGraphOp=TRUE;
  1661. // m_graph_op= _graph_leftToRight;
  1662. }
  1663. void CGraphSoftView::OnGraphToptobottom() 
  1664. {
  1665. // TODO: Add your command handler code here
  1666. CClientDC dc(this);
  1667. OnPrepareDC(&dc);
  1668. SUNDLeftToRight *pStructTpToBm=new SUNDLeftToRight();
  1669. GetDocument()->GetSelGraphIDArray(pStructTpToBm->ArrId);
  1670. pStructTpToBm->rtOut=GetDocument()->GetSelectGraphBoundaryRect();
  1671. CUND_Base* pUndo = new CUND_TopToBtm(pStructTpToBm);
  1672. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1673. GetDocument()->GraphTopToBottom(&dc);
  1674. // m_bDrawFlag=FALSE;
  1675. // m_bGraphOp=TRUE;
  1676. // m_graph_op= _graph_topTobottom;
  1677. }
  1678. /////////////////////////////////////////////////////////
  1679. void CGraphSoftView::OnDestroy() 
  1680. {
  1681. // TODO: Add your message handler code here
  1682. CScrollView::OnDestroy();
  1683. }
  1684. BOOL CGraphSoftView::DestroyWindow() 
  1685. {
  1686. // TODO: Add your specialized code here and/or call the base class
  1687. return CScrollView::DestroyWindow();
  1688. }
  1689. //////////////////////////////////////////////////////////
  1690. void CGraphSoftView::OnSelectAll() 
  1691. {
  1692. // TODO: Add your command handler code here
  1693. POSITION pos;
  1694. CClientDC dc(this);
  1695. OnPrepareDC(&dc);
  1696. pos=GetDocument()->m_shapeList.GetHeadPosition();
  1697. while (pos!=NULL) {
  1698. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  1699. pShape->SetSelectFlag(TRUE);
  1700. pShape->DrawCutToRect(&dc,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
  1701. }
  1702. }
  1703. //////////////////////////////////////////////////////
  1704. void CGraphSoftView::OnUpdateSelectAll(CCmdUI* pCmdUI) 
  1705. {
  1706. // TODO: Add your command update UI handler code here
  1707. if(m_graph_op==_graph_noneOp&&GetDocument()->m_nCurrentShapeType==_shape_none
  1708. && GetDocument()->m_shapeList.GetCount()!=0){
  1709. pCmdUI->Enable(TRUE);
  1710. }else{
  1711. pCmdUI->Enable(FALSE);
  1712. }
  1713. }
  1714. /////////////////////////////////////////////////////////////////
  1715. void CGraphSoftView::OnOperationOver() 
  1716. {
  1717. // TODO: Add your command handler code here
  1718. CClientDC dc(this);
  1719. OnPrepareDC(&dc);
  1720. int old_rop = dc.SetROP2(R2_XORPEN);
  1721. if(m_bGraphOp!=FALSE){  
  1722. float flxTemp,flyTemp;
  1723. switch(m_graph_op){
  1724. case _graph_copy:
  1725. {
  1726. dc.SetROP2(old_rop);
  1727. CRect rect=GetSelectGraphBoundaryRect();
  1728. POSITION pos,posPrev;
  1729. pos=GetDocument()->m_shapeList.GetHeadPosition();
  1730. while (pos!=NULL) {
  1731. posPrev=pos;
  1732. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  1733. if(pShape->IsSelected()){
  1734. GetDocument()->m_shapeList.RemoveAt(posPrev);
  1735. pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  1736. delete pShape;
  1737. }
  1738. }
  1739. rect.left/=1000;
  1740. rect.top/=1000;
  1741. rect.right/=1000;
  1742. rect.bottom/=1000;
  1743. Redraw(&dc,&rect,FALSE);
  1744. dc.SetROP2(R2_XORPEN);
  1745. m_bGraphOp=FALSE;
  1746. m_graph_op=_graph_noneOp;
  1747. break;
  1748. }
  1749. case _graph_magnify:
  1750. {
  1751. int old_rop = dc.SetROP2(R2_XORPEN);
  1752. flxTemp=m_ptSelectGraphCenter.x/1000.0;
  1753. flyTemp=m_ptSelectGraphCenter.y/1000.0;
  1754. Lp2Dp(flxTemp,flyTemp);
  1755. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  1756. m_bGraphOp=FALSE;
  1757. m_graph_op=_graph_noneOp;
  1758. CPen pen,*poldPen;
  1759. pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  1760. poldPen=dc.SelectObject(&pen); 
  1761. float flLx,flRx,flTy,flBy;
  1762. flLx=m_rectSelectGraph.left/1000.0;
  1763. flTy=m_rectSelectGraph.top/1000.0;
  1764. flRx=m_rectSelectGraph.right/1000.0;
  1765. flBy=m_rectSelectGraph.bottom/1000.0;
  1766. Lp2Dp(flLx,flTy);
  1767. Lp2Dp(flRx,flBy);
  1768. dc.MoveTo(flLx,flTy);
  1769. dc.LineTo(flLx,flBy);
  1770. dc.LineTo(flRx,flBy);
  1771. dc.LineTo(flRx,flTy);
  1772. dc.LineTo(flLx,flTy);
  1773. dc.SelectObject(poldPen);  
  1774. dc.SetROP2(old_rop);
  1775. break;
  1776. }
  1777. case _graph_rotate:
  1778. {
  1779. flxTemp=m_flRotCenterX;
  1780. flyTemp=m_flRotCenterY;
  1781. Lp2Dp(flxTemp,flyTemp);
  1782. DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
  1783. // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
  1784. // CPen pen,*poldPen;
  1785. // pen.CreatePen(PS_SOLID,1, RGB(255,255,0));  
  1786. // poldPen=pDC->SelectObject(&pen);  
  1787. // pDC->MoveTo(rect.TopLeft());
  1788. // pDC->LineTo(rect.left,rect.bottom);
  1789. // pDC->LineTo(rect.right,rect.bottom);
  1790. // pDC->LineTo(rect.right,rect.top);
  1791. // pDC->LineTo(rect.TopLeft());
  1792. // pDC->SelectObject(poldPen);     
  1793. m_bGraphOp=FALSE;
  1794. m_graph_op=_graph_noneOp;
  1795. break;
  1796. }
  1797. case _graph_edit:
  1798. {
  1799. CShape* pShape=NULL;
  1800. POSITION pos=GetDocument()->m_shapeList.GetHeadPosition();
  1801. while (pos!=NULL) {
  1802. pShape=GetDocument()->m_shapeList.GetNext(pos);
  1803. if(pShape->IsSelected()){
  1804. break;
  1805. }
  1806. }
  1807. if(pShape!=NULL){
  1808. SUNDEdit *pStructEdit=new SUNDEdit();
  1809. pStructEdit->nID=pShape->GetID();
  1810. pStructEdit->ArrDataPrevX.Copy(m_ArrDataPrevX);
  1811. pStructEdit->ArrDataPrevY.Copy(m_ArrDataPrevY);
  1812. pShape->GetPtData(pStructEdit->ArrDataCurX,pStructEdit->ArrDataCurY);
  1813. CUND_Base* pUndo = new CUND_Edit(pStructEdit);
  1814. GetDocument()->m_pCore->AddUndoItem(pUndo);
  1815. }
  1816. }
  1817. default:
  1818. // m_bGraphOp=FALSE;
  1819. // m_graph_op=_graph_noneOp;
  1820. break;
  1821. }
  1822. }
  1823. m_bGraphOp=FALSE;
  1824. m_graph_op=_graph_noneOp;
  1825. dc.SetROP2(old_rop);
  1826. CRect rect(0,0,0,0);
  1827. //SetDrawMenuEnable(TRUE);
  1828. GetDocument()->SelectInRect(&rect,&dc,0,TRUE);
  1829. }
  1830. void CGraphSoftView::OnUpdateGraphDelete(CCmdUI* pCmdUI) 
  1831. {
  1832. // TODO: Add your command update UI handler code here
  1833. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1834. }
  1835. void CGraphSoftView::OnUpdateGraphCopy(CCmdUI* pCmdUI) 
  1836. {
  1837. // TODO: Add your command update UI handler code here
  1838. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1839. }
  1840. void CGraphSoftView::OnUpdateGraphMagnify(CCmdUI* pCmdUI) 
  1841. {
  1842. // TODO: Add your command update UI handler code here
  1843. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1844. }
  1845. void CGraphSoftView::OnUpdateGraphMove(CCmdUI* pCmdUI) 
  1846. {
  1847. // TODO: Add your command update UI handler code here
  1848. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1849. }
  1850. void CGraphSoftView::OnUpdateGraphPropertiy(CCmdUI* pCmdUI) 
  1851. {
  1852. // TODO: Add your command update UI handler code here
  1853. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1854. }
  1855. void CGraphSoftView::OnUpdateGraphRotate(CCmdUI* pCmdUI) 
  1856. {
  1857. // TODO: Add your command update UI handler code here
  1858. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1859. }
  1860. void CGraphSoftView::OnUpdateGraphToptobottom(CCmdUI* pCmdUI) 
  1861. {
  1862. // TODO: Add your command update UI handler code here
  1863. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1864. }
  1865. void CGraphSoftView::OnUpdateGraphEdit(CCmdUI* pCmdUI) 
  1866. {
  1867. // TODO: Add your command update UI handler code here
  1868. pCmdUI->Enable(GetDocument()->GetSelectNum()==1);
  1869. }
  1870. void CGraphSoftView::OnUpdateGraphLefttoright(CCmdUI* pCmdUI) 
  1871. {
  1872. // TODO: Add your command update UI handler code here
  1873. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1874. }
  1875. void CGraphSoftView::OnUpdateGraphPointshide(CCmdUI* pCmdUI) 
  1876. {
  1877. // TODO: Add your command update UI handler code here
  1878. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1879. }
  1880. void CGraphSoftView::OnUpdateGraphPointsshow(CCmdUI* pCmdUI) 
  1881. {
  1882. // TODO: Add your command update UI handler code here
  1883. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1884. }
  1885. void CGraphSoftView::OnUpdateGraphRotateLeft(CCmdUI* pCmdUI) 
  1886. {
  1887. // TODO: Add your command update UI handler code here
  1888. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1889. }
  1890. void CGraphSoftView::OnUpdateGraphRotateRight(CCmdUI* pCmdUI) 
  1891. {
  1892. // TODO: Add your command update UI handler code here
  1893. pCmdUI->Enable(GetDocument()->HasGraphSelected());
  1894. }
  1895. void CGraphSoftView::OnUpdateOperationOver(CCmdUI* pCmdUI) 
  1896. {
  1897. // TODO: Add your command update UI handler code here
  1898. pCmdUI->Enable(m_graph_op!=_graph_noneOp);
  1899. }
  1900. void CGraphSoftView::OnUpdateSelectPenwidth(CCmdUI* pCmdUI) 
  1901. {
  1902. // TODO: Add your command update UI handler code here
  1903. }
  1904. /////////////////////////////////////////////////////////
  1905. BOOL CGraphSoftView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  1906. {
  1907. // TODO: Add your message handler code here and/or call default
  1908. if(m_graph_op==_graph_noneOp&&GetDocument()->m_nCurrentShapeType==_shape_none) {
  1909. if(GetDocument()->HasGraphSelected()){
  1910. SetCursor(AfxGetApp()->LoadCursor(IDC_SELECT_ANY));
  1911. }else{
  1912.             SetCursor(AfxGetApp()->LoadCursor(IDC_SELECT_NONE));
  1913. }
  1914. return true ;
  1915. }
  1916. switch(GetDocument()->m_nCurrentShapeType){
  1917. case _shape_Line:
  1918. //SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_LINE));
  1919. //SetCursor(LoadCursorFromFile("dinosaur.ani"));
  1920. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_LINE));
  1921. return true;
  1922. case _shape_Parallelogram:
  1923. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_PARAGLLELOGRAM));
  1924. return true;
  1925. case _shape_Rectangle:
  1926. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_RECTANGLE));
  1927. return true;
  1928. case _shape_RoundRect:
  1929. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_ROUNDRECT));        
  1930. return true;
  1931. case _shape_Circle:
  1932. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_CIRCLE));
  1933. return true;
  1934. case _shape_Ellipse:
  1935. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_ELLIPSE));
  1936. return true;
  1937. case _shape_Polygon:
  1938. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_POLYGON));
  1939. return true;
  1940. case _shape_ModelCurve3Param:
  1941. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_MODELCURVE3PARAM));
  1942. return true;
  1943. case _shape_ModelCurve2AvB:
  1944.   SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_MODELCURVE2AVB));
  1945. return true;
  1946. case _shape_BezierCurve:
  1947. SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_BEZIERCURVE));
  1948. return true;
  1949. default:
  1950. break; 
  1951. }
  1952. switch(m_graph_op){
  1953. case _graph_rotate:
  1954. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_ROTATE));
  1955. return true;
  1956. case _graph_move:
  1957. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_MOVE));
  1958. return true;
  1959. case _graph_magnify:
  1960. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_MAGNIFY));
  1961. return true;
  1962. case _graph_copy:
  1963. SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_COPY));
  1964. return true;
  1965. case _graph_edit:
  1966.         //SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_POINTSEL));
  1967. //return true;
  1968. default:
  1969. break;
  1970. }
  1971. return false;
  1972. //return CScrollView::OnSetCursor(pWnd, nHitTest, message);
  1973. }
  1974. void CGraphSoftView::OnGraphRotatecenterSet() 
  1975. {
  1976. // TODO: Add your command handler code here
  1977. m_bSelectRotateCenter=!m_bSelectRotateCenter;
  1978. if(!m_bSelectRotateCenter){
  1979. m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
  1980. m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
  1981. }
  1982. }
  1983. void CGraphSoftView::OnUpdateGraphRotatecenterSet(CCmdUI* pCmdUI) 
  1984. {
  1985. // TODO: Add your command update UI handler code here
  1986. pCmdUI->SetCheck(m_bSelectRotateCenter?1:0);
  1987. }
  1988. void CGraphSoftView::OnGraphRotateLeft() 
  1989. {
  1990. // TODO: Add your command handler code here
  1991. m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
  1992.     m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
  1993. m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
  1994. POSITION pos;
  1995. CClientDC dc(this);
  1996. OnPrepareDC(&dc);
  1997. //int old_rop = dc.SetROP2(R2_XORPEN);
  1998. pos=GetDocument()->m_shapeList.GetHeadPosition();
  1999. while (pos!=NULL) {
  2000. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  2001. if(pShape->IsSelected()){
  2002. pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  2003. pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,-PI/2);
  2004. pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  2005. }
  2006. }
  2007. CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
  2008. rect.left/=1000;
  2009. rect.top/=1000;
  2010. rect.right/=1000;
  2011. rect.bottom/=1000;
  2012. Redraw(&dc,&rect);
  2013. GetDocument()->RefreshSelectGraph();
  2014. rect=GetDocument()->GetSelectGraphBoundaryRect();
  2015. rect.left/=1000;
  2016. rect.top/=1000;
  2017. rect.right/=1000;
  2018. rect.bottom/=1000;
  2019. Redraw(&dc,&rect);
  2020. //dc.SetROP2(old_rop);
  2021. }
  2022. void CGraphSoftView::OnGraphRotateRight() 
  2023. {
  2024. // TODO: Add your command handler code here
  2025. m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
  2026.     m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
  2027. m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
  2028. POSITION pos;
  2029. CClientDC dc(this);
  2030. OnPrepareDC(&dc);
  2031. pos=GetDocument()->m_shapeList.GetHeadPosition();
  2032. while (pos!=NULL) {
  2033. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  2034. if(pShape->IsSelected()){
  2035. pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  2036. pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,PI/2);
  2037. pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  2038. }
  2039. }
  2040. CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
  2041. rect.left/=1000;
  2042. rect.top/=1000;
  2043. rect.right/=1000;
  2044. rect.bottom/=1000;
  2045. Redraw(&dc,&rect);
  2046.     GetDocument()->RefreshSelectGraph();
  2047. rect=GetDocument()->GetSelectGraphBoundaryRect();
  2048. rect.left/=1000;
  2049. rect.top/=1000;
  2050. rect.right/=1000;
  2051. rect.bottom/=1000;
  2052. Redraw(&dc,&rect);
  2053. }
  2054. void CGraphSoftView::OnInputConfirm() 
  2055. {
  2056. // TODO: Add your command handler code here
  2057. if(m_pCurrentShape!=NULL){
  2058. CClientDC dc(this);
  2059. OnPrepareDC(&dc);
  2060. m_flArrayX.RemoveAll();
  2061. m_flArrayY.RemoveAll();
  2062. switch(GetDocument()->m_nCurrentShapeType) {
  2063. case _shape_Polygon:
  2064. case _shape_ModelCurve3Param:
  2065. case _shape_ModelCurve2AvB:
  2066. case _shape_BezierCurve:
  2067. {
  2068. int old_rop = dc.SetROP2(R2_XORPEN);
  2069. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  2070. dc.SetROP2(old_rop);
  2071. m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  2072. break;
  2073. }
  2074. default:
  2075. break;
  2076. }//switch{case:}
  2077.     }
  2078. m_pCurrentShape=NULL;
  2079. m_bDrawFlag=FALSE;
  2080. ClipCursor(NULL);
  2081. return;
  2082. }
  2083. void CGraphSoftView::OnShapeOver() 
  2084. {
  2085. // TODO: Add your command handler code here
  2086. CClientDC dc(this);
  2087. OnPrepareDC(&dc);
  2088. int old_rop = dc.SetROP2(R2_XORPEN);
  2089. CRect rect;
  2090. if(m_flArrayX.GetSize()>0){
  2091. if(GetDocument()->m_nCurrentShapeType==_shape_Parallelogram){
  2092. if(m_flArrayX.GetSize()<3){
  2093. int old_rop = dc.SetROP2(R2_XORPEN);
  2094. //rect=GetRectFromPoint(m_ptStart,m_ptPrev);
  2095. float x1=m_flStartX;
  2096. float y1=m_flStartY;
  2097. float x2=m_flPrevX;
  2098. float y2=m_flPrevY;
  2099. Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
  2100. Lp2Dp(x2,y2);
  2101. DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);  
  2102. dc.SetROP2(old_rop);
  2103. }
  2104. }
  2105. m_flArrayX.RemoveAll();
  2106. m_flArrayY.RemoveAll();
  2107. if(m_pCurrentShape!=NULL){
  2108. rect=m_pCurrentShape->GetBoundaryRect();
  2109. m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
  2110. GetDocument()->m_shapeList.RemoveTail();
  2111. // delete m_pCurrentShape;//内存泄漏
  2112. m_pCurrentShape=NULL;
  2113. // Redraw(&dc,&rect,FALSE);
  2114.      GetDocument()->m_pCore->DelLastUndoItem();//删除撤消项,这里将删除为新图形分配的空间
  2115. }
  2116. }
  2117. GetDocument()->m_nCurrentShapeType=_shape_none;
  2118. m_bDrawFlag=FALSE;
  2119. ClipCursor(NULL);
  2120. dc.SetROP2(old_rop);
  2121. return;
  2122. }
  2123. void CGraphSoftView::OnUpdateInputConfirm(CCmdUI* pCmdUI) 
  2124. {
  2125. // TODO: Add your command update UI handler code here
  2126. }
  2127. void CGraphSoftView::OnSelectPenwidth()
  2128. {
  2129. // TODO: Add your command handler code here
  2130. }
  2131. void CGraphSoftView::OnSelectFillColor() 
  2132. {
  2133. // TODO: Add your command handler code here
  2134. }
  2135. BOOL CGraphSoftView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  2136. {
  2137. // TODO: Add your specialized code here and/or call the base class
  2138. BOOL rlt= CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  2139. return rlt;
  2140. }
  2141. void CGraphSoftView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType) 
  2142. {
  2143. // TODO: Add your specialized code here and/or call the base class
  2144. CScrollView::CalcWindowRect(lpClientRect, nAdjustType);
  2145. }
  2146. void CGraphSoftView::DrawCut()
  2147. {
  2148. CClientDC dc(this);
  2149. OnPrepareDC(&dc);
  2150. OnEraseBkgnd(&dc) ;
  2151. CGraphSoftDoc* pDoc=GetDocument();
  2152. POSITION pos;
  2153. pos=pDoc->m_shapeList.GetHeadPosition();
  2154. while (pos!=NULL) {
  2155. CShape* pShape=pDoc->m_shapeList.GetNext(pos);
  2156. if(pShape->IsSelected()){
  2157. pShape->DrawCutToRect(&dc,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
  2158. }else{
  2159. pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  2160. }
  2161. }
  2162. }
  2163. BOOL CGraphSoftView::OnEraseBkgnd(CDC* pDC) 
  2164. {
  2165. // TODO: Add your message handler code here and/or call default
  2166. CBrush* pBrush = new CBrush ;
  2167. // pBrush->CreateSolidBrush(RGB(0,0,0));
  2168. CRect rect ;
  2169. CBrush *pOldBrush = (CBrush*)pDC->SelectObject(pBrush) ;
  2170. pDC->GetClipBox(&rect) ;
  2171. pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY) ;
  2172. pDC->SelectObject(pOldBrush) ;
  2173. // pDC->SetBkColor(COLORREF(RGB(128,128,128))) ;
  2174. // GetClientRect(rect) ;
  2175. delete pBrush;
  2176. return TRUE;
  2177. }
  2178. /////////////////////////////////////////////////////////////////////
  2179. void CGraphSoftView::Lp2Dp(CPoint* pPt)
  2180. {
  2181. pPt->x=((float)pPt->x)*m_rectMaxWindow.Width()/m_rectTarget.Width()+0.5;
  2182. pPt->y=((float)pPt->y)*m_rectMaxWindow.Height()/m_rectTarget.Height()+0.5;
  2183. }
  2184. void CGraphSoftView::Lp2Dp(CRect* pRect)
  2185. {
  2186. float flRate=((float)m_rectMaxWindow.Width())/m_rectTarget.Width();
  2187. pRect->left=((float)pRect->left-m_rectTarget.left)*flRate+0.5;
  2188. pRect->right=((float)pRect->right-m_rectTarget.left)*flRate+0.5;
  2189. pRect->top=((float)pRect->top-m_rectTarget.top)*flRate+0.5;
  2190.     pRect->bottom=((float)pRect->bottom-m_rectTarget.top)*flRate+0.5;
  2191. }
  2192. void CGraphSoftView::Dp2Lp(CPoint* pPt)
  2193. {
  2194. pPt->x=m_rectTarget.left+((float)pPt->x)*m_rectTarget.Width()/(float)m_rectMaxWindow.Width()+0.5;
  2195. pPt->y=m_rectTarget.top+((float)pPt->y)*m_rectTarget.Width()/(float)m_rectMaxWindow.Width()+0.5;
  2196. }
  2197. void CGraphSoftView::Dp2Lp(CRect* pRect)
  2198. {
  2199. pRect->left=m_rectTarget.left+((float)pRect->left)*m_rectTarget.Width()/m_rectMaxWindow.Width()+0.5;
  2200. pRect->right=m_rectTarget.left+((float)pRect->right)*m_rectTarget.Width()/m_rectMaxWindow.Width()+0.5;
  2201. pRect->top=m_rectTarget.top+((float)pRect->top)*m_rectTarget.Height()/m_rectMaxWindow.Height()+0.5;
  2202.     pRect->bottom=m_rectTarget.top+((float)pRect->bottom)*m_rectTarget.Height()/m_rectMaxWindow.Height()+0.5;
  2203. }
  2204. void CGraphSoftView::Lp2Dp(float& flX,float& flY)
  2205. {
  2206. // CSize sz;
  2207. // this->GetScrollBarSizes(sz);
  2208. // float flRate=((float)m_rectMaxWindow.Width())/sz.cx;
  2209. flX=flX*m_flRate;
  2210. flY=flY*m_flRate;
  2211. // float flRate=((float)m_rectMaxWindow.Width()/m_rectTarget.Width());
  2212. // flX=(flX-m_rectTarget.left)*flRate+0.5;
  2213. // flY=(flY-m_rectTarget.top)*flRate+0.5;
  2214. }
  2215. void CGraphSoftView::Dp2Lp(float& flX,float& flY)
  2216. {
  2217. // CSize sz;
  2218. // this->GetScrollBarSizes(sz);
  2219. // float flRate=((float)sz.cx)/m_rectMaxWindow.Width();
  2220. flX=flX/m_flRate;
  2221. flY=flY/m_flRate;
  2222. // flX=m_rectTarget.left+flX*m_rectTarget.Width()/(float)m_rectMaxWindow.Width();
  2223. // flY=m_rectTarget.top+flY*m_rectTarget.Width()/(float)m_rectMaxWindow.Width();
  2224. }
  2225. //////////////////////////////////////////////////////////////////////////////////
  2226. void CGraphSoftView::OnSelGraphPoint(WPARAM wParam,LPARAM lParam)
  2227. {
  2228. CClientDC dc(this);
  2229. OnPrepareDC(&dc);
  2230. int nFlag=(int)wParam;
  2231. GetDocument()->SetGraphDrawPtFlag(nFlag,&dc);
  2232. }
  2233. void CGraphSoftView::OnSelGraphRotate(WPARAM wParam,LPARAM lParam)
  2234. {
  2235. float angle=(int)wParam;
  2236. m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
  2237.     m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
  2238. m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
  2239. POSITION pos;
  2240. CClientDC dc(this);
  2241. OnPrepareDC(&dc);
  2242. //int old_rop = dc.SetROP2(R2_XORPEN);
  2243. pos=GetDocument()->m_shapeList.GetHeadPosition();
  2244. while (pos!=NULL) {
  2245. CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
  2246. if(pShape->IsSelected()){
  2247. pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
  2248. pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,-angle*PI/180);
  2249. pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
  2250. }
  2251. }
  2252. CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
  2253. rect.left/=1000;
  2254. rect.top/=1000;
  2255. rect.right/=1000;
  2256. rect.bottom/=1000;
  2257. Redraw(&dc,&rect);
  2258. GetDocument()->RefreshSelectGraph();
  2259. rect=GetDocument()->GetSelectGraphBoundaryRect();
  2260. rect.left/=1000;
  2261. rect.top/=1000;
  2262. rect.right/=1000;
  2263. rect.bottom/=1000;
  2264. Redraw(&dc,&rect);
  2265. }
  2266. void CGraphSoftView::OnSelGraphColor(WPARAM wParam,LPARAM lParam)
  2267. {
  2268. CClientDC dc(this);
  2269. OnPrepareDC(&dc);
  2270. COLORREF color=(COLORREF)wParam;
  2271. GetDocument()->SetSelGraphColor(color,&dc);
  2272. }
  2273. void CGraphSoftView::OnSelGraphFillClr(WPARAM wParam,LPARAM lParam)
  2274. {
  2275. CClientDC dc(this);
  2276. OnPrepareDC(&dc);
  2277. COLORREF color=(COLORREF)wParam;
  2278. GetDocument()->SetSelGraphFillClr(color,&dc);
  2279. }
  2280. void CGraphSoftView::OnSelGraphFillSty(WPARAM wParam,LPARAM lParam)
  2281. {
  2282. CClientDC dc(this);
  2283. OnPrepareDC(&dc);
  2284. int nStyle=(int)wParam;
  2285. GetDocument()->SetSelGraphFillSty((SHAPE_FILLSTYLE)nStyle,&dc);
  2286. }
  2287. void CGraphSoftView::OnSelGraphPenWidth(WPARAM wParam,LPARAM lParam)
  2288. {
  2289. CClientDC dc(this);
  2290. OnPrepareDC(&dc);
  2291. int nWidth=(int)wParam;
  2292. GetDocument()->SetSelGraphPenWidth(nWidth,&dc);
  2293. }
  2294. //////////////////////////////////////////////////////////////////////////////////
  2295. //End of File
  2296. void CGraphSoftView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  2297. {
  2298. // TODO: Add your specialized code here and/or call the base class
  2299. CRect rect=pInfo->m_rectDraw;//转窗口大小
  2300. rect.DeflateRect(rect.Width()/15,rect.Height()/16);
  2301. //画图
  2302. CGraphSoftDoc* pDoc = GetDocument();
  2303. ASSERT_VALID(pDoc);
  2304. POSITION pos;
  2305. pos=pDoc->m_shapeList.GetHeadPosition();
  2306. while (pos!=NULL) {
  2307. CShape* pShape=pDoc->m_shapeList.GetNext(pos);
  2308. if(pShape->IsSelected()){
  2309. //pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
  2310. pShape->DrawCutToRect(pDC,m_rectTarget,rect);
  2311. }else{
  2312. pShape->DrawCutToRect(pDC,m_rectTarget,rect);
  2313. }
  2314. }
  2315. //清除四边空间
  2316. CBrush newBrush;
  2317. newBrush.CreateSolidBrush(RGB(255,255,255));
  2318. CBrush *pOldBrush = (CBrush*)pDC->SelectObject(&newBrush) ;
  2319. this->GetClientRect(&rect) ;
  2320. rect.InflateRect(3,2);
  2321. pDC->PatBlt(0,0,pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height(),PATCOPY) ;
  2322. pDC->PatBlt(0,0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0,PATCOPY) ;
  2323. pDC->PatBlt(0,15*pInfo->m_rectDraw.Height()/16.0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0,PATCOPY) ;
  2324. pDC->PatBlt(14*pInfo->m_rectDraw.Width()/15.0,0,pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height(),PATCOPY) ;
  2325. //画页眉底线
  2326. CPen pen,*pOldPen;
  2327. pen.CreatePen(PS_SOLID,pInfo->m_rectDraw.Width()/200+1,RGB(0,0,0));
  2328. pOldPen=pDC->SelectObject(&pen);
  2329. pDC->MoveTo(pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height()/20.0);
  2330. pDC->LineTo(14.0*pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height()/20);
  2331. pDC->SelectObject(pOldPen);
  2332. //写页眉
  2333. CRect rectTop(0,0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0);
  2334. CFont font;
  2335. LOGFONT lf;
  2336. memset(&lf, 0, sizeof(LOGFONT));       // zero out structure
  2337. lf.lfHeight = pInfo->m_rectDraw.Height()/40;         
  2338. lf.lfWidth = pInfo->m_rectDraw.Width()/40;
  2339. // request a 12-pixel-height font
  2340. strcpy(lf.lfFaceName, "Arial");        // request a face name "Arial"
  2341. VERIFY(font.CreateFontIndirect(&lf));  // create the font
  2342. // Do something with the font just created...
  2343. CFont* def_font = pDC->SelectObject(&font);
  2344. pDC->DrawText("Made by GraphSoft",&rectTop,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  2345. pDC->SelectObject(pOldBrush) ;
  2346. pDC->SelectObject(def_font);
  2347. // Done with the font. Delete the font object.
  2348. font.DeleteObject();
  2349. newBrush.DeleteObject();
  2350. ScrollToPosition(m_rectMaxWindow.TopLeft());
  2351. }
  2352. void CGraphSoftView::OnInitialUpdate() 
  2353. {
  2354. SetScrollSizes(MM_TEXT,CSize(0,0));
  2355. // TODO: Add your specialized code here and/or call the base class
  2356. }
  2357. void CGraphSoftView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  2358. {
  2359. // TODO: Add your specialized code here and/or call the base class
  2360. CScrollView::OnPrepareDC(pDC, pInfo);
  2361. }
  2362. void CGraphSoftView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  2363. {
  2364. // TODO: Add your message handler code here and/or call default
  2365. float left = this->GetScrollPos(SB_HORZ);
  2366. CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
  2367. float flOffsetRate = ((float)left-m_rectMaxWindow.left)/(m_flRate*m_rectMaxWindow.Width());
  2368. float flViewMaxOffset = left-m_rectMaxWindow.left;
  2369. float flViewTargetOffset = flViewMaxOffset*((float)m_rectTarget.Width())/m_rectMaxWindow.Width();
  2370. float flFullViewOffset = flOffsetRate*pMainFrm->m_wndFullView.m_pBtn->m_MaxRect.Width();
  2371. pMainFrm->m_wndFullView.m_pBtn->m_targetrect.OffsetRect(flFullViewOffset,0);
  2372. m_rectMaxWindow.OffsetRect(flViewMaxOffset,0);
  2373.     m_rectTarget.OffsetRect(flViewTargetOffset,0);
  2374. pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
  2375. // Invalidate(TRUE);
  2376. CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
  2377. }
  2378. void CGraphSoftView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  2379. {
  2380. // TODO: Add your message handler code here and/or call default
  2381. float limit = this->GetScrollLimit(SB_VERT);
  2382. float top = this->GetScrollPos(SB_VERT);
  2383. CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
  2384. float flOffsetRate = ((float)top-m_rectMaxWindow.top)/(m_flRate*m_rectMaxWindow.Height());
  2385. float flViewMaxOffset = top-m_rectMaxWindow.top;
  2386. float flViewTargetOffset = flViewMaxOffset*((float)m_rectTarget.Width())/m_rectMaxWindow.Width();
  2387. float flFullViewOffset = flOffsetRate*pMainFrm->m_wndFullView.m_pBtn->m_MaxRect.Height();
  2388. pMainFrm->m_wndFullView.m_pBtn->m_targetrect.OffsetRect(0,flFullViewOffset);
  2389. m_rectMaxWindow.OffsetRect(0,flViewMaxOffset);
  2390.     m_rectTarget.OffsetRect(0,flViewTargetOffset);
  2391. pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
  2392. // Invalidate(TRUE);
  2393. CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
  2394. }
  2395. void CGraphSoftView::OnHelpfile() 
  2396. {
  2397. // TODO: Add your command handler code here
  2398. ShellExecute(NULL, "open", "GSHelpFile.chm", NULL, NULL, SW_SHOWNORMAL);
  2399. }