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.

552 lines
13 KiB
C++

1 month ago
// WellPoleDoc.cpp: 实现文件
//
#include "stdafx.h"
#include "ItemWellSection.h"
// WellPoleDoc
#include "DrawOperator/XyIO.h"
#include "DrawOperator/FileUtility.h"
#include "WellPoleLib/WellBaseObj.h"
#include "WellPoleLib/InTrackDepthSegment.h"
#include "WellPoleLib/TrackObj.h"
#include "WellPoleLib/TrackGroup.h"
#include "WellPoleLib/InclinedWellPole.h"
#include "WellPoleLib/InclinedTrack.h"
#include "WellPoleLib/TrackDepth.h"
#include "WellPoleLib/TrackCurve.h"
#include "WellPoleLib/TrackResult.h"
#include "WellPoleLib/WellPole.h"
#include "WellPoleLib/WellObjExtendInfo.h"
#include "MultiWellSectionLib/SectionWellObj.h"
#include "MultiWellSectionLib/FaultObj.h"
#include "MultiWellSectionLib/BendObj.h"
#include "MultiWellSectionLib/WellSection.h"
#include "MultiWellSectionDoc.h"
#include "MultiWellSectionlView.h"
#include "SigmaStore.h"
#include "../../UndoManager/UndoManager.h"
CMultiWellSectionDoc::CMultiWellSectionDoc()
{
m_pItemView = nullptr;
m_pItemView = std::make_unique<CItemView>(this);
m_pLastAction = NULL;
}
CMultiWellSectionDoc::~CMultiWellSectionDoc()
{
DeleteItem();
}
BOOL CMultiWellSectionDoc::OpenFile(LPCTSTR lpszFileName, BOOL bMergeFile)
{
if (!bMergeFile)
{
if (m_pXy != NULL) {
m_pXy->Clear();
}
// GdfCloseFile();
}
if (m_pXy == NULL)
m_pXy = new CXy;
m_pXy->SetXyType(CXy::XYTYPE::wellSection);
// 如果是恢复模式就用备份的数据和Action替换从文件获取内容
if (m_recoverMode)
{
if (CSigmaStore::GetInstance().Load(this, lpszFileName))
{
return TRUE;
}
return FALSE;
}
AfxGetPublicFunction()->EnableJudgeRange(TRUE);
if (m_pXy->ReadOtherWithExtension(lpszFileName))
{
m_FileName = lpszFileName;
return TRUE;
}
CString path(lpszFileName);
m_TempFileName = PreprocessFile(path);
if (m_TempFileName.IsEmpty())
{
return FALSE;
}
std::vector<COne*> oneList = m_pXy->GetLatestReadOnes();
oneList.clear();
CSplitPath sp(m_TempFileName);
CString ext = sp.GetExtension();
if (ext == ".pcg")
{
if (m_pXy == NULL)
m_pXy = new CXy;
GetDraw()->PCG_Read3(m_TempFileName);
}
else
{
CFile file;
if (file.Open(m_TempFileName, CFile::modeRead))
{
m_FileName = lpszFileName;
// FIXME: 我们基础库暂时依赖这个来获取要保存的文件名
//AfxGetPublicFunction()->__CurrentSaveFilePath = lpszFileName;
CArchive ar(&file, CArchive::load);
Serialize(ar);
ar.Close();
file.Close();
}
}
if (m_pXy != nullptr)
{
m_pXy->EnableMeshPackage(m_bEnableMeshPackage);
}
if (!m_TempFileName.IsEmpty() && m_TempFileName != path)
{
CFile::Remove(m_TempFileName);
m_TempFileName = "";
}
return TRUE;
}
BOOL CMultiWellSectionDoc::SaveFile(LPCTSTR lpszPathName)
{
CString newName = lpszPathName;
newName.MakeLower();
if (newName.GetLength() > 4)
newName = newName.Right(4);
if (newName.Find(".pcg") == 0)
m_nDocTypeID = DF_FORMAT_PCG;
m_FileName = lpszPathName;
CFile file;
if (file.Open(m_FileName, CFile::modeCreate | CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
Serialize(ar);
ar.Close();
file.Close();
PostProcessFile(m_FileName);
SaveActionPosition();
return TRUE;
}
return FALSE; // success
}
// WellPoleDoc 命令
CItem* CMultiWellSectionDoc::FindItem(int nType)
{
CItem* pit = NULL;
if (nType == ITEM_WELLSECTION)
{
pit = new CItemWellSection(this);
return pit;
}
else
return CSigmaDoc::FindItem(nType);
}
int CMultiWellSectionDoc::GetNodeWidth(void)
{
return 2;
}
CItemSelect* CMultiWellSectionDoc::GetSelectItem(void)
{
if (GetItem() == NULL) return NULL;
if (GetItem()->GetType() != ITEM_SELECT && !GetItem()->IsNestItem())
return NULL;
return (CItemSelect*)GetItem();
}
void CMultiWellSectionDoc::RemoveAt(COne* pOne)
{
GetDraw()->RemoveAt(pOne);
}
CSize CMultiWellSectionDoc::GetDocSize(void)
{
CSize sizeTotal(100, 100);
if (GetDraw() == NULL)return sizeTotal;
if (GetDraw()->GetCount() == 0)return sizeTotal;
CRect8 rect = GetDraw()->m_range;
double xm, ym, dx, dy;
dx = rect.right - rect.left;
dy = rect.top - rect.bottom;
xm = GetDC().left - rect.left;
ym = rect.top - GetDC().top;
int hts = GetDC().GetScreenWidth(dx);
int vts = GetDC().GetScreenHeight(fabs(dy));
vts = abs(vts);
sizeTotal.cx = hts;
sizeTotal.cy = vts;
return sizeTotal;
}
POSITION CMultiWellSectionDoc::AddElement(COne* pOne)
{
return GetDraw()->AddTailOne(pOne);
}
void CMultiWellSectionDoc::OnDraw(CXyDC& dc)
{
//TRACE(_T("CDrawDoc::OnDraw(CXyDC&),count=%ld\n"), GetDraw()->GetCount());
GetDraw()->Draw(dc, false);
}
void CMultiWellSectionDoc::Serialize(CArchive& ar)
{
CPublicFunction& pf = *AfxGetPublicFunction();
if (ar.IsStoring())
{
short ver = -1;
if (m_nDocTypeID == DF_FORMAT_PCG)
{
//BeginProgress(IDS_STRING_WriteFile);
CWellSection* pWellSection = GetWellSection();
if (pWellSection)
{
CXy* pxy = GetDraw();
CXyIO xy; xy.AttachInput(pxy, false);
CRect rt = GetView()->GetClientRect();
pxy->m_display = GetDC().GetReal(rt);
pxy->m_display.NormalizeRect();
GetDC().GetScale(pxy->m_scaleSize.cx, pxy->m_scaleSize.cy);
pxy->PCG_WriteCrossSection(*ar.GetFile(), ver);//本操作会导致剖面图元的POSITION发生变化因此需要在操作完成后重新设置Item中的POSITION
}
}
else
{
CSigmaDoc::Serialize(ar);
}
}
else
{
//CSigmaDoc::Serialize(ar);
if (m_pXy == NULL) m_pXy = new CXy;
//BeginProgress(IDS_STRING_OpenFile);
CString name = ar.GetFile()->GetFileName();
name.MakeLower();
CSplitPath sp(name);
CString ext = sp.GetExtension();
//ar.m_pDocument = this; // set back-pointer in archive
if (ext == _T(".dfb") ||
ext == _T(".dft"))
{
m_pXy->m_version = m_pXy->DFB_ReadVersion(ar);
m_pXy->DFB_ReadEncrypt(ar, m_pXy->m_version);
if (m_pXy->IsEncrypted())
{
//if (!VerifyPassword(GetDraw()))
//{
// m_bCancelRead = TRUE;
// EndProgress();
// return;
//}
}
m_pXy->DFB_Serialize(ar, m_pXy->m_version);
}
else if (ext == ".dml" || ext == ".xml")
m_pXy->DML_Read2(*(ar.GetFile()));
else if (ext == ".pcg")
GetDraw()->PCG_Read3(ar.m_strFileName);//m_pXy->PCG_Read2(*(ar.GetFile()));
else if (ext == ".kev")
{
m_pXy->DFD_Read2(*(ar.GetFile()));
}
else if (ext == ".dfd")
{
m_pXy->DFD_Read2(*(ar.GetFile()));
}
else if (ext == ".xyz")
{
m_pXy->DFD_Read2(*(ar.GetFile()));
}
}
}
BOOL CMultiWellSectionDoc::GetElementRect(POSITION pos, CRect8& range)
{
if (pos == NULL) return FALSE;
range = GetDraw()->GetAt(pos)->GetRect();
return TRUE;
}
void CMultiWellSectionDoc::SetActionItem(CActionItem* pAction, bool bDo/*=true*/)
{
m_pLastAction = pAction;
if (bDo) m_pLastAction->Do();
}
//CWellPole* CMultiWellSectionDoc::GetWellPole()
//{
// CWellPole *pWell = NULL;
// POSITION pos = GetDraw()->GetValueList()->GetHeadPosition();
// while(pos != NULL)
// {
// COne* pOne = (COne*)GetDraw()->GetValueList()->GetNext(pos);
// if (pOne->GetType() == KEP_WELL)
// {
// pWell = (CWellPole*)pOne->GetValue();
// break;
// }
// }
//
// return pWell;
//}
//
//COne* CMultiWellSectionDoc::GetWellPoleOne()
//{
// CWellPole *pWell = NULL;
// POSITION pos = GetDraw()->GetValueList()->GetHeadPosition();
// while (pos != NULL)
// {
// COne* pOne = (COne*)GetDraw()->GetValueList()->GetNext(pos);
// if (pOne->GetType() == KEP_WELL)
// {
// return pOne;
// break;
// }
// }
//
// return NULL;
//}
CWellSection* CMultiWellSectionDoc::GetWellSection()
{
CWellSection *pWellSection = NULL;
POSITION pos = GetDraw()->GetValueList()->GetHeadPosition();
while (pos != NULL)
{
COne* pOne = (COne*)GetDraw()->GetValueList()->GetNext(pos);
if (pOne->GetType() == KEP_WELLSECTION)
{
pWellSection = (CWellSection*)pOne->GetValue();
break;
}
}
return pWellSection;
}
COne* CMultiWellSectionDoc::GetWellSectionOne()
{
CWellPole *pWell = NULL;
POSITION pos = GetDraw()->GetValueList()->GetHeadPosition();
while (pos != NULL)
{
COne* pOne = (COne*)GetDraw()->GetValueList()->GetNext(pos);
if (pOne->GetType() == KEP_WELLSECTION)
{
return pOne;
break;
}
}
return NULL;
}
void CMultiWellSectionDoc::NormalEXTLogFont(GDFLOGFONTEXT& font)
{
long nH = font.m_logFont.lfHeight;
double dScaleX = 1;
double dScaleY = 1;
GetDC().GetScale(dScaleX, dScaleY);
GetDC().SetScale(0.1, 0.1);
font.m_dHeight = GetDC().GetRealHeight(nH*72.0 / GetDC().GetDC()->GetDeviceCaps(LOGPIXELSY));
GetDC().SetScale(dScaleX, dScaleY);
if (font.m_logFont.lfFaceName == "Times New Roman")
font.m_dWidth = font.m_dHeight*0.4;
else
font.m_dWidth = font.m_dHeight*0.5;
}
BOOL CMultiWellSectionDoc::GetDrawRange(CRect8& rect)
{
CWellSection* pWellSection= GetWellSection();
if(pWellSection == NULL)
return CSigmaDoc::GetDrawRange(rect);
else
{
rect = pWellSection->GetRect();
rect.InflateRect(100, 100);
}
return TRUE;
}
void CMultiWellSectionDoc::ClearSelection(void)
{
if (GetItemType() == ITEM_SELECT || GetItemType() == ITEM_WELLSECTION)
GetSelectItem()->CancelSelection();
}
int CMultiWellSectionDoc::Undo()
{
CItem* pItem = GetItem();
if (pItem != NULL && pItem->GetType() == ITEM_WELLSECTION)
{
CItemWellSection *pWellItem = (CItemWellSection *)pItem;
pWellItem->m_WellObjSelectlist.RemoveAll();
}
return m_pActionMgr->Undo();
}
int CMultiWellSectionDoc::Redo()
{
CItem* pItem = GetItem();
if (pItem != NULL && pItem->GetType() == ITEM_WELLSECTION)
{
CItemWellSection *pWellItem = (CItemWellSection *)pItem;
pWellItem->m_WellObjSelectlist.RemoveAll();
}
return m_pActionMgr->Redo();
}
CWellSection* CMultiWellSectionDoc::CreateNewWellSection(LPCTSTR title, double depthScale, double levelScale, double horizonScale)
{
CWellSection* pWellSection = new CWellSection();
GetDraw()->AddElement(pWellSection, KEP_WELLSECTION);
pWellSection->m_strTitleName = title;
pWellSection->m_fDepthScale = depthScale;
pWellSection->m_fHorzScale = horizonScale;
pWellSection->m_fLevelScale = levelScale;
pWellSection->m_bResForm = TRUE;
pWellSection->GetFeature()->m_nBendFillStyle = 1;
return pWellSection;
}
CSectionWellObj* CMultiWellSectionDoc::AddNewWell(LPCSTR wellName, double depthScale, double top, double bottom, double x, double y, double bushingLevel, LPCTSTR wellTemplateFile)
{
CSectionWellObj* pWellPole = NULL;
if (wellTemplateFile != NULL && wellName != NULL)
{
CKXmlParse xp;
if (xp.ReadXmlFile((char*)wellTemplateFile))
{
CSectionWellObj* pWell1 = new CSectionWellObj();
int ret = pWell1->ReadPCG(xp, -1);
if (ret == 0)
delete pWell1;
else
{
pWellPole = pWell1;
pWellPole->SetDepthProportion(depthScale);
pWellPole->SetWellDepth(top, bottom);
pWellPole->SetWellName(wellName);
pWellPole->SetTitle(wellName);
pWellPole->m_fX = x;
pWellPole->m_fY = y;
pWellPole->m_fLevel = bushingLevel;
CWellSection *pWellSection = GetWellSection();
pWellSection->m_WellList.AddTail(pWellPole);
pWellPole->CWellBaseObj::SetParent(pWellSection); //要使用基类的函数否则会将所有track的parent设置为剖面
pWellPole->SetParentXY(this->GetDraw());
pWellPole->CalculateSize(pWellPole->GetRect().TopLeft());
}
}
}
return pWellPole;
}
void CMultiWellSectionDoc::WellSectionReSetAllWellsPosition(BOOL bNeedComputedDepth, double topExtent, double bottomExtent)
{
CWellSection* pWellSection = GetWellSection();
double fXPre;
double fYPre;
CSectionWellObj *pSectionWell;
BOOL bFirst = TRUE;
POSITION pos = pWellSection->m_WellList.GetHeadPosition();
while (pos != NULL)
{
pSectionWell = (CSectionWellObj*)pWellSection->m_WellList.GetNext(pos);
if (bFirst)
{
pSectionWell->m_fHorzDistance = 0;
fXPre = pSectionWell->m_fX;
fYPre = pSectionWell->m_fY;
bFirst = FALSE;
}
else
{
pSectionWell->m_fHorzDistance = sqrt((pSectionWell->m_fX - fXPre)*(pSectionWell->m_fX - fXPre) + (pSectionWell->m_fY - fYPre)*(pSectionWell->m_fY - fYPre));
fXPre = pSectionWell->m_fX;
fYPre = pSectionWell->m_fY;
}
if (bNeedComputedDepth)
{
double top, bottom;
pSectionWell->GetDatasTopBottomDepth(top, bottom);
top -= topExtent;
bottom += bottomExtent;
pSectionWell->SetWellDepth(top, bottom);
}
else
{
pSectionWell->SetWellDepth(pSectionWell->m_dSdep - topExtent, pSectionWell->m_dEdep + bottomExtent);
}
}
pWellSection->ComputeSectionPosition();
pWellSection->ReSetPosition();
}
void CMultiWellSectionDoc::WellSectionConnectLayers(CStringArray& strTrackTypeArr)
{
if (strTrackTypeArr.GetSize() == 0)
return;
std::vector<CWellObjExtendInfo*> trackInfos = CWellObjExtendInfoMgr::GetInstance()->GetWellTrackInfos();
std::vector<int> trackTypes;
for (int i = 0; i < strTrackTypeArr.GetSize(); i++)
{
for (int j = 0; j < trackInfos.size(); j++)
{
if (strTrackTypeArr[i] == trackInfos[j]->m_cTypeStr)
trackTypes.push_back(trackInfos[j]->m_type);
}
}
CWellSection* pWellSection = GetWellSection();
CItemWellSection* pItemWellSection = new CItemWellSection(this);
pItemWellSection->SetDrawObj(pWellSection);
pItemWellSection->CreateLayers(trackTypes);
delete pItemWellSection;
}