Exemple #1
0
        // TODO: Selecting shall be done on actual IElement reference.
        // TODO: It seems to be non-working anyway.
        public void SelectEdge(string source, string target)
        {
            for (var i = 0; i < this.Graph.DataGraph.Edges.Count(); i++)
            {
                if (this.Graph.DataGraph.Edges.ToList()[i].Source.Name == source &&
                    this.Graph.DataGraph.Edges.ToList()[i].Target.Name == target)
                {
                    var edge = this.Graph.DataGraph.Edges.ToList()[i];
                    foreach (var ed in this.graphArea.EdgesList)
                    {
                        if (ed.Key == edge)
                        {
                            HighlightBehaviour.SetIsHighlightEnabled(ed.Value, true);
                            break;
                        }
                    }

                    break;
                }
            }
        }
Exemple #2
0
        private void calculateMinSpanTreeBoruvka()
        {
            resetEdgesHighligh();

            List <Edge> validEdges = new List <Edge>();
            List <Edge> usedEdges  = new List <Edge>();

            foreach (var edge in edgeCollection)
            {
                if (!isInUsedEdgelist(edge.src, edge.dest, usedEdges))
                {
                    validEdges.Add(edge);
                    validEdges[validEdges.Count - 1].index = validEdges.Count - 1;
                    usedEdges.Add(edge);
                }
            }

            Boruvka boruvka = new Boruvka();

            List <int> resultEdges = boruvka.start(validEdges, nodeCollection.Nodes.Count, validEdges.Count);

            foreach (var edge in validEdges)
            {
                Console.WriteLine("Valid edges: " + edge.index);
            }

            foreach (var edgeIndex in resultEdges)
            {
                highlightTheEdge(validEdges[edgeIndex].srcNode, validEdges[edgeIndex].destNode);
                highlightTheEdge(validEdges[edgeIndex].destNode, validEdges[edgeIndex].srcNode);
            }

            foreach (var vertex in _gArea.VertexList)
            {
                HighlightBehaviour.SetHighlighted(vertex.Value, true);
            }

            totalJarak = boruvka.totalJarak;
        }
        public void SelectNode(string name)
        {
            for (var i = 0; i < this.Graph.DataGraph.Vertices.Count(); i++)
            {
                if (this.Graph.DataGraph.Vertices.ToList()[i].Name == name)
                {
                    var vertex = this.Graph.DataGraph.Vertices.ToList()[i];
                    this.NodeSelected?.Invoke(this, new NodeSelectedEventArgs {
                        Node = vertex
                    });
                    foreach (var ed in this.graphArea.VertexList)
                    {
                        if (ed.Key == vertex)
                        {
                            HighlightBehaviour.SetIsHighlightEnabled(ed.Value, true);
                        }
                    }

                    break;
                }
            }
        }
        private void SelectVertex(VertexControl vc)
        {
            var v = vc.Vertex as DataVertex;

            if (v == null)
            {
                return;
            }

            if (_selectedVertices.Contains(v.Id))
            {
                _selectedVertices.Remove(v.Id);
                HighlightBehaviour.SetHighlighted(vc, false);
                //DragBehaviour.SetIsTagged(vc, false);
            }
            else
            {
                _selectedVertices.Add(v.Id);
                HighlightBehaviour.SetHighlighted(vc, true);
                //DragBehaviour.SetIsTagged(vc, true);
            }
        }
