Arc.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:4k
源码类别:
GIS编程
开发平台:
Visual C++
- // Arc.cpp: implementation of the CArc class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- //#include "Draw.h"
- #include "Arc.h"
- #include "math.h"
- //#include "DrawDoc.h"
- #define pi 3.1415926
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- extern IsRectCross(float minx,float miny,float maxx,float maxy);
- //extern CGraphPara *p_GraphPara;
- //CArc::CArc();
- //float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
- //BOOL IsRectCross(float minx,float miny,float maxx,float maxy);
- //BOOL IsRectCross(float minx,float miny,float maxx,float maxy)
- //{
- // if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
- // return FALSE; //如两个矩形不相交
- // else
- // return TRUE;
- //}
- void CArc::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- if(b_Delete)
- return ;
- int x,y,rr;
- int x1,y1,x2,y2;
- float minx,miny,maxx,maxy;
- GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
- if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
- return;
- short LineType=m_LineType;
- short LineWide=max(1,DLtoVL(m_LineWide));
- short ColorPen=m_ColorPen;
- if(m_DrawModel==1)
- {
- if(m_LineType!=2)
- LineType=2;
- else
- LineType++;
- }
- else if(m_DrawModel==2)
- ColorPen=BackColor;
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- CPen pen((int)LineType,(int)LineWide,p_GraphPara->GetColor(ColorPen));
- CPen* pOldPen=pDC->SelectObject(&pen);
- if(m_DrawMode==0)
- pDC->SetROP2(R2_COPYPEN);
- else if(m_DrawMode==1)
- pDC->SetROP2(R2_NOT);
- DPtoVP(m_CircleX,m_CircleY,&x,&y);
- rr=DLtoVL(m_CircleR);
- x1=(int)(x+(DLtoVL(m_CircleR*cos(m_Angle1))));
- y1=(int)(y-DLtoVL(m_CircleR*sin(m_Angle1)));
- x2=(int)(x+DLtoVL(m_CircleR*cos(m_Angle2)));
- y2=(int)(y-DLtoVL(m_CircleR*sin(m_Angle2)));
- // Invalidate();
- pDC->Arc(x-rr,y-rr,x+rr,y+rr,x1,y1,x2,y2);
- pDC->SelectObject(pOldPen);
- }
- void CArc::GetRect(float* minX,float* minY,float* maxX,float* maxY)
- {
- float x,y,x1,y1,x2,y2;
- int i,pb;
- //得到圆弧的起点坐标
- x=m_CircleX+(float)(cos(m_Angle1)*m_CircleR);
- y=m_CircleY+(float)(sin(m_Angle1)*m_CircleR);
- //用圆弧起点坐标来初始化边界矩形
- x1=x;y1=y;
- x2=x;y2=y;
- //得到圆弧的中终点坐标
- x=m_CircleX+(float)(cos(m_Angle2)*m_CircleR);
- y=m_CircleY+(float)(sin(m_Angle2)*m_CircleR);
- //得到最小和最大坐标
- x1=min(x,x1);x2=max(x,x2);
- y1=min(y,y1);y2=max(y,y2);
- for(i=0;i<4;i++)
- {
- if(IsInArc(pi/2*i))
- {
- if(i==0)
- {
- x=m_CircleX+m_CircleR;
- y=m_CircleY;
- }
- else if(i==1)
- {
- x=m_CircleX;
- y=m_CircleY+m_CircleR;
- }
- else if(i==2)
- {
- x=m_CircleX-m_CircleR;
- y=m_CircleY;
- }
- else if(i==3)
- {
- x=m_CircleX;
- y=m_CircleY-m_CircleR;
- }
- x1=min(x,x1);x2=max(x,x2);
- y1=min(y,y1);y2=max(y,y2);
- }
- }
- *minX=x1;*maxX=x2;*minY=y1;*maxY=y2;
- }
- void CArc::CalLong()
- {
- float angle=m_Angle2;
- if(this->m_Angle2<this->m_Angle1)
- angle+=pi*2;
- CCircle::CalLong();
- m_fLong=m_fLong*(angle-m_Angle1)/(pi*2);
- }
- BOOL CArc::IsInArc(float angle)
- {
- if((m_Angle1<m_Angle2&&angle<m_Angle2&&angle>=m_Angle1)||
- m_Angle1>m_Angle2&&(!(angle<=m_Angle1&&angle>=m_Angle2)))
- return TRUE;
- else
- return FALSE;
- }
- BOOL CArc::IsPoint(float x,float y,float j1,float blc)
- {
- if(CCircle::IsPoint(x,y,j1,blc))//调用CCircle类的IsPoint函数判断是否选中了圆
- {
- float xx=CalDisp(x,y,m_CircleX,m_CircleY);
- float ang=(float)acos((x-m_CircleX)/xx);
- if(y-m_CircleY<0)
- ang=(float)pi*2-ang;
- if(IsInArc(ang))
- return TRUE;
- }
- return FALSE;
- }
- void CArc::Move(float x_Move,float y_Move)
- {
- CCircle::Move(x_Move,y_Move);
- }
- void CArc::Rotate(float baseX,float baseY,float angle)
- {
- RotatePoint(baseX,baseY,angle,&this->m_CircleX,&this->m_CircleY);
- this->m_Angle1+=angle;
- this->m_Angle2+=angle;
- }
- CArc::~CArc()
- {
- }