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/UCDraw/GeoSigmaDrawLib/GeoSigmaWellPoleXY.cs

410 lines
15 KiB
C#

1 month ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
using System.Xml;
using System.Collections.Generic;
namespace GeoSigmaDrawLib
{
public class GeoSigmaWellPoleXY : GeoSigmaXY
{
//public static void InvalidateWnd()
//{
// Console.WriteLine($"数据更新: ");
//}
//private static GeoSigmaLib.InvalidateWndCallback s_wndCallback = InvalidateWnd;
public struct newWellInfo
{
public string wellName;
public float welltop;
public float wellbottom;
public float ratio;
public string templateFilePath;
}
public IntPtr GetView()
{
return pView;
}
public struct WellObjInfo
{
public UInt64 objHandle;
public int type;
public int mtype; //对象分类
public string cTypeName; //对象类型中文名称
public string eTypeName; //对象类型英文名称
}
public enum eWellExtType
{
TypeInvalidate = -1,
Track_Normal, //普通道
Track_Group, //组合道
Track_Depth, //深度道
Track_Curve, //曲线道
Track_Discrete, //散点道
Track_Picture, //图片道
Track_Text, //文字道
Track_Symbol, //符号道
Track_Lith, //岩性道
Track_Sample, //岩样道
Track_CorePosition, //取芯位置道
Track_OilTest, //试油道
Track_Result, //解释结果道
Track_Stratum, //地层道
Track_SandLayer, //砂层组道
Track_OilLayerGroup, //油层组道
Track_ProduceLayer, //产层段道
Track_TestExtraction, //试采数据道
Track_ReserveUnit, //储量单元道
Track_StandardLayer, //标准层道
Track_Shot, //射孔道
Track_CementingQuality, //固井质量道
Track_CementingQualityCurve, //固井质量曲线道
Track_ProducedFluidSection, //产液剖面道
Track_WaterAbsorptionSection, //吸水剖面道
Track_FaultPoint, //断点道
Track_WaveShape, //波形道.先废弃不用
Track_ValidThick, //有效厚度道
Track_Bury, //埋深道
Track_Facies, //沉积相道
Track_CoreWell, //井壁取芯道
KEP_WELL = 1200,
KEP_TRACK =1205,
KEP_LITH = 1211,
KEP_RESULT = 1218,
KEP_SYMBOL = 1222,
KEP_SAMPLE = 1223,
KEP_CORING = 1225,
KEP_TEXT = 1232,
KEP_LAYERGROUP = 1234,
KEP_OILTEST = 1235,
KEP_IMAGE = 1236,
KEP_FAULTPOINT = 1237,
KEP_TESTEXTRACTION = 1238,
KEP_TRACKINDATA = 1599,
};
public struct WellTableColumnInfo
{
public string tabname;
public string tabnameCH;
public string[] colNames;
public string[] colNamesCH;
}
public class WellTableColumanMgr
{
public Dictionary<string, WellTableColumnInfo> mTableColInfos;
public WellTableColumanMgr()
{
mTableColInfos = new Dictionary<string, WellTableColumnInfo>();
}
public bool hasTable(string tabname)
{
return mTableColInfos.ContainsKey(tabname);
}
public string getTableCHName(string tablename)
{
string chname = "";
if(mTableColInfos.ContainsKey(tablename))
{
chname = mTableColInfos[tablename].tabnameCH;
}
return chname;
}
public void getTableColumnNames(string tablename, ref string[] colnames)
{
if (mTableColInfos.ContainsKey(tablename))
{
colnames = new string[mTableColInfos[tablename].colNames.Length];
for (int i = 0; i < colnames.Length; i++)
colnames[i] = mTableColInfos[tablename].colNames[i];
}
}
public void getTableColumnCHNames(string tablename, ref string[] colnames)
{
if (mTableColInfos.ContainsKey(tablename))
{
colnames = new string[mTableColInfos[tablename].colNamesCH.Length];
for (int i = 0; i < colnames.Length; i++)
colnames[i] = mTableColInfos[tablename].colNamesCH[i];
}
}
public string getColumnCHName(string tablename,string colname)
{
string chname = "";
if (mTableColInfos.ContainsKey(tablename))
{
WellTableColumnInfo colinfos = mTableColInfos[tablename];
for (int i = 0; i < colinfos.colNames.Length; i++)
{
if (colinfos.colNames[i] == colname)
chname = colinfos.colNamesCH[i];
}
}
return chname;
}
public void GetTableColumnCHNames(string tableName, string[]colnamesEN,ref string[]colnamesCH)
{
colnamesCH = new string[colnamesEN.Length];
if (mTableColInfos.ContainsKey(tableName))
{
for(int i = 0; i < colnamesEN.Length; i++)
{
colnamesCH[i] = getColumnCHName(tableName, colnamesEN[i]);
}
}
}
}
public static bool bReadParams = false;
public static WellTableColumanMgr mWellTableInfos;
void ReadParamsFile()
{
if (GeoSigmaWellPoleXY.bReadParams == false)
{
GeoSigmaWellPoleXY.bReadParams = true;
GeoSigmaWellPoleXY.mWellTableInfos = new WellTableColumanMgr();
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string filePath = appDir + "WellDataConfig.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNode root = xmlDoc.DocumentElement;
if (root != null)
{
XmlNodeList nodeList = root.SelectNodes("WellTrackData/Table");
foreach (XmlNode tnode in nodeList)
{
string tabname = tnode.Attributes["ID"]?.Value;
string tabnameCH = tnode.Attributes["Name"]?.Value;
WellTableColumnInfo tcolInfo = new WellTableColumnInfo();
tcolInfo.tabname = tabname;
tcolInfo.tabnameCH = tabnameCH;
XmlNodeList cnodeList = tnode.ChildNodes;
tcolInfo.colNames = new string[cnodeList.Count];
tcolInfo.colNamesCH = new string[cnodeList.Count];
int i = 0;
foreach (XmlNode cnode in cnodeList)
{
string colId = cnode.Attributes["ID"]?.Value;
string colChName = cnode.Attributes["Name"]?.Value;
tcolInfo.colNames[i] = colId;
tcolInfo.colNamesCH[i] = colChName;
i++;
}
GeoSigmaWellPoleXY.mWellTableInfos.mTableColInfos[tabname] = tcolInfo;
}
}
}
}
public GeoSigmaWellPoleXY(GeoSigmaXY.eViewType vType = GeoSigmaXY.eViewType.wellpole): base(vType)
{
// mViewType = GeoSigmaXY.eViewType.wellpole;
//pView = GeoSigmaLib.CreateWellPoleView();
// GeoSigmaLib.RegisterCallback(pView, s_wndCallback);
ReadParamsFile();
}
public IntPtr CreateNewWell(string wellName, double top, double bottom, double ratio, string templatefile)
{
return GeoSigmaLib.CreateNewWell(pView, wellName, top, bottom, ratio, templatefile);
}
public void ViewExtendWidth()
{
GeoSigmaLib.ViewExtendWidth(pView);
}
public void ViewExtendCenter()
{
GeoSigmaLib.ViewExtendCenter(pView);
}
public int ViewSetItemForSelectedElement( int x, int y)
{
return GeoSigmaLib.ViewSetItemForSelectedElement(pView, x, y);
}
public int SelectWellPoleSetCursor(int mouseX, int mouseY)
{
int nHandle = -1;
if (pView == null)
return -1;
GeoSigmaLib.SelectWellPoleSetCursor(pView, mouseX, mouseY, ref nHandle);
return nHandle;
}
public void SetWellPoleViewOperationKind(ViewOperationKind kind)
{
GeoSigmaLib.SetWellPoleViewOperationKind(pView,kind);
}
public void InitWellPosition(int lrEdge)
{
GeoSigmaLib.InitWellPosition(pView, lrEdge);
}
public bool IsLockWellHead()
{
bool b = GeoSigmaLib.IsLockWellHead(pView);
Console.WriteLine($"is lock wellHead= {b}");
return b;
}
public void SetLockWellHead(bool block)
{
GeoSigmaLib.SetLockWellHead(pView, block);
}
public void MouseWheelForLockWellHead(int nFlags, int zDelta, int x, int y)
{
GeoSigmaLib.MouseWheelForLockWellHead(pView, nFlags, zDelta, x, y);
}
public void ScrollVForLockWellHead( int nFlags, int scrollValue, int pageSize, int lineSize, int scrollMin, int scrollMax)
{
GeoSigmaLib.ScrollVForLockWellHead(pView, nFlags, scrollValue, pageSize, lineSize, scrollMin, scrollMax);
}
public void SetScrollBarVRangeForLockWellHead( ref int vrange, ref int page, ref int value)
{
GeoSigmaLib.SetScrollBarVRangeForLockWellHead(pView, ref vrange, ref page, ref value);
}
public bool GetSelectWellObject( ref int type, ref int mtype, ref UInt64 objHandle)
{
return GeoSigmaLib.GetSelectWellObject(pView, ref type, ref mtype, ref objHandle);
}
public int GetWellTrackTypeInfo(ref int[]typeIdArr, ref string[] typeNameArr)
{
IntPtr typeBuff, typeStrBuf;
typeBuff = IntPtr.Zero;
typeStrBuf = IntPtr.Zero;
int typeBuffLen, typeStrLen;
typeBuffLen = typeStrLen = 0;
int typeNum = GeoSigmaLib.GetWellTrackTypeInfo(ref typeBuff, ref typeBuffLen, ref typeStrBuf, ref typeStrLen);
if(typeNum>0)
{
typeIdArr = new int[typeNum];
Marshal.Copy(typeBuff, typeIdArr, 0, typeNum);
GeoSigmaLib.FreeByteArray(typeBuff);
string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen);
typeNameArr = strType.Split('|');
GeoSigmaLib.FreeByteArray(typeStrBuf);
}
return typeNum;
}
public bool DeleteSelectedWellObject()
{
return GeoSigmaLib.DeleteSelectedWellObject(pView);
}
public bool AddTrackAfterSelectedWellObject( int[] trackTypes, int trackNum)
{
return GeoSigmaLib.AddTrackAfterSelectedWellObject(pView ,trackTypes, trackNum);
}
public bool SelectedTrackCombineLeftTrack()
{
return GeoSigmaLib.SelectedTrackCombineLeftTrack(pView);
}
public bool SelectedTrackCombineRightTrack()
{
return GeoSigmaLib.SelectedTrackCombineRightTrack(pView);
}
public bool GetSelectedWell( ref UInt64 wellHandle)
{
return GeoSigmaLib.GetSelectedWell(pView, ref wellHandle);
}
public bool GetWellTrackDataJson( UInt64 trackHandle, ref string jsonStr)
{
IntPtr jsonStrBuff = IntPtr.Zero;
int strLen = 0;
bool b = GeoSigmaLib.GetWellTrackDataJson(pView, trackHandle, ref jsonStrBuff, ref strLen);
if(b)
{
//jsonStr = Marshal.PtrToStringAnsi(jsonStrBuff, strLen);
byte[] bytes = new byte[strLen];
Marshal.Copy(jsonStrBuff, bytes, 0, strLen);
jsonStr = Encoding.UTF8.GetString(bytes);
GeoSigmaLib.FreeByteArray(jsonStrBuff);
}
return b;
}
public void GetWellTrackData(UInt64 trackHandle, ref string dataType, ref string[]colName, ref string[,]strData)
{
string jsonStr = "";
GetWellTrackDataJson(trackHandle , ref jsonStr);
JObject json = JObject.Parse(jsonStr);
dataType = (string)json["dataType"];
JArray colNames = (JArray)json["columnName"];
colName = new string[colNames.Count()];
int ii = 0;
foreach (string jitem in colNames)
{
//JObject j = (JObject)jitem;
colName[ii] = jitem; // j.ToString();
ii++;
}
ii = 0;
JArray datas = (JArray)json["data"];
strData = new string[datas.Count(), colNames.Count()];
foreach(var jitem in datas)
{
JArray jarr = (JArray)jitem;
int jj = 0;
foreach (string jstr in jarr)
{
strData[ii, jj] = jstr; // Encoding.Unicode.GetString(unicodebytes); // Encoding.UTF8.GetString(utf8byts);
jj++;
}
ii++;
}
}
public bool SetWellTrackDataJson(UInt64 trackHandle, byte[]jsonbuf, int datalen)
{
bool b = GeoSigmaLib.SetWellTrackDataJson(pView , trackHandle, jsonbuf,datalen);
return b;
}
public bool SetPictureInWellTrack(UInt64 tHandle, string filePath)
{
return GeoSigmaLib.SetPictureInWellTrack(pView,tHandle, filePath);
}
}
}