示例#1
0
 protected override void OnLayerChanged(DiagramLayer oldLayer, DiagramLayer newLayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldLayer, newLayer, mainObj);
     if (((oldLayer != null) && (newLayer == null)) && oldLayer.IsInDocument)
     {
         DiagramDocument       document1   = oldLayer.Document;
         IDictionaryEnumerator enumerator1 = this.Map.GetEnumerator();
         while (enumerator1.MoveNext())
         {
             DictionaryEntry entry1   = enumerator1.Entry;
             DiagramView     view1    = (DiagramView)entry1.Key;
             Control         control1 = (Control)entry1.Value;
             if ((view1 != null) && (control1 != null))
             {
                 this.DisposeControl(control1, view1);
             }
         }
         this.Map.Clear();
     }
     else if (((oldLayer != null) && (newLayer == null)) && oldLayer.IsInView)
     {
         DiagramView view2    = oldLayer.View;
         Control     control2 = this.FindControl(view2);
         if (control2 != null)
         {
             this.Map.Remove(view2);
             if (control2 != null)
             {
                 this.DisposeControl(control2, view2);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Get Utility Network from a map
        /// </summary>
        /// <param name="map">Map, use the active map if missing</param>
        /// <returns>Utility Network</returns>
        internal static UtilityNetwork GetUtilityNetworkFromActiveMap(Map map = null)
        {
            if (map == null)
            {
                map = MapView.Active.Map;
            }
            if (map == null)
            {
                return(null);
            }

            IReadOnlyList <Layer> myLayers = map.GetLayersAsFlattenedList();

            foreach (Layer l in myLayers)
            {
                if (l.GetType() == typeof(UtilityNetworkLayer))
                {
                    return(((UtilityNetworkLayer)l).GetUtilityNetwork());
                }
                else if (l.GetType() == typeof(DiagramLayer))
                {
                    DiagramLayer   dl = l as DiagramLayer;
                    NetworkDiagram nd = dl.GetNetworkDiagram();
                    return(nd.DiagramManager.GetNetwork <UtilityNetwork>());
                }
            }

            return(null);
        }
示例#3
0
        public async void CreateDiagramLayerFromNetworkDiagram(NetworkDiagram myDiagram)
        {
            #region Open a diagram window from a Network Diagram

            // Create a diagram layer from a NetworkDiagram (myDiagram)
            DiagramLayer diagramLayer = await QueuedTask.Run <DiagramLayer>(() =>
            {
                // Create the diagram map
                var newMap = MapFactory.Instance.CreateMap(myDiagram.Name, ArcGIS.Core.CIM.MapType.NetworkDiagram, MapViewingMode.Map);
                if (newMap == null)
                {
                    return(null);
                }

                // Open the diagram map
                var mapPane = ArcGIS.Desktop.Core.ProApp.Panes.CreateMapPaneAsync(newMap, MapViewingMode.Map);
                if (mapPane == null)
                {
                    return(null);
                }

                //Add the diagram to the map
                return(newMap.AddDiagramLayer(myDiagram));
            });

            #endregion
        }
示例#4
0
 protected override void OnLayerChanged(DiagramLayer oldlayer, DiagramLayer newlayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (((oldlayer != null) && (newlayer == null)) && (this.Anchor != null))
     {
         this.Anchor.RemoveObserver(this);
     }
 }
示例#5
0
        public virtual void Unlink()
        {
            DiagramLayer layer1 = base.Layer;

            if (layer1 != null)
            {
                layer1.Remove(this);
            }
        }
        /// <summary>
        /// Apply the layout to the layer
        /// </summary>
        /// <param name="diagramLayer">Diagram Layer</param>
        public void Apply(DiagramLayer diagramLayer)
        {
            if (diagramLayer == null)
            {
                return;
            }
            QueuedTask.Run(() =>
            {
                try
                {
                    NetworkDiagram Diagram = diagramLayer.GetNetworkDiagram();
                    Execute(Diagram);

                    MapView.Active.Redraw(true);
                    MapView.Active.ZoomTo(Diagram.GetDiagramInfo().DiagramExtent.Expand(1.08, 1.08, true));
                }
                catch (Exception ex)
                {
                    CreateDiagramWithACustomLayoutModule.ShowException(ex);
                }
            });
        }
示例#7
0
 protected virtual void OnLayerChanged(DiagramLayer oldlayer, DiagramLayer newlayer, DiagramShape mainObj)
 {
 }
示例#8
0
 internal void SetLayer(DiagramLayer value, DiagramShape mainObj, bool undoing)
 {
     GroupShape group1 = this as GroupShape;
     if (group1 != null)
     {
         DiagramShape[] objArray1 = group1.CopyArray();
         for (int num1 = 0; num1 < objArray1.Length; num1++)
         {
             DiagramShape obj1 = objArray1[num1];
             obj1.SetLayer(value, mainObj, undoing);
         }
     }
     DiagramLayer layer1 = this.myLayer;
     DiagramLayer layer2 = value;
     if (layer1 != layer2)
     {
         if (layer2 == null)
         {
             if (!undoing)
             {
                 this.OnLayerChanged(layer1, null, mainObj);
             }
             this.myLayer = null;
         }
         else
         {
             this.myLayer = layer2;
             if (!undoing)
             {
                 this.OnLayerChanged(layer1, layer2, mainObj);
             }
         }
     }
 }
示例#9
0
 protected override void OnLayerChanged(DiagramLayer oldLayer, DiagramLayer newLayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldLayer, newLayer, mainObj);
     if (((oldLayer != null) && (newLayer == null)) && oldLayer.IsInDocument)
     {
         DiagramDocument document1 = oldLayer.Document;
         IDictionaryEnumerator enumerator1 = this.Map.GetEnumerator();
         while (enumerator1.MoveNext())
         {
             DictionaryEntry entry1 = enumerator1.Entry;
             DiagramView view1 = (DiagramView)entry1.Key;
             Control control1 = (Control)entry1.Value;
             if ((view1 != null) && (control1 != null))
             {
                 this.DisposeControl(control1, view1);
             }
         }
         this.Map.Clear();
     }
     else if (((oldLayer != null) && (newLayer == null)) && oldLayer.IsInView)
     {
         DiagramView view2 = oldLayer.View;
         Control control2 = this.FindControl(view2);
         if (control2 != null)
         {
             this.Map.Remove(view2);
             if (control2 != null)
             {
                 this.DisposeControl(control2, view2);
             }
         }
     }
 }
示例#10
0
        /// <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 ");
                            }
                        }
                    });
                }
            }
        }
