/// <summary> /// Get all diagram Elements /// </summary> internal static void LoadDiagramFeatures(NetworkDiagram Diagram, out SelectionSet selection) { DiagramElementQueryResult deqr; selection = MapView.Active.Map.GetSelection(); if (selection == null || selection.Count == 0) { DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes { QueryDiagramContainerElement = true, QueryDiagramEdgeElement = true, QueryDiagramJunctionElement = true }; deqr = Diagram.QueryDiagramElements(query); } else { List <long> junctionIDs = new List <long>(); List <long> edgeIDs = new List <long>(); List <long> containerIDs = new List <long>(); foreach (var v in selection.ToDictionary()) { if (v.Key is FeatureLayer layer) { if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPoint) { junctionIDs.AddRange(v.Value); } else if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolygon) { containerIDs.AddRange(v.Value); } else if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolyline) { edgeIDs.AddRange(v.Value); } } } DiagramElementQueryByObjectIDs query1 = new DiagramElementQueryByObjectIDs { JunctionObjectIDs = junctionIDs, ContainerObjectIDs = containerIDs, EdgeObjectIDs = edgeIDs }; deqr = Diagram.QueryDiagramElements(query1); } g_DiagramJunctionElements = deqr.DiagramJunctionElements.ToList(); g_DiagramEdgeElements = deqr.DiagramEdgeElements.ToList(); g_DiagramContainerElements = deqr.DiagramContainerElements.ToList(); }
/// <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> /// Run the rotate selected junctions /// </summary> /// <param name="rotation">Rotation Angle</param> private void RotateSelectedJunctions(double rotation) { if (MapView.Active != null) { // Get the Network Diagram Layer DiagramLayer diagramLayer = GetDiagramLayerFromMap(MapView.Active.Map); if (diagramLayer != null) { QueuedTask.Run(() => { // Get the Network Diagram NetworkDiagram diagram = diagramLayer.GetNetworkDiagram(); if (diagram != null) { try { List <long> junctionObjectIDs = new List <long>(); // get the selection by Layer SelectionSet selection = MapView.Active.Map.GetSelection(); // Get the selection only for junctions foreach (var v in selection.ToDictionary()) { FeatureLayer featureLayer = v.Key as FeatureLayer; if (featureLayer != null) { if (featureLayer.ShapeType != esriGeometryType.esriGeometryPoint) { continue; } junctionObjectIDs.AddRange(v.Value); } } // if no junction selected, work on all diagram junctions DiagramElementQueryResult result; if (junctionObjectIDs.Count == 0) { DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes { QueryDiagramContainerElement = false, QueryDiagramEdgeElement = false, QueryDiagramJunctionElement = true }; result = diagram.QueryDiagramElements(query); } else { DiagramElementQueryByObjectIDs query = new DiagramElementQueryByObjectIDs { AddConnected = false, AddContents = false, JunctionObjectIDs = junctionObjectIDs }; result = diagram.QueryDiagramElements(query); } List <DiagramJunctionElement> junctionsToSave = new List <DiagramJunctionElement>(); // Set the new Rotation Value foreach (var junction in result.DiagramJunctionElements) { if (_isRelative) { junction.Rotation += rotation; } else { junction.Rotation = rotation; } junctionsToSave.Add(junction); } // Save junctions if needed if (junctionsToSave.Count() > 0) { NetworkDiagramSubset nds = new NetworkDiagramSubset { DiagramEdgeElements = null, DiagramContainerElements = null, DiagramJunctionElements = junctionsToSave }; diagram.SaveLayout(nds, true); MapView.Active.Redraw(true); // re set the selection if (selection.Count > 0) { MapView.Active.Map.SetSelection(selection, SelectionCombinationMethod.New); } } } catch (GeodatabaseException e) { MessageBox.Show(e.Message, "Failed to Rotate Junctions "); } } }); } } }