Пример #1
0
		public bool Equals (Rect2D value)
		{
			return (x == value.X &&
				y == value.Y &&
				width == value.Width &&
				height == value.Height);
		}
Пример #2
0
		public bool Contains (Rect2D rect)
		{
			if (rect.Left < this.Left ||
			    rect.Right > this.Right)
				return false;

			if (rect.Top < this.Top ||
			    rect.Bottom > this.Bottom)
				return false;

			return true;
		}
Пример #3
0
        public bool Contains(Rect2D rect)
        {
            if (rect.Left < this.Left ||
                rect.Right > this.Right)
            {
                return(false);
            }

            if (rect.Top < this.Top ||
                rect.Bottom > this.Bottom)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        public void Intersect(Rect2D rect)
        {
            double _x      = Math.Max(x, rect.x);
            double _y      = Math.Max(y, rect.y);
            double _width  = Math.Min(Right, rect.Right) - _x;
            double _height = Math.Min(Bottom, rect.Bottom) - _y;

            if (_width < 0 || _height < 0)
            {
                x     = y = Double.PositiveInfinity;
                width = height = Double.NegativeInfinity;
            }
            else
            {
                x      = _x;
                y      = _y;
                width  = _width;
                height = _height;
            }
        }
Пример #5
0
 public static bool Equals(Rect2D rect1, Rect2D rect2)
 {
     return(rect1.Equals(rect2));
 }
Пример #6
0
        private static bool IsInRegion(Rect2D region, ILocatable locatable, bool fullyEnclosed)
        {
            double x0 = locatable.X;
            double y0 = locatable.Y;

            if (false == fullyEnclosed) // Cross selection.
            {
                var test = new Rect2D(x0, y0, locatable.Width, locatable.Height);
                return region.IntersectsWith(test);
            }

            double x1 = x0 + locatable.Width;
            double y1 = y0 + locatable.Height;
            return (region.Contains(x0, y0) && region.Contains(x1, y1));
        }
Пример #7
0
        internal void SelectInRegion(Rect2D region, bool isCrossSelect)
        {
            bool fullyEnclosed = !isCrossSelect;

            foreach (NodeModel n in Model.Nodes)
            {
                double x0 = n.X;
                double y0 = n.Y;

                if (IsInRegion(region, n, fullyEnclosed))
                {
                    if (!DynamoSelection.Instance.Selection.Contains(n))
                        DynamoSelection.Instance.Selection.Add(n);
                }
                else
                {
                    if (n.IsSelected)
                        DynamoSelection.Instance.Selection.Remove(n);
                }
            }

            foreach (var n in Model.Notes)
            {
                double x0 = n.X;
                double y0 = n.Y;

                if (IsInRegion(region, n, fullyEnclosed))
                {
                    if (!DynamoSelection.Instance.Selection.Contains(n))
                        DynamoSelection.Instance.Selection.Add(n);
                }
                else
                {
                    if (n.IsSelected)
                        DynamoSelection.Instance.Selection.Remove(n);
                }
            }

            foreach (var n in Model.Annotations)
            {
                double x0 = n.X;
                double y0 = n.Y;

                if (IsInRegion(region, n, fullyEnclosed))
                {
                    if (!DynamoSelection.Instance.Selection.Contains(n))
                        DynamoSelection.Instance.Selection.Add(n);
                }
                else
                {
                    if (n.IsSelected)
                        DynamoSelection.Instance.Selection.Remove(n);
                }
            }
        }
Пример #8
0
            internal static SelectInRegionCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);

                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");
                double width = helper.ReadDouble("Width");
                double height = helper.ReadDouble("Height");

                var region = new Rect2D(x, y, width, height);
                bool isCrossSelection = helper.ReadBoolean("IsCrossSelection");
                return new SelectInRegionCommand(region, isCrossSelection);
            }
Пример #9
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return(false); // Mouse event not handled.
            }
Пример #10
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active 
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever 
                    // it touches the selection box as opposed to only select 
                    // it when it is entirely within the selection box) when 
                    // mouse moves in the opposite direction (i.e. the current 
                    // mouse position is smaller than the point mouse-down 
                    // happened).
                    // 
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return false;
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return true;
                    }

                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return false; // Mouse event not handled.
            }
