private void SymbolCanvas_PointerReleased(object sender, PointerRoutedEventArgs e) { if (_symbolPointerPressed) { _symbolPointerPressed = false; if (SelectedShapes.Count > 0) { SelectedShapes.Clear(); SetIdleOnVoid(); } else { foreach (var shape in SymbolShapes) { SelectedShapes.Add(shape); } SetShapesAreSelected(); } PickerShape = null; PickerCanvas.Invalidate(); } }
private void ScaleShape(Shape shape) { SelectedShapes.Clear(); SelectedShapes.Add(shape); if (FocusedShapes != shape) { FocusedShapes = null; } EditMode = EditMode.Scale; }
public void CreateGroup(GroupShapes gr) { foreach (var shape in gr.Children) { DrawnShapes.Remove(shape); SelectedShapes.Remove(shape); } DrawnShapes.Add(gr); SelectedShapes.Add(gr); CreateMemento(); }
private void PasteButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (CutCopyShapes.Count > 0) { SelectedShapes.Clear(); foreach (var template in CutCopyShapes) { var shape = template.Clone(); SymbolShapes.Add(shape); SelectedShapes.Add(shape); } SetShapesAreSelected(); EditorCanvas.Invalidate(); } }
private void HandleSelectionEnded(object sender, MouseButtonEventArgs e) { if (!CanvasSelectable) { return; //Canvas is marked as not selectable, abort } Point pos = e.GetPosition(c); var raycastResult = GetSelectedShapes(c, new RectangleGeometry(new Rect(Math.Min(pos.X, selectionStartPoint.X), Math.Min(pos.Y, selectionStartPoint.Y), selectionRectangle.Width, selectionRectangle.Height))); foreach (Shape s in raycastResult) { SelectedShapes.Add(s); } c.Children.Remove(selectionRectangle); selectionRectangle.Visibility = Visibility.Collapsed; }
public void AddRemoveSelectedShape(int x, int y) { var shape = DrawnShapes.LastOrDefault(s => s.Contains(x, y)); if (shape == null) { SelectedShapes.Clear(); } else { if (!SelectedShapes.Contains(shape)) { SelectedShapes.Add(shape); } else { SelectedShapes.Remove(shape); } } _g.RefreshView(); }
private void ShapeSelectorHit(int index) { var shape = SymbolShapes[index]; if (IsSelectOneOrMoreShapeMode) { if (SelectedShapes.Contains(shape)) { SelectedShapes.Remove(shape); } else { SelectedShapes.Add(shape); } } else { SelectedShapes.Clear(); SelectedShapes.Add(shape); } GrtProperty(shape); PickerShape = null; if (SelectedShapes.Count > 0) { SetShapesAreSelected(); } else { SetIdleOnVoid(); } PickerShape = null; SetSizeSliders(); PickerCanvas.Invalidate(); EditorCanvas.Invalidate(); }
/* this function was rewritten in early May 2011 to handle hyperarcs, but also in pursuit of * more efficient code as it seemed to be a bottleneck for large graphs. The following is thus * "optimized" code which is not necessarily easy to follow, and could be more succinct. However, * the goal to remove looping overall all the graph elements has been eliminated. This was the * more "elegant" approach in the old method, but takes a long time for large graphs. */ public void UpdateSelection() { try { Clear(); var elements = gd.GetSelectedElements().Cast <FrameworkElement>().ToList(); /* the following if is figure out when dragging an empty arc endpoint */ if ((elements.Count == 1) && (elements[0] is NullNodeIconShape)) { gd.activeNullNode = (NullNodeIconShape)elements[0]; gd.Select(SelectedShapes); if (gd.activeNullNode.GraphElement is arc) { ((DisplayShape)gd.activeNullNode.GraphElement.DisplayShape).icon.Selected = true; selectedArcs.Add((arc)gd.activeNullNode.GraphElement); } else { ((DisplayShape)gd.activeNullNode.GraphElement.DisplayShape).icon.Selected = true; selectedHyperArcs.Add((hyperarc)gd.activeNullNode.GraphElement); } return; } /* else, you are not dragging an arc and have selected a set of nodes and arcs. */ int i = 0; while (i < elements.Count) { if (elements[i] is NodeIconShape) { /*select node*/ var icon = (NodeIconShape)elements[i]; var n = icon.GraphElement; var s = (FrameworkElement)n.DisplayShape.Shape; selectedNodes.Add((node)n); if ((icon.Width > s.Width) && (icon.Height > s.Height)) { SelectedShapes.Add(icon); } elements.RemoveAt(i); /*select node shape*/ SelectedShapes.Add(s); var index = elements.IndexOf(s); if (index >= 0) { elements.RemoveAt(index); if (index <= i) { i--; } } } else if (elements[i] is ArcIconShape) { /*select arc*/ var a = ((ArcIconShape)elements[i]).GraphElement; selectedArcs.Add((arc)a); /*select icon*/ // SelectedShapes.Add(elements[i]); ((ArcIconShape)elements[i]).Selected = true; elements.RemoveAt(i); /*select arc shape*/ //SelectedShapes.Add((FrameworkElement)a.DisplayShape.Shape); elements.Remove((FrameworkElement)a.DisplayShape.Shape); } else if (elements[i] is ArcShape) { /*select arc*/ var icon = ((ArcShape)elements[i]).icon; var a = icon.GraphElement; selectedArcs.Add((arc)a); /*select icon*/ // SelectedShapes.Add(icon); icon.Selected = true; elements.Remove(icon); /*select arc shape*/ //SelectedShapes.Add(elements[i]); elements.RemoveAt(i); } else if (elements[i] is HyperArcIconShape) { /*select node*/ var h = ((HyperArcIconShape)elements[i]).GraphElement; selectedHyperArcs.Add((hyperarc)h); /*select icon*/ ((HyperArcIconShape)elements[i]).Selected = true; elements.RemoveAt(i); /*select node shape*/ elements.Remove((FrameworkElement)h.DisplayShape.Shape); } else if (elements[i] is HyperArcShape) { /*select node*/ var icon = ((HyperArcShape)elements[i]).icon; var h = icon.GraphElement; selectedHyperArcs.Add((hyperarc)h); /*select icon*/ icon.Selected = true; elements.Remove(icon); /*select node shape*/ elements.RemoveAt(i); } else { i++; } } /* now anything that's left may be a node shape */ foreach (var e in elements) { if (!gd.nodeShapes.Contains(e)) { continue; } var n = gd.getNodeFromShape(e); if (n == null) { continue; } var icon = ((DisplayShape)n.DisplayShape).icon; // what if e is a null shape? /*select node*/ selectedNodes.Add(n); /*select icon*/ if ((icon.Width > e.Width) && (icon.Height > e.Height)) { SelectedShapes.Add(icon); } /*select node shape*/ SelectedShapes.Add(e); } /* now we need to add any arcs that have both their nodes (To, From) in the selection. */ if (selectedNodes.Count > 0) { /* three actions are performed in this condition. First we find the reference point * (else it's at the origin). Second, we select and implicitly selected arcs - arcs * which have both of their nodes selected. And finally, we select all the implicitly * selected hyperarcs. */ /* First */ ReferencePoint = new Point(selectedNodes.Min(n => n.X), selectedNodes.Min(n => n.Y)); /* Second */ var implicitSelectArcs = selectedNodes.SelectMany(n => n.arcsFrom); implicitSelectArcs = implicitSelectArcs.Intersect(selectedNodes.SelectMany(n => n.arcsTo)); foreach (var a in implicitSelectArcs) { ((DisplayShape)a.DisplayShape).icon.Selected = true; } selectedArcs = selectedArcs.Union(implicitSelectArcs).ToList(); /* Third */ var implicitHyperArcs = selectedNodes.SelectMany(n => n.arcs) .Where(h => h is hyperarc).Cast <hyperarc>().ToList(); implicitHyperArcs.RemoveAll(h => (selectedHyperArcs.Contains(h) || (h.nodes.Intersect(selectedNodes).Count() < h.nodes.Count))); selectedHyperArcs = selectedHyperArcs.Union(implicitHyperArcs).ToList(); foreach (hyperarc h in implicitHyperArcs) { ((DisplayShape)h.DisplayShape).icon.Selected = true; } } else { ReferencePoint = new Point(); } gd.Select(SelectedShapes); } catch (Exception exc) { ErrorLogger.Catch(exc); } }