Exemple #5
0
        private void CreateEdgeControl(VertexControl vc)
        {
            if (_ecFrom == null)
            {
                _editorManager.CreateVirtualEdge(vc, vc.GetPosition());
                _ecFrom = vc;
                HighlightBehaviour.SetHighlighted(_ecFrom, true);
                return;
            }
            if (_ecFrom == vc)
            {
                return;
            }

            var data = new DataEdge((DataVertex)_ecFrom.Vertex, (DataVertex)vc.Vertex);
            var ec   = new EdgeControl(_ecFrom, vc, data);

            graphArea.InsertEdgeAndData(data, ec, 0, true);

            HighlightBehaviour.SetHighlighted(_ecFrom, false);
            _ecFrom = null;
            _editorManager.DestroyVirtualEdge();
        }
        private void CreateVertex(GraphArea area, ZoomControl zoom, DataVertex data = null, double x = double.MinValue, double y = double.MinValue)
        {
            _viewmodel.Do(new CreateVertexOperation(Area, data, x, y,
                                                    (v, vc) =>
            {
                _selectedVertices.Add(v.Id);

                //area.RelayoutGraph(true);

                UpdateHighlightBehaviour(false);

                foreach (var selectedV in _selectedVertices)
                {
                    var localvc = area.VertexList.Where(pair => pair.Key.Id == selectedV).Select(pair => pair.Value).FirstOrDefault();
                    HighlightBehaviour.SetHighlighted(localvc, true);
                }

                if (tbtnCanDrag.IsChecked.Value)
                {
                    DragBehaviour.SetIsDragEnabled(vc, true);
                }
                else
                {
                    DragBehaviour.SetIsDragEnabled(vc, false);
                }

                v.IsEditing          = true;
                v.OnPositionChanged -= v_OnPositionChanged;
                v.OnPositionChanged += v_OnPositionChanged;
            },
                                                    (v) =>
            {
                _selectedVertices.Remove(v.Id);
                //on vertex recreated
            }));
            //FitToBounds(area.Dispatcher, zoom);
        }