Пример #11
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());

                    var draggedGroups = DynamoSelection.Instance.Selection.OfType <AnnotationModel>();

                    // Here we check if the mouse cursor is inside any Annotation groups
                    var dropGroups = owningWorkspace.Annotations
                                     .Where(x =>
                                            !draggedGroups.Select(a => a.GUID).Contains(x.AnnotationModel.GUID) &&
                                            x.IsExpanded &&
                                            x.AnnotationModel.Rect.Contains(mouseCursor.X, mouseCursor.Y));

                    // In scenarios where there are nested groups, the above will return both
                    // the nested group and the parent group, as the mouse coursor will be inside
                    // both of there rects. In these cases we want to get group that is nested
                    // inside the parent group.
                    var dropGroup = dropGroups
                                    .FirstOrDefault(x => !x.AnnotationModel.HasNestedGroups) ?? dropGroups.FirstOrDefault();


                    // If the dropGroup is null or any of the selected items is already in the dropGroup,
                    // we disable the drop border by setting NodeHoveringState to false
                    var draggedModels = DynamoSelection.Instance.Selection
                                        .OfType <ModelBase>()
                                        .Except(draggedGroups.SelectMany(x => x.Nodes));

                    if (dropGroup is null ||
                        draggedModels
                        .Any(x => owningWorkspace.Model.Annotations.ContainsModel(x)))
                    {
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);
                    }

                    // If we are dragging groups over a group that is already nested
                    // we return as we cant have more than one nested layer
                    else if (draggedGroups.Any() &&
                             owningWorkspace.Model.Annotations.ContainsModel(dropGroup.AnnotationModel) ||
                             draggedGroups.Any(x => x.HasNestedGroups))
                    {
                        return(false); // Mouse event not handled.
                    }

                    // If the dropGroups NodeHoveringState is set to false
                    // we need to set it to true for the drop border to be displayed.
                    else if (!dropGroup.NodeHoveringState)
                    {
                        // make sure there are no other group
                        // set to NodeHoveringState before setting
                        // the current group.
                        // If we dont do this there are scenarios where
                        // two groups are very close and a node is dragged
                        // quickly between the two where the hovering state
                        // is not reset.
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);

                        // If the dropGroup belongs to another group
                        // we need to check if the parent group is collapsed
                        // if it is we dont want to be able to add new
                        // models to the drop group.
                        var parentGroup = owningWorkspace.Annotations
                                          .Where(x => x.AnnotationModel.ContainsModel(dropGroup.AnnotationModel))
                                          .FirstOrDefault();
                        if (parentGroup != null && !parentGroup.IsExpanded)
                        {
                            return(false);
                        }

                        dropGroup.NodeHoveringState = true;
                    }
                }
Пример #12
0
        public void Intersect(Rect2D rect)
        {
            double _x = Math.Max(x, rect.x);
            double _y = Math.Max(y, rect.y);
            double _width = Math.Min(Right, rect.Right) - _x;
            double _height = Math.Min(Bottom, rect.Bottom) - _y;

            if (_width < 0 || _height < 0)
            {
                x = y = Double.PositiveInfinity;
                width = height = Double.NegativeInfinity;
            }
            else
            {
                x = _x;
                y = _y;
                width = _width;
                height = _height;
            }
        }
Пример #13
0
 public bool IntersectsWith(Rect2D rect)
 {
     return !((Left >= rect.Right) || (Right <= rect.Left) ||
         (Top >= rect.Bottom) || (Bottom <= rect.Top));
 }
Пример #14
0
		public static bool Equals (Rect2D rect1, Rect2D rect2)
		{
			return rect1.Equals (rect2);
		}
Пример #15
0
 public bool IntersectsWith(Rect2D rect)
 {
     return(!((Left >= rect.Right) || (Right <= rect.Left) ||
              (Top >= rect.Bottom) || (Bottom <= rect.Top)));
 }
