#include "stdafx.h" #include "SigmaView.h" #include "SectionDoc.h" #include "ItemWellGroupEdit.h" #include "ActionAddItem.h" #include "ActionListItem.h" #include ".\actionmodifieditem.h" #include ".\actionbackupitem.h" #include"TinyXml/tinyxml.h" using namespace NBase; extern "C" __declspec(dllexport) int WellGroupEditSetData(CSigmaView * pView, BYTE* buffElement, int buffLen) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return 0; CItemWellGroupEdit * itemEdit = dynamic_cast(pItem); if (itemEdit == NULL) return 0; itemEdit->SetData(buffElement, buffLen); return 1; } extern "C" __declspec(dllexport) int WellGroupEditGetData(CSigmaView * pView, BYTE*& buffElement, int& buffLen) { int nElementCount = (int)pView->m_pDoc->m_BranchElements.size(); if (nElementCount == 0) { return 0; } CWellGroup* pWellGroup = new CWellGroup; COne* pOne = pView->m_pDoc->GetDraw()->CreateOne(pWellGroup, WELL_GROUP); CXy* pXy = pView->m_pDoc->m_pXy; vector branchCopys; for (int i = 0; i < nElementCount; i++) { WellGroupBranchStruct branch = pView->m_pDoc->m_BranchElements[i]; //if(branch.) WellGroupBranchStruct branchCopy; branchCopy.BranchIndex = branch.BranchIndex; branchCopy.DataPosition = branch.DataPosition; branchCopy.DataType = branch.DataType; branchCopys.push_back(branchCopy); } std::sort(branchCopys.begin(), branchCopys.end() , [](const WellGroupBranchStruct& branchA, const WellGroupBranchStruct& branchB) { if (branchA.BranchIndex == branchB.BranchIndex) { return branchA.DataType < branchB.DataType; } return branchA.BranchIndex < branchB.BranchIndex; }); int nCurrIndex = -1; // 生成数据 for (int i = 0; i < nElementCount; i++) { WellGroupBranchStruct branchInfo = branchCopys[i]; COne* pOne = pXy->GetAt(branchInfo.DataPosition); // 偏移线 if (branchInfo.DataType == 0) { CCurveEx* pCurveOffset = (CCurveEx*)pOne->value; pWellGroup->x0 = pCurveOffset->x[0]; pWellGroup->y0 = pCurveOffset->y[0]; CPointNameEx ptStart, ptEnd; CWellBranch* wellBranch = new CWellBranch; if (pOne->HowToViewCurve != nullptr) { CHowToViewCurve* pHwOffset = new CHowToViewCurve; *pHwOffset = *pOne->HowToViewCurve; wellBranch->m_pHowTowViewCurveOffset = pHwOffset; } for (int j = i + 1; j < nElementCount; j++) { WellGroupBranchStruct branchHori = branchCopys[j]; if (branchHori.BranchIndex == branchInfo.BranchIndex) { i++; COne* pOneOther = pXy->GetAt(branchHori.DataPosition); if (pOneOther->HowToViewCurve != nullptr) { CHowToViewCurve* pHwHori = new CHowToViewCurve; *pHwHori = *pOneOther->HowToViewCurve; wellBranch->m_pHowTowViewCurveHori = pHwHori; } CCurveEx* pCurveHori = (CCurveEx*)pOneOther->value; wellBranch->PointStart.x0 = pCurveHori->x[0]; wellBranch->PointStart.y0 = pCurveHori->y[0]; wellBranch->PointEnd.x0 = pCurveHori->x[1]; wellBranch->PointEnd.y0 = pCurveHori->y[1]; break; } } pWellGroup->WellBranches.push_back(wellBranch); nCurrIndex++; } else if (branchInfo.DataType == 2) { CPointNameEx* ptStart = (CPointNameEx*)(pOne->value); pWellGroup->WellBranches[nCurrIndex]->PointStart = *ptStart; if (pOne->HowToViewPoint != nullptr) { CHowToViewPoint* pHwp = new CHowToViewPoint; *pHwp = *pOne->HowToViewPoint; pWellGroup->WellBranches[nCurrIndex]->m_pHowTowViewPointStart = pHwp; } } else if (branchInfo.DataType == 3) { CPointNameEx* ptStart = (CPointNameEx*)(pOne->value); pWellGroup->WellBranches[nCurrIndex]->PointEnd = *ptStart; if (pOne->HowToViewPoint != nullptr) { CHowToViewPoint* pHwp = new CHowToViewPoint; *pHwp = *pOne->HowToViewPoint; pWellGroup->WellBranches[nCurrIndex]->m_pHowTowViewPointEnd = pHwp; } } else if (branchInfo.DataType == 4) { CPointNameEx* pWell = (CPointNameEx*)pOne->value; pWellGroup->SetName(pWell->GetName()); if (pOne->HowToViewPoint != nullptr) { CHowToViewPoint* pHwp = new CHowToViewPoint; *pHwp = *pOne->HowToViewPoint; pWellGroup->m_pHowTowViewPointWell = pHwp; } } } pOne->WriteMemory(buffElement, 0, buffLen, 3); return 1; } //extern "C" __declspec(dllexport) //int WellGroupEditMovePoint(CSigmaView * pView, POSITION elementPos) //{ // int nElementCount = pView->m_pDoc->m_BranchElements.size(); // if (nElementCount == 0) { // return 0; // } // COne* pOneMoved = pView->m_pDoc->GetDraw()->GetAt(elementPos); // CPointNameEx* ptMoved = (CPointNameEx*)pOneMoved->value; // // for (int i = 0; i < nElementCount; i++) // { // WellGroupBranchStruct branch = pView->m_pDoc->m_BranchElements[i]; // if (branch.DataPosition == elementPos) { // // 移动的是入靶点 // if (branch.DataType == 2) { // for (const auto &branchFind : pView->m_pDoc->m_BranchElements) // { // if (branchFind.BranchIndex == branch.BranchIndex // && branchFind.DataType == 0) { // COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); // CCurveEx* pCurve = (CCurveEx*)pOne->value; // pCurve->x[1] = ptMoved->x0; // pCurve->y[1] = ptMoved->y0; // } // else if (branchFind.BranchIndex == branch.BranchIndex // && branchFind.DataType == 1) // { // COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); // CCurveEx* pCurve = (CCurveEx*)pOne->value; // pCurve->x[0] = ptMoved->x0; // pCurve->y[0] = ptMoved->y0; // } // } // } // else if (branch.DataType == 3) { // 移动出靶点 // for (const auto &branchFind : pView->m_pDoc->m_BranchElements) // { // if (branchFind.BranchIndex == branch.BranchIndex // && branchFind.DataType == 1) { // COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); // CCurveEx* pCurve = (CCurveEx*)pOne->value; // pCurve->x[1] = ptMoved->x0; // pCurve->y[1] = ptMoved->y0; // } // } // } // else if (branch.DataType == 4) { // 移动井点 // for (const auto &branchFind : pView->m_pDoc->m_BranchElements) // { // if (branchFind.DataType == 0) { // COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); // CCurveEx* pCurve = (CCurveEx*)pOne->value; // pCurve->x[0] = ptMoved->x0; // pCurve->y[0] = ptMoved->y0; // } // } // } // break; // } // } // return 1; //} extern "C" __declspec(dllexport) int WellGroupEditMoveElement(CSigmaView * pView, POSITION elementPos) { int nElementCount = (int)pView->m_pDoc->m_BranchElements.size(); if (nElementCount == 0) { return 0; } COne* pOneMoved = pView->m_pDoc->GetDraw()->GetAt(elementPos); if (pOneMoved->GetType() == DOUBLEFOX_CURVE) { CCurveEx* pCurve = (CCurveEx*)pOneMoved->value; for (int i = 0; i < nElementCount; i++) { WellGroupBranchStruct branch = pView->m_pDoc->m_BranchElements[i]; if (branch.DataPosition == elementPos) { // 水平段被移动 if (branch.DataType == 1) { for (const auto &branchFind : pView->m_pDoc->m_BranchElements) { if (branchFind.BranchIndex == branch.BranchIndex) { if (branchFind.DataType == 0) { COne* pOneOffset = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CCurveEx* pCurveOffset = (CCurveEx*)pOneOffset->value; pCurveOffset->x[1] = pCurve->x[0]; pCurveOffset->y[1] = pCurve->y[0]; } else if (branchFind.DataType == 2) { COne* pOneOffset = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CPointNameEx* pPtStart = (CPointNameEx*)pOneOffset->value; pPtStart->x0 = pCurve->x[0]; pPtStart->y0 = pCurve->y[0]; } else if (branchFind.DataType == 3) { COne* pOneOffset = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CPointNameEx* pPtStart = (CPointNameEx*)pOneOffset->value; pPtStart->x0 = pCurve->x[1]; pPtStart->y0 = pCurve->y[1]; } } } } break; } } } else if (pOneMoved->GetType() == DOUBLEFOX_POINT) { CPointNameEx* ptMoved = (CPointNameEx*)pOneMoved->value; for (int i = 0; i < nElementCount; i++) { WellGroupBranchStruct branch = pView->m_pDoc->m_BranchElements[i]; if (branch.DataPosition == elementPos) { // 移动的是入靶点 if (branch.DataType == 2) { for (const auto &branchFind : pView->m_pDoc->m_BranchElements) { if (branchFind.BranchIndex == branch.BranchIndex && branchFind.DataType == 0) { COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CCurveEx* pCurve = (CCurveEx*)pOne->value; pCurve->x[1] = ptMoved->x0; pCurve->y[1] = ptMoved->y0; } else if (branchFind.BranchIndex == branch.BranchIndex && branchFind.DataType == 1) { COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CCurveEx* pCurve = (CCurveEx*)pOne->value; pCurve->x[0] = ptMoved->x0; pCurve->y[0] = ptMoved->y0; } } } else if (branch.DataType == 3) { // 移动出靶点 for (const auto &branchFind : pView->m_pDoc->m_BranchElements) { if (branchFind.BranchIndex == branch.BranchIndex && branchFind.DataType == 1) { COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CCurveEx* pCurve = (CCurveEx*)pOne->value; pCurve->x[1] = ptMoved->x0; pCurve->y[1] = ptMoved->y0; } } } else if (branch.DataType == 4) { // 移动井点 for (const auto &branchFind : pView->m_pDoc->m_BranchElements) { if (branchFind.DataType == 0) { COne* pOne = pView->m_pDoc->GetDraw()->GetAt(branchFind.DataPosition); CCurveEx* pCurve = (CCurveEx*)pOne->value; pCurve->x[0] = ptMoved->x0; pCurve->y[0] = ptMoved->y0; } } } break; } } } return 1; } extern "C" __declspec(dllexport) int WellGroupEditMoveElementS(CSigmaView * pView) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return 0; CItemWellGroupEdit * pItemEdit = dynamic_cast(pItem); if (pItemEdit == NULL) return 0; CPositionList* pSelects = &(pItemEdit->m_selection); // 被选中的图元列表 POSITION pos, pt; pos = pSelects->GetHeadPosition(); while (pos != NULL) { pt = pSelects->GetNext(pos); WellGroupEditMoveElement(pView, pt); } return 1; } extern "C" __declspec(dllexport) double XyGetCurveLength(CXy* pXy, POSITION pos) { COne* pOne = pXy->GetAt(pos); if (pOne == nullptr) { return 0; } CCurveEx* pCurve = (CCurveEx*)pOne->value; if (pCurve == nullptr) { return 0; } return pCurve->Length(); } extern "C" __declspec(dllexport) void SetBranchHorizonLength(CSigmaView * pView,double curveLength, POSITION elementPos) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return; CItemWellGroupEdit * itemEdit = dynamic_cast(pItem); if (itemEdit == NULL) return; itemEdit->SetBranchHorizonLength(curveLength, elementPos); } /// /// 克隆井组数据 /// extern "C" __declspec(dllexport) bool WellGroupClone(CSigmaView* pView, POSITION posSelect) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return nullptr; CItemSelect * itemSelect = dynamic_cast(pItem); if (itemSelect == nullptr || itemSelect->m_selection.IsEmpty()) { return nullptr; } pView->m_pDoc->SaveActionPosition(); POSITION pos = (itemSelect->m_selection).GetHeadPosition(); // 克隆模版 POSITION posElement = itemSelect->m_selection.GetAt(pos); CXy* pXy = pView->m_pDoc->m_pXy; COne* pOne = pXy->GetAt(posElement); CWellGroup* pGroup = (CWellGroup*)pOne->value; int selBranchCount = pGroup->WellBranches.size(); double dSelX = pGroup->x0; double dSelY = pGroup->y0; int leftCount = pGroup->m_pParameter->BranchCountLeft; int rightCount = pGroup->m_pParameter->BranchCountRight; CPtrList * values = pXy->GetValueList(); pos = values->GetHeadPosition(); CActionListItem* pAction = new CActionListItem(pView->m_pDoc, ID_PROCESS_CURVE_ENCRYPT); int nCount = 0; while (pos) { if (pos == posElement) { values->GetNext(pos); continue; } COne* pOne = pXy->GetAt(pos); if (pOne->GetType() == WELL_GROUP) { CWellGroup* pWellDest = (CWellGroup*)pOne->value; if (pWellDest->m_pParameter == nullptr) { continue; } int leftCountDes = pWellDest->m_pParameter->BranchCountLeft; int rightCountDes = pWellDest->m_pParameter->BranchCountRight; // 如果井支数不同,则不进行克隆 //int branchCount = pWellDest->WellBranches.size(); if (leftCountDes != leftCount || rightCountDes != rightCount) { values->GetNext(pos); continue; } // 添加撤销功能 CActionModifiedItem* pModifiedItem = new CActionModifiedItem(pView->m_pDoc, IDS_STRING_CURVE); pModifiedItem->BackupOldItem(pos, pOne); CWellGroup wellOld; wellOld = *pWellDest; double dXOld = pWellDest->x0; double dYOld = pWellDest->y0; double dXOffset = dXOld - dSelX; double dYOffset = dYOld - dSelY; // 复制井组数据 *pWellDest = *pGroup; pWellDest->Offset(dXOffset, dYOffset); pWellDest->SetName(wellOld.GetName()); for (int i = 0; i < pWellDest->WellBranches.size(); i++) { if (wellOld.WellBranches.size() > i) { CString strStartName = wellOld.WellBranches[i]->PointStart.GetName(); pWellDest->WellBranches[i]->PointStart.SetName(strStartName); CString strEndName = wellOld.WellBranches[i]->PointEnd.GetName(); pWellDest->WellBranches[i]->PointEnd.SetName(strEndName); } } nCount++; // 撤销恢复 pModifiedItem->BackupNewItem(); pAction->AddTailItem(pModifiedItem); } values->GetNext(pos); } if (nCount > 0) { pView->m_pDoc->SetActionItem(pAction); } else { delete pAction; } return true; } extern "C" __declspec(dllexport) BSTR WellGroupStatistic(CSigmaView* pView) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return nullptr; CItemSelect * itemSelect = dynamic_cast(pItem); if (itemSelect == nullptr || itemSelect->m_selection.IsEmpty()) { return nullptr; } // 创建一个XML的文档对象。 TiXmlDocument *xmlDocument = new TiXmlDocument(); TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "UTF-8", ""); xmlDocument->LinkEndChild(decl); // 根元素。 TiXmlElement *rootElement = new TiXmlElement("ROOT"); xmlDocument->LinkEndChild(rootElement); int decimal = 6; CXy* pXy = pView->m_pDoc->m_pXy; for (POSITION pos = (itemSelect->m_selection).GetHeadPosition(); pos != nullptr; (itemSelect->m_selection).GetNext(pos)) { CString strText; POSITION pt = itemSelect->m_selection.GetAt(pos); COne* pOne = pXy->GetAt(pt); if (pOne->GetType() == WELL_GROUP) { CWellGroup* pGroup = (CWellGroup*)pOne->value; CString strName = pGroup->GetName(); for (const auto &branch : pGroup->WellBranches) { TiXmlElement *itemElement = new TiXmlElement("Item"); rootElement->LinkEndChild(itemElement); TiXmlElement *nameElement = new TiXmlElement("井号"); itemElement->LinkEndChild(nameElement); TiXmlText *nameValue = new TiXmlText(strName); nameElement->LinkEndChild(nameValue); TiXmlElement *nameStart = new TiXmlElement("入靶点"); itemElement->LinkEndChild(nameStart); strText = branch->PointStart.GetName(); TiXmlText *startValue = new TiXmlText(strText); nameStart->LinkEndChild(startValue); TiXmlElement *nameStartX = new TiXmlElement("入靶点X"); itemElement->LinkEndChild(nameStartX); AfxGetPublicFunction()->FloatToString(strText, branch->PointStart.x0, decimal); TiXmlText *startX = new TiXmlText(strText); nameStartX->LinkEndChild(startX); TiXmlElement *nameStartY = new TiXmlElement("入靶点Y"); itemElement->LinkEndChild(nameStartY); AfxGetPublicFunction()->FloatToString(strText, branch->PointStart.y0, decimal); TiXmlText *startY = new TiXmlText(strText); nameStartY->LinkEndChild(startY); TiXmlElement *nameEnd = new TiXmlElement("出靶点"); itemElement->LinkEndChild(nameEnd); strText = branch->PointEnd.GetName(); TiXmlText *EndValue = new TiXmlText(strText); nameEnd->LinkEndChild(EndValue); TiXmlElement *nameEndX = new TiXmlElement("出靶点X"); itemElement->LinkEndChild(nameEndX); AfxGetPublicFunction()->FloatToString(strText, branch->PointEnd.x0, decimal); TiXmlText *endX = new TiXmlText(strText); nameEndX->LinkEndChild(endX); TiXmlElement *nameEndY = new TiXmlElement("出靶点Y"); itemElement->LinkEndChild(nameEndY); AfxGetPublicFunction()->FloatToString(strText, branch->PointEnd.y0, decimal); TiXmlText *endY = new TiXmlText(strText); nameEndY->LinkEndChild(endY); // 计算垂直靶前距 double xA = pGroup->x0; double yA = pGroup->y0; double xB = branch->PointStart.x0; double yB = branch->PointStart.y0; double xC = xB; double yC = yB; double xD = branch->PointEnd.x0; double yD = branch->PointEnd.y0; double xAB = xB - xA; double yAB = yB - yA; double xCD = xD - xC; double yCD = yD - yC; double cos = (xAB*xCD + yAB * yCD) / sqrt((xAB*xAB + yAB * yAB)*(xCD*xCD+yCD*yCD)); double distOffset = sqrt(xAB*xAB + yAB * yAB)*cos; // 靶前位移 double dOffsetLength = sqrt(xAB*xAB + yAB * yAB); TiXmlElement *branchOffset = new TiXmlElement("靶前位移"); itemElement->LinkEndChild(branchOffset); AfxGetPublicFunction()->FloatToString(strText, dOffsetLength, decimal); TiXmlText *valueBranchOffset = new TiXmlText(strText); branchOffset->LinkEndChild(valueBranchOffset); // 垂直靶前距 TiXmlElement *nameOffsetDist = new TiXmlElement("垂直靶前距"); itemElement->LinkEndChild(nameOffsetDist); AfxGetPublicFunction()->FloatToString(strText, distOffset, decimal); TiXmlText *valueDist = new TiXmlText(strText); nameOffsetDist->LinkEndChild(valueDist); // 井支长度 double dBranchLength = sqrt(xCD * xCD + yCD * yCD); TiXmlElement *branchLength = new TiXmlElement("井支长度"); itemElement->LinkEndChild(branchLength); AfxGetPublicFunction()->FloatToString(strText, dBranchLength, decimal); TiXmlText *valueBranchLength = new TiXmlText(strText); branchLength->LinkEndChild(valueBranchLength); // 井支角度 double dBranchAngle = 0; if (xCD == 0) { dBranchAngle = 90; } else { dBranchAngle = atan(yCD / xCD); dBranchAngle = dBranchAngle * 180 / PI; } TiXmlElement *branchAngle = new TiXmlElement("井支角度"); itemElement->LinkEndChild(branchAngle); AfxGetPublicFunction()->FloatToString(strText, dBranchAngle, decimal); TiXmlText *valueBranchAngle = new TiXmlText(strText); branchAngle->LinkEndChild(valueBranchAngle); } } } TiXmlPrinter printer; xmlDocument->Accept(&printer); CString strReturn(""); strReturn = CString(printer.CStr()); delete xmlDocument; xmlDocument = nullptr; return strReturn.AllocSysString(); }