|
|
using DevExpress.CodeParser;
|
|
|
using DevExpress.Diagram.Core.Shapes;
|
|
|
using DevExpress.Xpo.DB;
|
|
|
|
|
|
using EmbedIO.WebSockets;
|
|
|
|
|
|
using GeoSigma.SigmaDrawerUtil;
|
|
|
|
|
|
using GeoSigmaDrawLib;
|
|
|
|
|
|
using KevDrawServer.Drawer;
|
|
|
|
|
|
using Swan;
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
using System.Drawing.Imaging;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net.WebSockets;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
|
|
|
|
|
namespace KevDrawServer
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 图形操作类.
|
|
|
/// </summary>
|
|
|
public class EventResponse
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Initializes a new instance of the <see cref="EventResponse"/> class.
|
|
|
/// </summary>
|
|
|
/// <param name="drawer">The drawer.</param>
|
|
|
/// <param name="context">The context.</param>
|
|
|
public EventResponse(WebDrawer drawer, IWebSocketContext context)
|
|
|
{
|
|
|
this.Drawer = drawer;
|
|
|
this.Context = context;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets 图形操作实例.
|
|
|
/// </summary>
|
|
|
public WebDrawer Drawer { get; set; } = null;
|
|
|
/// <summary>
|
|
|
/// Gets or sets 连接上下文.
|
|
|
/// </summary>
|
|
|
public IWebSocketContext Context { get; set; } = null;
|
|
|
|
|
|
private string imageFile = "temp/K1.png";
|
|
|
|
|
|
public JsEvent ExcuteOperator(string evtentType, Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
object objDrawerWidth = null;
|
|
|
object objDrawerHeight = null;
|
|
|
if (keyValues != null)
|
|
|
{
|
|
|
keyValues.TryGetValue("width", out objDrawerWidth);
|
|
|
keyValues.TryGetValue("height", out objDrawerHeight);
|
|
|
}
|
|
|
|
|
|
if (objDrawerWidth != null && objDrawerHeight != null)
|
|
|
{
|
|
|
double dDrawerWidth = 0;
|
|
|
double dDrawerHeight = 0;
|
|
|
double.TryParse($"{objDrawerWidth}", out dDrawerWidth);
|
|
|
double.TryParse($"{objDrawerHeight}", out dDrawerHeight);
|
|
|
if (dDrawerWidth > 0 && dDrawerHeight > 0)
|
|
|
{
|
|
|
this.Drawer.DrawerSize = new Size((int)dDrawerWidth, (int)dDrawerHeight);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
JsEvent evtResult = null;
|
|
|
int nKeyCode = 0;
|
|
|
switch (evtentType)
|
|
|
{
|
|
|
case "OpenFile":
|
|
|
evtResult = this.ShowImg();
|
|
|
break;
|
|
|
case "EditWellGroup":
|
|
|
evtResult = this.ShowImg();
|
|
|
break;
|
|
|
case "ZoomIn":
|
|
|
evtResult = this.ZoomIn(keyValues);
|
|
|
break;
|
|
|
case "ZoomOut":
|
|
|
evtResult = this.ZoomOut(keyValues);
|
|
|
break;
|
|
|
case "ViewAll":
|
|
|
evtResult = this.ViewAll(keyValues);
|
|
|
break;
|
|
|
case "Refresh":
|
|
|
evtResult = this.ReFresh();
|
|
|
break;
|
|
|
case "Center":
|
|
|
evtResult = this.DrawCenter();
|
|
|
break;
|
|
|
case "ViewPan":
|
|
|
evtResult = this.ViewPan(keyValues);
|
|
|
break;
|
|
|
case "ViewWindow":
|
|
|
evtResult = this.ViewWindow(keyValues);
|
|
|
break;
|
|
|
case "Redraw":
|
|
|
evtResult = this.Redraw();
|
|
|
break;
|
|
|
case "SwitchToolType":
|
|
|
if (this.Drawer != null)
|
|
|
{
|
|
|
this.Drawer.ActiveTool = (UCDraw.DrawToolType)Convert.ToInt32(keyValues["toolType"]);
|
|
|
}
|
|
|
break;
|
|
|
case "MouseDown":
|
|
|
//double dX = Convert.ToDouble(dictionary["x"]);
|
|
|
//double dY = Convert.ToDouble(dictionary["y"]);
|
|
|
//await ClickImageAsync(dX, dY);
|
|
|
break;
|
|
|
case "LButtonUp":
|
|
|
double dUpX = Convert.ToDouble(keyValues["x"]);
|
|
|
double dUpY = Convert.ToDouble(keyValues["y"]);
|
|
|
|
|
|
if (keyValues["keyCode"] != null)
|
|
|
{
|
|
|
nKeyCode = Convert.ToInt32(keyValues["keyCode"]);
|
|
|
}
|
|
|
evtResult = this.LButtonUp(dUpX, dUpY, nKeyCode);
|
|
|
break;
|
|
|
case "SelectRegion": // 区域选择
|
|
|
double dStartX = Convert.ToDouble(keyValues["startX"]);
|
|
|
double dStartY = Convert.ToDouble(keyValues["startY"]);
|
|
|
double dEndX = Convert.ToDouble(keyValues["endX"]);
|
|
|
double dEndY = Convert.ToDouble(keyValues["endY"]);
|
|
|
bool bAdd = false;
|
|
|
if (keyValues["isAdd"] != null)
|
|
|
{
|
|
|
bAdd = Convert.ToBoolean(keyValues["isAdd"]);
|
|
|
}
|
|
|
evtResult = this.SelectRegion(dStartX, dStartY, dEndX, dEndY, bAdd);
|
|
|
break;
|
|
|
case "SelectDragStart": // 拖动选择操作开始
|
|
|
evtResult = this.SelectDragStart();
|
|
|
break;
|
|
|
case "SelectMouseMove":
|
|
|
double dMoveX = Convert.ToDouble(keyValues["x"]);
|
|
|
double dMoveY = Convert.ToDouble(keyValues["y"]);
|
|
|
int nHandle = Convert.ToInt32(keyValues["handleIndex"]);
|
|
|
evtResult = this.SelectMouseMove(dMoveX, dMoveY);
|
|
|
break;
|
|
|
case "SelectTransformElements":
|
|
|
double dDragStartX = Convert.ToDouble(keyValues["startX"]);
|
|
|
double dDragStartY = Convert.ToDouble(keyValues["startY"]);
|
|
|
double dDragEndX = Convert.ToDouble(keyValues["endX"]);
|
|
|
double dDragEndY = Convert.ToDouble(keyValues["endY"]);
|
|
|
if (this.Drawer != null)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Bitmap bmp = this.Drawer.SelectTransformElements(dDragStartX, dDragStartY, dDragEndX, dDragEndY);
|
|
|
evtResult = this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
catch (EmbedIO.WebSockets.WebSocketException ex)
|
|
|
{
|
|
|
Terminal.WriteLine(ex.Message);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case "DragElement":
|
|
|
double dDragX = Convert.ToDouble(keyValues["x"]);
|
|
|
double dDragY = Convert.ToDouble(keyValues["y"]);
|
|
|
evtResult = this.TranslateElements(dDragX, dDragY);
|
|
|
break;
|
|
|
case "SelectMouseDown":
|
|
|
double dX = Convert.ToDouble(keyValues["x"]);
|
|
|
double dY = Convert.ToDouble(keyValues["y"]);
|
|
|
//await ClickImageAsync(dX, dY);
|
|
|
evtResult = this.SelectLButtonDown(dX, dY);
|
|
|
break;
|
|
|
case "SelectMouseUp":
|
|
|
double dSelectUpX = Convert.ToDouble(keyValues["x"]);
|
|
|
double dSelectUpY = Convert.ToDouble(keyValues["y"]);
|
|
|
int nMouseUpKeyCode = 0;
|
|
|
if (keyValues["keyCode"] != null)
|
|
|
{
|
|
|
nMouseUpKeyCode = Convert.ToInt32(keyValues["keyCode"]);
|
|
|
}
|
|
|
evtResult = this.SelectMouseUp(dSelectUpX, dSelectUpY, nMouseUpKeyCode);
|
|
|
break;
|
|
|
case "GetElementProperty":
|
|
|
evtResult = this.GetSelectElementProperty();
|
|
|
break;
|
|
|
case "SetElementProperty":
|
|
|
long elementID = 0;
|
|
|
string strPropertyData = @"";
|
|
|
strPropertyData = string.Empty;
|
|
|
if (keyValues.ContainsKey("elementID"))
|
|
|
{
|
|
|
long.TryParse($"{keyValues["elementID"]}", out elementID);
|
|
|
}
|
|
|
if (keyValues.ContainsKey("data"))
|
|
|
{
|
|
|
strPropertyData = $"{keyValues["data"]}";
|
|
|
}
|
|
|
evtResult = this.SetSelectElementProperty(strPropertyData);
|
|
|
break;
|
|
|
case "WellGroupClone":
|
|
|
long wellGroupID = 0;
|
|
|
if (keyValues.ContainsKey("elementID"))
|
|
|
{
|
|
|
long.TryParse($"{keyValues["elementID"]}", out elementID);
|
|
|
}
|
|
|
evtResult = this.SelectWellGroupClone(wellGroupID);
|
|
|
break;
|
|
|
case "GetWellGroupData":
|
|
|
evtResult = this.SelectGetWellGroupData();
|
|
|
break;
|
|
|
case "SaveFile":
|
|
|
evtResult = this.SaveFile();
|
|
|
break;
|
|
|
case "GetLayers":
|
|
|
evtResult = this.GetLayersJson(); // GetLayers();
|
|
|
break;
|
|
|
case "GetLayersNorm":
|
|
|
evtResult = this.GetLayers(); // GetLayers();
|
|
|
break;
|
|
|
case "GetElementsCount":
|
|
|
evtResult = this.GetElementsCount(); // GetLayers();
|
|
|
break;
|
|
|
case "SetLayersStatus":
|
|
|
string strData = $"{keyValues["layerData"]}";
|
|
|
evtResult = this.SetLayersStatus(strData);
|
|
|
break;
|
|
|
case "DeleteLayers":
|
|
|
string strLayersData = $"{keyValues["layers"]}";
|
|
|
int nWithChilden = 1;
|
|
|
if (keyValues.ContainsKey("widthChild"))
|
|
|
{
|
|
|
Int32.TryParse($"{keyValues["widthChild"]}", out nWithChilden);
|
|
|
}
|
|
|
evtResult = this.DeleteLayers(strLayersData, nWithChilden == 1);
|
|
|
break;
|
|
|
case "ClearAll":
|
|
|
int needUndo = 0;
|
|
|
string strNeedUndo = $"{keyValues["needUndo"]}";
|
|
|
if (!string.IsNullOrEmpty(strNeedUndo))
|
|
|
{
|
|
|
int.TryParse(strNeedUndo, out needUndo);
|
|
|
}
|
|
|
evtResult = this.ClearAll(needUndo == 1 ? true : false);
|
|
|
break;
|
|
|
case "AddBufferData":
|
|
|
string strBuffer = $"{keyValues["bufferData"]}";
|
|
|
evtResult = this.AddBufferData(strBuffer);
|
|
|
break;
|
|
|
case "AddBasicDraw":
|
|
|
{
|
|
|
string strDrawBuffer = $"{keyValues["bufferData"]}";
|
|
|
string strLayer = $"{keyValues["layer"]}";
|
|
|
bool bCreateBlock = Convert.ToBoolean(keyValues["CreateBlock"]);
|
|
|
evtResult = this.InsertDataBottom(strDrawBuffer, strLayer, bCreateBlock);
|
|
|
}
|
|
|
break;
|
|
|
case "MergeFile": // 合并图件
|
|
|
string strFileName = $"{keyValues["fileName"]}";
|
|
|
evtResult = this.MergeFile(strFileName);
|
|
|
break;
|
|
|
case "QueryRangeScreen2Real":
|
|
|
double dScreenStartX = Convert.ToDouble(keyValues["startX"]);
|
|
|
double dScreenEndX = Convert.ToDouble(keyValues["endX"]);
|
|
|
double dScreenStartY = Convert.ToDouble(keyValues["startY"]);
|
|
|
double dScreenEndY = Convert.ToDouble(keyValues["endY"]);
|
|
|
evtResult = this.QueryRangeScreen2RealX(dScreenStartX, dScreenEndX, dScreenStartY, dScreenEndY);
|
|
|
break;
|
|
|
case "CreateFavorableArea":
|
|
|
string strToken = $"{keyValues["token"]}";
|
|
|
var drawer = GlobalSession.GetData(strToken);
|
|
|
string filename = Path.GetFileNameWithoutExtension(((WebDrawer)drawer).DrawFileName);
|
|
|
double min = Convert.ToDouble(keyValues["min"]);
|
|
|
double max = Convert.ToDouble(keyValues["max"]);
|
|
|
string layer = Convert.ToString(keyValues["layer"]);
|
|
|
string dir = keyValues["dir"].ToString();
|
|
|
evtResult = this.CreateFavorableArea(dir, filename, layer, min, max);
|
|
|
break;
|
|
|
case "MergeFavorableArea":
|
|
|
strToken = $"{keyValues["token"]}";
|
|
|
drawer = GlobalSession.GetData(strToken);
|
|
|
filename = Path.GetFileName(((WebDrawer)drawer).DrawFileName);
|
|
|
dir = keyValues["dir"].ToString();
|
|
|
strFileName = $"{keyValues["fileName"]}";
|
|
|
evtResult = this.MergeFavorableArea(dir, filename, strFileName);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
return evtResult;
|
|
|
}
|
|
|
|
|
|
public JsEvent ShowImg(string file = "", int w = 0, int h = 0, bool sendContent = false)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
Bitmap bmp = null;
|
|
|
|
|
|
if (w != 0 && h != 0)
|
|
|
{
|
|
|
this.Drawer.DrawerSize = new Size(w, h);
|
|
|
}
|
|
|
|
|
|
bmp = new Bitmap(this.Drawer.DrawerSize.Width, this.Drawer.DrawerSize.Height);
|
|
|
bmp.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
{
|
|
|
this.Drawer.OnPaint(g);
|
|
|
}
|
|
|
|
|
|
JsEvent jsEvent = this.CreateImgEvent(bmp, "", sendContent);
|
|
|
if (jsEvent != null)
|
|
|
{
|
|
|
jsEvent.Success = true;
|
|
|
}
|
|
|
return jsEvent;
|
|
|
}
|
|
|
public JsEvent ZoomIn(Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
this.Drawer.ZoomIn();
|
|
|
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
public JsEvent ZoomOut(Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
//this.drawer = GetCurrentDrawer();
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
this.Drawer.ZoomOut();
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
public JsEvent ViewAll(Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
this.Drawer.ViewAll();
|
|
|
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 移动浏览
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent ViewPan(Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
double dStartX = Convert.ToDouble(keyValues["startX"]);
|
|
|
double dStartY = Convert.ToDouble(keyValues["startY"]);
|
|
|
double dEndX = Convert.ToDouble(keyValues["endX"]);
|
|
|
double dEndY = Convert.ToDouble(keyValues["endY"]);
|
|
|
|
|
|
Bitmap bmp = null;
|
|
|
bmp = this.Drawer.ViewOperatorPan(dStartX, dStartY, dEndX, dEndY);
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 移动浏览
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent ViewWindow(Dictionary<string, object> keyValues)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
double dStartX = Convert.ToDouble(keyValues["startX"]);
|
|
|
double dStartY = Convert.ToDouble(keyValues["startY"]);
|
|
|
double dEndX = Convert.ToDouble(keyValues["endX"]);
|
|
|
double dEndY = Convert.ToDouble(keyValues["endY"]);
|
|
|
|
|
|
Bitmap bmp = this.Drawer.ViewOperatorWindow(dStartX, dStartY, dEndX, dEndY);
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
|
|
|
public JsEvent LButtonUp(double x, double y, int keyCode)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
Bitmap bmp = this.Drawer.LButtonUp(x, y, keyCode);
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 选择区域内图元函数,根据起始点和结束点坐标执行区域选择操作
|
|
|
/// </summary>
|
|
|
/// <param name="startX">选择区域的起始点X坐标</param>
|
|
|
/// <param name="startY">选择区域的起始点Y坐标</param>
|
|
|
/// <param name="endX">选择区域的结束点X坐标</param>
|
|
|
/// <param name="endY">选择区域的结束点Y坐标</param>
|
|
|
/// <param name="add">是否是添加状态</param>
|
|
|
/// <returns>返回JsEvent对象,表示选择区域操作产生的JavaScript事件</returns>
|
|
|
public JsEvent SelectRegion(double startX, double startY, double endX, double endY, bool add)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
Bitmap bmp = this.Drawer.SelectByRegion(startX, startY, endX, endY, add);
|
|
|
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取选择区域图元轮廓
|
|
|
/// </summary>
|
|
|
/// <returns>选择区域轮廓</returns>
|
|
|
public JsEvent SelectDragStart()
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
this.Drawer.ActiveTool = UCDraw.DrawToolType.Select;
|
|
|
using (Bitmap bmp = this.Drawer.SelectDragStart())
|
|
|
{
|
|
|
|
|
|
if (bmp == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
bmp.MakeTransparent(Color.White);
|
|
|
Point pt = this.Drawer.CacheImgLocation;
|
|
|
|
|
|
string strFile = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
strFile = Path.Combine(WebConfig.HtmlRoot, this.imageFile);
|
|
|
bmp.Save(strFile);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
string strEventName = "DragElement";
|
|
|
|
|
|
var responseEvent = new JsEvent(strEventName);
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>();
|
|
|
keyValues.Add("Data", this.imageFile);
|
|
|
keyValues.Add("ImgLeft", pt.X);
|
|
|
keyValues.Add("ImgTop", pt.Y);
|
|
|
keyValues.Add("ImgWidth", bmp.Width);
|
|
|
keyValues.Add("ImgHeight", bmp.Height);
|
|
|
responseEvent.Data = keyValues;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
}
|
|
|
public JsEvent SelectMouseMove(double x, double y)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
int result = 0;
|
|
|
|
|
|
result = this.Drawer.SelectMouseMove(x, y);
|
|
|
|
|
|
// Console.WriteLine($"MouseMove hanle:{result}");
|
|
|
JsEvent responseEvent = new JsEvent("SelectHandle")
|
|
|
{
|
|
|
Data = result,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
public JsEvent TranslateElements(double x, double y)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
Bitmap bmp = this.Drawer.TranslateElements(x, y);
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
catch (EmbedIO.WebSockets.WebSocketException ex)
|
|
|
{
|
|
|
//Console.WriteLine($"WebSocketException: {ex.Message}");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
//Console.WriteLine($"Exception: {ex.Message}");
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
public JsEvent SelectLButtonDown(double x, double y)
|
|
|
{
|
|
|
if (this.Drawer == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
using (Bitmap bmp = this.Drawer.LButtonDown(x, y))
|
|
|
{
|
|
|
if (bmp == null)
|
|
|
{ return null; }
|
|
|
bmp.MakeTransparent(Color.White);
|
|
|
Point pt = this.Drawer.CacheImgLocation;
|
|
|
|
|
|
string strFile = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
strFile = Path.Combine(WebConfig.HtmlRoot, this.imageFile);
|
|
|
bmp.Save(strFile);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Terminal.WriteLine($"SendImg: {ex.Message}");
|
|
|
return null;
|
|
|
}
|
|
|
string strEventName = "DragElement";
|
|
|
|
|
|
var responseEvent = new JsEvent(strEventName);
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>();
|
|
|
keyValues.Add("Data", this.imageFile);
|
|
|
keyValues.Add("ImgLeft", pt.X);
|
|
|
keyValues.Add("ImgTop", pt.Y);
|
|
|
keyValues.Add("ImgWidth", bmp.Width);
|
|
|
keyValues.Add("ImgHeight", bmp.Height);
|
|
|
responseEvent.Data = keyValues;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 选中对象
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent SelectMouseUp(double endX, double endY, int keyCode)
|
|
|
{
|
|
|
Bitmap bmp = this.Drawer.LButtonUp(endX, endY, keyCode);
|
|
|
return this.CreateImgEvent(bmp);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 井组克隆.
|
|
|
/// </summary>
|
|
|
/// <param name="elementID">The element i d.</param>
|
|
|
/// <returns>A JsEvent.</returns>
|
|
|
public JsEvent SelectWellGroupClone(long elementID = 0)
|
|
|
{
|
|
|
bool bSuccess = this.Drawer.SelectWellGroupClone(elementID);
|
|
|
if (bSuccess == true)
|
|
|
{
|
|
|
return this.Redraw();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获得选中的井组相关数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent SelectGetWellGroupData()
|
|
|
{
|
|
|
string strWellGroupData = this.Drawer.SelectGetWellGroupData();
|
|
|
var responseEvent = new JsEvent("WellGroupData");
|
|
|
responseEvent.Data = strWellGroupData;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置选中图元的属性
|
|
|
/// </summary>
|
|
|
/// <param name="propertyData"></param>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent SetSelectElementProperty(string propertyData)
|
|
|
{
|
|
|
bool success = this.Drawer.SetElementProperty(propertyData);
|
|
|
if (success == false)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
return this.Redraw();
|
|
|
}
|
|
|
public JsEvent GetSelectElementProperty()
|
|
|
{
|
|
|
string strElementData = string.Empty;
|
|
|
long lPosition = 0;
|
|
|
this.Drawer.GetSelectedElement(ref strElementData, ref lPosition);
|
|
|
var responseEvent = new JsEvent("ElementProperty");
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>();
|
|
|
keyValues.Add("ElementID", lPosition);
|
|
|
keyValues.Add("ElementData", strElementData);
|
|
|
responseEvent.Data = keyValues;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 保存图形.
|
|
|
/// </summary>
|
|
|
/// <returns>A JsEvent.</returns>
|
|
|
public JsEvent SaveFile()
|
|
|
{
|
|
|
bool bSuccess = this.Drawer.SaveFile();
|
|
|
var responseEvent = new JsEvent("Save");
|
|
|
responseEvent.Data = bSuccess;
|
|
|
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
private JsEvent CreateImgEvent(Bitmap bmp, string eventName = "", bool sendContent = false)
|
|
|
{
|
|
|
if (bmp == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
byte[] image = null;
|
|
|
string strFile = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
if (sendContent == false)
|
|
|
{
|
|
|
strFile = Path.Combine(WebConfig.HtmlRoot, this.imageFile);
|
|
|
string strPath = Path.GetDirectoryName(strFile);
|
|
|
if (!Directory.Exists(strPath))
|
|
|
{
|
|
|
Directory.CreateDirectory(strPath);
|
|
|
}
|
|
|
bmp.Save(strFile);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
image = ConvertBitmapToByteArray(bmp);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
//Console.WriteLine($"SendImg: {ex.Message}");
|
|
|
return null;
|
|
|
}
|
|
|
string strEventName = eventName;
|
|
|
if (string.IsNullOrEmpty(eventName))
|
|
|
{
|
|
|
strEventName = "Redraw";
|
|
|
}
|
|
|
var responseEvent = new JsEvent(strEventName);
|
|
|
if (sendContent)
|
|
|
{
|
|
|
string base64Header = $"data:image/png;base64,";
|
|
|
responseEvent.Data = (base64Header + Convert.ToBase64String(image));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
responseEvent.Data = this.imageFile;
|
|
|
}
|
|
|
return responseEvent;
|
|
|
}
|
|
|
public JsEvent Redraw()
|
|
|
{
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Refresh-刷新
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent ReFresh()
|
|
|
{
|
|
|
this.Drawer.Geo.ReloadFile();
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// ReCenter -全图居中
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent DrawCenter()
|
|
|
{
|
|
|
this.Drawer.Geo.ReloadFile();
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets 所有图元的数量.
|
|
|
/// </summary>
|
|
|
/// <returns>A JsEvent.</returns>
|
|
|
public JsEvent GetElementsCount()
|
|
|
{
|
|
|
var responseEvent = new JsEvent("GetElementsCount");
|
|
|
int nCount = this.Drawer.Geo.GetElementCount();
|
|
|
responseEvent.Data = nCount;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
#region 图层管理
|
|
|
/// <summary>
|
|
|
/// 获得图层数据.获取层位字符串(常规格式)
|
|
|
/// </summary>
|
|
|
/// <returns>A Task.</returns>
|
|
|
public JsEvent GetLayers()
|
|
|
{
|
|
|
var responseEvent = new JsEvent("ReloadLayer")
|
|
|
{
|
|
|
Data = this.Drawer.LayerTree.Layers
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取图层,获得JSON结构化图层数据.
|
|
|
/// </summary>
|
|
|
/// <returns>A Task.</returns>
|
|
|
public JsEvent GetLayersJson()
|
|
|
{
|
|
|
var responseEvent = new JsEvent("ReloadLayer")
|
|
|
{
|
|
|
Data = this.Drawer.LayerTree.LayersJson
|
|
|
};
|
|
|
// responseEvent.Data = this.Drawer.LayerTree.LayersJson;
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the layers status.
|
|
|
/// </summary>
|
|
|
/// <param name="layersStatus">The layers status.
|
|
|
/// VIEW_EDIT = 10,
|
|
|
/// VIEW_NOT_EDIT = 11,
|
|
|
/// NOT_VIEW_NOT_EDIT = 12</param>
|
|
|
/// <returns>A Task.</returns>
|
|
|
public JsEvent SetLayersStatus(string layersStatus)
|
|
|
{
|
|
|
GeoLayerTree layerTree = this.Drawer?.LayerTree;
|
|
|
if (layerTree.SetLayersStatus(layersStatus))
|
|
|
{
|
|
|
return this.ShowImg();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 删除图层
|
|
|
/// </summary>
|
|
|
/// <param name="layers"></param>
|
|
|
/// <param name="withSubLayer"></param>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent DeleteLayers(string layers, bool withSubLayer)
|
|
|
{
|
|
|
var layerArray = layers.Split(new string[] { Environment.NewLine, "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
int nCount = layerArray.Length;
|
|
|
if (nCount == 0)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
for (int i = 0; i < nCount; i++)
|
|
|
{
|
|
|
int nIndexFind = layerArray[i].IndexOf("Layer:\\", 0, StringComparison.CurrentCultureIgnoreCase);
|
|
|
if (nIndexFind >= 0)
|
|
|
{
|
|
|
layerArray[i] = layerArray[i].Remove(0, 7 + nIndexFind);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this.Drawer.DeleteLayers(layerArray, withSubLayer);
|
|
|
return this.ShowImg();
|
|
|
//var responseEvent = new JsEvent("DeleteLayers")
|
|
|
//{
|
|
|
// Data = string.Empty,
|
|
|
//};
|
|
|
//await SendTargetedEvent(socketContex, responseEvent).ConfigureAwait(true);
|
|
|
//await this.ShowImgAsync();
|
|
|
}
|
|
|
public JsEvent ClearAll(bool needUndo)
|
|
|
{
|
|
|
bool bSuccess = this.Drawer.ClearAll(needUndo);
|
|
|
|
|
|
var responseEvent = new JsEvent("ClearAll")
|
|
|
{
|
|
|
Data = bSuccess,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 合并图件
|
|
|
/// <summary>
|
|
|
/// 合并图件
|
|
|
/// </summary>
|
|
|
/// <param name="fileName">图件地址</param>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent MergeFile(string fileName)
|
|
|
{
|
|
|
DrawerConfig.StartupPath = WebConfig.StartupPath;
|
|
|
//string strServerPath = WebConfig.MapDirectory;// 获取配置文件中的MapDirectory目录
|
|
|
// string strMapFile = Path.Combine(strServerPath, fileName);
|
|
|
if (!File.Exists(fileName))
|
|
|
{
|
|
|
var responseEventError = new JsEvent("MergeFile")
|
|
|
{
|
|
|
Data = false,
|
|
|
};
|
|
|
return responseEventError;
|
|
|
}
|
|
|
bool isSuccess = this.Drawer.MergeFile(fileName);
|
|
|
var responseEvent = new JsEvent("MergeFile")
|
|
|
{
|
|
|
Data = isSuccess,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 数据操作
|
|
|
/// <summary>
|
|
|
/// 添加数据.
|
|
|
/// </summary>
|
|
|
/// <param name="data">The data.</param>
|
|
|
/// <returns>A Task.</returns>
|
|
|
public JsEvent AddBufferData(string data)
|
|
|
{
|
|
|
int nResult = this.Drawer.AddBufferData(data);
|
|
|
|
|
|
var responseEvent = new JsEvent("AddBufferData")
|
|
|
{
|
|
|
Data = nResult,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
public JsEvent InsertDataBottom(string data, string newLayer, bool createBlock)
|
|
|
{
|
|
|
bool nResult = false;
|
|
|
if (createBlock)
|
|
|
{
|
|
|
string strData = $"Layer M {newLayer}{Environment.NewLine}Block{Environment.NewLine}{data}{Environment.NewLine}EndBlock{Environment.NewLine}";
|
|
|
nResult = this.Drawer.InsertDataBottom(data, "");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
nResult = this.Drawer.InsertDataBottom(data, newLayer);
|
|
|
}
|
|
|
var responseEvent = new JsEvent("AddBasicDraw")
|
|
|
{
|
|
|
Data = nResult,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 坐标工具
|
|
|
/// <summary>
|
|
|
/// 屏幕坐标转换为实际坐标.
|
|
|
/// </summary>
|
|
|
/// <param name="startX">The start x.</param>
|
|
|
/// <param name="endX"></param>
|
|
|
/// <param name="startY">The start y.</param>
|
|
|
/// <param name="endY"></param>
|
|
|
/// <returns>A Task.</returns>
|
|
|
public JsEvent QueryRangeScreen2RealX(double startX, double endX, double startY, double endY)
|
|
|
{
|
|
|
double dRectLeft = 0, dRectRight = 0, dRectTop = 0, dRectBottom = 0;
|
|
|
this.Drawer.Geo.GetScreenReal((int)startX, (int)startY, (int)endX, (int)endY
|
|
|
, ref dRectLeft, ref dRectTop, ref dRectRight, ref dRectBottom);
|
|
|
|
|
|
Dictionary<string, object> keyValues = new Dictionary<string, object>();
|
|
|
keyValues.Add("left", dRectLeft);
|
|
|
keyValues.Add("bottom", dRectBottom);
|
|
|
keyValues.Add("right", dRectRight);
|
|
|
keyValues.Add("top", dRectTop);
|
|
|
var responseEvent = new JsEvent("MapRangeReal")
|
|
|
{
|
|
|
Data = keyValues,
|
|
|
};
|
|
|
return responseEvent;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建有利区
|
|
|
/// </summary>
|
|
|
/// <param name="dir">图件存储目录</param>
|
|
|
/// <param name="layerName">将创建有利区的图层,如果不存在,则会自动创建图层</param>
|
|
|
/// <param name="sourceFileName">原文件名,不带路径</param>
|
|
|
/// <param name="zMin">最小 z 值</param>
|
|
|
/// <param name="zMax">最大 z 值</param>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent CreateFavorableArea(string dir, string sourceFileName, string layerName, double zMin, double zMax)
|
|
|
{
|
|
|
var drawerData = new DrawerData();
|
|
|
this.Drawer.Geo.CreateFavorableArea(drawerData.pXy, "有利区", zMin, zMax);
|
|
|
|
|
|
string filename = $"{sourceFileName}-有利区-{DateTime.Now:yyyyMMddHHmmssff}.kev";
|
|
|
string strMapFile = Path.Combine(dir, filename);
|
|
|
drawerData.SaveAs(strMapFile);
|
|
|
|
|
|
var keyValues = new Dictionary<string, object>()
|
|
|
{
|
|
|
{ "filename", filename },
|
|
|
};
|
|
|
|
|
|
return new JsEvent("CreateFavorableArea")
|
|
|
{
|
|
|
Data = keyValues,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 合并有利区底图
|
|
|
/// </summary>
|
|
|
/// <param name="dir">目录</param>
|
|
|
/// <param name="sourceFileName">原图文件</param>
|
|
|
/// <param name="bottomFileName">底层</param>
|
|
|
/// <returns></returns>
|
|
|
public JsEvent MergeFavorableArea(string dir, string sourceFileName, string bottomFileName)
|
|
|
{
|
|
|
string filename = $"{Path.GetFileNameWithoutExtension(sourceFileName)}-有利区-{DateTime.Now:HHmmssff}-带底图.kev";
|
|
|
string sourcePath = Path.Combine(dir, sourceFileName);
|
|
|
string targetPath = Path.Combine(dir, filename);
|
|
|
string bottomPath = Path.Combine(dir, bottomFileName);
|
|
|
string type = "MergeFavorableArea";
|
|
|
|
|
|
var drawerData = new DrawerData();
|
|
|
if (!drawerData.OpenFile(sourcePath))
|
|
|
{
|
|
|
return this.ErrorEvent(type, $"打开原文件失败,原文件路径: {sourcePath}");
|
|
|
}
|
|
|
|
|
|
if (!drawerData.MergeFile(bottomPath))
|
|
|
{
|
|
|
return this.ErrorEvent(type, $"合并文件失败,合并文件路径: {bottomPath}");
|
|
|
}
|
|
|
|
|
|
if (!drawerData.SaveAs(targetPath))
|
|
|
{
|
|
|
return this.ErrorEvent(type, $"保存文件失败,保存文件路径: {targetPath}");
|
|
|
}
|
|
|
|
|
|
return new JsEvent(type)
|
|
|
{
|
|
|
Success = true,
|
|
|
Data = new Dictionary<string, object>()
|
|
|
{
|
|
|
{ "filename", $"{Path.GetFileName(targetPath)}" },
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
private JsEvent ErrorEvent(string type, string message)
|
|
|
{
|
|
|
return new JsEvent(type)
|
|
|
{
|
|
|
Success = false,
|
|
|
Data = new Dictionary<string, object>()
|
|
|
{
|
|
|
{ "error", message },
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
/// <summary>
|
|
|
/// 创建井组编辑模型
|
|
|
/// </summary>
|
|
|
/// <param name="wellGroupData">井组数据</param>
|
|
|
/// <param name="w">默认显示宽度</param>
|
|
|
/// <param name="h">默认显示高度</param>
|
|
|
/// <param name="context">网络请求上下文</param>
|
|
|
/// <param name="token">模型的Token</param>
|
|
|
/// <param name="parentToken">父图形的Token</param>
|
|
|
/// <returns></returns>
|
|
|
public async static Task<string> CreateWellGroupDrawerAsync(string wellGroupData, int w, int h, IWebSocketContext context, string token, string parentToken)
|
|
|
{
|
|
|
WebDrawer drawer = (WebDrawer)GlobalSession.GetData(parentToken);
|
|
|
WellGroupDrawer wellGroupDrawer = new WellGroupDrawer(wellGroupData, w, h, drawer.Geo);
|
|
|
string strToken = wellGroupDrawer.Geo.GetDrawerXy().ToInt64().ToString();
|
|
|
if (!string.IsNullOrEmpty(strToken))
|
|
|
{
|
|
|
GlobalSession.StoreData(token, wellGroupDrawer);
|
|
|
GlobalSession.StoreData($"Lock_{token}", new SemaphoreSlim(1, 1));
|
|
|
}
|
|
|
Logger.Info("CreateWellGroupDrawerAsync:" + token);
|
|
|
await Task.CompletedTask;
|
|
|
return strToken;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Creates the drawer.
|
|
|
/// </summary>
|
|
|
/// <param name="file">The file.</param>
|
|
|
/// <param name="w">The w.</param>
|
|
|
/// <param name="h">The h.</param>
|
|
|
/// <param name="context"></param>
|
|
|
public async static Task<string> CreateDrawerAsync(string file, int w, int h, IWebSocketContext context, string token)
|
|
|
{
|
|
|
DrawerConfig.StartupPath = WebConfig.StartupPath;
|
|
|
string strServerPath = WebConfig.MapDirectory;
|
|
|
WebDrawer drawer = new WebDrawer(w, h);
|
|
|
string strMapFile = Path.Combine(strServerPath, file);
|
|
|
//ImageFile = Path.Combine(strServerPath, "K1.png");
|
|
|
string strToken = string.Empty;
|
|
|
await Task.Run(() =>
|
|
|
{
|
|
|
GeoSigmaXY geo = drawer.OpenFile(strMapFile);
|
|
|
if (geo != null)
|
|
|
{
|
|
|
strToken = geo.GetDrawerXy().ToInt64().ToString();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strToken))
|
|
|
{
|
|
|
GlobalSession.StoreData(token, drawer);
|
|
|
//Context.Session["DrawerFile"] = file;
|
|
|
GlobalSession.StoreData($"Lock_{token}", new SemaphoreSlim(1, 1));
|
|
|
}
|
|
|
Logger.Info("CreateDrawerAsync:" + token);
|
|
|
return strToken;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 资源销毁
|
|
|
/// </summary>
|
|
|
public static async Task CloseDrawerAsync(string token, IWebSocketContext context)
|
|
|
{
|
|
|
SemaphoreSlim drawerLock = (SemaphoreSlim)GlobalSession.GetData($"Lock_{token}");
|
|
|
if (drawerLock == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
// 确保在销毁前没有其他线程访问Drawer对象
|
|
|
await drawerLock.WaitAsync();
|
|
|
try
|
|
|
{
|
|
|
WebDrawer drawer = (WebDrawer)GlobalSession.GetData(token);
|
|
|
|
|
|
if (drawer != null)
|
|
|
{
|
|
|
drawer.Dispose(); // 释放资源
|
|
|
|
|
|
GlobalSession.TryRemove(token, out object objDrawer); // 从Session中移除Drawer对象
|
|
|
GlobalSession.TryRemove($"Lock_{token}", out object objLock); // 从Session中移除锁对象
|
|
|
|
|
|
drawer = null;
|
|
|
}
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
drawerLock.Release();
|
|
|
drawerLock.Dispose(); // 释放 SemaphoreSlim 资源
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Converts the bitmap to byte array.
|
|
|
/// </summary>
|
|
|
/// <param name="bitmap">The bitmap.</param>
|
|
|
/// <returns>An array of byte.</returns>
|
|
|
public static byte[] ConvertBitmapToByteArray(Bitmap bitmap)
|
|
|
{
|
|
|
if (bitmap == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
|
{
|
|
|
// 选择图像格式,可以是Png、Jpeg等
|
|
|
bitmap.Save(memoryStream, ImageFormat.Png);
|
|
|
return memoryStream.ToArray();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|