#include "StdAfx.h" #include "ItemWellSection.h" #include "WellPoleLib/WellCommonDef.h" #include "WellPoleLib/WellBaseObj.h" #include "WellPoleLib/WellClassObjGroup.h" #include "WellPoleLib/InTrackDepthSegment.h" #include "WellPoleLib\InTrackResult.h" #include "WellPoleLib\InTrackLayerGroup.h" #include "WellPoleLib/WellPole.h" #include "MultiWellSectionLib/FaultObj.h" #include "MultiWellSectionLib\BendObj.h" #include "MultiWellSectionLib/SectionWellObj.h" #include "MultiWellSectionLib\WellSection.h" #include "MultiWellSectionLib\VirtualWellObj.h" #include "MultiWellSectionLib\MWSectionScaleBox.h" //#include "WellPoleLib\InTrackStandardLayer.h" #include "../ItemWellBase.h" #include "ItemBend.h" #include "ItemFault.h" #include "ItemAddFault.h" #include "ItemVirtualWell.h" #include "ItemSectionWell.h" #include "ItemWcsTrackIn.h" #include "MultiWellSectionDoc.h" #include "MultiWellSectionlView.h" //#include "GDataBinder/DataBindTemplate.h" BOOL GetLinesWithSegmentPt1(PointF &tp, PointF down, PointF local, PointF LinePt1, PointF LinePt2) { double x, y; // 获取这两条线段所占的矩形区域 if (LinePt1.X == LinePt2.X&&local.X == down.X) return FALSE; if (LinePt1.Y == LinePt2.Y&&local.Y == down.Y) return FALSE; if (abs((local.X - down.X)*(LinePt1.Y - LinePt2.Y) - (local.Y - down.Y)*(LinePt1.X - LinePt2.X)) < 0.000001) return FALSE; //两条直线平行 //如果某一条线段为横向水平线段 //if (fabs(down.X-local.X)<0.001) if (down.X == local.X) { //那么交点的横坐标一定和该线段上所有点的横坐标相同 tp.X = down.X; // 根据直角三角形三边之间的关系可以得出交点的纵坐标,看不懂的可以自己画个图 tp.Y = LinePt1.Y + (LinePt2.Y - LinePt1.Y)*(tp.X - LinePt1.X) / (LinePt2.X - LinePt1.X); } else//同理根据直角三角形三边之间的关系可以确立下面的公式,看不懂的可以自己画个图 { x = ((local.Y - down.Y)*(LinePt2.X - LinePt1.X)*down.X - (LinePt2.Y - LinePt1.Y)*(local.X - down.X)*LinePt1.X + (LinePt1.Y - down.Y)*(local.X - down.X)*(LinePt2.X - LinePt1.X)) / ((local.Y - down.Y)*(LinePt2.X - LinePt1.X) - (local.X - down.X)*(LinePt2.Y - LinePt1.Y)); tp.X = x;//+0.000001; //double k1,k2; //k1 = (down.Y - local.Y)/(down.X - local.X); k2 = (LinePt1.Y - LinePt2.Y)/(LinePt1.X - LinePt2.X); //double b1,b2; //b1 = down.Y - k1*down.X; b2 = LinePt1.Y - k2*LinePt1.X; //double xx = (b2-b1)/(k1-k2); y = down.Y + (local.Y - down.Y)*(x - down.X) / (local.X - down.X); tp.Y = y;//+0.000001; if (LinePt1.Y == LinePt2.Y) tp.Y = LinePt1.Y; } double maxx, minx, maxy, miny; maxx = down.X > local.X ? down.X : local.X; minx = down.X > local.X ? local.X : down.X; maxy = down.Y > local.Y ? down.Y : local.Y; miny = down.Y > local.Y ? local.Y : down.Y; double lmaxx, lminx, lmaxy, lminy; lmaxx = LinePt1.X > LinePt2.X ? LinePt1.X : LinePt2.X; lminx = LinePt1.X > LinePt2.X ? LinePt2.X : LinePt1.X; lmaxy = LinePt1.Y > LinePt2.Y ? LinePt1.Y : LinePt2.Y; lminy = LinePt1.Y > LinePt2.Y ? LinePt2.Y : LinePt1.Y; if (((minx - 0.000001) < tp.X && tp.X < (maxx + 0.000001)) && (miny - 0.000001 < tp.Y && tp.Y < (maxy + 0.000001)) && ((lminx - 0.000001) < tp.X && tp.X < (lmaxx + 0.000001)) && (lminy - 0.000001 < tp.Y && tp.Y < (lmaxy + 0.000001))) return TRUE; return FALSE; } BOOL IsValidIntersect(PointF tp, int ptNum1, int l1id1, PointF down, int l1id2, PointF local, int ptNum2, int l2id1, PointF LinePt1, int l2id2, PointF LinePt2) { BOOL b = FALSE; double dis = 1; double tmp; if (l1id1 == 0) { tmp = sqrt((tp.X - down.X)*(tp.X - down.X) + (tp.Y - down.Y)*(tp.Y - down.Y)); if (tmp < dis) return b; } if (l1id2 == ptNum1 - 1) { tmp = sqrt((tp.X - local.X)*(tp.X - local.X) + (tp.Y - local.Y)*(tp.Y - local.Y)); if (tmp < dis) return b; } if (l2id1 == 0) { tmp = sqrt((tp.X - LinePt1.X)*(tp.X - LinePt1.X) + (tp.Y - LinePt1.Y)*(tp.Y - LinePt1.Y)); if (tmp < dis) return b; } if (l2id2 == ptNum2 - 1) { tmp = sqrt((tp.X - LinePt2.X)*(tp.X - LinePt2.X) + (tp.Y - LinePt2.Y)*(tp.Y - LinePt2.Y)); if (tmp < dis) return b; } b = TRUE; return b; } namespace NItem { CItemWellSection::CItemWellSection(CSigmaDoc* pDoc) : CItemWcsSingleWell(pDoc) { SetType(ITEM_WELLSECTION); m_bUseAddItem = FALSE; m_pItemOilWaterBoundary = NULL; m_pWellSection = NULL; //m_bDeleteControls = TRUE; //CMapSectionCtrl* pmf = (CMapSectionCtrl*)GetDoc()->GetActiveFrame()->GetMapCtrl(); //if(pmf)pmf->ShowToolBar(IDR_TOOLBAR_SECTIONWELL, TRUE); } CItemWellSection::~CItemWellSection(void) { if(m_pItemOilWaterBoundary != NULL) { delete m_pItemOilWaterBoundary; m_pItemOilWaterBoundary = NULL; } //CMapSectionCtrl* pmf = (CMapSectionCtrl*)GetDoc()->GetActiveFrame()->GetMapCtrl(); //if(pmf)pmf->ShowToolBar(IDR_TOOLBAR_SECTIONWELL, FALSE); } CWellSection *CItemWellSection::GetWellSection() { return this->m_pWellSection; // (CWellSection *)GetDoc()->GetDraw()->GetAtValue(GetPos()); } CItemWellBase* CItemWellSection::CreateItem(CWellBaseObj* pObj) { CItemWellBase* pItem = NULL; if(pObj->GetType() == KEP_WELL) { CItemSectionWell* pItemSectionWell = new CItemSectionWell(GetDoc()); pItem = pItemSectionWell; pItem->SetPos(GetPos()); pItemSectionWell->SetDrawObj(pObj); //pItemSectionWell->SetWellFrame(FALSE); } else if(pObj->GetType() == KEP_SECTIONBEND) { pItem = new CItemBend(GetDoc()); pItem->SetPos(GetPos()); ((CItemBend*)pItem)->SetDrawObj(pObj); pItem->m_WellObjSelectlist.AddTail(pObj); } else if (pObj->GetType()==KEP_SECTIONFAULT) { pItem = new CItemFault(GetDoc()); pItem->SetPos(GetPos()); ((CItemFault*)pItem)->SetDrawObj(pObj); } //else if (pObj->GetType()==KEP_SECTIONRULER) //{ // pItem = new CItemRuler(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemRuler*)pItem)->SetDrawObj((CRulerObj*)pObj); //} else if (pObj->GetType()==KEP_SECTIONVIRTUALWELL) { pItem = new CItemVirtualWell(GetDoc()); pItem->SetPos(GetPos()); ((CItemVirtualWell*)pItem)->SetDrawObj((CVirtualWellObj*)pObj); } //else if (pObj->GetType()==KEP_SECTIONSCALEBOX) //{ // pItem = new CItemScaleBox(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemScaleBox*)pItem)->SetDrawObj(pObj); //} else if (pObj->GetType()==KEP_TEXTBOX) { //pItem = new CItemTextBox(GetWnd()); //pItem->SetPos(GetPos()); //((CItemTextBox*)pItem)->SetDrawObj(pObj); } else if (pObj->GetType()==KEP_MARK) { //pItem = new CItemWellMark(GetWnd()); //pItem->SetPos(GetPos()); //((CItemWellMark*)pItem)->SetDrawObj(pObj); } //else if (pObj->GetType()==DOUBLEFOX_ELLIPSE) //{ // pItem = new CItemWellEllipse(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemWellEllipse*)pItem)->SetDrawObj(pObj); //} //else if (pObj->GetType()==DOUBLEFOX_ARC) //{ // pItem = new CItemWellArc(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemWellArc*)pItem)->SetDrawObj(pObj); //} //else if (pObj->GetType()==KEP_SECTIONLINE) //{ // pItem = new CItemWellEquilateral(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemWellEquilateral*)pItem)->SetDrawObj(pObj); //} //else if (pObj->GetType()==KEP_SECTIONLEGEND) //{ // pItem = new CItemLegend(GetWnd()); // pItem->SetPos(GetPos()); // ((CItemLegend*)pItem)->SetDrawObj(pObj); //} if(pItem != NULL) pItem->SetItemSection(this); return pItem; } void CItemWellSection::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) { if(m_bUseAddItem) { if(m_pItemSelected != NULL) { m_pItemSelected->OnLButtonDown(pDC,nFlags,point,vk); return; } } m_bLDown = TRUE; CPoint2D ptReal = GetDC()->GetReal(point); m_downPoint = m_firstPoint = m_lastPoint = point; selectMode = ESelectMode::selnone; CWellSection *pWellSection = GetWellSection(); CWellBaseObj* pObj = NULL; if (m_WellObjSelectlist.GetCount()==1) { pObj = m_WellObjSelectlist.GetHead(); int nHandleSize = HANDLESIZE; double dHandleSize = GetDC()->GetRealSize(CSize(nHandleSize/2, nHandleSize/2)).cx; nDragHandle = pObj->HitTest(ptReal,dHandleSize,TRUE); if (nDragHandle!=0) { if(m_pItemSelected != NULL) { //m_pItemSelected->OnLButtonDown(pDC,nFlags, point,vk); //return; if (m_pItemSelected->GetType() != ITEM_BEND) { m_pItemSelected->OnLButtonDown(pDC, nFlags, point, vk); return; } else {//Bend 对象的选中操作复杂,内部有几个选中区域,只有本次Hit的点与前次选中的区域匹配才能认为是有效DragHandle. CItemBend* pItemBend = (CItemBend*)m_pItemSelected; CBendObj* pBend = (CBendObj*)pObj; if (pItemBend->m_SelectCurveMode == CItemBend::CurveBend && pBend->m_HitTestSelectId == 1) { pItemBend->OnLButtonDownAfterHitTest(nFlags, point, nDragHandle,pDC); return; } else if (pItemBend->m_SelectCurveMode == CItemBend::CurveTopLine && pBend->m_HitTestSelectId == 2) { pItemBend->OnLButtonDownAfterHitTest(nFlags, point, nDragHandle, pDC); return; } else if (pItemBend->m_SelectCurveMode == CItemBend::CurveBotLine && pBend->m_HitTestSelectId == 3) { pItemBend->OnLButtonDownAfterHitTest(nFlags, point, nDragHandle, pDC); return; } else { nDragHandle = 0; } } } if (nDragHandle != 0) { selectMode = ESelectMode::size; } } } if (selectMode==CItemSelect::selnone) { int nHandleSize= HANDLESIZE; double dHandleSize = GetDC()->GetRealSize(CSize(nHandleSize/2, nHandleSize/2)).cx; CRect8 r(ptReal.x0,ptReal.y0,ptReal.x0,ptReal.y0); CSize8 sz=GetDoc()->GetSelectSize(); double sx=GetDC()->GetRealWidth(sz.cx); double sy=fabs(GetDC()->GetRealHeight(sz.cy)); r.InflateRect(sx,sy); pObj = pWellSection->ObjectAt(r,dHandleSize); BOOL bChange = FALSE; if(!IsSelected(pObj)) { bChange = TRUE; //OnDraw(GetDC()); if(m_pItemSelected != NULL) {//井柱的选中操作使用的是贴图绘制方式,即将选中的状态画到一个图片上,然后贴到memdc上,其它对象的选中绘制是使用Rop2方式,两种方式需要协调一致。 BOOL oldItemWell = m_pItemSelected->GetType() == ITEM_SECTIONWELL ? TRUE : FALSE; if (!oldItemWell) OnDraw(GetDC()); //当选中的不是井时,需要绘制一次,消除前一个对象的绘制。 delete m_pItemSelected; m_pItemSelected = NULL; CMultiWellSectionView *pView = (CMultiWellSectionView*)GetView(); if (oldItemWell) {//当前一个对象不是井时,需要重新绘制一次选择bmpdc,清楚上次井的对象的影响。 DrawHandle(GetDC());// (&xyDC); } else { if (pObj != NULL && pObj->GetType() == KEP_WELL) GetDoc()->Invalidate();//当本次对象选中井时,重绘一次整个的memdc,可以清除上次选中对象的影响。 } } } //选中 Select(pObj); if(pObj!=NULL) { selectMode = ESelectMode::move; if(m_pItemSelected == NULL) { m_pItemSelected = CreateItem((CWellBaseObj*)pObj); //if(m_pItemSelected != NULL) // OnDraw(GetDC()); } if(m_pItemSelected != NULL) { if (bChange) { m_pItemSelected->OnLButtonDown(pDC,nFlags, point,vk); OnDraw(GetDC(),pDC); return; //需要返回,因为内部的item会修改属性页。 } else { if (m_pItemSelected->GetType() != ITEM_WELL)//同一层位对象内部的选中状态发生了变化,所以需要自绘一次消除上次的影响。 { //m_pItemSelected->OnDraw(GetDC(),pDC); m_pItemSelected->OnLButtonDown(pDC,nFlags, point,vk); //m_pItemSelected->OnDraw(GetDC(),pDC); //OnDraw(GetDC()); return; //需要返回,因为内部的item会修改属性页。 } } } else { //GetView()->SetCapture(); } } else { //m_WellObjSelectlist.RemoveAll(); if(m_pItemSelected != NULL) { m_pItemSelected->OnLButtonDown(pDC,nFlags, point,vk); return; } c_down = ptReal; c_last = ptReal; selectMode = netSelect; //GetView()->SetCapture(); } if(bChange) OnDraw(GetDC(),pDC); } //刷新属性页 } void CItemWellSection::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk) { //if (m_pItemOilWaterBoundary!=NULL) //{ // ReleaseCapture(); // m_bDrag = FALSE; // m_bLDown = FALSE; // nDragHandle = 0; // delete m_pItemOilWaterBoundary; // m_pItemOilWaterBoundary=NULL; //} if(m_pItemSelected != NULL) { m_pItemSelected->OnLButtonUp(pDC,nFlags, point,vk); return ; } m_firstPoint = m_lastPoint = point; CPoint2D downPoint = GetDC()->GetReal(m_downPoint); CPoint2D lastPoint = GetDC()->GetReal(m_lastPoint); if((m_downPoint.x-m_lastPoint.x)!=0 || (m_downPoint.y-m_lastPoint.y)!=0) { if (m_WellObjSelectlist.GetCount() == 1) { CWellBaseObj* pObj = (CWellBaseObj* )m_WellObjSelectlist.GetHead(); CRect rect = GetDC()->GetScreen(pObj->GetPos()); rect.InflateRect(10,10); GetDoc()->Invalidate(); if (IsCaptureState()) { SetReUnDoAction(); if(selectMode==CItemSelect::move) { CRect8 position = pObj->GetPos(); CPoint2D delta(lastPoint.x0-downPoint.x0,lastPoint.y0-downPoint.y0); pObj->m_delta = delta; position.OffsetRect(delta.x0, delta.y0); pObj->MoveTo(position); } else if (selectMode==CItemSelect::size && nDragHandle!=0) { //内置对象交互句柄 pObj->m_delta = CPoint2D(0,0); CRect8 oldRectReal = pObj->GetPos(); pObj->MoveHandleTo(nDragHandle, lastPoint); CRect8 newRectReal = pObj->GetPos(); ////矩阵变换(针对椭圆类图元) //REAL elements[6]; memset(elements,0,sizeof(REAL)*6); //elements[0] = newRectReal.Width()/oldRectReal.Width(); //elements[1] = 0.0; //elements[2] = 0.0; //elements[3] = newRectReal.Height()/oldRectReal.Height(); //elements[4] = (double)m_lastPoint.x - (double)m_downPoint.x*elements[0]; //elements[5] = (double)m_lastPoint.y - (double)m_downPoint.y*elements[3]; //pObj->Transform(GetDC(), elements); } //重新计算剖面范围 CWellSection* pWellSection = GetWellSection(); pWellSection->ReSetPosition(); //GetView()->SetScrollBarRange(); rect = GetDC()->GetScreen(pObj->GetPos()); rect.InflateRect(10,10); GetDoc()->Invalidate(); } } } m_bDrag = FALSE; m_bLDown = FALSE; nDragHandle = 0; CRect8 rect=GetRect(); DrawMode(pDC,&rect); ReleaseCapture(); if(selectMode == netSelect) DoLButtonUp(pDC); } void CItemWellSection::DoLButtonUp(CDC* pDC) { if(m_WellObjSelectlist.GetCount() > 0) return; CRect8 rect=GetRect(); CWellSection* pWellSection = GetWellSection(); CBendObj* pBend = NULL; POSITION pos = pWellSection->m_BendList.GetTailPosition(); while(pos != NULL) { pBend = (CBendObj *)pWellSection->m_BendList.GetPrev(pos); if (pBend->IsInRange(rect)) { m_WellObjSelectlist.AddTail(pBend); } } if(m_WellObjSelectlist.GetCount() > 0) { CItemBend* pItemBend= new CItemBend(GetDoc()); SetItem(pItemBend); pItemBend->SetItemSection(this); pItemBend->SetSelectCurveMode(CItemBend::CurveBend); pItemBend->SetPos(GetPos()); pos = m_WellObjSelectlist.GetHeadPosition(); while(pos != NULL) pItemBend->m_WellObjSelectlist.AddTail(m_WellObjSelectlist.GetNext(pos)); //m_WellObjSelectlist.RemoveAll(); pItemBend->OnDraw(GetDC(), pDC); } } int CItemWellSection::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point) { //if (m_pItemOilWaterBoundary!=NULL) //{ // m_pItemOilWaterBoundary->OnMouseMove(pDC, nFlags, point); // return; //} if(m_pItemSelected != NULL) { m_pItemSelected->OnMouseMove(pDC,nFlags, point); return 0; } if(m_WellObjSelectlist.GetCount() == 0) { CItemSelect::OnMouseMove(pDC,nFlags, point); return 1; } CPoint2D lastPoint = GetDC()->GetReal(point); CWellBaseObj* pObjSelected = m_WellObjSelectlist.GetHead(); if(IsCaptureState() && m_bLDown) { //刷新 OnDraw(GetDC(), pDC); m_bDrag = TRUE; m_lastPoint = point; if (selectMode==CItemSelect::move)// 移动图元(道头、曲线头) { CPoint2D endPoint = GetDC()->GetReal(m_lastPoint); CPoint2D startPoint = GetDC()->GetReal(m_firstPoint); CPoint2D delta(endPoint.x0-startPoint.x0,endPoint.y0-startPoint.y0); pObjSelected->SetDelta(delta); } //刷新 OnDraw(GetDC(), pDC); m_firstPoint = m_lastPoint; } else m_lastPoint = point; return 1; } BOOL CItemWellSection::OnSetCursor(CPoint pt, int& handle) { //if (m_pItemOilWaterBoundary!=NULL) //{ // return m_pItemOilWaterBoundary->OnSetCursor(pWnd, nHitTest, message); //} if(m_pItemSelected != NULL) { return m_pItemSelected->OnSetCursor( pt, handle); } if(m_WellObjSelectlist.GetCount() == 0) { //SetCursor(AfxGetApp()->LoadStandardCursor(IDC_UPARROW)); handle = -1; return TRUE; } CWellBaseObj* pObjSelected = m_WellObjSelectlist.GetHead(); CPoint2D lastPoint = GetDC()->GetReal(m_lastPoint); int nHandleSize = HANDLESIZE; // double dHandleSize = GetDC()->GetRealSize(CSize(nHandleSize/2, nHandleSize/2)).cx; int nHandle = pObjSelected->HitTest(lastPoint,dHandleSize,TRUE); if (nHandle != 0) { handle = -1; } else handle = 4; return TRUE; } int CItemWellSection::GetSubMenu() { // 井 int iRMenu = 0; //if (m_pItemSelected!=NULL) //{ // if (m_pItemSelected->GetType()==ITEM_VIRTUALWELL) // { // iRMenu = 35; // } // else if (m_pItemSelected->GetType()==ITEM_SCALE_RULER) // { // iRMenu = 37; // } // else if (m_pItemSelected->GetType()==ITEM_FAULT) // { // iRMenu = 39; // } // //else if (m_pItemSelected->GetType()==ITEM_TEXTBOX) // //{ // // iRMenu = 41; // //} // //else if (m_pItemSelected->GetType()==ITEM_WELLMARK) // //{ // // iRMenu = 42; // //} // else // return m_pItemSelected->GetSubMenu(); //} if(m_WellObjSelectlist.GetCount() == 0) return 0; if (m_pItemSelected != NULL) return m_pItemSelected->GetSubMenu(); return iRMenu; } void CItemWellSection::OnDraw(CXyDC* pXyDC) { DrawHandle(pXyDC);// (GetDC()); if(m_pItemSelected != NULL) { m_pItemSelected->OnDraw(pXyDC); } } void CItemWellSection::OnDraw(CXyDC* pXyDC,CDC* pDC) { DrawHandle(pXyDC);// (GetDC()); if (m_pItemSelected != NULL) { m_pItemSelected->OnDraw(pXyDC,pDC); } } //删除井并删除相关bend层 void CItemWellSection::RemoveWell(CWellPole* pWellObj) { CWellSection* WellSection = GetWellSection(); POSITION posFind = WellSection->m_WellList.Find(pWellObj); POSITION posTemp = posFind; CWellPole* pPreWell = NULL; CWellPole* pNextWell = NULL; if (posFind==WellSection->m_WellList.GetHeadPosition()) { WellSection->m_WellList.GetNext(posTemp); if (posTemp!=NULL) { pNextWell = (CWellPole*)WellSection->m_WellList.GetNext(posTemp); } } else if (posFind==WellSection->m_WellList.GetTailPosition()) { WellSection->m_WellList.GetPrev(posTemp); if (posTemp!=NULL) { pPreWell = (CWellPole*)WellSection->m_WellList.GetPrev(posTemp); } } else { WellSection->m_WellList.GetPrev(posTemp); if (posTemp!=NULL) { pPreWell = (CWellPole*)WellSection->m_WellList.GetPrev(posTemp); } posTemp = posFind; (CWellPole*)WellSection->m_WellList.GetNext(posTemp); if (posTemp!=NULL) { pNextWell = (CWellPole*)WellSection->m_WellList.GetNext(posTemp); } } if (posFind!=NULL) { BOOL b1 = FALSE; BOOL b2 = FALSE; BOOL b3 = FALSE; POSITION posBend = WellSection->m_BendList.GetHeadPosition(); while (posBend!=NULL) { CBendObj* pBend = (CBendObj*)WellSection->m_BendList.GetNext(posBend); if (pBend->m_pWellLeft == pWellObj || pBend->m_pWellRight == pWellObj) WellSection->DeleteBend(pBend); //b1 = FALSE; //b2 = FALSE; //b3 = FALSE; //CBendObj* pBend = (CBendObj*)WellSection->m_BendList.GetNext(posBend); //if (pBend->m_pLayerLeft->GetWell() == pWellObj||(pBend->m_pLayerRight!=NULL&&pBend->m_pLayerRight->GetWell() ==pWellObj)) //{ // b1 = TRUE; //} //if (pPreWell!=NULL) //{ // if (pBend->m_pLayerLeft->GetWell() == pPreWell&&pBend->m_pLayerRight==NULL&&pBend->m_ptEndBreak.x0>pPreWell->GetPos().right) // { // b2 = TRUE; // } //} //if (pNextWell!=NULL) //{ // if (pBend->m_pLayerLeft->GetWell() == pNextWell&&pBend->m_pLayerRight==NULL&&pBend->m_ptEndBreak.x0GetPos().left) // { // b3 = TRUE; // } //} //if (b1||b2||b3) //{ // WellSection->DeleteBend(pBend); //} } WellSection->m_WellList.RemoveAt(posFind); m_pItemSelected = NULL; delete pWellObj; m_WellObjSelectlist.RemoveAll(); } } void CItemWellSection::OnLButtonDblClk(UINT nFlags, CPoint point) { if(m_bUseAddItem) { SetState(FALSE); if(m_pItemSelected != NULL) { if (m_pItemSelected->GetType()==ITEM_ADDFAULT) { m_pItemSelected->OnLButtonDblClk(nFlags,point);//当新断层建立时,执行该函数后,m_pItemSelected将由CItemAddFault变化为CItemFault Invalidate(); return; } delete m_pItemSelected; } m_pItemSelected = NULL; } else { if(m_pItemSelected != NULL) { m_pItemSelected->OnLButtonDblClk(nFlags,point);//当新断层建立时,执行该函数后,m_pItemSelected将由CItemAddFault变化为CItemFault } } } void CItemWellSection::Clear() { if(m_pItemSelected != NULL) delete m_pItemSelected; m_pItemSelected = NULL; if(m_pItemOilWaterBoundary != NULL) delete m_pItemOilWaterBoundary; m_pItemOilWaterBoundary = NULL; m_WellObjSelectlist.RemoveAll(); } void CItemWellSection::DeleteItem() { CItemWellBase::DeleteItem(); if(m_pItemOilWaterBoundary != NULL) delete m_pItemOilWaterBoundary; m_pItemOilWaterBoundary = NULL; m_WellObjSelectlist.RemoveAll(); } int CItemWellSection::DeleteSelection(void) { //if (m_WellObjSelectlist.GetCount() == 0) //{ // return; //} if (m_pItemSelected!=NULL) { if (m_pItemSelected->GetType() == ITEM_BEND || m_pItemSelected->GetType() == ITEM_FAULT) SetReUnDoAction(FALSE, IDS_STRING_ACTION_MOVE,2); else SetReUnDoAction(FALSE); ((CItemWellBase*)m_pItemSelected)->DeleteSelection(); } if (m_pItemSelected) delete m_pItemSelected; m_pItemSelected = NULL; Clear(); GetWellSection()->ReSetPosition(); //GetView()->SetScrollBarRange(); GetDoc()->Invalidate(); return 1; } void SetBendDataForDFOld(CWellSection* pSection ,CBendObj* pBend ,CWellPole* pWell,CWellPole* pWellAnother, CWellBaseObj*pLayerDrawObj , CWellBaseObj* pTrackInObject, int nInt) { double xLeftValue, xRightValue; pBend->GetBendXValue(xLeftValue, xRightValue); pBend->m_nLithoBreakStyle = 2; pBend->m_fLithoBreakWidth = 0.1; pBend->m_fTopLithoBreakPoint = 0.5; pBend->m_fBottomLithoBreakPoint = 0.5; pBend->m_fOutBendControlLevel = 0.0; if (pTrackInObject->GetType() == KEP_RESULT) { CInTrackResult* pLayerLeft = (CInTrackResult*)pBend->m_pLayerLeft; CInTrackResult* pLayerRight = (CInTrackResult*)pBend->m_pLayerRight; if ((pLayerLeft->m_strResult != pLayerRight->m_strResult) && !(pLayerLeft->m_strResult == "干层" || pLayerRight->m_strResult == "干层")) { pBend->m_fWaterTop = pBend->m_fGasBottom = pLayerLeft->GetPos().CenterPoint().y0 - (pLayerLeft->GetPos().CenterPoint().y0 - pLayerRight->GetPos().CenterPoint().y0) / 2; } } double yLeftValue = pLayerDrawObj->GetPos().CenterPoint().y0; double yRightValue = pTrackInObject->GetRect().CenterPoint().y0; double HeightLeft = pLayerDrawObj->GetPos().Height(); double HeightRight = pTrackInObject->GetRect().Height(); if (nInt == 1) { pSection->ComputeBendPosition(pBend, yRightValue, yLeftValue, HeightRight, HeightLeft); } else if (nInt == 2) { pSection->ComputeBendPosition(pBend, yLeftValue, yRightValue, HeightLeft, HeightRight); } pBend->AddControlPoints(xLeftValue, yLeftValue, xRightValue, yRightValue, xRightValue - xLeftValue); dfPoint ptTemp; ptTemp.x0 = xLeftValue; ptTemp.y0 = yLeftValue + HeightLeft * 0.5; pBend->m_ptArrCurveTopOld.Add(ptTemp); ptTemp.y0 = yLeftValue - HeightLeft * 0.5; pBend->m_ptArrCurveBotOld.Add(ptTemp); ptTemp.x0 = xRightValue; ptTemp.y0 = yRightValue + HeightRight * 0.5; pBend->m_ptArrCurveTopOld.Add(ptTemp); ptTemp.y0 = yRightValue - HeightRight * 0.5; pBend->m_ptArrCurveBotOld.Add(ptTemp); //添加Bend的断层链表 pBend->SetSlotType(); pBend->BendAddFault(); pBend->ComputeSlopeAndConstant(); pBend->CreateBendLines(); CString strLithoLeft; CString strLithoRight; CString strResultLeft; CString strResultRight; if (pLayerDrawObj->GetType() == KEP_RESULT) { CInTrackResult* pLayerLeft = (CInTrackResult*)pBend->m_pLayerLeft; strLithoLeft = pLayerLeft->m_strLitho; strResultLeft = pLayerLeft->m_strResult; if (NULL != pBend->m_pLayerRight) { CInTrackResult* pLayerRight = (CInTrackResult*)pBend->m_pLayerRight; strLithoRight = pLayerRight->m_strLitho; strResultRight = pLayerRight->m_strResult; } } else if (pLayerDrawObj->GetType() == KEP_LAYERGROUP) { CInTrackLayerGroup* pLayerLeft = (CInTrackLayerGroup*)pBend->m_pLayerLeft; strLithoLeft = pLayerLeft->m_strLitho; if (NULL != pBend->m_pLayerRight) { CInTrackLayerGroup* pLayerRight = (CInTrackLayerGroup*)pBend->m_pLayerRight; strLithoRight = pLayerRight->m_strLitho; } } if ((/*!strLithoLeft.IsEmpty() && !strLithoRight.IsEmpty() && */strLithoLeft != strLithoRight) || (/*!strResultLeft.IsEmpty() && !strResultRight.IsEmpty() && */strResultLeft != strResultRight)) { pBend->bBreakLithoTemp = TRUE; pBend->CreateBendLithoBreak(); } pBend->CreateBendFills(); pBend->SetShowFill(TRUE); pBend->SetShowTopLine(TRUE); pBend->SetShowBotLine(TRUE); if (pSection->IsStratumSmooth()) { pBend->SmoothBendLines(); } } void SetBendDataForResFormPCG(CWellSection* pSection, CBendObj* pBend, CWellPole* pWell, CWellPole* pWellAnother, CWellBaseObj*pLayerDrawObj, CWellBaseObj* pTrackInObject, int nInt) { pBend->SetSlotType(); if (pBend->m_pLayerRight->GetPos().left > pBend->m_pLayerLeft->GetPos().left) { pBend->m_ptBeginBreak.x0 = pBend->m_pLayerLeft->GetPos().right; pBend->m_ptBeginBreak.y0 = pBend->m_pLayerLeft->GetPos().CenterPoint().y0; CWellPole* pWellLeft = pBend->m_pWellLeft; pBend->m_ptEndBreak.x0 = pBend->m_pLayerRight->GetPos().left; pBend->m_ptEndBreak.y0 = pBend->m_pLayerRight->GetPos().CenterPoint().y0; } //逆连层 else { pBend->m_ptBeginBreak.x0 = pBend->m_pLayerLeft->GetPos().left; pBend->m_ptBeginBreak.y0 = pBend->m_pLayerLeft->GetPos().CenterPoint().y0; pBend->m_ptEndBreak.x0 = pBend->m_pLayerRight->GetPos().right; pBend->m_ptEndBreak.y0 = pBend->m_pLayerRight->GetPos().CenterPoint().y0; } pBend->InitBendControlPoints(); } BOOL compareTwoLayerName(CInTrackDepthSegment* pParentInTrack , CInTrackDepthSegment* pParentThatIn) { if (pParentInTrack->GetType() != pParentThatIn->GetType()) return FALSE; if (pParentInTrack->GetLayerName() == pParentThatIn->GetLayerName()) return TRUE; return FALSE; } //是否有bend与这个线段交叉 BOOL ComputeIntersectBend(CWellSection *pSection, CPoint2D pt1, CPoint2D pt2, CString leftWell, CString rightWell) { CPoint2D bpt1, bpt2, rpt; POSITION pos = pSection->m_BendList.GetHeadPosition(); while (pos != NULL) { CBendObj *pBend = (CBendObj*)pSection->m_BendList.GetNext(pos); if (pBend->m_pLayerRight != NULL) { if (pBend->m_pWellLeft->GetWellName() == leftWell && pBend->m_pWellRight->GetWellName() == rightWell) { bpt1 = pBend->m_pLayerLeft->GetRect().CenterPoint(); bpt2 = pBend->m_pLayerRight->GetRect().CenterPoint(); if (nsWellPoleFunc::LineIntersect(rpt, pt1, pt2, bpt1, bpt2)) { return TRUE; } } } } return FALSE; } ////////////// 层按左右名称添加连层 void CItemWellSection::ConnectOnName(CWellBaseObj* pLayerDrawObj,int nInt, std::vector& linkbends) { linkbends.clear(); ETrackType trackTypeClass[4]; //地层道的级别 trackTypeClass[0] = Track_Stratum; trackTypeClass[1] = Track_OilLayerGroup; trackTypeClass[2] = Track_SandLayer; trackTypeClass[3] = Track_Result; CTrackObj* pTrack = (CTrackObj*)pLayerDrawObj->GetParent(); int trackClassId = -1; for (int i = 0; i < 4; i++) { if (trackTypeClass[i] == pTrack->GetTrackType()) { trackClassId = i; break; } } CTrackObj* pthisParent = NULL; CWellPole * pWell = (CWellPole *)pTrack->GetParent(); if (trackClassId > 0) {//获得当前连地层的父级别的地层道 for (int i = trackClassId - 1; i > -1; i--) { TRACKLIST tracklist; pWell->GetAllTrack(&tracklist, trackTypeClass[i]); if (tracklist.size() > 0) { if ((*tracklist.begin())->GetChildren().size() > 0) { pthisParent = (*tracklist.begin()); break; } } } } CInTrackDepthSegment* pCurrentInTrack = (CInTrackDepthSegment*)pLayerDrawObj; CInTrackDepthSegment* pParentInTrack = NULL; if (pthisParent != NULL) { WELLOBJLIST::iterator it = pthisParent->GetChildren().begin(); for (; it!= pthisParent->GetChildren().end(); it++) { if ((*it)->IsTrackChildTopEnd()) { CInTrackDepthSegment* ptIn = (CInTrackDepthSegment*)(*it); if ((ptIn->m_fSdep - 0.0001) < pCurrentInTrack->m_fSdep && (ptIn->m_fEdep + 0.0001) > pCurrentInTrack->m_fEdep) { pParentInTrack = ptIn; break; } } } } CWellSection* pSection = (CWellSection*)pWell->GetParent(); if (NULL == pSection) { return; } CWellPole* pWellAnother = NULL; POSITION posFind = pSection->m_WellList.Find(pWell); if (nInt == 1) { pSection->m_WellList.GetPrev(posFind); } else if (nInt == 2) { pSection->m_WellList.GetNext(posFind); } if (posFind!=NULL) { if (nInt == 2) { pWellAnother = (CWellPole*)pSection->m_WellList.GetNext(posFind); } else if (nInt == 1) { pWellAnother = (CWellPole*)pSection->m_WellList.GetPrev(posFind); } } if (pWellAnother == NULL) { return; } else { CInTrackDepthSegment* pParentThatIn = NULL; CTrackObj* pthatParent = NULL; if (pParentInTrack != NULL) {//搜集两边同级别地层的父级地层道,父级地层, 获得对面井内的父级地层对象 TRACKLIST tracklist; pWellAnother->GetAllTrack(&tracklist, pthisParent->GetTrackType()); if (tracklist.size() > 0) { if ((*tracklist.begin())->GetChildren().size() > 0) { pthatParent = (*tracklist.begin()); WELLOBJLIST::iterator it = pthatParent->GetChildren().begin(); for (; it != pthatParent->GetChildren().end(); it++) { if ((*it)->IsTrackChildTopEnd()) { CInTrackDepthSegment* ptIn = (CInTrackDepthSegment*)(*it); if (compareTwoLayerName(pParentInTrack, ptIn)) { pParentThatIn = ptIn; break; } } } } } } TRACKLIST tracklist; pWellAnother->GetAllTrack(&tracklist, pTrack->GetTrackType()); TRACKLIST::iterator it = tracklist.begin(); for(; it!= tracklist.end(); it++) { CTrackObj* pNextTrackObj = (CTrackObj*)*it; if (pNextTrackObj->GetTrackType() == pTrack->GetTrackType()) { WELLOBJLIST::iterator wit = pNextTrackObj->GetChildren().begin(); for(; wit != pNextTrackObj->GetChildren().end(); wit++) { CWellBaseObj* pTrackInObject = *wit; BOOL bName = FALSE; if (!pTrackInObject->IsTrackChildTopEnd()) { continue; } CInTrackDepthSegment* pt = (CInTrackDepthSegment*)pTrackInObject; if (compareTwoLayerName(pCurrentInTrack, pt) == FALSE) continue; if(ComputeIntersectBend(pSection,pCurrentInTrack->GetRect().CenterPoint(), pt->GetRect().CenterPoint(), pWell->GetWellName(), pWellAnother->GetWellName())) continue; if (pParentThatIn) {//进行连层的判断,防止出现跨越父级的串层。 if ((pParentThatIn->m_fSdep - 0.0001) < pt->m_fSdep && pt->m_fEdep < (pParentThatIn->m_fEdep + 0.0001)) bName = TRUE; } else bName = TRUE; if (bName) { POSITION posBend = pSection->m_BendList.GetHeadPosition(); BOOL bCreate = TRUE; while (posBend!=NULL) { BOOL bFirst,bSceond,bThird; CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetNext(posBend); if (nInt == 1) { /////////若两个层之间已经有连层则跳出 不创建新的连层 bFirst = (pBend->m_pLayerLeft == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerRight == (CInTrackDepthSegment*)pLayerDrawObj) || (pBend->m_pLayerRight == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerLeft == (CInTrackDepthSegment*)pLayerDrawObj); ////////若左边层已经连接了一个尖灭层则跳出 不创建新的连层 bSceond = pBend->m_pLayerLeft == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerRight == NULL && pBend->m_ptArrControls[0].Xm_ptArrControls[1].X;; ////////若当前层已经连接了一个尖灭层则跳出 不创建新的连层 bThird = pBend->m_pLayerLeft == (CInTrackDepthSegment*)pLayerDrawObj && pBend->m_pLayerRight == NULL && pBend->m_ptArrControls[0].X>pBend->m_ptArrControls[1].X;; } else if (nInt == 2) { /////////若两个层之间已经有连层则跳出 不创建新的连层 bFirst = (pBend->m_pLayerLeft == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerRight == (CInTrackDepthSegment*)pLayerDrawObj) || (pBend->m_pLayerRight == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerLeft == (CInTrackDepthSegment*)pLayerDrawObj); ////////若左边层已经连接了一个尖灭层则跳出 不创建新的连层 bSceond = pBend->m_pLayerLeft == (CInTrackDepthSegment*)pTrackInObject && pBend->m_pLayerRight == NULL && pBend->m_ptArrControls[0].X>pBend->m_ptArrControls[1].X; ////////若当前层已经连接了一个尖灭层则跳出 不创建新的连层 bThird = pBend->m_pLayerLeft == (CInTrackDepthSegment*)pLayerDrawObj && pBend->m_pLayerRight == NULL && pBend->m_ptArrControls[0].Xm_ptArrControls[1].X; } if (bFirst || bSceond || bThird) { bCreate = FALSE; } } if (bCreate) { CBendObj *pBend = new CBendObj(); pBend->SetParent(pSection); if (nInt == 1) { pBend->m_pWellLeft = pWellAnother; pBend->m_pWellRight = pWell; pBend->m_pLayerLeft = (CInTrackDepthSegment*)pTrackInObject; pBend->m_LeftLayerName = ((CInTrackDepthSegment*)pTrackInObject)->GetLayerName(); pBend->m_pLayerRight =(CInTrackDepthSegment*)pLayerDrawObj; pBend->m_RightLayerName = ((CInTrackDepthSegment*)pLayerDrawObj)->GetLayerName(); } else { pBend->m_pWellLeft = pWell; pBend->m_pWellRight = pWellAnother; pBend->m_pLayerLeft = (CInTrackDepthSegment*)pLayerDrawObj; pBend->m_LeftLayerName = ((CInTrackDepthSegment*)pLayerDrawObj)->GetLayerName(); pBend->m_pLayerRight = (CInTrackDepthSegment*)pTrackInObject; pBend->m_RightLayerName = ((CInTrackDepthSegment*)pTrackInObject)->GetLayerName(); } pBend->m_ptBeginBreak.x0 = pLayerDrawObj->GetPos().CenterPoint().x0; pBend->m_ptEndBreak.x0 = pTrackInObject->GetRect().CenterPoint().x0; CTrackObj* pTrack1 = (CTrackObj*)pBend->m_pLayerLeft->GetParent(); //// 若添加的连层与相关两口井之间已经存在的连层出现交叉情况则取消连层的创建(注意通过位置进行判断是否bend交叉) POSITION pos = pSection->m_BendList.GetHeadPosition(); BOOL bBreak = FALSE; while(pos != NULL) { CWellBaseObj* pObj = pSection->m_BendList.GetNext(pos); if (pObj->GetType() == KEP_SECTIONBEND) { CBendObj* pBendObj = (CBendObj*)pObj; CTrackObj* pTrack2 = (CTrackObj*)pBendObj->m_pLayerLeft->GetParent(); if (pTrack1->GetTrackType() != pTrack2->GetTrackType()) continue; //如果不是一种类型的层位bend,不用比较 double topLeft,topRight; double TLeft,TRight; if (pBendObj->m_pLayerRight != NULL) { CWellPole* pWellLeft = (CWellPole*)pBendObj->m_pLayerLeft->GetWell(); CWellPole* pWellRight = (CWellPole*)pBendObj->m_pLayerRight->GetWell(); if ((pWellLeft == pWell && pWellRight ==pWellAnother) || (pWellLeft == pWellAnother && pWellRight == pWell)) { if (pBendObj->m_pLayerRight->GetPos().left > pBendObj->m_pLayerLeft->GetPos().left) { topLeft = pBendObj->m_pLayerLeft->GetPos().top; topRight = pBendObj->m_pLayerRight->GetPos().top; } else { topLeft = pBendObj->m_pLayerRight->GetPos().top; topRight = pBendObj->m_pLayerLeft->GetPos().top; } if (pBend->m_pLayerRight->GetPos().left > pBend->m_pLayerLeft->GetPos().left) { TLeft = pBend->m_pLayerLeft->GetPos().top; TRight = pBend->m_pLayerRight->GetPos().top; } else { TLeft = pBend->m_pLayerRight->GetPos().top; TRight = pBend->m_pLayerLeft->GetPos().top; } BOOL bOne = topLeft > TLeft&&topRight < TRight; BOOL bSecond = topLeft < TLeft&&topRight > TRight; if (bOne || bSecond) { bBreak = TRUE; break; } } } } } if (bBreak) { pBend = NULL; delete pBend; continue; } //////////按名称左连接 if (nInt == 1) { ((CInTrackDepthSegment*)pLayerDrawObj)->m_BendLeftList.push_back(pBend); ((CInTrackDepthSegment*)pTrackInObject)->m_BendRightList.push_back(pBend); ReOrederList(((CInTrackDepthSegment*)pLayerDrawObj)->m_BendLeftList,1); ReOrederList(((CInTrackDepthSegment*)pTrackInObject)->m_BendRightList,2); } /////////按名称右链接 else if (nInt == 2) { ((CInTrackDepthSegment*)pLayerDrawObj)->m_BendRightList.push_back(pBend); ((CInTrackDepthSegment*)pTrackInObject)->m_BendLeftList.push_back(pBend); ReOrederList(((CInTrackDepthSegment*)pLayerDrawObj)->m_BendRightList,2); ReOrederList(((CInTrackDepthSegment*)pTrackInObject)->m_BendLeftList,1); } if (pSection->m_bResForm) { SetBendDataForResFormPCG(pSection, pBend, pWell, pWellAnother, pLayerDrawObj, pTrackInObject, nInt); } else SetBendDataForDFOld(pSection, pBend, pWell,pWellAnother, pLayerDrawObj, pTrackInObject, nInt); pSection->m_BendList.AddTail(pBend); linkbends.push_back(pBend); } } } break; } } tracklist.clear(); } } //////层中连层链表的重新排序 BOOL bCompareBendLayer(WELLOBJLIST::iterator& it, WELLOBJLIST::iterator& nextIt, int nInt) { BOOL b = FALSE; CWellBaseObj* pObj = *it; CWellBaseObj* pObjAnOther = *nextIt; if (pObj->GetType() == KEP_SECTIONBEND && pObjAnOther->GetType() == KEP_SECTIONBEND) { CBendObj* pBendObj = (CBendObj*)pObj; CInTrackDepthSegment* pLayer = NULL; CBendObj* pBendObjAnother = (CBendObj*)pObjAnOther; CInTrackDepthSegment* pLayerAnother = NULL; ///////按连层左边层位的高低排序 if (nInt == 1) { if (pBendObj->m_pLayerLeft->GetPos().left < pBendObj->m_pLayerRight->GetPos().left) { pLayer = pBendObj->m_pLayerLeft; } else/////////若连层是逆连层(左边横坐标比右边横坐标大) { pLayer = pBendObj->m_pLayerRight; } } ///////按连层右边层位的高低排序 else if (nInt == 2) { if (pBendObj->m_pLayerLeft->GetPos().left < pBendObj->m_pLayerRight->GetPos().left) { pLayer = pBendObj->m_pLayerRight; } else/////////若连层是逆连层(左边横坐标比右边横坐标大) { pLayer = pBendObj->m_pLayerLeft; } } ///////按连层左边层位的高低排序 if (nInt == 1) { if (pBendObjAnother->m_pLayerLeft->GetPos().left < pBendObjAnother->m_pLayerRight->GetPos().left) { pLayerAnother = pBendObjAnother->m_pLayerLeft; } else/////////若连层是逆连层(左边横坐标比右边横坐标大) { pLayerAnother = pBendObjAnother->m_pLayerRight; } } ///////按连层右边层位的高低排序 else if (nInt == 2) { if (pBendObjAnother->m_pLayerRight->GetPos().left > pBendObjAnother->m_pLayerLeft->GetPos().left) { pLayerAnother = pBendObjAnother->m_pLayerRight; } else/////////若连层位逆连层(左边横坐标比右边横坐标大) { pLayerAnother = pBendObjAnother->m_pLayerLeft; } } if (pLayerAnother->GetPos().top > pLayer->GetPos().top) { b = TRUE; } } return b; } void CItemWellSection::ReOrederList(WELLOBJLIST& BendList, int nInt) { if (BendList.size() < 2) return; //根据层位置有高到低链表重新排序 bool swapped; auto endIt = BendList.end(); // 用于优化,记录未排序部分的结束位置 do { swapped = false; WELLOBJLIST::iterator it = BendList.begin(); WELLOBJLIST::iterator nextIt = std::next(it); while (nextIt != endIt) { if (bCompareBendLayer(it,nextIt,nInt)) { std::iter_swap(it, nextIt); swapped = true; } ++it; ++nextIt; } --endIt; // 每次循环后,最大的元素已经冒泡到最后,无需再比较 } while (swapped); // 如果没有发生交换,说明已经有序 } void CItemWellSection::ApplingTemplateFile(CFile &fr,BOOL bAll) { //应用模板的井链表 CWellBaseObjList WellList; CWellSection * pSection = (CWellSection *)GetWellSection(); if (bAll) { POSITION posWell = pSection->m_WellList.GetHeadPosition(); while(posWell!=NULL) { CWellPole *pWellObj = (CWellPole *)pSection->m_WellList.GetNext(posWell); WellList.AddTail(pWellObj); } } else { if(m_WellObjSelectlist.GetCount() == 1) { CWellBaseObj* pDrawObj = (CWellBaseObj*)m_WellObjSelectlist.GetHead(); if (pDrawObj->GetType() == KEP_WELL) { CWellPole *pWellObj = (CWellPole *)pDrawObj; WellList.AddTail(pWellObj); } } } BOOL bDelete = FALSE; CPointArr fDistance; //////保存井之间的间距 POSITION posSectionWell = pSection->m_WellList.GetHeadPosition(); CWellPole* pWellNext = NULL; while(posSectionWell != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(posSectionWell); POSITION posFind = pSection->m_WellList.Find(pWellObj); pSection->m_WellList.GetNext(posFind); if (posFind!=NULL) { pWellNext = (CWellPole*)pSection->m_WellList.GetNext(posFind); dfPoint temppoint; temppoint.x0 = pWellNext->GetPos().left - pWellObj->GetPos().right; fDistance.Add(temppoint); } } //////保存断层在两口井之间的相对位置 POSITION posBend = pSection->m_BendList.GetHeadPosition(); //while(NULL != posBend) //{ // double XLeft = 0.0; // double XRight = 0.0; // CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetNext(posBend); // pBend->GetBendXValue(XLeft,XRight); // for (int i = 0; im_faultArr.GetCount(); i++) // { // CFaultObj* pFault = (CFaultObj*)pBend->m_faultArr.GetAt(i).pFault; // for (int j = 0;jm_ptArr.GetCount(); j++) // { // pFault->m_ptArr[j].z0 = pFault->m_ptArr[j].x0-XLeft; // } // } //} POSITION posWell = WellList.GetHeadPosition(); while(posWell!=NULL) { CWellPole *pWellObj = (CWellPole *)WellList.GetNext(posWell); fr.SeekToBegin(); //备份井内道对象 TRACKLIST tracklist; tracklist.assign(pWellObj->GetTrackList().rbegin(), pWellObj->GetTrackList().rend()); // 这样将井的所有道,包括组合道都获得 //pWellObj->GetAllTrack(&tracklist); pWellObj->GetTrackList().clear(); // ->RemoveAll(); CString strWellTitle = pWellObj->m_strTitle; CString strWellName = pWellObj->GetWellName(); double fx = 0.0; double fy = 0.0; fx = ((CSectionWellObj*)pWellObj)->m_fX; fy = ((CSectionWellObj*)pWellObj)->m_fY; double fLevel = pWellObj->m_fLevel; double topDepth = pWellObj->m_dSdep; double endDepth = pWellObj->m_dEdep; double left = pWellObj->GetPos().left; double proportion = pWellObj->m_fProportion; double dOldTrackHead = pWellObj->m_dHeightTrackHead; double dOldWellHead = pWellObj->m_dHeightWellHead; double tracktop = pWellObj->GetPos().top-dOldWellHead-dOldTrackHead; double nWellId = pWellObj->GetId(); std::vector oldWellIntervalVec; oldWellIntervalVec.insert(oldWellIntervalVec.begin(),pWellObj->GetIntervalVec()->begin(),pWellObj->GetIntervalVec()->end()); AfxGetPublicFunction()->SetCodeType(CODE_GB2321); if(pWellObj->ReadPCG(fr, -1) == 0) { //恢复道备份 pWellObj->GetTrackList().assign(tracklist.begin(), tracklist.end()); tracklist.clear(); return ; } else { ////释放以前的组对象 pWellObj->m_strTitle = strWellTitle; pWellObj->SetWellName(strWellName); //pWellObj->ReSetWellHead(); pWellObj->m_fLevel = fLevel; ((CSectionWellObj*)pWellObj)->m_fX=fx; ((CSectionWellObj*)pWellObj)->m_fY=fy; pWellObj->GetPos().left = left; pWellObj->GetPos().top = tracktop+pWellObj->m_dHeightWellHead+pWellObj->m_dHeightTrackHead; pWellObj->m_dSdep = topDepth; pWellObj->m_dEdep = endDepth; pWellObj->GetIntervalVec()->clear(); pWellObj->GetIntervalVec()->insert(pWellObj->GetIntervalVec()->begin(),oldWellIntervalVec.begin(),oldWellIntervalVec.end()); pWellObj->m_fProportion = proportion; pWellObj->m_fMarginLR = pWellObj->m_fMarginTB = 0.0; pWellObj->SetId(nWellId); pWellObj->CalculateSize(pWellObj->GetPos().TopLeft()); //应用井模板 TRACKLIST::iterator it; pWellObj->GetTemplateList().assign(tracklist.begin(), tracklist.end()); //多井剖面时,重新设置连层指针 tracklist.clear(); pWellObj->GetAllTrack(&tracklist); POSITION posBend = pSection->m_BendList.GetTailPosition(); while(posBend != NULL) { CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetPrev(posBend); if (pBend->m_pWellLeft == pWellObj || pBend->m_pWellRight == pWellObj) { BOOL bExist = FALSE; it = tracklist.begin(); for(; it!= tracklist.end(); it++) { CTrackObj *pTrack = *it; if (((CTrackObj*)pBend->m_pLayerLeft->GetParent())->GetTrackType() == pTrack->GetTrackType()) { bExist = TRUE; break; } else if (pBend->m_pLayerRight != NULL && ((CTrackObj*)pBend->m_pLayerRight->GetParent())->GetTrackType() == pTrack->GetTrackType()) { bExist = TRUE; break; } else if (pBend->m_pLayerRight == NULL && pBend->m_pWellRight == pWellObj) { bExist = TRUE; break; } } if (!bExist) { pSection->DeleteBend(pBend); } } } tracklist.clear(); pWellObj->ApplingTemplate(TRUE,pWellObj->m_dHeightTrackHead,pWellObj->m_dHeightWellHead); CItemWcsSingleWell itemwell(GetDoc()); itemwell.ImportDataAll(pWellObj, FALSE); } //AfxGetPublicFunction()->SetCodeType((DWORD)::GetPreferences().WorkaroundSave.m_nCodeMode); } fr.Close(); //重新计算连层 CRect8 oldrect = pSection->GetRect(); if (fDistance.GetCount()>0) { int nWell = 0; double dWellRight = 0; POSITION pos = pSection->m_WellList.GetHeadPosition(); while (pos != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(pos); //重新计算井位置 if(nWell > 0) { pWellObj->GetPos().left = fDistance.GetAt(nWell-1).x0 + dWellRight; pWellObj->CalculateSize(pWellObj->GetPos().TopLeft()); } nWell ++; dWellRight = pWellObj->GetPos().right; } } posWell = pSection->m_WellList.GetHeadPosition(); while(posWell!=NULL) { CWellPole *pWellObj = (CWellPole *)pSection->m_WellList.GetNext(posWell); pSection->ReComputeBends(pWellObj); } //////重新计算断层的位置 posBend = pSection->m_BendList.GetHeadPosition(); while(NULL != posBend) { double XLeft = 0.0; double XRight = 0.0; CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetNext(posBend); pBend->GetBendXValue(XLeft,XRight); for (int i = 0; im_faultArr.GetCount(); i++) { CFaultObj* pFault = (CFaultObj*)pBend->m_faultArr.GetAt(i).pFault; for (int j = 0;jm_ptArr.GetCount(); j++) { pFault->m_ptArr.GetAt(j).x0 = XLeft + pFault->m_ptArr.GetAt(j).z0; } } } POSITION posFault = pSection->m_FaultList.GetHeadPosition(); while(posFault != NULL) { CFaultObj* pFault = (CFaultObj*)pSection->m_FaultList.GetNext(posFault); pFault->FaultReCut(); } //计算剖面范围 pSection->ReSetPosition(); //刷新 CRect8 rect = pSection->GetRect(); rect.CombinRect(oldrect); CRect rt = GetDC()->GetScreen(rect); rt.InflateRect(10,10); GetDoc()->Invalidate(); WellList.RemoveAll(); } void CItemWellSection::ApplingWellDbTemplate(BOOL bAll) { //CDlgApplyTemplate dlg("Section"); //if(dlg.DoModal() == IDCANCEL) // return; //if(dlg.m_pMemFile) // ApplingTemplateFile(*dlg.m_pMemFile,bAll); } void CItemWellSection::ApplingWellTemplate(BOOL bAll) { //撤销 //SetReUnDoAction(FALSE); //CFileDialog dlg(TRUE,NULL,"", OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, // "Well Template (*.dml)|*.dml|",NULL,0); //CString filepathstr; //if (dlg.DoModal()!=IDOK) //{ // return; //} ////保存路径 //filepathstr=dlg.GetPathName(); //CString ext = dlg.GetFileExt(); //if(ext == "dml") //dml格式 //{ // SetReUnDoAction(FALSE); // CStdioFile fr; // if(!fr.Open(filepathstr,CFile::modeRead)) // return; // ApplingTemplateFile(fr,bAll); //} } void CItemWellSection::GetLegendObject(const CStringArray &StyleList,CRect8 rt) { if (NULL == m_pWellSection || StyleList.GetCount() == 0) { return; } CXy* pXy = (CXy*)m_pWellSection->GetParentXY(); if (NULL == pXy) { return; } WELLOBJLIST Objectlist; CStringArray StrArr; POSITION pos = m_pWellSection->m_WellList.GetHeadPosition(); //while(pos) //{ // CWellBaseObj* pObj = (CWellBaseObj*)m_pWellSection->m_WellList.GetNext(pos); // if (pObj->GetType() == KEP_WELL) // { // CWellPole* pWell = (CWellPole*)pObj; // GetSymbolObj(Objectlist,StyleList,pWell); // } //} //CreatLegendObject(Objectlist,rt,pXy); } void CItemWellSection::ConnectLayer(CSectionWellObj* pWell, int TrackType, int layerType) { CTrackObj* pTrack = NULL; //////地层连层 pTrack = pWell->FindTrack(ETrackType(TrackType)); std::vector linkBends; if (NULL != pTrack) { //POSITION pos1 = pTrack->GetChildObjList().GetHeadPosition(); WELLOBJLIST::iterator pos1 = pTrack->GetChildren().begin(); for (; pos1 != pTrack->GetChildren().end(); pos1++) { CWellBaseObj* pObj1 = *pos1; if (pObj1->GetType() == layerType) { CInTrackDepthSegment* pTopEnd = (CInTrackDepthSegment*)pObj1; if (pTopEnd->m_fSdep >= pWell->m_dSdep && pTopEnd->m_fEdep <= pWell->m_dEdep) { ConnectOnName(pTopEnd, 2,linkBends); } } } } } void CItemWellSection::CreateLayers() { if (NULL == m_pWellSection) { return; } POSITION pos = m_pWellSection->m_WellList.GetHeadPosition(); while(pos != m_pWellSection->m_WellList.GetTailPosition()) { CWellBaseObj* pObj = m_pWellSection->m_WellList.GetNext(pos); if (pObj->GetType() == KEP_WELL) { CSectionWellObj* pWell = (CSectionWellObj*)pObj; ConnectLayer(pWell, Track_Stratum, KEP_LAYERGROUP); //地层连层 ConnectLayer(pWell, Track_StandardLayer, KEP_STANDARD); //标准层连层 ConnectLayer(pWell, Track_OilLayerGroup, KEP_LAYERGROUP); //油层组连层 ConnectLayer(pWell, Track_SandLayer, KEP_LAYERGROUP); //砂层组连层 ConnectLayer(pWell, Track_Result, KEP_RESULT);///解释连层 } } if (m_pWellSection->m_bResForm) {//在这种情况下,上面的操作只是生成了bend,并进行ben的参数设置。 m_pWellSection->ComputeAllBendsTopBottomForResForm(); m_pWellSection->ComputeAllBendsByThreads(); } } void CItemWellSection::CreateLayers(std::vectorlayersTrackType) { if (NULL == m_pWellSection) { return; } POSITION pos = m_pWellSection->m_WellList.GetHeadPosition(); while (pos != m_pWellSection->m_WellList.GetTailPosition()) { CWellBaseObj* pObj = m_pWellSection->m_WellList.GetNext(pos); if (pObj->GetType() == KEP_WELL) { CSectionWellObj* pWell = (CSectionWellObj*)pObj; for (int i = 0; i < layersTrackType.size(); i++) { if(layersTrackType[i] == Track_Stratum) ConnectLayer(pWell, Track_Stratum, KEP_LAYERGROUP); if (layersTrackType[i] == Track_StandardLayer) ConnectLayer(pWell, Track_StandardLayer, KEP_STANDARD); if (layersTrackType[i] == Track_OilLayerGroup) ConnectLayer(pWell, Track_OilLayerGroup, KEP_LAYERGROUP); if (layersTrackType[i] == Track_SandLayer) ConnectLayer(pWell, Track_SandLayer, KEP_LAYERGROUP); if (layersTrackType[i] == Track_Result) ConnectLayer(pWell, Track_Result, KEP_RESULT); } //ConnectLayer(pWell, Track_Stratum, KEP_LAYERGROUP); //地层连层 //ConnectLayer(pWell, Track_StandardLayer, KEP_STANDARD); //标准层连层 //ConnectLayer(pWell, Track_OilLayerGroup, KEP_LAYERGROUP); //油层组连层 //ConnectLayer(pWell, Track_SandLayer, KEP_LAYERGROUP); //砂层组连层 //ConnectLayer(pWell, Track_Result, KEP_RESULT);///解释连层 } } if (m_pWellSection->m_bResForm) {//在这种情况下,上面的操作只是生成了bend,并进行ben的参数设置。 m_pWellSection->ComputeAllBendsTopBottomForResForm(); m_pWellSection->ComputeAllBendsByThreads(); } } void CItemWellSection::BreakLayers() { if (NULL == m_pWellSection) { return; } POSITION pos = m_pWellSection->m_BendList.GetTailPosition(); while(pos != NULL) { CWellBaseObj* pObj = m_pWellSection->m_BendList.GetPrev(pos); m_pWellSection->DeleteBend((CBendObj*)pObj); } m_pWellSection->m_BendList.RemoveAll(); if (this->m_pItemSelected != NULL) { if (this->m_pItemSelected->GetType() == ITEM_BEND) { delete m_pItemSelected; m_pItemSelected = NULL; m_WellObjSelectlist.RemoveAll(); } } GetDoc()->Invalidate(); } CItem* CItemWellSection::GetItem() { //ggff 20160526 if(m_pItemSelected) return m_pItemSelected; else return CItemWcsSingleWell::GetItem(); } void CItemWellSection::MakeFaultFromFaultPoint() { if (NULL == m_pWellSection) { return; } m_pWellSection->MakeFaultFromFaultPoint(); } void CItemWellSection::SetAllWellColumnLineShape() { if (NULL == m_pWellSection) { return; } CSize8 size = GetDC()->GetRealSize(CSize(2,0)); m_pWellSection->SetAllWellColumnLineShape(size.cx); } void CItemWellSection::DeleteAllFaults() { if (NULL == m_pWellSection) { return; } SetItem(NULL); m_WellObjSelectlist.RemoveAll(); m_pWellSection->DeleteAllFaults(); } BOOL GetFaultsIntersect(CFaultObj* pFault1,CFaultObj*pFault2,dfPoint &retPt,int& f1Id,int& f2Id) { BOOL b= FALSE; PointF tp,f1pt1,f1Pt2,f2pt1,f2pt2; for(int ii = 0; iim_ptArr.GetSize() -1; ii++) { if(b) break; f1pt1.X = pFault1->m_ptArr[ii].x0; f1pt1.Y = pFault1->m_ptArr[ii].y0; f1Pt2.X = pFault1->m_ptArr[ii+1].x0; f1Pt2.Y = pFault1->m_ptArr[ii+1].y0; for(int jj = 0; jjm_ptArr.GetSize()-1; jj++) { f2pt1.X = pFault2->m_ptArr[jj].x0; f2pt1.Y = pFault2->m_ptArr[jj].y0; f2pt2.X = pFault2->m_ptArr[jj+1].x0; f2pt2.Y = pFault2->m_ptArr[jj+1].y0; if(GetLinesWithSegmentPt1(tp,f1pt1,f1Pt2,f2pt1,f2pt2)) { if(IsValidIntersect(tp,pFault1->m_ptArr.GetSize(),ii,f1pt1,ii+1,f1Pt2,pFault2->m_ptArr.GetSize(),jj,f2pt1,jj+1,f2pt2))//判断是否是有效断点,防止出现一条断层线的两头端点只是简单接触另一条的情况 { f1Id = ii; f2Id =jj; retPt.x0 = tp.X; retPt.y0 = tp.Y; b = TRUE; break; } } } } return b; } void CItemWellSection::GetIntersectFaults(FAULTVECTOR &faultVec1,FAULTVECTOR &faultVec2,CPointArr &retPtArr,CUIntArray &f1idArr,CUIntArray &f2idArr) { if (NULL == m_pWellSection) { return; } if(m_pWellSection->m_FaultList.GetSize() == 0) return; CFaultObj *pFaultObj1,*pFaultObj2; FAULTVECTOR allFaultVec; POSITION pos = m_pWellSection->m_FaultList.GetHeadPosition(); while(pos) { pFaultObj1 = (CFaultObj *)m_pWellSection->m_FaultList.GetNext(pos); if(pFaultObj1->m_strName.IsEmpty()) continue; allFaultVec.push_back(pFaultObj1); } if(allFaultVec.size()<1) return; dfPoint retPt; int f1Id,f2Id; for(int ii = 0; ii< allFaultVec.size()-1; ii++) { pFaultObj1 = allFaultVec[ii]; if(pFaultObj1->m_strName.IsEmpty()) continue; for(int jj = ii+1; jjm_strName.IsEmpty()) continue; if(GetFaultsIntersect(pFaultObj1,pFaultObj2,retPt,f1Id,f2Id)) { faultVec1.push_back(pFaultObj1); faultVec2.push_back(pFaultObj2); retPtArr.Add(retPt); f1idArr.Add(f1Id); f2idArr.Add(f2Id); } } } } //沿着断层线移动移动一个点 dfPoint MovePtalongFault(dfPoint fpt,double offv,CFaultObj *pCutFault,int cutId) { dfPoint retPt = fpt; double miny,maxy; dfPoint pt1,pt2; for(int ii =0; ii< pCutFault->m_ptArr.GetSize()-1; ii++) { pt1 = pCutFault->m_ptArr[ii] ; pt2 = pCutFault->m_ptArr[ii+1]; maxy = pt1.y0 > pt2.y0 ? pt1.y0 : pt2.y0; miny = pt1.y0 < pt2.y0 ? pt1.y0 : pt2.y0; if(((miny-0.000001)< (fpt.y0+offv)) && ((fpt.y0+offv)<(maxy+0.000001))) { retPt.y0 = fpt.y0+offv; if(abs(pt1.x0-pt2.x0)<0.000001) { retPt.x0 = pt1.x0; } else { if(abs(pt1.y0 - pt2.y0)< 0.000001) retPt.x0 = pt2.x0; else retPt.x0 = pt1.x0 + (pt2.x0 - pt1.x0)*(retPt.y0 - pt1.y0)/(pt2.y0 - pt1.y0); } break; } } return retPt; } //对被切割的断层点进行一些调整移动,按照切割它的断层断距,pHCutFault是指切断被切层的头部的断层,pTCutFault是指尾部 void MoveBeCutFault(CWellSection *pSection,CFaultObj *pBeCutFault,CFaultObj *pHCutFault,int hCutId,CFaultObj *pTCutFault,int tCutId) { CSectionWellObj *pWell =(CSectionWellObj *) pSection->m_WellList.GetHead(); double v; if(pHCutFault) { dfPoint retPt; if(pBeCutFault->m_ptArr[0].x0 > pBeCutFault->m_ptArr[pBeCutFault->m_ptArr.GetSize()-1].x0) v = pWell->HeightToScreenCY(pHCutFault->m_fLeftThrow); else v = pWell->HeightToScreenCY(-pHCutFault->m_fRightThrow); retPt = MovePtalongFault(pBeCutFault->m_ptArr[0],v,pHCutFault,hCutId); pBeCutFault->m_ptArr[0] = retPt; } if(pTCutFault) { dfPoint retPt; if(pBeCutFault->m_ptArr[0].x0 > pBeCutFault->m_ptArr[pBeCutFault->m_ptArr.GetSize()-1].x0) v = pWell->HeightToScreenCY(-pTCutFault->m_fRightThrow); else v = pWell->HeightToScreenCY(pTCutFault->m_fLeftThrow); retPt = MovePtalongFault(pBeCutFault->m_ptArr[pBeCutFault->m_ptArr.GetSize()-1],v,pTCutFault,tCutId); pBeCutFault->m_ptArr[pBeCutFault->m_ptArr.GetSize()-1] = retPt; } } void AddFaultPoint(CFaultObj *pNewFault,dfPoint newPt) { if(pNewFault->m_ptArr.GetSize()>0) { dfPoint tpoint = pNewFault->m_ptArr[pNewFault->m_ptArr.GetSize()-1]; if(!(abs(tpoint.x0 - newPt.x0)<0.01 && abs(tpoint.y0 - newPt.y0)<0.01)) //如果新加入的点同已有的最后一点重复,就不加了 pNewFault->m_ptArr.Add(newPt); } else pNewFault->m_ptArr.Add(newPt); } void CItemWellSection::DoFaultsIntersect(CFaultObj *pBeCutFault,CUIntArray &PtIdArr,CPointArr &SectPointArr,FAULTVECTOR &CutFaultVec,CUIntArray &CutPtIdArr,FAULTVECTOR &newFaultVec) { if (NULL == m_pWellSection) { return; } if(m_pWellSection->m_FaultList.GetSize() == 0 || PtIdArr.GetSize()==0) return; CFaultObj *pNewFault; pNewFault = new CFaultObj; pNewFault->m_strName = pBeCutFault->m_strName; pNewFault->m_fLeftThrow = pBeCutFault->m_fLeftThrow; pNewFault->m_fRightThrow = pBeCutFault->m_fRightThrow; pNewFault->SetParent(m_pWellSection); for(int ii = 0; ii<=PtIdArr[0]; ii++) { AddFaultPoint(pNewFault,pBeCutFault->m_ptArr[ii]);//pNewFault->m_ptArr.Add(pBeCutFault->m_ptArr[ii]); } AddFaultPoint(pNewFault,SectPointArr[0]); newFaultVec.push_back(pNewFault); MoveBeCutFault(m_pWellSection,pNewFault,NULL,0,CutFaultVec[0],CutPtIdArr[0]); for(int ii = 0; iim_strName = pBeCutFault->m_strName; pNewFault->m_fLeftThrow = pBeCutFault->m_fLeftThrow; pNewFault->m_fRightThrow = pBeCutFault->m_fRightThrow; AddFaultPoint(pNewFault,SectPointArr[ii]); pNewFault->SetParent(m_pWellSection); for(int jj = PtIdArr[ii]+1; jj<=PtIdArr[ii+1]; jj++) { AddFaultPoint(pNewFault,pBeCutFault->m_ptArr[jj]);//pNewFault->m_ptArr.Add(pBeCutFault->m_ptArr[jj]); } AddFaultPoint(pNewFault,SectPointArr[ii+1]); newFaultVec.push_back(pNewFault); MoveBeCutFault(m_pWellSection,pNewFault,CutFaultVec[ii],CutPtIdArr[ii],CutFaultVec[ii+1],CutPtIdArr[ii+1]); } pNewFault = new CFaultObj; pNewFault->m_strName = pBeCutFault->m_strName; pNewFault->m_fLeftThrow = pBeCutFault->m_fLeftThrow; pNewFault->m_fRightThrow = pBeCutFault->m_fRightThrow; AddFaultPoint(pNewFault,SectPointArr[SectPointArr.GetSize()-1]); pNewFault->SetParent(m_pWellSection); for(int ii = PtIdArr[PtIdArr.GetSize()-1]+1; ii< pBeCutFault->m_ptArr.GetSize(); ii++) { AddFaultPoint(pNewFault,pBeCutFault->m_ptArr[ii]); } newFaultVec.push_back(pNewFault); MoveBeCutFault(m_pWellSection,pNewFault,CutFaultVec[CutFaultVec.size()-1],CutPtIdArr[CutPtIdArr.GetSize()-1],NULL,0); } BOOL CItemWellSection::IsAddBendLayerPoint() { if (m_pItemSelected == NULL) return FALSE; BOOL b = FALSE; if (m_pItemSelected->GetType() == ITEM_BEND) { b = TRUE; } return b; } BOOL CItemWellSection::IsAddFaultPoint() { if (m_pItemSelected == NULL) return FALSE; BOOL b = FALSE; if (m_pItemSelected->GetType() == ITEM_FAULT) { b = TRUE; } return b; } void CItemWellSection::AddBendLayerPoint() { if (m_pItemSelected->GetType() == ITEM_BEND) { CItemBend *pItemBend = (CItemBend *)m_pItemSelected; pItemBend->AddBendLayerPoint(); } } void CItemWellSection::DeleteBendLayerPoint() { if (m_pItemSelected->GetType() == ITEM_BEND) { CItemBend *pItemBend = (CItemBend *)m_pItemSelected; pItemBend->DeleteBendLayerPoint(); } } void CItemWellSection::SetPos(POSITION pos) { CItem::SetPos(pos); COne* pOne = GetDoc()->GetDraw()->GetAt(pos); if (pOne->GetType() == KEP_WELLSECTION) { SetDrawObj((CWellBaseObj*)pOne->GetValue()); if (m_pItemSelected != NULL) { delete m_pItemSelected; m_pItemSelected = NULL; } m_WellObjSelectlist.RemoveAll(); } //this->m_pWellSection } CWellBaseObj* CItemWellSection::GetDrawObj() { return m_pWellSection; } BOOL CItemWellSection::ApplingTemplate(CKXmlParse& xp, CSectionWellObj* pSelectWellObj) { CWellBaseObjList WellList; CWellSection* pSection = (CWellSection*)GetWellSection(); if (pSelectWellObj == NULL) { POSITION posWell = pSection->m_WellList.GetHeadPosition(); while (posWell != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(posWell); WellList.AddTail(pWellObj); } } else { WellList.AddTail(pSelectWellObj); //if (m_WellObjSelectlist.GetCount() == 1) //{ // CWellBaseObj* pDrawObj = (CWellBaseObj*)m_WellObjSelectlist.GetHead(); // if (pDrawObj->GetType() == KEP_WELL) // { // CWellPole* pWellObj = (CWellPole*)pDrawObj; // WellList.AddTail(pWellObj); // } //} } BOOL bDelete = FALSE; CPointArr fDistance; //////保存井之间的间距 POSITION posSectionWell = pSection->m_WellList.GetHeadPosition(); CWellPole* pWellNext = NULL; while (posSectionWell != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(posSectionWell); POSITION posFind = pSection->m_WellList.Find(pWellObj); pSection->m_WellList.GetNext(posFind); if (posFind != NULL) { pWellNext = (CWellPole*)pSection->m_WellList.GetNext(posFind); dfPoint temppoint; temppoint.x0 = pWellNext->GetPos().left - pWellObj->GetPos().right; fDistance.Add(temppoint); } } //////保存断层在两口井之间的相对位置 POSITION posBend = pSection->m_BendList.GetHeadPosition(); //while(NULL != posBend) //{ // double XLeft = 0.0; // double XRight = 0.0; // CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetNext(posBend); // pBend->GetBendXValue(XLeft,XRight); // for (int i = 0; im_faultArr.GetCount(); i++) // { // CFaultObj* pFault = (CFaultObj*)pBend->m_faultArr.GetAt(i).pFault; // for (int j = 0;jm_ptArr.GetCount(); j++) // { // pFault->m_ptArr[j].z0 = pFault->m_ptArr[j].x0-XLeft; // } // } //} POSITION posWell = WellList.GetHeadPosition(); while (posWell != NULL) { CWellPole* pWellObj = (CWellPole*)WellList.GetNext(posWell); //fr.SeekToBegin(); //备份井内道对象 TRACKLIST tracklist; //TRACKLIST::reverse_iterator rit = pWellObj->GetTrackList().rbegin(); //for(; rit != pWellObj->GetTrackList().rend(); rit++) //{ // tracklist.push_front(*rit); //} tracklist.assign(pWellObj->GetTrackList().rbegin(), pWellObj->GetTrackList().rend()); // 这样将井的所有道,包括组合道都获得 //pWellObj->GetAllTrack(&tracklist); pWellObj->GetTrackList().clear(); // ->RemoveAll(); CString strWellTitle = pWellObj->m_strTitle; CString strWellName = pWellObj->GetWellName(); double fx = 0.0; double fy = 0.0; fx = ((CSectionWellObj*)pWellObj)->m_fX; fy = ((CSectionWellObj*)pWellObj)->m_fY; double fLevel = pWellObj->m_fLevel; double topDepth = pWellObj->m_dSdep; double endDepth = pWellObj->m_dEdep; double left = pWellObj->GetPos().left; double proportion = pWellObj->m_fProportion; double dOldTrackHead = pWellObj->m_dHeightTrackHead; double dOldWellHead = pWellObj->m_dHeightWellHead; double tracktop = pWellObj->GetPos().top - dOldWellHead - dOldTrackHead; double nWellId = pWellObj->GetId(); std::vector oldWellIntervalVec; oldWellIntervalVec.insert(oldWellIntervalVec.begin(), pWellObj->GetIntervalVec()->begin(), pWellObj->GetIntervalVec()->end()); AfxGetPublicFunction()->SetCodeType(CODE_GB2321); xp.InitRootNode(); //每次需要从新设置一下读取的井根节点 if (pWellObj->ReadPCG(xp, -1) == 0) { //恢复道备份 pWellObj->GetTrackList().assign(tracklist.begin(), tracklist.end()); //POSITION pos = tracklist.GetTailPosition(); //while (pos!=NULL) //{ // CTrackObj* pTrackObj = (CTrackObj*)tracklist.GetPrev(pos); // pWellObj->GetTrackList()->AddHead(pTrackObj); //} tracklist.clear(); //恢复组合道备份 //pos = trackGroupList.GetHeadPosition(); //while (pos!=NULL) //{ // CTrackGroupObj* pTrackGroupObj = trackGroupList.GetNext(pos); // pWellObj->GetTrackGroupList()->AddTail(pTrackGroupObj); //} //trackGroupList.RemoveAll(); //AfxGetPublicFunction()->SetCodeType((DWORD)::GetPreferences().WorkaroundSave.m_nCodeMode); return FALSE; } else { ////释放以前的组对象 //pos = trackGroupList.GetTailPosition(); //while(pos != NULL) //{ // delete trackGroupList.GetPrev(pos); //} //trackGroupList.RemoveAll(); pWellObj->m_strTitle = strWellTitle; pWellObj->SetWellName(strWellName); //pWellObj->ReSetWellHead(); pWellObj->m_fLevel = fLevel; ((CSectionWellObj*)pWellObj)->m_fX = fx; ((CSectionWellObj*)pWellObj)->m_fY = fy; pWellObj->GetPos().left = left; pWellObj->GetPos().top = tracktop + pWellObj->m_dHeightWellHead + pWellObj->m_dHeightTrackHead; pWellObj->m_dSdep = topDepth; pWellObj->m_dEdep = endDepth; pWellObj->GetIntervalVec()->clear(); pWellObj->GetIntervalVec()->insert(pWellObj->GetIntervalVec()->begin(), oldWellIntervalVec.begin(), oldWellIntervalVec.end()); pWellObj->m_fProportion = proportion; pWellObj->m_fMarginLR = pWellObj->m_fMarginTB = 0.0; pWellObj->SetId(nWellId); pWellObj->CalculateSize(pWellObj->GetPos().TopLeft()); //应用井模板 //pos = tracklist.GetHeadPosition(); //TRACKLIST::iterator it = tracklist.begin(); //for (; it != tracklist.end(); it++) // pWellObj->GetTemplateList().push_front(*it); pWellObj->GetTemplateList().assign(tracklist.begin(), tracklist.end()); //while(pos != NULL) // pWellObj->GetTemplateList().AddHead(tracklist.GetNext(pos)); //多井剖面时,重新设置连层指针 tracklist.clear(); pWellObj->GetAllTrack(&tracklist); POSITION posBend = pSection->m_BendList.GetTailPosition(); TRACKLIST::iterator it; while (posBend != NULL) {//使用新井模板状态下,删除用不到的bend,保留有用的bend CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetPrev(posBend); if (pBend->m_pWellLeft == pWellObj || pBend->m_pWellRight == pWellObj) { BOOL bExist = FALSE; it = tracklist.begin(); for (; it != tracklist.end(); it++) { CTrackObj* pTrack = *it; if (((CTrackObj*)pBend->m_pLayerLeft->GetParent())->GetTrackType() == pTrack->GetTrackType()) { bExist = TRUE; break; } else if (pBend->m_pLayerRight != NULL && ((CTrackObj*)pBend->m_pLayerRight->GetParent())->GetTrackType() == pTrack->GetTrackType()) { bExist = TRUE; break; } else if (pBend->m_pLayerRight == NULL && pBend->m_pWellRight == pWellObj) { bExist = TRUE; break; } } if (!bExist) { pSection->DeleteBend(pBend); } } } tracklist.clear(); pWellObj->ApplingTemplate(TRUE, pWellObj->m_dHeightTrackHead, pWellObj->m_dHeightWellHead); //CItemWcsSingleWell itemwell(GetDoc()); //itemwell.ImportDataAll(pWellObj, FALSE); } //AfxGetPublicFunction()->SetCodeType((DWORD)::GetPreferences().WorkaroundSave.m_nCodeMode); } //fr.Close(); //重新计算连层 CRect8 oldrect = pSection->GetRect(); if (fDistance.GetCount() > 0) { int nWell = 0; double dWellRight = 0; POSITION pos = pSection->m_WellList.GetHeadPosition(); while (pos != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(pos); //重新计算井位置 if (nWell > 0) { pWellObj->GetPos().left = fDistance.GetAt(nWell - 1).x0 + dWellRight; pWellObj->CalculateSize(pWellObj->GetPos().TopLeft()); } nWell++; dWellRight = pWellObj->GetPos().right; } } posWell = pSection->m_WellList.GetHeadPosition(); while (posWell != NULL) { CWellPole* pWellObj = (CWellPole*)pSection->m_WellList.GetNext(posWell); pSection->ReComputeBends(pWellObj); } //////重新计算断层的位置 posBend = pSection->m_BendList.GetHeadPosition(); while (NULL != posBend) { double XLeft = 0.0; double XRight = 0.0; CBendObj* pBend = (CBendObj*)pSection->m_BendList.GetNext(posBend); pBend->GetBendXValue(XLeft, XRight); for (int i = 0; i < pBend->m_faultArr.GetCount(); i++) { CFaultObj* pFault = (CFaultObj*)pBend->m_faultArr.GetAt(i).pFault; for (int j = 0; j < pFault->m_ptArr.GetCount(); j++) { pFault->m_ptArr.GetAt(j).x0 = XLeft + pFault->m_ptArr.GetAt(j).z0; } } } POSITION posFault = pSection->m_FaultList.GetHeadPosition(); while (posFault != NULL) { CFaultObj* pFault = (CFaultObj*)pSection->m_FaultList.GetNext(posFault); pFault->FaultReCut(); } //计算剖面范围 pSection->ReSetPosition(); //刷新 CRect8 rect = pSection->GetRect(); rect.CombinRect(oldrect); CRect rt = GetDC()->GetScreen(rect); rt.InflateRect(10, 10); //GetDoc()->Invalidate(rt); WellList.RemoveAll(); return TRUE; } BOOL CItemWellSection::ApplyingTemplateFileForWell(CString filePath, ULONGLONG wellHandle) { BOOL b = FALSE; CString strExt = ""; if (filePath.GetLength() < 4) return FALSE; strExt = filePath.Right(4); strExt = strExt.MakeLower(); if (strExt == ".pcg") { CKXmlParse xp; if (xp.ReadXmlFile(filePath.GetBuffer())) { SetReUnDoAction(); if (wellHandle != 0) { CSectionWellObj* pWell = (CSectionWellObj*)wellHandle; b = ApplingTemplate(xp, pWell); } else b = ApplingTemplate(xp, NULL); } } return b; } BOOL CItemWellSection::ApplyingWellTemplateForSection(ULONGLONG wellHandle) { CWellPole* pWellObj = (CWellPole*)(wellHandle); SetReUnDoAction(); pWellObj->SetActionTemplate(TRUE); pWellObj->SetNoSaveCallouts(TRUE); CMemFile fw; DWORD tcode = AfxGetPublicFunction()->GetCodeType(); AfxGetPublicFunction()->SetCodeType(CODE_GB2321); //AfxGetPublicFunction()->WriteDML_Head_Version(fw); //AfxGetPublicFunction()->WriteDML_Head_Xmlns(fw); nsWellPoleFunc::WritePCG_Head_Version(fw); pWellObj->WritePCG(fw, 2, 1);//pWellObj->WriteDML(fw, -1, 1); nsWellPoleFunc::WritePCG_Tail(fw); //AfxGetPublicFunction()->SetCodeType((DWORD)::GetPreferences().WorkaroundSave.m_nCodeMode); AfxGetPublicFunction()->InitSaveCounter(); pWellObj->SetActionTemplate(FALSE); pWellObj->SetNoSaveCallouts(FALSE); AfxGetPublicFunction()->SetCodeType(tcode); int fileLen = fw.GetLength(); //char* pBuf = new char[fileLen]; BYTE* pBuf = fw.Detach(); //fw.Read(pBuf,fileLen); CKXmlParse xp; if (xp.SetXmlFileBuffer((char*)pBuf, fileLen)) { ApplingTemplate(xp, NULL); } else return FALSE; return TRUE; } }