public static List <IFigure> FindImpactedDependencyChain(IFigure source, IFigure sink)
        {
            var visitedSet = new Dictionary <IFigure, bool>();

            AddAllDependents(
                source.AsEnumerable(),
                f => f.Dependents,
                visitedSet,
                null);

            var result = new List <IFigure>();

            AddImpactedDependency(sink, visitedSet, result);
            return(result);
        }
        protected override void ExecuteCore()
        {
            CustomDependencyRemovers = new List <IAction>();

            Deleted = Figure.AsEnumerable <IFigure>()
                      .TopologicalSort(GetRemovableDependencies)
                      .ToArray();

            foreach (var item in CustomDependencyRemovers)
            {
                item.Execute();
            }

            foreach (var item in Deleted)
            {
                Drawing.Figures.Remove(item);
            }

            Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs());
        }
示例#3
0
        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;
            bool isLocked = false;

            found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);

            IMovable oneMovable = found as IMovable;
            if (oneMovable != null && (found.Locked || oneMovable.AllowMove()))
            {
                if (found.Locked)
                {
                    isLocked = true;
                }
                else if (oneMovable.AllowMove())
                {
                    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 if (found != null)
            {
                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;
            }
        }
示例#4
0
        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();
        }
示例#5
0
 public SelectionChangedEventArgs(IFigure singleSelection)
     : this(singleSelection.AsEnumerable())
 {
 }
示例#6
0
 public FigureCoordinatesChangedEventArgs(IFigure singleFigure)
     : this(singleFigure.AsEnumerable())
 {
 }
示例#7
0
 public DeleteExecutedEventArgs(IFigure deletedFigure)
     : this(deletedFigure.AsEnumerable())
 {
 }
示例#8
0
 public SelectionChangedEventArgs(IFigure singleSelection)
     : this(singleSelection.AsEnumerable())
 {
 }
示例#9
0
 public FigureCoordinatesChangedEventArgs(IFigure singleFigure)
     : this(singleFigure.AsEnumerable())
 {
 }
示例#10
0
 public DeleteExecutedEventArgs(IFigure deletedFigure)
     : this(deletedFigure.AsEnumerable())
 {
 }
示例#11
0
        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;
            bool isLocked = false;

            found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);

            IMovable 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;
            }
        }
示例#12
0
        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;
            }
        }
示例#13
0
        bool mousePressed = false; //CC
        //MouseButton pressedButton = MouseButton.Left; //CC

        public override void MouseDown(object sender, MouseButtonEventArgs e)
        {
            var  canvas   = this.ParentCanvas as Canvas;
            bool isLocked = false;

            moving = new List <IMovable>();
            IEnumerable <IFigure> roots = null;

#if !SILVERLIGHT
            if (e.ChangedButton == MouseButton.Left)
            {
                offsetFromFigureLeftTopCorner = Coordinates(e, false, false, false);
                oldCoordinates         = offsetFromFigureLeftTopCorner;
                coordinatesOnMouseDown = offsetFromFigureLeftTopCorner;
                startedMoving          = false;

                //found = Drawing.Figures.MouseHover(offsetFromFigureLeftTopCorner);

                found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);
                IMovable oneMovable = found as IMovable;
                //canvas.Cursor = Cursors.Arrow;
                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;
                }
            }
            // Chuột giữa
            else if (e.ChangedButton == MouseButton.Middle)
            {
                canvas.Cursor = Cursors.Hand;

                // zoom extend
                if (e.ClickCount == 2)
                {
                    Drawing.CoordinateSystem.ZoomExtend();
                    return;
                }
                // Di chuyển lưới
                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;
                }
            }
#endif

            // Chuột phải hiển thị context menu
            else if (e.ChangedButton == MouseButton.Right)
            {
                ContextMenu menu = new ContextMenu();
                MenuItem    file = new MenuItem()
                {
                    Header = "Reactor"
                };
                MenuItem options = new MenuItem()
                {
                    Header = "Options", InputGestureText = "Ctrl+O"
                };
                options.Click += options_Click;

                menu.Items.Add(file);
                menu.Items.Add(new Separator());
                menu.Items.Add(options);

                var open = new MenuItem()
                {
                    Header = "_Open", InputGestureText = "Ctrl+O"
                };
                open.Click += Open_Click;
                var save = new MenuItem()
                {
                    Header = "_Save...", InputGestureText = "Ctrl+S"
                };
                //save.Click += Save_Click;
                var print = new MenuItem()
                {
                    Header = "Print"
                };
                //print.Click += Print_Click;
                var exit = new MenuItem()
                {
                    Header = "Exit"
                };
                //exit.Click += Exit_Click;

                var items = new UIElement[] {
                    open,
                    save,
                    print,
                    new Separator(),
                    exit
                };

                file.ItemsSource = items;

                canvas.ContextMenu = menu;
            }
        }