#include "StdAfx.h" #include "ItemWcsTrack.h" #include "MultiWellSectionDoc.h" #include "MultiWellSectionlView.h" #include "WellPoleLib/WellBaseObj.h" #include "WellPoleLib/WellClassObjGroup.h" #include "WellPoleLib/TrackObj.h" #include "WellPoleLib/InTrackTextRange.h" //#include "GSingleWellLib\GSingleWellLib\TrackLayerObj.h" //#include "GSingleWellLib\GSingleWellLib\TrackInLayer.h" #include "WellPoleLib/InclinedTrack.h" #include "WellPoleLib/TrackResult.h" #include "WellPoleLib/InTrackResult.h" #include "WellPoleLib/TrackText.h" #include "WellPoleLib/WellPole.h" #include "MultiWellSectionLib/BendObj.h" #include "MultiWellSectionLib/FenceBendObj.h" #include "MultiWellSectionLib/FaultObj.h" #include "MultiWellSectionLib/SectionWellObj.h" #include "MultiWellSectionLib/WellSection.h" #include "MultiWellSectionLib/WellFence.h" #include "ItemVirtualWell.h" namespace NItem { CItemVirtualWell::CItemVirtualWell(CSigmaDoc* pDoc, BOOL bAdd) : CItemWcsSingleWell(pDoc) { SetType(ITEM_VIRTUALWELL); m_bAdd = bAdd; m_bLDown = FALSE; nDragHandle = 0; m_pVirtualWell = NULL; m_pItemSection = NULL; } CItemVirtualWell::~CItemVirtualWell(void) { } void CItemVirtualWell::OnDraw(CXyDC* pXyDC) { CDC *pDC = GetDC()->GetDC(); CPen pen(PS_DOT, 0, RGB(0, 0, 0)); CPen *pOldPen = (CPen *)pDC->SelectObject(&pen); int old = pDC->SetROP2(R2_NOTXORPEN); if (m_bAdd) { CPoint p1,p2; p1 = m_downPoint; p2 = m_lastPoint; p2.x = p1.x; pDC->MoveTo(p1); pDC->LineTo(p2); } else { if(m_pVirtualWell!=NULL) { if(m_bDrag && m_lastPoint!=m_downPoint)//画拖拽框(整体、控制点) { if(selectMode==CItemSelect::move)//整体 { CRect position = pXyDC->GetScreen(m_pVirtualWell->GetRect()); position.NormalizeRect(); CRect rect = position; CPoint delta = CPoint(m_lastPoint.x-m_downPoint.x,0); rect.OffsetRect(delta.x, delta.y); pDC->Rectangle(rect); } else if (nDragHandle!=0)//控制点 { CRect rect = GetDC()->GetScreen(m_pVirtualWell->GetRect()); MoveHandle(nDragHandle, m_lastPoint, rect); pDC->Rectangle(rect); } } //画选中状态 if(!m_bDrag || m_firstPoint==m_downPoint) { //画控制点 CPoint2D point; CPen pen; pen.CreatePen(PS_SOLID, 1, RGB(200,0,0)); pOldPen = pDC->SelectObject(&pen); point.x0 = (m_pVirtualWell->GetPos().left+m_pVirtualWell->GetPos().right)/2; point.y0 = m_pVirtualWell->GetPos().top; DrawHandle(pXyDC, point); point.x0 = (m_pVirtualWell->GetPos().left+m_pVirtualWell->GetPos().right)/2; point.y0 = m_pVirtualWell->GetPos().bottom; DrawHandle(pXyDC, point); pDC->SelectObject(pOldPen); pen.DeleteObject(); pen.CreatePen(PS_DOT, 1, RGB(255,0,0)); pOldPen = pDC->SelectObject(&pen); CRect rect = GetDC()->GetScreen(m_pVirtualWell->GetRect()); pDC->Rectangle(rect); pDC->SelectObject(pOldPen); pen.DeleteObject(); } } } pDC->SelectObject(pOldPen); pen.DeleteObject(); pDC->SetROP2(old); } void CItemVirtualWell::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) { m_bLDown = TRUE; m_downPoint = m_firstPoint = m_lastPoint = point; if(m_pVirtualWell != NULL) { CPoint2D ptReal = GetDC()->GetReal(point); CWellBaseObj* pObj = m_pVirtualWell; int nHandleSize = HANDLESIZE; // ::GetPreferences().WorkaroundHandle.m_nHandleSize; double dHandleSize = GetDC()->GetRealSize(CSize(nHandleSize/2, nHandleSize/2)).cx; nDragHandle = pObj->HitTest(ptReal,dHandleSize,TRUE); if (nDragHandle != 0) { selectMode = ESelectMode::size; //GetView()->SetCapture(); } else { selectMode = ESelectMode::move; //GetView()->SetCapture(); } } else { OnDraw(GetDC()); //GetView()->SetCapture(); } //刷新属性页 //CXTPPropertyGrid &grid = GetPropertyGrid(GetDoc()->GetMainFrame()); //InitPropertyGrid(grid); } void CItemVirtualWell::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk) { m_firstPoint = m_lastPoint = point; m_bLDown = FALSE; CPoint2D ptDown = GetDC()->GetReal(m_downPoint); CPoint2D ptLast = GetDC()->GetReal(m_lastPoint); if(m_pVirtualWell == NULL) { double yMin = min(ptDown.y0,ptLast.y0); double yMax = max(ptDown.y0,ptLast.y0); if (fabs(yMin-yMax)==0.0) { ReleaseCapture(); return; } m_pVirtualWell = new CVirtualWellObj; m_pVirtualWell->GetPos().left = ptDown.x0-20; m_pVirtualWell->GetPos().right = ptDown.x0+20; m_pVirtualWell->GetPos().bottom = min(ptDown.y0, ptLast.y0); m_pVirtualWell->GetPos().top = max(ptDown.y0, ptLast.y0); CWellSection* pWellSection = GetItemSection()->GetWellSection(); m_pVirtualWell->SetParent(pWellSection); pWellSection->m_VirtualWellList.AddTail(m_pVirtualWell); m_pVirtualWell->ComputeBendValueLevel(); m_pVirtualWell = NULL; m_bLDown = FALSE; } else { CPoint2D delta(ptLast.x0-ptDown.x0,0/*ptLast.y0-ptDown.y0*/); if((m_downPoint.x-m_lastPoint.x)!=0 || (m_downPoint.y-m_lastPoint.y)!=0) { if (IsCaptureState()) { if(NULL != m_pItemSection) m_pItemSection->SetReUnDoAction(); if (selectMode==CItemSelect::size && nDragHandle!=0) { //内置对象交互句柄 m_pVirtualWell->MoveHandleTo(nDragHandle, ptLast); GetDoc()->Invalidate(); // m_pVirtualWell->GetParent()); } else if (selectMode==CItemSelect::move) { CRect8 position = m_pVirtualWell->GetPos(); m_pVirtualWell->m_delta.x0 = delta.x0; m_pVirtualWell->m_delta.y0 = 0; position.OffsetRect(delta.x0, delta.y0); m_pVirtualWell->MoveTo(position); } } } m_bDrag = FALSE; nDragHandle = 0; } GetDoc()->Invalidate(); ReleaseCapture(); } int CItemVirtualWell::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point) { if(m_bAdd) { ::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_RANGE)); CPoint2D lastPoint = GetDC()->GetReal(point); if(IsCaptureState() && m_bLDown) { OnDraw(GetDC()); m_bDrag = TRUE; m_lastPoint = point; OnDraw(GetDC()); } } else { if(m_pVirtualWell == NULL) return 0; CPoint2D lastPoint = GetDC()->GetReal(point); if(IsCaptureState()) { OnDraw(GetDC()); m_bDrag = TRUE; m_lastPoint = point; OnDraw(GetDC()); m_firstPoint = m_lastPoint; } else m_lastPoint = point; } return 1; } BOOL CItemVirtualWell::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { if(m_bAdd) { ::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_RANGE)); } else { CPoint2D lastPoint = GetDC()->GetReal(m_lastPoint); int nHandleSize = HANDLESIZE; // ::GetPreferences().WorkaroundHandle.m_nHandleSize; double dHandleSize = GetDC()->GetRealSize(CSize(nHandleSize/2, nHandleSize/2)).cx; int nHandle = m_pVirtualWell->HitTest(lastPoint,dHandleSize,TRUE); if(nHandle!=0) { ::SetCursor(GetHandleCursor(nHandle)); return TRUE; } else { CRect8 rt = CRect8(lastPoint.x0, lastPoint.y0, lastPoint.x0, lastPoint.y0); if(m_pVirtualWell->Intersects(rt, dHandleSize)) { ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL)); return TRUE; } } } ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_UPARROW)); return TRUE; //GetDoc()->GetCursor().SetCursor(CursorSelect); //return GetDoc()->GetCursor().SetCursor(); } int CItemVirtualWell::DeleteSelection(void) { if(GetDrawObj() == NULL) return 0; CWellSection* pWellSection = (CWellSection*)m_pVirtualWell->GetParent(); POSITION posFind = pWellSection->m_VirtualWellList.Find(m_pVirtualWell); pWellSection->m_VirtualWellList.RemoveAt(posFind); delete m_pVirtualWell; return 1; } }