示例#1
0
        public void DiagramElementQueryResultAndNetworkDiagramSubsetClasses(Geodatabase geodatabase, DiagramManager diagramManager, string diagramName)
        {
            // Retrieve a diagram
            using (NetworkDiagram diagramTest = diagramManager.GetNetworkDiagram(diagramName))
            {
                // Create a DiagramElementQueryByElementTypes query object to get the diagram elements we want to work with
                DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes();
                query.QueryDiagramJunctionElement  = true;
                query.QueryDiagramEdgeElement      = true;
                query.QueryDiagramContainerElement = true;

                // Retrieve those diagram elements
                DiagramElementQueryResult elements = diagramTest.QueryDiagramElements(query);

                // Create a NetworkDiagramSubset object to edit this set of diagram elements
                NetworkDiagramSubset subset = new NetworkDiagramSubset();
                subset.DiagramJunctionElements  = elements.DiagramJunctionElements;
                subset.DiagramEdgeElements      = elements.DiagramEdgeElements;
                subset.DiagramContainerElements = elements.DiagramContainerElements;

                // Edit the shapes of the diagram elements - left as an exercise for the student
                TranslateDiagramElements(subset);

                // Save the new layout of the diagram elements
                diagramTest.SaveLayout(subset, true);
            }
        }
        /// <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();
        }
示例#3
0
        /// <summary>
        /// Initialize class
        /// </summary>
        /// <param name="Diagram">NetworkDiagram</param>
        public void Initialize(NetworkDiagram Diagram)
        {
            _junctions.Clear();
            _edges.Clear();
            _containers.Clear();
            _adjacentEdges.Clear();
            _containment.Clear();

            DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes
            {
                QueryDiagramContainerElement = true,
                QueryDiagramEdgeElement      = true,
                QueryDiagramJunctionElement  = true
            };

            DiagramElementQueryResult deqr = Diagram.QueryDiagramElements(query);

            foreach (var container in deqr.DiagramContainerElements)
            {
                _containers[container.ID] = new CustomContainer(container);

                if (container.ContainerID > 0)
                {
                    AddContainment(container.ContainerID, container.ID);
                }
            }

            foreach (var junction in deqr.DiagramJunctionElements)
            {
                _junctions[junction.ID] = new CustomJunction(junction);

                if (junction.ContainerID > 0)
                {
                    AddContainment(junction.ContainerID, junction.ID);
                }
            }

            foreach (var edge in deqr.DiagramEdgeElements)
            {
                _edges[edge.ID] = new CustomEdge(edge);

                AddAdjacentEdge(edge.FromID, edge.ID);
                AddAdjacentEdge(edge.ToID, edge.ID);

                if (edge.ContainerID > 0)
                {
                    AddContainment(edge.ContainerID, edge.ID);
                }
            }
        }
示例#4
0
        /// <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);
        }
示例#5
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 ");
                            }
                        }
                    });
                }
            }
        }