#include "pch.h" #include "AppFunc.h" #include "Interface.h" #include "contourfillmap.h" typedef void(*CPPCallbackMousePos)(double mouseX, double mouseY); typedef void(*CPPCallbackViewStatus)(double pX, double pY, double scale); CPPCallbackMousePos mouseMoveEvent = nullptr; CPPCallbackViewStatus viewStatusEvent = nullptr; extern "C" __declspec(dllexport) void SetMouseMoveEvent(CPPCallbackMousePos callback) { mouseMoveEvent = callback; } extern "C" __declspec(dllexport) void SetViewStatusEvent(CPPCallbackViewStatus callback) { viewStatusEvent = callback; } extern "C" __declspec(dllexport) void Editor_InitView(void* hwnd, LPCTSTR imagePath) { char caImagePath[256]; memset(caImagePath, 0, sizeof(char) * 256); CString strImgPath(imagePath); if (!strImgPath.IsEmpty()) { strncpy_s(caImagePath, imagePath, strImgPath.GetLength()); } Func_InitView(hwnd, caImagePath); } extern "C" __declspec(dllexport) void Editor_InitViewWithColor(void* hwnd, int r, int g, int b) { Func_InitViewWithColor(hwnd, r, g, b); } extern "C" __declspec(dllexport) void Editor_RenderView() { Func_RenderView(); } extern "C" __declspec(dllexport) void Editor_ZoomView() { Func_ZoomView(); } extern "C" __declspec(dllexport) int Editor_CreateMesh(CXy* pXy, LPCTSTR contourLayer, LPCTSTR faultLayer, LPCTSTR pointLayer, LPCTSTR otherLineLayer, int type) { // 将网格 z 值小于 0 的设置为 0 POSITION meshPos = pXy->FindFirstElement(DOUBLEFOX_MESH); if (meshPos == nullptr) { return 0; } COne *pOne = pXy->GetAt(meshPos); CMesh* pMesh = (CMesh*)(pOne->GetValue()); CDimension3D* pDimension = pMesh->GetDfg(); int numx = pDimension->xnum(); int numy = pDimension->ynum(); double dx0 = pDimension->xmin(); double dy0 = pDimension->ymin(); double dStepX = pDimension->dx(); double dStepY = pDimension->dy(); double* pU = pDimension->u; // 设置Z值范围 Func_SetZRange(pDimension->range[0], pDimension->range[1]); //int nReturn = Func_LoadFile("C:\\temp\\k12.kev"); int nReturn = Func_CreateMesh(numx, numy, dx0, dy0, dStepX, dStepY, pU, type); // 设置颜色 vector colors; int nColorCount = pMesh->color.GetCount(); for (int i = 0; i < nColorCount; i++) { CColorItem colorMesh = pMesh->color.GetColorItem(i); ColorItem colorItem; colorItem.r = colorMesh.R(); colorItem.g = colorMesh.G(); colorItem.b = colorMesh.B(); colorItem.a = 1; colorItem.c = colorMesh.m_bContinue; colorItem.val = colorMesh.z; colors.push_back(colorItem); } Func_SetColorList(colors); if (type == 0) { // 设置断层 (支持多选) std::vector vecFault; // 总断层列表 if (faultLayer && lstrlen(faultLayer) > 0) { CString strFaultLayers = faultLayer; int nPos = 0; CString strSingleLayer = strFaultLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { std::vector vecTemp; TakeLayerLines(pXy, strSingleLayer, vecTemp, false, false); if (vecTemp.size() > 0) { vecFault.insert(vecFault.end(), vecTemp.begin(), vecTemp.end()); } strSingleLayer = strFaultLayers.Tokenize(_T(";"), nPos); } } if (vecFault.size() > 0) { Func_SetFaultList(vecFault, false); } // 设置等值线 std::vector vecContour; TakeLayerLines(pXy, contourLayer, vecContour, true, true); if (vecContour.size() > 0) { Func_SetContourList(vecContour); } } // 设置其它线 (支持多选) std::vector vecOtherLines; if (otherLineLayer && lstrlen(otherLineLayer) > 0) { CString strOtherLayers = otherLineLayer; int nPos = 0; CString strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { std::vector vecTemp; TakeLayerLines(pXy, strSingleLayer, vecTemp, false, false); if (vecTemp.size() > 0) { vecOtherLines.insert(vecOtherLines.end(), vecTemp.begin(), vecTemp.end()); } strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); } } if (vecOtherLines.size() > 0) { Func_SetOtherLines(vecOtherLines); } // 设置控制点 if (pointLayer && lstrlen(pointLayer) > 0) { std::vector ptControl; // 总的控制点集合 CString strPointLayers = pointLayer; int nPos = 0; CString strSingleLayer = strPointLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { NBase::CPositionList lstPoint; pXy->GetElement(strSingleLayer, lstPoint, false, false); if (lstPoint.GetCount() > 0) { POSITION pos = lstPoint.GetHeadPosition(); POSITION pt; std::string strLayer; while (pos) { pt = lstPoint.GetNext(pos); COne* pOne = (COne*)pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_POINT) { continue; } CPointNameEx* pPoint = (CPointNameEx*)(pOne->GetValue()); Point2D pt2d(pPoint->x0, pPoint->y0); CString cstrName = pPoint->GetName(); std::string strName; strName.assign(cstrName.GetBuffer(), cstrName.GetLength()); cstrName.ReleaseBuffer(); ControlPoint2d cpt2d(pt2d, pPoint->z0, strName); ptControl.push_back(cpt2d); // 添加到总集合 } } // 获取下一个图层名 strSingleLayer = strPointLayers.Tokenize(_T(";"), nPos); } // 如果收集到了控制点,统一设置 if (ptControl.size() > 0) { Func_SetControlPoint(ptControl); } } Func_ShowMesh(true); Func_ShowMeshVertex(false); Func_ZoomView(); return nReturn; } extern "C" __declspec(dllexport) void Editor_StartCommand() { Func_StartCommand(); } extern "C" __declspec(dllexport) void Editor_EndCommand() { Func_EndCommand(); } extern "C" __declspec(dllexport) void Editor_StrechUp(int ipx, int ipy, float rad, float per, int type, float wellrad =0) { Func_StrechUp(ipx, ipy, rad, per, type, wellrad); } extern "C" __declspec(dllexport) void Editor_StrechDown(int ipx, int ipy, float rad, float per, int type, float wellrad = 0) { Func_PushDown(ipx, ipy, rad, per, type, wellrad); } extern "C" __declspec(dllexport) void Editor_DragAway(int startx, int starty, int endx, int endy, float rad, float per, int type, float wellrad = 0) { Func_DragAway(startx, starty, endx, endy, rad, per, type, wellrad); } extern "C" __declspec(dllexport) void Editor_Smooth(int ipx, int ipy, float rad, float per, int type, float wellrad = 0) { Func_Smooth(ipx, ipy, rad, per, type, wellrad); } extern "C" __declspec(dllexport) void Editor_DrawCircle(int ipx, int ipy, float rad) { Func_DrawCircle(ipx, ipy, rad); } extern "C" __declspec(dllexport) void Editor_ClearCircle() { Func_ClearCircle(); } extern "C" __declspec(dllexport) void Editor_OffsetFault() { Func_OffsetFault(); } extern "C" __declspec(dllexport) void Editor_FreeAll() { Func_FreeAll(); } extern "C" __declspec(dllexport) bool Editor_CanUndo() { return Func_CanUndo(); } extern "C" __declspec(dllexport) bool Editor_CanRedo() { return Func_CanRedo(); } extern "C" __declspec(dllexport) void Editor_Undo() { Func_Undo(); } extern "C" __declspec(dllexport) void Editor_Redo() { Func_Redo(); } bool HaveCurveViewName(CLayer* pLayer) { CHowToViewCurve* pHowToView = pLayer->HowToViewCurve; if (pHowToView == nullptr || pHowToView->GetCount() == 0) { return false; } for (int i = 0; i < pHowToView->GetCount(); i++) { CCurveView* pView = pHowToView->GetAt(i); if (pView->GetType() == CurveInName || pView->GetType() == CurveInNameAny) { return true; } } return false; } extern "C" __declspec(dllexport) void Editor_DeleteArray(int64_t* array) { delete[] array; } /** * 智能等网数据回写 * * \param pXy 图件 * \param curveLayer 要写入的图层 * \param destroyArray 要移除的图元 POSITION,该图元并未被移除,要调用需要上层进行处理,同时还需要调用 Editor_DeleteArray 释放内存 * \param destroyLength 要移除的 * \param insertedArray 插入的图元 POSITION,图元已经插入,需要调用 Editor_DeleteArray 释放内存 * \param insertedLength * \param layerName 等值线标注图层 * \param layerNoName 等值线无标注图层 * \param type 等网编辑/沉积相编辑 * \return */ extern "C" __declspec(dllexport) bool Editor_PushbackData(CXy * pXy, LPCTSTR curveLayer, int64_t** destroyArray, int64_t& destroyLength, int64_t** insertedArray, int64_t& insertedLength, LPCTSTR layerName, LPCTSTR layerNoName, int type) { double* pValues = Func_GetValue(); double zMin = Func_GetZMin(); double zMax = Func_GetZMax(); POSITION meshPos = pXy->FindFirstElement(DOUBLEFOX_MESH); if (meshPos == nullptr) { return false; } COne *pOne = pXy->GetAt(meshPos); CMesh* pMesh = (CMesh*)(pOne->GetValue()); //CDimension3D* pDimension = pMesh->GetDfg(); CSize size = pMesh->size(); for (int i = 0; i < size.cx; i++) { for (int j = 0; j < size.cy; j++) { ((CMeshBase *)pMesh)->SetValue(i, j, pValues[i + j * size.cx]); } } pMesh->SetM(zMin, zMax); if (!type) { // 设置颜色 // 获取旧的颜色范围 double dZMinOld = 0; double dZMaxOld = 0; pMesh->color.GetZRange(dZMinOld, dZMaxOld); // 如果旧范围和新范围不同,只更新范围,不重分配颜色 if (fabs(dZMinOld - zMin) > 1e-6 || fabs(dZMaxOld - zMax) > 1e-6) { pMesh->color.SetZRange(zMin, zMax); } pMesh->GetBitmap(); } else { // 设置颜色 vector colors; Func_GetColorList(colors); // 设置颜色 double dZMinOld = 0; double dZMaxOld = 0; pMesh->color.GetZRange(dZMinOld, dZMaxOld); CArray ColorList; int nColorCount = colors.size(); for (int i = 0; i < nColorCount; i++) { const ColorItem& src = colors[i]; CColorItem colorMesh; // 设置 RGB + Alpha colorMesh.SetColor( (BYTE)src.r, (BYTE)src.g, (BYTE)src.b, (BYTE)(src.a * 255.0f) // float alpha 转 0-255 ); colorMesh.z = src.val; colorMesh.m_bContinue = src.c ? TRUE : FALSE; ColorList.Add(colorMesh); } pMesh->color.SetZRange(zMin, zMax); pMesh->color.SetColor(ColorList); pMesh->UpdateColorRuler(); pMesh->GetBitmap(); } // 等值线 CLayer* pLayerName = nullptr; CLayer* pLayerNoName = nullptr; pLayerName = pXy->FindLayer(layerName); pLayerNoName = pXy->FindLayer(layerNoName); if (pLayerName == nullptr || pLayerNoName == nullptr) { CPtrList lstLayer; pXy->FindLayers(curveLayer, lstLayer, true); POSITION posPos = lstLayer.GetHeadPosition(); while (posPos != nullptr) { CLayer* pLayerFind = (CLayer*)lstLayer.GetNext(posPos); bool bViewName = HaveCurveViewName(pLayerFind); if (bViewName) { pLayerName = pLayerFind; } else { pLayerNoName = pLayerFind; } } } if (pLayerNoName == nullptr&& pLayerName == nullptr) { pLayerNoName = pXy->FindAddLayer(curveLayer); pLayerName = pLayerNoName; } else if (pLayerName == nullptr) { pLayerName = pLayerNoName; } else if (pLayerNoName == nullptr) { pLayerNoName = pLayerName; } NBase::CPositionList lstPos; pXy->GetElement(curveLayer, lstPos, true, false); // 获取插入位置 POSITION posInsert = pXy->GetValueList()->GetTailPosition(); if (lstPos.GetCount() > 0) { posInsert = lstPos.GetHead(); //POSITION pos = lstPos.GetHeadPosition(); //POSITION pt; //while (pos) { // pt = lstPos.GetNext(pos); // pXy->RemoveAt(pt); //} } std::vector contourList; Func_GetContourList(contourList); std::vector insertedPositions; insertedPositions.clear(); for (int i = 0; i < contourList.size(); i++) { PlineList lstLine = contourList[i]; std::string strLayerName = lstLine.GetName(); //CLayer * pLayer = pXy->FindAddLayer(strLayerName.c_str()); double dLayerValue = lstLine.GetValue(); CString strValue; strValue.Format("%lg", dLayerValue); vector vctLine = lstLine.GetPaths(); for (int j = 0; j < vctLine.size(); j++) { PlineList::Polyline2d line = vctLine[j]; NBase::CPointList pointList; for (int k = 0; k < line.size(); k++) { NBase::dfPoint point; point.x0 = line[k].x(); point.y0 = line[k].y(); pointList.AddTail(point); } CCurveEx* pCurve = new CCurveEx(); pCurve->SetPoints(pointList, 2); pCurve->SetName(strValue); //POSITION pos = pXy->AddElement(pCurve, DOUBLEFOX_CURVE); POSITION pos = pXy->InsertElementAfter(posInsert, pCurve, DOUBLEFOX_CURVE); insertedPositions.push_back(pos); COne* pOne = pXy->GetAt(pos); CLayer * pLayer = pLayerName; if (strLayerName == "无标注") { pLayer = pLayerNoName; } pOne->SetLayer(pLayer); posInsert = pos; } } // 标记要被删除的图元 destroyLength = lstPos.GetCount(); *destroyArray = new int64_t[destroyLength]; int32_t destroyIndex = 0; for (POSITION pos = lstPos.GetHeadPosition(); pos != nullptr; lstPos.GetNext(pos)) { POSITION pt = lstPos.GetAt(pos); (*destroyArray)[destroyIndex++] = reinterpret_cast(pt); } // 标记要新插入的图元 insertedLength = insertedPositions.size(); *insertedArray = new int64_t[insertedLength]; int32_t insertedIndex = 0; for (POSITION pos : insertedPositions) { (*insertedArray)[insertedIndex++] = reinterpret_cast(pos); } return true; } extern "C" __declspec(dllexport) void Editor_ShowMesh(bool visible) { Func_ShowMesh(visible); } extern "C" __declspec(dllexport) void Editor_ShowMeshVertex(bool bShow) { Func_ShowMeshVertex(bShow); } extern "C" __declspec(dllexport) void Editor_ShowIsopleth(bool visible) { Func_ShowIsopleth(visible); } extern "C" __declspec(dllexport) void Editor_ShowControlPoint(bool visible) { Func_ShowControlPoint(visible); } extern "C" __declspec(dllexport) void Editor_ShowFault(bool visible) { Func_ShowFault(visible); } extern "C" __declspec(dllexport) void Editor_ShowBound(bool visible) { Func_ShowBound(visible); } extern "C" __declspec(dllexport) void Editor_ShowOtherLines(bool visible) { Func_ShowOtherLines(visible); } extern "C" __declspec(dllexport) void Editor_GetProperty(double& isopStep, int& markStep, double& minIsop, double& maxIsop, double& zMin, double& zMax) { Func_GetProperty(isopStep, markStep, minIsop, maxIsop, zMin, zMax); } extern "C" __declspec(dllexport) void Editor_SetProperty(double isopStep, int markStep, double minIsop, double maxIsop, double zMin, double zMax) { Func_SetProperty(isopStep, markStep, minIsop, maxIsop, zMin, zMax); } bool HaveCurveViewName(CXy* pxy, COne* pOne) { CHowToViewCurve* pHowToView = pOne->GetLayer()->HowToViewCurve; if (pHowToView == nullptr || pHowToView->GetCount()==0) { return false; } for (int i = 0; i < pHowToView->GetCount(); i++) { CCurveView* pView = pHowToView->GetAt(i); if (pView->GetType() == CurveInName || pView->GetType() == CurveInNameAny) { return true; } } return false; } //bWithSubLayer 是否包含子层 void TakeLayerLines(CXy * pXy, const LPCTSTR &layerName, std::vector &vecPline, bool isContour, bool bWithSubLayer) { if (layerName == nullptr || lstrlen(layerName) == 0) { return; } NBase::CPositionList lstFault; pXy->GetElement(layerName, lstFault, bWithSubLayer, false); if (lstFault.GetCount() > 0) { POSITION pos = lstFault.GetHeadPosition(); POSITION pt; std::string strLayer; while (pos) { pt = lstFault.GetNext(pos); COne *pOne = (COne *)pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) { continue; } bool bViewName = HaveCurveViewName(pXy, pOne); if (bViewName == true) { strLayer = "标注"; } else { strLayer = "无标注"; } CCurveEx* pCurve = (CCurveEx*)(pOne->GetValue()); CString cstrName = pCurve->GetName(); PlineList::Polyline2d pline2D; if (isContour) { // 等值线,设置Z值和图层 if (cstrName.IsEmpty()) { continue; } double z = _tcstod(cstrName, nullptr); bool bFind = false; for (size_t i = 0; i < vecPline.size(); i++) { auto contourList = vecPline[i]; if (abs(contourList.GetValue() - z) < 1E-5) { contourList.AddPath(pline2D); bFind = true; break; } } if (bFind == false) { CString cstrLayer = pOne->GetLayer()->GetName(); //std::string strLayer = CT2A(cstrLayer); PlineList lineList; lineList.AddPath(pline2D); lineList.SetValue(z); lineList.SetName(strLayer); vecPline.push_back(lineList); } } else { for (int i = 0; i < pCurve->num; i++) { Point2D point{ pCurve->x[i], pCurve->y[i] }; pline2D.push_back(point); } if (vecPline.size() == 0) { PlineList lineList; vecPline.push_back(lineList); } PlineList& lineList = vecPline[0]; lineList.AddPath(pline2D); //lineList.SetName(strLayer); } } } } #pragma region 二期功能接口 //井点Z值绑定功能 //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_WellAdaptiveAdjust(int correctionType, int gridNum, float rad, float range, float miu) { Func_WellAdaptiveAdjust(correctionType, gridNum, rad, range, miu); } //开启查看Z值 extern "C" __declspec(dllexport) void Editor_EnablePickMeshZ(bool bEnable) { Func_EnablePickMeshZ(bEnable); } //设置井点文字颜色 extern "C" __declspec(dllexport) void Editor_SetWellColor(int r = 255, int g = 255, int b = 255) { Func_SetWellColor(r, g, b); } extern "C" __declspec(dllexport) void Editor_SetWellTxtSize(float size) { Func_SetWellTxtSize(size); } //填充断层 extern "C" __declspec(dllexport) void Editor_EnableFillFault(bool bEnable) { Func_EnableFillFault(bEnable); } //过滤等值线 //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_FilterMesh(float throld) { Func_FilterMesh(throld); } //打开/退出绘制多边形(可以在多边形操作窗口初始化的时候打开,窗口关闭的时候退出) extern "C" __declspec(dllexport) void Editor_EnableDrawPolygon(bool bEnable) { Func_EnableDrawPolygon(bEnable); } //多边形拉升 //闭合多边形后,就可以调用了 //per:强度,wellRad:井点约束半径。默认为0,表示不约束 //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_StretchUpPolygon(float per, bool state, float wellRad = 0) { Func_StretchlUpPolygon(per, state, wellRad); } //多边形下压,用法同上 //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_PushDownPolygon(float per, bool state, float wellRad = 0) { Func_PushDownPolygon(per, state, wellRad); } //多边形平滑,用法同上 //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_SmoothPolygon(float per, bool state, float wellRad = 0) { Func_SmoothPolygon(per, state, wellRad); } //网格优化,用法同Func_StrechUp //这个功能支持undo/redo,可以在调用之前加Func_StartCommand,调用结束加Func_EndCommand extern "C" __declspec(dllexport) void Editor_OptimizeMesh(int startx, int starty, int endx, int endy, float rad, float per) { Func_OptimizeMesh(startx, starty, endx, endy, rad, per); } //获取显示位置 //(px,py)表示窗口左上角对应网格上的坐标 // scale表示网格缩放比例(一个像素多少米) extern "C" __declspec(dllexport) void Editor_GetViewPos(double& px, double& py, double& scale) { Func_GetViewPos(px, py, scale); } //设置显示位置 extern "C" __declspec(dllexport) void Editor_SetViewPos(double px, double py, double scale) { Func_SetViewPos(px, py, scale); } //获取鼠标位置 extern "C" __declspec(dllexport) void Editor_GetMousePos(double& px, double& py) { Func_GetMousePos(px, py); } //设置鼠标位置 extern "C" __declspec(dllexport) void Editor_SetMousePos(double px, double py) { Func_SetMousePos(px, py); } extern "C" __declspec(dllexport) void Editor_SetMouseWheelState(bool state) { Func_SetMouseWheelState(state); } #pragma endregion //表达式检测 extern "C" __declspec(dllexport) bool Editor_CompileExpressionZ(LPCTSTR expressionString) { char expressionStr[256]; memset(expressionStr, 0, sizeof(char) * 256); CString str(expressionString); if (!str.IsEmpty()) { strncpy_s(expressionStr, expressionString, str.GetLength()); } bool state = Func_CompileExpressionZ(expressionStr); return state; } //Z值运算 extern "C" __declspec(dllexport) bool Editor_CalculateZByExpression(LPCTSTR expressionString) { char expressionStr[256]; memset(expressionStr, 0, sizeof(char) * 256); CString str(expressionString); if (!str.IsEmpty()) { strncpy_s(expressionStr, expressionString, str.GetLength()); } bool state = Func_CalculateZByExpression(expressionStr); return state; } //获取最小Z值 extern "C" __declspec(dllexport) double Editor_GetZMin() { return Func_GetZMin(); } //获取最大Z值 extern "C" __declspec(dllexport) double Editor_GetZMax() { return Func_GetZMax(); } //设置显示小数位数 extern "C" __declspec(dllexport) void Editor_SetDecimalNumber(int num) { Func_SetDecimalNumber(num); } //获取显示的小数位数 extern "C" __declspec(dllexport) int Editor_GetDecimalNumber() { return Func_GetDecimalNumber(); } //设置断层控制状态 extern "C" __declspec(dllexport) void Editor_SetFaultControlState(bool state) { Func_SetFaultControlState(state); } //获取断层控制状态 extern "C" __declspec(dllexport) bool Editor_GetFaultControlState() { return Func_GetFaultControlState(); } //井点校正 extern "C" __declspec(dllexport) bool Editor_RectificationMeshWellCompute(double deltaz, int correctionType, int gridNum, int type, double factor) { return Func_RectificationMeshWellCompute(deltaz, correctionType, gridNum, type, factor); } //井点校正 线程终止 extern "C" __declspec(dllexport) void Editor_MeshWellThreadStop() { Func_MeshWellThreadStop(); } //井点校正 进度 extern "C" __declspec(dllexport) int Editor_GetWellRectificationProgress() { return Func_GetWellRectificationProgress(); } //刷新界面 extern "C" __declspec(dllexport) void Editor_UpdateObjectView() { return Func_UpdateObjectView(); } //仿制图章样本虚影 extern "C" __declspec(dllexport) void Editor_DrawCircleStampClone(int ipx, int ipy, float rad, bool state) { Func_DrawCircleStampClone(ipx, ipy, rad, state); } //仿制图章 extern "C" __declspec(dllexport) void Editor_StampClone(int ipx, int ipy, float rad) { return Func_StampClone(ipx, ipy, rad); } //仿制图章样本 extern "C" __declspec(dllexport) void Editor_StampCloneSample(int ipx, int ipy, float rad) { //Func_DrawCircleName("Circle1", ipx, ipy, rad); Func_DrawCircleStampClone(ipx, ipy, rad, true); return Func_StampCloneSample(ipx, ipy, rad); } //绘制箭头(物源方向) extern "C" __declspec(dllexport) void Editor_DrawTrendArrowOnWindow(LPCTSTR arrowName, int ipx, int ipy, float angle, float ratio) { Func_DrawTrendArrowOnWindow(arrowName, ipx, ipy, angle, ratio); } //清理单个箭头(物源方向) extern "C" __declspec(dllexport) void Editor_ClearTrendArrow(LPCTSTR arrowName) { Func_ClearTrendArrow(arrowName); } //清理所有箭头(物源方向) extern "C" __declspec(dllexport) void Editor_ClearAllTrendArrows() { Func_ClearAllTrendArrows(); } struct PointDataInterop { double X; double Y; double Z; double TZ; char Name[256]; }; //获取控制点 extern "C" __declspec(dllexport) int Editor_GetPointList(CXy* pXy, LPCTSTR pointLayer, PointDataInterop* outArray, int capacity) { int validCount = 0; if (pointLayer && lstrlen(pointLayer) > 0) { CString strPointLayers = pointLayer; int nPos = 0; CString strSingleLayer = strPointLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { NBase::CPositionList lstPoint; pXy->GetElement(strSingleLayer, lstPoint, true, false); if (lstPoint.GetCount() > 0) { POSITION pos = lstPoint.GetHeadPosition(); POSITION pt; while (pos) { pt = lstPoint.GetNext(pos); COne* pOne = (COne*)pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_POINT) { continue; } CPointNameEx* pPoint = (CPointNameEx*)(pOne->GetValue()); if (outArray != nullptr && validCount < capacity) { outArray[validCount].X = pPoint->x0; outArray[validCount].Y = pPoint->y0; outArray[validCount].Z = pPoint->z0; double z1 = 0; Func_GetPonitZ(pPoint->x0, pPoint->y0, z1); outArray[validCount].TZ = z1; CString cstrName = pPoint->GetName(); CT2A asciiName(cstrName); strncpy_s(outArray[validCount].Name, 256, asciiName, _TRUNCATE); } validCount++; } } strSingleLayer = strPointLayers.Tokenize(_T(";"), nPos); } } return validCount; } extern "C" __declspec(dllexport) int Editor_SetWellPointList(PointDataInterop* inArray, int count) { if (!inArray || count <= 0) return 0; std::vector pointList; pointList.reserve(count); for (int i = 0; i < count; ++i) { Point2D pt(inArray[i].X, inArray[i].Y); std::string strName = inArray[i].Name; ControlPoint2d cp(pt, inArray[i].Z, strName); pointList.push_back(cp); } Func_SetWellControlPoint(pointList); return 1; } extern "C" __declspec(dllexport) bool Editor_FittingCorrectionOperation(LPCTSTR expressionString) { char expressionStr[256]; memset(expressionStr, 0, sizeof(char) * 256); CString str(expressionString); if (!str.IsEmpty()) { strncpy_s(expressionStr, expressionString, str.GetLength()); } bool state = Func_FittingCorrectionOperation(expressionStr); return state; } //全图平滑(迭代高斯) extern "C" __declspec(dllexport) void Editor_FullSmoothIterativeGaussian(int type, double sigma, int iter, int gridNum) { Func_FullSmoothIterativeGaussian(type, sigma, iter, gridNum); } //全图平滑 extern "C" __declspec(dllexport) void Editor_FullSmoothIDWMesh(int type, double smoothCoefficient, int smoothTimes, int gridNum) { Func_FullSmoothIDWMesh(type, smoothCoefficient, smoothTimes, gridNum); } struct LineVolumnData { char Name[256]; double Area; double Volumn; double AreaVolumn; }; // 体积统计 (容积法) extern "C" __declspec(dllexport) int Editor_StatisVolumn(CXy* pXy, LPCTSTR otherLineLayer, LineVolumnData* outArray, int count, int volumeMode) { // 如果 outArray 为空,说明只需要计数,不需要创建繁重的 Mesh 和计算体积 bool bCalculate = (outArray != nullptr); CMesh* pOriginMesh = NULL; POSITION pos = pXy->FindFirstElement(DOUBLEFOX_MESH); if (pos) { pOriginMesh = (CMesh*)pXy->GetAtValue(pos); } if (pOriginMesh == NULL) { return 0; } CMesh* pWorkMesh = NULL; if (bCalculate) { pWorkMesh = new CMesh(); if (pWorkMesh) { *pWorkMesh = *pOriginMesh; double* pValues = Func_GetValue(); double zMin = Func_GetZMin(); double zMax = Func_GetZMax(); CSize size = pWorkMesh->size(); // 获取尺寸 for (int i = 0; i < size.cx; i++) { for (int j = 0; j < size.cy; j++) { ((CMeshBase*)pWorkMesh)->SetValue(i, j, pValues[i + j * size.cx]); } } pWorkMesh->SetM(zMin, zMax); } if (pWorkMesh == NULL) { return 0; } } int outputIndex = 0; // 获取每条线的面积体积以及均衡 if (otherLineLayer && lstrlen(otherLineLayer) > 0) { CString strOtherLayers = otherLineLayer; int nPos = 0; CString strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { NBase::CPositionList lstFault; pXy->GetElement(strSingleLayer, lstFault, true, false); if (lstFault.GetCount() > 0) { POSITION pos = lstFault.GetHeadPosition(); POSITION pt; while (pos) { pt = lstFault.GetNext(pos); COne* pOne = (COne*)pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) { continue; } if (!bCalculate) { outputIndex++; continue; } CCurveEx* pCurve = (CCurveEx*)(pOne->GetValue()); double area = pCurve->Area(); double areaVolumn = 0; double volumn = 0; CString strName = pCurve->GetName(); // 此时 pWorkMesh 一定存在 (前面已检查) if (pWorkMesh) { if (volumeMode == 0) //构造图 { NBase::CPoint3D point; if (pWorkMesh->GetHightPoint(pCurve, point) > 0) //计算高点 { double cz = pWorkMesh->GetClosedZ(*pCurve, point.z0); //计算闭合线 areaVolumn = pWorkMesh->TradeArea(*pCurve, cz); if (std::isnan(areaVolumn)) { areaVolumn = 0; } volumn = areaVolumn * area; } } else if (volumeMode == 1) //等厚图 { areaVolumn = pWorkMesh->TradeArea(*pCurve, 0); if (std::isnan(areaVolumn)) { areaVolumn = 0; } volumn = areaVolumn * area; } } // 填充数据到数组 if (outArray != nullptr && outputIndex < count) { outArray[outputIndex].Area = area; outArray[outputIndex].Volumn = volumn; outArray[outputIndex].AreaVolumn = areaVolumn; CT2A asciiName(strName); strcpy_s(outArray[outputIndex].Name, 256, asciiName); } outputIndex++; } } strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); } } // 清理内存 if (pWorkMesh) { delete pWorkMesh; pWorkMesh = NULL; } return outputIndex; } double TakeZFromName(LPCTSTR curveName) { vector vecString; CString strTmp; int iPos = 0; double dZ = 0; int nCount = 0; while (AfxExtractSubString(strTmp, curveName, iPos, ',')) { iPos++; dZ += atof(strTmp); nCount++; } return dZ / nCount; } // 清理 CMyCurve 指针向量 void ClearMyCurveVector(vector& vec) { for (size_t i = 0; i < vec.size(); i++) { if (vec[i] != NULL) delete vec[i]; } vec.clear(); } // 体积统计 (等值线法) extern "C" __declspec(dllexport) int Editor_ContourStatisVolumn(CXy* pXy, LPCTSTR otherLineLayer, LPCTSTR faultLayer, LineVolumnData* outArray, int count) { if (!otherLineLayer || lstrlen(otherLineLayer) == 0) return 0; //outArray是空则只算个数 bool bCalculate = (outArray != nullptr); std::vector rawContourList; std::vector rawFaults; if (bCalculate) { Func_GetContourList(rawContourList); if (faultLayer && lstrlen(faultLayer) > 0) { POSITION pos, pt; CList lstFault; pXy->GetElement(faultLayer, lstFault, TRUE); if (lstFault.GetCount() > 0) { pos = lstFault.GetHeadPosition(); while (pos) { pt = lstFault.GetNext(pos); COne* pOne = pXy->GetAt(pt); if (pOne->GetType() == DOUBLEFOX_CURVE) { rawFaults.push_back((CCurveEx*)pOne->value); } } } } } int outputIndex = 0; CString strOtherLayers = otherLineLayer; int nPos = 0; CString strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); while (strSingleLayer != _T("")) { NBase::CPositionList lstPolygons; pXy->GetElement(strSingleLayer, lstPolygons, true, false); if (lstPolygons.GetCount() > 0) { POSITION pos = lstPolygons.GetHeadPosition(); POSITION pt; while (pos) { pt = lstPolygons.GetNext(pos); COne* pOne = (COne*)pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; if (!bCalculate) { outputIndex++; continue; } CCurveEx* pBoundaryCurve = (CCurveEx*)(pOne->GetValue()); CString strName = pBoundaryCurve->GetName(); CContourFillMap cfmp; vector contours; vector flts; CMyCurve curBorder; curBorder.Create(pBoundaryCurve->num); for (int i = 0; i < pBoundaryCurve->num; i++) { curBorder.SetPoint(i, pBoundaryCurve->x[i], pBoundaryCurve->y[i], pBoundaryCurve->z[i]); } for (int i = 0; i < rawContourList.size(); i++) { // (保持原有的构建逻辑) PlineList lstLine = rawContourList[i]; double dLayerValue = lstLine.GetValue(); CString strValue; strValue.Format("%lg", dLayerValue); vector vctLine = lstLine.GetPaths(); for (int j = 0; j < vctLine.size(); j++) { const PlineList::Polyline2d& line = vctLine[j]; CMyCurve* curve = new CMyCurve(); curve->Create(line.size()); for (int k = 0; k < line.size(); k++) curve->SetPoint(k, line[k].x(), line[k].y(), dLayerValue); curve->SetName(strValue); curve->GetLocation(); contours.push_back(curve); } } cfmp.SetContours(contours); // ... 构建 flts ... for (size_t i = 0; i < rawFaults.size(); i++) { CCurveEx* pF = rawFaults[i]; CMyCurve* curve = new CMyCurve(); curve->Create(pF->num); for (int k = 0; k < pF->num; k++) curve->SetPoint(k, pF->x[k], pF->y[k], pF->z[k]); curve->SetName(pF->GetName()); curve->GetLocation(); flts.push_back(curve); } cfmp.SetFlts(flts); // ... 计算 ... cfmp.SetBorder(curBorder); cfmp.SetExtensivePara(1.1); cfmp.CreatePolygons(); double dAreaTotal = 0; double dVolumTotal = 0; std::vector resultAreas = cfmp.GetResultPolygons(); for (size_t i = 0; i < resultAreas.size(); i++) { CMyCurve* pResultCurve = resultAreas[i]; double dArea = pResultCurve->Area(); double dZ = TakeZFromName(pResultCurve->GetName()); dAreaTotal += dArea; dVolumTotal += dZ * dArea; } ClearMyCurveVector(contours); ClearMyCurveVector(flts); // 填充数据 if (outputIndex < count) { outArray[outputIndex].Area = dAreaTotal; outArray[outputIndex].Volumn = fabs(dVolumTotal); if (dAreaTotal != 0) outArray[outputIndex].AreaVolumn = fabs(dVolumTotal / dAreaTotal); else outArray[outputIndex].AreaVolumn = 0; CT2A asciiName(strName); strcpy_s(outArray[outputIndex].Name, 256, asciiName); } outputIndex++; } } strSingleLayer = strOtherLayers.Tokenize(_T(";"), nPos); } return outputIndex; } extern "C" __declspec(dllexport) void Editor_DragShape(int ipx, int ipy, int isx, int isy, float rad, float per) { Func_DragShape(ipx, ipy, isx, isy, rad, per); } extern "C" __declspec(dllexport) void Editor_DragShapeChangeData() { Func_DragShapeChangeData(); } #pragma region 沉积相 extern "C" __declspec(dllexport) void Editor_SetFaciesTypeZ(int zValue) { Func_SetFaciesType(zValue); } extern "C" __declspec(dllexport) void Editor_GetFaciesTypeZ(int px, int py, int &colorZ) { Func_GetFaciesTypeZ(px, py, colorZ); } extern "C" __declspec(dllexport) void Editor_BrushSetZInCircle(int ipx, int ipy, float rad, int zValue) { Func_BrushSetZInCircle(ipx, ipy, rad, zValue); } extern "C" __declspec(dllexport) void Editor_FeatherBrushInCircle(int ipx, int ipy, float rad, float per) { Func_FeatherBrushInCircle(ipx, ipy, rad, per); } extern "C" __declspec(dllexport) void Editor_BrushSmoothZInCircle(int ipx, int ipy, float rad, float per) { Func_BrushSmoothZInCircle(ipx, ipy, rad, per); } extern "C" __declspec(dllexport) void Editor_BrushEraseInCircle(int ipx, int ipy, float rad) { Func_BrushEraseInCircle(ipx, ipy, rad); } extern "C" __declspec(dllexport) void Editor_MagicWandSetZ(int ipx, int ipy, int zVaule) { Func_MagicWandSetZ(ipx, ipy, zVaule); } extern "C" __declspec(dllexport) void Editor_FaciesPolygonLassoZ(int zVaule) { Func_FaciesPolygonLassoZ(zVaule); } extern "C" __declspec(dllexport) void Editor_FaciesPolygonLassoSmooth(float per) { Func_FaciesPolygonLassoSmooth(per); } extern "C" __declspec(dllexport) void Editor_FaciesFullImageSmooth(float per) { Func_FaciesFullImageSmooth(per); } extern "C" __declspec(dllexport) int * Editor_GetFaciesList(int& count) { std::vector faciesList; Func_GetFaciesList(faciesList); count = faciesList.size(); if (count == 0) { return nullptr; } // 分配 COM 可释放的内存(C# 会自动调用 CoTaskMemFree) int* result = static_cast(CoTaskMemAlloc(count * sizeof(int))); if (!result) { return nullptr; } std::memcpy(result, faciesList.data(), count * sizeof(int)); return result; } extern "C" __declspec(dllexport) void Editor_GetColorByZ(double z, int& r, int& g, int& b) { Func_GetColorByZ(z, r, g, b); } extern "C" __declspec(dllexport) void Editor_SetColorByZ(double z, int r, int g, int b) { Func_SetColorByZ(z, r, g, b); } #pragma endregion