📄 gdrawview.cpp
字号:
// GDrawView.cpp : CGDrawView 类的实现
//
#include "stdafx.h"
#include "GDraw.h"
#include "GDrawDoc.h"
#include "GDrawView.h"
#include <math.h>
#include "SetLine.h"
#include "FilSet.h"
#include <gdiplus.h>
using namespace Gdiplus;
#include <math.h>
#include <stack>
#include <queue>
using namespace std;
#include"BgInfos.h"
#include"LinePro2.h"
#include"MainFrm.h"
#include"Circle.h"
#include"CirclePro.h"
#include"PolPro.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CGDrawView
IMPLEMENT_DYNCREATE(CGDrawView, CScrollView)
BEGIN_MESSAGE_MAP(CGDrawView, CScrollView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CScrollView::OnFilePrintPreview)
ON_COMMAND(32773, &CGDrawView::On32773)
ON_COMMAND(ID_CCLE, &CGDrawView::OnCircle)
ON_COMMAND(ID_SELECT, &CGDrawView::OnSelectGraph)
ON_COMMAND(ID_SETFIL, &CGDrawView::OnSetfil)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_Save, &CGDrawView::OnSave)
// ON_COMMAND(ID_AllSave, &CGDrawView::OnAllsave)
ON_COMMAND(ID_HIDE, &CGDrawView::OnHide)
ON_UPDATE_COMMAND_UI(ID_HIDE, &CGDrawView::OnUpdateHide)
ON_COMMAND(ID_BUTTON32791, &CGDrawView::OnLine)
ON_COMMAND(ID_BREAKLS, &CGDrawView::On_BreakLS)
ON_WM_ERASEBKGND()
ON_WM_SETCURSOR()
ON_COMMAND(32775, &CGDrawView::On32775)
ON_WM_LBUTTONDBLCLK()
ON_WM_MOUSEWHEEL()
ON_COMMAND(ID_RAILWAY, &CGDrawView::OnRailway)
END_MESSAGE_MAP()
// CGDrawView 构造/析构
CGDrawView::CGDrawView() :FillColor(255,255,0),pen(Color::Black )
,LBDown(0),Move(0)
{
// TODO: 在此处添加构造代码
init();
click_flag = 0;
}
CGDrawView::~CGDrawView()
{
while(!m_graphlist.empty ())
m_graphlist.pop_back ();
}
BOOL CGDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CScrollView::PreCreateWindow(cs);
}
// CGDrawView 绘制
void CGDrawView::init()
{
gp=NULL;
tmpgp=NULL;
docgp=NULL;
tmppre=NULL;
m_ptrGL=NULL;
m_LButton=0;
select=0;
hide=0;
//test=L"";
m_csFileName=L"";
whichshow=0;
bg_color=RGB(255,255,255);
isset=FALSE;
dline=0;
click=FALSE;
first_draw=TRUE;
breakline=0;
update=true;
type=0;
isupdate=0;
rail=ctl=0;
//填 充变量初始化
fillset=0;
settop=0;
start_point.x=start_point.y=0;
fill_choice=FALSE;
choice=true;
isdraw=FALSE;
editpnt=FALSE;
width=1024;
height=768;
}
void CGDrawView::OnDraw(CDC* pDC)
{
CGDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
/*//Point p2p[10]={Point(20,20),Point(342,123),Point(99,120),
//Point(265,76),Point(73,310),Point(420,290),Point(510,69 ),Point(230,110),Point(20,80),Point(77,240)};
Point p2p[3] = {Point(100,100), Point(200,200), Point(200,100)};
Point p2pp[7] = {Point(300,100), Point(400,200), Point(400,100),Point(450,100), Point(500,350), Point(600,500),Point(100,501)};
DrawTracks(pDC,p2p,3,Color::Red ,Color::Red );
//DrawTracks(pDC,p2pp,7,Color::Red ,Color::Red );
Graphics gp(pDC->m_hDC );
//DrawBZ(pDC,p2p,3,Color::Red ,Color::Red);
//DrawBSample(pDC,p2pp,7,Color::Red ,Color::Red);
gp.DrawLines (&Pen(Color::Green ),p2p,3);*/
if( pDoc->size)
{
init();
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
MainFrame->m_wndSplitter.DeleteView(1,0);
MainFrame->m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(BgInfos),CSize(400,10),NULL);
MainFrame->m_wndSplitter.RecalcLayout();
BgInfos* bg=(BgInfos*)MainFrame->m_wndSplitter.GetPane(1,0);
CWnd *pWnd=bg->GetDlgItem(IDC_BG);
CDC *pDC=pWnd->GetDC ();
pDC->FillRect (CRect(1,1,89,46),&CBrush(bg_color));
ReleaseDC(pDC);
bg->SetDlgItemInt(IDC_WIDTH,width);
bg->SetDlgItemInt(IDC_HEIGHT,height);
while(!m_graphlist.empty ())
m_graphlist.pop_back ();
while(!ptr_point.empty ())
m_graphlist.pop_back ();
bg_color=pDoc->bg_color;
width=pDoc->width;
height=pDoc->height;
CSize sizeTotal;
sizeTotal.cx=width;
sizeTotal.cy=height;
/* CString str;
str.Format(L"%d %d",width,height);
MessageBox(str);*/
UpdateData(true);
SetScrollSizes(MM_TEXT,sizeTotal);
bg->SetDlgItemInt(IDC_WIDTH,width);
bg->SetDlgItemInt(IDC_HEIGHT,height);
isset=1;
for( int i=0;i<pDoc->size;i++)
{
int p_num=pDoc->ptr[i].count;
CPoint *spp=new CPoint[p_num+1];
for( int j=0;j<p_num;j++)
{
/* spp[j].x=pDoc->ptr[i].p[j].x;
spp[j].y=pDoc->ptr[i].p[j].y;*/
spp[j]=pDoc->ptr[i].p[j];
}
Graph_Union ss(pDoc->ptr[i].type,p_num,pDoc->ptr[i].wide,pDoc->ptr[i].shape,spp,pDoc->ptr[i].colors,pDoc->ptr[i].fill_color);
m_graphlist.push_back(ss);
delete []spp;
delete []pDoc->ptr[i].p;
}
pDoc->size=0;
delete []pDoc->ptr;
}
if(isupdate==0 )
{
OnAllsave();
isupdate=1;
}
else ShowGraph(pDC);
}
// CGDrawView 打印
BOOL CGDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CGDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CGDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清除过程
}
// CGDrawView 诊断
#ifdef _DEBUG
void CGDrawView::AssertValid() const
{
CScrollView::AssertValid();
}
void CGDrawView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CGDrawDoc* CGDrawView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDrawDoc)));
return (CGDrawDoc*)m_pDocument;
}
#endif //_DEBUG
// CGDrawView 消息处理程序
void CGDrawView::On32773()
{
// TODO: 在此添加命令处理程序代码
dline=0;
breakline=0;
select=0;
fillset=0;
CSetLine csl;
// int x1,x2,y1,y2,lf,size;
if(csl.DoModal ()==IDOK)
{
CPoint p[2]={CPoint(csl.m_x1 ,csl.m_y1 ),CPoint(csl.m_x2,csl.m_y2)};
Graph_Union line(0,2,csl.m_size ,csl.m_lf ,p,csl.color.ToCOLORREF (),csl.color.ToCOLORREF ());
m_graphlist.push_back (line);
CPoint a=p[0],b=p[1];
CClientDC dc(this);
OnPrepareDC(&dc);
dc.LPtoDP(&a);
dc.LPtoDP(&b);
DrawLine(GetDC(),a.x,a.y,b.x,b.y,line.color ,line.shape ,line.wide );
}
}
void CGDrawView::getrect(Gdiplus::Point &b, Gdiplus::Point &e, CPoint *p)
{
double dx=b.X-e.X ,dy=b.Y-e.Y ;
double r=sqrt(dx*dx+dy*dy);
double sin_a=dy/r;
double cos_a=dx/r;
double xx= sin_a*8;
double yy= cos_a*8;
int x=(int)xx;
int y=(int)yy;
p[0].x=b.X -x;p[0].y =b.Y -y;
p[1].x=b.X +x;p[1].y =b.Y +y;
if(cos_a>=0)
{
p[2].x=e.X +x;p[2].y =e.Y +y;
p[3].x =e.X-x;p[3].y =e.Y -y;
}
else
{
p[2].x=e.X +x;p[2].y =e.Y -y;
p[3].x =e.X-x;p[3].y =e.Y +y;
}
}
void CGDrawView::ShowGraph(CDC *pDC)
{
list<Graph_Union>::iterator w;
for(w=m_graphlist.begin ();w!=m_graphlist.end();w++)
{
ShowGU(pDC,*w);
}
}
void CGDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认
click_flag = 1;
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if( choice && isdraw )
{
editpnt=TRUE;
SetCapture();
return ;
}
if( dline || breakline )
{
click_down=point;
click=TRUE;
first_draw=TRUE;
SetCapture();
}
else if( fillset )
{
int a=0;
}
else
{
UpdateData(true);
int ishave=0;
//CScrollView::OnLButtonDown(nFlags, point);
list<Graph_Union>::iterator w;
for(w=m_graphlist.begin ();w!=m_graphlist.end();w++)
{
if(w->type==0)
{
int minx=(w->pp[0].x>w->pp[1].x)?w->pp[1].x:w->pp[0].x;
int miny=(w->pp[0].y>w->pp[1].y)?w->pp[1].y:w->pp[0].y;
int maxx=(w->pp[0].x<w->pp[1].x)?w->pp[1].x:w->pp[0].x;
int maxy=(w->pp[0].y<w->pp[1].y)?w->pp[1].y:w->pp[0].y;
if( minx<point.x && miny<point.y && maxx>point.x && maxy>point.y )
{
CDC* pDC=GetDC();
CPoint a=CPoint(minx,miny);
CPoint b=CPoint(maxx,maxy);
dc.LPtoDP(&a);
dc.LPtoDP(&b);
CRect rect(a.x,a.y,b.x,b.y);
m_ptrGL=w;
m_LButton=1;
ishave=1;
start_point=point;
select=1;
type=0;
pDC->DrawFocusRect(rect);
ReleaseDC(pDC);
SetCapture();
goto f1;
}
}
else if( w->type==1)
{
int x=w->pp[0].x;
int y=w->pp[0].y;
int size=w->wide;
COLORREF col=w->color;
int r=w->shape;
if( abs(point.x-x)<r+size && abs(point.y-y)<size+r )
{
CDC *PDC=GetDC();
CPoint a=CPoint(x-r-size,y-r-size);
CPoint b=CPoint(x+r+size,y+r+size);
dc.LPtoDP(&a);
dc.LPtoDP(&b);
CRect rect(a.x,a.y,b.x,b.y);
PDC->DrawFocusRect(rect);
ReleaseDC(PDC);
m_ptrGL=w;
m_LButton=1;
ishave=1;
start_point=point;
select=1;
type=1;
SetCapture();
goto f1;
}
}
else if( w->type==2)
{
int minx,miny,maxx,maxy;
minx=maxx=w->pp[0].x;
miny=maxy=w->pp[0].y;
for( int s=1;s<w->count;s++)
{
if( minx>w->pp[s].x ) minx=w->pp[s].x;
if( maxx<w->pp[s].x ) maxx=w->pp[s].x;
if( miny>w->pp[s].y ) miny=w->pp[s].y;
if( maxy<w->pp[s].y ) maxy=w->pp[s].y;
}
fill_choice=FALSE;
if( point.x>minx && point.x<maxx && point.y>miny && point.y<maxy )
{
fill_choice=TRUE;
type=2;
m_ptrGL=w;
ishave=1;
// MessageBox(L"choice");
CPoint a=CPoint(minx,miny);
CPoint b=CPoint(maxx,maxy);
dc.LPtoDP(&a);
dc.LPtoDP(&b);
CRect rect(a.x,a.y,b.x,b.y);
CDC*pDC=GetDC();
pDC->DrawFocusRect(rect);
ReleaseDC(pDC);
start_point=point;
SetCapture();
goto f1;
}
}
else if( w->type==3)
{
int minx,miny,maxx,maxy;
minx=maxx=w->pp[0].x;
miny=maxy=w->pp[0].y;
for( int s=1;s<w->count;s++)
{
if( minx>w->pp[s].x ) minx=w->pp[s].x;
if( maxx<w->pp[s].x ) maxx=w->pp[s].x;
if( miny>w->pp[s].y ) miny=w->pp[s].y;
if( maxy<w->pp[s].y ) maxy=w->pp[s].y;
}
fill_choice=FALSE;
if( point.x>minx && point.x<maxx && point.y>miny && point.y<maxy )
{
fill_choice=TRUE;
type=3;
m_ptrGL=w;
ishave=1;
// MessageBox(L"choice");
CPoint a=CPoint(minx,miny);
CPoint b=CPoint(maxx,maxy);
dc.LPtoDP(&a);
dc.LPtoDP(&b);
CRect rect(a.x,a.y,b.x,b.y);
CDC*pDC=GetDC();
pDC->DrawFocusRect(rect);
ReleaseDC(pDC);
select=1;
start_point=point;
SetCapture();
goto f1;
}
}
}
m_LButton=0;
m_ptrGL=NULL;
select=0;
f1:
if( !hide )
{
if( !ishave )
{
select=0;
if( whichshow )
{
/* CDC *pdc=GetDC();
deletepoint(pdc, *tmppre);
ReleaseDC(pdc);*/
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
MainFrame->m_wndSplitter.DeleteView(1,0);
MainFrame->m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(BgInfos),CSize(400,10),NULL);
MainFrame->m_wndSplitter.RecalcLayout();
BgInfos* bg=(BgInfos*)MainFrame->m_wndSplitter.GetPane(1,0);
CWnd *pWnd=bg->GetDlgItem(IDC_BG);
CDC *pDC=pWnd->GetDC ();
pDC->FillRect (CRect(1,1,89,46),&CBrush(bg_color));
ReleaseDC(pDC);
whichshow=0;
bg->SetDlgItemInt(IDC_WIDTH,width);
bg->SetDlgItemInt(IDC_HEIGHT,height);
}
}
else
{
if( type==0)
{
select=1;
if( !whichshow || whichshow==2 || whichshow==3)
{
/* CDC *pdc=GetDC();
if( update )
update=false;
else
deletepoint(pdc,*tmppre);
ShowGU(pdc,*m_ptrGL,RGB(255,0,0));
ReleaseDC(pdc);*/
tmppre=m_ptrGL;
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
MainFrame->m_wndSplitter.DeleteView(1,0);
MainFrame->m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(LinePro2),CSize(400,10),NULL);
MainFrame->m_wndSplitter.RecalcLayout();
LinePro2 *line2=(LinePro2*)MainFrame->m_wndSplitter.GetPane(1,0);
choice=1;
whichshow=1;
}
}
else if( type==1)
{
select=1;
if( !whichshow || whichshow==1 ||whichshow==3 )
{
tmppre=m_ptrGL;
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
MainFrame->m_wndSplitter.DeleteView(1,0);
MainFrame->m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CCirclePro),CSize(400,10),NULL);
MainFrame->m_wndSplitter.RecalcLayout();
whichshow=2;
}
}
else if( type==2 || type==3)
{
select=1;
tmppre=m_ptrGL;
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
MainFrame->m_wndSplitter.DeleteView(1,0);
MainFrame->m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CPolPro),CSize(400,10),NULL);
MainFrame->m_wndSplitter.RecalcLayout();
whichshow=3;
//MessageBox(L"OK");
}
}
}
}
}
void CGDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if( !whichshow )
{
CMainFrame* MainFrame = (CMainFrame*)AfxGetMainWnd();
BgInfos *mouse=(BgInfos*) MainFrame->m_wndSplitter.GetPane(1,0);
UpdateData(true);
mouse->SetDlgItemInt(IDC_EDIT3,point.x,1);
mouse->SetDlgItemInt(IDC_EDIT4,point.y,1);
}
if( choice )
{
CDC*PDC=GetDC();
PDC->SetROP2(R2_XORPEN);
if( !editpnt )
{
int sel=0;
list<Graph_Union>::iterator w;
for(w=m_graphlist.begin ();w!=m_graphlist.end();w++)
{
for(int i=0;i<w->count;i++)
{
if( abs(point.x-w->pp[i].x)<5 && abs(point.y-w->pp[i].y)<5)
{
if( isdraw )
{
CPoint a=CPoint(start_point.x,start_point.y);
dc.LPtoDP(&a);
CRect rect2(a.x-10,a.y-10,a.x+10,a.y+10);
PDC->DrawFocusRect(rect2);
}
else isdraw=TRUE;
choicep_num=i;
start_point=w->pp[i];
m_ptrGL=w;
CPoint b=CPoint(start_point.x,start_point.y);
dc.LPtoDP(&b);
CRect rect(b.x-10,b.y-10,b.x+10,b.y+10);
PDC->DrawFocusRect(rect);
sel=1;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -