/// <summary>
 /// Adds or merges a collection into this collection
 /// </summary>
 /// <param name="collection"></param>
 public void AddRange(ShapeCollection collection)
 {
     for (int k = 0; k < collection.Count; k++)
     {
         this.Add(collection[k]);
     }
 }
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public GraphAbstract(SerializationInfo info, StreamingContext context)
        {
            #region Version test
            //test the version, warn if the build or major is different
            Version currentversion = Assembly.GetExecutingAssembly().GetName().Version;
            Version fileversion    = new Version(info.GetString("NetronGraphLibVersion"));
            int     diff           = currentversion.CompareTo(fileversion);

            if (fileversion.Minor != currentversion.Minor || fileversion.Major != currentversion.Major)
            {
                DialogResult res = MessageBox.Show("The graph was saved in version " + fileversion.ToString() + " while the current graph library has version " + currentversion.ToString() + ". It is not guaranteed that the graph will appeare as it was when saved. Are you sure you want to open the graph?", "Different version", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (res == DialogResult.No)
                {
                    return;
                }
            }
            #endregion

            Init();

            this.mShapes      = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection;
            this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection;


            this.mGraphInformation = info.GetValue("mGraphInformation", typeof(GraphInformation)) as GraphInformation;

            this.mLayers = info.GetValue("mLayers", typeof(GraphLayerCollection)) as GraphLayerCollection;
        }
Beispiel #3
0
        /// <summary>
        /// Returns the adjacent shapes on the basis of a structuring IGraph, usually
        /// what is being returned by Prim's algorithm.
        /// This is equal to the adjacent nodes if the graph is a tree.
        /// Whether a connected nodes is really a 'child' is the sense of being positioned
        /// on a lower level cannot be decided here but belongs to the layout
        /// </summary>
        /// <param name="structure"></param>
        /// <param name="shape"></param>
        /// <returns>A ShapeCollection of shapes</returns>
        private ShapeCollection AdjacentNodes(IGraph structure, Shape shape)
        {
            try
            {
                mSite.OutputInfo("Adjacents of '" + shape.Text + "':");
                int     index = (int)shape.Tag;
                IVertex vertex;
                //TODO: take direction into account
                IEnumerator     numer  = structure.GetVertex(index).Successors.GetEnumerator();
                ShapeCollection shapes = new ShapeCollection();
                while (numer.MoveNext())
                {
                    vertex = numer.Current as IVertex;
                    shapes.Add(nodes[vertex.Number]);
                    mSite.OutputInfo("\t - '" + nodes[vertex.Number].Text + "'");
                }
                numer = structure.GetVertex(index).Predecessors.GetEnumerator();
                while (numer.MoveNext())
                {
                    vertex = numer.Current as IVertex;
                    shapes.Add(nodes[vertex.Number]);
                    mSite.OutputInfo("\t - '" + nodes[vertex.Number].Text + "'");
                }


                return(shapes);
            }
            catch
            {
                //don't return null, make the collection just empty
                return(new ShapeCollection());
            }
        }
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public GraphAbstract(SerializationInfo info, StreamingContext context)
        {
            #region Version test
            //test the version, warn if the build or major is different
            Version currentversion = Assembly.GetExecutingAssembly().GetName().Version;
            Version fileversion    = new Version(info.GetString("NetronGraphLibVersion"));
            int     diff           = currentversion.CompareTo(fileversion);

            if (fileversion.Minor != currentversion.Minor || fileversion.Major != currentversion.Major)
            {
                DialogResult res = MessageBox.Show("The graph was saved in version " + fileversion.ToString() + " while the current graph library has version " + currentversion.ToString() + ". It is not guaranteed that the graph will appeare as it was when saved. Are you sure you want to open the graph?", "Different version", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (res == DialogResult.No)
                {
                    return;
                }
            }
            #endregion

            this.mShapes      = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection;
            this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection;


            this.mGraphInformation = info.GetValue("mGraphInformation", typeof(GraphInformation)) as GraphInformation;

            this.mLayers = info.GetValue("mLayers", typeof(GraphLayerCollection)) as GraphLayerCollection;

            if (mLayers != null)
            {
                GraphLayer layer = mLayers["Default"];
                if (layer == null)
                {
                    layer          = new GraphLayer("Default", Color.WhiteSmoke, 100);
                    layer.UseColor = false; //use colors only for upper layers
                    layer.Visible  = false;
                    mLayers.Add(layer);
                }

                //    foreach (GraphLayer tLayer in mLayers)
                //    {
                //        if (tLayer != null && tLayer.Visible)
                //        {
                //            mCurrentLayer = tLayer;
                //                  break;
                //        }
                //    }

                //    if (mCurrentLayer == null)
                //    {
                //              mCurrentLayer = DefaultLayer;
                //    }

                //     if (mCurrentLayer != null) mCurrentLayer.Visible = true;
                mLayers.ClearComplete += new EventHandler(Layers_ClearComplete);
            }

            BindEntityCollectionEvents();
        }
 public GraphLayout(IGraphSite mSite)
 {
     if(mSite==null) throw new Exception("No mSite specified in graph layout constructor.");;
     this.mSite = mSite;
     nnodes = mSite.Nodes.Count;
     nedges=mSite.Edges.Count;
     CanvasSize = mSite.Size;
     nodes=mSite.Nodes;
     edges=mSite.Edges;
 }
Beispiel #6
0
 /// <summary>
 /// Deserialization constructor
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected EntityBundle(SerializationInfo info, StreamingContext context)
 {
     this.mShapes      = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection;
     this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection;
     this.mDescription = info.GetString("mDescription");
     this.mName        = info.GetString("mName");
     try
     {
         this.mBundleImage = info.GetValue("mBundleImage", typeof(Image)) as Image;
     }
     catch
     {
         //leave the image to null
     }
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="mSite"></param>
 protected GraphLayout(IGraphSite mSite)
 {
     if (mSite == null)
     {
         throw new Exception("No mSite specified in graph layout constructor.");
     }
     ;
     this.mSite = mSite;
     nnodes     = mSite.Shapes.Count;
     nedges     = mSite.Connections.Count;
     CanvasSize = mSite.Size;
     nodes      = mSite.Shapes;
     edges      = mSite.Connections;
     extract    = mSite.Abstract;
 }
Beispiel #8
0
        /// <summary>
        /// Quicksort implementation
        /// </summary>
        /// <param name="lowerIndex"></param>
        /// <param name="upperIndex"></param>
        /// <param name="shapes"></param>
        public static void QuickSort(int lowerIndex, int upperIndex, ref ShapeCollection shapes)
        {
            int pivot, leftHold, rightHold;

            leftHold  = lowerIndex;
            rightHold = upperIndex;
            pivot     = shapes[lowerIndex].ZOrder;

            while (lowerIndex < upperIndex)
            {
                while ((shapes[upperIndex].ZOrder >= pivot) && (lowerIndex < upperIndex))
                {
                    upperIndex--;
                }

                if (lowerIndex != upperIndex)
                {
                    shapes[lowerIndex].ZOrder = shapes[upperIndex].ZOrder;
                    lowerIndex++;
                }

                while ((shapes[lowerIndex].ZOrder <= pivot) && (lowerIndex < upperIndex))
                {
                    lowerIndex++;
                }

                if (lowerIndex != upperIndex)
                {
                    shapes[upperIndex].ZOrder = shapes[lowerIndex].ZOrder;
                    upperIndex--;
                }
            }

            shapes[lowerIndex].ZOrder = pivot;
            pivot      = lowerIndex;
            lowerIndex = leftHold;
            upperIndex = rightHold;

            if (lowerIndex < pivot)
            {
                QuickSort(lowerIndex, pivot - 1, ref shapes);
            }

            if (upperIndex > pivot)
            {
                QuickSort(pivot + 1, upperIndex, ref shapes);
            }
        }
Beispiel #9
0
        /// <summary>
        /// return the shapes of layer
        /// </summary>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public ShapeCollection ShapesOfLayer(string layerName)
        {
            ShapeCollection shapes = new ShapeCollection();
            GraphLayer      layer  = Layers[layerName];

            if (layer != null)
            {
                foreach (Shape shape in Shapes)
                {
                    if (shape.Layer == layer)
                    {
                        shapes.Add(shape);
                    }
                }
            }
            return(shapes);
        }
Beispiel #10
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public EntityBundle(GraphControl mSite)
 {
     mConnections = new ConnectionCollection();
     mShapes      = new ShapeCollection();
     this.mSite   = mSite;
 }
        /// <summary>
        /// Implements the copy function to the clipboard
        /// </summary>
        /// <remarks>
        /// This doesn't work, bug in Clipboard object, hopefully fixed in Net v2 
        ///</remarks>
        public void Copy()
        {
            ShapeCollection ar = new ShapeCollection();
            foreach(Shape so in extract.Shapes)
            {
                if(so.IsSelected)
                {
                    ar.Add(so);
                }
            }
            if(ar.Count>0)
            {

                DataObject blurb = new DataObject(format.Name,extract);
                Clipboard.SetDataObject(blurb);
            }
        }
Beispiel #12
0
 /// <summary>
 /// Quick Sort Algorithm
 /// http://www.publicjoe.f9.co.uk/csharp/sort05.html
 /// </summary>
 /// <param name="shapes">a shapes collection</param>
 public static void QuickSort(ref ShapeCollection shapes)
 {
     QuickSort(0, shapes.Count - 1, ref shapes);
 }
 /// <summary>
 /// Removes the box in the parameter from the desktop
 /// (used when deleting from archive)
 /// </summary>
 /// <param name="boxes">Boxes to be removed</param>
 /// <remarks>There no need to have a
 /// IBoxModule list in the argument, because
 /// this command can be only accessible from 
 /// the desktop (not from the archive)</remarks>
 protected void RemoveBoxes(ShapeCollection boxes)
 {
     foreach (BoxNode node in boxes)
     {
         RemoveShape(node);
     }
     SelectedBoxes.Clear();
 }
Beispiel #14
0
 public virtual ShapeCollection GetChildShapes()
 {
     ShapeCollection sc = new ShapeCollection();
     foreach (Connector cr in this.Connectors) {
         foreach (Connection cn in cr.Connections) {
             sc.Add(cn.From == cr ? cn.To.BelongsTo : cn.From.BelongsTo);
         }
     }
     return sc;
 }
Beispiel #15
0
        /// <summary>
        /// Positions everything underneath the node and returns the total width of the kids
        /// </summary>
        /// <param name="containerNode"></param>
        /// <param name="first"></param>
        /// <param name="shiftLeft"></param>
        /// <param name="shiftTop"></param>
        /// <param name="structure"></param>
        /// <returns></returns>
        private float VerticalDrawTree(IGraph structure, Shape containerNode, bool first, float shiftLeft, float shiftTop)
        {
            bool            isFirst = false;
            ShapeCollection adj = AdjacentNodes(structure, containerNode);
            bool            isParent = adj.Count > 0? true: false;
            float           childrenWidth = 0;
            float           thisX, thisY;
            float           returned      = 0;
            float           verticalDelta = branchHeight;    //the applied vertical shift of the child depends on the Height of the containerNode

            visited[containerNode.UID.ToString()] = true;


            #region Children width
            for (int i = 0; i < adj.Count; i++)
            {
                //determine the width of the label
                if (i == 0)
                {
                    isFirst = true;
                }
                else
                {
                    isFirst = false;
                }
                if (adj[i].IsVisible && !visited[adj[i].UID.ToString()])
                {
                    if ((branchHeight - containerNode.Height) < 30)                    //if too close to the child, shift it with 40 units
                    {
                        verticalDelta = containerNode.Height + 40;
                    }
                    returned       = VerticalDrawTree(structure, adj[i], isFirst, shiftLeft + childrenWidth, shiftTop + verticalDelta);
                    childrenWidth += returned;
                }
            }
            if (childrenWidth > 0 && containerNode.IsExpanded)
            {
                childrenWidth = Math.Max(Convert.ToInt32(childrenWidth + (containerNode.Width - childrenWidth) / 2), childrenWidth);           //in case the length of the containerNode is bigger than the total length of the children
            }
            #endregion

            if (childrenWidth == 0)          //there are no children; this is the branch end
            {
                childrenWidth = containerNode.Width + wordSpacing;
            }

            #region Positioning
            thisY = shiftTop;
            if (adj.Count > 0 && containerNode.IsExpanded)
            {
                float firstChild = float.MaxValue;                 //for comparison to find the smallest
                float lastChild  = float.MinValue;
                float tmp;
                //loop over the adjacent nodes and take the first node that is positioned lower than the current
                //this is the zero-th entry if the graph is a tree but not in general
                int f = -1, l = -1;
                for (int k = 0; k < adj.Count; k++)
                {
                    if (positioned[adj[k].UID.ToString()])
                    {
                        tmp = adj[k].Rectangle.Left + adj[k].Width / 2;
                        if (tmp < firstChild)
                        {
                            firstChild = tmp;
                            f          = k;
                        }
                        if (tmp > lastChild)
                        {
                            lastChild = tmp;
                            l         = k;
                        }
                    }
                }
                /* informative but costly debugging info*/
                mSite.OutputInfo("               ");
                mSite.OutputInfo("Positioning : '" + containerNode.Text + "'");
                if (f > -1)
                {
                    mSite.OutputInfo("First child: '" + adj[f].Text + "'");
                }
                else
                {
                    mSite.OutputInfo("First child: not found");
                }
                if (l > -1)
                {
                    mSite.OutputInfo("Last child: '" + adj[l].Text + "'");
                }
                else
                {
                    mSite.OutputInfo("Last child: not found");
                }

                if (firstChild < float.MaxValue)              //there is an adjacent node and it's not positioned above this one
                {
                    if (firstChild == lastChild)
                    {
                        thisX = firstChild - containerNode.Width / 2;
                    }
                    else
                    {
                        //the following max in case the containerNode is larger than the childrenWidth
                        thisX = Math.Max(firstChild + (lastChild - firstChild - containerNode.Width) / 2, firstChild);
                    }
                }
                else
                {
                    thisX = shiftLeft;
                }
            }
            else
            {
                thisX = shiftLeft;
            }

            containerNode.X = thisX;
            containerNode.Y = thisY;
            positioned[containerNode.UID.ToString()] = true;
            mSite.Invalidate();
            #endregion

            return(childrenWidth);
        }