Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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);
                        }
                    }
                }
            }
        }