CIRCLE.cpp
上传用户:shangwu01
上传日期:2013-04-22
资源大小:707k
文件大小:6k
- // CIRCLE.cpp: implementation of the CCIRCLE class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CAD.h"
- #include "CIRCLE.h"
- #include "math.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CCIRCLE::CCIRCLE()
- {
- }
- CCIRCLE::~CCIRCLE()
- {
- }
- void CCIRCLE::circle_drawMove(CPoint m_pointorg,CPoint m_pointfal,CDC* pDC,int m_line_style,int m_line_width,COLORREF m_line_color)
- {
- double R;
- R=sqrt(pow(m_pointorg.x-m_pointfal.x,2)+pow(m_pointorg.y-m_pointfal.y,2));
- CPen pen;
- pen.CreatePen(m_line_style,m_line_width,m_line_color);
- pDC->SelectObject(&pen);
- pDC->Arc(CRect(m_pointorg.x-R,m_pointorg.y-R,m_pointorg.x+R,m_pointorg.y+R),m_pointfal,m_pointfal);
- pen.DeleteObject();//鼠标输出
- pen.CreatePen(PS_DOT,1,RGB(0,0,255));
- pDC->SelectObject(&pen);
- pDC->MoveTo(m_pointorg);
- pDC->LineTo(m_pointfal);
- pen.DeleteObject();//半径输出
- CString str;
- str.Format("R:%f",R);
- pDC->TextOut((m_pointorg.x+m_pointfal.x)/2+10,(m_pointorg.y+m_pointfal.y)/2+10,str,7);//文本输出
- }
- void CCIRCLE::circle_drawAttribution(CDC*pDC)
- {
- if(m_circle_save.GetSize())
- for(int i=0;i<m_circle_save.GetSize();i++)
- {
- CPoint certrepoint;
- double circleR;
- CPen pen;
- pen.CreatePen(((circle_data *)(m_circle_save.GetAt(i)))->m_line_style,((circle_data *)(m_circle_save.GetAt(i)))->m_line_width,
- ((circle_data *)(m_circle_save.GetAt(i)))->m_line_color);
- pDC->SelectObject(&pen);
- certrepoint=((circle_data *)(m_circle_save.GetAt(i)))->certrepoint;
- circleR=((circle_data *)(m_circle_save.GetAt(i)))->circleR;
- pDC->Arc(CRect(certrepoint.x-circleR,certrepoint.y-circleR,certrepoint.x+circleR,certrepoint.y+circleR),
- CPoint(certrepoint.x+circleR,certrepoint.y),CPoint(certrepoint.x+circleR,certrepoint.y));
- pen.DeleteObject();//圆的输出
- }
-
- }
- void CCIRCLE::circle_store(CPoint m_pointorg,CPoint m_pointfal,int m_line_style,int m_line_width,COLORREF m_line_color)
- {
- CPoint certrepoint;
- double circleR;
- certrepoint=m_pointorg;
- circleR=sqrt(pow(m_pointorg.x-m_pointfal.x,2)+pow(m_pointorg.y-m_pointfal.y,2));
-
- circle_data *pcircle_data=new circle_data(certrepoint,circleR,m_line_style,m_line_width,m_line_color);
- m_circle_save.Add(pcircle_data);//数据储存
-
- }
- void CCIRCLE::circle_catchcertre(CPoint point,CRgn *prgn,CDC *pDC)
- {
- if(m_circle_save.GetSize())
- for(int i=0;i<m_circle_save.GetSize();i++)
- {
- if(prgn->PtInRegion(((circle_data*)m_circle_save.GetAt(i))->certrepoint))
- circle_fillpoint(((circle_data*)m_circle_save.GetAt(i))->certrepoint,pDC);
- }
- }
- void CCIRCLE::circle_fillpoint(CPoint point,CDC *pDC)
- {
- CBrush brush;
- brush.CreateSolidBrush( RGB(0,255,255));
- pDC->SelectObject(&brush);
- pDC->Rectangle(CRect(point.x-4,point.y-4,point.x+4,point.y+4));
- brush.DeleteObject();
-
- }
- void CCIRCLE::circle_searchcertre(CPoint point,CPoint *pnearpoint,CRgn *prgn)
- {
- CPoint nearpoint;
- nearpoint=*pnearpoint;
-
- float nearrest;
- nearrest=sqrt(pow(point.x-nearpoint.x,2)+pow(point.y-nearpoint.y,2));
-
- if(m_circle_save.GetSize())
- for(int i=0;i<m_circle_save.GetSize();i++)
- if(prgn->PtInRegion(((circle_data*)m_circle_save.GetAt(i))->certrepoint))
- {
- float length;
- length=sqrt(pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.x-point.x,2)+
- pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.y-point.y,2));
- if(length<nearrest)
- nearpoint=((circle_data*)m_circle_save.GetAt(i))->certrepoint;
- }
-
- *pnearpoint=nearpoint;
-
- }
- bool CCIRCLE::circle_searchcircle(CPoint point,int *pNum,int *pnStyle,CDC *pmdc)
- {
- if(m_circle_save.GetSize())
- for(int i=0;i<m_circle_save.GetSize();i++)
- {
- float r;
- r=sqrt(pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.x-point.x,2)+
- pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.y-point.y,2));
- if(fabs(r-((circle_data*)m_circle_save.GetAt(i))->circleR)<3)
- {
- circle_fillpoint(((circle_data*)m_circle_save.GetAt(i))->certrepoint,pmdc);
- *pNum=i;
- *pnStyle=3;
- return(true);
- }
- }
- return(false);
- }
- bool CCIRCLE::circle_editselect(CPoint point,CPoint*ppointorg,int Num)
- {
- CPoint certrepoint;
- certrepoint=((circle_data*)m_circle_save.GetAt(Num))->certrepoint;
- CRgn rgn;
- rgn.CreateRectRgn(certrepoint.x-10,certrepoint.y-10,certrepoint.x+10,certrepoint.y+10);
- if(rgn.PtInRegion(point))
- {
- *ppointorg=certrepoint;
- return(true);
- }
- else
- return(false);
-
- }
- void CCIRCLE::circle_editmove(CPoint pointorg,CPoint pointfal,int Num,CDC* pDC)
- {
- CSize pointmove;
- pointmove=pointfal-pointorg;
-
- CPoint certrepoint;
- double circleR;
- certrepoint=((circle_data *)(m_circle_save.GetAt(Num)))->certrepoint+pointmove;
- circleR=((circle_data *)(m_circle_save.GetAt(Num)))->circleR;
- CPen pen;
- pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
- pDC->SelectObject(&pen);
- pDC->Arc(CRect(certrepoint.x-circleR,certrepoint.y-circleR,certrepoint.x+circleR,certrepoint.y+circleR),
- CPoint(certrepoint.x+circleR,certrepoint.y),CPoint(certrepoint.x+circleR,certrepoint.y));
- pen.DeleteObject();
- }
- void CCIRCLE::circle_editmovestore(CPoint pointorg,CPoint pointfal,int Num)
- {
- CSize pointmove;
- pointmove=pointfal-pointorg;
- ((circle_data *)(m_circle_save.GetAt(Num)))->certrepoint+=pointmove;
- }
- void CCIRCLE::circle_del(int Num)
- {
- circle_data *pdel=(circle_data*)m_circle_save.GetAt(Num);
- if(pdel!=NULL)
- {
- m_circle_save.RemoveAt(Num);
- delete pdel;
- }
-
- }
- ///////////////////////////////////////
- CCIRCLE::circle_data::circle_data(CPoint certrepoint,double circleR,int m_line_style,int m_line_width,COLORREF m_line_color)
- {
- this->certrepoint=certrepoint;
- this->circleR=circleR;
- this->m_line_style=m_line_style;
- this->m_line_width=m_line_width;
- this->m_line_color=m_line_color;
- }
- CCIRCLE::circle_data::~circle_data()
- {
- }