Exemple #7
0
        private void highlightPath(List <int> indexs)
        {
            Console.WriteLine("indexs:");
            foreach (var ind in indexs)
            {
                Console.WriteLine("indexs: " + ind);
            }
            _gArea.SetVerticesHighlight(false, (GraphControlType)1);

            foreach (var edge in _gArea.EdgesList)
            {
                HighlightBehaviour.SetHighlighted(edge.Value, false);
            }

            var index       = 0;
            var currentNode = nodeCollection.Nodes[0];
            var nextNode    = nodeCollection.Nodes[0];

            for (int i = 0; i < indexs.Count; i++)
            {
                index       = indexs[i];
                currentNode = nodeCollection.Nodes[index];

                Console.WriteLine("Current Node: " + currentNode.name);

                if (i + 1 < indexs.Count)
                {
                    nextNode = nodeCollection.Nodes[indexs[i + 1]];

                    highlightTheEdge(currentNode, nextNode);
                    highlightTheEdge(nextNode, currentNode);
                }

                HighlightBehaviour.SetHighlighted(_gArea.VertexList[currentNode.vertex], true);
            }
        }
        public void CreateEdge(int fromId, int toId)
        {
            if (View == null)
            {
                return;
            }

            var area   = View.Area;
            var source = area.VertexList.Where(pair => pair.Key.Id == fromId).Select(pair => pair.Key).FirstOrDefault();
            var target = area.VertexList.Where(pair => pair.Key.Id == toId).Select(pair => pair.Key).FirstOrDefault();

            if (source == null || target == null)
            {
                return;
            }

            Do(new CreateEdgeOperation(area, source, target,
                                       (e) =>
            {
                //on vertex created
                //_selectedVertices.Add(v.Id);

                HighlightBehaviour.SetIsHighlightEnabled(e, false);
                HighlightBehaviour.SetHighlighted(e, false);

                HighlightBehaviour.SetHighlighted(area.VertexList[source], false);
                HighlightBehaviour.SetHighlighted(area.VertexList[target], false);

                //UpdateIsInEditing(true);
            },
                                       (e) =>
            {
                //_selectedVertices.Remove(v.Id);
                //on vertex recreated
            }));
        }
 //-------------------------------------Highlight functions -----------------------------------------
 void CreateHighlight()
 {
     areaHighlight = Instantiate(areaHighlightPrefab.gameObject).GetComponent <HighlightBehaviour>();
     SetHighlightActive(false);
 }
 //================================================================================
 // Highlight functions
 //================================================================================
 void CreateHighlight()
 {
     areaHighlight = Instantiate(areaHighlightPrefab.gameObject).GetComponent <HighlightBehaviour>();
     areaHighlight.AdjustHighlightScaleAndOffsetFor(indicator);
 }
 private void Awake()
 {
     instance            = this;
     WordHunt.FoundWord += SetLineRenderer;
 }
        internal void AddEdge(DataEdge data, EdgeControl ec, VertexControl ecFrom, CableConfiguration cableConfiguration = null)
        {
            if (data == null)
            {
                return;
            }

            if (_ecFrom == null)
            {
                VertexControl vc = GetVertexControlWithDataVertex(data.Source.Element_id);;
                _ecFrom = vc;
            }


            if (mainWindow.graphView.Area.EdgesList.ContainsKey(data))
            {
                return;
            }

            if (graphState == GraphState.NORMAL)
            {
                data.Length = length;
                data.Text   = length.ToString();
            }

            if (data.Source.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX || data.Source.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX)
            {
                cableConfiguration = new CableConfiguration()
                {
                    Name = "xfm_1"
                };
                data.Configuration = cableConfiguration;
            }

            if (mainWindow.GlobalEdges.ContainsKey(data.Source.Element_id))
            {
                mainWindow.GlobalEdges[data.Source.Element_id].Add(data);
            }
            else
            {
                mainWindow.GlobalEdges.Add(data.Source.Element_id, new List <DataEdge>()
                {
                    data
                });
            }


            bool its_needed = CheckIfLabelNeeded(data);

            if (its_needed)
            {
                mainWindow.graphView.Area.AddEdge(data, ec, true);
            }
            else
            {
                mainWindow.graphView.Area.AddEdge(data, ec, false);
            }



            setEdgesDashStyle(ec, data.Source.typeOfVertex);

            HighlightBehaviour.SetHighlighted(_ecFrom, true);
            _ecFrom = null;
            DestroyVirtualEdge();
            mainWindow.segmentData.IsEnabled = true;


            if (graphState == GraphState.NORMAL)
            {
                undoRedoCommander.addUndoCommand(new Command("AddEdge", data));
            }
        }
        public void ConnectEdges(VertexControl vc, double length = 0)
        {
            if (_ecFrom == null)
            {
                CreateVirtualEdge(vc, vc.GetPosition());
                _ecFrom = vc;
                HighlightBehaviour.SetHighlighted(_ecFrom, true);
                return;
            }

            if (_ecFrom == vc)
            {
                return;
            }

            if ((DataVertex)_ecFrom.Vertex == null)
            {
                return;
            }

            var data = new DataEdge((DataVertex)_ecFrom.Vertex, (DataVertex)vc.Vertex);

            data.Length = length;

            //if (graphState == GraphState.PARTIAL_CONNECTING)
            //{

            //    if ((_ecFrom.Vertex as DataVertex).typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_PARTIAL_VERTEX)
            //    {
            //        DataVertexRegulator dvr_temp = (vc.Vertex as DataVertexRegulator);
            //        dvr_temp.CompensatorSettingsB = dvrp.CompensatorSettingsB;
            //        dvr_temp.Line_Segment_To = dvrp.Element_id;
            //        dvr_temp.R_SettingB = dvrp.R_SettingB;
            //        dvr_temp.VoltageLevelB = dvrp.VoltageLevelB;
            //        dvr_temp.X_SettingB = dvrp.X_SettingB;
            //    }
            //    else if ((_ecFrom.Vertex as DataVertex).typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX)
            //    {
            //        DataVertexRegulator dvr_temp = (_ecFrom.Vertex as DataVertexRegulator);
            //        dvr_temp.CompensatorSettingsB = dvrp.CompensatorSettingsB;
            //        dvr_temp.Line_Segment_To = dvrp.Element_id;
            //        dvr_temp.R_SettingB = dvrp.R_SettingB;
            //        dvr_temp.VoltageLevelB = dvrp.VoltageLevelB;
            //        dvr_temp.X_SettingB = dvrp.X_SettingB;
            //    }

            //}

            var ec = new EdgeControl(_ecFrom, vc, data);

            ec.DashStyle = EdgeDashStyle.DashDot;

            if (CheckIfConnectionExists(data) == true)
            {
                MessageBox.Show("Already connected!");
                return;
            }

            if (graphState == GraphState.PARTIAL_CONNECTING)
            {
                (mainWindow.graphView.DataContext as GraphViewModel).AddEdge(data, ec, _ecFrom);
                return;
            }

            w = new Window();
            w = new EdgeConfigurationView((DataVertex)_ecFrom.Vertex, mainWindow.GlobalVertices, null,
                                          ((DataVertex)vc.Vertex).Element_id, mainWindow.GlobalEdges, false, vc, null,
                                          mainWindow, mainWindow.GlobalCableConfiguration, ec, data, _ecFrom);
            w.Show();
        }