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.

1640 lines
40 KiB
C++

1 month ago
#include <algorithm>
#include "stdafx.h"
#include "SigmaDoc.h"
#include "UndoManager/UndoManager.h"
#include "ItemSelect.h"
#include "ItemEllipse.h"
#include "ItemCircle.h"
#include "ItemProportion.h"
#include "ItemPointAdd.h"
#include "ItemCurveArc.h"
#include "ItemGrid.h"
#include "ItemText.h"
#include "ItemRectangle.h"
#include "ItemEquilateral.h"
#include "ItemDelete.h"
#include "ItemExtendCurve.h"
#include "SigmaView.h"
#include "ItemBreakCurve.h"
#include "ItemTrimCurve.h"
#include "ItemCutIn.h"
#include "ItemCutOut.h"
#include "ItemPointCrossAdd.h"
#include "ItemCurveProcess.h"
#include "ItemCurveEditDeleteMulNodes.h"
#include "ItemEditCurveInName.H"
#include "ItemLinkCurve.h"
#include "DrawOperator/XyIO.h"
#include "PublicParam.h"
#include "ItemCopyAsImage.h"
#include "ItemAlign.h"
#include "ItemMesh.h"
#include "FindReplacement.h"
#include "StringManager.h"
#include "ItemPointProcess.h"
#include "ItemSaveToMark.h"
#include "ItemSolid.h"
#include "ItemSetContourName.h"
#include "ItemCopyAsImageEx.h"
#include "ItemCopyAsImagePolygon.h"
#include "ItemWellGroup.h"
#include "ItemWellGroupEdit.h"
#include "ItemBranchCurveEdit.h"
#include "ItemMeasure.h"
#include "ItemEraser.h"
#include "TinyXml/tinyxml.h"
#include "Util.h"
#include "SigmaStore.h"
#include "DrawOperator\FileUtility.h"
#include "StorageFactory.h"
CSigmaDoc::CSigmaDoc()
: m_bRedraw(true)
, m_pXy(nullptr)
, m_nUnitMode(0)
, m_bSaveAllLayer(true)
, m_bCapture(false)
, m_bEnableMeshPackage(false)
, m_crossPointStatus(-1)
, m_pLastAction(nullptr)
, m_EditLineState(0)
{
MoveSelect = NULL;
DocInit();
m_pDrawer = std::make_unique<CurveHandleDrawer>();
}
CSigmaDoc::~CSigmaDoc()
{
if (m_pXy != nullptr)
{
CSplitPath sp("");
CString path = sp.GetAbsolutePath(m_FileName);
CSigmaStore::GetInstance().Clear(path);
m_pActionMgr.reset();
delete m_pXy;
m_pXy = nullptr;
}
}
double CSigmaDoc::GetCurrentUnitScale(void)
{
CUnit ut;
CSize szUnit = m_pXy->GetUnit();
double scale = ut.Millimetres(CUnit::UNIT_KM) / ut.Millimetres(szUnit.cx);
return scale;
}
void CSigmaDoc::EnableMeshPackage(BOOL isEnable, BOOL force)
{
m_bEnableMeshPackage = isEnable;
if (m_pXy != nullptr) { m_pXy->EnableMeshPackage(isEnable, force); }
}
void CSigmaDoc::SetFaultLayer(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetFaultLayer(layer);
}
}
CString CSigmaDoc::GetFaultLayer()
{
return m_pXy->GetFaultLayer();
}
void CSigmaDoc::SetBorderLayer(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetBorderLayer(layer);
}
}
CString CSigmaDoc::GetBorderLayer()
{
return m_pXy->GetBorderLayer();
}
void CSigmaDoc::SetFaultLayer3D(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetFaultLayer3D(layer);
}
}
CString CSigmaDoc::GetFaultLayer3D()
{
return m_pXy->GetFaultLayer3D();
}
void CSigmaDoc::SetBorderLayer3D(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetBorderLayer3D(layer);
}
}
CString CSigmaDoc::GetBorderLayer3D()
{
return m_pXy->GetBorderLayer3D();
}
void CSigmaDoc::SetWellLayer3D(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetWellLayer3D(layer);
}
}
CString CSigmaDoc::GetWellLayer3D()
{
return m_pXy->GetWellLayer3D();
}
void CSigmaDoc::SetMainMeshLayer3D(CString layer)
{
if (m_pXy != nullptr)
{
m_pXy->SetMeshLayer3D(layer);
}
}
CString CSigmaDoc::GetMainMeshLayer3D()
{
return m_pXy->GetMeshLayer3D();
}
void CSigmaDoc::SetMainMeshId3D(int64_t id)
{
if (m_pXy != nullptr)
{
m_pXy->SetMainMeshId3D(id);
}
}
int64_t CSigmaDoc::GetMainMeshId3D()
{
return m_pXy->GetMainMeshId3D();
}
void CSigmaDoc::DocInit(void) //<2F><><EFBFBD><EFBFBD>m_pItemView<65><77>m_pItemPrint<6E>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (m_pXy) delete m_pXy; m_pXy = NULL;
m_pXy = new CXy();
m_pItemPrint = std::make_unique<CItemPrint>(this);
m_pItemView = std::make_unique<CItemView>(this);
m_pItemView->m_BackColor = this->mBackColor;
m_pActionMgr = std::make_unique<NAction::CActionManager>(this);
m_pFindReplacement = make_unique<CFindReplacement>(this);
}
CItemView* CSigmaDoc::GetItemView()
{
return m_pItemView.get();
}
CXy* CSigmaDoc::GetDraw(void)
{
return m_pXy;
}
void CSigmaDoc::SetDraw(CXy * pXy)
{
m_pXy = pXy;
}
void CSigmaDoc::EnableRedraw(bool bRedraw)
{
m_bRedraw = bRedraw;
}
void CSigmaDoc::Serialize(CArchive& ar, CPositionList& list, CXy* pxy)//fbw
{
if (pxy == NULL)
pxy = GetDraw();
short ver = CUR_VERSION;
if (ar.IsStoring())
{
//BeginProgress(IDS_STRING_WriteClipboard);
pxy->DFB_Write(ar, list, ver);
ar << (int)0;
}
else
{
//BeginProgress(IDS_STRING_ReadClipboard);
if (pxy->DFB_Read(ar, list, ver) > 0)
{
//if (pxy == GetDraw())
//SetModifiedFlag();
}
}
//EndProgress();
}
//void CSigmaDoc::SetModifiedFlag(BOOL bModified /*= TRUE*/)
//{
// CDrawDoc::SetModifiedFlag(bModified);
// ModifyTitle(bModified);
//}
void CSigmaDoc::Serialize(CArchive& ar, double leftMargin, double rightMargin,
double topMargin, double bottomMargin, int paperSizeType, int pdfAHType, int pdfPapertDirectionType)
{
//CPublicFunction& pf = *AfxGetPublicFunction();
//CString name=ar.GetFile()->GetFileName();
//name.MakeLower();
//CSplitPath sp(name);
if (ar.IsStoring())
{
//pf.InitSaveCounter();
CXy* pxy = m_pXy;
short ver = pxy->m_version;
////BeginProgress(IDS_STRING_WriteFile);
CXyIO xy; xy.AttachInput(pxy, false);
CRect rt = m_pView->GetClientRect();
pxy->m_display = GetDC().GetReal(rt);
pxy->m_display.NormalizeRect();
GetDC().GetScale(pxy->m_scaleSize.cx, pxy->m_scaleSize.cy);
switch (m_nDocTypeID)
{
default: //<2F><>ǰȱʡ<C8B1>
pxy->DFD_Write2(*(ar.GetFile()), ver, m_bSaveAllLayer);
break;
case DF_FORMAT_DFT: //˫<><CBAB>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ʽ
case DF_FORMAT_BINARY: //˫<><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD>ʽ
pxy->DFB_SerializeWrite(ar, ver, m_bSaveAllLayer);
break;
case DF_FORMAT_DML:
pxy->DML_WriteAll(*(ar.GetFile()), ver, m_bSaveAllLayer);
break;
case DF_FORMAT_PCG:
pxy->PCG_WriteAll(*(ar.GetFile()), 2, m_bSaveAllLayer);
break;
case DF_FORMAT_OLD_ASCII: //<2F>ϰ汾
pxy->DFD_Write2(*(ar.GetFile()), ver, m_bSaveAllLayer);
break;
case DF_FORMAT_DXF:
//pxy->ToDxf(&GetDC(), *(ar.GetFile()));
xy.ToDxf(&GetDC(), *(ar.GetFile()));
break;
case DF_FORMAT_CGM:
//pf.SetExportDPI(::GetPreferences().WorkaroundSave.m_nExportModeDPI, ::GetPreferences().WorkaroundSave.m_dExportDPI);
pxy->ToCgm(&GetDC(), *(ar.GetFile()));
//xy.ToCgm(&GetDC(), *(ar.GetFile()));
break;
case DF_FORMAT_EPS:
//pf.SetExportDPI(::GetPreferences().WorkaroundSave.m_nExportModeDPI, ::GetPreferences().WorkaroundSave.m_dExportDPI);
//pxy->ToEps(&GetDC(), *(ar.GetFile()));
xy.ToEps(&GetDC(), *(ar.GetFile()));
break;
case DF_FORMAT_PDF:
{
//pf.SetExportDPI(::GetPreferences().WorkaroundSave.m_nExportModeDPI, ::GetPreferences().WorkaroundSave.m_dExportDPI);
//pxy->ToPdf(&GetDC(), *(ar.GetFile()));
CRect8 pRect(leftMargin, topMargin, rightMargin, bottomMargin);
xy.ToPdf(&GetDC(), *(ar.GetFile()), pRect, paperSizeType, pdfAHType, pdfPapertDirectionType);
break;
}
case DF_FORMAT_UMAP_ASC:
//pxy->ToUmap(&GetDC(), *(ar.GetFile()));
xy.ToUmap(&GetDC(), *(ar.GetFile()));
break;
case DF_FORMAT_MAPGIS_W:
//pxy->ToMapGisAsc(&GetDC(), *(ar.GetFile()), FALSE);
xy.ToMapGisAsc(&GetDC(), *(ar.GetFile()), FALSE);
break;
case DF_FORMAT_KML:
//pxy->ToKML(*(ar.GetFile()));
xy.ToKML(*(ar.GetFile()));
break;
case DF_FORMAT_GEOMAP:
//pxy->ToGeoMap(&GetDC(), *(ar.GetFile()));
xy.ToGeoMap(&GetDC(), *(ar.GetFile()));
break;
case DF_FORMAT_XYZ:
pxy->DFD_WriteXYZ(*(ar.GetFile()));
break;
case DF_FORMAT_GDBX:
pxy->ToGDBX(&GetDC(), *ar.GetFile());
break;
}
}
else
{
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")
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()));
}
//// <20>ϲ<EFBFBD><CFB2><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD>
//m_pXy->CreateMeshPackage();
if (this->m_recoverMode)
{
SaveRawFile();
}
}
//EndProgress();
}
BOOL CSigmaDoc::ReloadFile()
{
if (m_FileName.IsEmpty()) {
return FALSE;
}
OpenFile(m_FileName, FALSE);
return TRUE;
}
//extern "C" __declspec(dllexport)
BOOL CSigmaDoc::OpenFile(LPCTSTR lpszFileName, BOOL bMergeFile)
{
if (!bMergeFile)
{
if (m_pXy != NULL) {
m_pXy->Clear();
}
// GdfCloseFile();
}
if (m_pXy == NULL)
m_pXy = new CXy;
// <20><><EFBFBD><EFBFBD><EFBFBD>ǻָ<C7BB>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݺ<EFBFBD>Action<6F><EFBFBD><E6BBBB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
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;
}
CFile file;
if (file.Open(m_TempFileName, CFile::modeRead))
{
m_FileName = lpszFileName;
// FIXME: <20><><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡҪ<C8A1><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//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 CSigmaDoc::CreateNew(LPCTSTR fileName) {
if (m_pXy == NULL)
m_pXy = new CXy;
if (m_pXy != NULL) {
m_pXy->Clear();
}
m_FileName = fileName;
return TRUE;
}
BOOL CSigmaDoc::SaveFile()
{
return SaveFile(m_FileName);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
BOOL CSigmaDoc::SaveFile(LPCTSTR lpszPathName)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
if (newName.IsEmpty())
{
//newName = m_strTitle;
newName = "newFile.kev";
}
m_nDocTypeID = DF_FORMAT_ASCII;
return false;
}
else
{
CString ext = AfxGetPublicFunction()->GetSplitPath(newName, "ext");
if (ext.MakeLower() == _T(".xyz"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_XYZ;
}
else if (ext.MakeLower() == _T(".gdbx"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_GDBX;
}
else if (ext.MakeLower() == _T(".kml"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_KML;
}
else
{
CDocType* pDocType = PARAM().GetDocType();
m_nDocTypeID = pDocType->GetIndexFromExt(AfxGetPublicFunction()->GetSplitPath(newName, "ext"));
m_nDocTypeID = pDocType->GetIDFromIndex(m_nDocTypeID);
}
}
m_FileName = newName;
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);
m_bModified = false;
m_pActionMgr->SavePostion();
return TRUE;
}
return FALSE; // success
}
BOOL CSigmaDoc::SaveFile(LPCTSTR lpszPathName, double leftMargin, double rightMargin,
double topMargin, double bottomMargin, int paperSizeType, int pdfAHType, int pdfPapertDirectionType)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
if (newName.IsEmpty())
{
newName = "newFile.kev";
}
m_nDocTypeID = DF_FORMAT_ASCII;
return false;
}
else
{
CString ext = AfxGetPublicFunction()->GetSplitPath(newName, "ext");
if (ext.MakeLower() == _T(".xyz"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_XYZ;
}
else if (ext.MakeLower() == _T(".gdbx"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_GDBX;
}
else if (ext.MakeLower() == _T(".kml"))
{
m_nDocTypeID = NFormatType::DF_FORMAT_KML;
}
else
{
CDocType* pDocType = PARAM().GetDocType();
m_nDocTypeID = pDocType->GetIndexFromExt(AfxGetPublicFunction()->GetSplitPath(newName, "ext"));
m_nDocTypeID = pDocType->GetIDFromIndex(m_nDocTypeID);
}
}
m_FileName = newName;
CFile file;
if (file.Open(m_FileName, CFile::modeCreate | CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
Serialize(ar, leftMargin, rightMargin,
topMargin, bottomMargin, paperSizeType, pdfAHType, pdfPapertDirectionType);
ar.Close();
file.Close();
PostProcessFile(m_FileName);
m_bModified = false;
m_pActionMgr->SavePostion();
return TRUE;
}
return FALSE; // success
}
void CSigmaDoc::SaveActionPosition()
{
m_bModified = false;
m_pActionMgr->SavePostion();
}
//extern "C" __declspec(dllexport)
//void GdfCloseFile()
//{
// if (m_pGdfXy != NULL)
// {
// delete m_pGdfXy;
// m_pGdfXy = NULL;
// }
//}
BOOL CSigmaDoc::GetDrawRange(CRect8& rect)
{
if (m_pXy->GetCount() == 0) return FALSE;
//switch (::GetPreferences().WorkaroundDisplay.m_nRecountRange)
switch(0)
{
default:
case 0:
{
m_pXy->GetRange(rect, FALSE);
}
break;
case 1:
{
m_pXy->GetRange(rect, FALSE);
}
break;
}
m_pXy->m_range = rect;
return TRUE;
}
void CSigmaDoc::Invalidate()
{
this->EnableRedraw(true);
// <20><>ʱ<EFBFBD><CAB1>C#<23>˿<EFBFBD><CBBF><EFBFBD>
//((CSigmaView*)this->GetView())->OnDrawMem();
//((CSigmaView*)this->GetView())->OnDrawDC();
//UpdateAllViews(NULL, HINT_UPDATE_VIEW, NULL); // ***MFC<46>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص㷽<D8B5><E3B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ҵ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>
//InvalidateEagleEye();
}
void CSigmaDoc::OnDraw(CXyDC & dc)
{
if (m_pXy == NULL)
{
return;
}
//TRACE(_T("CDrawDoc::OnDraw(CXyDC&),count=%ld\n"), m_pXy->GetCount());
//BeginProgress(0);
m_pXy->Draw(dc, false);
//EndProgress();
}
void CSigmaDoc::DrawHandle(double x, double y, DWORD nDrawMode, CDC* pDC)
{
CPoint pt = GetDC().GetScreen(x, y);
CRect rt(pt, pt);
//CSize sz = GetHandleSize();
CSize sz(8, 8);
sz.cx /= 2;
sz.cy /= 2;
rt.InflateRect(sz);
//m_Tracker.DrawHandle(GetDC().GetDC(), rt, nDrawMode);
m_pDrawer->Draw(pDC, rt, nDrawMode);
}
CSize CSigmaDoc::GetHandleSize(void)
{
return CSize(2, 2);
}
std::vector<POSITION> CSigmaDoc::GetSelectedItems(const CPoint2D& point)
{
CRect8 r = GetSelectedRect(point);
CPositionList select;
std::vector<POSITION> result;
GetDraw()->IsInRange(r, select, FALSE);
CListForEach(pos, select) {
POSITION pt = select.GetAt(pos);
COne *pOne = m_pXy->GetAt(pt);
if (pOne->IsView() && (!pOne->GetLayer()->IsNotViewNotEdit())) {
result.push_back(pt);
}
}
return result;
}
//<2F><>pos==NULLʱ<4C><CAB1>ѡ<EFBFBD><D1A1><EFBFBD>õ㴦<C3B5>ĵ<EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʱ<EFBFBD><CAB1>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>λ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD><D4AA>
POSITION CSigmaDoc::GetNextSelectedItem(const CPoint2D& point, POSITION pos)
{
if (pos == NULL)
return GetSelectedItem(point);
CRect8 r = GetSelectedRect(point);
CPositionList select;
//<2F><>ֻΪһ<CEAA><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
//<2F><>һ<EFBFBD>в<EFBFBD><D0B2><EFBFBD>ע<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD>Ҳ²<D2B2><C2B2>ǵ<EFBFBD><C7B5>÷<EFBFBD><C3B7><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> pos <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (GetDraw()->IsInRange(r, select) == 1) {
return select.GetTail();
} else if (select.GetCount() > 0) {
POSITION ps = select.Find(pos);
if (ps == NULL) {
return NULL;
}
if (ps == select.GetHeadPosition()) {
ps = select.GetTailPosition();
} else {
select.GetPrev(ps);
}
return select.GetAt(ps);
}
return NULL;
}
POSITION CSigmaDoc::GetSelectedItem(const CPoint2D& point)
{
CXy *pDraw = GetDraw();
if (pDraw == NULL)return NULL;
POSITION p = NULL;
CRect8 r = GetSelectedRect(point);
p = pDraw->IsInRange(r);
return p;
}
CRect8 CSigmaDoc::GetSelectedRect(const CPoint2D& point)
{
CRect8 r(point.x0, point.y0, point.x0, point.y0);
CSize8 sz = GetSelectSize();
CXyDC & dc = GetDC();
double sx = dc.GetRealWidth(sz.cx);
//double sx = sz.cx;
double sy = fabs(dc.GetRealHeight(sz.cy));
//double sy = sz.cy;
r.InflateRect(sx, sy);
return r;
}
void CSigmaDoc::InvalidateDelete(CPositionList& list)
{
MoveSelect = NULL;//fbw
this->EnableRedraw(true);
//UpdateAllViews(NULL, HINT_DELETE_SELECTION, &list);
}
CSize8 CSigmaDoc::GetSelectSize(void)
{
//double w = ::GetPreferences().Workaround.m_lSelectWidth;
double w = 8.0;
w *= 0.5;
return CSize8(w, w);
}
CXyDC& CSigmaDoc::GetDC(void)
{
//return m_zoom;
return m_xyDC;
}
void CSigmaDoc::SetDC(CXyDC& xydc)
{
m_xyDC = xydc;
}
void CSigmaDoc::SetCDC(CDC * pDC)
{
m_xyDC.Create(pDC);
}
CDC * CSigmaDoc::GetCDC()
{
return m_xyDC.GetDC();
}
void CSigmaDoc::ClearSelection(void)
{
if (GetItemType() == ITEM_SELECT)
GetSelectItem()->CancelSelection();
}
void CSigmaDoc::InvalidateSelection(CPositionList& list)
{
this->EnableRedraw(true);
//UpdateAllViews(NULL, HINT_UPDATE_SELECTION, &list);
}
CSigmaView * CSigmaDoc::GetView(void) {
return m_pView;
}
void CSigmaDoc::SetView(CSigmaView * pActiveView) {
m_pView = pActiveView;
this->mBackColor = pActiveView->mBackColor;
m_pItemView->m_BackColor = this->mBackColor;
m_pItemPrint->m_BackColor = this->mBackColor;;
}
void CSigmaDoc::SetBackColor(COLORREF color)
{
this->mBackColor = color;
m_pItemView->m_BackColor = this->mBackColor;
m_pItemPrint->m_BackColor = this->mBackColor;
CItem* pItem = this->GetItem();
if (pItem != nullptr)
{
pItem->m_BackColor = this->mBackColor;
}
}
void CSigmaDoc::Invalidate(POSITION pos)
{
if (pos == NULL) return;
this->EnableRedraw(true);
//UpdateAllViews(NULL, HINT_UPDATE_POSITION, (CObject*)pos);
//COne* pOne=(COne*)GetDraw()->GetAt(pos);
//Invalidate(pOne);
}
int CSigmaDoc::Undo()
{
return m_pActionMgr->Undo();
}
int CSigmaDoc::Redo()
{
return m_pActionMgr->Redo();
}
bool CSigmaDoc::CanUndo()
{
return m_pActionMgr->CanUndo();
}
bool CSigmaDoc::CanRedo()
{
return m_pActionMgr->CanRedo();
}
int CSigmaDoc::GetItemType(void)
{
if (GetItem())
return GetItem()->GetType();
return 0;
}
NItem::CItemSelect * CSigmaDoc::GetLastSelectItem(void)
{
CItemSelect *result = new CItemSelect(this);
CItemSelect *itemSelect = GetSelectItem();
result->SelectWithinRect(itemSelect->m_lastRect, FALSE);
return result;
}
CItemSelect * CSigmaDoc::GetSelectItem(void)
{
if (GetItem() == NULL) return NULL;
if (GetItem()->GetType() != ITEM_SELECT) return NULL;
return (CItemSelect*)GetItem();
}
BOOL CSigmaDoc::GetElementRect(POSITION pos, CRect8& range)
{
if (pos == NULL) return FALSE;
range = GetDraw()->GetAt(pos)->GetRect();
return TRUE;
}
void CSigmaDoc::SetActionItem(CActionItem* pAction, bool bDo/*=true*/)
{
if (pAction == nullptr)
{
return;
}
m_pLastAction = nullptr;
m_pActionMgr->SetLastAction(pAction);
m_pLastAction = pAction;
if (bDo) m_pLastAction->Do();
CSigmaStore::GetInstance().Save(this);
}
CItem * CSigmaDoc::GetItem(void)
{
return m_pItem.get();
}
void CSigmaDoc::DeleteItem(void)
{
//CItemSelect * select = GetSelectItem();
//if (select != 0)
//{
// m_selectionSet.RemoveAll();
// m_selectionSet.AddTail(&select->m_selection);
//}
if (GetSelectItem())
GetSelectItem()->CancelSelection();
m_pItem.reset();
}
void CSigmaDoc::SetItem(CItem* pItem)
{
if (GetSelectItem())
GetSelectItem()->CancelSelection();
m_pItem.reset(pItem);
//CMainFrame* pmf = (CMainFrame*)GetMainFrame();
//if (pmf)
//pmf->UpdatePropertyGridContent(pItem);
}
CItem* CSigmaDoc::FindItem(int nType)
{
CItem* pit = NULL;
switch (nType)
{
case ITEM_ERASER:
pit = new CItemEraser(this);
break; //<2F><>Ƥ
case ITEM_HYPERLINK: break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case ITEM_SELECT://Ԫ<><D4AA>ѡ<EFBFBD><D1A1>
pit = new CItemSelect(this);
break;
case ITEM_RECTANGLE://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemRectangle(this);
break;
case ITEM_ELLIPSE://<2F><><EFBFBD><EFBFBD>Բ
pit = new CItemEllipse(this);
break;
case ITEM_CIRCLE://<2F><>Բ
pit = new CItemCircle(this);
break;
case ITEM_CURVE://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemCurveMerge(this);
break;
case ITEM_LINK_CURVE:
pit = new CItemLinkCurve(this);
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case ITEM_SOLID: pit = new CItemSolid(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򣬽<EFBFBD><F2A3ACBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case ITEM_SOLID_LINK: pit = new NItem::CItemSolidLink(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case ITEM_SOLID_AUTO: pit = new CItemSolidAuto(this); break; //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
case ITEM_BREAK_CURVE://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemBreakCurve(this);
break;
case ITEM_BREAK_CURVE_DIRECT:
pit = new CItemBreakCurveDirect(this);
break;
//case ITEM_IMAGE_TRACE: pit = new CItemImageTrace(this); break; //ʸ<><CAB8><EFBFBD><EFBFBD>
case ITEM_EXTEND_CURVE:
pit = new CItemExtendCurve(this);
break;
case ITEM_TRIM_CURVE:
pit = new CItemTrimCurve(this);
break;
case ITEM_PROPORTION: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemProportion(this);
break;
case ITEM_COPY_AS_IMAGE:
pit = new CItemCopyAsImage(this);
break;
case ITEM_COPY_AS_IMAGE_EX:
pit = new CItemCopyAsImageEx(this);
break;
case ITEM_COPY_AS_IMAGE_POLYGON:
pit = new CItemCopyAsImagePolygon(this);
break;
//case ITEM_LINK_POINT: pit = new CItemLinkPoint(this); break; //<2F><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_CURVE_EDIT: pit = new CItemCurveEditDeleteMulNodes(this); break;//<2F><><EFBFBD>߱༭//pit=new CItemCurveEdit(this);
//case ITEM_PUT_INTO_CURVE: pit = new CItemPutIntoCurve(this); break; //<2F>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_2POINT_TO_RECT: pit = new CItem2PointToRect(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>
//case ITEM_3POINT_TO_RGN: pit = new CItem3PointToRect(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
case ITEM_ARC://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҡ<EFBFBD><D2A1><EFBFBD>
pit = new CItemArc(this);
break;
case ITEM_EQUILATERAL://<2F>ȱ߶<C8B1><DFB6><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemEquilateral(this);
break;
//case ITEM_IMAGE: pit = new CItemFileImage(this); break; //ͼ<><CDBC>
//case ITEM_MATRIX_MARK: pit = new CItemMatrixMark(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_INSERT_DRAW: pit = new CItemInsertDraw(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_SECTION: pit = new CItemSection(this); break; //Section<6F><6E><EFBFBD><EFBFBD>
//case ITEM_MXN: pit = new CItemFileMxn(this); break; //MXN<58><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_POINT_EDIT: pit = new CItemPointEdit(this); break; //<2F><><EFBFBD>
case ITEM_POINT://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemPointAdd(this);
break;
case ITEM_WELL_GROUP:
pit = new CItemWellGroup(this);
break;
case ITEM_WELL_GROUP_EDIT:
pit = new CItemWellGroupEdit(this);
break;
case ITEM_WELL_BRANCH_CURVE_EDIT:
pit = new CItemBranchCurveEdit(this, m_selectionSet);
break;
case ITEM_TEXT://<2F>ı<EFBFBD>
pit = new CItemText(this);
break;
case ITEM_MESH: pit = new CItemMesh(this); break; //3DMESH
////case ITEM_DONUT: pit=new CItemDonut(this); break; //<2F><><EFBFBD><EFBFBD>Բ
case ITEM_GRID://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pit = new CItemEditGrid(this);
break;
//case ITEM_NET: pit = new CItemEditNet(this); break; //<2F><>γ<EFBFBD><CEB3><EFBFBD><EFBFBD>
//case ITEM_FRAME: pit = new CItemEditFrame(this); break; //<2F>߿<EFBFBD>
//case ITEM_SCALE_OBJECT: pit = new CItemScaleObjects(this); break; //<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
case ITEM_SAVE_TO_MARK: pit = new CItemSaveToMark(this); break; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
case ITEM_DELETE: //ɾ<><C9BE>
pit = new CItemDelete(this);
break;
//case ITEM_FIND: pit = new CItemFind(this); break;
case ITEM_POINT_PROCESS: pit = new CItemPointProcess(this); break;
case ITEM_CURVE_PROCESS:
pit = new CItemCurveProcess(this);
break;
case ITEM_ALIGN:
pit = new CItemAlign(this);
break;
//case ITEM_TEXT_EDIT: pit = new CItemTextMulEdit(this); break;
//case ITEM_SELECT_GOTO: pit = new CItemSelectGoto(this); break;
//case ITEM_CALIBRATE: pit = new CItemCalibrate(this); break;
//case ITEM_OLE: pit = new CItemOle(this); break; //OLEԪ<45><D4AA>
//case ITEM_INSERT_TABLE: pit = new CItemInsertTable(this); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_SCALE_RULER: pit = new CItemScaleRuler(this); break;
//case ITEM_CROSSPOINT_EDIT: pit = new CItemPointCrossEdit(this); break;
case ITEM_CROSSPOINT:
pit = new CItemPointCrossAdd(this);
break;
//case ITEM_ADD_WELL: pit = new CItemAddWell(this); break; //<2F><><EFBFBD><EFBFBD><EBBEAE><EFBFBD><EFBFBD>
//case ITEM_WELL: pit = new CItemWell(this); break; //<2F><EFBFBD><E0BCAD>
//case ITEM_BLOCK: pit = new CItemBlock(this); break;
//case ITEM_SCATTER: pit = new CItemChart(this,CCrossChart::scatter); break; //<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_OILWATER: pit = new CItemChart(this,CCrossChart::oilwater); break; //ѡ<><D1A1>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//case ITEM_HISTORGRAM: pit = new CItemChart(this,CCrossChart::histogram); break;
//case ITEM_RTPORLOG: pit = new CItemChart(this,CCrossChart::rtporlog); break;
//case ITEM_RWASP: pit = new CItemChart(this,CCrossChart::rwaspcross); break;
//case ITEM_CROSS: pit = new CItemChart(this,CCrossChart::cross); break;
//case ITEM_LIGASCROSS: pit = new CItemChart(this,CCrossChart::ligascross); break;
//case ITEM_REGIONSELECT: pit = new CItemRegionSelect(this); break;
//case ITEM_ADD_FACIES: pit = new CItemFacies(this); break;
//case ITEM_WELLDATAGRAPH: pit = new CItemWellDataGraph(this); break;
//case ITEM_CHARTEX: pit = new CItemChartEx(this); break;
//case ITEM_CHARTEX_EDIT: pit = new CItemChartExEdit(this); break;
//case ITEM_INSERT_LABEL_RECT:
// pit = new CItemLabelRect(this); break;
//case ITEM_LABEL_RECT_EDIT:
// pit = new CItemLabelRect(this); break;
//case ITEM_INSERT_FAULTLINE: pit = new CItemInsertFaultLine(this); break;
case ITEM_CUT_IN:
pit = new CItemCutIn(this);
break;
case ITEM_CUT_OUT:
pit = new CItemCutOut(this);
break;
case ITEM_CURVE_EDIT:
pit = new CItemCurveEditDeleteMulNodes(this, m_selectionSet); //TODO<44><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
case ITEM_CURVE_INNAME:
pit = new CItemEditCurveInName(this);
break;
case DOUBLEFOX_MESH: pit = new CItemMesh(this); break;
case ITEM_SET_CONTOUR_NAME: pit = new CItemSetContourName(this); break;
case ITEM_MEASURE: pit = new CItemMeasure(this); break;
}
if (pit != nullptr)
{
pit->m_BackColor = this->mBackColor;
}
return pit;
}
//QTransformTracker& CSigmaDoc::GetTracker(void)
//{
// return m_Tracker;
//}
void CSigmaDoc::DrawItem(CXyDC& dc, int nModeX, int nModeY)
{
if (GetItem())
GetItem()->OnDraw(&dc);
}
void CSigmaDoc::ClearSelectionSet()
{
m_selectionSet.RemoveAll();
}
void CSigmaDoc::AddToSelectionSet(POSITION pos)
{
m_selectionSet.AddTail(pos);
}
void CSigmaDoc::ReplaceSelectionSet(CPositionList & positionList)
{
m_selectionSet.RemoveAll();
m_selectionSet.AddTail(&positionList);
}
void CSigmaDoc::GetSelectionSet(CPositionList & positionListOut)
{
positionListOut.RemoveAll();
positionListOut.AddTail(&m_selectionSet);
}
bool CSigmaDoc::IsEmptySelectionSet()
{
return m_selectionSet.IsEmpty();
}
CRect8 CSigmaDoc::GetRectOfSelectedSet()
{
CRect8 rect(0, 0, 0, 0);
if (m_selectionSet.IsEmpty())
return rect;
COne* pOne;
rect.SetRect(1e100, -1e100, -1e100, 1e100);
POSITION pos, pt;
pos = m_selectionSet.GetHeadPosition();
while (pos != NULL)
{
pt = m_selectionSet.GetNext(pos);
pOne = (COne*)GetDraw()->GetAt(pt);
pOne->GetRange(rect);
}
return rect;
}
CRect8 CSigmaDoc::GetRectOfLastSelected()
{
CRect8 rect(0, 0, 0, 0);
if (m_selectionSet.IsEmpty())
return rect;
POSITION pos = m_selectionSet.GetTailPosition();
if (pos == nullptr)
{
return rect;
}
POSITION pt = m_selectionSet.GetAt(pos);
COne* pOne = (COne*)GetDraw()->GetAt(pt);
pOne->GetRange(rect);
TRACE("top: %f, left, %f, bottom: %f, right: %f\n", rect.top, rect.left, rect.bottom, rect.right);
return rect;
}
CFindReplacement * CSigmaDoc::GetFindReplacement()
{
return m_pFindReplacement.get();
}
void CSigmaDoc::SetSelection(CPositionList& list)
{
if (GetItemType() != ITEM_SELECT)
this->SetItem(FindItem(ITEM_SELECT));
GetSelectItem()->Select(list);
}
void CSigmaDoc::InsertParameterPair(CString & key, CString & value)
{
m_parametersMap[key] = value;
}
bool CSigmaDoc::GetParameter(CString & key, CString & valueOut)
{
auto ite = m_parametersMap.find(key);
if (ite == m_parametersMap.end())
return false;
valueOut = ite->second;
return true;
}
void CSigmaDoc::Modified(BOOL isModified)
{
m_bModified = isModified;
}
bool CSigmaDoc::IsModified()
{
if (m_bModified)
{
return true;
}
return m_pActionMgr->IsModified();
}
bool CSigmaDoc::IsCapturedScreen()
{
return m_bCapture;
}
void CSigmaDoc::SetCapturedScreenStatus(bool bCapture)
{
m_bCapture = bCapture;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ͼֽ<CDBC>Ŀ<EFBFBD><C4BF><EFBFBD>
void CSigmaDoc::GetDrawingWithAndHeightInScreen(int & widthOut, int & heightOut)
{
widthOut = heightOut = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>ĺ<EFBFBD><C4BA>׳<EFBFBD><D7B3><EFBFBD>
CRect8 rect(1e100, -1e100, -1e100, 1e100);
GetDrawRange(rect);
//widthOut = GetDC().GetScreenWidth8(rect.Width()) * GetDC().UnitX;
//heightOut = GetDC().GetScreenHeight8(rect.Height()) * GetDC().UnitY;
widthOut = GetDC().GetScreenWidth8(rect.Width());
heightOut = GetDC().GetScreenHeight8(rect.Height());
widthOut = fabs(widthOut);
heightOut = fabs(heightOut);
}
void CSigmaDoc::SetSelection(POSITION pos)
{
if (pos == NULL) return;
CPositionList list;
list.AddHead(pos);
SetSelection(list);
}
void CSigmaDoc::SaveRawFile()
{
// ע<><20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>֮<EFBFBD>󣬱<EFBFBD><F3A3ACB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ洢һ<E6B4A2><D2BB>ԭʼͼ<CABC><CDBC>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD> action <20><><EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD> Action <20>еIJ<D0B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD> Do <20>У<EFBFBD><D0A3>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> Action ֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>У<EFBFBD><D0A3><EFBFBD>´洢Ϊһ<CEAA><D2BB><EFBFBD>Ѿ<EFBFBD><D1BE>޸Ĺ<DEB8><C4B9><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
CSplitPath sp("");
CString path = sp.GetAbsolutePath(m_FileName);
CSigmaStore::GetInstance().Clear(path); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ܴ<EFBFBD><DCB4><EFBFBD>ԭʼͼ<CABC><CDBC><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CSigmaStore::GetInstance().Save(this);
}
void CSigmaDoc::EnableRecoverMode(bool enable)
{
m_recoverMode = enable;
}
bool CSigmaDoc::IsSnapEnabled() const
{
return m_snapEnabled;
}
void CSigmaDoc::EnableSnap(bool enable)
{
m_snapEnabled = enable;
}
CString CSigmaDoc::GetElementTypeString(POSITION pSelect)
{
CString str = _T("");
if (pSelect == NULL || !::AfxIsValidAddress(pSelect, sizeof(POSITION)))
return str;
CStringManager stringManager;
CXy *pDraw = GetDraw();
switch (pDraw->GetElementType(pSelect))
{
case DOUBLEFOX_CURVE: str = stringManager.GetStringByIDS("IDS_STRING_CURVE"); break;
case DOUBLEFOX_TEXT: str = stringManager.GetStringByIDS("IDS_STRING_Text"); break;
case DOUBLEFOX_ELLIPSE:
case DOUBLEFOX_CIRCLE: str = stringManager.GetStringByIDS("IDS_STRING_Circle"); break;
case DOUBLEFOX_IMAGE: str = stringManager.GetStringByIDS("IDS_STRING_Image"); break;
case DOUBLEFOX_WMF: str = stringManager.GetStringByIDS("IDS_STRING_WMF"); break;
case DOUBLEFOX_PROPORTION: str = stringManager.GetStringByIDS("IDS_STRING_Proportion"); break;
case DOUBLEFOX_DRAW_RECT: str = stringManager.GetStringByIDS("IDS_STRING_DrawRect"); break;
case DOUBLEFOX_INSERT:
case DOUBLEFOX_DRAW: str = stringManager.GetStringByIDS("IDS_STRING_Draw"); break;
case DOUBLEFOX_MESH: str = stringManager.GetStringByIDS("IDS_STRING_MESH"); break;
case DOUBLEFOX_XYZ: str = stringManager.GetStringByIDS("IDS_STRING_XYZ"); break;
case DOUBLEFOX_POINT: str = stringManager.GetStringByIDS("IDS_STRING_Point"); break;
case DOUBLEFOX_FRAME: str = stringManager.GetStringByIDS("IDS_STRING_Frame"); break;
case DOUBLEFOX_MXN: str = stringManager.GetStringByIDS("IDS_STRING_MXN"); break;
case DOUBLEFOX_GRID: str = stringManager.GetStringByIDS("IDS_STRING_GRID"); break;
case DOUBLEFOX_NET: str = stringManager.GetStringByIDS("IDS_STRING_NET"); break;
default: str = stringManager.GetStringByIDS("IDS_STRING_Other"); break;
}
return str;
}
void CSigmaDoc::PushActionDC(UINT nTypeID)
{
PushDC();
}
void CSigmaDoc::PushDC(void)
{
CXyDC *pDC = new CXyDC;
*pDC = GetDC();
if (!IsPreview())
ZoomStack.Push(pDC, DOUBLEFOX_XYDC);
else
ZoomStackPreview.Push(pDC, DOUBLEFOX_XYDC);
}
void CSigmaDoc::EnablePreview(bool bEnable)
{
m_bIsPreview = bEnable;
}
BOOL CSigmaDoc::IsPreview(void)
{
return m_bIsPreview;
}
int CSigmaDoc::GetZoomStackCount(void)
{
if (!IsPreview())
return ZoomStack.GetCount();
else
return ZoomStackPreview.GetCount();
}
void CSigmaDoc::PopDC(void)
{
COne* pOne = NULL;
if (!IsPreview())
pOne = ZoomStack.Pop();
else
pOne = ZoomStackPreview.Pop();
if (pOne == NULL)return;
SetDC(*((CXyDC*)(pOne->GetValue())));
delete pOne;
}
static CString ElementStringToXml(const CString& base, const CString& details)
{
TiXmlDocument doc;
auto* rootElement = new TiXmlElement("root");
auto* baseElement = new TiXmlElement("base");
auto* detailsElement = new TiXmlElement("detail");
baseElement->LinkEndChild(new TiXmlText(base));
detailsElement->LinkEndChild(new TiXmlText(details));
rootElement->LinkEndChild(baseElement);
rootElement->LinkEndChild(detailsElement);
doc.LinkEndChild(rootElement);
TiXmlPrinter printer;
doc.Accept(&printer);
return CString(printer.CStr());
}
CString CSigmaDoc::GetElementString(POSITION pSelect, CPoint2D* pPoint)
{
CString str, string, detailString;
if (pSelect == NULL || !::AfxIsValidAddress(pSelect, sizeof(POSITION)))
{
//string.LoadString(IDS_STRING_DoubleFox);
//return string;
return "";
}
CXy *pDraw = GetDraw();
CLayer* pLayer = pDraw->GetElementLayer(pSelect);
CString layerName;
if (pLayer != nullptr)
{
layerName = pLayer->GetPathName();
}
switch (pDraw->GetElementType(pSelect))
{
case DOUBLEFOX_CURVE_STATION:
case DOUBLEFOX_TV:
case DOUBLEFOX_CURVE:
{
CCurveEx* curve;
curve = (CCurveEx*)pDraw->GetAtValue(pSelect);
if (curve == NULL)break;
if (curve->name == NULL)
//string.Format("Type=Pline,Name=,area=%lf,Length=%lf", curve->Area(), curve->Length());
//string.Format("<22><>:");
;
else
string.Format("%s", curve->name);
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, <20><><EFBFBD><EFBFBD>: %s, <20><><EFBFBD><EFBFBD>=%lf, <20><><EFBFBD><EFBFBD>=%lf", layerName, curve->name, curve->Length(), curve->Area());
}
break;
case DOUBLEFOX_TEXT:
/*string.Format("Type=<3D>ı<EFBFBD>,Name=%s", ((CText*)pDraw->GetAtValue(pSelect))->GetName());*/
string.Format("<EFBFBD>ı<EFBFBD>:%s", ((CText*)pDraw->GetAtValue(pSelect))->GetName());
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, <20>ı<EFBFBD>: %s", layerName, ((CText*)pDraw->GetAtValue(pSelect))->GetName());
break;
case DOUBLEFOX_ELLIPSE:
case DOUBLEFOX_CIRCLE://Format("Circle(Բ)");
//string = "Type=Բ";
{
string = "Բ";
CCircle* pCircle = (CCircle*)pDraw->GetAtValue(pSelect);
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, Բ<><D4B2>: %lf, %lf, <20>뾶: %lf", layerName, pCircle->x0, pCircle->y0, pCircle->GetRadius());
}
break;
case DOUBLEFOX_IMAGE:
// string.Format("Type=ͼ<><CDBC>,Name=%s", ((CImageInsert*)pDraw->GetAtValue(pSelect))->GetName());
string.Format("ͼ<EFBFBD><EFBFBD>:%s", ((CImageInsert*)pDraw->GetAtValue(pSelect))->GetName());
if (pPoint)
{
CPoint pt = ((CImageInsert*)pDraw->GetAtValue(pSelect))->RealToImagePoint(pPoint->x0, pPoint->y0);
if (((CImageInsert*)pDraw->GetAtValue(pSelect))->GetImage())
{
COLORREF col = ((CImageInsert*)pDraw->GetAtValue(pSelect))->GetImage()->GetPixel(pt.x, pt.y);
str.Format(",RGB=(%ld,%ld,%ld)", GetRValue(col), GetGValue(col), GetBValue(col));
string += str;
}
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
}
break;
case DOUBLEFOX_PROPORTION://Format("Proportion(<28>߶α<DFB6><CEB1><EFBFBD><EFBFBD><EFBFBD>)");
//string = "Type=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
string = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_DRAW_RECT://Format("Rect(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>)");
//string = "Type=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
string = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_STATION:
case DOUBLEFOX_DRAW:
case DOUBLEFOX_INSERT:
//string.Format("Type=<3D><><EFBFBD><EFBFBD>,Name=%s", ((CInsertDraw*)pDraw->GetAtValue(pSelect))->GetName());
string.Format("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s", ((CInsertDraw*)pDraw->GetAtValue(pSelect))->GetName());
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_MESH://Format("Mesh(3DMESHʵ<48><CAB5>)");//string = "Type=<3D><><EFBFBD><EFBFBD>";
{
double v = ((CMesh*)pDraw->GetAtValue(pSelect))->GetValue(pPoint->x0, pPoint->y0);
if (fabs(v) < 1e9)
AfxGetPublicFunction()->FloatToString(string, v, 6);
else
string.Format("%.4e", v);
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
}
break;
case DOUBLEFOX_XYZ:
case DOUBLEFOX_POINT:
{
CPointNameEx* cp;
cp = (CPointNameEx*)pDraw->GetAtValue(pSelect);
//str.LoadString(IDS_STRING_Point);
//string.Format("Type=<3D><>,Name=%s", cp->GetName());
string.Format("%s", cp->GetName());
//if (cp->IsXYZ())
//{
// CPointXyz* pp = (CPointXyz*)cp;
// if (pp->m_pXyzValue)
// {
// char sss[256];
// AfxGetPublicFunction()->FloatToString(sss, pp->m_pXyzValue[0], 10);
// string += ",Z=" + CString(sss);
// }
//}
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
}
break;
case DOUBLEFOX_FRAME:
//string = "Type=<3D>߿<EFBFBD>";
string = "<EFBFBD>߿<EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_MXN:
//string.Format("Type=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,Name=%s", ((CMxn*)pDraw->GetAtValue(pSelect))->GetName());
string.Format("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s", ((CMxn*)pDraw->GetAtValue(pSelect))->GetName());
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_GRID:
//string = "Type=ֱ<><D6B1><EFBFBD><EFBFBD>";
string = "ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_NET:
string = "Type=<3D><>γ<EFBFBD><CEB3>";
string = "<EFBFBD><EFBFBD>γ<EFBFBD><EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
case DOUBLEFOX_WMF:
// string = "Type=Ԫ<>ļ<EFBFBD>";
string = "ͼԪ<EFBFBD>ļ<EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
default: // Format("Other(<28><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>Ԫ<EFBFBD><D4AA>)");
// string = "Type=<3D><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>Ԫ<EFBFBD><D4AA>";
string = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>";
detailString.Format("ͼ<EFBFBD><EFBFBD>: %s, %s", layerName, string);
break;
}
//str.Format("Layer=%s,%s", ((CLayer*)pDraw->GetElementLayer(pSelect))->GetPathName(), string);
//str.Format("Layer=%s,%s", ((CLayer*)pDraw->GetElementLayer(pSelect))->GetPathName(), string);
return ElementStringToXml(string, detailString);
}
CString CSigmaDoc::GetSelectedElementLayer(CPositionList& list)
{
CString layer = _T("");
CString txt;
POSITION pos, pt;
pos = list.GetHeadPosition();
while (pos)
{
pt = list.GetNext(pos);
txt = GetDraw()->GetElementLayer(pt)->GetPathName();
if (layer.Find(txt) < 0)
{
if (!layer.IsEmpty()) layer += _T(";");
layer += txt;
}
}
return layer;
}
BOOL CSigmaDoc::VerifyPassword(CXy* pxy)
{
if (pxy->GetFileEncrypt() == NULL) return TRUE;
if (!pxy->IsEncrypted()) return TRUE; // no password to check
while (TRUE)
{
//CDlgPasswordRetrieve dlg;
//if (IDOK == dlg.DoModal())
//{
// if (pxy->GetFileEncrypt()->VerifyPassword(dlg.GetPassword()))
// return TRUE;
// else if (::AfxMessageBox(IDS_ENABLE_ENCRYPTION, MB_YESNO) == IDNO)
// break;
//}
//else
// break; // user cancelled
}
return FALSE;
}
int CSigmaDoc::SerializeRead(CXy* pxy, CArchive& ar)
{
if (pxy == NULL) return 0;
TRY
{
pxy->m_version = pxy->DFB_ReadVersion(ar);
pxy->DFB_ReadEncrypt(ar, pxy->m_version);
if (pxy->IsEncrypted())
{
if (!VerifyPassword(pxy))
return 0;
}
pxy->DFB_Serialize(ar, pxy->m_version);
}
CATCH_ALL(e)
{
THROW_LAST();
return 0;
}
END_CATCH_ALL
return 1;
}
int CSigmaDoc::SerializeRead(CXy* pxy, CString strInput)
{
int rt = 0;
CFileMapping fm;
CString mapName = fm.CreateMappingName(strInput);
if (fm.Open(strInput, mapName))
{
CMemFile mf((BYTE*)fm.GetData(), (UINT)fm.GetMappingSize());
CArchive ar((CFile*)&mf, CArchive::load | CArchive::bNoFlushOnDelete);
rt = SerializeRead(pxy, ar);
ar.Close();
mf.Close();
fm.CloseAll();
}
else
{
CFile file;
if (!file.Open(strInput, CFile::modeRead | CFile::shareDenyWrite)) return 0;
CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);
rt = SerializeRead(pxy, ar);
ar.Close();
file.Close();
}
return rt;
}
CItem* CSigmaDoc::GetOtherItem(void)
{
return m_pOtherItem.get();
}
void CSigmaDoc::ClearItems(void)
{
DeleteItem();
DeleteOtherItem();
}
void CSigmaDoc::DeleteOtherItem(void)
{
/*CMainFrame* pmf = (CMainFrame*)GetMainFrame();
if (pmf)
pmf->SetFocus();*/
if (GetSelectItem())
GetSelectItem()->CancelSelection();
if (m_pOtherItem)
m_pOtherItem.reset();
/*if (pmf)
pmf->UpdatePropertyGridContent(NULL);*/
}
BOOL CSigmaDoc::SetDefaultCursor(void)
{
/*CItemView* itemView = new CItemView();
if (itemView->IsViewState())
return CDrawDoc::SetDefaultCursor();
if (GetItem())
return GetItem()->OnSetCursor(NULL, HTCLIENT, 0);*/
return FALSE;
}
void CSigmaDoc::SetStatusOfCrossPoint(int status)
{
m_crossPointStatus = status;
}
int CSigmaDoc::GetStatusOfCrossPoint()
{
return m_crossPointStatus;
}
int CSigmaDoc::GetEditLineStatus()
{
return this->m_EditLineState;
}
void CSigmaDoc::SetEditLineStatus(int status)
{
this->m_EditLineState = status;
}
NAction::CActionManager* CSigmaDoc::GetActionManager()
{
return m_pActionMgr.get();
}