示例#11
0
 protected override void OnLayerChanged(DiagramLayer oldlayer, DiagramLayer newlayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (((oldlayer != null) && (newlayer == null)) && (this.Anchor != null))
     {
         this.Anchor.RemoveObserver(this);
     }
 }
示例#12
0
        /// <summary>
        /// Apply the layout to the diagram layer
        /// </summary>
        /// <param name="diagramLayer">Diagram Layer</param>
        public void Apply(DiagramLayer diagramLayer)
        {
            if (diagramLayer == null)
            {
                return;
            }
            try
            {
                QueuedTask.Run(() =>
                {
                    NetworkDiagram Diagram = diagramLayer.GetNetworkDiagram();

                    var selection = MapView.Active.Map.GetSelection();
                    if (selection != null && selection.Count > 0)
                    {
                        List <long> JunctionObjectIDs  = new List <long>();
                        List <long> ContainerObjectIDs = new List <long>();
                        List <long> EdgeObjectIDs      = new List <long>();

                        foreach (var v in selection.ToDictionary())
                        {
                            if (v.Key is FeatureLayer layer)
                            {
                                if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPoint)
                                {
                                    JunctionObjectIDs.AddRange(v.Value);
                                }
                                else if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolygon)
                                {
                                    ContainerObjectIDs.AddRange(v.Value);
                                }
                                else if (layer.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolyline)
                                {
                                    EdgeObjectIDs.AddRange(v.Value);
                                }
                            }
                        }

                        Diagram.ApplyLayout(layoutParameters, new DiagramElementObjectIDs
                        {
                            ContainerObjectIDs = ContainerObjectIDs,
                            JunctionObjectIDs  = JunctionObjectIDs,
                            EdgeObjectIDs      = EdgeObjectIDs
                        }, ArcGIS.Core.Data.ServiceSynchronizationType.Synchronous);
                    }
                    else
                    {
                        Diagram.ApplyLayout(layoutParameters, ArcGIS.Core.Data.ServiceSynchronizationType.Synchronous);
                    }

                    MapView.Active.Redraw(true);
                    MapView.Active.ZoomTo(Diagram.GetDiagramInfo().DiagramExtent.Expand(1.05, 1.05, true));

                    if (FrameworkApplication.CurrentTool.Contains("_networkdiagrams_"))
                    {
                        FrameworkApplication.SetCurrentToolAsync("esri_mapping_exploreTool");
                    }
                });
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }
示例#13
0
 protected override void OnLayerChanged(DiagramLayer oldlayer, DiagramLayer newlayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (((newlayer == null) && !this.NoClearPorts) && ((mainObj is IDiagramLine) || !base.IsChildOf(mainObj)))
     {
         IDiagramLine link1 = this.AbstractLink;
         IDiagramPort port1 = this.FromPort;
         if (port1 != null)
         {
             port1.RemoveLink(link1);
         }
         IDiagramPort port2 = this.ToPort;
         if (port2 != null)
         {
             port2.RemoveLink(link1);
         }
     }
     else if (newlayer != null)
     {
         IDiagramLine link2 = this.AbstractLink;
         IDiagramPort port3 = this.FromPort;
         if (port3 != null)
         {
             port3.AddDestinationLink(link2);
         }
         IDiagramPort port4 = this.ToPort;
         if (port4 != null)
         {
             port4.AddSourceLink(link2);
         }
     }
 }
