private void GraphBehavior_EdgesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Remove everything deleted from selection switch (e.Action) { case NotifyCollectionChangedAction.Add: break; case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Replace: foreach (var oldItem in e.OldItems) { SelectedEdges.Remove(oldItem); } break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Reset: var edges = (IList)sender; for (int index = 0; index < SelectedVertices.Count; index++) { if (!edges.Contains(SelectedEdges[index])) { SelectedEdges.RemoveAt(index--); } } break; default: throw new ArgumentOutOfRangeException(); } }
AlgorithmBlob(TabCanvas tabCanvas) { UIGraph = tabCanvas.GraphCanvas.Graph; AlgorithmGraph = new Choosability.Graph(UIGraph.GetEdgeWeights()); BitGraph = new BitLevelGeneration.BitGraph_long(UIGraph.GetEdgeWeights()); SelectedVertices = UIGraph.Vertices.Select((v, i) => v.IsSelected ? i : -1).Where(x => x >= 0).ToList(); SelectedEdges = UIGraph.Edges.Where(e => e.IsSelected).Select(e => new Tuple <int, int>(UIGraph.Vertices.IndexOf(e.V1), UIGraph.Vertices.IndexOf(e.V2))).ToList(); EdgeIndexLookup = new Dictionary <Tuple <int, int>, int>(); int k = 0; for (int i = 0; i < AlgorithmGraph.N; i++) { for (int j = i + 1; j < AlgorithmGraph.N; j++) { if (AlgorithmGraph[i, j]) { EdgeIndexLookup[new Tuple <int, int>(i, j)] = k; EdgeIndexLookup[new Tuple <int, int>(j, i)] = k; k++; } } } SelectedEdgeIndices = SelectedEdges.Select(tuple => EdgeIndexLookup[tuple]).ToList(); }
internal void SelectEdges(List <Edge> passingEdges) { SelectedEdges.InsertRange(passingEdges); for (int i = _levels.Count - 1; i >= 0; i--) { SelectEdgesOnLevel(i, passingEdges); } }
public void UnselectColoredEdges(List <Edge> edgesToPutOff, object color) { //do not put off all the edges, otherwise it will cause disconnected components in //multiple selection Set <Rail> railsOfEdge = new Set <Rail>(); Dictionary <Edge, Boolean> removeEdge = new Dictionary <Edge, Boolean>(); foreach (Edge e in edgesToPutOff) { for (int i = _levels.Count - 1; i >= 0; i--)//int i = Levels.Count - 1; { if (_levels[i]._railsOfEdges.ContainsKey(e) == false) { continue; //is it a bug? } railsOfEdge = _levels[i]._railsOfEdges[e]; foreach (var r in railsOfEdge) { if (r.Color == null) { continue; } if (r.Color.Count >= 1) { if (!removeEdge.ContainsKey(e)) { removeEdge[e] = true; } } r.Color.Remove(color); } } if (!removeEdge.ContainsKey(e)) { e.Color = null; } } //foreach (Edge e in removeEdge.Keys) //edgesToPutOff.Remove(e); var edgesToPutoffSet = new Set <Edge>(edgesToPutOff); for (int i = _levels.Count - 1; i >= 0; i--) { PutOffEdgesOnLevel(i, edgesToPutoffSet); } foreach (var e in edgesToPutOff) { SelectedEdges.Remove(e); } }
public void UnselectEdges(List <Edge> edgesToPutOff) { var edgesToPutoffSet = new Set <Edge>(edgesToPutOff); for (int i = _levels.Count - 1; i >= 0; i--) { PutOffEdgesOnLevel(i, edgesToPutoffSet); } foreach (var e in edgesToPutOff) { SelectedEdges.Remove(e); } }
internal void SelectEdges(List <Edge> passingEdges, int currentLayer) { SelectedEdges.InsertRange(passingEdges); foreach (Edge edge in passingEdges) { for (int i = 0; i <= currentLayer; i++) { Set <Rail> railsOfEdge; if (_levels[i]._railsOfEdges.TryGetValue(edge, out railsOfEdge)) { var passingEdge = new List <Edge>(); passingEdge.Add(edge); SelectEdgesOnLevel(i, passingEdge); } } } }
public void PutOffAllEdges() { UnselectEdges(SelectedEdges.ToList()); }
public void UnselectEdges(List <Edge> edgesToPutOff) { Set <Rail> railsOfEdge = new Set <Rail>(); Dictionary <Edge, Boolean> removeEdge = new Dictionary <Edge, Boolean>(); foreach (Edge e in edgesToPutOff) { //this for loop seems helping the keypress='end' for (int i = _levels.Count - 1; i >= 0; i--) //int i = Levels.Count-1; { if (_levels[i]._railsOfEdges.ContainsKey(e) == false) { continue; } railsOfEdge = _levels[i]._railsOfEdges[e]; foreach (var r in railsOfEdge) { if (r.Color == null || r.Color.Count == 0) { continue; } if (r.Color.Count > 1) { if (!removeEdge.ContainsKey(e)) { removeEdge[e] = true; } } r.Color.Remove(e.Color); } } if (!removeEdge.ContainsKey(e)) { e.Color = null; } } foreach (Edge e in removeEdge.Keys) { edgesToPutOff.Remove(e); } var edgesToPutoffSet = new Set <Edge>(edgesToPutOff); for (int i = _levels.Count - 1; i >= 0; i--) { PutOffEdgesOnLevel(i, edgesToPutoffSet); } /* * foreach (Edge edge in edgesToPutOff) * { * for (int i = 0; i <= _levels.Count - 1; i++){ * Set<Rail> railsOfEdge; * if (_levels[i]._railsOfEdges.TryGetValue(edge, out railsOfEdge)) * { * var PutoffSet = new List<Edge>(); * PutoffSet.Add(edge); * PutOffEdgesOnLevel(i, new Set<Edge>(PutoffSet)); * break; * } * } * } */ foreach (var e in edgesToPutOff) { SelectedEdges.Remove(e); } }