public static void RecalculateAllDependents(this IFigure figure) { DependencyAlgorithms .FindDescendants(f => f.Dependents, new IFigure[] { figure }) .Reverse() .ForEach(f => f.RecalculateAndUpdateVisual()); }
protected override bool CanSelectFigure(IFigure figure) { if (DependencyAlgorithms.FigureCompletelyDependsOnFigures(figure, GetSelection().Without(figure))) { return(false); } return(true); }
public static void RecalculateAllDependents(this IFigure figure) { var dependentsToRecalculate = DependencyAlgorithms .FindDescendants(f => f.Dependents, new IFigure[] { figure }); dependentsToRecalculate.Reverse(); foreach (var dependent in dependentsToRecalculate) { dependent.RecalculateAndUpdateVisual(); } }
protected override bool CanSelectFigure(IFigure figure) { if (Inputs.Contains(figure)) { return(false); } if (DependencyAlgorithms.FigureCompletelyDependsOnFigures(figure, Inputs)) { return(true); } return(false); }
protected override void TrySelectFigure(IFigure figure) { if (!CanSelectFigure(figure)) { return; } SelectFigure(figure); foreach (var selected in GetSelection()) { if (DependencyAlgorithms.FigureCompletelyDependsOnFigures(selected, GetSelection().Without(selected))) { DeselectFigure(selected); } } }
protected override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { base.MouseLeftButtonDown(sender, e); if (e.Handled) { return; } offsetFromFigureLeftTopCorner = Coordinates(e); oldCoordinates = offsetFromFigureLeftTopCorner; moving = new List <IMovable>(); IEnumerable <IFigure> roots = null; IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner); IEnumerable <IFigure> selection = null; // 11-12-2010 Scott if (IsCtrlPressed()) { if (found != null) { found.Selected = !found.Selected; } selection = Drawing.GetSelectedFigures(); } else { if (found == null || !found.Selected) { Drawing.ClearSelectedFigures(); if (found != null && (found is Game.PBPlayer || found is LabelBase || found is LineBase)) // 11-19-2010 Scott { found.Selected = true; selection = found.AsEnumerable(); } } } Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs(Drawing.GetSelectedFigures())); IMovable oneMovable = found as IMovable; if (oneMovable != null) { offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates); moving.Add(oneMovable); roots = found.AsEnumerable(); } else if (found != null) { if (!(found is Game.Zone) && !(found is LineBase)) // 11-19-2010 Scott { roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found); if (roots.All(root => root is IMovable)) { moving.AddRange(roots.Cast <IMovable>()); } } } if (roots != null) { toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots).Reverse(); } else { toRecalculate = null; } if (moving.IsEmpty()) { toRecalculate = null; } //if (found == null) //{ // if (!Drawing.Canvas.Children.Contains(SelectRect)) // { // Drawing.Canvas.Children.Add(SelectRect); // } // System.Windows.Controls.Canvas.SetLeft(SelectRect, e.GetPosition(Drawing.Canvas).X); // System.Windows.Controls.Canvas.SetTop(SelectRect, e.GetPosition(Drawing.Canvas).Y); // SelectRect.Visibility = Visibility.Visible; //} Drawing.Figures.UpdateVisual(); }
List <IFigure> GetFiguresToRecalculate(PointOnFigure pointOnFigure, IPoint dependentPoint) { return(DependencyAlgorithms.FindImpactedDependencyChain(pointOnFigure, dependentPoint)); }
private void LButtonDown(Point pt) { offsetFromFigureLeftTopCorner = this.ToLogical(pt); oldCoordinates = offsetFromFigureLeftTopCorner; moving = new List <IMovable>(); IEnumerable <IFigure> roots = null; IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner); IEnumerable <IFigure> selection = null; if (found is SubPoint) {// can't move sub point 01-11-10 scott return; } // remove by scott 08-25-2009 if (IsCtrlPressed()) { if (found != null) { found.Selected = !found.Selected; } selection = Drawing.GetSelectedFigures(); } else { if (found == null || !found.Selected) { Drawing.ClearSelectedFigures(); if (found != null) { found.Selected = true; selection = found.AsEnumerable(); } } } IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures(); Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs(selectedFigures)); IMovable oneMovable = found as IMovable; if (oneMovable != null /*&&!(oneMovable is Game.Zone)* 03-10-2011 Scott*/) { /*if (oneMovable is IPoint) * { * // when we drag a point, we want it to snap to the cursor * // so that the point center is directly under the tip of the mouse * offsetFromFigureLeftTopCorner = new Point(); * oldCoordinates = oneMovable.Coordinates; * } * else * {*/ // however when we drag other stuff (such as text labels) // we want the mouse to always touch the part of the draggable // where it first touched during MouseDown // we don't want the draggable to "snap" to the cursor like points do offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates); /*}*/ moving.Add(oneMovable); roots = found.AsEnumerable(); } else if (found != null) { if (!(found is Game.Zone) && !(found is LineBase)) // 11-18-2010 Scott { roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found); if (roots.All(root => root is IMovable)) { moving.AddRange(roots.Cast <IMovable>()); } } } if (roots != null) { toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots).Reverse(); } else { toRecalculate = null; } //03-09-2010 Scott if (moving.Count > 0 && moving[0] is Game.PBBall && mode == 1) { Drawing.Figures.OfType <IMovable>().ForEach(f => { if (!(f is Game.PBBall) && !(f is SubPoint)) { moving.Add(f); } } ); } else if (found != null) { IEnumerable <IFigure> figuresSelected = Drawing.GetSelectedFigures(); if (figuresSelected.All(f => f is Game.PBPlayer || f is LabelBase || f is FreePoint || f is PrePoint || f is PBLine)) // 11-12-2010 Scott add labelbase support { moving.Clear(); IEnumerable <IFigure> fs = Drawing.GetSelectedFigures(); // 08-04-11 Scott foreach (IFigure f in fs) { if (f is PBLine) { foreach (IFigure pf in (f as PBLine).Dependencies) { if (pf is IMovable && !moving.Contains(pf as IMovable)) { moving.Add(pf as IMovable); } } } if (f is IMovable) { moving.Add(f as IMovable); } } // end } } if (moving.IsEmpty()) {// coordinate system //Drawing.Canvas.Cursor = new Cursor(AppDomain.CurrentDomain.BaseDirectory + @"\Resource\CursorHand.cur"); //01-04-2010 scott //moving.Add(Drawing.CoordinateSystem); //var allFigures = Drawing.Figures.GetAllFiguresRecursive(); // remove by scott 06-24-2009 //roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, allFigures); //moving.AddRange(roots.OfType<IMovable>()); //roots = null; toRecalculate = null; // Figures; } }
public override void MouseDown(object sender, MouseButtonEventArgs e) { #if !SILVERLIGHT if (e.ClickCount == 2) { Drawing.CoordinateSystem.ZoomExtend(); return; } #endif offsetFromFigureLeftTopCorner = Coordinates(e, false, false, false); oldCoordinates = offsetFromFigureLeftTopCorner; coordinatesOnMouseDown = offsetFromFigureLeftTopCorner; startedMoving = false; moving = new List <IMovable>(); IEnumerable <IFigure> roots = null; var isLocked = false; found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner); var oneMovable = found as IMovable; if (oneMovable != null) { if (!found.Locked) { if (oneMovable is IPoint) { // when we drag a point, we want it to snap to the cursor // so that the point center is directly under the tip of the mouse offsetFromFigureLeftTopCorner = new Point(); oldCoordinates = oneMovable.Coordinates; } else { // however when we drag other stuff (such as text labels) // we want the mouse to always touch the part of the draggable // where it first touched during MouseDown // we don't want the draggable to "snap" to the cursor like points do offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates); } roots = DependencyAlgorithms.FindRoots(f => f.Dependents, found); if (roots.All(root => (!root.Locked))) { moving.Add(oneMovable); roots = found.AsEnumerable(); } else { isLocked = true; } } else { isLocked = true; } } else if (found != null && !found.Locked) { if (!found.Locked) { roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found); if (roots.All(root => root is IMovable)) { if (roots.All(root => ((IMovable)root).AllowMove())) { moving.AddRange(roots.OfType <IMovable>()); } else { isLocked = true; } } } else { isLocked = true; } } if (roots != null) { toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots); toRecalculate.Reverse(); } else { toRecalculate = null; } if (moving.IsEmpty() && !isLocked && !Drawing.CoordinateGrid.Locked) { moving.Add(Drawing.CoordinateSystem); //var allFigures = Drawing.Figures.GetAllFiguresRecursive(); //roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, allFigures); //moving.AddRange(roots.OfType<IMovable>()); //roots = null; toRecalculate = null; // Figures; } }