public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; m_ActiveView = app.Current2DMapControl.ActiveView; IGraphicsContainer pGC = m_ActiveView.GraphicsContainer; if (this.m_ActiveView.FocusMap.FeatureSelection != null) { this.m_ActiveView.FocusMap.ClearSelection(); } bool ready = false; if (app == null || app.Current2DMapControl == null) { return; } IGeometry pGeo = null; int preCount = 0; int nextCount = 0; try { if (button == 1) { PointClass searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } ready = true; if (ready) { bool haveone = false; foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups) { if (haveone) { break; } foreach (MajorClass mc in lg.MajorClasses) { if (haveone) { break; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; //DFDataConfig.Class.FieldInfo fi; //int indexFusu = 0; ////string nodefcId = null; foreach (SubClass sc in mc.SubClasses) { if (haveone) { break; } if (!sc.Visible2D) { continue; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pFeatureCursor = fc.Search(pSpatialFilter, false); if (pFeatureCursor == null) { continue; } pFeature = pFeatureCursor.NextFeature(); if (pFeature == null) { continue; } IGeometry pGeometry = pFeature.Shape as IGeometry; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline pLine = pGeometry as IPolyline; this._EdgeFCID = fc.FeatureClassID.ToString(); this._EdgeOID = pFeature.OID; color = GetRGBColor(0, 230, 240); IElement lineElement = LineElementRenderer(pLine, color); pGC.AddElement(lineElement, 0); } haveone = true; break; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); IFeatureLayer fl = dffc.GetFeatureLayer(); if (fc == null || pGeo == null || fl == null) { continue; } if (!fl.Visible) { continue; } if (facc.Name != "PipeNode") { continue; } DFDataConfig.Class.FieldInfo fi = facc.GetFieldInfoBySystemName("Additional"); IFields fiCol = fc.Fields; int indexFusu = fiCol.FindField(fi.Name); WaitForm.Start("正在分析...", "请稍后"); TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc2DId); if (tc == null) { WaitForm.Stop(); return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { WaitForm.Stop(); XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { HashSet <string> valveIds = new HashSet <string>(); if (!string.IsNullOrEmpty(fc2DId) && ValveManager.Instance.Exists(fc2DId)) { valveIds = ValveManager.Instance.GetValveIds(fc2DId); } else { IFeature feature; string fusu; //IQueryFilter filter = new QueryFilter(); //filter.WhereClause = fi.Name + " LIKE '%阀%'"; IFeatureCursor cursor = fc.Search(null, false); int n = fc.FeatureCount(null); if (indexFusu == 0) { return; } while ((feature = cursor.NextFeature()) != null) { //valveIds.Add(fc2DId + "_" + feature.OID.ToString()); fusu = feature.get_Value(indexFusu).ToString(); if (fusu == "阀门" || fusu == "阀门井") { valveIds.Add(fc2DId + "_" + feature.OID.ToString()); } } ValveManager.Instance.Add(fc2DId, valveIds); } //string edgeID = this._EdgeFCID + "_" + this._EdgeOID.ToString(); if (EdgeManager.Instance.Exists(this._EdgeFCID, this._EdgeOID.ToString())) { edge = EdgeManager.Instance.GetEdgeByID(this._EdgeFCID, this._EdgeOID.ToString()); } preNode = edge.PreNode; nextNode = edge.NextNode; HashSet <string> recordPre = new HashSet <string>(); HashSet <string> recordNext = new HashSet <string>(); color = GetRGBColor(255, 0, 0); net.BGFX(preNode.ID, nextNode.ID, valveIds, ref recordPre, ref recordNext); if (recordPre.Count <= 0 && recordNext.Count <= 0) { continue; } preCount = recordPre.Count; nextCount = recordNext.Count; foreach (string s in recordPre) { int id; Node n = NodeManager.Instance.GetNodeByID(s); Int32.TryParse(n.FeatureId, out id); IFeature feature = fc.GetFeature(id); IPoint point = feature.Shape as IPoint; //color = GetRGBColor(255, 0, 0); IElement elementpPoint = PointElementRenderer(point, color); pGC.AddElement(elementpPoint, 0); IElement elementText = AddCallout(app.Current2DMapControl, point, "需关闭阀门", color); pGC.AddElement(elementText, 1); app.Current2DMapControl.CenterAt(point); } foreach (string s in recordNext) { int id; Node n = NodeManager.Instance.GetNodeByID(s); Int32.TryParse(n.FeatureId, out id); IFeature feature = fc.GetFeature(id); IPoint point = feature.Shape as IPoint; color = GetRGBColor(0, 0, 0); IElement elementpPoint = PointElementRenderer(point, color); pGC.AddElement(elementpPoint, 0); IElement elementText = AddCallout(app.Current2DMapControl, point, "需关闭阀门", color); pGC.AddElement(elementText, 1); app.Current2DMapControl.CenterAt(point); } app.Current2DMapControl.MapScale = 500; app.Current2DMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } if (haveone) { break; } } } } } } } } catch (System.Exception ex) { } finally { WaitForm.Stop(); XtraMessageBox.Show("上游需关闭阀门:" + preCount + "\n下游需关闭阀门:" + nextCount, "提示"); SuspendCommand(); } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; m_ActiveView = app.Current2DMapControl.ActiveView; IGraphicsContainer pGC = m_ActiveView.GraphicsContainer; if (this.m_ActiveView.FocusMap.FeatureSelection != null) { this.m_ActiveView.FocusMap.ClearSelection(); } bool ready = false; if (app == null || app.Current2DMapControl == null) { return; } IGeometry pGeo = null; try { if (button == 1) { PointClass searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } ready = true; if (ready) { bool haveone = false; foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups) { foreach (MajorClass mc in lg.MajorClasses) { string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeNode") { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); if (fc == null || pGeo == null || fl == null) { continue; } if (!fl.Visible) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pFeatureCursor = fc.Search(pSpatialFilter, false); if (pFeatureCursor == null) { continue; } pFeature = pFeatureCursor.NextFeature(); if (pFeature == null) { continue; } haveone = true; IGeometry pGeometry = pFeature.Shape as IGeometry; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint pPoint = pGeometry as IPoint; if (this._bFinished) { this._bFinished = false; this._startFCID = fc.FeatureClassID.ToString(); this._startOid = pFeature.OID; AddCallout(pPoint, "起点"); app.Current2DMapControl.ActiveView.Refresh(); } else { if (this._startFCID == fc.FeatureClassID.ToString() && this._startOid == pFeature.OID) { XtraMessageBox.Show("您选中的是同一个管点设施。", "提示"); return; } this._bFinished = true; AddCallout(pPoint, "终点"); app.Current2DMapControl.ActiveView.Refresh(); if (this._startFCID != fc.FeatureClassID.ToString()) { XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示"); return; } else { WaitForm.Start("正在分析...", "请稍后"); TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc.FeatureClassID.ToString()); if (tc == null) { return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { WaitForm.Stop(); XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { string startId = this._startFCID + "_" + this._startOid.ToString(); string endId = fc.FeatureClassID.ToString() + "_" + pFeature.OID.ToString(); List <string> path; double shortestLength = net.SPFA(startId, endId, out path); if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0)) { List <IPoint> listPt = new List <IPoint>(); IPointCollection pointCol = new PolylineClass(); foreach (string nodeId in path) { int index = nodeId.LastIndexOf("_"); string fcID = nodeId.Substring(0, index); string oid = nodeId.Substring(index + 1, nodeId.Length - index - 1); DF2DFeatureClass dffcTemp = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fcID); if (dffcTemp == null || dffcTemp.GetFeatureClass() == null) { continue; } if (dffcTemp.GetFacilityClassName() != "PipeNode") { continue; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "OBJECTID =" + oid; filter.SubFields = "OBJECTID ,SHAPE"; IFeature feature = null; IFeatureCursor cursor = null; try { cursor = dffcTemp.GetFeatureClass().Search(filter, false); while ((feature = cursor.NextFeature()) != null) { if (feature.Shape != null && feature.Shape is IGeometry) { IGeometry geo = feature.Shape as IGeometry; switch (geo.GeometryType) { case esriGeometryType.esriGeometryPoint: IPoint pt = geo as IPoint; //pt.Z = pt.Z + 1; listPt.Add(pt); pointCol.AddPoint(pt); break; } } } } catch (System.Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (feature != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); feature = null; } } } if (listPt.Count > 0) { IPolyline polyline = pointCol as IPolyline; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbol(); pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pLineSymbol.Width = 5; pLineSymbol.Color = GetRGBColor(0, 230, 240); IElement elementL = new LineElement(); elementL.Geometry = polyline; ILineElement pLineElement = elementL as ILineElement; pLineElement.Symbol = pLineSymbol; pGC.AddElement(elementL, 0); ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = GetRGBColor(255, 0, 0); simpleMarkerSymbol.Outline = false; simpleMarkerSymbol.Size = 5; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; foreach (IPoint pt in listPt) { try { IMarkerElement pMarkerElement = new MarkerElementClass(); pMarkerElement.Symbol = simpleMarkerSymbol; IElement pElement = pMarkerElement as IElement; pElement.Geometry = pt; pGC.AddElement(pElement, 0); } catch (System.Exception ex) { continue; } } } app.Current2DMapControl.ActiveView.Refresh(); } else { WaitForm.Stop(); XtraMessageBox.Show("两点不连通!", "提示"); pGC.DeleteAllElements(); } } } } } } if (haveone) { break; } } if (haveone) { break; } } } } } catch (System.Exception ex) { XtraMessageBox.Show("分析出错!", "提示"); } finally { WaitForm.Stop(); } }