📄 direction2view.cpp
字号:
CDirection2Doc* pDoc = GetDocument(); //得到文档类对象的指针
num = pDoc->GetDrawnum();
for(int i=num-1;i>=0;i--)
{
pDraw = pDoc->GetDraw(i);
CRect rect = pDraw ->GetDimRect();
CDirection2App *pApp = (CDirection2App *) AfxGetApp();
if(rect.PtInRect(point)) //为矩形内
{
if( pDraw->Gettype() == 1)
{
//对象为直线时,显示直线属性对话框
pLine=(CLine *)pDoc->GetDraw(i); //得到直线对象
double zhi=pLine->GetZhi();
m_lineset->Updatelinedata(pLine->m_linecolor,pLine->m_color,
pLine->m_text,pLine->linewidth,
zhi,pLine->m_name,pLine->m_linestyle);
m_lineset->ShowWindow(SW_SHOW);
}
else if(pDraw->Gettype() == 2)
{//对象为矩形时,显示矩形属性对话框
Rectf1=(CRectFill *)pDoc->GetDraw(i); //得到直线对象
double zhi2=Rectf1->GetZhi();
//int m_width,m_height; //图形的长宽
// COLORREF m_rectcolor;
// COLORREF m_rectfillcolor;
m_rectset->updaterectdata(Rectf1->m_rectfillcolor,Rectf1->m_rectcolor,
Rectf1->m_color,Rectf1->m_text,
zhi2,Rectf1->m_height,
Rectf1->m_width,Rectf1->m_name);
m_rectset->ShowWindow(SW_SHOW);
}
else if(pDraw->Gettype() == 3)
{//对象为文字时,显示文字属性对话框
text=(CText *)pDoc->GetDraw(i); //得到文字对象
}
break ; // 假如有重叠的,则只能设计其中的一个 。
}
}
CScrollView::OnLButtonDblClk(nFlags, point);
}
void CDirection2View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
//通过按下 DEL键来删除相应的选择的 对象
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CDirection2View::OnShuxing()
{
// TODO: Add your command handler code here
//用于查看修改对象的属性,当前为跳出相关对象的属性窗口
CDirection2Doc* pDoc = GetDocument();
CBasepic *pDraw;
CLine *pLine ;
CRectFill *Rectf1;
if(selectindex!=-1)
{
pDraw=pDoc->GetDraw(selectindex);
if( pDraw->Gettype() == 1)
{
//对象为直线时,显示直线属性对话框
pLine=(CLine *)pDraw; //得到直线对象
double zhi=pLine->GetZhi();
m_lineset->Updatelinedata(pLine->m_linecolor,pLine->m_color,
pLine->m_text,pLine->linewidth,
zhi,pLine->m_name,pLine->m_linestyle);
m_lineset->SetIndex(selectindex);
m_lineset->ShowWindow(SW_SHOW);
}
else if(pDraw->Gettype() == 2)
{//对象为矩形时,显示矩形属性对话框
Rectf1=(CRectFill *)pDraw; //得到对象
double zhi2=Rectf1->GetZhi();
//int m_width,m_height; //图形的长宽
// COLORREF m_rectcolor;
// COLORREF m_rectfillcolor;
m_rectset->updaterectdata(Rectf1->m_rectfillcolor,Rectf1->m_rectcolor,
Rectf1->m_color,Rectf1->m_text,
zhi2,Rectf1->m_height,
Rectf1->m_width,Rectf1->m_name);
m_rectset->SetIndex(selectindex);
(m_rectset->m_over).SetCheck(false);
(m_rectset->m_begin).SetCheck(false);
if(selectindex==m_begin)
(m_rectset->m_begin).SetCheck(true);//表明这是起点
if(selectindex==m_last) //表明这是终点
(m_rectset->m_over).SetCheck(true);
m_rectset->ShowWindow(SW_SHOW);
}
else if(pDraw->Gettype() == 3)
{//对象为文字时,显示文字属性对话框
}
}
else
MessageBox("请你选择要查看属性的对象!","提示" ,MB_OKCANCEL);
}
void CDirection2View::OnLook()
{
// TODO: Add your command handler code here
//查看对象的属性 与 onshuxing 相同
OnShuxing();
}
void CDirection2View::OnShanchu112()
{
// TODO: Add your command handler code here
///这里是用于设计删除选择的对象用
}
void CDirection2View::OnFanhui()
{
// TODO: Add your command handler code here
///这是用于撤销,返回原来操作用的
}
void CDirection2View::OnSetbedin()
{
// TODO: Add your command handler code here
///用于快速设计起始点
CDirection2Doc* pDoc = GetDocument();
if(((CBasepic *)pDoc->GetDraw(selectindex))->Gettype()==2)
m_begin=selectindex; //最短路径的起点
}
void CDirection2View::OnSetlast()
{
// TODO: Add your command handler code here
///用于快速设计结束点
CDirection2Doc* pDoc = GetDocument();
if(((CBasepic *)pDoc->GetDraw(selectindex))->Gettype()==2)
m_last=selectindex; //最短路径的起点
}
void CDirection2View::OnBegin22()
{
// TODO: Add your command handler code here
if(m_begin==-1 || m_last==-1)
return;
//开始求解最短路径,开始按钮
//佛洛伊德算法
int v,w,u,n;
int bpoint=0;
int lpoint=0; //存放起点和终点在,存储数组中的索引
CString beginname; //放起点和终点的名字
CString lastname;
// LinkList rectlist;
// Lnode *s;
// rectlist=NULL;
int rect[MAXSIDE]; //定义一个可容下最大个数的矩形索引数组
CBasepic *basepicture;
CRectFill *vrectfill;
CRectFill *wrectfill;
CDirection2Doc* pDoc = GetDocument();
n=pDoc->GetDrawnum(); //得到所有对象的总数
w=0;
beginname=((CRectFill *)pDoc->GetDraw(m_begin))->m_name; //放起点和终点的名字
lastname=((CRectFill *)pDoc->GetDraw(m_last))->m_name;
for(v=0;v<n;v++)
{
basepicture=(CBasepic *)pDoc->GetDraw(v); //得到对象
if(basepicture->Gettype()==2) //如果为矩形
{
// s=new Lnode;
// s->data=v;
// s->next=rectlist;
// rectlist=s;
if(w<MAXSIDE)
{ rect[w]=v;
if(v==m_begin)
bpoint=w;
if(v==m_last)
lpoint=w;
w++;
}
}
}
n=w; //得到矩形对象的个数
CLine *linelist;
int P[MAXSIDE][MAXSIDE]; //保存v点到w点最短路径,的w点的前驱节点
long D[MAXSIDE][MAXSIDE]; //保存v点到w点的最短距离,为双精度
int wlineindex=0;
int vlineindex=0;
int vlinenum; //两点相关直线的数目
int wlinenum;
int vdata;
int wdata;
int vi=0;//用于求直接路径长度的循环
int wi=0;
BOOL flag=false;
for(v=0;v<n;++v)
{
vdata = rect[v]; //得到V 点的索引
// vrectfill=(CRectFill *)pDoc->GetDraw(v); //得到v 点对象
vrectfill=(CRectFill *)pDoc->GetDraw(vdata);
vlinenum = vrectfill->Getlinenum(); //得到相关直线数目
for(w=0;w<n;++w)
{
//计算v 点 到 w 点 的直接距离
if(v!=w)
{
wdata = rect[w]; //得到w 点的索引
wrectfill=(CRectFill *)pDoc->GetDraw(wdata); //得到w 点对象
wlinenum =wrectfill->Getlinenum(); //得到相关直线数目
for( vi=0;vi<vlinenum;vi++) //用于获取存在直接路径的路径,长度
for( wi=0;wi<wlinenum;wi++)
{
vlineindex=vrectfill->Getline(vi);
wlineindex=wrectfill->Getline(wi);
if(vlineindex==wlineindex) //两点间存在直接路径
{
linelist = (CLine *)pDoc->GetDraw(vlineindex);//得到该相关直线对象
D[v][w] = linelist->GetZhi(); // 求v 和 w 点的 直接距离,如果没有,则为 无穷大的数
goto last;
}
else
D[v][w] = 1000000000;
}
}
else
D[v][w] =0;
//如果没有 直接路径 D[v][w] 的值应为 ???双精度的最大值 1.7e308 此值应注意防止在此系统中出现
last: //跳出那些循环
if(D[v][w] < 2100000000) //如果v 到 w 点有直接路径,则
P[v][w]=v;
else
if(v!=w)
P[v][w]=-2;
else
P[v][w]=-1;
}
}
for(u=0;u<n;++u)
for(v=0;v<n;++v)
for(w=0;w<n;++w)
if(D[v][u]+D[u][w]<D[v][w])
{
D[v][w]=D[v][u]+D[u][w];
P[v][w]=u;
}
///最短路径求解完毕,下面为显示所求得的最短路径。
//存放起点和终点在,存储数组中的索引 bpoint,lpoint
//显示最短路径的走法
((CRectFill *)pDoc->GetDraw( rect[bpoint]))->Setselete(true);
((CRectFill *)pDoc->GetDraw( rect[lpoint]))->Setselete(true);
int a[MAXSIDE] ; //放路径点中的数组索引
int indexp;
int indexp1;
a[0]=P[bpoint][lpoint];
for(int ji=0;ji<n;ji++) ////设计该点被选中
{
indexp1=a[ji];
a[ji+1]=P[bpoint][indexp1];
indexp=a[ji+1];
if(indexp == -1 )
break;
((CRectFill *)pDoc->GetDraw( rect[indexp]))->Setselete(true);
}
///刷新屏幕
CClientDC ClientDC(this);
OnPrepareDC(&ClientDC);
ClientDC.SelectObject(&m_PenDotted);
ClientDC.SetROP2(R2_NOT);
ClientDC.SetBkMode(TRANSPARENT);
ClientDC.SelectStockObject(NULL_BRUSH);
ClientDC.SetROP2(R2_COPYPEN);
this->Invalidate();
OnDraw(&ClientDC);
//最短距离为 D[bpoint][lpoint]
CString szstring;
szstring.Format("(%d)",D[bpoint][lpoint] );
//beginname; //放起点和终点的名字
//lastname;
MessageBox(beginname + _T("--到--")+ lastname + _T( "最短距离为:")+szstring,"最短路径为……" ,MB_OKCANCEL);
}
void CDirection2View::OnUpdateBegin22(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CDirection2View::WriteText(WPARAM wParam ,LPARAM lParam)
{
CString str;
CBasepic *pDraw;
CPoint point1;
COLORREF TextColor; //字体颜色
LOGFONT text; //字体式样
CClientDC ClientDC(this);
OnPrepareDC(&ClientDC);
CDirection2Doc* pDoc = GetDocument();
str=m_textset->m_Word;
point1=m_textset->m_textpoint;
ClientDC.DPtoLP(&point1);
TextColor=m_textset->m_textcolor;
text=m_textset->m_text;
//函数格式CText(int x1,int y1,CString name,LOGFONT text,COLORREF color)
(CBasepic *) pDraw = new CText(point1.x,point1.y,
str,text,TextColor);
ClientDC.SetROP2(R2_COPYPEN);
pDoc -> AddDraw(pDraw);
pDraw->Draw(&ClientDC);
pDoc->UpdateAllViews(this,0,pDraw);
///刷新屏幕
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -