Parallelogram.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:32k
源码类别:
绘图程序
开发平台:
Visual C++
- // Parallelogram.cpp: implementation of the CParallelogram class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "Parallelogram.h"
- #include "GlobalFunction.h"
- #include "math.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- ///////////////////////////////////
- IMPLEMENT_SERIAL( CParallelogram, CShape, 0 )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CParallelogram::CParallelogram():CShape()
- {
- m_flFirstxTemp=m_flFirstx=0;
- m_flFirstyTemp=m_flFirsty=0;
- m_flSecondxTemp=m_flSecondx=0;
- m_flSecondyTemp=m_flSecondy=0;
- m_flThirdxTemp=m_flThirdx=0;
- m_flThirdyTemp=m_flThirdy=0;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- ////////////////////////////
- CParallelogram::CParallelogram(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
- {
- m_flFirstxTemp=m_flFirstx=0;
- m_flFirstyTemp=m_flFirsty=0;
- m_flSecondxTemp=m_flSecondx=0;
- m_flSecondyTemp=m_flSecondy=0;
- m_flThirdxTemp=m_flThirdx=0;
- m_flThirdyTemp=m_flThirdy=0;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- //////////////////////////////
- CParallelogram::CParallelogram(CParallelogram * const pParallelogram):CShape(pParallelogram)
- {
- m_flFirstx=pParallelogram->m_flFirstx;
- m_flFirsty=pParallelogram->m_flFirsty;
- m_flSecondx=pParallelogram->m_flSecondx;
- m_flSecondy=pParallelogram->m_flSecondy;
- m_flThirdx=pParallelogram->m_flThirdx;
- m_flThirdy=pParallelogram->m_flThirdy;
- ////
- m_flFirstxTemp=pParallelogram->m_flFirstxTemp;
- m_flFirstyTemp=pParallelogram->m_flFirstyTemp;
- m_flSecondxTemp=pParallelogram->m_flSecondxTemp;
- m_flSecondyTemp=pParallelogram->m_flSecondyTemp;
- m_flThirdxTemp=pParallelogram->m_flThirdxTemp;
- m_flThirdyTemp=pParallelogram->m_flThirdyTemp;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- CParallelogram::~CParallelogram()
- {
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- //存储
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::Serialize( CArchive& ar)
- {
- CShape::Serialize( ar ) ;
- if ( ar.IsLoading() ){
- ar>>m_flFirstx;
- ar>>m_flFirsty;
- ar>>m_flSecondx;
- ar>>m_flSecondy;
- ar>>m_flThirdx;
- ar>>m_flThirdy;
- //temp
- m_flFirstxTemp=m_flFirstx;
- m_flFirstyTemp=m_flFirsty;
- m_flSecondxTemp=m_flSecondx;
- m_flSecondyTemp=m_flSecondy;
- m_flThirdxTemp=m_flThirdx;
- m_flThirdyTemp=m_flThirdy;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- } else {
- ar<<m_flFirstx;
- ar<<m_flFirsty;
- ar<<m_flSecondx;
- ar<<m_flSecondy;
- ar<<m_flThirdx;
- ar<<m_flThirdy;
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- //绘画
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, fillColor);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- CPoint ptArray[4];
- ptArray[0].x=m_flFirstxTemp;
- ptArray[0].y=m_flFirstyTemp;
- ptArray[1].x=m_flSecondxTemp;
- ptArray[1].y=m_flSecondyTemp;
- ptArray[2].x=m_flThirdxTemp;
- ptArray[2].y=m_flThirdyTemp;
- ptArray[3].x=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- ptArray[3].y=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- AreaFill(pDC,4,ptArray,fillColor);
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth,color);
- pDC->SelectObject(&pen);
- pDC->MoveTo(m_flFirstxTemp,m_flFirstyTemp);
- pDC->LineTo(m_flSecondxTemp,m_flSecondyTemp);
- pDC->LineTo(m_flThirdxTemp,m_flThirdyTemp);
- // pDC->LineTo(m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp,m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp);
- pDC->LineTo(m_flForthxTemp,m_flForthyTemp);
- pDC->LineTo(m_flFirstxTemp,m_flFirstyTemp);
- if(GetDrawPointsFlag()==1){
- DrawPoints(pDC,color);
- }
- pDC->SelectObject(poldPen);
- }
- ///////////////////////////////////////////
- void CParallelogram::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
- {
- //得到移动扩缩后的关键数据
- float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
- //移动
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- flFirstx=m_flFirstxTemp+stepx;
- flFirsty=m_flFirstyTemp+stepy;
- flSecondx=m_flSecondxTemp+stepx;
- flSecondy=m_flSecondyTemp+stepy;
- flThirdx=m_flThirdxTemp+stepx;
- flThirdy=m_flThirdyTemp+stepy;
- flForthx=m_flForthxTemp+stepx;
- flForthy=m_flForthyTemp+stepy;
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- flFirstx=(flFirstx-cx)*flScale+cx;
- flFirsty=(flFirsty-cy)*flScale+cy;
- flSecondx=(flSecondx-cx)*flScale+cx;
- flSecondy=(flSecondy-cy)*flScale+cy;
- flThirdx=(flThirdx-cx)*flScale+cx;
- flThirdy=(flThirdy-cy)*flScale+cy;
- flForthx=(flForthx-cx)*flScale+cx;
- flForthy=(flForthy-cy)*flScale+cy;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- {
- pDC->MoveTo(flFirstx,flFirsty-1-GetPenWidth());
- pDC->LineTo(flFirstx,flFirsty+2+GetPenWidth());
- pDC->MoveTo(flFirstx-1-GetPenWidth(),flFirsty);
- pDC->LineTo(flFirstx+2+GetPenWidth(),flFirsty);
- pDC->MoveTo(flSecondx,flSecondy-1-GetPenWidth());
- pDC->LineTo(flSecondx,flSecondy+2+GetPenWidth());
- pDC->MoveTo(flSecondx-1-GetPenWidth(),flSecondy);
- pDC->LineTo(flSecondx+2+GetPenWidth(),flSecondy);
- pDC->MoveTo(flThirdx,flThirdy-1-GetPenWidth());
- pDC->LineTo(flThirdx,flThirdy+2+GetPenWidth());
- pDC->MoveTo(flThirdx-1-GetPenWidth(),flThirdy);
- pDC->LineTo(flThirdx+2+GetPenWidth(),flThirdy);
- pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
- pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
- pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
- pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- void CParallelogram::DrawPoints(CDC *pDC,COLORREF color)
- {
- float flForthx,flForthy;
- // flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- // flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- {
- pDC->MoveTo(m_flFirstxTemp,m_flFirstyTemp-1-GetPenWidth());
- pDC->LineTo(m_flFirstxTemp,m_flFirstyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flFirstxTemp-1-GetPenWidth(),m_flFirstyTemp);
- pDC->LineTo(m_flFirstxTemp+2+GetPenWidth(),m_flFirstyTemp);
- pDC->MoveTo(m_flSecondxTemp,m_flSecondyTemp-1-GetPenWidth());
- pDC->LineTo(m_flSecondxTemp,m_flSecondyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flSecondxTemp-1-GetPenWidth(),m_flSecondyTemp);
- pDC->LineTo(m_flSecondxTemp+2+GetPenWidth(),m_flSecondyTemp);
- pDC->MoveTo(m_flThirdxTemp,m_flThirdyTemp-1-GetPenWidth());
- pDC->LineTo(m_flThirdxTemp,m_flThirdyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flThirdxTemp-1-GetPenWidth(),m_flThirdyTemp);
- pDC->LineTo(m_flThirdxTemp+2+GetPenWidth(),m_flThirdyTemp);
- pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
- pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
- pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
- pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- ////////////////////////////////////////////
- void CParallelogram::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
- //移动
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- flFirstx=m_flFirstxTemp+stepx;
- flFirsty=m_flFirstyTemp+stepy;
- flSecondx=m_flSecondxTemp+stepx;
- flSecondy=m_flSecondyTemp+stepy;
- flThirdx=m_flThirdxTemp+stepx;
- flThirdy=m_flThirdyTemp+stepy;
- flForthx=m_flForthxTemp+stepx;
- flForthy=m_flForthyTemp+stepy;
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- // flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- flFirstx=(flFirstx-cx)*flScale+cx;
- flFirsty=(flFirsty-cy)*flScale+cy;
- flSecondx=(flSecondx-cx)*flScale+cx;
- flSecondy=(flSecondy-cy)*flScale+cy;
- flThirdx=(flThirdx-cx)*flScale+cx;
- flThirdy=(flThirdy-cy)*flScale+cy;
- flForthx=(flForthx-cx)*flScale+cx;
- flForthy=(flForthy-cy)*flScale+cy;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, fillColor);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- CPoint ptArray[4];
- ptArray[0].x=flFirstx;
- ptArray[0].y=flFirsty;
- ptArray[1].x=flSecondx;
- ptArray[1].y=flSecondy;
- ptArray[2].x=flThirdx;
- ptArray[2].y=flThirdy;
- ptArray[3].x=flForthx;
- ptArray[3].y=flForthy;
- AreaFill(pDC,4,ptArray,fillColor);
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth,color);
- pDC->SelectObject(&pen);
- pDC->MoveTo(flFirstx,flFirsty);
- pDC->LineTo(flSecondx,flSecondy);
- pDC->LineTo(flThirdx,flThirdy);
- pDC->LineTo(flForthx,flForthy);
- pDC->LineTo(flFirstx,flFirsty);
- if(GetDrawPointsFlag()==1){
- DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
- }
- pDC->SelectObject(poldPen);
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- if(flArrayX.GetSize()<3){
- return;
- }
- CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
- m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
- m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
- m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(1);
- m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
- m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(2);
- m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(2);
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- if(ptArray.GetSize()<3){
- return;
- }
- CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
- m_flFirstxTemp=m_flFirstx=((CPoint)ptArray.GetAt(0)).x;
- m_flFirstyTemp=m_flFirsty=((CPoint)ptArray.GetAt(0)).y;
- m_flSecondxTemp=m_flSecondx=((CPoint)ptArray.GetAt(1)).x;
- m_flSecondyTemp=m_flSecondy=((CPoint)ptArray.GetAt(1)).y;
- m_flThirdxTemp=m_flThirdx=((CPoint)ptArray.GetAt(2)).x;
- m_flThirdyTemp=m_flThirdy=((CPoint)ptArray.GetAt(2)).y;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CParallelogram::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
- m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
- m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(1);
- m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
- m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(2);
- m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(2);
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CParallelogram::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- flArrayX.RemoveAll();
- flArrayY.RemoveAll();
- flArrayX.Add(m_flFirstxTemp);
- flArrayX.Add(m_flSecondxTemp);
- flArrayX.Add(m_flThirdxTemp);
- flArrayY.Add(m_flFirstyTemp);
- flArrayY.Add(m_flSecondyTemp);
- flArrayY.Add(m_flThirdyTemp);
- }
- CShape* CParallelogram::GetCopy()
- {
- CShape* pGraph=new CParallelogram(this);
- return pGraph;
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::Move(CDC *pDC,float stepx,float stepy)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstx+=stepx;
- m_flFirsty+=stepy;
- m_flSecondx+=stepx;
- m_flSecondy+=stepy;
- m_flThirdx+=stepx;
- m_flThirdy+=stepy;
- //temp
- m_flFirstxTemp+=stepx;
- m_flFirstyTemp+=stepy;
- m_flSecondxTemp+=stepx;
- m_flSecondyTemp+=stepy;
- m_flThirdxTemp+=stepx;
- m_flThirdyTemp+=stepy;
- m_flForthx+=stepx;
- m_flForthy+=stepy;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CParallelogram::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
- {
- if(m_nSelectPtNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- float flX,flY;
- float flDisA,flDisB;
- switch(m_nSelectPtNum) {
- case 0:
- flX = m_flThirdx;
- flY = m_flThirdy;
- flDisA=GetDistance(m_flThirdx,m_flThirdy,m_flFirstx,m_flFirsty);
- flDisB=GetDistance(m_flThirdx,m_flThirdy,CurX,CurY);
- break;
- case 1:
- flX = m_flForthx;
- flY = m_flForthy;
- flDisA=GetDistance(m_flForthx,m_flForthy,m_flSecondx,m_flSecondy);
- flDisB=GetDistance(m_flForthx,m_flForthy,CurX,CurY);
- break;
- case 2:
- flX = m_flFirstx;
- flY = m_flFirsty;
- flDisA=GetDistance(m_flFirstx,m_flFirsty,m_flThirdx,m_flThirdy);
- flDisB=GetDistance(m_flFirstx,m_flFirsty,CurX,CurY);
- break;
- case 3:
- flX = m_flSecondx;
- flY = m_flSecondy;
- flDisA=GetDistance(m_flSecondx,m_flSecondy,m_flForthx,m_flForthy);
- flDisB=GetDistance(m_flSecondx,m_flSecondy,CurX,CurY);
- break;
- }
- if(flDisA<1){
- flDisA=1;
- }
- Magnify(pDC,flX,flY,flDisB/flDisA);
- //CShape::Draw(pDC);
- }else if(m_nSelectLineNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- float flCut1x,flCut1y,flCut2x,flCut2y;
- float flX1[4],flY1[4],flX2[4],flY2[4];
- switch(m_nSelectLineNum) {
- case 0:
- flX1[0]=m_flForthx;
- flY1[0]=m_flForthy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flFirstx;
- flY1[2] = m_flFirsty;
- flX1[3] = m_flSecondx;
- flY1[3] = m_flSecondy;
- flX2[0]=m_flThirdx;
- flY2[0]=m_flThirdy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = m_flFirstx;
- flY2[2] = m_flFirsty;
- flX2[3] = m_flSecondx;
- flY2[3] = m_flSecondy;
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flForthx)>=0.01){
- m_flFirstxTemp=(m_flFirstx-m_flForthx)*((float)CurX-flCut1x)/(flCut1x-m_flForthx)+m_flFirstx;
- }
- if(fabs(flCut1y-m_flForthy)>=0.01){
- m_flFirstyTemp=(m_flFirsty-m_flForthy)*((float)CurY-flCut1y)/(flCut1y-m_flForthy)+m_flFirsty;
- }
- if(fabs(flCut2x-m_flThirdx)>=0.01){
- m_flSecondxTemp=(m_flSecondx-m_flThirdx)*((float)CurX-flCut2x)/(flCut2x-m_flThirdx)+m_flSecondx;
- }
- if(fabs(flCut2y-m_flThirdy)>=0.01){
- m_flSecondyTemp=(m_flSecondy-m_flThirdy)*((float)CurY-flCut2y)/(flCut2y-m_flThirdy)+m_flSecondy;
- }
- }
- break;
- case 1:
- flX1[0]=m_flFirstx;
- flY1[0]=m_flFirsty;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flSecondx;
- flY1[2] = m_flSecondy;
- flX1[3] = m_flThirdx;
- flY1[3] = m_flThirdy;
- flX2[0]=m_flForthx;
- flY2[0]=m_flForthy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flFirstx)>=0.01){
- m_flSecondxTemp=(m_flSecondx-m_flFirstx)*((float)CurX-flCut1x)/(flCut1x-m_flFirstx)+m_flSecondx;
- }
- if(fabs(flCut1y-m_flFirsty)>=0.01){
- m_flSecondyTemp=(m_flSecondy-m_flFirsty)*((float)CurY-flCut1y)/(flCut1y-m_flFirsty)+m_flSecondy;
- }
- if(fabs(flCut2x-m_flForthx)>=0.01){
- m_flThirdxTemp=(m_flThirdx-m_flForthx)*((float)CurX-flCut2x)/(flCut2x-m_flForthx)+m_flThirdx;
- }
- if(fabs(flCut2y-m_flForthy)>=0.01){
- m_flThirdyTemp=(m_flThirdy-m_flForthy)*((float)CurY-flCut2y)/(flCut2y-m_flForthy)+m_flThirdy;
- }
- }
- break;
- case 2:
- flX1[0]=m_flSecondx;
- flY1[0]=m_flSecondy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flThirdx;
- flY1[2] = m_flThirdy;
- flX1[3] = m_flForthx;
- flY1[3] = m_flForthy;
- flX2[0]=m_flFirstx;
- flY2[0]=m_flFirsty;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flSecondx)>=0.01){
- m_flThirdxTemp=(m_flThirdx-m_flSecondx)*((float)CurX-flCut1x)/(flCut1x-m_flSecondx)+m_flThirdx;
- }
- if(fabs(flCut1y-m_flSecondy)>=0.01){
- m_flThirdyTemp=(m_flThirdy-m_flSecondy)*((float)CurY-flCut1y)/(flCut1y-m_flSecondy)+m_flThirdy;
- }
- if(fabs(flCut2x-m_flFirstx)>=0.01){
- m_flForthxTemp=(m_flForthx-m_flFirstx)*((float)CurX-flCut2x)/(flCut2x-m_flFirstx)+m_flForthx;
- }
- if(fabs(flCut2y-m_flFirsty)>=0.01){
- m_flForthyTemp=(m_flForthy-m_flFirsty)*((float)CurY-flCut2y)/(flCut2y-m_flFirsty)+m_flForthy;
- }
- }
- break;
- case 3:
- flX1[0]=m_flThirdx;
- flY1[0]=m_flThirdy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flForthx;
- flY1[2] = m_flForthy;
- flX1[3] = m_flFirstx;
- flY1[3] = m_flFirsty;
- flX2[0]=m_flSecondx;
- flY2[0]=m_flSecondy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flThirdx)>=0.01){
- m_flForthxTemp=(m_flForthx-m_flThirdx)*((float)CurX-flCut1x)/(flCut1x-m_flThirdx)+m_flForthx;
- }
- if(fabs(flCut1y-m_flThirdy)>=0.01){
- m_flForthyTemp=(m_flForthy-m_flThirdy)*((float)CurY-flCut1y)/(flCut1y-m_flThirdy)+m_flForthy;
- }
- if(fabs(flCut2x-m_flSecondx)>=0.01){
- m_flFirstxTemp=(m_flFirstx-m_flSecondx)*((float)CurX-flCut2x)/(flCut2x-m_flSecondx)+m_flFirstx;
- }
- if(fabs(flCut2y-m_flSecondy)>=0.01){
- m_flFirstyTemp=(m_flFirsty-m_flSecondy)*((float)CurY-flCut2y)/(flCut2y-m_flSecondy)+m_flFirsty;
- }
- }
- break;
- }
- //CShape::Draw(pDC);
- }
- }
- /////////////////////////////////////////////
- //function Rotate(...)
- //Rotate flAngle degrees around the ptCenter given as a param
- ////////////////////////////////////////////
- void CParallelogram::Rotate(CDC *pDC,float CX,float CY,float flAngle)
- {
- if(m_flScaleTemp!=1){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptRotateCenterTemp=CPoint(CX,CY);
- m_flAngleTemp=flAngle;
- m_bModified=TRUE;
- m_flFirstxTemp=((m_flFirstx-CX)*cos(flAngle)-(m_flFirsty-CY)*sin(flAngle))+CX;
- m_flFirstyTemp=((m_flFirsty-CY)*cos(flAngle)+(m_flFirstx-CX)*sin(flAngle))+CY;
- m_flSecondxTemp=((m_flSecondx-CX)*cos(flAngle)-(m_flSecondy-CY)*sin(flAngle))+CX;
- m_flSecondyTemp=((m_flSecondy-CY)*cos(flAngle)+(m_flSecondx-CX)*sin(flAngle))+CY;
- m_flThirdxTemp=((m_flThirdx-CX)*cos(flAngle)-(m_flThirdy-CY)*sin(flAngle))+CX;
- m_flThirdyTemp=((m_flThirdy-CY)*cos(flAngle)+(m_flThirdx-CX)*sin(flAngle))+CY;
- m_flForthxTemp=((m_flForthx-CX)*cos(flAngle)-(m_flForthy-CY)*sin(flAngle))+CX;
- m_flForthyTemp=((m_flForthy-CY)*cos(flAngle)+(m_flForthx-CX)*sin(flAngle))+CY;
- //Draw(pDC);
- }
- /////////////////////////////////////////////
- //function Magnify(...)
- //Magnify flScale times relative to the ptCenter given as a param
- ////////////////////////////////////////////
- void CParallelogram::Magnify(CDC *pDC,float CX,float CY,float flScale)
- {
- if(m_flAngleTemp!=0){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptMagnifyCenterTemp=CPoint(CX,CY);
- m_flScaleTemp=flScale;
- m_bModified=TRUE;
- m_flFirstxTemp=(m_flFirstx-CX)*flScale+CX;
- m_flFirstyTemp=(m_flFirsty-CY)*flScale+CY;
- m_flSecondxTemp=(m_flSecondx-CX)*flScale+CX;
- m_flSecondyTemp=(m_flSecondy-CY)*flScale+CY;
- m_flThirdxTemp=(m_flThirdx-CX)*flScale+CX;
- m_flThirdyTemp=(m_flThirdy-CY)*flScale+CY;
- m_flForthxTemp=(m_flForthx-CX)*flScale+CX;
- m_flForthyTemp=(m_flForthy-CY)*flScale+CY;
- //Draw(pDC);
- }
- void CParallelogram::TopToBottom(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flFirstyTemp;
- m_flSecondyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flSecondyTemp;
- m_flThirdyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flThirdyTemp;
- m_flFirsty=rect.top/1000.0+rect.bottom/1000.0-m_flFirsty;
- m_flSecondy=rect.top/1000.0+rect.bottom/1000.0-m_flSecondy;
- m_flThirdy=rect.top/1000.0+rect.bottom/1000.0-m_flThirdy;
- m_flForthyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flForthyTemp;
- m_flForthy=rect.top/1000.0+rect.bottom/1000.0-m_flForthy;
- //CShape::Draw(pDC);
- }
- void CParallelogram::LeftToRight(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstxTemp=rect.left/1000.0+rect.right/1000.0-m_flFirstxTemp;
- m_flSecondxTemp=rect.left/1000.0+rect.right/1000.0-m_flSecondxTemp;
- m_flThirdxTemp=rect.left/1000.0+rect.right/1000.0-m_flThirdxTemp;
- m_flFirstx=rect.left/1000.0+rect.right/1000.0-m_flFirstx;
- m_flSecondx=rect.left/1000.0+rect.right/1000.0-m_flSecondx;
- m_flThirdx=rect.left/1000.0+rect.right/1000.0-m_flThirdx;
- m_flForthxTemp=rect.left/1000.0+rect.right/1000.0-m_flForthxTemp;
- m_flForthx=rect.left/1000.0+rect.right/1000.0-m_flForthx;
- //CShape::Draw(pDC);
- }
- ///
- void CParallelogram::RefreshData(bool bRefresh)
- {
- if(bRefresh){
- m_flFirstx = m_flFirstxTemp;
- m_flFirsty = m_flFirstyTemp;
- m_flSecondx = m_flSecondxTemp ;
- m_flSecondy = m_flSecondyTemp;
- m_flThirdx = m_flThirdxTemp;
- m_flThirdy = m_flThirdyTemp;
- m_flForthx = m_flForthxTemp;
- m_flForthy = m_flForthyTemp;
- m_bModified=FALSE;
- m_ptMagnifyCenterTemp=CPoint(0,0);
- m_flScaleTemp=1;
- m_ptRotateCenterTemp=CPoint(0,0);
- m_flAngleTemp=0;
- }
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////
- //function------IsInRect
- //return value
- //0----------out
- //1----------cut
- //2----------in
- /////////////////////////////////////////////
- int CParallelogram::IsInRect(CRect rect)
- {
- int nRltVal=0,nTemp;
- float flForthx,flForthy;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- if((nTemp=GetLineStateToRect(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp,rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp,rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(m_flThirdxTemp,m_flThirdyTemp,flForthx,flForthy,rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(flForthx,flForthy,m_flFirstxTemp,m_flFirstyTemp,rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if(nRltVal==3){
- nRltVal=1;
- }else if(nRltVal==0){
- CPoint pt[4];
- pt[0].x=rect.left;
- pt[0].y=rect.top;
- pt[1].x=rect.right;
- pt[1].y=rect.top;
- pt[2].x=rect.right;
- pt[2].y=rect.bottom;
- pt[3].x=rect.left;
- pt[3].y=rect.bottom;
- if(IsPointinRegion(pt[0])&&IsPointinRegion(pt[1])&&
- IsPointinRegion(pt[2])&&IsPointinRegion(pt[3])&&
- m_nFillStyle==_shape_solid_fill){
- nRltVal=1;
- }
- }
- return nRltVal;
- }
- CRect CParallelogram::GetBoundaryRect()
- {
- CRect rect;
- float flForthx,flForthy;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- rect.left=1000*min(m_flFirstxTemp,min(m_flSecondxTemp,min(m_flThirdxTemp,flForthx)));
- rect.right=1000*max(m_flFirstxTemp,max(m_flSecondxTemp,max(m_flThirdxTemp,flForthx)));
- rect.top=1000*min(m_flFirstyTemp,min(m_flSecondyTemp,min(m_flThirdyTemp,flForthy)));
- rect.bottom=1000*max(m_flFirstyTemp,max(m_flSecondyTemp,max(m_flThirdyTemp,flForthy)));
- return rect;
- }
- CPoint CParallelogram::GetCenterPoint()
- {
- CRect rect=GetBoundaryRect();
- return rect.CenterPoint();
- }
- int CParallelogram::IsPointinRegion(POINT point)
- //方法:
- //通过计算点的右射线与四边形各边(线段)的交点来判断!
- //仅当焦点数为1时,点在四边形内
- {
- int nRltVal=0;
- float flForthx,flForthy;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- //in
- if(point.y>min(m_flFirstyTemp,m_flSecondyTemp)&&point.y<max(m_flFirstyTemp,m_flSecondyTemp))
- {
- if((m_flSecondxTemp-(m_flSecondxTemp-m_flFirstxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flFirstyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flThirdyTemp,m_flSecondyTemp)&&point.y<max(m_flThirdyTemp,m_flSecondyTemp))
- {
- if((m_flSecondxTemp-(m_flSecondxTemp-m_flThirdxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flThirdyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flThirdyTemp,flForthy)&&point.y<max(m_flThirdyTemp,flForthy))
- {
- if((flForthx-(flForthx-m_flThirdxTemp)*(flForthy-point.y)/(flForthy-m_flThirdyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flFirstyTemp,flForthy)&&point.y<max(m_flFirstyTemp,flForthy))
- {
- if((flForthx-(flForthx-m_flFirstxTemp)*(flForthy-point.y)/(flForthy-m_flFirstyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(nRltVal==1){
- return 1;
- }
- //out
- return 0;
- }
- ////////////////
- int CParallelogram::GetPtState(float flx,float fly,float flRate)
- {
- //on out point
- if(IsPtInRect(m_flFirstxTemp-3*flRate,m_flFirstyTemp-3*flRate,m_flFirstxTemp+3*flRate,m_flFirstyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=0;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flSecondxTemp-3*flRate,m_flSecondyTemp-3*flRate,m_flSecondxTemp+3*flRate,m_flSecondyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=1;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flThirdxTemp-3*flRate,m_flThirdyTemp-3*flRate,m_flThirdxTemp+3*flRate,m_flThirdyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=2;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flForthxTemp-3*flRate,m_flForthyTemp-3*flRate,m_flForthxTemp+3*flRate,m_flForthyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=3;
- m_nSelectLineNum=-1;
- return 1;
- }
- //on out line
- if(GetPtStateToBigLine(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=0;
- return 2;
- }
- if(GetPtStateToBigLine(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=1;
- return 2;
- }
- if(GetPtStateToBigLine(m_flThirdxTemp,m_flThirdyTemp,m_flForthxTemp,m_flForthyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=2;
- return 2;
- }
- if(GetPtStateToBigLine(m_flForthxTemp,m_flForthyTemp,m_flFirstxTemp,m_flFirstyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=3;
- return 2;
- }
- //out
- m_nSelectPtNum=-1;
- m_nSelectLineNum=-1;
- return 0;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File
- float CParallelogram::GetSelectLineRate()
- {
- if(m_nSelectLineNum==0||m_nSelectLineNum==2){
- return -GetLineRate(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp);
- }
- if(m_nSelectLineNum==1||m_nSelectLineNum==3){
- return -GetLineRate(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ExPort
- // ABSTRACT :Export to a txt file
- // FUNCTION :File->Export...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // O FILE* outStream Out put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::ExPort(FILE* outStream)//增加导出txt功能时用
- {
- fprintf(outStream, " CParallelogram n");
- CShape::ExPort(outStream);
- fprintf( outStream, "%f %f %f %f %f %fn",m_flFirstxTemp, m_flFirstyTemp, m_flSecondxTemp, m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ImPort
- // ABSTRACT :ImPort from a txt file
- // FUNCTION :File->ImPort...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // I FILE* inStream in put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CParallelogram::ImPort(FILE* inStream)
- {
- CShape::ImPort(inStream);
- fscanf(inStream, "%f %f %f %f %f %f",&m_flFirstx, &m_flFirsty, &m_flSecondx, &m_flSecondy,&m_flThirdx,&m_flThirdy);
- m_flFirstxTemp=m_flFirstx;
- m_flFirstyTemp=m_flFirsty;
- m_flSecondxTemp=m_flSecondx;
- m_flSecondyTemp=m_flSecondy;
- m_flThirdxTemp=m_flThirdx;
- m_flThirdyTemp=m_flThirdy;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- CString CParallelogram::GetNameString()
- {
- CString str;
- str.LoadString(IDS_PARALLELOGRAM);
- return str;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File//////////////////////