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.
154 lines
5.8 KiB
C#
154 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using AI.AgentIntegration;
|
|
using GeoSigma.UCDraw.Service;
|
|
using GeoSigma.UCDraw.UC;
|
|
using GeoSigmaDrawLib;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace PcgDrawR.Services
|
|
{
|
|
/// <summary>
|
|
/// 负责栅格化(网络化)相关的业务逻辑。
|
|
/// </summary>
|
|
public class GriddingModuleService
|
|
{
|
|
private readonly IAppEnvironment env;
|
|
private readonly GriddingContext griddingContext;
|
|
private readonly GriddingService griddingService;
|
|
|
|
private readonly string importRoot;
|
|
private readonly string outputPath;
|
|
|
|
public GriddingModuleService(IAppEnvironment env, string importRoot = "E:/import", string outputPath = "E:/output.kev")
|
|
{
|
|
this.env = env ?? throw new ArgumentNullException(nameof(env));
|
|
this.importRoot = importRoot;
|
|
this.outputPath = outputPath;
|
|
|
|
griddingContext = new GriddingContext(this.importRoot);
|
|
griddingService = new GriddingService();
|
|
}
|
|
|
|
public Task<AppActionResult> GetParametersAsync(AppAction action)
|
|
{
|
|
string yaml = griddingContext.GetParametersYamlForAI();
|
|
return Task.FromResult(AppActionResult.Sucess(yaml));
|
|
}
|
|
|
|
public Task<AppActionResult> SetParametersAsync(AppAction action)
|
|
{
|
|
if (!action.Parameters.TryGetValue("parameters", out var parametersObj))
|
|
{
|
|
return Task.FromResult(AppActionResult.Fail("缺少 'parameters' 参数"));
|
|
}
|
|
|
|
string parametersStr = parametersObj.ToString();
|
|
griddingContext.SetParametersFromYaml(parametersStr);
|
|
return Task.FromResult(AppActionResult.Sucess("设置成功"));
|
|
}
|
|
|
|
public Task<AppActionResult> GetColumnsAsync(AppAction action)
|
|
{
|
|
List<string> requredColumns = griddingContext.GetRequiredColumns(griddingContext.CurrentImportDataType);
|
|
List<string> availableColumns = griddingContext.GetAvailableColumns();
|
|
|
|
var dataToSerialize = new
|
|
{
|
|
RequiredColumns = requredColumns,
|
|
AvailableColumns = availableColumns,
|
|
};
|
|
|
|
return Task.FromResult(AppActionResult.Sucess(JsonConvert.SerializeObject(dataToSerialize)));
|
|
}
|
|
|
|
public async Task<AppActionResult> LoadXyzAsync(AppAction action)
|
|
{
|
|
if (!action.Parameters.TryGetValue("path", out var pathObj))
|
|
{
|
|
return AppActionResult.Fail("缺少 'path' 参数");
|
|
}
|
|
|
|
string path = pathObj.ToString();
|
|
|
|
griddingContext.CurrentImportDataType = DataLoaderModel.ImportDataType.Xyz;
|
|
bool ok = await griddingService.LoadFileAsync(griddingContext, path);
|
|
griddingContext.CurrentDataType = UCDraw.GraphDataType.XYZ;
|
|
return ok ? AppActionResult.Sucess("加载成功") : AppActionResult.Fail("加载文件失败");
|
|
}
|
|
|
|
public Task<AppActionResult> MatchColumnsAsync(AppAction action)
|
|
{
|
|
var connections = new List<ShapeConnection>();
|
|
foreach (var kv in action.Parameters)
|
|
{
|
|
connections.Add(new ShapeConnection(kv.Key, kv.Value.ToString()));
|
|
}
|
|
|
|
griddingService.SetColumnMapping(griddingContext, connections);
|
|
return Task.FromResult(AppActionResult.Sucess("加载成功"));
|
|
}
|
|
|
|
public async Task<AppActionResult> ImportAsync(AppAction action)
|
|
{
|
|
await griddingService.ImportAsync(griddingContext, griddingContext.CurrentImportDataType);
|
|
return AppActionResult.Sucess("导入成功");
|
|
}
|
|
|
|
public async Task<AppActionResult> RunAsync(AppAction action)
|
|
{
|
|
var result = await griddingService.GriddingAsync(griddingContext, outputPath);
|
|
if (result.Success && !string.IsNullOrWhiteSpace(result.Output))
|
|
{
|
|
env.MainForm.Invoke(() =>
|
|
{
|
|
env.ActiveUCDrawEdit?.OpenFile(result.Output);
|
|
});
|
|
}
|
|
return AppActionResult.Sucess("网络化成功");
|
|
}
|
|
|
|
public Task<AppActionResult> PreviewDataAsync(AppAction action)
|
|
{
|
|
string markdown = griddingService.GetPreviewData(griddingContext);
|
|
AppActionResult result = AppActionResult.Sucess(message: markdown);
|
|
return Task.FromResult(result);
|
|
}
|
|
|
|
public Task<AppActionResult> AddScaleBarAsync(AppAction action)
|
|
{
|
|
var geo = env.ActiveGeo;
|
|
if (geo != null)
|
|
{
|
|
var cache = griddingContext.griddingModel.XyzAreaCache;
|
|
bool result = geo.CreateProportionFull("比例尺", cache.XMin, cache.YMin, cache.XMax, cache.YMax, 100, 10, 10);
|
|
if (result)
|
|
{
|
|
return Task.FromResult(AppActionResult.Sucess("添加比例尺成功"));
|
|
}
|
|
else
|
|
{
|
|
return Task.FromResult(AppActionResult.Fail("添加失败: 当前没有打开任何图件"));
|
|
}
|
|
}
|
|
|
|
return Task.FromResult(AppActionResult.Fail("添加失败: 当前没有打开任何图件"));
|
|
}
|
|
|
|
public Task<AppActionResult> AddLegendAsync(AppAction action)
|
|
{
|
|
var geo = env.ActiveGeo;
|
|
var cache = griddingContext.griddingModel.XyzAreaCache;
|
|
if (geo != null)
|
|
{
|
|
double width = Math.Abs(cache.XMax - cache.XMin) / 3.0;
|
|
geo.LegendAdd(cache.XMin, cache.YMin, width, 3, "");
|
|
return Task.FromResult(AppActionResult.Sucess("添加图例成功"));
|
|
}
|
|
return Task.FromResult(AppActionResult.Fail("添加失败: 当前没有打开任何图件"));
|
|
}
|
|
}
|
|
}
|
|
|