示例#14
0
 protected override void OnLayerChanged(DiagramLayer oldlayer, DiagramLayer newlayer, DiagramShape mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (this.Editor != null)
     {
         DiagramView view1 = this.Editor.View;
         if (view1 != null)
         {
             this.DoEndEdit(view1);
         }
     }
 }
示例#15
0
 public static void ReparentToCommonSubGraph(DiagramShape obj, DiagramShape child1, DiagramShape child2, bool behind, DiagramLayer layer)
 {
     SubGraphNode graph1 = SubGraphNode.FindParentSubGraph(child1);
     SubGraphNode graph2 = SubGraphNode.FindParentSubGraph(child2);
     DiagramShape obj1 = DiagramShape.FindCommonParent(graph1, graph2);
     while ((obj1 != null) && !(obj1 is SubGraphNode))
     {
         obj1 = obj1.Parent;
     }
     SubGraphNode graph3 = obj1 as SubGraphNode;
     if ((obj.Parent != graph3) || (obj.Layer == null))
     {
         if ((obj.Parent == null) && (obj.Layer == null))
         {
             if (graph3 != null)
             {
                 if (behind)
                 {
                     graph3.InsertBefore(null, obj);
                 }
                 else
                 {
                     graph3.InsertAfter(null, obj);
                 }
             }
             else
             {
                 layer.Add(obj);
             }
         }
         else
         {
             DiagramShapeCollection collection1 = new DiagramShapeCollection();
             collection1.Add(obj);
             if (graph3 != null)
             {
                 graph3.AddCollection(collection1, false);
             }
             else
             {
                 layer.AddCollection(collection1, false);
             }
         }
     }
 }
示例#16
0
 public static void ReparentAllLinksToSubGraphs(IDiagramShapeCollection coll, bool behind, DiagramLayer layer)
 {
     foreach (DiagramShape obj1 in coll)
     {
         IDiagramNode node1 = obj1 as IDiagramNode;
         if (node1 != null)
         {
             foreach (IDiagramLine link1 in node1.Links)
             {
                 if (((link1 != null) && (link1.FromPort != null)) && (link1.ToPort != null))
                 {
                     SubGraphNode.ReparentToCommonSubGraph(link1.DiagramShape, link1.FromPort.DiagramShape, link1.ToPort.DiagramShape, behind, layer);
                 }
             }
             continue;
         }
         IDiagramPort port1 = obj1 as IDiagramPort;
         if (port1 != null)
         {
             foreach (IDiagramLine link2 in port1.Links)
             {
                 if (((link2 != null) && (link2.FromPort != null)) && (link2.ToPort != null))
                 {
                     SubGraphNode.ReparentToCommonSubGraph(link2.DiagramShape, link2.FromPort.DiagramShape, link2.ToPort.DiagramShape, behind, layer);
                 }
             }
             continue;
         }
         IDiagramLine link3 = obj1 as IDiagramLine;
         if (((link3 != null) && (link3.FromPort != null)) && (link3.ToPort != null))
         {
             SubGraphNode.ReparentToCommonSubGraph(link3.DiagramShape, link3.FromPort.DiagramShape, link3.ToPort.DiagramShape, behind, layer);
         }
     }
 }