/// <summary>
 /// Modify the order of the objects in the given <see cref="T:Northwoods.Go.GoCollection" /> <paramref name="c" />
 /// to be in their Z-order position in the layers of this collection.
 /// </summary>
 /// <param name="c">a <see cref="T:Northwoods.Go.GoCollection" /> that will be modified</param>
 /// <remarks>See the remarks for <see cref="M:Northwoods.Go.GoLayerCollection.SortByZOrder(Northwoods.Go.GoObject[])" />.</remarks>
 public void SortByZOrder(GoCollection c)
 {
     if (!c.IsEmpty)
     {
         ZOrderComparer comparer = GetComparer();
         c.Sort(comparer);
     }
 }
Example #2
0
        /// <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);
        }
Example #3
0
 /// <summary>
 /// Construct an IEnumerator for iterating either forwards or backwards over a
 /// <see cref="T:System.Collections.Generic.List`1" />s.
 /// </summary>
 /// <param name="a"></param>
 /// <param name="forward"></param>
 public GoCollectionEnumerator(List <GoObject> a, bool forward)
 {
     myArray              = a;
     myForward            = forward;
     myIndex              = -1;
     myOriginalChanges    = 0;
     myOriginalCollection = null;
     Reset();
 }
Example #4
0
        /// <summary>
        /// Change the <see cref="P:Northwoods.Go.GoObject.Parent" /> of an object to be the common subgraph that
        /// contains two given objects, or if there is no such subgraph, add the object to the given layer.
        /// </summary>
        /// <param name="obj">the <see cref="T:Northwoods.Go.GoObject" /> to reparent</param>
        /// <param name="child1">an object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <param name="child2">another object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <param name="behind">whether to add the <paramref name="obj" /> at the beginning of the list
        /// of the subgraph's children (thus behind all other subgraph children), or at the end of the list
        /// (thus appearing in front of all the other subgraph children)</param>
        /// <param name="layer">
        /// the <see cref="T:Northwoods.Go.GoLayer" /> to which the <paramref name="obj" /> should be added,
        /// if there is no common parent <see cref="T:Northwoods.Go.GoSubGraphBase" /> for <paramref name="child1" /> and
        /// <paramref name="child2" />
        /// </param>
        /// <remarks>
        /// All of the arguments to this method should be non-null.
        /// </remarks>
        public static void ReparentToCommonSubGraph(GoObject obj, GoObject child1, GoObject child2, bool behind, GoLayer layer)
        {
            GoSubGraphBase a        = FindParentSubGraph(child1);
            GoSubGraphBase b        = FindParentSubGraph(child2);
            GoObject       goObject = GoObject.FindCommonParent(a, b);

            while (goObject != null && !(goObject is GoSubGraphBase))
            {
                goObject = goObject.Parent;
            }
            GoSubGraphBase goSubGraphBase = goObject as GoSubGraphBase;

            if (obj.Parent == goSubGraphBase && obj.Layer != null)
            {
                return;
            }
            if (obj.Parent == null && obj.Layer == null)
            {
                if (goSubGraphBase != null)
                {
                    if (behind)
                    {
                        goSubGraphBase.InsertBefore(null, obj);
                    }
                    else
                    {
                        goSubGraphBase.InsertAfter(null, obj);
                    }
                }
                else
                {
                    layer.Add(obj);
                }
            }
            else
            {
                GoCollection goCollection = new GoCollection();
                goCollection.Add(obj);
                if (goSubGraphBase != null)
                {
                    goSubGraphBase.AddCollection(goCollection, reparentLinks: false);
                }
                else
                {
                    layer.AddCollection(goCollection, reparentLinks: false);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Make sure each link, either directly in the given collection, or connected to the nodes in
        /// the given collection, belong to the appropriate <see cref="T:Northwoods.Go.GoSubGraphBase" />.
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="behind">whether to add the <paramref name="coll" /> at the beginning of the list
        /// of the subgraph's children (thus behind all other subgraph children), or at the end of the list
        /// (thus appearing in front of all the other subgraph children)</param>
        /// <param name="layer">the <see cref="T:Northwoods.Go.GoLayer" /> for links whose ports do not both belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <remarks>
        /// This calls <see cref="M:Northwoods.Go.GoSubGraphBase.ReparentToCommonSubGraph(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoObject,System.Boolean,Northwoods.Go.GoLayer)" /> for each <see cref="T:Northwoods.Go.IGoLink" /> in the
        /// <paramref name="coll" /> collection, or for each <see cref="T:Northwoods.Go.IGoLink" /> connected to each <see cref="T:Northwoods.Go.IGoNode" />
        /// in the <paramref name="coll" /> collection.
        /// </remarks>
        public static void ReparentAllLinksToSubGraphs(IGoCollection coll, bool behind, GoLayer layer)
        {
            GoCollection goCollection = new GoCollection();

            foreach (GoObject item in coll)
            {
                goCollection.Add(item);
            }
            foreach (GoObject item2 in goCollection)
            {
                IGoNode goNode = item2 as IGoNode;
                if (goNode != null)
                {
                    foreach (IGoLink link in goNode.Links)
                    {
                        if (link != null && link.FromPort != null && link.ToPort != null)
                        {
                            ReparentToCommonSubGraph(link.GoObject, link.FromPort.GoObject, link.ToPort.GoObject, behind, layer);
                        }
                    }
                }
                else
                {
                    IGoPort goPort = item2 as IGoPort;
                    if (goPort != null)
                    {
                        foreach (IGoLink link2 in goPort.Links)
                        {
                            if (link2 != null && link2.FromPort != null && link2.ToPort != null)
                            {
                                ReparentToCommonSubGraph(link2.GoObject, link2.FromPort.GoObject, link2.ToPort.GoObject, behind, layer);
                            }
                        }
                    }
                    else
                    {
                        IGoLink goLink = item2 as IGoLink;
                        if (goLink != null && goLink.FromPort != null && goLink.ToPort != null)
                        {
                            ReparentToCommonSubGraph(goLink.GoObject, goLink.FromPort.GoObject, goLink.ToPort.GoObject, behind, layer);
                        }
                    }
                }
            }
        }
Example #6
0
 /// <summary>
 /// Unlike the standard behavior provided by <see cref="T:Northwoods.Go.GoGroup" />'s <see cref="M:Northwoods.Go.GoGroup.PickObjects(System.Drawing.PointF,System.Boolean,Northwoods.Go.IGoCollection,System.Int32)" />,
 /// subgraphs allow the picking of more than one child, if they overlap each other at the given point.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="selectableOnly"></param>
 /// <param name="coll"></param>
 /// <param name="max"></param>
 /// <returns></returns>
 /// <remarks>
 /// If <see cref="M:Northwoods.Go.GoObject.CanView" /> is false for this group, no children are added to the collection.
 /// </remarks>
 public override IGoCollection PickObjects(PointF p, bool selectableOnly, IGoCollection coll, int max)
 {
     if (coll == null)
     {
         coll = new GoCollection();
     }
     if (coll.Count >= max)
     {
         return(coll);
     }
     if (!GoObject.ContainsRect(Bounds, p))
     {
         return(coll);
     }
     if (!CanView())
     {
         return(coll);
     }
     foreach (GoObject backward in base.Backwards)
     {
         GoSubGraphBase goSubGraphBase = backward as GoSubGraphBase;
         if (goSubGraphBase != null)
         {
             goSubGraphBase.PickObjects(p, selectableOnly, coll, max);
         }
         else
         {
             GoObject goObject = backward.Pick(p, selectableOnly);
             if (goObject != null)
             {
                 coll.Add(goObject);
                 if (coll.Count >= max)
                 {
                     return(coll);
                 }
             }
         }
     }
     if (PickableBackground && (!selectableOnly || CanSelect()))
     {
         coll.Add(this);
     }
     return(coll);
 }
Example #7
0
        /// <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);
        }