using GeoSigma.SigmaDrawerElement; using GeoSigma.UCDraw.WellAndSection; using GeoSigmaDrawLib; using InterfaceWorkAreaData; using SigmaDrawerElement; using System; using System.Collections.Generic; using static GeoSigmaDrawLib.GeoSigmaWellPoleXY; namespace GeoSigma.UCDraw { /// /// 井道解析类 /// public class WellTrackAccessor { public bool bOpenWorkArea = false; // 这里直接将原来的 xml 格式存一份,然后输出的时候,再把这里面没有,输出里面有的元素和属性剔除掉 private static Dictionary formatCache = new Dictionary(); private WellObjInfo selectObjInfo = default(WellObjInfo); private GeoSigmaWellPoleXY wellGeo; public WellPoleContext wellPoleContext { get; set; } /// /// Initializes a new instance of the class. /// /// wellGeo public WellTrackAccessor(GeoSigmaWellPoleXY wellGeo) { this.wellGeo = wellGeo ?? throw new ArgumentNullException(nameof(wellGeo)); wellPoleContext = new WellPoleContext(); } /// /// 解析井道 /// /// GeoSigmaWellPoleXY 对象,剖面图图件对象 /// track 对象 public object LoadWellTrack(GeoSigmaXY.eViewType viewType) { bool success = wellGeo.GetSelectWellObject(ref selectObjInfo.type, ref selectObjInfo.mtype, ref selectObjInfo.objHandle); if (!success) { return null; } string strXml = string.Empty; bool b = wellGeo.GetWellObjectAttributesXml(selectObjInfo.objHandle, selectObjInfo.type, selectObjInfo.mtype, ref strXml); if (!Enum.IsDefined(typeof(eWellExtType), selectObjInfo.type)) { return null; } eWellExtType type = (eWellExtType)selectObjInfo.type; string newStrXml = strXml.Replace("\"True\"", "\"true\"") .Replace("\"False\"", "\"false\""); if (!Enum.IsDefined(typeof(eWellExtType), selectObjInfo.mtype)) { return null; } selectObjInfo.wellHandle = 0; b = wellGeo.GetSelectedWell(ref selectObjInfo.wellHandle); if (b && wellGeo.GetWellBaseInfo(selectObjInfo.wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo) == true) { wellPoleContext.wellName = wellinfo.wellName; } else wellPoleContext.wellName = ""; eWellExtType mType = (eWellExtType)selectObjInfo.mtype; // 缓存这个类型的 xml 格式,为什么不一个类型缓存一次? // 因为 KEP_LAYERGROUP 这个类型对应了两种不同的 xml 类型 formatCache[mType] = newStrXml; wellPoleContext.geoWellPole = wellGeo; wellPoleContext.wellObjHandle = selectObjInfo.wellHandle; wellPoleContext.workArea = workAreaDb.Instance.workData; wellPoleContext.bReadCurveTable = false; wellPoleContext.selectObjHandle = selectObjInfo.objHandle; UInt64 ParentObj = 0; GeoSigmaWellPoleXY.GetWellBaseObjectParent(selectObjInfo.objHandle, ref ParentObj); wellPoleContext.ParentObj = ParentObj; return SerializeTrack(newStrXml, mType, wellPoleContext, viewType); } /// /// 设置属性 /// /// track public void SaveWellTrack(object track, GeoSigmaXY.eViewType viewType) { string xml = XmlHelper.Serialize(track); if (xml != null) { eWellExtType mType = (eWellExtType)selectObjInfo.mtype; //if (viewType == GeoSigmaXY.eViewType.wellsection && mType == eWellExtType.KEP_WELL) //{ // string oldXmlFormat = formatCache[mType]; // string formatedXml = XmlFieldFilter.RemoveExtraFields(xml, oldXmlFormat); //} //else { // 这里非常关键,我们在 formatCache 里面存储了原来应该是什么格式 // 现在输出的 xml 会多出很多字段和属性出来,主要是 WellTrack 里面有很多相似字段, // 但是又有部分不同,为了不要写一堆类,于是写了个大类把这些元素和属性都包含进去了, // 我们在 formatCache 里面存储了获取到的是什么格式,现在我们拿输出和它对比, // 将多余的元素和属性剔除掉 if (formatCache.ContainsKey(mType)) { string oldXmlFormat = formatCache[mType]; string formatedXml = XmlFieldFilter.RemoveExtraFields(xml, oldXmlFormat); wellGeo.SetWellObjectAttributesXml(selectObjInfo.objHandle, selectObjInfo.type, selectObjInfo.mtype, formatedXml); if (track is WellCurveTrack twellCurveTrack) { if (twellCurveTrack.CurveTrack.bRefreshWorkAreaData) { if (selectObjInfo.type == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK) && selectObjInfo.mtype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Curve) && wellPoleContext.curveTable != null) {//曲线道 WellDataConvert.getWellCurveValueForNewWell(wellPoleContext.curveTable, wellGeo, selectObjInfo.wellHandle, selectObjInfo.objHandle, twellCurveTrack.CurveTrack.Name); } } } else if (track is WellCycleTrack tCycleTrack) { if (tCycleTrack.WellTrack.bRefreshWorkAreaData) { WellDataConvert.setWellCycleDataToTrack(wellPoleContext.geoWellPole, wellPoleContext.wellName, selectObjInfo.objHandle, tCycleTrack.WellTrack.Data.RefTableId); } } else if( track is WellCommonDataTrack tCommonDataTrack) { if(this.bOpenWorkArea && tCommonDataTrack.WellTrack.bRefreshWorkAreaData) { WellDataConvert.setDataToWellCommonDataTrack(wellPoleContext.geoWellPole, wellPoleContext.wellName, selectObjInfo.objHandle, tCommonDataTrack.dataItems.RefTableId, tCommonDataTrack.dataItems); } } else if (track is WellTextTrack tTextTrack) { if (this.bOpenWorkArea && tTextTrack.WellTrack.bRefreshWorkAreaData) { WellDataConvert.setWellTableDataToTrack(wellPoleContext.geoWellPole, wellPoleContext.wellName, selectObjInfo.objHandle, tTextTrack.WellTrack.Data.RefTableId, tTextTrack.WellTrack.Data.RefColId); } } else if (track is WellSymbolTrack tSybmolTrack) { if (this.bOpenWorkArea && tSybmolTrack.WellTrack.bRefreshWorkAreaData) { WellDataConvert.setWellTableDataToTrack(wellPoleContext.geoWellPole, wellPoleContext.wellName, selectObjInfo.objHandle, tSybmolTrack.WellTrack.Data.RefTableId, tSybmolTrack.WellTrack.Data.RefColId); } } } } } } private static readonly Dictionary TypeMap = new Dictionary { { eWellExtType.KEP_LAYERGROUP, typeof(WellLayerGroup) }, { eWellExtType.KEP_LITH, typeof(WellLithologySection) }, { eWellExtType.KEP_RESULT, typeof(WellPropLayerSettings) }, { eWellExtType.KEP_TEXTRANGE, typeof(WellTextSettingsTrack) }, { eWellExtType.KEP_SHOT, typeof(WellShotInnerTrack) }, { eWellExtType.KEP_SYMBOL, typeof(WellSymbolInnerTrack) }, { eWellExtType.KEP_WELL, typeof(WellPole) }, { eWellExtType.KEP_INTRACK_CYCLE, typeof(WellCycleLayerSetting) }, { eWellExtType.KEP_INTRACK_INNERLAYER, typeof(WellInnerLayerDataSetting)}, { eWellExtType.KEP_FAULTPOINT, typeof(WellFaultPointDataSetting)}, { eWellExtType.KEP_INTRACK_SANDSTONE, typeof(WellSandstoneInTrackDataSetting)}, { eWellExtType.KEP_INTRACK_FACIES, typeof(WellInTrackFacies)}, { eWellExtType.KEP_SECTIONBEND, typeof(WellSectionBendDataSetting)}, { eWellExtType.KEP_SECTIONFAULT, typeof(WellSectionFaultDataSetting)}, { eWellExtType.KEP_WELLSECTION, typeof(WellSectionSetting)}, {eWellExtType.KEP_INTRACK_COMMONDATA, typeof(WellInTrackCommonData) }, {eWellExtType.KEP_OILTEST, typeof(WellInTrackOilTest) }, {eWellExtType.KEP_CORING, typeof(WellInTrackCoring) }, {eWellExtType.KEP_COREWELL,typeof(WellInTrackSideWallCoring) }, {eWellExtType.KEP_INTRACK_FLUIDPRODUCINGPROFILE,typeof(WellInTracFluidProducingProfile) }, {eWellExtType.KEP_INTRACK_WATERINJECTIONPROFILE,typeof(WellInTracWaterInjectionProfile) }, { eWellExtType.Track_CorePosition, typeof(WellCoreTrack) }, { eWellExtType.Track_CoreWell, typeof(WellWallCoreTrack) }, { eWellExtType.Track_Curve, typeof(WellCurveTrack) }, { eWellExtType.Track_Depth, typeof(WellDepthTrack) }, { eWellExtType.Track_Discrete, typeof(WellPointTrack) }, { eWellExtType.Track_FaultPoint, typeof(WellFaultPointTrack) }, { eWellExtType.Track_Group, typeof(WellGroupTrack) }, { eWellExtType.Track_Lith, typeof(WellLithologyTrack) }, { eWellExtType.Track_OilLayerGroup, typeof(WellOilLayerTrack) }, { eWellExtType.Track_Picture, typeof(WellPictureTrack) }, { eWellExtType.Track_Result, typeof(WellInterpretationLayerTrack) }, { eWellExtType.Track_Sample, typeof(WellRockSampleTrack) }, { eWellExtType.Track_SandLayer, typeof(WellSandSetsTrack) }, { eWellExtType.Track_Shot, typeof(WellShotTrack) }, { eWellExtType.Track_Stratum, typeof(WellStratigraphicUnitTrack) }, { eWellExtType.Track_Symbol, typeof(WellSymbolTrack) }, { eWellExtType.Track_TestExtraction, typeof(WellSamplingTrack) }, { eWellExtType.Track_Text, typeof(WellTextTrack) }, { eWellExtType.Track_Cycle, typeof(WellCycleTrack) }, { eWellExtType.Track_Facies, typeof(WellFaciesTrack)}, { eWellExtType.Track_InnerLayer, typeof(WellInnerLayerTrack)}, { eWellExtType.Track_Sandstone, typeof(WellSandstoneTrack)}, { eWellExtType.Track_CommonData, typeof(WellCommonDataTrack)}, { eWellExtType.Track_OilTest,typeof(WellTestOilTrack) }, { eWellExtType.Track_WaterInjectionTrace,typeof(WellWaterInjectionTrack)}, { eWellExtType.Track_FluidProducingProfileTrace,typeof(WellFluidProducingProfileTrack)}, }; public static object SerializeTrack(string strXml, eWellExtType type, WellPoleContext wellPoleContext, GeoSigmaXY.eViewType viewType) { if (!TypeMap.TryGetValue(type, out var trackType)) { return null; } object tObj = null; if (type == eWellExtType.KEP_WELL && viewType == GeoSigmaXY.eViewType.wellsection) { var wellType = typeof(SecitonWellSetting); tObj = XmlHelper.Deserialize(wellType, strXml); } else { tObj = XmlHelper.Deserialize(trackType, strXml); } if (tObj is WellObjectXmlBase wObjXmlBase) { wObjXmlBase.wellPoleContext = wellPoleContext; } return tObj; } } }