📄 visdrawview.cpp
字号:
m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,(LPCTSTR)(pDoc->m_strLanguage));
// CFigureObj::c_objs.RemoveTail();
CFigureObj::c_drawObj=cheObj;
pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(NULL);
// m_wndDlgBarLanguage.UpdateData();
}
if(CFigureObj::c_drawObj==moObj)
{
// if(m_pID == m_picIDmo)
m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,(LPCTSTR)(pDoc->m_strLanguage));
CFigureObj::c_drawObj=cheObj;
pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(NULL);
// CFigureObj::c_objs.RemoveTail();
// m_wndDlgBarLanguage.UpdateData();
}
}*/
//m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,_T(""));
//POSITION pos01 = m_selection.GetHeadPosition();
//
// if((pos01 != NULL) && (m_selection.GetCount() == 1))
//
// {
// CTextObj* pObj=m_select.GetNext(pos01);
// m_dlg.m_string=pObj->m_string;
// if (m_dlg.DoModal() != IDOK)
// return;
// pObj->SetInputText(m_dlg.m_string);
// Invalidate();
// return;
//
//// }
// if (m_selection.GetCount() > 1 && CDrawTool::c_drawShape == selectTool)
// {
// CVisDrawDoc* pDoc = GetDocument();
// CPropertySheet sheet( _T("设备管理信息") );
// CShebeiDlg dlg;
// //dlg.m_bNoFill = FALSE;
// sheet.AddPage( &dlg );
// if (sheet.DoModal() != IDOK)
// return;
// //m_bBrush = !dlg.m_bNoFill;
// POSITION pos1 = m_selection.GetHeadPosition();
// while (pos1 != NULL)
// {
// CFigureObj* pObj = m_selection.GetNext(pos1);
// //pObj->m_bBrush=!dlg.m_bNoFill;
// }
// Invalidate();
// pDoc->SetModifiedFlag();
// }
//if(CDrawTool::c_drawShape ==selectTool)
//{
//CString strxiToool=_T("在X(数量)个工位上,铣(加工方法),保持Z(加工要求),P(加工尺寸和精度)");
//}
//CFigureObj* pObj = CFigureObj::FindObj(CFigureObj::c_drawObj);
//if(pObj !=NULL)
//{
//
//POSITION pos = m_selection.GetHeadPosition();
//if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selectTool)
//{
//while(pos != NULL)
//{
//CDrawTool* pTool2 = (CDrawTool*)
//CFigureObj* pObj = m_selection.GetNext(pos);
//pTool->c_tools.GetNext(pos);
//if(CDrawTool::c_drawShape ==xiTool)
//{
//if(CFigureObj::c_drawObj==baoObj)
//{
// m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,(LPCTSTR)(pDoc->m_strLanguage));
// //CFigureObj::c_drawObj==cheObj;
// //Invalidate();
// //return;
// pDoc->SetModifiedFlag();
// pDoc->UpdateAllViews(NULL);
// }
////}
////}
//if(CFigureObj::c_drawObj==xiObj)
//{
// m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,"123");
// //CFigureObj::c_drawObj==cheObj;
// pDoc->SetModifiedFlag();
// pDoc->UpdateAllViews(NULL);
// //return;
// }
////}
//}
/*else
{
CSelectTool* pSelTool;
pSelTool->OnLButtonUp(this, nFlags, point);
_T("车-端面-保持尺寸-50-(-0.1,+0.1)mm")
}*/
//}
}
void CVisDrawView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
//if(CDrawTool::c_drawShape=cheTool)
if (pTool != NULL)
pTool->OnLButtonDblClk(this, nFlags, point);
//CGongshiDlg dlg;
// dlg.m_cheXinghao.AddString("che");
CVisDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//CTextWriteDlg m_dlg;
//CMoObjList* pMoObjList =GetDocument()->GetObjects();
//
POSITION pos01 = m_selection.GetHeadPosition();
if((pos01 != NULL) && (m_selection.GetCount() == 1))
{
CMoObj* pmoObj=m_moselect.GetNext(pos01);
//CFigureObj* pObj= m_selection.GetNext(pos);
//m_dlg.m_string=pObj->m_string;
// if (m_dlg.DoModal() != IDOK)
// return;
// pObj->SetInputText(m_dlg.m_string);
// POSITION pos =m_moselect.GetTailPosition();
// while(pos !=NULL)
// {
// m_moselect.GetPrev(pos);
m_wndDlgBarLanguage.SetDlgItemTextA(IDC_EDIT_LANGUAGE,(LPCTSTR)(pDoc->m_strLanguage));
m_wndDlgBar.SetDlgItemTextA(IDC_EDIT_JD,(LPCTSTR)_T("(-0, +0)"));
Invalidate();
//pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(this);
return;
// }
}
}
//baoTool,
//xiTool,
//moTool,
//tangTool,
//zuanTool,
//chongTool,
//juTool,
//zhongxinTool,
//zhewanTool
void CVisDrawView::OnInitialUpdate()
{
// CVisDrawScrollView::OnInitialUpdate();
CVisDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_sizeDoc = pDoc->GetSize();
m_x0 = m_sizeDoc.cx / 2;
m_y0 = m_sizeDoc.cy / 2;
SetScrollSizes(MapMode, m_sizeDoc);
}
void CVisDrawView::OnZoomIn()
{
// TODO: 在此添加命令处理程序代码
OnZoom(m_Zoom * 2);
}
void CVisDrawView::OnZoomOut()
{
// TODO: 在此添加命令处理程序代码
OnZoom(m_Zoom / 2);
}
void CVisDrawView::OnZoomFit()
{
// TODO: 在此添加命令处理程序代码
CRect rectClient;
GetLogClientRect(&rectClient);
CPoint pointCenter = rectClient.CenterPoint();
pointCenter.x = MulDiv(pointCenter.x, ZOOM_ONE, m_Zoom);
pointCenter.y = MulDiv(pointCenter.y, ZOOM_ONE, m_Zoom);
// change zoom
OnZoom(ZOOM_ONE);
// calculate new center point with zoom
pointCenter.x = MulDiv(pointCenter.x, m_Zoom, ZOOM_ONE);
pointCenter.y = MulDiv(pointCenter.y, m_Zoom, ZOOM_ONE);
// center on new point
CenterOnPoint(pointCenter);
}
void CVisDrawView::OnZoomWindow()
{
// TODO: 在此添加命令处理程序代码
}
void CVisDrawView::OnZoom(long Zoom)
{
if (Zoom < m_ZoomMin)
{
MessageBeep(MB_ICONEXCLAMATION);
Zoom = m_ZoomMin;
}
if (Zoom > m_ZoomMax)
{
MessageBeep(MB_ICONEXCLAMATION);
Zoom = m_ZoomMax;
}
if (Zoom != m_Zoom)
{
m_Zoom = Zoom;
CSize sizeTotal = m_sizeDoc;
sizeTotal.cx = MulDiv(sizeTotal.cx, m_Zoom, ZOOM_ONE);
sizeTotal.cy = MulDiv(sizeTotal.cy, m_Zoom, ZOOM_ONE);
SetScrollSizes(MapMode, sizeTotal);
}
}
void CVisDrawView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: 在此添加专用代码和/或调用基类
CRect rect;
CVisDrawScrollView::OnPrepareDC(pDC, pInfo);
if (pDC->IsPrinting())
{
int cx = 10 * pDC->GetDeviceCaps(HORZSIZE);
int cy = 10 * pDC->GetDeviceCaps(VERTSIZE);
rect.SetRect(0, 0, cx, -cy);
m_xo = 0; // no offset for printing
m_yo = cy;
m_Scale = ZOOM_ONE; // no zoom for printing
int nPages = pInfo->m_nCurPage - 1;
int x = (nPages&1)*((int)m_nPageWidth);
int y = (nPages/2)* -((int)m_nPageHeight);
pDC->SetWindowOrg(x,y);
}
else
{
GetLogClientRect(&rect);
rect.OffsetRect(-m_Offset); // clip rect in [lu]
m_xo = m_Offset.x; // offset for drawing
m_yo = m_Offset.y; // origin bottom/left
m_Scale = m_Zoom; // zoom for drawing
}
}
//逻辑坐标转化为实际坐标
void CVisDrawView::ClientToWorld( CPoint npoint, double &pointx, double &pointy)
{
double scale, zm, sc;
zm=ZOOM_ONE;
sc=m_Scale;
scale=zm/sc;
pointx = npoint.x*scale - m_x0;
pointy = -npoint.y*scale + m_y0;
}
double CVisDrawView::ClientToWorld( double distance)
{
double scale, zm, sc;
zm=ZOOM_ONE;
sc=m_Scale;
scale=zm/sc;
return distance*scale;
}
//实际坐标转化为逻辑坐标
void CVisDrawView::WorldToClient(CPoint &npoint, double pointx, double pointy)
{
double scale, zm, sc;
zm=ZOOM_ONE;
sc=m_Scale;
scale=sc/zm;
npoint.x = (int)((pointx + m_x0)*scale) - m_xo;
npoint.y = (int)((-pointy + m_y0)*scale) - m_yo;
}
double CVisDrawView::WorldToClient( double distance)
{
double scale, zm, sc;
zm=ZOOM_ONE;
sc=m_Scale;
scale=sc/zm;
return distance*scale;
}
//绘制坐标网格线
void CVisDrawView::DrawGrid(CDC* pDC)
{
CVisDrawDoc* pDoc = GetDocument();
CRect rect;
CSize size;
size = pDoc->GetSize();
rect.left = -size.cx / 2;
rect.top = size.cy / 2;
rect.right = size.cx / 2;
rect.bottom = -size.cy / 2;
CPoint pt1,pt2,pp;
double x1,y1;
CPen penDash;
penDash.CreatePen(PS_SOLID, 1, m_gridColor);
CPen* pOldPen = pDC->SelectObject(&penDash);
WorldToClient(pp,0, rect.top);
pDC->MoveTo(pp);
WorldToClient(pp,0, rect.bottom);
pDC->LineTo(pp);
WorldToClient(pp,rect.left, 0);
pDC->MoveTo(pp);
WorldToClient(pp,rect.right, 0);
pDC->LineTo(pp);
CPen penDot;
penDot.CreatePen(PS_DOT, 1, m_gridColor);
pDC->SelectObject(&penDot);
for(int x = m_GridDistance;x < rect.right;x += m_GridDistance)
{
x1 = x;
y1 = rect.top;
WorldToClient(pp,x1,y1);
pDC->MoveTo(pp);
x1 = x;
y1 = rect.bottom;
WorldToClient(pp,x1,y1);
pDC->LineTo(pp);
}
for(int x= -m_GridDistance;x > rect.left;x -= m_GridDistance)
{
x1 = x;
y1 = rect.top;
WorldToClient(pp,x1,y1);
pDC->MoveTo(pp);
x1 = x;
y1 = rect.bottom;
WorldToClient(pp,x1,y1);
pDC->LineTo(pp);
}
for(int y = m_GridDistance;y < rect.top;y += m_GridDistance)
{
x1 = rect.left;
y1 = y;
WorldToClient(pp,x1,y1);
pDC->MoveTo(pp);
x1 = rect.right;
y1 = y;
WorldToClient(pp,x1,y1);
pDC->LineTo(pp);
}
for(int y = -m_GridDistance;y > rect.bottom;y -= m_GridDistance)
{
x1 = rect.left;
y1 = y;
WorldToClient(pp,x1,y1);
pDC->MoveTo(pp);
x1 = rect.right;
y1 = y;
WorldToClient(pp,x1,y1);
pDC->LineTo(pp);
}
pDC->SelectObject(pOldPen);
}
BOOL CVisDrawView::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//return CVisDrawScrollView::OnEraseBkgnd(pDC);
return TRUE;
}
void CVisDrawView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (m_bActive != bActivate)
{
if (bActivate)
m_bActive = bActivate;
m_bActive = bActivate;
}
}
//刷新图元边界矩形范围
void CVisDrawView::InvalObj(CFigureObj* pObj)
{
CVisDrawDoc* pDoc = GetDocument();
int nDistance;
nDistance = pDoc->GetSetectDistance();
//nDistance = nDistance + 1;
CRect rect = pObj->m_position;
DocToClient(rect);
rect.NormalizeRect();
if (m_bActive && IsSelected(pObj))
{
rect.left -= nDistance;
rect.top -= nDistance;
rect.right += nDistance;
rect.bottom += nDistance;
}
rect.InflateRect(1, 1);
InvalidateRect(rect, FALSE);
}
//把图元对象指针添加到选择集
void CVisDrawView::Select(CFigureObj* pObj, BOOL bAdd)
{
//bAdd为0,清空选择集;否则把pObj添加到选择集
if (!bAdd)
{
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
}
if (pObj == NULL || IsSelected(pObj))
return;
m_selection.AddTail(pObj);
//m_select.AddTail(pObj);
//更新图元对象范围矩形区域
InvalObj(pObj);
}
// rect 为设备坐标
void CVisDrawView::SelectWithinRect(CRect rect, BOOL bAdd)
{
//bAdd为0,清空选择集
if (!bAdd)
Select(NULL);
//把矩形设备坐标转化为逻辑坐标
ClientToDocDraw(rect);
//遍历文档图元对象指针链表
CFigureObjList* pObList = GetDocument()->GetObjects();
POSITION posObj = pObList->GetHeadPosition();
while (posObj != NULL)
{
CFigureObj* pObj = pObList->GetNext(posObj);
//判断图元是否与拾取矩形相交,如果相交,把图元添加到选择集体
if (pObj->Intersects(this,rect))
Select(pObj, TRUE);
}
}
//把图元对象指针从选择集中删除
void CVisDrawView::Deselect(CFigureObj* pObj)
{
POSITION pos = m_selection.Find(pObj);
if (pos != NULL)
{
InvalObj(pObj);
m_selection.RemoveAt(pos);
// m_select.AddTail(pObj);
}
}
BOOL CVisDrawView::IsSelected(const CObject* pDocItem) const
{
CFigureObj* pDrawObj = (CFigureObj*)pDocItem;
return m_selection.Find(pDrawObj) != NULL;
}
void CVisDrawView::PasteNative(COleDataObject& dataObject)
{
// get file refering to clipboard data
CFile* pFile = dataObject.GetFileData(m_cfDraw);
if (pFile == NULL)
return;
// connect the file to the archive
CArchive ar(pFile, CArchive::load);
TRY
{
ar.m_pDocument = GetDocument(); // set back-pointer in archive
// read the selection
m_selection.Serialize(ar);
}
CATCH_ALL(e)
{
ar.Close();
delete pFile;
THROW_LAST();
}
END_CATCH_ALL
ar.Close();
delete pFile;
}
void CVisDrawView::OnEditCopy()
{
// TODO: 在此添加命令处理程序代码
ASSERT_VALID(this);
ASSERT(m_cfDraw != NULL);
// 创建一个共享文件并把它与CArchive相关联
CSharedFile file;
CArchive ar(&file, CArchive::store);
// Serialize selected objects to the archive
m_selection.Serialize(ar);
ar.Close();
COleDataSource* pDataSource = NULL;
TRY
{
pDataSource = new COleDataSource;
// put on local format instead of or in addation to
pDataSource->CacheGlobalData(m_cfDraw, file.Detach());
CFigureObj* pDrawObj = m_selection.GetHead();
pDataSource->SetClipboard();
}
CATCH_ALL(e)
{
delete pDataSource;
THROW_LAST();
}
END_CATCH_ALL
}
void CVisDrawView::OnUpdateEditCopy(CCmdUI *pCmdUI)
{
// TODO: 在此添加命令更新用户界面处理程序代码
pCmdUI->Enable(!m_selection.IsEmpty());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -