/// <summary> /// If NetworkDiagram exists, fill the lists of DiagramElements, with the selection /// If there is no selection and GetSelection is true, get all DiagramElements in diagram /// </summary> /// <param name="GetAllElements">Get all DiagramElements in diagram</param> /// <param name="GetSelection">Get only DiagramElements in selection, if exist, if not get all</param> /// <returns>NetworkDiagram exists</returns> internal static bool IsDiagramUsable(bool GetAllElements = false, bool GetSelection = false) { if (GlobalDiagram == null) { GetParameters(MapView.Active.Map); } if (GlobalDiagram == null) { return(false); } if (GlobalGeodatabase.HasEdits()) { return(false); } if (GetAllElements == false && GetSelection == false) { return(true); } if (GetSelection) { GlobalSelectedJunctionIDs = new List <long>(); GlobalSelectedContainerIDs = new List <long>(); GlobalSelectedEdgeIDs = new List <long>(); GlobalMapSelection = MapView.Active.Map.GetSelection(); foreach (var v in GlobalMapSelection) { FeatureLayer layer = v.Key as FeatureLayer; if (layer.ShapeType == esriGeometryType.esriGeometryPoint) { foreach (var id in v.Value) { GlobalSelectedJunctionIDs.Add(id); } } else if (layer.ShapeType == esriGeometryType.esriGeometryPolygon) { foreach (var id in v.Value) { GlobalSelectedContainerIDs.Add(id); } } else { foreach (var id in v.Value) { GlobalSelectedEdgeIDs.Add(id); } } } } else { GlobalMapSelection = null; } DiagramElementQueryResult deqr; try { if (GetAllElements || (GlobalSelectedContainerIDs.Count + GlobalSelectedEdgeIDs.Count + GlobalSelectedJunctionIDs.Count == 0)) { DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes { QueryDiagramContainerElement = true, QueryDiagramEdgeElement = true, QueryDiagramJunctionElement = true }; deqr = GlobalDiagram.QueryDiagramElements(query); } else { DiagramElementQueryByObjectIDs query1 = new DiagramElementQueryByObjectIDs { AddConnected = true, AddContents = true, ContainerObjectIDs = GlobalSelectedContainerIDs, JunctionObjectIDs = GlobalSelectedJunctionIDs, EdgeObjectIDs = GlobalSelectedEdgeIDs }; deqr = GlobalDiagram.QueryDiagramElements(query1); } } catch (Exception ex) { ShowException(exception: ex); return(false); } GlobalDiagramJunctionElements = deqr.DiagramJunctionElements.ToList(); GlobalDiagramEdgeElements = deqr.DiagramEdgeElements.ToList(); GlobalDiagramContainerElements = deqr.DiagramContainerElements.ToList(); return(true); }
/// <summary> /// Set Global fields /// </summary> /// <param name="map">Diagram Layer</param> internal static void GetParameters(Map map) { if (map == null) { CleanModule(); return; } if (GlobalActiveMapName != map.Name || GlobalDiagram == null || GlobalDiagramLayer == null) { GlobalActiveMap = map; GlobalActiveMapName = GlobalActiveMap.Name; GlobalDiagramLayer = GetDiagramLayerFromMap(map); if (GlobalDiagramLayer == null) { CleanModule(); } else { QueuedTask.Run(() => { try { GlobalDiagram = GlobalDiagramLayer.GetNetworkDiagram(); } catch { GlobalDiagram = null; } try { if (GlobalDiagram != null) { GlobalDiagramManager = GlobalDiagram.DiagramManager; GlobalUtilityNetwork = GlobalDiagramManager.GetNetwork <UtilityNetwork>(); GlobalGeodatabase = GlobalUtilityNetwork.GetDatastore() as Geodatabase; NetworkDiagramInfo networkDiagramInfo = GlobalDiagram.GetDiagramInfo(); if (networkDiagramInfo == null) { GlobalIsSystem = false; GlobalEnvelope = null; GlobalIsStored = false; GlobalContainerMargin = 0.5; } else { GlobalIsSystem = networkDiagramInfo.IsSystem; GlobalEnvelope = networkDiagramInfo.DiagramExtent; GlobalIsStored = networkDiagramInfo.IsStored; GlobalContainerMargin = networkDiagramInfo.ContainerMargin; } GlobalTypeGeo = GlobalGeodatabase.GetGeodatabaseType(); if (GlobalTypeGeo == GeodatabaseType.Service) { VersionManager vm = GlobalGeodatabase.GetVersionManager(); if (vm != null) { GlobalIsVersioned = (vm.GetCurrentVersion() != null); } else { GlobalIsVersioned = false; } } else { GlobalIsVersioned = false; } } else { GlobalDiagramLayer = null; } CleanSelections(); } catch (Exception ex) { ShowException(exception: ex); CleanModule(); } }); } } }