⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawview.cpp

📁 希望大家多多交流
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				index=31;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			
			}
			break;
	case 31:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint2=point;
				haveselectpoint=2;//设置选中一个点标识
				index=32;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			}
			break;
	case 32:{tonearbypoint(point);//转移到己有的邻近点上
			CPoint oncircle;
			oncircle.x=point.x+selectpoint1.x-selectpoint2.x;
			oncircle.y=point.y+selectpoint1.y-selectpoint2.y;
			pDoc->mygraph.AddTail(thegraph(point,oncircle,3));
			index=30;
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 40:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint1=point;
				haveselectpoint=1;//设置选中一个点标识
				index=41;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
						
			}
			break;
	case 41:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint2=point;
				POSITION pos;
				if(isaobject(selectpoint1,selectpoint2,2, pos))//选择的两点是否确定一条线段
					{haveselectpoint=2;//设置选中一个点标识
					index=42;
					}
				else 
					{AfxMessageBox("你必须选择同一条直线上的点!",MB_ICONERROR);
					index=50;
					haveselectpoint=0;
					}
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			}
			break;
	case 42:{tonearbypoint(point);//转移到己有的邻近点上
			int A=(selectpoint2.x-selectpoint1.x)*(selectpoint2.x-selectpoint1.x);
			int B=(selectpoint2.y-selectpoint1.y)*(selectpoint2.y-selectpoint1.y);
			int C=(selectpoint2.x-selectpoint1.x)*(selectpoint2.y-selectpoint1.y);
			CPoint temp;//垂足
			temp.x=(C*point.y+A*point.x+B*selectpoint1.x-C*selectpoint1.y)/(A+B);
			temp.y=(C*point.x+B*point.y+A*selectpoint1.y-C*selectpoint1.x)/(A+B);
			pDoc->mygraph.AddTail(thegraph(point,temp,2));
			POSITION pos;//以下加上由垂足分成的两条线段
			if(isaobject(selectpoint1,selectpoint2,2, pos))
				{pDoc->mygraph.AddTail(thegraph(selectpoint1,temp,2));
				 pDoc->mygraph.AddTail(thegraph(selectpoint2,temp,2));
				};
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			index=40;
			haveselectpoint=0;
			}
			break;
	case 50:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint1=point;
				haveselectpoint=1;//设置选中一个点标识
				index=51;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			
			}
			break;
	case 51:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint2=point;
				POSITION pos;
				if(isaobject(selectpoint1,selectpoint2,2, pos))//选择的两点确定一条线段则延长它
					{haveselectpoint=2;//设置选中一个点标识
					index=52;
					}
				else 
					{AfxMessageBox("你必须选择同一条直线上的点!",MB_ICONERROR);
					index=50;
					haveselectpoint=0;
					}
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			}
			break;
	case 52:{tonearbypoint(point);//转移到己有的邻近点上
			CPoint temp=point+selectpoint1-selectpoint2;
			pDoc->mygraph.AddTail(thegraph(point,temp,2));
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			index=50;
			haveselectpoint=0;
			}
			break;
	case 60:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint1=point;
				haveselectpoint=1;//设置选中一个点标识
				index=61;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			
			}
			break;
	case 61:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint2=point;
				POSITION pos;
				index=60;
				haveselectpoint=0;
				if(isaobject(selectpoint1,selectpoint2,2, pos))//选择的两点确定一条线段则延长它
					{thegraph& pthegraph=pDoc->mygraph.GetAt(pos);
					CPoint point1=pthegraph.point1;
					CPoint point2=pthegraph.point2;
					pthegraph.point1.x=point1.x+point1.x-point2.x;
					pthegraph.point2.x=point2.x-point1.x+point2.x;
					pthegraph.point1.y=point1.y+point1.y-point2.y;
					pthegraph.point2.y=point2.y-point1.y+point2.y;					
					}
				else AfxMessageBox("你必须选择同一条直线上的点!",MB_ICONERROR);					
				pDoc->UpdateAllViews(NULL);//去显示延长了的线段
				}
			}
			break;
	case 70:{tonearbypoint(point);//转移到己有的邻近点上	
			pDoc->mygraph.AddTail(thegraph(point));
			pDoc->mygraph.GetTail().type=1;
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 80:break;
	case 90:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint1=point;
				haveselectpoint=1;//设置选中一个点标识
				index=91;
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			
			}
			break;
	case 91:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint2=point;
				POSITION pos,pos1,pos2,pos3;
				if(isaobject(selectpoint1,selectpoint2,2, pos2)\
					||isaobject(selectpoint1,selectpoint2,3, pos3)\
					||isaobject(selectpoint1,selectpoint2,1, pos1))//选择的两点确定一条线段或一个圆或一个点
					{haveselectpoint=2;//设置选中两个点标识
					index=90;
					if(isaobject(selectpoint1,selectpoint2,2, pos2)\
					&&isaobject(selectpoint1,selectpoint2,3, pos3))//如果同时选中一条直线和一个圆
						 {if(AfxMessageBox("你必须确定你选择的是圆还是直线,在此选择并删除它们中的一个。(确定为直线,取消为圆)",MB_OKCANCEL)==IDOK)
							{pDoc->mygraph.RemoveAt(pos2);
							index=90;
							haveselectpoint=0;
							pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
							pDoc->UpdateAllViews(NULL);							
							}
						 else{pDoc->mygraph.RemoveAt(pos3);//选择取消则删除圆
							index=90;
							haveselectpoint=0;
							pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
							pDoc->UpdateAllViews(NULL);
							 }
						 }
					else {if(AfxMessageBox("你己经选定了一个对象,你确定要删除它吗?",MB_OKCANCEL)==IDOK)
							{if(isaobject(selectpoint1,selectpoint2,2, pos2))pos=pos2;
							if(isaobject(selectpoint1,selectpoint2,3, pos3))pos=pos3;
							if(isaobject(selectpoint1,selectpoint2,1, pos1))pos=pos1;
							pDoc->mygraph.RemoveAt(pos);
							index=90;
							haveselectpoint=0;
							pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
							pDoc->UpdateAllViews(NULL);
							}
						else{AfxMessageBox("你己经取消了操作,请重新开始选择。");
							index=90;
							haveselectpoint=0;
							}
						 }
					}
				else 
					{AfxMessageBox("你选择的两点不能确定一个图形对象,请重新开始选择!",MB_ICONERROR);
					index=90;
					haveselectpoint=0;
					}
				pDoc->UpdateAllViews(NULL);//去显示被选中的点
				}
			}
			break;
	default:break;
	}
	CView::OnLButtonUp(nFlags, point);
	}
}
bool CDrawView::tonearbypoint(CPoint& point)
{//如果点击的是一个很接近己有点的点,则修正此点为己有点
	CDrawDoc* pDoc = GetDocument();
	POSITION pos = pDoc->mygraph.GetHeadPosition();
	for (int i=0;i < pDoc->mygraph.GetCount();i++)
	{
	thegraph& pthegraph=pDoc->mygraph.GetNext(pos);
	switch(pthegraph.type)
	{
	case 1:if(abs(pthegraph.point1.x-point.x)<4&&abs(pthegraph.point1.y-point.y)<4){point=pthegraph.point1;return TRUE;}break;
	case 2:
	case 3:if(abs(pthegraph.point1.x-point.x)<4&&abs(pthegraph.point1.y-point.y)<4){point=pthegraph.point1;return TRUE;}
		if(abs(pthegraph.point2.x-point.x)<4&&abs(pthegraph.point2.y-point.y)<4){point=pthegraph.point2;return TRUE;}break;
	case 4:if(abs(pthegraph.point1.x-point.x)<4&&abs(pthegraph.point1.y-point.y)<4){point=pthegraph.point1;return TRUE;}
		if(abs(pthegraph.point2.x-point.x)<4&&abs(pthegraph.point2.y-point.y)<4){point=pthegraph.point2;return TRUE;}
		if(abs(pthegraph.point3.x-point.x)<4&&abs(pthegraph.point3.y-point.y)<4){point=pthegraph.point3;return TRUE;}break;
	default:return FALSE;
	}

	}
	return FALSE;

}


