You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1328 lines
35 KiB
C++

// LaiPuLaserView.cpp : CLaiPuLaserView 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "LaiPuLaser.h"
#endif
#include "LaiPuLaserDoc.h"
#include "LaiPuLaserView.h"
#include "MainFrm.h"
#include "MouseToolmgr.h"
#include "GlobalDrawMgr.h"
#include "MarkObjPropertieMgr.h"
#include "GlobalFunction.h"
#include "CommandDelete.h"
#include "CommandMove.h"
#include "LogMgr.h"
#include "DlgArray.h"
#include "WorkAreaMgr.h"
#include "Ruler.h"
#include "ModuleDeviceMgr.h"
#include "ModuleDrawMgr.h"
#include "CommandMgr.h"
#include "WorkDataMgr.h"
#include "TemplateMgr.h"
#include "AuthorityMgr.h"
#include "ObjFillMgr.h"
#include "CommonFlowMgr.h"
#include "CriticalSection.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CLaiPuLaserView
#if 1
IMPLEMENT_DYNCREATE(CLaiPuLaserView, CScrollView)
BEGIN_MESSAGE_MAP(CLaiPuLaserView, CScrollView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_COMMAND(ID_MOUSE_RECT, OnToolRect)
ON_UPDATE_COMMAND_UI(ID_MOUSE_RECT, OnUpdateToolRect)
ON_COMMAND(ID_TOOL_POINT, OnToolOnePoint)
ON_UPDATE_COMMAND_UI(ID_TOOL_POINT, OnUpdateToolOnePoint)
ON_COMMAND(ID_LASER_COORD, OnToolLaserCoord)
ON_UPDATE_COMMAND_UI(ID_LASER_COORD, OnUpdateToolLaserCoord)
ON_COMMAND(ID_MOUSE_CIRCLE, OnToolCircle)
ON_UPDATE_COMMAND_UI(ID_MOUSE_CIRCLE, OnUpdateToolCircle)
ON_COMMAND(ID_MOUSE_LINE, OnToolLine)
ON_UPDATE_COMMAND_UI(ID_MOUSE_LINE, OnUpdateToolLine)
ON_COMMAND(ID_PLINE, OnToolPline)
ON_UPDATE_COMMAND_UI(ID_PLINE, OnUpdateToolPline)
ON_COMMAND(ID_POLYGON, OnToolPolygon)
ON_UPDATE_COMMAND_UI(ID_POLYGON, OnUpdateToolPolygon)
ON_COMMAND(ID_UNDO, OnUndo)
ON_UPDATE_COMMAND_UI(ID_UNDO, OnUpdateUndo)
ON_COMMAND(ID_REDO, OnRedo)
ON_UPDATE_COMMAND_UI(ID_REDO, OnUpdateRedo)
ON_COMMAND(ID_ROTATO, OnToolRotato)
ON_COMMAND(ID_SLE_ALL, OnSelAllObj)
ON_COMMAND(ID_REV_SEL_OBJ, OnRevSelObj)
ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
ON_COMMAND(ID_WORK_SPACE_VIEW, OnWorkSpaceView)
ON_COMMAND(ID_MOVE_TO_CENTER, OnMoveToCenter)
ON_COMMAND(ID_OBJ_FILL, OnObjFill)
ON_COMMAND(ID_MIRROR_H, OnMirrorH)
ON_COMMAND(ID_MIRROR_V, OnMirrorV)
ON_COMMAND(ID_ROTATO_90_L, OnRotato90L)
ON_COMMAND(ID_ROTATO_90_R, OnRotato90R)
ON_COMMAND(ID_ARRAY, OnArray)
ON_COMMAND(ID_CUT, OnCut)
ON_COMMAND(ID_BREAK, OnBreak)
ON_COMMAND(ID_CHAMFER, OnChamfer)
ON_COMMAND(ID_FILLET, OnFillet)
ON_COMMAND(ID_EXPLODE, OnExplode)
ON_COMMAND(ID_DELETE, OnDelSelObj)
ON_COMMAND(ID_JOIN, OnJoin)
ON_COMMAND(ID_COPY, OnCopy)
ON_COMMAND(ID_MOVE, OnMove)
ON_COMMAND(ID_DIS_MEASURE, OnMeasure)
ON_COMMAND(ID_REVERSE, OnReverse)
ON_COMMAND(ID_ADD_NODE, OnAddNode)
ON_COMMAND(ID_DEL_NODE, OnDelNode)
ON_UPDATE_COMMAND_UI(ID_ROTATO, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_MOVE_TO_CENTER, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_OBJ_FILL, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_MIRROR_H, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_MIRROR_V, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_ROTATO_90_L, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_ROTATO_90_R, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_ARRAY, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_CHAMFER, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_FILLET, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_EXPLODE, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_DELETE, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_FILL, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_JOIN, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_COPY, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_MOVE, OnUpdateObjOperate)
ON_UPDATE_COMMAND_UI(ID_REVERSE, OnUpdateObjOperate)
ON_WM_ERASEBKGND()
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_MOUSEWHEEL()//鼠标滚轴消息
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_SETCURSOR()//设置鼠标
END_MESSAGE_MAP()
#endif
// CLaiPuLaserView 构造/析构
CLaiPuLaserView::CLaiPuLaserView()
{
m_bFirstIn = true;//是否第一次进入
m_bCtrl = false;//ctrl 键是否按下
m_bEraseBkgnd = true;//是否重绘背景色
m_bEraseBkgnd2 = true;//是否重绘背景色(不会自动恢复)
}
CLaiPuLaserView::~CLaiPuLaserView()
{
}
//获取当前视类指针
CLaiPuLaserView* m_pView = NULL;//保存当前视类的指针
BOOL CLaiPuLaserView::PreCreateWindow(CREATESTRUCT& cs)
{
// CREATESTRUCT cs 来修改窗口类或样式
return CScrollView::PreCreateWindow(cs);
}
//框架在第一次调用OnDraw前会调用OnInitialUpdate
void CLaiPuLaserView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize Size;
Size = gDraw->GetScrollViewSize();
SetZoomSizes(Size);
}
#if 1//绘制
HDC CLaiPuLaserView::GetHDC()
{
return ::GetDC(GetSafeHwnd());
}
CDC* CLaiPuLaserView::GetCDC()
{
return CDC::FromHandle(GetHDC());
}
// CLaiPuLaserView 绘制
void CLaiPuLaserView::OnDraw(CDC* pDC)
{
CLaiPuLaserDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
if(m_bFirstIn)
{
//工作区域观察
DoZoomFull();
}
//先擦除之前的捕捉点
gMouseToolMgr.ResetCatchPoint(pDC);
//模块可以绘制一些内容
gModuleDeviceMgr.Draw(pDC);
gModuleDrawMgr.Draw(pDC);
//绘制当前layer 的内容
if(!m_bFirstIn)
{
gLayer.Draw(pDC);
}
m_bFirstIn = false;
}
#endif
// CLaiPuLaserView 打印
void CLaiPuLaserView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CLaiPuLaserView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CLaiPuLaserView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
void CLaiPuLaserView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
#if 1//鼠标键盘操作
//鼠标滚轮消息响应函数
BOOL CLaiPuLaserView::OnMouseWheel(UINT nFlags,short zDelta,CPoint point)
{
if(gDraw->IsbMouseWheel())
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
//先擦除之前的捕捉点
gMouseToolMgr.ResetCatchPoint(&dc);
if(zDelta > 0)//向上滚放大
{
DoZoomIn(gDraw->GetCurZoomPoint());
}
else if(zDelta < 0)//向下滚缩小
{
DoZoomOut(gDraw->GetCurZoomPoint());
}
//显示缩放比例
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
pFrame->ShowViewScale(m_zoomScale);
}
return TRUE;
}
void CLaiPuLaserView::OnMouseMove(UINT nFlags, CPoint point)
{
//屏幕坐标转换为设备坐标
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
gDraw->SetCurZoomPoint(point);//鼠标移动的时候记录缩放点
gDraw->SetbNeedRedraw(true);
//显示鼠标位置坐标
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
pFrame->ShowMouseCoord(point);
//鼠标工具
gMouseToolMgr.OnMouseMove(nFlags,point,dc);
//绘制标尺光标的位置
gRuler->DrawMousePos(&dc, point);
CScrollView::OnMouseMove(nFlags, point);
}
void CLaiPuLaserView::OnLButtonDown(UINT nFlags, CPoint point)
{
//屏幕坐标转换为设备坐标
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
gMouseToolMgr.OnLButtonDown(nFlags,point,dc);
CScrollView::OnLButtonDown(nFlags, point);
}
void CLaiPuLaserView::OnLButtonUp(UINT nFlags, CPoint point)
{
//屏幕坐标转换为设备坐标
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
gMouseToolMgr.OnLButtonUp(nFlags,point,dc);
CScrollView::OnLButtonUp(nFlags, point);
}
void CLaiPuLaserView::OnRButtonDown(UINT nFlags, CPoint point)
{
//屏幕坐标转换为设备坐标
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
gMouseToolMgr.OnRButtonDown(nFlags,point,dc);
//CScrollView::OnRButtonDown(nFlags, point);
}
void CLaiPuLaserView::OnRButtonUp(UINT nFlags, CPoint point)
{
//屏幕坐标转换为设备坐标
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
gMouseToolMgr.OnRButtonUp(nFlags,point,dc);
//CScrollView::OnRButtonUp(nFlags, point);
}
void CLaiPuLaserView::OnMButtonDown(UINT nFlags, CPoint point)
{
}
void CLaiPuLaserView::OnMButtonUp(UINT nFlags, CPoint point)
{
}
//水平滚动条单击消息响应函数
void CLaiPuLaserView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
//点击箭头
if(SB_LINEDOWN == nSBCode || SB_LINEUP == nSBCode)
{
CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
Invalidate();
}
//拖的时候
if(SB_THUMBTRACK == nSBCode)
{
CScrollView::OnHScroll(SB_THUMBTRACK, nPos, pScrollBar);
Invalidate();
}
//结束拖动
if(SB_THUMBPOSITION == nSBCode)
{
CScrollView::OnHScroll(SB_THUMBPOSITION, nPos, pScrollBar);
Invalidate();
}
}
//垂直滚动条单击消息响应函数
void CLaiPuLaserView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
//点击箭头
if(SB_LINEDOWN == nSBCode || SB_LINEUP == nSBCode)
{
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
Invalidate();
}
//拖的时候
if(SB_THUMBTRACK == nSBCode)
{
CScrollView::OnVScroll(SB_THUMBTRACK, nPos, pScrollBar);
Invalidate();
}
//结束拖动
if(SB_THUMBPOSITION == nSBCode)
{
CScrollView::OnVScroll(SB_THUMBPOSITION, nPos, pScrollBar);
Invalidate();
}
}
//处理键盘响应
BOOL CLaiPuLaserView::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
char c = pMsg->wParam;
switch(c)
{
case VK_CONTROL:
m_bCtrl = true;
OnCtrl();
break;
case 'A'://ctrl + A 全选
if(m_bCtrl)
{
OnSelAllObj();
}
break;
case 'Z'://ctrl + Z 撤销
if(m_bCtrl)
{
OnUndo();
}
break;
case 'Y'://ctrl + Y 重做
if(m_bCtrl)
{
OnRedo();
}
break;
case 'S'://ctrl + S 保存
if(m_bCtrl)
{
//屏蔽
}
break;
case VK_SPACE:
OnSpace();
break;
case VK_ESCAPE://Esc 键
OnEscape();
break;
case VK_DELETE://删除
OnDelSelObj();
break;
case VK_UP:
OnArrowDir(_DIR_U);
break;
case VK_DOWN:
OnArrowDir(_DIR_D);
break;
case VK_LEFT:
OnArrowDir(_DIR_L);
break;
case VK_RIGHT:
OnArrowDir(_DIR_R);
break;
default:
break;
}
}
if(pMsg->message==WM_KEYUP)
{
switch(pMsg->wParam)
{
case VK_CONTROL:
m_bCtrl = false;
break;
default:
break;
}
}
return CScrollView::PreTranslateMessage(pMsg);
}
//ESC 键响应
void CLaiPuLaserView::OnEscape()
{
CClientDC dc(this);
OnPrepareDC(&dc);
gMouseToolMgr.OnEscapeKey(&dc);
gLayer.NotSelAllObj();//obj 全不选
gMouseToolMgr.SetMouseTool(_TOOL_POINT);
GetFrame()->ResetCaptionBar();
RefreshView();
gLogMgr->WriteDebugLog("OnEscape");
}
//方向键响应
void CLaiPuLaserView::MoveObjToPtByDir(DIRECTION dir,double Dis)
{
double MoveDisX = 0;
double MoveDisY = 0;
switch(dir)
{
case _DIR_L:
MoveDisX -= Dis;
break;
case _DIR_R:
MoveDisX += Dis;
break;
case _DIR_U:
MoveDisY += Dis;
break;
case _DIR_D:
MoveDisY -= Dis;
break;
default:
break;
}
gLayer.OnMove(MoveDisX,MoveDisY);
RefreshView();
}
#endif
#if 1//按键响应
//方向键
void CLaiPuLaserView::OnArrowDir(DIRECTION dir)
{
MoveObjToPtByDir(dir,gDraw->GetKeyboardMoveDis());
}
//空格键
void CLaiPuLaserView::OnSpace()
{
}
void CLaiPuLaserView::OnCtrl()
{
}
#endif
void CLaiPuLaserView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CLaiPuLaserView 诊断
#ifdef _DEBUG
void CLaiPuLaserView::AssertValid() const
{
CView::AssertValid();
}
void CLaiPuLaserView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CLaiPuLaserDoc* CLaiPuLaserView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLaiPuLaserDoc)));
return (CLaiPuLaserDoc*)m_pDocument;
}
#endif //_DEBUG
#if 1//view 缩放用
/*---------------------------------------------------------------------------
FUNCTION: SetZoomSizes
PURPOSE : Set up the CLaiPuLaserView class with the logical page size, and
scrolling page/line units.
This replaces CScrollView::SetScrollSizes.
---------------------------------------------------------------------------*/
void CLaiPuLaserView::SetZoomSizes (SIZE sizeTotal,const SIZE& sizePage,const SIZE& sizeLine)
{
// Set up the defaults
ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0);
m_nMapMode = MM_ANISOTROPIC; // Need for arbitrary scaling
m_totalLog = sizeTotal;
// Setup default Viewport extent to be conversion of Window extent
// into device units.
//BLOCK for DC
{
CWindowDC dc(NULL);
dc.SetMapMode(m_nMapMode);
// total size
m_totalDev = m_totalLog;
dc.LPtoDP((LPPOINT)&m_totalDev);
} // Release DC here
// Save the origional Viewport Extent
m_origTotalDev = m_totalDev;
// Save the origional scrollbar info - for CalcBars
m_origPageDev = sizePage;
m_origLineDev = sizeLine;
// Fugure out scroll bar info
CalcBars();
// Notify the class that the zoom scale was set
NotifyZoom();
} // SetZoomSizes
/*---------------------------------------------------------------------------
FUNCTION: OnPrepareDC
PURPOSE : Override of CScrollView for MM_ANISOTROPIC zoom mode
---------------------------------------------------------------------------*/
void CLaiPuLaserView::OnPrepareDC (CDC* pDC,CPrintInfo* pInfo)
{
#ifdef _DEBUG
if (m_nMapMode != MM_ANISOTROPIC) {
TRACE0("Error: must call SetZoomSizes() before painting zoom view\n");
ASSERT(FALSE);
return;
}
#endif //_DEBUG
ASSERT_VALID(pDC);
ASSERT(m_totalLog.cx >= 0 && m_totalLog.cy >= 0);
ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
// Set the Mapping mode, and the window and viewport extents
pDC->SetMapMode(m_nMapMode);//可变比例映射模式
pDC->SetViewportExt(m_totalDev); // in device coordinates
pDC->SetWindowExt(m_totalLog);// in logical coordinates
CPoint ptVpOrg;
// by default shift viewport origin in negative direction of scroll
ASSERT(pDC->GetWindowOrg() == CPoint(0,0));
ptVpOrg = -GetDeviceScrollPosition();
// Center full fit
CRect rect;
GetClientRect(&rect);
// if client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
if (m_totalDev.cx < rect.Width())
ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2;
if (m_totalDev.cy < rect.Height())
ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2;
// Set the new origin
pDC->SetViewportOrg(ptVpOrg);
// For default Printing behavior
CScrollView::OnPrepareDC(pDC, pInfo);
} // OnPrepareDC
/*---------------------------------------------------------------------------
FUNCTION: CalcBars
PURPOSE : Update the scrollbars - uses logical units
Call when the Viewport changes size.
---------------------------------------------------------------------------*/
void CLaiPuLaserView::CalcBars (void)
{
{ // BLOCK for DC
CWindowDC dc(NULL);
dc.SetMapMode(m_nMapMode);
// Calculate new device units for scrollbar
// Start with origional logical units from SetScrollPos
m_pageDev = m_origPageDev;
dc.LPtoDP((LPPOINT)&m_pageDev);
m_lineDev = m_origLineDev;
dc.LPtoDP((LPPOINT)&m_lineDev);
} // Free DC
// Make sure of the range
if (m_pageDev.cy < 0) m_pageDev.cy = -m_pageDev.cy;
if (m_lineDev.cy < 0) m_lineDev.cy = -m_lineDev.cy;
// If none specified - use one tenth
ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
//滚动条滚动一行的距离
//double Scale = m_zoomScale/DEFAULT_SCALE;
double Scale = m_zoomScale/VIEW_SCALE20;
double min = 10;//限制最小距离
double max = 500;//限制最大距离
double val = 20*Scale;
if(val<min)
{
val = min;
}
if(val>max)
{
val = max;
}
if(m_pageDev.cx == 0)
m_pageDev.cx = m_totalDev.cx/val;
if(m_pageDev.cy == 0)
m_pageDev.cy = m_totalDev.cy/val;
if(m_lineDev.cx == 0)
m_lineDev.cx = m_pageDev.cx /val;
if(m_lineDev.cy == 0)
m_lineDev.cy = m_pageDev.cy /val;
// Now update the scrollbars
if (m_hWnd != NULL)
{
UpdateBars();
Invalidate(TRUE); // Zoom scale changed, redraw all
}
} // CalcBars
//放大
int CLaiPuLaserView::DoZoomIn(CPoint Point)
{
CPoint ptCenter;
ASSERT(m_nMapMode == MM_ANISOTROPIC);
CPoint CurPt = GetScreenCenterPoint();
double Scale = gDraw->GetMouseWheelScale();
// Save the current center point.
ptCenter.x = CurPt.x+(Point.x-CurPt.x)*(Scale-1);
ptCenter.y = CurPt.y+(Point.y-CurPt.y)*(Scale-1);
// Increase the zoom scale.
if(m_zoomScale<MAX_SCALE)
m_zoomScale *= Scale;
else
return TRUE;
// Modify the Viewport extent
m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
CalcBars();
// Set the current center point.
CenterOnLogicalPoint(ptCenter);
// Notify the class that a new zoom scale was done
NotifyZoom();
return TRUE;
}
//缩小
int CLaiPuLaserView::DoZoomOut(CPoint Point)
{
CPoint ptCenter;
ASSERT(m_nMapMode == MM_ANISOTROPIC);
CPoint CurPt = GetScreenCenterPoint();
double Scale = gDraw->GetMouseWheelScale();
// Save the current center point.
ptCenter.x = CurPt.x-(Point.x-CurPt.x)*(Scale-1);
ptCenter.y = CurPt.y-(Point.y-CurPt.y)*(Scale-1);
// Decrease the zoom scale.
if(m_zoomScale>MIN_SCALE)
m_zoomScale /= Scale;
else
return TRUE;
// Modify the Viewport extent
m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
CalcBars();
// Set the current center point (logical coordinates.
CenterOnLogicalPoint(ptCenter);
// Notify the class that a new zoom scale was done
NotifyZoom();
return TRUE;
}
//工作区域观察(在线程里调用这个函数可能会造成软件崩溃)
int CLaiPuLaserView::DoZoomFull(void)
{
RectView(gDraw->GetWorkAreaViewScale());
return TRUE;
}
//矩形区域观察
void CLaiPuLaserView::RectView(double scale,Dbxy pt)
{
ASSERT(m_nMapMode == MM_ANISOTROPIC);
CRect rect;
CPoint point = gDraw->Dbxy2CPoint(pt);
//计算适当比例
m_zoomScale = scale;
// Modify the Viewport extent
m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
CalcBars();
// Set the current center point.
CenterOnLogicalPoint(point);
// Notify the class that a new zoom scale was done
NotifyZoom();
}
/*---------------------------------------------------------------------------
FUNCTION: CenterOnLogicalPoint
PURPOSE : Same as CScrollView::CenterOnPoint, but for logical coordinates
---------------------------------------------------------------------------*/
void CLaiPuLaserView::CenterOnLogicalPoint(CPoint pt)
{
//Convert the point to device coordinates
ViewLPtoDP(&pt);
// Account for scroll bar position
ClientToDevice(pt);
// Use CScrollView's function for device coordinates
CScrollView::CenterOnPoint(pt);
} // CenterOnLogicalPoint
/*---------------------------------------------------------------------------
FUNCTION: GetLogicalCenterPoint
PURPOSE : Get the center of screen in logical coordinates
---------------------------------------------------------------------------*/
CPoint CLaiPuLaserView::GetLogicalCenterPoint (void) // Point in logical units
{
CPoint pt;
CRect rect;
// Get the center of screen
GetClientRect(&rect);
pt.x = (rect.Width() / 2);
pt.y = (rect.Height() / 2);
// Convert the point to logical coordinates
ViewDPtoLP(&pt);
return pt;
} // GetLogicalCenterPoint
/*---------------------------------------------------------------------------
FUNCTION: ViewDPtoLP
PURPOSE : Same as DPtoLP, but gets the Client DC for the view
---------------------------------------------------------------------------*/
void CLaiPuLaserView::ViewDPtoLP (
LPPOINT lpPoints,
int nCount)
{
// Convert to logical units
// Called from View when no DC is available
ASSERT(m_nMapMode > 0); // must be set
CWindowDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(lpPoints, nCount);
} // ViewDPtoLP
/*---------------------------------------------------------------------------
FUNCTION: ViewLPtoDP
PURPOSE : Same as LPtoDP, but gets the Client DC for the view
---------------------------------------------------------------------------*/
void CLaiPuLaserView::ViewLPtoDP (
LPPOINT lpPoints,
int nCount)
{
// Convert to logical units
// Called from View when no DC is available
ASSERT(m_nMapMode > 0); // must be set
CWindowDC dc(this);
OnPrepareDC(&dc);
dc.LPtoDP(lpPoints, nCount);
} // ViewLPtoDP
/*---------------------------------------------------------------------------
FUNCTION: ClientToDevice
PURPOSE : Convert from Client coordinates to relative Device coordinates
---------------------------------------------------------------------------*/
void CLaiPuLaserView::ClientToDevice (
CPoint &point)
{
// Need to account for scrollbar position
CPoint scrollPt = GetDeviceScrollPosition();
point.x += scrollPt.x;
point.y += scrollPt.y;
} // ClientToDevice
/*---------------------------------------------------------------------------
FUNCTION: NormalizeRect
PURPOSE : Normalize the rectangle
---------------------------------------------------------------------------*/
void CLaiPuLaserView::NormalizeRect (
CRect &rect)
{
if (rect.left > rect.right) {
int r = rect.right;
rect.right = rect.left;
rect.left = r;
}
if (rect.top > rect.bottom) {
int b = rect.bottom;
rect.bottom = rect.top;
rect.top = b;
}
} // NormalizeRect
/*---------------------------------------------------------------------------
FUNCTION: PersistRatio
PURPOSE : Make a CSize maintain the given ratio (by shrinking if nescessary)
---------------------------------------------------------------------------*/
void CLaiPuLaserView::PersistRatio (
const CSize &orig,
CSize &dest,
CPoint &remainder)
{
double ratio1 = (double) orig.cx / orig.cy;
double ratio2 = (double) dest.cx / dest.cy;
int newSize;
// Do nothing if they are the same
if (ratio1 > ratio2)
{
// Shrink hieght
newSize = (int)(dest.cx / ratio1);
remainder.x = 0;
remainder.y = dest.cy - newSize;
dest.cy = newSize;
} else if (ratio2 > ratio1)
{
// Shrink width
newSize = (int)(dest.cy * ratio1);
remainder.x = dest.cx - newSize;
remainder.y = 0;
dest.cx = newSize;
}
} // PersistRatio
//获取当前比例的值
int CLaiPuLaserView::GetCurrScaleVal(int val)
{
return (val/m_zoomScale);
}
double CLaiPuLaserView::GetCurrScaleVal(double val)
{
return (val/m_zoomScale);
}
#endif
#if 1//视图操作
//放大
void CLaiPuLaserView::OnZoomIn()
{
DoZoomIn(GetScreenCenterPoint());
}
void CLaiPuLaserView::OnZoomOut()
{
DoZoomOut(GetScreenCenterPoint());
}
//工作区域观察
void CLaiPuLaserView::OnWorkSpaceView()
{
DoZoomFull();
}
#endif
#if 1//撤销重做
void CLaiPuLaserView::OnUndo()
{
gCommandMgr.Undo();
RefreshView();
//更新选择对象的属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateUndo(CCmdUI* pCmdUI)
{
if(gCommandMgr.HasUndoCmd())
{
pCmdUI->Enable(true);
}
else
{
pCmdUI->Enable(false);
}
pCmdUI->SetCheck(false);
}
void CLaiPuLaserView::OnRedo()
{
gCommandMgr.Redo();
RefreshView();
//更新选择对象的属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateRedo(CCmdUI* pCmdUI)
{
if(gCommandMgr.HasRedoCmd())
{
pCmdUI->Enable(true);
}
else
{
pCmdUI->Enable(false);
}
pCmdUI->SetCheck(false);
}
#endif
#if 1//绘制相关
void CLaiPuLaserView::OnToolPoint()
{
gMouseToolMgr.SetMouseTool(_TOOL_POINT);
}
void CLaiPuLaserView::OnToolRect()
{
gMouseToolMgr.SetMouseTool(_TOOL_RECT);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateToolRect(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_RECT?1:0);
}
//画点
void CLaiPuLaserView::OnToolOnePoint()
{
gMouseToolMgr.SetMouseTool(_TOOL_ONE_POINT);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateToolOnePoint(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_ONE_POINT?1:0);
}
void CLaiPuLaserView::OnToolLaserCoord()
{
gMouseToolMgr.SetMouseTool(_TOOL_LASER_COORD);
RefreshView();
}
void CLaiPuLaserView::OnUpdateToolLaserCoord(CCmdUI* pCmdUI)
{
pCmdUI->Enable(false);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_LASER_COORD?1:0);
}
void CLaiPuLaserView::OnToolPolygon()
{
}
void CLaiPuLaserView::OnUpdateToolPolygon(CCmdUI* pCmdUI)
{
}
void CLaiPuLaserView::OnToolCircle()
{
gMouseToolMgr.SetMouseTool(_TOOL_CIRCLE);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateToolCircle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_CIRCLE?1:0);
}
void CLaiPuLaserView::OnToolLine()
{
gMouseToolMgr.SetMouseTool(_TOOL_LINE);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateToolLine(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_LINE?1:0);
}
void CLaiPuLaserView::OnToolPline()
{
gMouseToolMgr.SetMouseTool(_TOOL_PLINE);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnUpdateToolPline(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(gMouseToolMgr.GetToolType()==_TOOL_PLINE?1:0);
}
#endif
#if 1//图形操作相关
void CLaiPuLaserView::OnUpdateObjOperate(CCmdUI* pCmdUI)
{
if(gLayer.HasObjSel())
{
pCmdUI->Enable(true);
}
else
{
pCmdUI->Enable(false);
}
}
void CLaiPuLaserView::OnSelAllObj()
{
if(gDraw->IsEditLayerObj())
{
gLayer.SelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
}
void CLaiPuLaserView::OnMoveToCenter()
{
MoveSelObjToCenter();
}
void CLaiPuLaserView::MoveSelObjToCenter()
{
CLayer & layer = gLayer;
Dbxy pt = layer.GetSelObjRect().GetCenterPt();
layer.OnMove(pt.x*(-1),pt.y*(-1));
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
//反选
void CLaiPuLaserView::OnRevSelObj()
{
if(gDraw->IsEditLayerObj())
{
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
}
void CLaiPuLaserView::OnDelSelObj()
{
CLayer &layer = gLayer;
if(layer.HasObjSel())
{
//创建撤销指令
CCommandDelete *pCmd = new CCommandDelete;
gCommandMgr.AddUndoCommand(pCmd);
pCmd->Excute();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
}
//水平镜像
void CLaiPuLaserView::OnMirrorH()
{
gLayer.OnMirror(_X);
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
//垂直镜像
void CLaiPuLaserView::OnMirrorV()
{
gLayer.OnMirror(_Y);
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
//左旋转90度
void CLaiPuLaserView::OnRotato90L()
{
gLayer.OnRotato(90);
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnRotato90R()
{
gLayer.OnRotato(-90);
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnToolRotato()
{
gMouseToolMgr.SetMouseTool(_TOOL_ROTATO);
}
void CLaiPuLaserView::OnCut()
{
gMouseToolMgr.SetMouseTool(_TOOL_CUT);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
//打断节点
void CLaiPuLaserView::OnBreak()
{
gMouseToolMgr.SetMouseTool(_TOOL_BREAK_NODE);
}
void CLaiPuLaserView::OnChamfer()
{
}
void CLaiPuLaserView::OnFillet()
{
}
//分解
void CLaiPuLaserView::OnExplode()
{
gLayer.OnExplode();
RefreshView();
}
//合并
void CLaiPuLaserView::OnJoin()
{
if(gLayer.OnJoin())
{
RefreshView();
gLogMgr->WriteDebugLog("OnJoin ----OK ");
}
else
{
gLogMgr->WriteDebugLog("OnJoin ----Err ");
}
}
void CLaiPuLaserView::OnCopy()
{
gMouseToolMgr.SetMouseTool(_TOOL_COPY);
}
void CLaiPuLaserView::OnMove()
{
gMouseToolMgr.SetMouseTool(_TOOL_MOVE2);
}
//反转
void CLaiPuLaserView::OnReverse()
{
gLayer.OnReverseSelObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CLaiPuLaserView::OnAddNode()
{
gMouseToolMgr.SetMouseTool(_TOOL_ADD_NODE);
RefreshView();
}
void CLaiPuLaserView::OnDelNode()
{
gMouseToolMgr.SetMouseTool(_TOOL_DEL_NODE);
RefreshView();
}
void CLaiPuLaserView::OnMeasure()
{
gMouseToolMgr.SetMouseTool(_TOOL_MEASURE);
gLayer.SelAllObj();
gLayer.RevSelAllObj();
RefreshView();
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
//阵列
void CLaiPuLaserView::OnArray()
{
CDlgArray dlg;
if(dlg.DoModal()==IDOK)
{
RefreshView();
}
}
void CLaiPuLaserView::OnObjFill()
{
}
#endif
#if 1
//绘制view 背景颜色
BOOL CLaiPuLaserView::OnEraseBkgnd(CDC *pDC)
{
if(m_bEraseBkgnd2&&m_bEraseBkgnd)
{
CScrollView::OnEraseBkgnd(pDC);
CRect rect;
GetClientRect(rect);
CBrush BkgndBrush;
COLORREF color = RGB_BLACK;
color = gDraw->GetBkgndColor();
BkgndBrush.CreateSolidBrush(color);
pDC->FillRect(&rect,&BkgndBrush);
}
m_bEraseBkgnd = true;//恢复
return TRUE;
}
BOOL CLaiPuLaserView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
return true;
}
//重绘view
void CLaiPuLaserView::RefreshView()
{
#if 1
if(gDraw->IsbDlgLayerViewShow())
{
CString WndName = "Wafer View";
CString WndMsg = "Invalidate";
SendMsgToWnd(WndName,WndMsg);
}
else
{
//需要在编辑界面才刷新
if(gDraw->IsbObjEditMode())
{
gCriticalSection_ViewInvalidate.Lock();
gLogMgr->WriteDebugLog("RefreshView");
Invalidate();
gCriticalSection_ViewInvalidate.Unlock();
}
}
#else
Invalidate();
#endif
}
CPoint CLaiPuLaserView::GetScreenCenterPoint()
{
CClientDC dc(this);
OnPrepareDC(&dc);
//获取客户区范围
CRect rect;
GetClientRect(&rect);//获取窗口客户区的坐标
dc.DPtoLP(rect);
//计算中心点
CPoint Cpoint;
Cpoint.x = (rect.left + (rect.right-rect.left)/2);
Cpoint.y = (rect.top + (rect.bottom-rect.top)/2);
return Cpoint;
}
//限制鼠标范围
void CLaiPuLaserView::LimitCursor()
{
CRect rect;
GetClientRect(&rect);//获取窗口客户区的坐标
ClientToScreen(&rect);//将矩形的用户坐标转换成屏幕坐标
ClipCursor(&rect);//限制鼠标范围
}
//释放对鼠标范围的限制
void CLaiPuLaserView::ReleseLimitCursor()
{
ClipCursor(NULL);//释放鼠标限制
}
//设置鼠标光标
void CLaiPuLaserView::SetCursorStyle(MOUSE_TOOL type)
{
switch(type)
{
case _TOOL_POINT:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_POINT));
break;
case _TOOL_RECT:
case _TOOL_LINE:
case _TOOL_PLINE:
case _TOOL_CIRCLE:
case _TOOL_MOVE2:
case _TOOL_ROTATO:
case _TOOL_COPY:
case _TOOL_MEASURE:
case _TOOL_ONE_POINT:
case _TOOL_LASER_COORD:
case _TOOL_PT_MOVE_TO_CCD:
case _TOOL_SET_MARK_PT:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_DRAW));
break;
case _TOOL_TEXT:
case _TOOL_BARCODE:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_TXT));
break;
case _TOOL_MOVE:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_MOVE));
break;
case _TOOL_CUT:
case _TOOL_ADD_NODE:
case _TOOL_DEL_NODE:
case _TOOL_BREAK_NODE:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_NODE));
break;
case _TOOL_MOVE_NODE:
case _TOOL_STRETCH:
SetCursor(AfxGetApp()->LoadCursor(IDC_MOUSE_HAND));
break;
default:
break;
}
}
#endif