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/InterfaceFavorableArea.cpp

146 lines
3.2 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "stdafx.h"
#include <stack>
#include <random>
#include "DrawOperator/XyIO.h"
#include "TinyXml/tinyxml.h"
#include "ActionDeleteItem.h"
#include "DrawOperator/Net.h"
#include "DrawOperator/LibraryManager.h"
#include "DrawOperator\FileUtility.h"
#include "DrawOperator/unordered_dense.h"
#include "DrawOperator\MergePDFFile.h"
#include "ActionAddItem.h"
#include "Util.h"
#include "Legend.h"
#include "UndecidedZone.h"
#include "SigmaView.h"
/**
* 生成有利区zMin 和 zMax 是闭区间
*
* \param pXy 图件
* \param layerName 指定的图层名
* \param zMin 最小 z 值
* \param zMax 最大 z 值
* \param plAdd 新增的图元 POSITION
* \return
*/
int CreateFavorableAreaImpl(CXy* pSourceXy, CXy* pTargetXy, const CString& layerName, double zMin, double zMax, CPositionList& plAdd)
{
if (pSourceXy == nullptr)
{
TRACE("pXy 不能为 nullptr\n");
return 0;
}
if (zMin >= zMax)
{
TRACE("zMin 不能大于 zMax\n");
return 0;
}
CPositionList select;
pSourceXy->GetElement(DOUBLEFOX_MESH, select);
if (select.IsEmpty())
{
return 0;
}
CLayer* pLayer = pTargetXy->FindAddLayer(layerName);
if (pLayer == nullptr)
{
TRACE("查找或创建图层\"%s\"失败", layerName);
return 0;
}
for (POSITION pos = select.GetHeadPosition(); pos != nullptr; select.GetNext(pos))
{
POSITION pt = select.GetAt(pos);
COne* pOne = pSourceXy->GetAt(pt);
if (pOne == nullptr)
{
continue;
}
CMesh* pMesh = pOne->GetValueSafe<CMesh>();
UndecidedZone undecidedZone(pMesh);
std::vector<std::unique_ptr<CCurveEx>> curves = undecidedZone.ComputeRegions(zMin, zMax);
for (auto& curve : curves)
{
auto pOne = std::make_unique<COne>();
pOne->SetLayer(pLayer);
pOne->SetValueSafe(std::move(curve.release()));
pOne->SetColor(RGB(0, 0, 0));
POSITION posAdd = pTargetXy->AddTailOne(pOne.release());
plAdd.AddTail(posAdd);
}
}
return plAdd.GetCount();
}
extern "C" __declspec(dllexport)
int XyCreateFavorableArea(CXy* pSourceXy, CXy* pTargetXy, const LPCTSTR layerName, double zMin, double zMax)
{
if (pSourceXy == nullptr)
{
TRACE("pSourceXy 不能为 nullptr\n");
return 0;
}
if (pTargetXy == nullptr)
{
TRACE("pTargetXy 不能为 nullptr\n");
return 0;
}
if (layerName == nullptr)
{
TRACE("layerName 不能为 nullptr\n");
return 0;
}
CPositionList plAdd;
return CreateFavorableAreaImpl(pSourceXy, pTargetXy, layerName, zMin, zMax, plAdd);
}
/**
* 创建有利区
*
* \param pView 图件对象
* \param layerName 要创建的目标图层
* \param zMin 最小 z 值
* \param zMax 最大 z 值
* \return
*/
extern "C" __declspec(dllexport)
int CreateFavorableArea(CSigmaView* pView, CXy* pTargetXy, LPCTSTR layerName, double zMin, double zMax)
{
if (pView == nullptr)
{
TRACE("pView 不能为 nullptr\n");
return 0;
}
if (layerName == nullptr)
{
TRACE("layerName 不能为 nullptr\n");
return 0;
}
CPositionList plAdd;
int nCount = CreateFavorableAreaImpl(pView->m_pDoc->m_pXy, pTargetXy, layerName, zMin, zMax, plAdd);
// 如果修改的当前图件,我们让它能够撤消
if (pView->m_pDoc->m_pXy == pTargetXy && plAdd.GetCount() > 0)
{
auto pItem = std::make_unique<CActionAddItem>(pView->m_pDoc, 0, plAdd);
pView->m_pDoc->SetActionItem(pItem.release());
}
return nCount;
}