void CDrawView::OnZoomup() 
{
	// TODO: Add your command handler code here
	
	if(zoomnum<12)
	{zoomnum++;
	CDrawDoc* pDoc = GetDocument();
	pDoc->windowsSize=CSize(pDoc->windowsSize.cx+512,pDoc->windowsSize.cy+384);
	SetScrollSizes(MM_TEXT,pDoc->windowsSize);
	}
	else MessageBox("现在己经是最大纸张了!");
}

void CDrawView::OnViewQuestion() 
{
	// TODO: Add your command handler code here
	QuestionDialog questiondialog;
	CDrawDoc* pDoc = GetDocument();
	questiondialog.m_question=pDoc->question;
	if(questiondialog.DoModal()==IDOK)pDoc->question=questiondialog.m_question;	//注意:如果
	//修改了题目又要保存的话,应该在退出程序的时候选择保存。如果仅修改了题目而没作图,程序是
	//不会提示你保存的。

}

void CDrawView::OnViewShrink() 
{
	// TODO: Add your command handler code here
	SetScaleToFitSize(GetTotalSize());
	fitsize=TRUE;//标示进入缩小视图
	
}

void CDrawView::displayselectpoint(CPoint& point,CDC* pDC)
{//显示被选中的点,即画四个红色小竖条
	CPen newpen(PS_SOLID,0,0x000000ff);
	CPen* oldpen=pDC->SelectObject(&newpen);
	pDC->MoveTo(point.x+6,point.y);
	pDC->LineTo(point.x+2,point.y);
	pDC->MoveTo(point.x-6,point.y);
	pDC->LineTo(point.x-2,point.y);
	pDC->MoveTo(point.x,point.y-6);
	pDC->LineTo(point.x,point.y-2);
	pDC->MoveTo(point.x,point.y+6);
	pDC->LineTo(point.x,point.y+1);
	pDC->SelectObject(oldpen);
}

bool CDrawView::isaobject(CPoint& point1,CPoint& point2,int type,POSITION& pos)
{//判定point1与point2是否确定一个类型为type的对象,并将位置存于pos中
	CDrawDoc* pDoc = GetDocument();
	pos = pDoc->mygraph.GetHeadPosition();
	for (int i=0;i < pDoc->mygraph.GetCount();i++)
	{
	thegraph& pthegraph=pDoc->mygraph.GetNext(pos);
	if((pthegraph.point1==point1||pthegraph.point2==point1||pthegraph.point3==point1)\
		&&(pthegraph.point1==point2||pthegraph.point2==point2||pthegraph.point3==point2)\
		&&(point1!=point2)&&pthegraph.type==type)//如果两点都是一个图形对象中的点并且类型一致
		{if(pos==NULL)pos = pDoc->mygraph.GetTailPosition();
		else thegraph& pthegraph=pDoc->mygraph.GetPrev(pos);
		return true;
		}
	if((type==1)&&(point1==point2)&&(pthegraph.point1==point1))//如果选择的是一个点
		{if(pos==NULL)pos = pDoc->mygraph.GetTailPosition();
		else thegraph& pthegraph=pDoc->mygraph.GetPrev(pos);
		return true;
		}
	}
	return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -