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; using System.Drawing; namespace GeoSigmaDrawLib { public class GeoSigmaWellPoleXY : GeoSigmaXY { //public static void InvalidateWnd() //{ // Console.WriteLine($"数据更新: "); //} //private static GeoSigmaLib.InvalidateWndCallback s_wndCallback = InvalidateWnd; public class WellBaseInfo { public WellBaseInfo() { wellName = ""; welltop = wellbottom = 0; ratio = 500; } public string wellName; public float welltop; public float wellbottom; public float ratio; } public class NewWellInfo : WellBaseInfo { public string templateFilePath; public int tid; // =-1表示不是工区井。 } //public struct newWellInfo //{ // public string wellName; // public float welltop; // public float wellbottom; // public float ratio; // public string templateFilePath; // public int tid; // =-1表示不是工区井。 //} public IntPtr GetView() { return pView; } public struct WellObjInfo { public UInt64 wellHandle; 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_FluidProducingProfileTrace, //产液剖面道 Track_WaterInjectionTrace, //吸水剖面道 Track_FaultPoint, //断点道 Track_WaveShape, //波形道.先废弃不用 Track_ValidThick, //有效厚度道 Track_Bury, //埋深道 Track_Facies, //沉积相道 Track_CoreWell, //井壁取芯道 Track_Block, //方波曲线道 Track_Trajectory, //斜井轨迹道 Track_VdlImage, //变密度道 Track_WaveCurve, //波形道 Track_SeisSection, //地震剖面道 Track_Sandstone , //砂岩道 Track_InnerLayer, //夹层道 Track_Cycle, Track_CommonData, KEP_WELL = 1200, KEP_TRACK = 1205, KEP_LITH = 1211, KEP_RESULT = 1218, KEP_COREWELL = 1219, KEP_TEXTRANGE = 1221, KEP_SYMBOL = 1222, KEP_SAMPLE = 1223, KEP_CORING = 1225, KEP_SHOT = 1226,//射孔符号 KEP_TEXT = 1232, KEP_LAYERGROUP = 1234, KEP_OILTEST = 1235, KEP_IMAGE = 1236, KEP_FAULTPOINT = 1237, KEP_TESTEXTRACTION = 1238, KEP_SECTIONBEND = 1306, KEP_WELLSECTION = 1307, KEP_SECTIONFAULT = 1308, KEP_INTRACK_SANDSTONE = 1314, KEP_INTRACK_INNERLAYER = 1315, KEP_INTRACK_CYCLE = 1316, KEP_INTRACK_FACIES = 1317, KEP_INTRACK_COMMONDATA = 1318, KEP_INTRACK_WATERINJECTIONPROFILE = 1319, KEP_INTRACK_FLUIDPRODUCINGPROFILE = 1320, KEP_TRACKINDATA = 1599, }; public struct WellTableColumnInfo { public string tabname; public string tabnameCH; public string[] colNames; public string[] colNamesCH; } public class WellTableColumanMgr { public Dictionary mTableColInfos; public WellTableColumanMgr() { mTableColInfos = new Dictionary(); } 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; public static 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 static bool GetWellBaseObjectParent(UInt64 objHandle, ref UInt64 ParentObj) { return GeoSigmaLib.GetWellBaseObjectParent(objHandle, ref ParentObj); } public GeoSigmaWellPoleXY(GeoSigmaXY.eViewType vType = GeoSigmaXY.eViewType.wellpole) : base(vType) { // mViewType = GeoSigmaXY.eViewType.wellpole; //pView = GeoSigmaLib.CreateWellPoleView(); // GeoSigmaLib.RegisterCallback(pView, s_wndCallback); ReadParamsFile(); } public int ViewSetItemForSelectedElement(int x, int y) { return GeoSigmaLib.ViewSetItemForSelectedElement(pView, x, y); } 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 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); } static 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 , out UInt64[] newtrackHands, out int[] newttypes) { newtrackHands = new UInt64[0]; newttypes = new int[0]; IntPtr newtrackhandBuf; newtrackhandBuf = IntPtr.Zero; IntPtr newttypeBuff; newttypeBuff = IntPtr.Zero; int newtracknum = 0; bool b = false; b = GeoSigmaLib.AddTrackAfterSelectedWellObject(pView, trackTypes, trackNum, ref newtrackhandBuf,ref newttypeBuff,ref newtracknum); if(b && newtracknum > 0) { newtrackHands = new UInt64[newtracknum]; for(int i = 0; i< newtracknum; i++) { newtrackHands[i] = (UInt64)Marshal.ReadInt64(newtrackhandBuf, i * sizeof(UInt64)); } GeoSigmaLib.FreeByteArray(newtrackhandBuf); newttypes = new int[trackNum]; for (int i = 0; i < trackNum; i++) { newttypes[i] = (int)Marshal.ReadInt32(newttypeBuff, i * sizeof(int)); } GeoSigmaLib.FreeByteArray(newttypeBuff); } return b; } 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, string jsonStr) { if (jsonStr == "") return false; if (jsonStr == null) return false; byte[] databytes = Encoding.UTF8.GetBytes(jsonStr); bool b = SetWellTrackDataJson(trackHandle, databytes, databytes.Length); return b; } 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); } public bool GetWellObjectAttributesJson(UInt64 objHandle, int type, int ttype, ref string strJson) { IntPtr jsonStrBuff = IntPtr.Zero; int strLen = 0; bool b = GeoSigmaLib.GetWellObjectAttributesJson(pView, objHandle, type, ttype, ref jsonStrBuff, ref strLen); if (b) { byte[] bytes = new byte[strLen]; Marshal.Copy(jsonStrBuff, bytes, 0, strLen); strJson = Encoding.UTF8.GetString(bytes); GeoSigmaLib.FreeByteArray(jsonStrBuff); } return b; } public bool SetWellObjectAttributesJson(UInt64 objHandle, int type, int ttype, byte[] jsonbuf, int datalen) { bool b = GeoSigmaLib.SetWellObjectAttributesJson(pView, objHandle, type, ttype, jsonbuf, datalen); return b; } public static bool GetSymbolNamesForResult(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForResult(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForResult(string symbolName, IntPtr hdcMem, int width, int height) { bool b = GeoSigmaLib.GetDrawSymbolForResult(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithology(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithology(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithology(string symbolName, IntPtr hdcMem, int width, int height) { bool b = GeoSigmaLib.GetDrawSymbolForLithology(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithologyColor(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithologyColor(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithologyColor(string symbolName, IntPtr hdcMem, int width, int height) { bool b = GeoSigmaLib.GetDrawSymbolForLithologyColor(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithOilGas(out string[] NamesArr) { //含油气性 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithOilGas(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithOilGas(string symbolName, IntPtr hdcMem, int width, int height) { //含油气性 bool b = GeoSigmaLib.GetDrawSymbolForLithOilGas(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithContent(out string[] NamesArr) { //含有物 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithContent(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithContent(string symbolName, IntPtr hdcMem, int width, int height) { //含含有物 bool b = GeoSigmaLib.GetDrawSymbolForLithContent(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithFront(out string[] NamesArr) { //岩性前缀 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithFront(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithFront(string symbolName, IntPtr hdcMem, int width, int height) { //岩性前缀 bool b = GeoSigmaLib.GetDrawSymbolForLithFront(symbolName, hdcMem, width, height); return b; } public static bool GetSymbolNamesForLithConstitution(out string[] NamesArr) { //岩性构造 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetSymbolNamesForLithConstitution(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolForLithConstitution(string symbolName, IntPtr hdcMem, int width, int height) { //岩性构造 bool b = GeoSigmaLib.GetDrawSymbolForLithConstitution(symbolName, hdcMem, width, height); return b; } public static bool GetNormalSymbolNames(out string[] NamesArr) { //符号道符号 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetNormalSymbolNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawNormalSymbol(string symbolName, IntPtr hdcMem, int width, int height) { //符号道符号 bool b = GeoSigmaLib.GetDrawNormalSymbol(symbolName, hdcMem, width, height); return b; } /// /// 曲线填充符号 /// /// 名称 /// 成功/失败 public static bool GetCurveFillSymbolNames(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetCurveFillSymbolNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawCurveFillSymbol(string symbolName, IntPtr hdcMem, int width, int height) { //曲线填充符号 bool b = GeoSigmaLib.GetDrawCurveFillSymbol(symbolName, hdcMem, width, height); return b; } public bool GetWellAllCurveNames(UInt64 wellHandle, out string[] NamesArr) { //所有曲线名称 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellAllCurveNames(pView, wellHandle, ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public bool GetWellAllDiscreteNames(UInt64 wellHandle, out string[] NamesArr) { //所有散点曲线名称 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellAllDiscreteNames(pView, wellHandle, ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public bool GetWellFrameLineNames( out string[] NamesArr) { //所有散点曲线名称 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellFrameLineNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetWellCurveLineNames(out string[] NamesArr) { //所有散点曲线名称 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellCurveLineNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawWellCurveLine(string lineName, IntPtr hdcMem, int width, int height) { // bool b = GeoSigmaLib.GetDrawWellCurveLine(lineName, hdcMem, width, height); return b; } public bool GetDrawWellFrameLine(string lineName, IntPtr hdcMem, int width, int height) { // bool b = GeoSigmaLib.GetDrawWellFrameLine(lineName, hdcMem, width, height); return b; } public bool GetWellObjectAttributesXml(UInt64 objHandle, int type, int ttype, ref string strResult) { IntPtr StrBuff = IntPtr.Zero; int strLen = 0; bool b = GeoSigmaLib.GetWellObjectAttributesXml( objHandle, type, ttype, ref StrBuff, ref strLen); if (b) { byte[] bytes = new byte[strLen]; Marshal.Copy(StrBuff, bytes, 0, strLen); Encoding gb2312 = Encoding.GetEncoding("GB2312"); strResult = gb2312.GetString(bytes); GeoSigmaLib.FreeByteArray(StrBuff); } return b; } public bool SetWellObjectAttributesXml(UInt64 objHandle, int type, int ttype, string strXml) // byte[] jsonbuf, int datalen) { if (strXml == null) { return false; } Encoding gb2312 = Encoding.GetEncoding("GB2312"); byte[] databytes = gb2312.GetBytes(strXml); bool b = GeoSigmaLib.SetWellObjectAttributesXml(pView, objHandle, type, ttype, databytes, databytes.Length); return b; } public bool GetWellTracks(UInt64 wellHandle, out UInt64[] trackHands, out int[]ttypes, out string []dataRefBuf) { bool b = false; trackHands = new UInt64[0]; ttypes = new int[0]; dataRefBuf = new string[0]; IntPtr trackhandBuf; trackhandBuf = IntPtr.Zero; IntPtr ttypeBuff; ttypeBuff = IntPtr.Zero; int trackNum = 0; IntPtr drefBuf; drefBuf = IntPtr.Zero; int drefBufLen = 0; IntPtr refTable; refTable = IntPtr.Zero; int refTableLen = 0; IntPtr refCol; refCol = IntPtr.Zero; int refColLen = 0; b = GeoSigmaLib.GetWellTracks(pView, wellHandle, ref trackhandBuf, ref ttypeBuff, ref trackNum, ref drefBuf, ref drefBufLen , ref refTable, ref refTableLen,ref refCol, ref refColLen); if(b) { trackHands = new UInt64[trackNum]; for(int i = 0; i< trackNum; i++) { trackHands[i] = (UInt64)Marshal.ReadInt64(trackhandBuf, i * sizeof(UInt64)); } GeoSigmaLib.FreeByteArray(trackhandBuf); ttypes = new int[trackNum]; for (int i = 0; i < trackNum; i++) { ttypes[i] = (int)Marshal.ReadInt32(ttypeBuff, i * sizeof(int)); } GeoSigmaLib.FreeByteArray(ttypeBuff); string strRef = Marshal.PtrToStringAnsi(drefBuf, drefBufLen); dataRefBuf = strRef.Split('|'); GeoSigmaLib.FreeByteArray(drefBuf); GeoSigmaLib.FreeByteArray(refTable); GeoSigmaLib.FreeByteArray(refCol); } return b; } public bool GetPerforationLayerType(out string[] typesArr) { typesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetPerforationLayerType(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); typesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public bool SaveWellPoleTemplateFile(string filePathName) { return GeoSigmaLib.SaveWellPoleTemplateFile(pView, filePathName); } public bool ApplyingWellPoleTemplateFile(string filePathName) { return GeoSigmaLib.ApplyingWellPoleTemplateFile(pView, filePathName); } public static bool GetWellTrajectoryDatasJson(UInt64 wellHandle, ref string[] colName, ref string[,] strData) { IntPtr jsonStrBuff = IntPtr.Zero; int strLen = 0; string strJson = ""; bool b = GeoSigmaLib.GetWellTrajectoryDatasJson(wellHandle, ref jsonStrBuff, ref strLen); if (b) { //jsonStr = Marshal.PtrToStringAnsi(jsonStrBuff, strLen); byte[] bytes = new byte[strLen]; Marshal.Copy(jsonStrBuff, bytes, 0, strLen); strJson = Encoding.UTF8.GetString(bytes); GeoSigmaLib.FreeByteArray(jsonStrBuff); } else return b; JObject json = JObject.Parse(strJson); JArray colNames = (JArray)json["columnName"]; colName = new string[colNames.Count()]; int ii = 0; foreach (string jitem in colNames) { colName[ii] = jitem; 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++; } b = true; return b; } public static bool SetWellTrajectoryDatasJson(UInt64 wellHandle, string strJson) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetWellTrajectoryDatasJson(wellHandle, databytes, databytes.Length); return b; } public static bool SetWellStratificationJson(UInt64 wellHandle, string strJson) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetWellStratificationJson(wellHandle, databytes, databytes.Length); return b; } public static bool GetCurvePointSymbolNames(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetCurvePointSymbolNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawCurvePointSymbol(string symbolName, IntPtr hdcMem, int width, int height) { //曲线填充符号 bool b = GeoSigmaLib.GetDrawCurvePointSymbol(symbolName, hdcMem, width, height); return b; } public static bool GetStratumLithNames(out string[] NamesArr) {//连层用岩性填充符号 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetStratumLithNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawStratumLith(string symbolName, IntPtr hdcMem, int width, int height) { ////连层用岩性填充符号 bool b = GeoSigmaLib.GetDrawStratumLith(symbolName, hdcMem, width, height); return b; } public static bool SetStratumDivisionJson(UInt64 wellHandle, string strJson) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetStratumDivisionJson(wellHandle, databytes, databytes.Length); return b; } public bool TrackReadWellTableData(UInt64 trackHandle) { bool b = GeoSigmaLib.TrackReadWellTableData(trackHandle); return b; } public bool TrackIsWellTableDataSource(UInt64 trackHandle) { bool b = GeoSigmaLib.TrackIsWellTableDataSource(trackHandle); return b; } public static bool TrackGetDataSourceID(UInt64 trackHandle, ref string sourceId, ref string colId) { IntPtr sourceStrBuff = IntPtr.Zero; int sourceLen = 0; IntPtr colStrBuff = IntPtr.Zero; int colLen = 0; bool b = GeoSigmaLib.TrackGetDataSourceID(trackHandle, ref sourceStrBuff,ref sourceLen,ref colStrBuff,ref colLen); if(b) { if(sourceLen>0) { byte[] bytes = new byte[sourceLen]; Marshal.Copy(sourceStrBuff, bytes, 0, sourceLen); sourceId = Encoding.UTF8.GetString(bytes); GeoSigmaLib.FreeByteArray(sourceStrBuff); } if(colLen > 0) { byte[] bytes = new byte[colLen]; Marshal.Copy(colStrBuff, bytes, 0, colLen); colId = Encoding.UTF8.GetString(bytes); GeoSigmaLib.FreeByteArray(colStrBuff); } } return b; } public static bool TrackSetDataRefID(UInt64 trackHandle, string sourceId,string colId) { byte[] sdatabytes = Encoding.UTF8.GetBytes(sourceId); byte[] cdatabyes = Encoding.UTF8.GetBytes(colId); bool b = GeoSigmaLib.TrackSetDataRefID(trackHandle, sdatabytes, sdatabytes.Length , cdatabyes , cdatabyes.Length); return b; } public static bool SetWellFaultDatasJson(UInt64 wellHandle, string strJson, bool bRefreshTracks) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetWellFaultDatasJson(wellHandle, databytes, databytes.Length , bRefreshTracks); return b; } public static bool SetWellReservesLayersJson(UInt64 wellHandle, string strJson, bool bRefreshTracks) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetWellReservesLayersJson(wellHandle, databytes, databytes.Length , bRefreshTracks); return b; } public static bool SetWellSandSetsJson(UInt64 wellHandle, string strJson, bool bRefreshTracks) { byte[] databytes = Encoding.UTF8.GetBytes(strJson); bool b = GeoSigmaLib.SetWellSandSetsJson(wellHandle, databytes, databytes.Length , bRefreshTracks); return b; } public bool SetWellUndoRedoAction() { return GeoSigmaLib.SetWellUndoRedoAction(pView); } public static bool GetWellStratificationClasses(UInt64 wellHandle, out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellStratificationClasses(wellHandle, ref typeStrBuf, ref typeStrLen); if(b && typeStrLen != 0) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetWellStratumClasses(UInt64 wellHandle, out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetWellStratumClasses(wellHandle, ref typeStrBuf, ref typeStrLen); if (b && typeStrLen != 0) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public bool GetWellBaseInfo(UInt64 wellHandle, out WellBaseInfo wellinfo ) { bool b = false; wellinfo = new WellBaseInfo(); string strResult = ""; b = GetWellObjectAttributesXml(wellHandle, (int)GeoSigmaWellPoleXY.eWellExtType.KEP_WELL, 0, ref strResult); if(b == true && strResult != "") { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(strResult); XmlNode node = xmlDoc.SelectSingleNode("/Pcg/Head"); if (node != null) { wellinfo.wellName = node.Attributes["WellName"].Value; } node = xmlDoc.SelectSingleNode("/Pcg/Styles"); if(node != null) { String tstr = node.Attributes["DepthScale"].Value; if(float.TryParse(tstr, out float scale)) { wellinfo.ratio = scale; } tstr = node.Attributes["Top"].Value; if (float.TryParse(tstr, out float top)) { wellinfo.welltop = top; } tstr = node.Attributes["Bottom"].Value; if (float.TryParse(tstr, out float Bottom)) { wellinfo.wellbottom = Bottom; } } } catch (XmlException xmle) { Console.WriteLine(xmle.Message); } } return b; } public bool SetAddFaultPoint() { return GeoSigmaLib.SetAddFaultPoint(pView); } public bool IsAddFaultPoint() { return GeoSigmaLib.IsAddFaultPoint(pView); } public static bool GetWellTableDatasJson(UInt64 wellHandle,string tableId, ref string strJson) { IntPtr jsonStrBuff = IntPtr.Zero; int strLen = 0; byte[] databytes = Encoding.UTF8.GetBytes(tableId); bool b = GeoSigmaLib.GetWellTableDatasJson(wellHandle,databytes,databytes.Length, ref jsonStrBuff, ref strLen); if (b) { //jsonStr = Marshal.PtrToStringAnsi(jsonStrBuff, strLen); byte[] bytes = new byte[strLen]; Marshal.Copy(jsonStrBuff, bytes, 0, strLen); strJson = Encoding.UTF8.GetString(bytes); GeoSigmaLib.FreeByteArray(jsonStrBuff); } else return b; return b; } //沉积相名称 public static bool GetFaciesNames(out string[] NamesArr) { NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetFaciesNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static Color ColorRefToColor(uint colorRef) { byte r = (byte)(colorRef & 0xFF); // 低 8 位:Red byte g = (byte)((colorRef >> 8) & 0xFF); // 中 8 位:Green byte b = (byte)((colorRef >> 16) & 0xFF); // 高 8 位:Blue return Color.FromArgb(r, g, b); } public static bool GetFaciesColor(string facies, ref Color fclr) { bool b = false; byte[] databytes = Encoding.UTF8.GetBytes(facies); uint uclr = 0x00ffffff; b = GeoSigmaLib.GetFaciesColor(databytes, databytes.Length, ref uclr); if(b) { fclr = ColorRefToColor(uclr); } return b; } public static bool RefreshAllInTrackObjsForOneWellTable(UInt64 wellHandle, string tableId) { //刷新关联某个井表的所有道内数据对象 bool b = false; byte[] databytes = Encoding.UTF8.GetBytes(tableId); b = GeoSigmaLib.RefreshAllInTrackObjsForOneWellTable(wellHandle, databytes, databytes.Length); return b; } public int GetCurrentDrawItemType() { return GeoSigmaLib.GetCurrentDrawItemType(pView); } public static bool WellTempateGetTracksType(string tempfilePath, out int[] ttypes ,out string[]refCols) { refCols = new string[0]; bool b = false; ttypes = new int[0]; int trackNum = 0; IntPtr ttypeBuff; ttypeBuff = IntPtr.Zero; IntPtr refCol; refCol = IntPtr.Zero; int refColLen = 0; b = GeoSigmaLib.WellTempateGetTracksType(tempfilePath, ref ttypeBuff, ref trackNum, ref refCol, ref refColLen); if (b) { ttypes = new int[trackNum]; for (int i = 0; i < trackNum; i++) { ttypes[i] = (int)Marshal.ReadInt32(ttypeBuff, i * sizeof(int)); } GeoSigmaLib.FreeByteArray(ttypeBuff); string strRef = Marshal.PtrToStringAnsi(refCol, refColLen); refCols = strRef.Split('|'); GeoSigmaLib.FreeByteArray(refCol); } return b; } public bool MovingSelectedTrackInWell() { return GeoSigmaLib.MovingSelectedTrackInWell(pView); } public bool SetSelectedTrackInWellMovePicture(IntPtr hdc) { return GeoSigmaLib.SetSelectedTrackInWellMovePicture(pView, hdc); } public bool GetSelectedWellObjectScreenRange(ulong objHandle, ref int left, ref int top, ref int right, ref int bottom) { return GeoSigmaLib.GetSelectedWellObjectScreenRange(pView, objHandle, ref left, ref top, ref right, ref bottom); } public static bool GetStratumBendStyleNames(out string[] NamesArr) { //连层样式 NamesArr = new string[0]; IntPtr typeStrBuf; typeStrBuf = IntPtr.Zero; int typeStrLen; typeStrLen = 0; bool b = GeoSigmaLib.GetStratumBendStyleNames(ref typeStrBuf, ref typeStrLen); if (b) { string strType = Marshal.PtrToStringAnsi(typeStrBuf, typeStrLen); NamesArr = strType.Split('|'); GeoSigmaLib.FreeByteArray(typeStrBuf); } return b; } public static bool GetDrawSymbolBendStyle(string symbolName, IntPtr hdcMem, int width, int height) { //连层样式 bool b = GeoSigmaLib.GetDrawSymbolBendStyle(symbolName, hdcMem, width, height); return b; } public bool WellPoleGetToolTipInfo(int X, int Y, ref string strInfo) { IntPtr StrBuf; StrBuf = IntPtr.Zero; int StrLen; StrLen = 0; bool b = GeoSigmaLib.WellPoleGetToolTipInfo(pView,X, Y, ref StrBuf,ref StrLen); if (b) { strInfo = Marshal.PtrToStringAnsi(StrBuf, StrLen); GeoSigmaLib.FreeByteArray(StrBuf); } return b; } } }