using System; using System.Drawing; using System.Windows.Forms; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; namespace Cyberpipe { public class NetworkAnalysisTool { private static GSOFeatures traceUpDownFeats; private static GSOFeatures connectFeats; private static GSOFeatures closeValveFeats; private static GSOLayer flowLayer; //上下游分析 public static void ClearTraceUpDownAnalysis() { if (traceUpDownFeats != null) { for (int i = 0; i < traceUpDownFeats.Length; i++) { traceUpDownFeats[i].HighLight = false; GSOGeoPolyline3D geoline = traceUpDownFeats[i].Geometry as GSOGeoPolyline3D; if (geoline != null) { GSOLineStyle3D lineStyle = geoline.Style as GSOLineStyle3D; if (lineStyle != null) { lineStyle.ArrowVisible = false; } } } traceUpDownFeats = null; } } public static void TraceUpDownAnalysis(bool isUp, GSOFeature selFeature, GSOLayer selLayer) { ClearTraceUpDownAnalysis(); GSODataset curCAYDataset = selLayer.Dataset; if (curCAYDataset == null || curCAYDataset.DataSource == null) { MessageBox.Show("选中管线所在图层不是数据库图层!", "提示"); return; } string srName = curCAYDataset.Name; GSONetworkDataset curCAYNDataset = curCAYDataset.DataSource.GetDatasetByName(srName + "Network") as GSONetworkDataset; if (curCAYNDataset == null) { MessageBox.Show("选中管线所在图层没有创建拓扑!", "提示"); return; } int[] arryResID; curCAYNDataset.TraceUpDownAnalysis(selFeature.ID, out arryResID, isUp, false, true); traceUpDownFeats = selLayer.GetFeaturesByIDs(arryResID); if (traceUpDownFeats == null) { MessageBox.Show(isUp ? "没有上游" : "没有下游"); return; } for (int i = 0; i < traceUpDownFeats.Length; i++) { traceUpDownFeats[i].HighLight = true; GSOGeoPolyline3D geoline = traceUpDownFeats[i].Geometry as GSOGeoPolyline3D; GSOLineStyle3D lineStyle = geoline.Style as GSOLineStyle3D; if (geoline != null) { if (lineStyle != null && lineStyle.ArrowStyle == null) { lineStyle.ArrowStyle = new GSOArrowStyle(); lineStyle.ArrowStyle.BodyWidth = 2; lineStyle.ArrowStyle.BodyLen = 6; lineStyle.ArrowStyle.HeadWidth = 8; lineStyle.ArrowStyle.HeadLen = 10; lineStyle.ArrowStyle.OutlineVisible = true; lineStyle.ArrowStyle.OutlineColor = Color.Red; lineStyle.ArrowStyle.Speed = lineStyle.ArrowStyle.Speed / 2; } if (lineStyle != null) { lineStyle.ArrowVisible = true; lineStyle.ArrowStyle.Play(); } } } } public static void TraceUpAnalysis(GSOFeature selFeature, GSOLayer selLayer) { TraceUpDownAnalysis(true, selFeature, selLayer); } public static void TraceDownAnalysis(GSOFeature selFeature, GSOLayer selLayer) { TraceUpDownAnalysis(false, selFeature, selLayer); } //连通性分析 public static void ClearConnexityAnalysis() { if (connectFeats != null) { for (int i = 0; i < connectFeats.Length; i++) { connectFeats[i].HighLight = false; GSOGeoPolyline3D geoline = connectFeats[i].Geometry as GSOGeoPolyline3D; if (geoline != null) { GSOLineStyle3D lineStyle = geoline.Style as GSOLineStyle3D; if (lineStyle != null) { lineStyle.ArrowVisible = false; } } } connectFeats = null; } } public static void ConnexityAnalysis(GSOFeature feat0, GSOFeature feat1, GSOLayer layer) { ClearConnexityAnalysis(); GSOGeoPolyline3D line1 = feat0.Geometry as GSOGeoPolyline3D; GSOGeoPolyline3D line2 = feat1.Geometry as GSOGeoPolyline3D; if (line1 == null || line2 == null || line1.Style==null|| line2.Style==null) { MessageBox.Show("请选择管线!!"); return; } GSODataset curCAYDataset = layer.Dataset; string srName = curCAYDataset.Name; GSONetworkDataset curCAYNDataset = curCAYDataset.DataSource.GetDatasetByName(srName + "Network") as GSONetworkDataset; if (curCAYNDataset == null) { MessageBox.Show("该图层没有创建网络拓扑,请先创建网络拓扑信息再进行分析!", "提示"); return; } int[] arryResID; curCAYNDataset.ConnexityAnalysis(feat0.ID, feat1.ID, out arryResID, false, true); connectFeats = layer.GetFeaturesByIDs(arryResID); if (connectFeats == null || connectFeats.Length < 1) { String strLine1 = "管线:" + feat0.ID; String strLine2 = "管线:" + feat1.ID; MessageBox.Show(strLine1 + " 与 " + strLine2 + " 不连通", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } for (int i = 0; i < connectFeats.Length; i++) { connectFeats[i].HighLight = true; GSOGeoPolyline3D geoline = connectFeats[i].Geometry as GSOGeoPolyline3D; if (geoline != null) { GSOLineStyle3D lineStyle = geoline.Style as GSOLineStyle3D; if (lineStyle != null) { if (lineStyle.ArrowStyle == null) { lineStyle.ArrowStyle = new GSOArrowStyle(); } lineStyle.ArrowStyle.BodyLen = 8; lineStyle.ArrowVisible = true; lineStyle.ArrowStyle.Play(); } } } } //关阀分析 public static void ClearValvesAnalysis() { if (closeValveFeats != null) { for (int i = 0; i<closeValveFeats.Length; i++) { GSOFeature feature = closeValveFeats[i]; feature.Label.Text = ""; } closeValveFeats = null; } } public static GSOFeatures CloseValvesAnalysis(GSOFeature selFeature, GSOLayer selLayer,GSOLayer valLayer) { ClearValvesAnalysis(); if (selLayer == null ||selLayer.Dataset==null|| selLayer.Dataset.DataSource == null || selFeature==null || selFeature.Geometry == null || selFeature.Geometry.Type != EnumGeometryType.GeoPolyline3D) { return null; } GSODataset curCAYDataset = selLayer.Dataset; GSONetworkDataset curCAYNDataset = curCAYDataset.DataSource. GetDatasetByName(curCAYDataset.Name + "Network") as GSONetworkDataset; if (curCAYNDataset == null) { MessageBox.Show("该图层没有创建网络拓扑,请先创建网络拓扑信息再进行分析!", "提示"); return null; } int[] arryResNodeID = null; int[] arryResValveID = null; try { curCAYNDataset.CloseValveAnalysis(selFeature.ID, out arryResNodeID, out arryResValveID, false, true); } catch (Exception e) { MessageBox.Show(e.Message); return null; } closeValveFeats = valLayer.GetFeaturesByIDs(arryResValveID); return closeValveFeats; } //爆管分析 public static void ClearExplodeAnalysis(GSOGlobeControl globeControl) { GSOFeatures feats = globeControl.Globe.MemoryLayer.GetFeatureByName("粒子要素", true); if (feats != null && feats.Length!=0) { globeControl.Globe.MemoryLayer.RemoveFeatureByID(feats[0].ID); } } public static void ExplodeAnalysis(GSOGlobeControl globeControl, GSOFeature selfeature,GSOLayer sellayer) { ClearExplodeAnalysis(globeControl); GSOGeoPolyline3D line = selfeature.Geometry as GSOGeoPolyline3D; if (line == null || line.Style==null) { MessageBox.Show("请选择管线!!"); return; } GSOPipeLineStyle3D pipeStyle = line.Style as GSOPipeLineStyle3D; GSOPoint3d pt = new GSOPoint3d(); double length = line.GetSpaceLength(true, 6378137);//线的长度 GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2); GSOPoint3d point3d = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1]; pt.X = point3d.X; pt.Y = point3d.Y; pt.Z = point3d.Z; pt.Z += pipeStyle.Radius * 2; if (sellayer.Caption.Contains("气")) { AddFire(pt.X, pt.Y, pt.Z, globeControl); } else { AddFountain(pt.X, pt.Y, pt.Z,globeControl); } } /// <summary> /// 添加火苗 功能 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> public static void AddFire(double x, double y, double z, GSOGlobeControl globeControl1) { GSOFeatures feats = globeControl1.Globe.MemoryLayer.GetFeatureByName("粒子要素", true); if (feats.Length > 0) globeControl1.Globe.MemoryLayer.RemoveFeatureByID(feats[0].ID); string strResPath = Application.StartupPath + "/Resource"; // 烟火粒子示例,由三个发射器构成 GSOGeoParticle geoParticle = new GSOGeoParticle(); geoParticle.SetPosition(x, y, z); // 添加到这个经纬度位置 geoParticle.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSORingParticleEmitter emitter = new GSORingParticleEmitter(); emitter.TexturePath = strResPath + "/ParticleImage/flare1.png";//烟1111111111111 emitter.SetSizeFix(1, 1); emitter.VelFix = 1; emitter.VelRnd = 5; emitter.AngleXYFix = 0; emitter.AngleXYRnd = 180; emitter.AngleXZFix = 90; emitter.AngleXZRnd = 0; emitter.LifeFix = 0.5f; emitter.LifeRnd = 0.0f; emitter.RotFix = 0; emitter.RotRnd = 0; emitter.RotVelFix = 0; emitter.RotVelRnd = 0; emitter.EmitPerSec = 100; emitter.IsLumAdded = true; // 采用线性插值生成粒子的初始颜色 emitter.ColorRndStart = Color.White; emitter.ColorRndEnd = Color.Red; GSOColorParticleEffector effector2 = new GSOColorParticleEffector(); effector2.SetColorChanged(0, -1, -1, 0); effector2.StartTime = 0.0f; effector2.EndTime = -1.0f; emitter.AddEffector(effector2); // 将三个发射器添加到粒子对象中 geoParticle.AddEmitter(emitter); geoParticle.Play(); GSOFeature emitterFeature = new GSOFeature(); emitterFeature.Geometry = geoParticle; emitterFeature.Name = "粒子要素"; // globeControl1.Globe.MemoryLayer.AddFeature(emitterFeature); } /// <summary> /// 添加喷泉 功能 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> public static void AddFountain(double x, double y, double z, GSOGlobeControl globeControl1) { GSOFeatures feats = globeControl1.Globe.MemoryLayer.GetFeatureByName("粒子要素", true); if (feats.Length > 0) globeControl1.Globe.MemoryLayer.RemoveFeatureByID(feats[0].ID); string strResPath = Application.StartupPath + "/Resource"; GSOGeoParticle geoParticle = new GSOGeoParticle(); geoParticle.SetPosition(x, y, z); // 添加到这个经纬度位置 geoParticle.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOPointParticleEmitter emitter = new GSOPointParticleEmitter(); emitter.TexturePath = strResPath + "/ParticleImage/test.png"; emitter.SetSizeFix(0.5f, 2); emitter.VelFix = 10; emitter.VelRnd = 2; emitter.GravityAcc = 9.8f; emitter.AngleXYFix = 0; emitter.AngleXYRnd = 180; emitter.AngleXZFix = 88; emitter.AngleXZRnd = 2; emitter.LifeFix = 5.0f; emitter.LifeRnd = 1.0f; emitter.RotFix = 0; emitter.RotRnd = 0; emitter.RotVelFix = 0; emitter.RotVelRnd = 0; emitter.EmitPerSec = 1000; emitter.ColorRndStart = Color.FromArgb(33, 255, 255, 255); emitter.ColorRndEnd = Color.FromArgb(11, 255, 255, 255); emitter.IsLumAdded = false; // 将三个发射器添加到粒子对象中 geoParticle.AddEmitter(emitter); geoParticle.Play(); GSOFeature emitterFeature = new GSOFeature(); emitterFeature.Geometry = geoParticle; emitterFeature.Name = "粒子要素"; // globeControl1.Globe.MemoryLayer.AddFeature(emitterFeature); } //流向分析 public static void ClearFlowDirectionAnalysis() { if (flowLayer == null) { return; } GSOFeatures features = flowLayer.GetAllFeatures(); if (features != null) { for (int i = 0; i < features.Length; i++) { features[i].HighLight = false; GSOGeoPolyline3D geoline = features[i].Geometry as GSOGeoPolyline3D; if (geoline != null) { GSOLineStyle3D lineStyle = geoline.Style as GSOLineStyle3D; if (lineStyle != null) { lineStyle.ArrowVisible = false; } } } } flowLayer = null; } public static void FlowDirectionAnalysis(GSOLayer layer) { ClearFlowDirectionAnalysis(); if (layer == null) { return; } GSOFeatures feats = layer.GetAllFeatures(); if (feats==null ||feats.Length == 0) return; for (int i = 0; i < feats.Length; i++) { GSOFeature feat = feats[i]; GSOLineStyle3D lineStyle = feat.Geometry.Style as GSOLineStyle3D; if (lineStyle != null) { if (lineStyle.ArrowStyle == null) { lineStyle.ArrowStyle = new GSOArrowStyle(); } lineStyle.ArrowStyle.BodyWidth = 2; lineStyle.ArrowStyle.BodyLen = 6; lineStyle.ArrowStyle.HeadWidth = 8; lineStyle.ArrowStyle.HeadLen = 10; lineStyle.ArrowStyle.OutlineVisible = true; lineStyle.ArrowStyle.OutlineColor = Color.Red; lineStyle.ArrowStyle.Speed = 25; lineStyle.ArrowStyle.Play(); lineStyle.ArrowVisible = true; feat.Geometry.SetModified(true); } } flowLayer = layer; } //清除所有分析 public static void ClearAllTopAnalysis(GSOGlobeControl globeControl) { ClearConnexityAnalysis(); ClearExplodeAnalysis(globeControl); ClearFlowDirectionAnalysis(); ClearTraceUpDownAnalysis(); ClearValvesAnalysis(); } } }