Пример #16
0
        internal void SelectInRegion(Rect2D region, bool isCrossSelect)
        {
            var fullyEnclosed = !isCrossSelect;
            var selection = DynamoSelection.Instance.Selection;
            var childlessModels = Model.Nodes.Concat<ModelBase>(Model.Notes);

            foreach (var n in childlessModels)
            {
                if (IsInRegion(region, n, fullyEnclosed))
                {
                    selection.AddUnique(n);
                }
                else if (n.IsSelected)
                {
                    selection.Remove(n);
                }
            }

            foreach (var n in Model.Annotations)
            {
                if (IsInRegion(region, n, fullyEnclosed))
                {
                    selection.AddUnique(n);
                    // if annotation is selected its children should be added to selection too
                    foreach (var m in n.SelectedModels)
                    {
                        selection.AddUnique(m);
                    }
                }
                else if (n.IsSelected)
                {
                    selection.Remove(n);
                }
            }
        }
Пример #17
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="region"></param>
            /// <param name="isCrossSelection"></param>
            public SelectInRegionCommand(Rect2D region, bool isCrossSelection)
            {
                redundant = true; // High-frequency command.

                Region = region;
                IsCrossSelection = isCrossSelection;
            }
Пример #18
0
        /// <summary>
        /// Updates the group boundary based on the nodes / notes selection.
        /// </summary>      
        internal void UpdateBoundaryFromSelection()
        {          
            var selectedModelsList = selectedModels.ToList();
          
            if (selectedModelsList.Any())
            {
                var groupModels = selectedModelsList.OrderBy(x => x.X).ToList();
              
                //Shifting x by 10 and y to the height of textblock
                var regionX = groupModels.Min(x => x.X) - ExtendSize;
                //Increase the Y value by 10. This provides the extra space between
                // a model and textbox. Otherwise there will be some overlap
                var regionY = groupModels.Min(y => y.Y) - ExtendSize - (TextBlockHeight == 0.0 ? MinTextHeight : TextBlockHeight);
              
                //calculates the distance between the nodes
                var xDistance = groupModels.Max(x => x.X) - regionX;
                var yDistance = groupModels.Max(x => x.Y) - regionY;

                var widthandheight = CalculateWidthAndHeight();

                var maxWidth = widthandheight.Item1;
                var maxHeight = widthandheight.Item2;

                // InitialTop is to store the Y value without the Textblock height
                this.InitialTop = groupModels.Min(y => y.Y);

                var region = new Rect2D
                {
                    X = regionX,
                    Y = regionY,
                    Width = xDistance + maxWidth + ExtendSize,
                    Height = yDistance + maxHeight + ExtendSize
                };
             
                this.X = region.X;              
                this.Y = region.Y;
                this.Width = region.Width;
                this.Height = region.Height;

                //Calculate the boundary if there is any overlap
                ModelBase overlap = null;
                foreach (var nodes in SelectedModels)
                {
                    if (!region.Contains(nodes.Rect))
                    {
                        overlap = nodes;
                        if (overlap.Rect.Top < this.X ||
                                    overlap.Rect.Bottom > region.Bottom) //Overlap in height - increase the region height
                        {
                            if (overlap.Rect.Bottom - region.Bottom > 0)
                            {
                                this.Height += overlap.Rect.Bottom - region.Bottom + ExtendSize + ExtendYHeight;
                            }
                            region.Height = this.Height;
                        }
                        if (overlap.Rect.Left < this.Y ||
                                overlap.Rect.Right > region.Right) //Overlap in width - increase the region width
                        {
                            if (overlap.Rect.Right - region.Right > 0)
                            {
                                this.Width += overlap.Rect.Right - region.Right + ExtendSize;
                            }
                            region.Width = this.Width;
                        }
                    }
                }
                               
                //Initial Height is to store the Actual height of the group.
                //that is the height should be the initial height without the textblock height.
                if (this.InitialHeight <= 0.0)
                    this.InitialHeight = region.Height;
            }
            else
            {
                this.Width = 0;
                this.height = 0;               
            }
        }
Пример #19
0
 public static Rect2D Intersect(Rect2D rect1, Rect2D rect2)
 {
     Rect2D result = rect1;
     result.Intersect(rect2);
     return result;
 }