/// <summary> /// Create a new selection object containing an image of all of the real selected objects. /// </summary> /// <returns>a new <see cref="T:Northwoods.Go.GoSelection" /> holding view objects that represent the /// objects in the <see cref="P:Northwoods.Go.GoView.Selection" /></returns> /// <remarks> /// This creates a new <see cref="T:Northwoods.Go.GoSelection" /> for this view. /// The objects that are in this selection have been added to the default /// layer of the view. /// </remarks> public virtual GoSelection CreateDragSelection() { GoSelection goSelection = new GoSelection(null); PointF position = base.CurrentObject.Position; SizeF offset = GoTool.SubtractPoints(base.CurrentObject.Location, position); GoDragRectangle goDragRectangle = new GoDragRectangle(); goDragRectangle.Bounds = base.CurrentObject.Bounds; goDragRectangle.Offset = offset; goDragRectangle.Visible = false; base.View.Layers.Default.Add(goDragRectangle); goSelection.Add(goDragRectangle); GoCollection goCollection = new GoCollection(); goCollection.InternalChecksForDuplicates = false; foreach (GoObject item in (EffectiveSelection != null) ? EffectiveSelection : base.Selection) { goCollection.Add(item.DraggingObject); } base.View.Document.Layers.SortByZOrder(goCollection); RectangleF bounds = GoDocument.ComputeBounds(goCollection, base.View); float num = 1E+21f; float num2 = 1E+21f; foreach (GoObject item2 in goCollection) { if (item2.Top < num) { num = item2.Top; } if (item2.Left < num2) { num2 = item2.Left; } } float num3 = base.View.WorldScale.Width; if (bounds.Width * num3 > 2000f || bounds.Height * num3 > 2000f) { num3 *= Math.Min(2000f / (bounds.Width * num3), 2000f / (bounds.Height * num3)); } Bitmap bitmapFromCollection = base.View.GetBitmapFromCollection(goCollection, bounds, num3, paper: false); GoDragImage goDragImage = new GoDragImage(); goDragImage.Image = bitmapFromCollection; goDragImage.Bounds = new RectangleF(bounds.X, bounds.Y, (float)bitmapFromCollection.Width / num3, (float)bitmapFromCollection.Height / num3); if (num < 1E+21f && num2 < 1E+21f) { goDragImage.Offset = new SizeF(num2 - bounds.X + offset.Width, num - bounds.Y + offset.Height); } else { goDragImage.Offset = offset; } base.View.Layers.Default.Add(goDragImage); goSelection.Add(goDragImage); return(goSelection); }
/// <summary> /// Produce a new <see cref="T:Northwoods.Go.GoSelection" /> that is the real set of objects /// to be moved by <see cref="M:Northwoods.Go.GoView.MoveSelection(Northwoods.Go.GoSelection,System.Drawing.SizeF,System.Boolean)" /> or copied by /// <see cref="M:Northwoods.Go.GoView.CopySelection(Northwoods.Go.GoSelection,System.Drawing.SizeF,System.Boolean)" />. /// </summary> /// <param name="coll"></param> /// <param name="move">true for moving, false for copying</param> /// <returns>a <see cref="T:Northwoods.Go.GoSelection" /> that is cached as <see cref="P:Northwoods.Go.GoToolDragging.EffectiveSelection" /></returns> /// <remarks> /// This method is used to try to avoid problems with double-moving /// due to duplicate entries or both a parent and its child being in /// the argument collection. /// This also removes objects whose <see cref="P:Northwoods.Go.GoObject.DraggingObject" /> /// is null or has a false value for <see cref="M:Northwoods.Go.GoObject.CanMove" /> (if /// <paramref name="move" /> is true) or a false value for <see cref="M:Northwoods.Go.GoObject.CanCopy" /> /// (if <paramref name="move" /> is false). /// Furthermore this adds to the collection all links that have both /// ports in the selection. /// </remarks> public virtual GoSelection ComputeEffectiveSelection(IGoCollection coll, bool move) { Dictionary <GoObject, bool> dictionary = new Dictionary <GoObject, bool>(); GoCollection goCollection = null; GoSelection goSelection = new GoSelection(null); foreach (GoObject item in coll) { GoObject draggingObject = item.DraggingObject; if (draggingObject != null && !(move ? (!draggingObject.CanMove()) : (!draggingObject.CanCopy())) && !alreadyDragged(dictionary, draggingObject)) { dictionary[draggingObject] = true; if (!draggingObject.IsTopLevel) { if (goCollection == null) { goCollection = new GoCollection(); } goCollection.Add(draggingObject); } goSelection.Add(draggingObject); } } if (EffectiveSelectionIncludesLinks) { GoObject[] array = goSelection.CopyArray(); for (int i = 0; i < array.Length; i++) { IGoNode goNode = array[i] as IGoNode; if (goNode != null) { foreach (IGoLink destinationLink in goNode.DestinationLinks) { if (!alreadyDragged(dictionary, destinationLink.GoObject) && (destinationLink.ToPort == null || alreadyDragged(dictionary, destinationLink.ToPort.GoObject))) { dictionary[destinationLink.GoObject] = true; goSelection.Add(destinationLink.GoObject); } } foreach (IGoLink sourceLink in goNode.SourceLinks) { if (!alreadyDragged(dictionary, sourceLink.GoObject) && (sourceLink.FromPort == null || alreadyDragged(dictionary, sourceLink.FromPort.GoObject))) { dictionary[sourceLink.GoObject] = true; goSelection.Add(sourceLink.GoObject); } } } } } if (goCollection != null) { GoCollection goCollection2 = null; foreach (GoObject item2 in goSelection) { GoObject draggingObject2 = item2.DraggingObject; if (draggingObject2 is GoGroup) { foreach (GoObject item3 in goCollection) { if (item3.IsChildOf(draggingObject2)) { if (goCollection2 == null) { goCollection2 = new GoCollection(); } goCollection2.Add(item3); } } } } if (goCollection2 != null) { foreach (GoObject item4 in goCollection2) { goSelection.Remove(item4); } return(goSelection); } } return(goSelection); }