DrawView.cpp
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:24k
源码类别:

GIS编程

开发平台:

Visual C++

  1. // DrawView.cpp : implementation of the CDrawView class
  2. //
  3. #include "stdafx.h"
  4. #include "Draw.h"
  5. #include "DrawDoc.h"
  6. #include "DrawView.h"
  7. #include "math.h"
  8. #define pi 3.1415926
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDrawView
  16. //CGraphPara *p_GraphPara;
  17. IMPLEMENT_DYNCREATE(CDrawView, CView)
  18. BEGIN_MESSAGE_MAP(CDrawView, CView)
  19. //{{AFX_MSG_MAP(CDrawView)
  20. ON_WM_SIZE()
  21. ON_WM_MOUSEMOVE()
  22. ON_WM_LBUTTONDOWN()
  23. ON_WM_RBUTTONDOWN()
  24. ON_COMMAND(ID_DRAW_ARC,OnDrawArc)
  25. ON_COMMAND(ID_DRAW_CIRCLE,OnDrawCircle)
  26. ON_COMMAND(ID_DRAW_CIRCLE1,OnDrawCircle1)
  27.     ON_COMMAND(ID_DRAW_LINE,OnDrawLine)
  28. ON_COMMAND(ID_DRAW_PLINE,OnDrawPline)
  29. ON_COMMAND(ID_DRAW_RGN,OnDrawPlineRgn)
  30. ON_COMMAND(ID_DRAW_TEXT,OnDrawText)
  31. ON_COMMAND(ID_DRAW_NET,OnDrawNet)
  32. ON_COMMAND(ID_DRAW_NET_LINK,OnDrawNetLink)
  33. ON_COMMAND(ID_GRAPH_REDRAW, OnGraphRedraw)
  34. ON_COMMAND(ID_GRAPH_ZOOM, OnGraphZoom)
  35. ON_COMMAND(ID_GRAPH_PAN, OnGraphPan)
  36. ON_COMMAND(ID_GRAPH_UP, OnGraphUp)
  37. ON_COMMAND(ID_GRAPH_FIRST, OnGraphFirst)
  38. ON_COMMAND(ID_GRAPH_ALL, OnGraphAll)
  39. ON_COMMAND(ID_SELECT_MOUSE, OnSelectMouse)
  40. ON_COMMAND(ID_SELECT_CLEAR, OnSelectClear)
  41. ON_COMMAND(ID_EDIT_MOVE, OnEditMove)
  42. ON_COMMAND(ID_SELECT_DELETE, OnSelectDelete)
  43. //}}AFX_MSG_MAP
  44. // Standard printing commands
  45. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  46. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  47. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  48. ON_COMMAND(ID_TEXT_MESSAGE,DrawText)
  49. ON_COMMAND(ID_TEXT_ONOK,DrawTextOnOk)
  50. ON_COMMAND(ID_TEXT_ONCANCEL,DrawTextOnCancel)
  51. END_MESSAGE_MAP()
  52. CDrawView *p_View;
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CDrawView construction/destruction
  55. void DPtoVP(float x,float y,int *X,int *Y);
  56. void VPtoDP(int x,int y,float *X,float *Y);
  57. int DLtoVL(float l);
  58. float VLtoDL(int l);
  59. extern float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
  60. void DPtoVP(float x,float y,int *X,int *Y)
  61. {
  62. p_View->DPtoVP(x,y,X,Y);
  63. }
  64. void VPtoDP(int x,int y,float *X,float *Y)
  65. {
  66. p_View->VPtoDP(x,y,X,Y);
  67. }
  68. int DLtoVL(float l)
  69. {
  70. return p_View->DLtoVL(l);
  71. }
  72. float VLtoDL(int l)
  73. {
  74. return p_View->VLtoDL(l);
  75. }
  76. CDrawView::CDrawView()
  77. {
  78. // TODO: add construction code here
  79. m_xStart=0.0;
  80. m_yStart=0.0;
  81. blc=1.0;
  82. m_pColor=1;//设置笔色
  83. m_bColor=0;//当前底色的序号
  84. m_brColor=1;//设置填充色
  85. m_LineWide=1.0;//设置线宽
  86. m_LineType=0;//设置线型
  87. m_Layer=1;//选择当前图层
  88. PointXyz=new PointStruct[10000];
  89. pTextDlg=NULL;
  90. //以下设置初始字体大小
  91. m_FontHeight=20;
  92. m_FontWide=10;
  93. m_TextAngle=0;
  94. m_FontAngle=0;
  95. m_FontBetween=1;
  96. m_TextString.Empty();
  97. m_Text1=new CText();//创建一个标注文本对象
  98. }
  99. CDrawView::~CDrawView()
  100. {
  101. delete PointXyz;
  102. delete m_Text1;
  103. }
  104. BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
  105. {
  106. // TODO: Modify the Window class or styles here by modifying
  107. //  the CREATESTRUCT cs
  108. return CView::PreCreateWindow(cs);
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CDrawView drawing
  112. void CDrawView::VPtoDP(int x,int y,float *X,float *Y)
  113. {
  114. *X=m_xStart+x*blc;
  115. if(m_MapMode==1)
  116. *Y=m_yStart+blc*(m_hScreen-y);
  117. else
  118. *Y=m_yStart+blc*(y+m_hScreen);
  119. }
  120. void CDrawView::DPtoVP(float x,float y,int *X,int *Y)
  121. {
  122. *X=(int)((x-m_xStart)/blc);
  123. if(m_MapMode==1)
  124. *Y=m_hScreen-(int)((y-m_yStart)/blc);
  125. else
  126. *Y=(int)((y-m_yStart)/blc)-m_hScreen;
  127. }
  128. float CDrawView::VLtoDL(int l)
  129. {
  130. return blc*l;
  131. }
  132. int CDrawView::DLtoVL(float l)
  133. {
  134. return (int)(l/blc);
  135. }
  136. void CDrawView::OnSize(UINT nType,int cx,int cy)
  137. {
  138. m_wScreen=cx;
  139. m_hScreen=cy;
  140. CView::OnSize(nType,cx,cy);
  141. }
  142. void CDrawView::DrawBack(CDC* pDC)
  143. {
  144. CGraphPara m_GraphPara;
  145.     CGraphPara *p_GraphPara;
  146. p_GraphPara=&m_GraphPara;
  147. CBrush brush(p_GraphPara->GetColor(m_bColor));
  148. CBrush* pOldBrush=pDC->SelectObject(&brush);
  149. pDC->PatBlt(0,0,m_wScreen,m_hScreen,PATCOPY);
  150. pDC->SelectObject(pOldBrush);
  151. }
  152. void CDrawView::OnDraw(CDC* pDC)
  153. {
  154. CDrawDoc* pDoc = GetDocument();
  155. ASSERT_VALID(pDoc);
  156. // TODO: add draw code for native data here
  157. xMinScreen=m_xStart;
  158. yMinScreen=m_yStart;
  159. xMaxScreen=xMinScreen+blc*m_wScreen;
  160. yMaxScreen=yMinScreen+blc*m_hScreen;
  161.     DrawBack(pDC);
  162.     int a=m_bColor;
  163. pDoc->Draw(pDC,0,0,m_bColor);
  164. m_MapMode=pDC->SetMapMode(1);
  165. }
  166. /////////////////////////////////////////////////////////////////////////////
  167. // CDrawView printing
  168. BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
  169. {
  170. // default preparation
  171. return DoPreparePrinting(pInfo);
  172. }
  173. void CDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  174. {
  175. // TODO: add extra initialization before printing
  176. }
  177. void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  178. {
  179. // TODO: add cleanup after printing
  180. }
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CDrawView diagnostics
  183. #ifdef _DEBUG
  184. void CDrawView::AssertValid() const
  185. {
  186. CView::AssertValid();
  187. }
  188. void CDrawView::Dump(CDumpContext& dc) const
  189. {
  190. CView::Dump(dc);
  191. }
  192. CDrawDoc* CDrawView::GetDocument() // non-debug version is inline
  193. {
  194. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
  195. return (CDrawDoc*)m_pDocument;
  196. }
  197. #endif //_DEBUG
  198. /////////////////////////////////////////////////////////////////////////////
  199. // CDrawView message handlers
  200. extern CGraphPara *p_GraphPara;
  201. void CDrawView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  202. {
  203. // TODO: Add your specialized code here and/or call the base class
  204. p_View=this;
  205. CDrawDoc* pDoc=(CDrawDoc*)GetDocument();
  206. p_Screen=pDoc->m_Screen;
  207. CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  208. }
  209. void CDrawView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  210. {
  211. // TODO: Add your specialized code here and/or call the base class
  212. CPaintDC dc(this);
  213. OnPrepareDC(&dc);
  214. OnDraw(&dc);
  215. CView::OnPrint(pDC, pInfo);
  216. }
  217. void CDrawView::OnMouseMove(UINT nFlags, CPoint point) 
  218. {
  219. // TODO: Add your message handler code here and/or call default
  220. CDrawDoc* pDoc=GetDocument();
  221. CClientDC ddd(this);
  222. CPen pen(0,0,RGB(0,0,0));
  223. CPen* pOldPen=ddd.SelectObject(&pen);//在绘图对象中选择CPen对象
  224. ddd.SetROP2(R2_NOT);
  225. BOOL pb;
  226. int x1,y1;
  227. CArc m_Arc1;
  228. if(m_DrawCurrent==1&&PushNumb==1)//直线
  229. {
  230. if(mPointOld!=point)
  231. {
  232. ddd.MoveTo(mPointOrign);
  233. ddd.LineTo(mPointOld);
  234. ddd.MoveTo(mPointOrign);
  235. ddd.LineTo(point);
  236. mPointOld=point;
  237. }
  238. }
  239. else if((m_DrawCurrent==2||m_DrawCurrent==3)&&PushNumb>=1)
  240. {
  241. if(mPointOld!=point)
  242. {
  243. ddd.MoveTo(mPointOrign);
  244. ddd.LineTo(mPointOld);
  245. ddd.MoveTo(mPointOrign);
  246. ddd.LineTo(point);
  247. mPointOld=point;
  248. }
  249. }
  250. else if((m_DrawCurrent==4||m_DrawCurrent==5)&&PushNumb>=1)
  251. //如果正在绘制圆或填充圆,并且已经按下圆心点
  252. {
  253. if(mPointOld!=point)
  254. {
  255. if(m_DrawCurrent==4)
  256. {
  257. ddd.SelectStockObject(NULL_BRUSH);
  258. }
  259. r=(int)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
  260. ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
  261. r=(int)sqrt(pow((long)(mPointOrign.x-point.x),2)+pow((float)(mPointOrign.y-point.y),2));
  262. ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
  263. mPointOld=point;
  264. }
  265. //Invalidate();
  266. }
  267. else if(m_DrawCurrent==6)//圆弧
  268. {
  269. if(PushNumb==2&&mPointOld!=point)
  270. {
  271.      if(DrawArcYes)
  272. m_Arc1.Draw(&ddd,1,0,m_bColor);
  273.   pb=jsarc(mPointOrign1,mPointOrign,point,&m_CircleX,&m_CircleY,&m_CircleR,&m_Angle1,&m_Angle2);
  274. if(pb)
  275. {
  276. m_Arc1.Init(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,0,m_CircleX,m_CircleY,m_CircleR,m_Angle1,m_Angle2);
  277. m_Arc1.Draw(&ddd,1,0,m_bColor);
  278. }
  279. DrawArcYes=pb;
  280. mPointOld=point;
  281. }
  282. // Invalidate();
  283. }
  284. else if(m_DrawCurrent==10&&PushNumb==1)
  285. {
  286. if(mPointOld!=point)
  287. {
  288. ddd.MoveTo(mPointOrign);
  289. ddd.LineTo(mPointOld);
  290. ddd.MoveTo(mPointOrign);
  291. ddd.LineTo(point);
  292. mPointOld=point;
  293. }
  294. }
  295. else if((m_DrawCurrent==11||m_DrawCurrent==12)&&PushNumb==1)
  296. {
  297. if(point!=mPointOld)
  298. {
  299. if(m_DrawCurrent==11)//放大
  300. {
  301. ddd.SelectStockObject(NULL_BRUSH); //设置不填充状态
  302. ddd.Rectangle(mPointOrign.x,mPointOrign.y,mPointOld.x,mPointOld.y);
  303. ddd.Rectangle(mPointOrign.x,mPointOrign.y,point.x,point.y);
  304. }
  305. else 
  306. {
  307. ddd.MoveTo(mPointOrign);ddd.LineTo(mPointOld);
  308. ddd.MoveTo(mPointOrign);ddd.LineTo(point);  //画新的橡皮线
  309. }
  310. mPointOld=point;
  311. }
  312. }
  313. else if(m_DrawCurrent==19)
  314. {
  315. if(point!=mPointOld&&PushNumb>0)
  316. {
  317. x1=VLtoDL(point.x-mPointOld.x);
  318. y1=-VLtoDL(point.y-mPointOld.y);
  319. x_Move+=x1;
  320. y_Move+=y1;
  321. for(int i=0;i<pDoc->n_GraphSelect;i++)
  322. pDoc->DrawGraph(&ddd,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,1,1,0);
  323. for( i=0;i<pDoc->n_GraphSelect;i++)
  324. {
  325. CDraw* pDraw=pDoc->GetGraph(pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index);
  326. pDraw->Move(x1,y1);
  327. pDraw->Draw(&ddd,1,1,0);
  328. }
  329. }
  330. mPointOld=point;
  331. }
  332. CView::OnMouseMove(nFlags, point);
  333. }
  334. void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) 
  335. {
  336. // TODO: Add your message handler code here and/or call default
  337. CDrawDoc* pDoc=GetDocument();
  338. CClientDC ht(this);
  339. float r;
  340. float xx1,yy1,xx2,yy2;
  341. int x1,x2,y1,y2,Lb,index,pbh,id_only;
  342. float BackColor;
  343. BOOL m_bFill;
  344. int id;
  345. int m_sNetID;
  346. //画直线
  347. if(m_DrawCurrent==1)
  348. {
  349. if(PushNumb==0)
  350. {
  351. PushNumb++;
  352. mPointOrign=point;
  353. mPointOld=point;
  354. SetCapture();
  355. }
  356. else if(PushNumb==1)
  357. {
  358. VPtoDP(mPointOrign.x,mPointOrign.y,&xx1,&yy1);
  359. VPtoDP(point.x,point.y,&xx2,&yy2);
  360. id_only=pDoc->GetGraphID(1);
  361. int b=m_pColor;
  362. CLine* pLine=pDoc->AddLine(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,xx1,yy1,xx2,yy2);
  363. pLine->Draw(&ht,0,0,m_bColor);
  364. PushNumb=0;
  365. ReleaseCapture();
  366. }
  367. }
  368. //连续直线或者多边形区域
  369. else if(m_DrawCurrent==2||m_DrawCurrent==3)
  370. {
  371. PointXyz[PushNumb].x=m_xStart+blc*point.x;
  372. PointXyz[PushNumb].y=m_yStart+blc*(m_hScreen-point.y);
  373. if(PushNumb==0)
  374. {
  375. SetCapture();
  376. mPointOrign=point;
  377. mPointOld=point;
  378. }
  379. else
  380. {
  381. mPointOrign=mPointOld;
  382. mPointOld=point;
  383. }
  384. PushNumb++;//记录按下鼠标左键的次数
  385. }
  386. else if(m_DrawCurrent==4||m_DrawCurrent==5)//圆或者填充圆
  387. {
  388. if(PushNumb==0)
  389. {
  390. mPointOrign=point;
  391. mPointOld=point;
  392. PushNumb++;
  393.             SetCapture();
  394. }
  395. else
  396. {
  397. r=(float)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
  398. VPtoDP(mPointOrign.x,mPointOrign.y,&xx1,&yy1);
  399. if(m_DrawCurrent==4)
  400. m_bFill=0;
  401. else
  402. m_bFill=1;
  403. id_only=pDoc->GetGraphID(3);
  404. int a=m_pColor;
  405. pDoc->AddCircle(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,xx1,yy1,r,m_bFill)->Draw(&ht,0,0,m_bColor);
  406. PushNumb=0;
  407. ReleaseCapture();
  408. }
  409. }
  410. else if(m_DrawCurrent==6)//圆弧
  411. {
  412. if(PushNumb==0)
  413. {
  414. SetCapture();
  415. DrawArcYes=0;
  416. mPointOrign1=point;
  417. PushNumb++;
  418. }
  419. else if(PushNumb==1)
  420. {
  421. mPointOrign=point;
  422. PushNumb++;
  423. }
  424. else
  425. {
  426. jsarc(mPointOrign1,mPointOrign,point,&m_CircleX,&m_CircleY,&m_CircleR,&m_Angle1,&m_Angle2);
  427. id_only=pDoc->GetGraphID(4);
  428. pDoc->AddArc(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,m_CircleX,m_CircleY,m_CircleR,m_Angle1,m_Angle2)->Draw(&ht,0,0,m_bColor);
  429. PushNumb=0;
  430. ReleaseCapture();
  431.             Invalidate();
  432. }
  433. }
  434. else if(m_DrawCurrent==7)//标注文本的交互绘制
  435. {
  436. VPtoDP(point.x,point.y,&m_TextX,&m_TextY);
  437. if(!pTextDlg)
  438. {
  439. pTextDlg=new TextWriteDlg(this,m_TextString);
  440. ASSERT(pTextDlg);
  441. }
  442. if(!(pTextDlg->IsOpen()))
  443. pTextDlg->Create(IDD_WRITE_TEXT,this);
  444. if(!(pTextDlg->IsVisible()))
  445. pTextDlg->ShowWindow(SW_SHOW);
  446. }
  447. else if(m_DrawCurrent==8)
  448. {
  449. VPtoDP(point.x,point.y,&xx1,&yy1);
  450. id=pDoc->GetGraphID(8);
  451. pDoc->AddNetPoint(xx1,yy1,3,m_Layer,id,m_pColor)->Draw(&ht,0,0,1);
  452. PushNumb=0;
  453. ReleaseCapture();
  454. }
  455. else if(m_DrawCurrent==9)
  456. {
  457. VPtoDP(point.x,point.y,&xx1,&yy1);
  458. int nn1=pDoc->PointSelect(8,xx1,yy1,blc,&Lb,&index,&pbh);
  459. if(nn1>0)
  460. {
  461. if(PushNumb==0)
  462. {
  463. PushNumb++;
  464. m_sNetID=pbh;
  465. mPointOrign=point;
  466. mPointOld=point;
  467. SetCapture();
  468. }
  469. else if(PushNumb==1)
  470. {
  471. ht.MoveTo(mPointOrign);
  472. ht.LineTo(point);
  473. pDoc->AddNetLink(m_sNetID,pbh)->Draw(&ht,0,0,m_bColor);
  474. PushNumb=0;
  475. ReleaseCapture();
  476. }
  477. }
  478. }
  479. else if(m_DrawCurrent==11||m_DrawCurrent==12)
  480. {
  481. if(PushNumb==0)
  482. {
  483. mPointOrign=point;  //原点等于按中点
  484. mPointOld=point;
  485. PushNumb++;
  486. SetCapture();
  487. }
  488. else if(PushNumb==1)
  489. {
  490. if(m_DrawCurrent==11)//图形放大
  491. {
  492. x1=min(mPointOrign.x,point.x);
  493. y1=max(mPointOrign.y,point.y);
  494. x2=max(mPointOrign.x,point.x);
  495. y2=min(mPointOrign.y,point.y);
  496. VPtoDP(x1,y1,&m_xStart,&m_yStart);//得到视图屏幕原点实际坐标
  497. //改变原点的坐标
  498. m_xStart=m_xStart+blc*x1;
  499. m_yStart=m_yStart+blc*(m_hScreen-y1);
  500. //改变比例
  501. float b11=(float)m_wScreen/(float)(x2-x1);
  502. float b12=(float)m_hScreen/(float)(y1-y2);
  503. // float b11=(float)(x2-x1)/(float)m_wScreen;
  504. // float b12=(float)(y2-y1)/(float)m_hScreen;
  505. if(b12<b11)
  506. b11=b12;
  507. blc=blc/b11;
  508. }
  509. else 
  510. {
  511. m_xStart=m_xStart-blc*(point.x-mPointOrign.x);
  512. m_yStart=m_yStart+blc*(point.y-mPointOrign.y);
  513. }
  514. PushNumb=0;//完成操作,左键按下数置0
  515.             m_DrawCurrent=0;//完成一次后不继续运行此功能
  516. pDoc->AddScreen(m_xStart,m_yStart,blc);
  517. ReleaseCapture();
  518. Invalidate();
  519. }
  520. }
  521. else if(m_DrawCurrent==19)
  522. {
  523. if(PushNumb=0)
  524. {
  525. x_Move=0;
  526. y_Move=0;
  527. mPointOrign=point;
  528. mPointOld=point;
  529. PushNumb++;
  530. SetCapture();
  531. }
  532. else if(PushNumb==1)
  533. {
  534. PushNumb=0;
  535. ReleaseCapture();
  536. m_DrawCurrent=0;
  537. Invalidate();
  538. }
  539. }
  540. else if(m_DrawCurrent==30)//实现点选图形元素的功能
  541. {
  542. if(pDoc->n_GraphSelect==10000)
  543. {
  544. AfxMessageBox("最多只能选择10000个图形元素");
  545. return ;
  546. }
  547. VPtoDP(point.x,point.y,&xx1,&yy1);
  548. float j1=blc*4;
  549. BOOL pb=pDoc->PointSelect(xx1,yy1,j1,blc,&Lb,&index,&id_only);
  550. if(pb)
  551. {
  552. BOOL pb1=pDoc->AddSelectList(Lb,index,id_only);
  553. if(pb1)
  554. pDoc->DrawGraph(&ht,Lb,index,0,1,BackColor);
  555. // pDoc->DrawGraph(&ht,Lb,index,0,1);
  556. }
  557. }
  558. // CView::OnLButtonDown(nFlags, point);
  559. }
  560. void CDrawView::OnRButtonDown(UINT nFlags, CPoint point) 
  561. {
  562. // TODO: Add your message handler code here and/or call default
  563. CDrawDoc* pDoc=GetDocument();
  564. CClientDC ddd(this);
  565. CPen pen(0,0,RGB(0,0,0));
  566. CPen* pOldPen=ddd.SelectObject(&pen);
  567. ddd.SetROP2(R2_NOT);
  568. int id_only;
  569. CArc m_Arc1;
  570. if(m_DrawCurrent==1&&PushNumb==1)
  571. {
  572. ddd.MoveTo(mPointOrign);
  573. ddd.LineTo(mPointOld);
  574. PushNumb=0;
  575. ReleaseCapture();
  576. }
  577. else if((m_DrawCurrent==2||m_DrawCurrent==3)&&PushNumb>0)
  578. {
  579. ddd.MoveTo(mPointOrign);
  580. ddd.LineTo(mPointOld);
  581. if(m_DrawCurrent==2&&PushNumb>1)
  582. {
  583. id_only=pDoc->GetGraphID(2);
  584. pDoc->AddPLine(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,PushNumb,PointXyz)->Draw(&ddd,0,0,m_bColor);
  585. ReleaseCapture();
  586. }
  587. else if(m_DrawCurrent==3&&PushNumb>2)
  588. {
  589. id_only=pDoc->GetGraphID(2);
  590. pDoc->AddPLineRgn(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,PushNumb,PointXyz,0,1)->Draw(&ddd,0,0,m_bColor);
  591. ReleaseCapture();
  592. }
  593. PushNumb=0;
  594. ReleaseCapture();
  595. }
  596. else if((m_DrawCurrent==4||m_DrawCurrent==5)&&PushNumb>0)
  597. {
  598. if(m_DrawCurrent==4)
  599. ddd.SelectStockObject(NULL_BRUSH);
  600. r=(int)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
  601.         ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
  602. ReleaseCapture();
  603. PushNumb=0;
  604. }
  605. else if(m_DrawCurrent==6&&PushNumb>0)
  606. {
  607. if(PushNumb==2)
  608. m_Arc1.Draw(&ddd,1,0,m_bColor);
  609. PushNumb=0;
  610. ReleaseCapture();
  611. }
  612. else if(m_DrawCurrent==9&&PushNumb==1)
  613. {
  614. ddd.MoveTo(mPointOrign);
  615. ddd.LineTo(mPointOld);
  616. PushNumb=0;
  617. ReleaseCapture();
  618. }
  619. else if((m_DrawCurrent==11||m_DrawCurrent==12)&&PushNumb==1)
  620. {
  621. ddd.SelectStockObject(NULL_BRUSH);
  622. if(m_DrawCurrent==11)
  623. ddd.Rectangle(mPointOrign.x,mPointOrign.y,point.x,point.y);
  624. else 
  625. {
  626. ddd.MoveTo(mPointOrign);
  627. ddd.LineTo(point);
  628. }
  629. ReleaseCapture();
  630. PushNumb=0;
  631. }
  632. else if(m_DrawCurrent==19&&PushNumb>0)
  633. {
  634. for(int i=0;i<pDoc->n_GraphSelect;i++)
  635. pDoc->DrawGraph(&ddd,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,1,1,0);
  636. for(i=0;i<pDoc->n_GraphSelect;i++)
  637. pDoc->GetGraph(pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index)->Move(-x_Move,-y_Move);
  638. ReleaseCapture();
  639. PushNumb=0;
  640. // m_bPopup=1;
  641. Invalidate();
  642. }
  643. ddd.SelectObject(pOldPen);//恢复原来的画笔
  644. CView::OnRButtonDown(nFlags, point);
  645. }
  646. void CDrawView::OnDrawLine()
  647. {
  648. PushNumb=0;
  649. m_DrawCurrent=1;
  650. }
  651. void CDrawView::OnDrawCircle()
  652. {
  653. PushNumb=0;
  654. m_DrawCurrent=4;
  655. }
  656. void CDrawView::OnDrawCircle1()
  657. {
  658. PushNumb=0;
  659. m_DrawCurrent=5;
  660. }
  661. void CDrawView::OnDrawArc()
  662. {
  663. PushNumb=0;
  664. m_DrawCurrent=6;
  665. }
  666. void CDrawView::OnDrawText()
  667. {
  668. PushNumb=0;
  669. m_DrawCurrent=7;
  670. }
  671. void CDrawView::OnDrawPline()
  672. {
  673. PushNumb=0;
  674. m_DrawCurrent=2;
  675. }
  676. void CDrawView::OnDrawPlineRgn()
  677. {
  678. PushNumb=0;
  679. m_DrawCurrent=3;
  680. }
  681. void CDrawView::OnDrawNet()
  682. {
  683. PushNumb=0;
  684. m_DrawCurrent=8;
  685. }
  686. void CDrawView::OnDrawNetLink()
  687. {
  688. PushNumb=0;
  689. m_DrawCurrent=9;
  690. }
  691. BOOL CDrawView::jsarc(CPoint p1,CPoint p2,CPoint p3,float *CircleX,float *CircleY,float *CircleR,float *Angle1,float *Angle2)
  692. {
  693. float an1,an2,an3,k1,k2;
  694. float x1,y1,x2,y2,x3,y3,xx1,xx2,yy1,yy2,xx,yy,rr;
  695. x1=(float)p1.x;y1=(float)p1.y;x2=(float)p2.x;//将三个点的变量赋值给浮点变量
  696. y2=(float)p2.y;x3=(float)p3.x;y3=(float)p3.y;
  697. if(x1==x2&&y1==y2||x1==x3&&y1==y3||x2==x3&&y2==y3)//如果有两个点的坐标相同
  698. return FALSE;          //操作不成功,返回FALSE
  699. xx1=(x1+x2)/2;yy1=(y1+y2)/2;
  700. xx2=(x2+x3)/2;yy2=(y2+y3)/2;
  701. if(fabs(y2-y1)>0.5)   //如果第一条直线段的垂线不是竖直线
  702. k1=-(x2-x1)/(y2-y1);
  703. if(fabs(y3-y2)>0.5)
  704. k2=-(x3-x2)/(y3-y2);
  705. if(k1==k2&&k1==0.0)
  706. return 0;
  707. if(fabs(y2-y1)<0.5)
  708. {
  709. xx=xx1;
  710. if(fabs(y3-y2)<0.5)
  711. {
  712. yy=y2+10000;
  713. rr=10000;
  714. }
  715. else 
  716. {
  717. yy=yy2+k2*(xx2-xx);
  718. rr=yy-y2;
  719. if(rr<0)
  720. rr=-rr;
  721. }
  722. }
  723. else if(fabs(y2-y3)<0.5)
  724. {
  725. yy=yy1+k1*(xx1-xx);
  726. rr=yy-y2;
  727. if(rr<0)
  728. rr=-rr;
  729. }
  730. else 
  731. {
  732. if(k1==k2)
  733. {
  734. xx=x2+(float)(10000/sqrt(1+k1*k1));
  735. yy=y2+(float)(10000/sqrt((1+k1*k1)/(k1*k1)));
  736. rr=10000;
  737. }
  738. else
  739. {
  740. xx=(yy2-yy1+k1*xx1-k2*xx2)/(k1-k2);
  741. yy=yy1+k1*(xx-xx1);
  742. rr=(float)sqrt((xx-x1)*(xx-x1)+(yy-y1)*(yy-y1));
  743. }
  744. }
  745. *CircleX=m_xStart+blc*xx;
  746. *CircleY=m_yStart+blc*(m_hScreen-yy)*blc;
  747. *CircleR=blc*rr;
  748. an1=(float)acos((x1-xx)/rr);
  749. if(y1-yy>0)
  750. an1=(float)(pi*2-an1);
  751. an2=(float)acos((x2-xx)/rr);
  752. if(y2-yy>0)
  753. an2=(float)(pi*2-an2);
  754. an3=(float)acos((x3-xx)/rr);
  755. if(y3-yy>0)
  756. an3=(float)(pi*2-an3);
  757. if(an2>an1&&an2<an1+pi||an2<an1&&an2+pi<an1)
  758. {
  759. *Angle1=an1;
  760. *Angle2=an3;
  761. }
  762. else
  763. {
  764. *Angle1=an3;
  765. *Angle2=an1;
  766. }
  767. return TRUE;
  768. }
  769. void CDrawView::DrawText()
  770. {
  771. CClientDC ht(this);
  772. m_TextString=pTextDlg->m_Text;  //从标注文本对话框中得到标注文本内容
  773.     m_Text1->Init(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,m_TextX,m_TextY,m_TextAngle,m_FontAngle,m_FontHeight,m_FontWide,m_FontBetween,0,m_TextString);
  774. m_Text1->Draw(&ht,0,0,m_bColor);//绘制标准文本
  775. }
  776. void CDrawView::DrawTextOnOk()
  777. {
  778. CDrawDoc* pDoc=GetDocument();
  779. CClientDC ht(this);
  780. int TextLong;
  781. PushNumb=0;
  782. m_TextString=pTextDlg->m_Text;
  783. TextLong=m_TextString.GetLength();
  784. if(TextLong>0)
  785. {
  786. int id_only=pDoc->GetGraphID(5);
  787. pDoc->AddText(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,
  788. m_TextX,m_TextY,m_TextAngle,m_FontAngle,m_FontHeight,m_FontWide,
  789. m_FontBetween,0,TextLong,m_TextString)->Draw(&ht,0,0,m_bColor);
  790. pTextDlg->m_Text.Empty();    //晴空字符串内容
  791. pTextDlg->SendMessage(WM_INITDIALOG);
  792. }
  793. }
  794. void CDrawView::DrawTextOnCancel()
  795. {
  796. pTextDlg->m_Text.Empty();//晴空标注文本对话框中编辑框内的内容
  797. pTextDlg->SendMessage(WM_INITDIALOG);
  798. }
  799. void CDrawView::OnGraphRedraw() 
  800. {
  801. // TODO: Add your command handler code here
  802. CDrawDoc* pDoc=GetDocument();
  803. pDoc->UpdateAllViews(this);//使文档对象的所有视图重画
  804. Invalidate();
  805. }
  806. void CDrawView::OnGraphZoom() 
  807. {
  808. // TODO: Add your command handler code here
  809. m_DrawCurrent=11;//标识进行图形放大操作
  810.     PushNumb=0;
  811. }
  812. void CDrawView::OnGraphPan() 
  813. {
  814. // TODO: Add your command handler code here
  815. m_DrawCurrent=12;//标识进行图形摆动操作
  816. PushNumb=0;
  817. }
  818. void CDrawView::OnGraphUp() 
  819. {
  820. // TODO: Add your command handler code here
  821. CDrawDoc* pDoc=(CDrawDoc*)GetDocument();
  822. if(pDoc->m_CurrentScreen>0)
  823. pDoc->m_CurrentScreen--;
  824. m_xStart=p_Screen[pDoc->m_CurrentScreen].sx;
  825. m_yStart=p_Screen[pDoc->m_CurrentScreen].sy;
  826. blc=p_Screen[pDoc->m_CurrentScreen].blc;
  827. Invalidate();    //重画图形
  828. }
  829. void CDrawView::OnGraphFirst() //重画首屏
  830. {
  831. // TODO: Add your command handler code here
  832. CDrawDoc* pDoc=GetDocument();
  833. if(pDoc->m_CurrentScreen==0)
  834. return ;
  835. m_xStart=p_Screen[0].sx;
  836. m_yStart=p_Screen[0].sy;
  837. blc=p_Screen[0].blc;
  838. pDoc->AddScreen(m_xStart,m_yStart,blc);
  839. Invalidate();
  840. }
  841. //实现显示全屏功能
  842. void CDrawView::OnGraphAll() 
  843. {
  844. // TODO: Add your command handler code here
  845. float minx,miny,maxx,maxy,bl1;
  846. CDrawDoc* pDoc=GetDocument();
  847. SetCapture();
  848. SetCursor(LoadCursor(NULL,IDC_WAIT));
  849. BOOL pb=pDoc->GetRect(&minx,&miny,&maxx,&maxy);
  850. SetCursor(LoadCursor(NULL,IDC_ARROW));
  851. ReleaseCapture();
  852. if(!pb)
  853. return ;
  854. bl1=(maxx-minx)/(m_wScreen-20);
  855. blc=(maxy-miny)/(m_hScreen-20);
  856. if(bl1>blc)
  857. blc=bl1;
  858. m_xStart=minx-10*blc;
  859. m_yStart=miny-10*blc;
  860. p_Screen[0].sx=m_xStart;
  861. p_Screen[0].sy=m_yStart;
  862. p_Screen[0].blc=blc;
  863. pDoc->m_CurrentScreen=0;
  864. Invalidate();
  865. }
  866. void CDrawView::OnSelectMouse() 
  867. {
  868. // TODO: Add your command handler code here
  869.     m_DrawCurrent=30;   //标识进行图形元素点选操作 
  870. PushNumb=0;
  871. }
  872. void CDrawView::OnSelectClear() 
  873. {
  874. // TODO: Add your command handler code here
  875. CDrawDoc* pDoc=GetDocument();
  876. CClientDC ht(this);
  877. for(int i=0;i<pDoc->n_GraphSelect;i++)
  878. pDoc->DrawGraph(&ht,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,0,0,0);
  879. pDoc->n_GraphSelect=0;
  880. }
  881. void CDrawView::OnEditMove() 
  882. {
  883. // TODO: Add your command handler code here
  884. CDrawDoc* pDoc=GetDocument();
  885. m_DrawCurrent=19;
  886. PushNumb=0;
  887. }
  888. void CDrawView::Delete(CDC* pDC,int Lb,int index)
  889. {
  890. float x1,y1,x2,y2;
  891. CDrawDoc* pDoc=GetDocument();
  892. CDraw* pDraw;
  893. pDraw=pDoc->GetGraph(Lb,index);
  894. pDraw->Delete(1);
  895. if(Lb==1)
  896. pDraw->Draw(pDC,0,2,m_bColor);
  897. else if(Lb==2)
  898. pDraw->Draw(pDC,0,2,m_bColor);
  899. else if(Lb==3)
  900. {
  901. if(!pDraw->IsFill())
  902. pDraw->Draw(pDC,0,2,m_bColor);
  903. else
  904. {
  905. pDraw->GetRect(&x1,&y1,&x2,&y2);
  906. ReDrawRect(x1,y1,x2,y2);
  907. }
  908. }
  909. else if(Lb==4)
  910. pDraw->Draw(pDC,0,2,m_bColor);
  911. else if(Lb==5)
  912. {
  913. pDraw->GetRect(&x1,&y1,&x2,&y2);
  914. ReDrawRect(x1,y1,x2,y2);
  915. }
  916. else if(Lb==6)
  917. {
  918. pDraw->GetRect(&x1,&y1,&x2,&y2);
  919. ReDrawRect(x1,y1,x2,y2);
  920. }
  921. else if(Lb==7)
  922. {
  923. pDraw->GetRect(&x1,&y1,&x2,&y2);
  924. ReDrawRect(x1,y1,x2,y2);
  925. }
  926. else if(Lb==8)
  927. pDraw->Draw(pDC,0,2,m_bColor);
  928. }
  929. void CDrawView::ReDrawRect(float X1,float Y1,float X2,float Y2)
  930. {
  931. float xx1,xx2,yy1,yy2;
  932. CRect r1;
  933. //以下是视图屏幕矩形区域的实际坐标
  934. xx1=xMinScreen;
  935. xx2=xMaxScreen;
  936. yy1=yMinScreen;
  937. yy2=yMaxScreen;
  938. //得到需要绘制区域与视图屏幕区域相交的边界矩形
  939. BOOL IsCross=RectCross(&xx1,&yy1,&xx2,&yy2,X1,Y1,X2,Y2);
  940. if(IsCross)
  941. {
  942. r1.left=(int)((xx1-m_xStart)/blc)-1;
  943. r1.right=(int)((xx2-m_xStart)/blc)+1;
  944. r1.top=m_hScreen-(int)((yy2-m_yStart)/blc)-1;
  945. r1.bottom=m_hScreen-(int)((yy1-m_yStart)/blc)+1;
  946. InvalidateRect(r1);
  947. }
  948. }
  949. BOOL CDrawView::RectCross(float* x1,float* y1,float* x2,float* y2,float xx1,float yy1,float xx2,float yy2)
  950. {
  951. float m_X1,m_Y1,m_X2,m_Y2;
  952. m_X1=*x1;m_Y1=*y1;m_X2=*x2;m_Y2=*y2;
  953. if(m_X1>xx2||m_X2<xx1||m_Y1>yy2||m_Y2<yy1)
  954. return FALSE;
  955. else
  956. {
  957. *x1=max(m_X1,xx1);
  958. *y1=max(m_Y1,yy1);
  959. *x2=min(m_X2,xx2);
  960. *y2=min(m_X2,yy2);
  961. return TRUE;
  962. }
  963. }
  964. void CDrawView::OnSelectDelete() 
  965. {
  966. // TODO: Add your command handler code here
  967. CDrawDoc* pDoc=GetDocument();
  968. CClientDC ht(this);
  969. for(int i=0;i<pDoc->n_GraphSelect;i++)
  970. {
  971. Delete(&ht,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index);
  972. ReleaseCapture();
  973. pDoc->n_GraphSelect=0;
  974. }
  975. }