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

289 lines
9.5 KiB
C++

1 month ago
#include "stdafx.h"
#include "ItemWellGroupEdit.h"
#include "ActionDeleteItem.h"
CItemWellGroupEdit::CItemWellGroupEdit(CSigmaDoc * ppDoc)
:CItemSelect(ppDoc)
{
m_pWellGroupOne = nullptr;
this->SetType(ITEM_WELL_GROUP_EDIT);
}
CItemWellGroupEdit::~CItemWellGroupEdit(void)
{
if (m_pWellGroupOne != nullptr)
{
delete m_pWellGroupOne;
m_pWellGroupOne = nullptr;
}
}
int CItemWellGroupEdit::DeleteSelection(void)
{
if (GetItemForGrid()) this->DeleteItemGrid();
//GetDoc()->InvalidateDelete(m_selection);
if (m_selection.IsEmpty())
return 0;
int nResult = m_selection.GetSize();
POSITION posSelect = m_selection.GetHead();
for (int i = 0; i < m_pDoc->m_BranchElements.size(); i++)
{
WellGroupBranchStruct branchInfo = m_pDoc->m_BranchElements[i];
if (posSelect == branchInfo.DataPosition) {
if (branchInfo.DataType <= 3) {
m_selection.RemoveAll();
for (int j = 0; j < m_pDoc->m_BranchElements.size(); j++) {
if (m_pDoc->m_BranchElements[j].BranchIndex == branchInfo.BranchIndex)
{
m_selection.AddTail(m_pDoc->m_BranchElements[j].DataPosition);
}
}
break;
}
}
}
CActionDeleteItem * deleteItem = new CActionDeleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, m_selection);
GetDoc()->SetActionItem(deleteItem);
for (int i = (int)m_pDoc->m_BranchElements.size() - 1; i >= 0; i--) {
POSITION posList = m_selection.GetHeadPosition();
while (posList != nullptr) {
POSITION posFind = m_selection.GetNext(posList);
if (posFind == m_pDoc->m_BranchElements[i].DataPosition)
{
m_pDoc->m_BranchElements.erase(m_pDoc->m_BranchElements.begin() + i);
}
}
}
m_selection.RemoveAll();
m_Tracker.Clear();
return nResult;
}
int CItemWellGroupEdit::OnMouseMove(CDC * pDC, UINT nFlags, CPoint point)
{
int nElementCount = (int)GetDoc()->m_BranchElements.size();
CXy* pXy = GetDoc()->GetDraw();
for (POSITION pos = (m_selection).GetHeadPosition(); pos != nullptr; (m_selection).GetNext(pos))
{
POSITION posOne = m_selection.GetAt(pos);
for (auto &item : GetDoc()->m_BranchElements) {
if (item.DataPosition == posOne && item.DataType == 0) {
return 0;
}
}
}
return CItemSelect::OnMouseMove(pDC, nFlags, point);
}
BOOL CItemWellGroupEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
int nElementCount = (int)GetDoc()->m_BranchElements.size();
CXy* pXy = GetDoc()->GetDraw();
for (POSITION pos = (m_selection).GetHeadPosition(); pos != nullptr; (m_selection).GetNext(pos))
{
POSITION posOne = m_selection.GetAt(pos);
for (auto &item : GetDoc()->m_BranchElements) {
if (item.DataPosition == posOne && item.DataType == 0) {
return false;
}
}
}
return CItemSelect::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CItemWellGroupEdit::SetBranchHorizonLength(double curveLength, POSITION pos) {
for (int i = 0; i < m_pDoc->m_BranchElements.size(); i++) {
POSITION posFind = m_pDoc->m_BranchElements[i].DataPosition;
if (pos == posFind) {
if (m_pDoc->m_BranchElements[i].DataType == 1)
{
COne* pOne = m_pDoc->GetDraw()->GetAt(pos);
CCurveEx* pCurve = (CCurveEx*)pOne->value;
double dX1 = pCurve->x[0];
double dY1 = pCurve->y[0];
double dX2 = pCurve->x[1];
double dY2 = pCurve->y[1];
double dL = pCurve->Length();
if (dL == 0) {
return;
}
double dX = (curveLength / dL)*(dX2 - dX1) + dX1;
double dY = (curveLength / dL)*(dY2 - dY1) + dY1;
pCurve->x[1] = dX;
pCurve->y[1] = dY;
for (int j = 0; j < m_pDoc->m_BranchElements.size(); j++) {
if (m_pDoc->m_BranchElements[j].DataType == 3
&& m_pDoc->m_BranchElements[j].BranchIndex== m_pDoc->m_BranchElements[i].BranchIndex)
{
COne* pOnePt = m_pDoc->GetDraw()->GetAt(m_pDoc->m_BranchElements[j].DataPosition);
CPointNameEx* pPoint = (CPointNameEx*)pOnePt->value;
pPoint->x0 = dX;
pPoint->y0 = dY;
}
}
}
else if (m_pDoc->m_BranchElements[i].DataType == 0)
{
COne* pOne = m_pDoc->GetDraw()->GetAt(pos);
CCurveEx* pCurve = (CCurveEx*)pOne->value;
double dX1 = pCurve->x[0];
double dY1 = pCurve->y[0];
double dX2 = pCurve->x[1];
double dY2 = pCurve->y[1];
double dL = pCurve->Length();
if (dL == 0) {
return;
}
double dX = (curveLength / dL)*(dX2 - dX1) + dX1;
double dY = (curveLength / dL)*(dY2 - dY1) + dY1;
pCurve->x[1] = dX;
pCurve->y[1] = dY;
for (int j = 0; j < m_pDoc->m_BranchElements.size(); j++) {
if (m_pDoc->m_BranchElements[j].BranchIndex != m_pDoc->m_BranchElements[i].BranchIndex)
{
continue;
}
if (m_pDoc->m_BranchElements[j].DataType == 2)
{
COne* pOnePt = m_pDoc->GetDraw()->GetAt(m_pDoc->m_BranchElements[j].DataPosition);
CPointNameEx* pPoint = (CPointNameEx*)pOnePt->value;
pPoint->x0 = dX;
pPoint->y0 = dY;
}
else if (m_pDoc->m_BranchElements[j].DataType == 1) {
COne* pOneHori = m_pDoc->GetDraw()->GetAt(m_pDoc->m_BranchElements[j].DataPosition);
CCurveEx* pCurveHori = (CCurveEx*)pOneHori->value;
double dOffsetX = dX - pCurveHori->x[0];
double dOffsetY = dY - pCurveHori->y[0];
pCurveHori->x[0] = dX;
pCurveHori->y[0] = dY;
pCurveHori->x[1] = pCurveHori->x[1] + dOffsetX;
pCurveHori->y[1] = pCurveHori->y[1] + dOffsetY;
for (int k = 0; k < m_pDoc->m_BranchElements.size(); k++) {
if (m_pDoc->m_BranchElements[k].BranchIndex == m_pDoc->m_BranchElements[i].BranchIndex
&& m_pDoc->m_BranchElements[k].DataType == 3) {
COne* pOneEnd = m_pDoc->GetDraw()->GetAt(m_pDoc->m_BranchElements[k].DataPosition);
CPointNameEx* ptEnd = (CPointNameEx*)pOneEnd->value;
ptEnd->x0 = pCurveHori->x[1];
ptEnd->y0 = pCurveHori->y[1];
break;
}
}
}
}
}
break;
}
}
}
void CItemWellGroupEdit::SetData(BYTE* buffElement, int buffLen)
{
CXy* pXy = m_pDoc->GetDraw();
if (m_pWellGroupOne == nullptr) {
m_pWellGroupOne = CreateOne();
}
m_pWellGroupOne->ReadMemory(buffElement, 0, buffLen, 3);
CWellGroup* pGroup = (CWellGroup*)m_pWellGroupOne->value;
for (int i = 0; i < pGroup->WellBranches.size(); i++) {
CCurveEx *pCurve = new CCurveEx;
pCurve->Create(2);
pCurve->x[0] = pGroup->x0;
pCurve->y[0] = pGroup->y0;
pCurve->x[1] = pGroup->WellBranches[i]->PointStart.x0;
pCurve->y[1] = pGroup->WellBranches[i]->PointStart.y0;
POSITION pos = pXy->AddElement(pCurve, DOUBLEFOX_CURVE);
COne* pOneOffset = pXy->GetAt(pos);
pOneOffset->HowToViewCurve = pGroup->WellBranches[i]->m_pHowTowViewCurveOffset;
WellGroupBranchStruct branchStruct;
branchStruct.BranchIndex = i;
branchStruct.DataPosition = pos;
branchStruct.DataType = 0;
m_pDoc->m_BranchElements.push_back(branchStruct);
CCurveEx *pCurveHori = new CCurveEx;
pCurveHori->Create(2);
pCurveHori->x[0] = pGroup->WellBranches[i]->PointStart.x0;
pCurveHori->y[0] = pGroup->WellBranches[i]->PointStart.y0;
pCurveHori->x[1] = pGroup->WellBranches[i]->PointEnd.x0;
pCurveHori->y[1] = pGroup->WellBranches[i]->PointEnd.y0;
POSITION posHori = pXy->AddElement(pCurveHori, DOUBLEFOX_CURVE);
COne* pOneHori = pXy->GetAt(posHori);
pOneHori->HowToViewCurve = pGroup->WellBranches[i]->m_pHowTowViewCurveHori;
WellGroupBranchStruct branchStructHori;
branchStructHori.BranchIndex = i;
branchStructHori.DataPosition = posHori;
branchStructHori.DataType = 1;
m_pDoc->m_BranchElements.push_back(branchStructHori);
// <20><><EFBFBD>е<EFBFBD>
CPointNameEx* ptStart = new CPointNameEx;
POSITION posPtStart = pXy->AddElement(ptStart, DOUBLEFOX_POINT);
*ptStart = pGroup->WellBranches[i]->PointStart;
if (pGroup->WellBranches[i]->m_pHowTowViewPointStart != nullptr)
{
CHowToViewPoint* pHowToViewPointStart = new CHowToViewPoint();
*pHowToViewPointStart = *(pGroup->WellBranches[i]->m_pHowTowViewPointStart);
COne* pOnePtStart = pXy->GetAt(posPtStart);
pOnePtStart->HowToViewPoint = pHowToViewPointStart;
}
WellGroupBranchStruct branchPtStart;
branchPtStart.BranchIndex = i;
branchPtStart.DataPosition = posPtStart;
branchPtStart.DataType = 2;
m_pDoc->m_BranchElements.push_back(branchPtStart);
// <20><><EFBFBD>е<EFBFBD>
CPointNameEx* ptEnd = new CPointNameEx;
*ptEnd = pGroup->WellBranches[i]->PointEnd;
POSITION posPtEnd = pXy->AddElement(ptEnd, DOUBLEFOX_POINT);
if (pGroup->WellBranches[i]->m_pHowTowViewPointEnd != nullptr)
{
COne* pOnePtEnd = pXy->GetAt(posPtEnd);
CHowToViewPoint* pHowToViewPointEnd = new CHowToViewPoint();
*pHowToViewPointEnd = *(pGroup->WellBranches[i]->m_pHowTowViewPointEnd);
pOnePtEnd->HowToViewPoint = pHowToViewPointEnd;
}
WellGroupBranchStruct branchPtEnd;
branchPtEnd.BranchIndex = i;
branchPtEnd.DataPosition = posPtEnd;
branchPtEnd.DataType = 3;
m_pDoc->m_BranchElements.push_back(branchPtEnd);
}
// <20><><EFBFBD><EFBFBD>
CPointNameEx* ptWell = new CPointNameEx;
*ptWell = *((CPointNameEx*)pGroup);
POSITION posPtWell = pXy->AddElement(ptWell, DOUBLEFOX_POINT);
COne* pOnePtWell = pXy->GetAt(posPtWell);
if (pGroup->m_pHowTowViewPointWell != nullptr)
{
CHowToViewPoint* pHowToViewPointWell = new CHowToViewPoint();
*pHowToViewPointWell = *pGroup->m_pHowTowViewPointWell;
pOnePtWell->HowToViewPoint = pHowToViewPointWell;
}
WellGroupBranchStruct branchPtWell;
branchPtWell.BranchIndex = -1;
branchPtWell.DataPosition = posPtWell;
branchPtWell.DataType = 4;
m_pDoc->m_BranchElements.push_back(branchPtWell);
}
COne* CItemWellGroupEdit::CreateOne()
{
CWellGroup* pWellGroup = new CWellGroup;
//pWellGroup->x0 = m_pt.x0;
//pWellGroup->y0 = m_pt.y0;
//pWellGroup->z0 = m_z; // m_pt.z0;
//pWellGroup->angle = m_angle;
//pWellGroup->SetName(m_pointName);
COne* pOne = m_pDoc->GetDraw()->CreateOne(pWellGroup, WELL_GROUP);
return pOne;
}